Esempio n. 1
0
 def __init__(self,
              name='',
              link_img='',
              number=0,
              need_peoples=0,
              maintenance_price=0,
              total_maintenance_price=0,
              reserve=0,
              reserve_weapon=0,
              storage_capacity=0,
              modifiers=None,
              unit_characteristic=None):
     if modifiers is None:
         modifiers = [ModifierView()]
     if unit_characteristic is None:
         unit_characteristic = [UnitCharacteristicView()]
     self.name = name
     self.link_img = link_img
     self.number = number
     self.need_peoples = need_peoples
     self.maintenance_price = maintenance_price
     self.total_maintenance_price = total_maintenance_price
     self.reserve = reserve
     self.reserve_weapon = reserve_weapon
     self.storage_capacity = storage_capacity
     self.modifiers = modifiers
     self.unit_characteristic = unit_characteristic
 def __init__(self,
              population=0,
              farmers=0,
              miners=0,
              workers=0,
              soldiers=0,
              free=0,
              others=0,
              percent_total_progress=0,
              modifiers=None,
              pie_chart_data=None,
              pie_chart_labels=None):
     if pie_chart_labels is None:
         pie_chart_labels = []
     if pie_chart_data is None:
         pie_chart_data = []
     if modifiers is None:
         modifiers = [ModifierView()]
     self.population = population
     self.farmers = farmers
     self.miners = miners
     self.workers = workers
     self.soldiers = soldiers
     self.free = free
     self.others = others
     self.percent_total_progress = percent_total_progress
     self.modifiers = modifiers
     self.pie_chart_data = pie_chart_data
     self.pie_chart_labels = pie_chart_labels
Esempio n. 3
0
 def __init__(self, name='', percent_value=0, profit=0, modifiers=None):
     if modifiers is None:
         modifiers = [ModifierView()]
     self.name = name
     self.percent_value = percent_value
     self.profit = profit
     self.modifiers = modifiers
Esempio n. 4
0
 def get_politics_laws(self, user_id: str):
     user = User.objects(id=user_id).first()
     country = Country.objects(id=user.country.id).first()
     conscription_laws = []
     pop_laws = []
     for law in Law.objects():
         if 'Conscript law:' in law.name:
             conscription_percent = re.split(' ', law.description)[-1]
             conscription_laws.append(
                 LawView(law.name, law.description, [
                     ModifierView(mod.value, mod.address_to)
                     for mod in law.modifiers
                 ], conscription_percent))
         else:
             pop_laws.append(
                 LawView(law.name, f' ({law.description})', [
                     ModifierView(mod.value, mod.address_to)
                     for mod in law.modifiers
                 ]))
     return PoliticsView(country.adopted_laws, conscription_laws, pop_laws)
Esempio n. 5
0
    def get_population(self, user_id: str):
        start = time.time()
        user = User.objects(id=user_id).first()
        country = Country.objects(id=user.country.id).first()
        modifiers_view_list = []
        population_modifiers = 0  # -> 1(100%)

        for mod in country.population.modifiers:
            modifiers_view_list.append(
                ModifierView(round(mod.value, 2), mod.address_from))
            population_modifiers += mod.value
        modifiers_view_list.append(
            ModifierView(country.population.basic_percent_growth_rate,
                         'basic percent'))

        percent_total_progress = round(
            (population_modifiers +
             country.population.basic_percent_growth_rate), 2)

        pie_chart_labels = [
            'Farmers', 'Miners', 'Workers', 'Solders', 'Free', 'Others'
        ]
        pie_chart_data = [
            country.population.farmers, country.population.miners,
            country.population.factory_workers, country.population.solders,
            country.population.free_people,
            country.population.total_population *
            (country.population.min_percent_others / 100)
        ]

        population_view = PopulationView(
            country.population.total_population, country.population.farmers,
            country.population.miners, country.population.factory_workers,
            country.population.solders, country.population.free_people,
            country.population.others, percent_total_progress,
            modifiers_view_list, pie_chart_data, pie_chart_labels)
        finish = time.time()
        return population_view
 def __init__(self,
              name='',
              price_upgrade=0,
              level=0,
              max_level=100,
              percent_total_result=0,
              modifiers=None):
     if modifiers is None:
         modifiers = [ModifierView()]
     self.name = name
     self.price_upgrade = price_upgrade
     self.level = level
     self.max_level = max_level
     self.percent_total_result = percent_total_result
     self.modifiers = modifiers
Esempio n. 7
0
    def get_technologies(self, user_id: str):
        start = time.time()
        user = User.objects(id=user_id).first()
        country = Country.objects(id=user.country.id).first()

        technologies_view_list = []
        for technology in country.technologies:
            technology_view = TechnologyView(
                technology.name, technology.price_upgrade, technology.level,
                technology.max_level,
                technology.level * technology.modifiers[0].value, [
                    ModifierView(mod.value, mod.address_to)
                    for mod in technology.modifiers
                ])
            technologies_view_list.append(technology_view)

        finish = time.time()
        return technologies_view_list
