Пример #1
0
    def setUp(self):
        super(PrototypeTests, self).setUp()
        current_time = TimePrototype.get_current_time()
        current_time.increment_turn()

        self.persons_changed_at_turn = TimePrototype.get_current_turn_number()

        self.p1, self.p2, self.p3 = create_test_map()

        self.person = create_person(self.p1, PERSON_STATE.IN_GAME)

        result, account_id, bundle_id = register_user('test_user1',
                                                      '*****@*****.**',
                                                      '111111')
        self.hero_1 = HeroPrototype.get_by_account_id(account_id)

        result, account_id, bundle_id = register_user('test_user2',
                                                      '*****@*****.**',
                                                      '111111')
        self.hero_2 = HeroPrototype.get_by_account_id(account_id)

        result, account_id, bundle_id = register_user('test_user3',
                                                      '*****@*****.**',
                                                      '111111')
        self.hero_3 = HeroPrototype.get_by_account_id(account_id)

        current_time = TimePrototype.get_current_time()
        current_time.increment_turn()
Пример #2
0
    def test_push_power(self):
        self.place.push_power(0, 10)
        self.assertEqual(self.place.power, 10)

        TimePrototype.get_current_time().increment_turn()
        self.place.push_power(1, 1)
        self.assertEqual(self.place.power,
                         1 + 10*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH-1).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH-1, 100)
        self.assertEqual(self.place.power,
                         100 + 10*1.0/places_settings.POWER_HISTORY_LENGTH + 2.0/places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH, 1000)
        self.assertEqual(self.place.power,
                         1000 + 100*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH + 1.0/places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH+1).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH+1, 10000)
        self.assertEqual(self.place.power,
                         10000 +
                         1000*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH +
                         100*float(places_settings.POWER_HISTORY_LENGTH-2)/places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH+2).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH+2, 100000)
        self.assertEqual(round(self.place.power, 5),
                         round(100000 +
                               10000*float(places_settings.POWER_HISTORY_LENGTH-1)/places_settings.POWER_HISTORY_LENGTH +
                               1000*float(places_settings.POWER_HISTORY_LENGTH-2)/places_settings.POWER_HISTORY_LENGTH +
                               100*float(places_settings.POWER_HISTORY_LENGTH-3)/places_settings.POWER_HISTORY_LENGTH, 5) )
Пример #3
0
    def setUp(self):
        super(TestPrototypeEnd, self).setUp()

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator.get_test_name('new_name_1'))
        self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')

        self.bill.state = relations.BILL_STATE.ACCEPTED

        TimePrototype.get_current_time().increment_turn()
Пример #4
0
    def setUp(self):
        super(TestPrototypeEnd, self).setUp()

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted')

        self.bill.state = relations.BILL_STATE.ACCEPTED

        TimePrototype.get_current_time().increment_turn()
Пример #5
0
    def test_increment_turn(self):
        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 0)

        time.increment_turn()
        self.assertEqual(time.turn_number, 1)
        time.save()

        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 1)
Пример #6
0
    def test_increment_turn(self):
        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 0)

        time.increment_turn()
        self.assertEqual(time.turn_number, 1)
        time.save()

        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 1)
Пример #7
0
    def test_creation(self):
        Setting.objects.all().delete()
        settings.refresh()

        settings_number = Setting.objects.all().count()
        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 0)
        self.assertEqual(Setting.objects.all().count(), settings_number + 1)
        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 0)
        self.assertEqual(Setting.objects.all().count(), settings_number + 1)
Пример #8
0
    def test_creation(self):
        Setting.objects.all().delete()
        settings.refresh()

        settings_number = Setting.objects.all().count()
        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 0)
        self.assertEqual(Setting.objects.all().count(), settings_number+1)
        time = TimePrototype.get_current_time()
        self.assertEqual(time.turn_number, 0)
        self.assertEqual(Setting.objects.all().count(), settings_number+1)
Пример #9
0
    def test_move_out_game(self):
        self.assertEqual(self.person.place.persons_changed_at_turn, self.persons_changed_at_turn)

        TimePrototype.get_current_time().increment_turn()

        current_time = datetime.datetime.now()
        self.assertTrue(self.person.out_game_at < current_time)
        self.assertEqual(self.person.state, PERSON_STATE.IN_GAME)
        self.person.move_out_game()
        self.assertTrue(self.person.out_game_at > current_time)
        self.assertEqual(self.person.state, PERSON_STATE.OUT_GAME)

        self.assertEqual(self.person.place.persons_changed_at_turn, TimePrototype.get_current_turn_number())
Пример #10
0
    def test_move_out_game(self):
        self.assertEqual(self.person.place.persons_changed_at_turn,
                         self.persons_changed_at_turn)

        TimePrototype.get_current_time().increment_turn()

        current_time = datetime.datetime.now()
        self.assertTrue(self.person.out_game_at < current_time)
        self.assertEqual(self.person.state, PERSON_STATE.IN_GAME)
        self.person.move_out_game()
        self.assertTrue(self.person.out_game_at > current_time)
        self.assertEqual(self.person.state, PERSON_STATE.OUT_GAME)

        self.assertEqual(self.person.place.persons_changed_at_turn,
                         TimePrototype.get_current_turn_number())
