Skip to content

Commit

Permalink
Add robots.txt. Refactoring core app.
Browse files Browse the repository at this point in the history
  • Loading branch information
KuzenkovAG committed Jul 6, 2023
1 parent db23b42 commit a12ba17
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 44 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
"""
Define function of increasing amount depend on building level:
- Building time
- Research time;
- Gold amount;
- Resources (wood, stone) amount.
Cost of buildings
"""
import math

BUILD_TIME_COEF = 0.08
SEARCH_TIME_COEF = 0.2
RES_TIME_COEF = 0.2
BUILD_EXPONENT_COEF = 3
SEARCH_EXPONENT_COEF = 2
RES_EXPONENT_COEF = 2.5
ZERO_EXPONENT = 1


def get_building_time(level, tech=1, time=None):
"""Building time depend on level."""
result = (
((1 / math.e ** (level - ZERO_EXPONENT) + 1 * BUILD_TIME_COEF)
* level ** BUILD_EXPONENT_COEF) * time / tech
)
return result


def get_research_time(level, tech=1, time=None):
"""Research time depend on level."""
result = (
((1 / math.e ** (level - ZERO_EXPONENT) + SEARCH_TIME_COEF)
* level ** SEARCH_EXPONENT_COEF
) * time / tech
)
return result


def get_gold_amount(level, tech=1, res=None):
Expand Down
36 changes: 36 additions & 0 deletions hmom3/apps/core/balance/duration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Define function of increasing amount depend on building level:
- Building time
- Research time
"""
import math

BUILD_TIME_COEF = 0.08
SEARCH_TIME_COEF = 0.2
BUILD_EXPONENT_COEF = 3
SEARCH_EXPONENT_COEF = 2
ZERO_EXPONENT = 1


def get_building_time(level, tech=1, time=None):
"""Building time depend on level."""
result = (
((1 / math.e ** (level - ZERO_EXPONENT) + 1 * BUILD_TIME_COEF)
* level ** BUILD_EXPONENT_COEF) * time / tech
)
return result


def get_research_time(level, tech=1, time=None):
"""Research time depend on level."""
result = (
((1 / math.e ** (level - ZERO_EXPONENT) + SEARCH_TIME_COEF)
* level ** SEARCH_EXPONENT_COEF
) * time / tech
)
return result


if __name__ == '__main__':
for i in range(1, 101):
print(int(get_research_time(i, 1, 1)))
2 changes: 1 addition & 1 deletion hmom3/apps/core/balance/resources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Define function of increasing resource depend on level.
Define function of increasing user resource depend on level.
"""
from django.conf import settings

Expand Down
1 change: 1 addition & 0 deletions hmom3/apps/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


def for_not_authorized(func):
"""If user is authorized - redirect to town."""
def wrap(request, *args, **kwargs):
if request.user.is_authenticated:
return redirect(reverse('towns:index'))
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion hmom3/apps/towns/management/commands/patch0-5-1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.core.management.base import BaseCommand

from ....core.balance.duration_cost import get_gold_amount
from ....core.balance.duration import get_gold_amount
from ....core.balance.resources import get_resource_income
from ....towns import models

Expand Down
8 changes: 4 additions & 4 deletions hmom3/apps/towns/management/commands/patch0-5-2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.core.management.base import BaseCommand

from ....core.balance import duration_cost
from ....core.balance import duration
from ....towns import models

DEF_GOLD_INCOME = settings.DEF_GOLD_INCOME
Expand All @@ -23,17 +23,17 @@ def handle(self, *args, **options):
).all()

for user_building in buildings:
user_building.gold = duration_cost.get_gold_amount(
user_building.gold = duration.get_gold_amount(
level=user_building.level + 1,
tech=1,
res=user_building.building.type.base_gold
)
user_building.wood = duration_cost.get_resources_amount(
user_building.wood = duration.get_resources_amount(
level=user_building.level + 1,
tech=1,
res=user_building.building.type.base_wood
)
user_building.stone = duration_cost.get_resources_amount(
user_building.stone = duration.get_resources_amount(
level=user_building.level + 1,
tech=1,
res=user_building.building.type.base_stone
Expand Down
2 changes: 1 addition & 1 deletion hmom3/apps/towns/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.urls import reverse
from django.utils import timezone

from ..core.balance.duration_cost import get_building_time
from ..core.balance.duration import get_building_time

User = get_user_model()

Expand Down
10 changes: 5 additions & 5 deletions hmom3/apps/towns/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import get_object_or_404
from django.utils import timezone

from ..core.balance import duration_cost
from ..core.balance import costs_buildings, duration
from . import models
from .action import building_level_up

Expand Down Expand Up @@ -30,17 +30,17 @@ def _level_up(instance):
base_gold = instance.building.type.base_gold
base_wood = instance.building.type.base_wood
base_stone = instance.building.type.base_stone
instance.building_time = duration_cost.get_building_time(
instance.building_time = duration.get_building_time(
level=instance.level, time=build_time)
instance.gold = duration_cost.get_gold_amount(
instance.gold = costs_buildings.get_gold_amount(
level=instance.level,
res=base_gold
)
instance.wood = duration_cost.get_resources_amount(
instance.wood = costs_buildings.get_resources_amount(
level=instance.level,
res=base_wood
)
instance.stone = duration_cost.get_resources_amount(
instance.stone = costs_buildings.get_resources_amount(
level=instance.level, res=base_stone
)
instance.save()
Expand Down
5 changes: 5 additions & 0 deletions hmom3/hmom3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from django.views.generic import TemplateView

urlpatterns = [
path('', include('apps.users.urls', namespace='users')),
Expand All @@ -11,6 +12,10 @@
path('market/', include('apps.market.urls', namespace='market')),
path('hooks/', include('apps.webhooks.urls', namespace='webhooks')),
path('management/', admin.site.urls),
path('robots.txt', TemplateView.as_view(
template_name='robots.txt',
content_type='text/plain')
),
]

if settings.DEBUG:
Expand Down
3 changes: 3 additions & 0 deletions hmom3/templates/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
User-agent: *
Allow: /
Disallow: /mana/

0 comments on commit a12ba17

Please sign in to comment.