Esempio n. 8
0
    def get_army(self, user_id: str):
        start = time.time()
        user = User.objects(id=user_id).first()
        country = Country.objects(id=user.country.id).first()
        army = country.army.units
        army_units = ArmyUnit.objects()
        army_view_list = []
        sum_attack_modifiers = GameService().get_army_modifiers(
            country, 'attack')
        sum_defence_modifiers = GameService().get_army_modifiers(
            country, 'defence')

        for name_unit in army:
            if name_unit == 'Infantry':
                warehouse = next(
                    filter(lambda x: x.goods.name == 'Infantry equipment',
                           country.warehouses), None)
                weapons = warehouse.goods.value
                storage_capacity = warehouse.capacity

            elif name_unit == 'Artillery':
                warehouse = next(
                    filter(lambda x: x.goods.name == 'Artillery',
                           country.warehouses), None)
                weapons = warehouse.goods.value
                storage_capacity = warehouse.capacity

            elif name_unit == 'Anti-tank gun':
                warehouse = next(
                    filter(lambda x: x.goods.name == 'Anti-tank gun',
                           country.warehouses), None)
                weapons = warehouse.goods.value
                storage_capacity = warehouse.capacity

            elif name_unit == 'Air defense':
                warehouse = next(
                    filter(lambda x: x.goods.name == 'Air defense',
                           country.warehouses), None)
                weapons = warehouse.goods.value
                storage_capacity = warehouse.capacity

            elif name_unit == 'Tank':
                warehouse = next(
                    filter(lambda x: x.goods.name == 'Tanks',
                           country.warehouses), None)
                weapons = warehouse.goods.value
                storage_capacity = warehouse.capacity

            elif name_unit == 'Aviation':
                warehouse = next(
                    filter(lambda x: x.goods.name == 'Aviation',
                           country.warehouses), None)
                weapons = warehouse.goods.value
                storage_capacity = warehouse.capacity

            unit = army_units.filter(name=name_unit).first()
            unit_characteristic_view_list = [
                UnitCharacteristicView(
                    item.unit_name, item.attack_value * sum_attack_modifiers,
                    item.defence_value * sum_defence_modifiers)
                for item in unit.unit_characteristic.values()
            ]

            modifiers = [
                ModifierView(mod.value, mod.address_from + ' TO ATTACK')
                for mod in country.army.attack_modifiers
            ]
            modifiers.extend([
                ModifierView(mod.value, mod.address_from + ' TO DEFENCE')
                for mod in country.army.defence_modifiers
            ])

            army_card_view = ArmyCardView(
                name_unit, unit.link_img, army[name_unit], unit.need_peoples,
                unit.maintenance_price,
                unit.maintenance_price * army[name_unit],
                country.army.reserve_military_manpower, round(weapons, 2),
                storage_capacity, modifiers, unit_characteristic_view_list)
            army_view_list.append(army_card_view)
        finish = time.time()
        return army_view_list
Esempio n. 9
0
    def get_budget(self, user_id: str):
        start = time.time()
        user = User.objects(id=user_id).first()
        country = Country.objects(id=user.country.id).first()

        pop_taxes_profit = int(GameService().get_pop_taxes_profit(country))
        army_taxes_profit = int(GameService().get_army_taxes_profit(country))
        farms_taxes_profit = int(GameService().get_farms_taxes_profit(country))
        mines_taxes_profit = int(GameService().get_mines_taxes_profit(country))
        factories_taxes_profit = int(
            GameService().get_factories_taxes_profit(country))

        taxes_profit = pop_taxes_profit + farms_taxes_profit + mines_taxes_profit + factories_taxes_profit
        farms_profit = int(GameService().get_farms_production_profit(country))
        mines_profit = int(GameService().get_mines_production_profit(country))
        factories_profit = int(
            GameService().get_factories_production_profit(country))
        total_profit = taxes_profit + farms_profit + mines_profit + factories_profit

        pop_tax_card = TaxesCard(
            'population taxes', country.budget.population_taxes,
            pop_taxes_profit, [
                ModifierView(round(mod.value, 2), mod.address_from)
                for mod in country.population.modifiers
            ])
        army_views_modifiers = [
            ModifierView(round(mod.value, 2), 'to attack, ' + mod.address_from)
            for mod in country.army.attack_modifiers
        ]
        army_views_modifiers.extend([
            ModifierView(round(mod.value, 2),
                         'to defence, ' + mod.address_from)
            for mod in country.army.defence_modifiers
        ])
        army_tax_card = TaxesCard('army taxes', country.budget.military_taxes,
                                  army_taxes_profit, army_views_modifiers)
        farms_tax_card = TaxesCard(
            'farms taxes', country.budget.farms_taxes, farms_taxes_profit, [
                ModifierView(round(mod.value, 2), mod.address_from)
                for mod in country.industry_modifiers
                if mod.address_to == 'farms' or mod.address_to == 'industry'
            ])
        mines_tax_card = TaxesCard(
            'mines taxes', country.budget.mines_taxes, mines_taxes_profit, [
                ModifierView(round(mod.value, 2), mod.address_from)
                for mod in country.industry_modifiers
                if mod.address_to == 'mines' or mod.address_to == 'industry'
            ])
        factories_tax_card = TaxesCard(
            'factories taxes', country.budget.factories_taxes,
            factories_taxes_profit, [
                ModifierView(round(mod.value, 2), mod.address_from)
                for mod in country.industry_modifiers if
                mod.address_to == 'factories' or mod.address_to == 'industry'
            ])

        budget_view = BudgetView(int(country.budget.money), taxes_profit,
                                 farms_profit, mines_profit, factories_profit,
                                 country.budget.military_expenses,
                                 total_profit, pop_tax_card, army_tax_card,
                                 farms_tax_card, mines_tax_card,
                                 factories_tax_card)

        finish = time.time()
        return budget_view