Пример #11
0
    def test_user_form__move_delay(self):
        data = {'caption': 'caption-caption',
                'rationale': 'rationale',
                'chronicle_on_accepted': 'chronicle-on-accepted',
                'person': self.person_2.id,
                'new_place': self.place3.id}

        form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id)
        self.assertFalse(form.is_valid())

        TimePrototype.get_current_time().increment_turn()

        form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id)

        self.assertTrue(form.is_valid())
Пример #12
0
    def test_no_stop_when_quest_required_replane(self):

        self.action_idl.percents = 0.0

        self.assertFalse(self.action_trade.replane_required)

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        self.action_trade.percents_barier = 2

        self.assertEqual(self.hero.bag.occupation, 2)

        current_time = TimePrototype.get_current_time()

        self.storage.process_turn()

        self.assertEqual(self.hero.bag.occupation, 1)
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action, self.action_trade)

        self.action_trade.replane_required = True

        current_time.increment_turn()

        self.storage.process_turn(continue_steps_if_needed=False)
        self.assertEqual(self.hero.bag.occupation, 0)
        self.assertEqual(len(self.hero.actions.actions_list), 1)

        self.assertEqual(self.action_trade.state, self.action_trade.STATE.PROCESSED)
        self.assertEqual(self.hero.actions.current_action, self.action_idl)
Пример #13
0
    def test_sequence_move(self):

        current_time = TimePrototype.get_current_time()

        while self.hero.actions.current_action != self.action_idl:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.hero.position.road.point_1_id, self.p2.id)
        self.assertEqual(self.hero.position.road.point_2_id, self.p3.id)

        real_percents = None

        prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.p1, break_at=0.9)
        while self.hero.actions.current_action != self.action_idl:
            real_percents = self.hero.actions.current_action.percents
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(round(real_percents, 1), 0.9)

        self.assertEqual(self.hero.position.road.point_1_id, self.p1.id)
        self.assertEqual(self.hero.position.road.point_2_id, self.p2.id)

        prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.p2)
        while self.hero.position.place is None or self.hero.position.place.id != self.p2.id:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE)
        self.storage._test_save()
Пример #14
0
def form_game_info(account=None, is_own=False, client_turns=None):
    from the_tale.accounts.prototypes import AccountPrototype
    from the_tale.game.prototypes import GameState
    from the_tale.game.pvp.prototypes import Battle1x1Prototype

    game_time = TimePrototype.get_current_time()

    data = {'mode': 'pve',
            'turn': game_time.ui_info(),
            'game_state': GameState.state().value,
            'map_version': map_info_storage.version,
            'account': None,
            'enemy': None }

    if account:
        battle = Battle1x1Prototype.get_by_account_id(account.id)
        data['account'] = _form_game_account_info(game_time,
                                                  account,
                                                  in_pvp_queue=False if battle is None else battle.state.is_WAITING,
                                                  is_own=is_own,
                                                  client_turns=client_turns)

        if battle and battle.state.is_PROCESSING:
            data['mode'] = 'pvp'
            data['enemy'] = _form_game_account_info(game_time,
                                                    AccountPrototype.get_by_id(battle.enemy_id),
                                                    in_pvp_queue=False,
                                                    is_own=False,
                                                    client_turns=client_turns)

    return data
 def _end_battle(self, hero_1_health, hero_2_health):
     self.hero_1.health = hero_1_health
     self.hero_2.health = hero_2_health
     current_time = TimePrototype.get_current_time()
     self.meta_action_battle.process()
     current_time.increment_turn()
     self.meta_action_battle.process()
Пример #16
0
    def test_sync_persons_add_new_person__force_when_zero_persons(self):
        TimePrototype.get_current_time().increment_turn()

        self.assertEqual(self.place.persons_changed_at_turn, 0)
        self.assertFalse(self.place.can_add_person)

        old_persons = self.place.persons

        for person in self.place.persons:
            person.move_out_game()

        self.place.sync_persons(force_add=False)

        self.assertEqual(self.place.persons_changed_at_turn, TimePrototype.get_current_turn_number())
        self.assertEqual(len(self.place.persons), 1)
        self.assertFalse(self.place.persons[0] in old_persons)
Пример #17
0
    def quest_test_method(self):

        # defends from first quest rule
        self.hero.statistics.change_quests_done(1)
        heroes_logic.save_hero(self.hero)

        current_time = TimePrototype.get_current_time()

        test_upgrade_equipment = random.randint(
            0, 1)  # test child quest or upgrade equipment for SearchSmith

        while self.hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests:
            if quest == SearchSmith and test_upgrade_equipment:
                self.hero.money = QuestPrototype.upgrade_equipment_cost(
                    self.hero) * 2
                self.hero.next_spending = ITEMS_OF_EXPENDITURE.INSTANT_HEAL

            self.storage.process_turn()
            current_time.increment_turn()

        # test if quest is serializable
        s11n.to_json(self.hero.quests.current_quest.serialize())

        self.complete_quest()

        self.assertEqual(self.hero.actions.current_action.TYPE,
                         ActionIdlenessPrototype.TYPE)

        if quest == SearchSmith and test_upgrade_equipment:
            self.assertTrue(
                self.hero.statistics.money_spend_for_artifacts > 0
                or self.hero.statistics.money_spend_for_sharpening > 0)
