From a12ba170e1aebe8068f3263d531edaa437d66379 Mon Sep 17 00:00:00 2001 From: Alexey Kuzenkov Date: Fri, 7 Jul 2023 03:02:37 +0600 Subject: [PATCH] Add robots.txt. Refactoring core app. --- ...calculate_coefs.py => _calculate_coefs.py} | 0 .../{duration_cost.py => costs_buildings.py} | 33 +---------------- hmom3/apps/core/balance/duration.py | 36 +++++++++++++++++++ hmom3/apps/core/balance/resources.py | 2 +- hmom3/apps/core/decorators.py | 1 + hmom3/apps/core/migrations/__init__.py | 0 .../towns/management/commands/patch0-5-1.py | 2 +- .../towns/management/commands/patch0-5-2.py | 8 ++--- hmom3/apps/towns/models.py | 2 +- hmom3/apps/towns/utils.py | 10 +++--- hmom3/hmom3/urls.py | 5 +++ hmom3/templates/robots.txt | 3 ++ 12 files changed, 58 insertions(+), 44 deletions(-) rename hmom3/apps/core/balance/{calculate_coefs.py => _calculate_coefs.py} (100%) rename hmom3/apps/core/balance/{duration_cost.py => costs_buildings.py} (50%) create mode 100644 hmom3/apps/core/balance/duration.py delete mode 100644 hmom3/apps/core/migrations/__init__.py create mode 100644 hmom3/templates/robots.txt diff --git a/hmom3/apps/core/balance/calculate_coefs.py b/hmom3/apps/core/balance/_calculate_coefs.py similarity index 100% rename from hmom3/apps/core/balance/calculate_coefs.py rename to hmom3/apps/core/balance/_calculate_coefs.py diff --git a/hmom3/apps/core/balance/duration_cost.py b/hmom3/apps/core/balance/costs_buildings.py similarity index 50% rename from hmom3/apps/core/balance/duration_cost.py rename to hmom3/apps/core/balance/costs_buildings.py index d47bf69..927cfac 100644 --- a/hmom3/apps/core/balance/duration_cost.py +++ b/hmom3/apps/core/balance/costs_buildings.py @@ -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): diff --git a/hmom3/apps/core/balance/duration.py b/hmom3/apps/core/balance/duration.py new file mode 100644 index 0000000..5cf6dfa --- /dev/null +++ b/hmom3/apps/core/balance/duration.py @@ -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))) diff --git a/hmom3/apps/core/balance/resources.py b/hmom3/apps/core/balance/resources.py index 4db8816..cba66cd 100644 --- a/hmom3/apps/core/balance/resources.py +++ b/hmom3/apps/core/balance/resources.py @@ -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 diff --git a/hmom3/apps/core/decorators.py b/hmom3/apps/core/decorators.py index 25feee7..480d400 100644 --- a/hmom3/apps/core/decorators.py +++ b/hmom3/apps/core/decorators.py @@ -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')) diff --git a/hmom3/apps/core/migrations/__init__.py b/hmom3/apps/core/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/hmom3/apps/towns/management/commands/patch0-5-1.py b/hmom3/apps/towns/management/commands/patch0-5-1.py index a77b4ad..904c162 100644 --- a/hmom3/apps/towns/management/commands/patch0-5-1.py +++ b/hmom3/apps/towns/management/commands/patch0-5-1.py @@ -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 diff --git a/hmom3/apps/towns/management/commands/patch0-5-2.py b/hmom3/apps/towns/management/commands/patch0-5-2.py index 92772a5..5d6de8a 100644 --- a/hmom3/apps/towns/management/commands/patch0-5-2.py +++ b/hmom3/apps/towns/management/commands/patch0-5-2.py @@ -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 @@ -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 diff --git a/hmom3/apps/towns/models.py b/hmom3/apps/towns/models.py index 9af39de..0f32729 100644 --- a/hmom3/apps/towns/models.py +++ b/hmom3/apps/towns/models.py @@ -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() diff --git a/hmom3/apps/towns/utils.py b/hmom3/apps/towns/utils.py index 6622407..ede7375 100644 --- a/hmom3/apps/towns/utils.py +++ b/hmom3/apps/towns/utils.py @@ -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 @@ -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() diff --git a/hmom3/hmom3/urls.py b/hmom3/hmom3/urls.py index 9a93ec3..2e58c6e 100644 --- a/hmom3/hmom3/urls.py +++ b/hmom3/hmom3/urls.py @@ -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')), @@ -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: diff --git a/hmom3/templates/robots.txt b/hmom3/templates/robots.txt new file mode 100644 index 0000000..9013f76 --- /dev/null +++ b/hmom3/templates/robots.txt @@ -0,0 +1,3 @@ +User-agent: * +Allow: / +Disallow: /mana/ \ No newline at end of file