Пример #18
0
    def test_processed(self):
        current_time = TimePrototype.get_current_time()

        self.assertEqual(self.hero.journal.messages_number(), 2)

        with self.check_calls_count("the_tale.game.heroes.logic.push_message_to_diary", 0):
            self.storage.process_turn()

            current_time.increment_turn()

            self.assertEqual(self.hero.journal.messages_number(), 3)

            self.storage.process_turn()
            current_time.increment_turn()

            self.assertEqual(self.hero.journal.messages_number(), 4)

            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

            self.assertEqual(self.hero.journal.messages_number(), 5)

        self.assertTrue(self.hero.actions.current_action.TYPE.is_IDLENESS)

        self.storage._test_save()
Пример #19
0
    def test_sell_and_continue(self):
        old_money = self.hero.money

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        self.assertEqual(self.hero.bag.occupation, 2)

        self.action_trade.percents_barier = 2

        current_time = TimePrototype.get_current_time()

        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action, self.action_trade)
        self.assertEqual(self.hero.bag.occupation, 1)

        self.assertTrue(self.hero.money > old_money)

        old_money = self.hero.money

        current_time.increment_turn()

        self.storage.process_turn(continue_steps_if_needed=False)
        self.assertEqual(len(self.hero.actions.actions_list), 1)
        self.assertEqual(self.hero.actions.current_action, self.action_idl)

        self.assertEqual(self.hero.bag.occupation, 0)

        self.assertTrue(self.hero.money > old_money)
        self.storage._test_save()
Пример #20
0
def form_game_info(account=None, is_own=False, client_turns=None):
    from the_tale.accounts.prototypes import AccountPrototype
    from the_tale.game.prototypes import GameState
    from the_tale.game.pvp.prototypes import Battle1x1Prototype

    game_time = TimePrototype.get_current_time()

    data = {'mode': 'pve',
            'turn': game_time.ui_info(),
            'game_state': GameState.state().value,
            'map_version': map_info_storage.version,
            'account': None,
            'enemy': None }

    if account:
        battle = Battle1x1Prototype.get_by_account_id(account.id)
        data['account'] = _form_game_account_info(game_time,
                                                  account,
                                                  in_pvp_queue=False if battle is None else battle.state.is_WAITING,
                                                  is_own=is_own,
                                                  client_turns=client_turns)

        if battle and battle.state.is_PROCESSING:
            data['mode'] = 'pvp'
            data['enemy'] = _form_game_account_info(game_time,
                                                    AccountPrototype.get_by_id(battle.enemy_id),
                                                    in_pvp_queue=False,
                                                    is_own=False,
                                                    client_turns=client_turns)

    return data
Пример #21
0
    def test_process_next_turn(self):

        time = TimePrototype.get_current_time()
        time.increment_turn()
        time.save()

        self.assertEqual(time.turn_number, 1)

        for i in xrange(c.MAP_SYNC_TIME - 1):
            self.worker.process_next_turn(time.turn_number)
            self.assertFalse(hasattr(self.worker, "_data_synced"))

            if time.turn_number < bills_settings.BILLS_PROCESS_INTERVAL / c.TURN_DELTA:
                self.assertFalse(hasattr(self.worker, "_bills_applied"))
            else:
                self.assertEqual(
                    self.worker._bills_applied,
                    time.turn_number / (bills_settings.BILLS_PROCESS_INTERVAL / c.TURN_DELTA),
                )

            time.increment_turn()
            time.save()

        self.worker.process_next_turn(time.turn_number)
        self.assertTrue(self.worker._data_synced)
Пример #22
0
    def test_stop_when_quest_required_replane(self):

        self.action_idl.percents = 0.0

        self.assertFalse(self.action_trade.replane_required)

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        self.action_trade.percents_barier = 2

        self.assertEqual(self.hero.bag.occupation, 2)

        current_time = TimePrototype.get_current_time()

        self.storage.process_turn()

        self.assertEqual(self.hero.bag.occupation, 1)
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action, self.action_trade)

        self.action_trade.replane_required = True

        current_time.increment_turn()

        self.storage.process_turn(continue_steps_if_needed=False)
        self.assertEqual(self.hero.bag.occupation, 1)
        self.assertEqual(len(self.hero.actions.actions_list), 1)

        self.assertEqual(self.action_trade.state, self.action_trade.STATE.PROCESSED)
        self.assertEqual(self.hero.actions.current_action, self.action_idl)
Пример #23
0
    def test_sell_and_continue(self):
        old_money = self.hero.money

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)
        self.hero.bag.put_artifact(artifact)

        self.assertEqual(self.hero.bag.occupation, 2)

        self.action_trade.percents_barier = 2

        current_time = TimePrototype.get_current_time()

        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action, self.action_trade)
        self.assertEqual(self.hero.bag.occupation, 1)

        self.assertTrue(self.hero.money > old_money)

        old_money = self.hero.money

        current_time.increment_turn()

        self.storage.process_turn(continue_steps_if_needed=False)
        self.assertEqual(len(self.hero.actions.actions_list), 1)
        self.assertEqual(self.hero.actions.current_action, self.action_idl)

        self.assertEqual(self.hero.bag.occupation, 0)

        self.assertTrue(self.hero.money > old_money)
        self.storage._test_save()
Пример #24
0
    def test_not_enough_voices_percents(self):

        current_time = TimePrototype.get_current_time()
        current_time.increment_turn()
        current_time.increment_turn()

        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill,
                             relations.VOTE_TYPE.REFRAINED)

        self.assertEqual(Post.objects.all().count(), 1)

        with mock.patch(
                'the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method'
        ) as cmd_run_account_method:
            self.assertFalse(self.bill.apply())

        self.assertEqual(cmd_run_account_method.call_count, 0)
        self.assertTrue(self.bill.state.is_REJECTED)

        self.assertEqual(Post.objects.all().count(), 2)

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_REJECTED)

        places_storage.sync(force=True)

        self.place1.sync_parameters()
        self.assertEqual(self.place1.stability, 1.0)

        self.assertEqual(bill.applyed_at_turn, current_time.turn_number)

        self.check_place(self.place1.id, self.place1.name,
                         self.place1.utg_name.forms)
Пример #25
0
    def test_lighting(self):
        current_time = TimePrototype.get_current_time()
        action_battle = actions_prototypes.ActionBattlePvE1x1Prototype.create(
            hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero))

        current_time.increment_turn()
        self.storage.process_turn()

        old_mob_health = action_battle.mob.health
        old_percents = action_battle.percents

        self.assertTrue(HELP_CHOICES.LIGHTING in action_battle.help_choices)

        with mock.patch(
                'the_tale.game.actions.prototypes.ActionBase.get_help_choice',
                lambda x: HELP_CHOICES.LIGHTING):
            with self.check_delta(lambda: self.hero.statistics.help_count, 1):
                self.assertEqual(self.ability.use(**self.use_attributes),
                                 (ComplexChangeTask.RESULT.SUCCESSED,
                                  ComplexChangeTask.STEP.SUCCESS, ()))

        self.assertTrue(old_mob_health > action_battle.mob.health)
        self.assertEqual(self.hero.actions.current_action.percents,
                         action_battle.percents)
        self.assertTrue(old_percents < action_battle.percents)
Пример #26
0
 def _end_battle(self, hero_1_health, hero_2_health):
     self.hero_1.health = hero_1_health
     self.hero_2.health = hero_2_health
     current_time = TimePrototype.get_current_time()
     self.meta_action_battle.process()
     current_time.increment_turn()
     self.meta_action_battle.process()
Пример #27
0
    def test_sequence_move(self):

        current_time = TimePrototype.get_current_time()

        while self.hero.actions.current_action != self.action_idl:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.hero.position.road.point_1_id, self.p2.id)
        self.assertEqual(self.hero.position.road.point_2_id, self.p3.id)

        real_percents = None

        prototypes.ActionMoveToPrototype.create(hero=self.hero,
                                                destination=self.p1,
                                                break_at=0.9)
        while self.hero.actions.current_action != self.action_idl:
            real_percents = self.hero.actions.current_action.percents
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(round(real_percents, 1), 0.9)

        self.assertEqual(self.hero.position.road.point_1_id, self.p1.id)
        self.assertEqual(self.hero.position.road.point_2_id, self.p2.id)

        prototypes.ActionMoveToPrototype.create(hero=self.hero,
                                                destination=self.p2)
        while self.hero.position.place is None or self.hero.position.place.id != self.p2.id:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.hero.actions.current_action.TYPE,
                         prototypes.ActionInPlacePrototype.TYPE)
        self.storage._test_save()
Пример #28
0
def get_power_points():

    month = TimePrototype.get_current_time().game_time.month_record

    points = []

    points = [
        _default_temperature_points(delta={
            MONTHS.COLD: -0.1,
            MONTHS.HOT: 0.1
        }.get(month, 0)),
        _default_wetness_points(delta={
            MONTHS.DRY: -0.1,
            MONTHS.CRUDE: 0.1
        }.get(month, 0)),
        _default_vegetation_points(),
        _default_soil_points()
    ]

    for place in places_storage.all():
        points.extend(get_place_power_points(place))
        for race in RACE.records:
            points.extend(get_place_race_power_points(place, race))

    for building in buildings_storage.all():
        points.extend(get_building_power_points(building))

    return points
Пример #29
0
    def test_not_enough_voices_percents(self):

        current_time = TimePrototype.get_current_time()
        current_time.increment_turn()
        current_time.increment_turn()

        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.REFRAINED)

        self.assertEqual(Post.objects.all().count(), 1)

        with self.check_not_changed(lambda: self.place1.attrs.stability):
            with mock.patch('the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method') as cmd_run_account_method:
                self.assertFalse(self.bill.apply())

            self.assertEqual(cmd_run_account_method.call_count, 0)
            self.assertTrue(self.bill.state.is_REJECTED)

            self.assertEqual(Post.objects.all().count(), 2)

            bill = BillPrototype.get_by_id(self.bill.id)
            self.assertTrue(bill.state.is_REJECTED)

            places_storage.places.sync(force=True)

            self.place1.refresh_attributes()

        self.assertEqual(bill.applyed_at_turn, current_time.turn_number)

        self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
Пример #30
0
    def test_teleport(self):
        move_place = self.p3
        if move_place.id == self.hero.position.place.id:
            move_place = self.p1

        current_time = TimePrototype.get_current_time()

        action_move = actions_prototypes.ActionMoveToPrototype.create(
            hero=self.hero, destination=move_place)

        current_time.increment_turn()
        self.storage.process_turn()

        old_road_percents = self.hero.position.percents
        old_percents = action_move.percents

        with mock.patch(
                'the_tale.game.actions.prototypes.ActionBase.get_help_choice',
                lambda x: HELP_CHOICES.TELEPORT):
            with self.check_delta(lambda: self.hero.statistics.help_count, 1):
                self.assertEqual(self.ability.use(**self.use_attributes),
                                 (ComplexChangeTask.RESULT.SUCCESSED,
                                  ComplexChangeTask.STEP.SUCCESS, ()))

        self.assertTrue(old_road_percents < self.hero.position.percents)
        self.assertTrue(old_percents < action_move.percents)
        self.assertEqual(self.hero.actions.current_action.percents,
                         action_move.percents)
Пример #31
0
    def test_teleport__length_is_0(self):

        current_time = TimePrototype.get_current_time()

        self.storage.process_turn(continue_steps_if_needed=False)

        self.action_move.length = 0
        self.action_move.percents = 1
        self.hero.position.percents = 1

        with self.check_not_changed(lambda: self.action_move.percents):
            self.action_move.teleport(1, create_inplace_action=True)

        self.assertEqual(self.action_move.state,
                         self.action_move.STATE.PROCESSED)

        self.assertTrue(self.action_move.updated)

        current_time.increment_turn()

        self.storage.process_turn(continue_steps_if_needed=False)

        self.assertEqual(self.hero.position.place.id, self.p2.id)

        self.storage._test_save()
Пример #32
0
    def quest_test_method(self):

        # defends from first quest rule
        self.hero.statistics.change_quests_done(1)
        self.hero.save()

        current_time = TimePrototype.get_current_time()

        test_upgrade_equipment = random.randint(0, 1) # test child quest or upgrade equipment for SearchSmith

        while self.hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests:
            if quest == SearchSmith and test_upgrade_equipment:
                self.hero._model.money = QuestPrototype.upgrade_equipment_cost(self.hero) * 2
                self.hero._model.next_spending = ITEMS_OF_EXPENDITURE.INSTANT_HEAL

            self.storage.process_turn()
            current_time.increment_turn()

        # test if quest is serializable
        s11n.to_json(self.hero.quests.current_quest.serialize())

        self.complete_quest()

        self.assertEqual(self.hero.actions.current_action.TYPE, ActionIdlenessPrototype.TYPE)

        if quest == SearchSmith and test_upgrade_equipment:
            self.assertTrue(self.hero.statistics.money_spend_for_artifacts > 0 or
                            self.hero.statistics.money_spend_for_sharpening > 0)
Пример #33
0
    def test_process_next_turn_with_skipped_hero(self):

        current_time = TimePrototype.get_current_time()
        current_time.increment_turn()
        current_time.save()

        self.worker.process_register_account(self.account.id)

        self.worker.storage.skipped_heroes.add(self.hero.id)

        with mock.patch(
                'the_tale.game.actions.prototypes.ActionBase.process_turn'
        ) as action_process_turn:
            with mock.patch(
                    'the_tale.game.workers.supervisor.Worker.cmd_account_release_required'
            ) as release_required_counter:
                with mock.patch('the_tale.game.heroes.logic.save_hero'
                                ) as save_counter:
                    with mock.patch(
                            'the_tale.game.conf.game_settings.SAVED_UNCACHED_HEROES_FRACTION',
                            0):
                        self.worker.process_next_turn(
                            TimePrototype.get_current_turn_number())

        self.assertEqual(action_process_turn.call_count, 0)
        self.assertEqual(save_counter.call_count, 1)
        self.assertEqual(release_required_counter.call_count, 1)
Пример #34
0
    def test_processed(self):
        current_time = TimePrototype.get_current_time()

        self.assertEqual(self.hero.journal.messages_number(), 2)

        with self.check_calls_count(
                'the_tale.game.heroes.logic.push_message_to_diary', 0):
            self.storage.process_turn()

            current_time.increment_turn()

            self.assertEqual(self.hero.journal.messages_number(), 3)

            self.storage.process_turn()
            current_time.increment_turn()

            self.assertEqual(self.hero.journal.messages_number(), 4)

            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

            self.assertEqual(self.hero.journal.messages_number(), 5)

        self.assertTrue(self.hero.actions.current_action.TYPE.is_IDLENESS)

        self.storage._test_save()
Пример #35
0
    def test_move_change_place_coordinates_and_back(self):

        current_time = TimePrototype.get_current_time()

        while len(self.hero.actions.actions_list) != 1:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.hero.actions.current_action.TYPE,
                         prototypes.ActionIdlenessPrototype.TYPE)
        self.assertTrue(self.hero.position.is_walking
                        or self.hero.position.place)  # can end in start place

        prototypes.ActionMoveNearPlacePrototype.create(hero=self.hero,
                                                       place=self.p1,
                                                       back=True)
        self.p1.x = self.p1.x + 1
        self.p1.y = self.p1.y + 1
        places_logic.save_place(self.p1)

        while self.hero.position.place is None or self.hero.position.place.id != self.p1.id:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.hero.actions.current_action.TYPE,
                         prototypes.ActionInPlacePrototype.TYPE)
        self.assertTrue(not self.hero.position.is_walking)
        self.storage._test_save()
Пример #36
0
    def test_full_battle__with_companion(self):
        battle_ability = random.choice([
            ability for ability in effects.ABILITIES.records
            if isinstance(ability.effect, effects.BaseBattleAbility)
        ])

        companion_record = companions_storage.companions.enabled_companions(
        ).next()
        companion_record.abilities = container.Container(
            start=(battle_ability, ))

        companion = companions_logic.create_companion(companion_record)
        self.hero.set_companion(companion)

        self.hero.reset_accessors_cache()

        current_time = TimePrototype.get_current_time()

        while len(self.hero.actions.actions_list) != 1:
            self.storage.process_turn()
            current_time.increment_turn()

        self.assertTrue(self.action_idl.leader)

        self.storage._test_save()
Пример #37
0
    def test_push_power(self):
        self.place.push_power(0, 10)
        self.assertEqual(self.place.power, 10)

        TimePrototype.get_current_time().increment_turn()
        self.place.push_power(1, 1)
        self.assertEqual(
            self.place.power,
            1 + 10 * float(places_settings.POWER_HISTORY_LENGTH - 1) /
            places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH - 1).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH - 1, 100)
        self.assertEqual(
            self.place.power,
            100 + 10 * 1.0 / places_settings.POWER_HISTORY_LENGTH +
            2.0 / places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH, 1000)
        self.assertEqual(
            self.place.power,
            1000 + 100 * float(places_settings.POWER_HISTORY_LENGTH - 1) /
            places_settings.POWER_HISTORY_LENGTH +
            1.0 / places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH + 1).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH + 1, 10000)
        self.assertEqual(
            self.place.power,
            10000 + 1000 * float(places_settings.POWER_HISTORY_LENGTH - 1) /
            places_settings.POWER_HISTORY_LENGTH +
            100 * float(places_settings.POWER_HISTORY_LENGTH - 2) /
            places_settings.POWER_HISTORY_LENGTH)

        TimePrototype(places_settings.POWER_HISTORY_LENGTH + 2).save()
        self.place.push_power(places_settings.POWER_HISTORY_LENGTH + 2, 100000)
        self.assertEqual(
            round(self.place.power, 5),
            round(
                100000 +
                10000 * float(places_settings.POWER_HISTORY_LENGTH - 1) /
                places_settings.POWER_HISTORY_LENGTH +
                1000 * float(places_settings.POWER_HISTORY_LENGTH - 2) /
                places_settings.POWER_HISTORY_LENGTH +
                100 * float(places_settings.POWER_HISTORY_LENGTH - 3) /
                places_settings.POWER_HISTORY_LENGTH, 5))
Пример #38
0
    def complete_quest(self):
        current_time = TimePrototype.get_current_time()

        while not self.action_idl.leader:
            self.storage.process_turn()
            current_time.increment_turn()

            self.hero.ui_info(actual_guaranteed=True) # test if ui info formed correctly
Пример #39
0
    def complete_quest(self):
        current_time = TimePrototype.get_current_time()

        while not self.action_idl.leader:
            self.storage.process_turn()
            current_time.increment_turn()

            self.hero.ui_info(actual_guaranteed=True) # test if ui info formed correctly
Пример #40
0
    def test_sync_persons_add_new_person__force_when_zero_persons(self):
        TimePrototype.get_current_time().increment_turn()

        self.assertEqual(self.place.persons_changed_at_turn, 0)
        self.assertFalse(self.place.can_add_person)

        old_persons = self.place.persons

        for person in self.place.persons:
            person.move_out_game()

        self.place.sync_persons(force_add=False)

        self.assertEqual(self.place.persons_changed_at_turn,
                         TimePrototype.get_current_turn_number())
        self.assertEqual(len(self.place.persons), 1)
        self.assertFalse(self.place.persons[0] in old_persons)
Пример #41
0
    def test_percents_consistency(self):
        current_time = TimePrototype.get_current_time()

        # just test that quest will be ended
        while not self.action_idl.leader:
            self.storage.process_turn()
            current_time.increment_turn()
            self.assertEqual(self.storage.tests_get_last_action().percents, self.hero.last_action_percents)
    def test_companion_healing_by_hero__not_healed(self):

        current_time = TimePrototype.get_current_time()
        self.hero.companion.health = 1

        with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL):
            self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()
Пример #43
0
    def test_full(self):

        current_time = TimePrototype.get_current_time()

        while not self.action_idl.leader:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.storage._test_save()
Пример #44
0
def update_map(index):

    generator = WorldInfoPrototype.get_by_id(map_info_storage.item.world_id).generator

    generator.clear_power_points()
    generator.clear_biomes()

    if generator.w != map_settings.WIDTH or generator.h != map_settings.HEIGHT:
        dx, dy = generator.resize(map_settings.WIDTH, map_settings.HEIGHT)
        places_storage.places.shift_all(dx, dy)
        places_storage.buildings.shift_all(dx, dy)

    for point in get_power_points():
        generator.add_power_point(point)

    for terrain in TERRAIN.records:
        generator.add_biom(Biom(id_=terrain))

    generator.do_step()

    biomes_map = generator.get_biomes_map()

    time = TimePrototype.get_current_time()

    draw_info = get_draw_info(biomes_map)

    terrain = []
    for y in range(0, generator.h):
        row = []
        terrain.append(row)
        for x in range(0, generator.w):
            row.append(biomes_map[y][x].id)

    map_info_storage.set_item(MapInfoPrototype.create(turn_number=time.turn_number,
                                                      width=generator.w,
                                                      height=generator.h,
                                                      terrain=terrain,
                                                      world=WorldInfoPrototype.create_from_generator(generator)))

    MapInfoPrototype.remove_old_infos()

    raw_draw_info = []
    for row in draw_info:
        raw_draw_info.append([])
        for cell in row:
            raw_draw_info[-1].append(cell.get_sprites())

    data = {'width': generator.w,
            'height': generator.h,
            'map_version': map_info_storage.version,
            'format_version': '0.1',
            'draw_info': raw_draw_info,
            'places': dict( (place.id, place.map_info() ) for place in places_storage.places.all() ),
            # 'buildings': dict( (building.id, building.map_info() ) for building in buildings_storage.all() ),
            'roads': dict( (road.id, road.map_info() ) for road in roads_storage.all()) }

    models.MapRegion.objects.create(turn_number=time.turn_number, data=data)
Пример #45
0
    def test_post_created_at_turn(self):
        current_turn = TimePrototype.get_current_time()

        current_turn.increment_turn()
        current_turn.increment_turn()

        ThreadPrototype.create(self.subcategory, 'thread-2-caption', self.account, 'thread-2-text')

        self.assertEqual(PostPrototype._db_latest().created_at_turn, current_turn.turn_number)
Пример #46
0
    def test_created_at_turn(self):
        current_turn = TimePrototype.get_current_time()

        current_turn.increment_turn()
        current_turn.increment_turn()

        post = PostPrototype.create(thread=self.thread, author=self.account, text='post-1-text')

        self.assertEqual(post.created_at_turn, current_turn.turn_number)
Пример #47
0
    def test_full(self):

        current_time = TimePrototype.get_current_time()

        while not self.action_idl.leader:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.storage._test_save()
Пример #48
0
    def test_approved(self):
        current_time = TimePrototype.get_current_time()
        current_time.increment_turn()
        current_time.increment_turn()
        current_time.increment_turn()

        VotePrototype.create(self.account2, self.bill,
                             relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)
        VotePrototype.create(self.account4, self.bill,
                             relations.VOTE_TYPE.REFRAINED)

        ##################################
        # set name forms

        data = self.bill.user_form_initials
        data.update(
            linguistics_helpers.get_word_post_data(self.bill.data.name_forms,
                                                   prefix='name'))
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)
        ##################################

        self.assertEqual(Post.objects.all().count(), 1)

        with mock.patch(
                'the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method'
        ) as cmd_run_account_method:
            self.assertTrue(self.bill.apply())

        self.assertEqual(cmd_run_account_method.call_args_list, [
            mock.call(account_id=self.bill.owner.id,
                      method_name=accounts_prototypes.AccountPrototype.
                      update_actual_bills.__name__,
                      data={})
        ])

        self.assertTrue(self.bill.state.is_ACCEPTED)

        self.assertEqual(Post.objects.all().count(), 2)

        bill = BillPrototype.get_by_id(self.bill.id)
        self.assertTrue(bill.state.is_ACCEPTED)

        places_storage.places.sync(force=True)

        self.place1.refresh_attributes()
        self.assertTrue(self.place1.attrs.stability < 1.0)

        self.assertEqual(bill.applyed_at_turn, current_time.turn_number)

        self.check_place(self.place1.id, 'new_name_1-нс,ед,им',
                         self.bill.data.name_forms.forms)
Пример #49
0
    def test_buy_meal__from_moveto(self):
        prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.place_3)

        current_time = TimePrototype.get_current_time()

        with contextlib.nested( self.check_decreased(lambda: self.hero.money),
                                self.check_increased(lambda: self.hero.statistics.money_spend_for_companions)):
            while self.hero.actions.current_action.TYPE != prototypes.ActionInPlacePrototype.TYPE:
                current_time.increment_turn()
                self.storage.process_turn(continue_steps_if_needed=False)
Пример #50
0
    def test_full_move(self):

        current_time = TimePrototype.get_current_time()

        while self.hero.position.place is None or self.hero.position.place.id != self.p3.id:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE)
        self.storage._test_save()
Пример #51
0
    def check_companion_healing_by_hero(self, companion_type):

        current_time = TimePrototype.get_current_time()
        self.hero.companion.health = 1

        with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL+c.COMPANIONS_REGEN_BY_HERO):
            self.companion_record.type = companion_type
            self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()
    def test_companion_healing_by_hero__not_healed(self):

        current_time = TimePrototype.get_current_time()
        self.hero.companion.health = 1

        with self.check_delta(lambda: self.hero.companion.health,
                              c.COMPANIONS_HEALTH_PER_HEAL):
            self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()
Пример #53
0
    def test_lighting_when_mob_killed(self):
        current_time = TimePrototype.get_current_time()
        action_battle = actions_prototypes.ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero))

        current_time.increment_turn()
        self.storage.process_turn()

        action_battle.mob.health = 0

        self.assertFalse(HELP_CHOICES.LIGHTING in action_battle.help_choices)
    def test_corridor(self):

        # fill_empty_keys_with_fake_phrases(u'test_hero_level_companion')

        result, account_id, bundle_id = register_user(uuid.uuid4().hex) # pylint: disable=W0612
        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]

        self.set_hero_companion()

        current_time = TimePrototype.get_current_time()

        for level in xrange(1, 100):
            print
            print '-----------------------------------------------------------------------'
            print 'process level %d\texpected turns: %d\texpected days: %.2f' % (level, f.turns_on_lvl(level), f.time_on_lvl(level)/24)

            for i in xrange(f.turns_on_lvl(level)): # pylint: disable=W0612
                self.storage.process_turn()
                current_time.increment_turn()

                # simulate user behaviour on healing companion
                if self.hero.companion.health < self.hero.companion.max_health / 2:
                    self.hero.companion.health = self.hero.companion.max_health

            self.hero.randomized_level_up()


            exp_to_next_level = float(self.hero.experience) / f.exp_on_lvl(self.hero.level) * 100
            exp_from_expected = float(f.total_exp_to_lvl(self.hero.level)+self.hero.experience)/f.total_exp_to_lvl(level+1)*100
            exp_untaken = f.total_exp_to_lvl(level+1) - f.total_exp_to_lvl(self.hero.level) - self.hero.experience
            quests_untaken = float(exp_untaken) / f.experience_for_quest(c.QUEST_AREA_RADIUS)
            print u'hero level: %d\texp: %.2f%%\texp from expected: %.2f%% (%d exp, %.2f quests)\ttotal quests %d' % (self.hero.level,
                                                                                                                      exp_to_next_level,
                                                                                                                      exp_from_expected,
                                                                                                                      exp_untaken,
                                                                                                                      quests_untaken,
                                                                                                                      self.hero.statistics.quests_done)
            print u'abilities: %s' % ' '.join(u'%s-%d' % (ability_id, ability.level) for ability_id, ability in self.hero.abilities.abilities.items())
            print u'deaths: %d' % self.hero.statistics.pve_deaths

            total_gold = f.total_gold_at_lvl(self.hero.level)
            print u'total money: %d from expected %d (x%.2f)' % (self.hero.statistics.money_earned,
                                                                 total_gold,
                                                                 float(self.hero.statistics.money_earned) / total_gold if total_gold > 0 else 0)

            total_artifacts = int(f.total_time_for_lvl(self.hero.level) / 24 * c.ARTIFACTS_LOOT_PER_DAY )
            print u'total artifacts: %d from expected %d (x%.2f)' % (self.hero.statistics.artifacts_had,
                                                                     total_artifacts,
                                                                     float(self.hero.statistics.artifacts_had) / total_artifacts if total_artifacts > 0 else 0)
            print u'power: %r from expected %r' % (self.hero.power, Power.power_to_level(self.hero.preferences.archetype.power_distribution, self.hero.level))
            print u'power total: %d from expected %r (x%.2f)' % (self.hero.power.total(),
                                                                 Power.power_to_level(self.hero.preferences.archetype.power_distribution, self.hero.level).total(),
                                                                 float(self.hero.power.total()) / Power.power_to_level(self.hero.preferences.archetype.power_distribution, self.hero.level).total())
Пример #55
0
    def test_push_message(self):
        current_time = TimePrototype.get_current_time()

        self.messages.push_message(self.create_message('1'))
        self.messages.push_message(self.create_message('2'))

        current_time.increment_turn()

        self.messages.push_message(self.create_message('3'))

        self.assertEqual([msg.message for msg in self.messages.messages], ['1', '2', '3'])
Пример #56
0
    def test_full(self):

        current_time = TimePrototype.get_current_time()

        while len(self.hero.actions.actions_list) != 1:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertTrue(self.action_idl.leader)

        self.storage._test_save()
Пример #57
0
    def test_full_battle(self):

        current_time = TimePrototype.get_current_time()

        while len(self.hero.actions.actions_list) != 1:
            self.storage.process_turn()
            current_time.increment_turn()

        self.assertTrue(self.action_idl.leader)

        self.storage._test_save()