Пример #1
0
    def test_exclude__different_data(self):
        cards = []

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.iteritems(
        ):
            companions_logic.create_random_companion_record(
                '%s companion' % rarity,
                mode=companions_relations.MODE.AUTOMATIC,
                abilities=rarity_abilities,
                state=companions_relations.STATE.ENABLED)

        for i in xrange(len(relations.CARD_TYPE.records)):
            card = self.hero.cards.get_new_card(exclude=cards)
            cards.append(card)

        self.assertEqual(self.hero.cards.get_new_card(exclude=cards), None)

        cards[0].data = {'fake-data': True}
        self.assertEqual(cards[0].type,
                         self.hero.cards.get_new_card(exclude=cards).type)

        self.assertEqual(set(card.type for card in cards),
                         set(relations.CARD_TYPE.records))
Пример #2
0
    def test_exclude(self):
        cards = []

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items(
        ):
            companions_logic.create_random_companion_record(
                '%s companion' % rarity,
                mode=companions_relations.MODE.AUTOMATIC,
                abilities=rarity_abilities,
                state=companions_relations.STATE.ENABLED)

        for i in range(
                len([
                    card_type for card_type in relations.CARD_TYPE.records
                    if card_type.in_game
                ])):
            card = self.hero.cards.get_new_card(exclude=cards)
            cards.append(card)
            self.assertTrue(card.type.in_game)

        self.assertEqual(self.hero.cards.get_new_card(exclude=cards), None)

        self.assertEqual(
            set(card.type for card in cards),
            set(card_type for card_type in relations.CARD_TYPE.records
                if card_type.in_game))
Пример #3
0
    def test_exclude_not_allowrd_effects(self):
        effects = set()

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items():
            companions_logic.create_random_companion_record('%s companion' % rarity,
                                                            mode=companions_relations.MODE.AUTOMATIC,
                                                            abilities=rarity_abilities,
                                                            state=companions_relations.STATE.ENABLED)


        @classmethod
        def effect_availability(cls):
            return bool(cls.TYPE.value % 2)

        with mock.patch('the_tale.game.cards.effects.BaseEffect.available', effect_availability):
            with mock.patch('the_tale.game.cards.effects.GetCompanionBase.available', effect_availability):
                for i in range(10000):
                    effects.add(self.hero.cards.get_new_card().effect.TYPE)

        for effect_type in relations.CARD_TYPE.records:
            if effect_type.value % 2 == 0:
                self.assertNotIn(effect_type, effects)
Пример #4
0
    def test_exclude(self):
        created_cards = []

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items(
        ):
            companions_logic.create_random_companion_record(
                '%s companion' % rarity,
                mode=companions_relations.MODE.AUTOMATIC,
                abilities=rarity_abilities,
                state=companions_relations.STATE.ENABLED)

        for i in range(len([card_type for card_type in cards.CARD.records])):
            card = logic.create_card(allow_premium_cards=True,
                                     exclude=created_cards)
            created_cards.append(card)

        self.assertEqual(
            logic.create_card(allow_premium_cards=True, exclude=created_cards),
            None)

        self.assertEqual(set(card.type for card in created_cards),
                         set(card_type for card_type in cards.CARD.records))
Пример #5
0
    def setUp(self):
        super(GetCompanionCreateTests, self).setUp()
        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)

        self.hero = self.storage.accounts_to_heroes[self.account_1.id]

        self.disabled_companion = companions_logic.create_random_companion_record('disbled')
        self.manual_companion = companions_logic.create_random_companion_record('manual', mode=companions_relations.MODE.MANUAL)

        self.effect = effects.GetCompanionCommon()
Пример #6
0
    def _test_companion_death_speed(self):
        companion_record = logic.create_random_companion_record(
            'test companion',
            state=relations.STATE.ENABLED,
            dedication=relations.DEDICATION.BRAVE)  #,#,;
        companion = logic.create_companion(companion_record)
        self.hero.set_companion(companion)
        self.hero.preferences.set_companion_dedication(
            heroes_relations.COMPANION_DEDICATION.NORMAL)

        old_health = self.hero.companion.health

        while self.hero.companion:
            self.hero.companion.coherence = 50

            self.storage.process_turn()
            turn.increment()

            self.hero.randomized_level_up()

            if not self.hero.is_alive:
                if hasattr(self.hero.actions.current_action, 'fast_resurrect'):
                    self.hero.actions.current_action.fast_resurrect()

            if self.hero.companion:
                old_health = self.hero.companion.health
Пример #7
0
    def test_companion_exorcims__not_demon(self):

        self.companion_record = companions_logic.create_random_companion_record(
            'exorcist', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(
            companions_logic.create_companion(self.companion_record))

        not_demon_record = mobs_prototypes.MobRecordPrototype.create_random(
            'demon',
            type=mobs_relations.MOB_TYPE.random(
                exclude=(mobs_relations.MOB_TYPE.DEMON, )))
        not_demon = mobs_prototypes.MobPrototype(record_id=not_demon_record.id,
                                                 level=self.hero.level,
                                                 is_boss=False)

        self.hero.actions.pop_action()

        with self.check_delta(lambda: self.hero.statistics.pve_kills, 0):
            action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero,
                                                               mob=not_demon)

        self.assertEqual(action_battle.percents, 0.0)
        self.assertEqual(action_battle.state,
                         self.action_battle.STATE.BATTLE_RUNNING)

        self.storage.process_turn(continue_steps_if_needed=False)

        self.assertEqual(self.hero.actions.current_action, action_battle)
Пример #8
0
    def setUp(self):
        super(InPlaceActionCompanionLeaveTests, self).setUp()
        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.action_idl = self.hero.actions.current_action

        self.companion_record = companions_logic.create_random_companion_record('thief', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        self.hero.money = f.expected_gold_in_day(self.hero.level)

        self.hero.position.set_place(self.place_1)
        self.hero.position.update_previous_place()
        self.hero.position.set_place(self.place_2)

        self.artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.loot, 1, rarity=RARITY.NORMAL)
        self.hero.put_loot(self.artifact)

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

        self.hero.position.move_out_place()
Пример #9
0
    def test_politics_power_multiplier__all_effects(self):
        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.might = 1000

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero._model.level = 100

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.actual_bills.append(time.time())
            self.hero.actual_bills.append(time.time())

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.preferences.set_risk_level(
                relations.RISK_LEVEL.VERY_HIGH)

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.equipment.get(
                relations.EQUIPMENT_SLOT.PLATE
            ).record.special_effect = artifacts_relations.ARTIFACT_EFFECT.GREAT_POWER

        with self.check_increased(self.hero.politics_power_multiplier):
            companion_record = companions_logic.create_random_companion_record(
                name='test-companion',
                state=companions_relations.STATE.ENABLED,
                abilities=companions_abilities_container.Container(
                    start=(companions_effects.ABILITIES.KNOWN, )))
            companion = companions_logic.create_companion(companion_record)
            self.hero.set_companion(companion)

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.abilities.add(
                nonbattle_abilities.DIPLOMATIC.get_id(),
                level=len(nonbattle_abilities.DIPLOMATIC.POWER_MULTIPLIER))
Пример #10
0
    def test_politics_power_multiplier__all_effects(self):
        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.might = 1000

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.level = 100

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.actual_bills.append(time.time())
            self.hero.actual_bills.append(time.time())

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.preferences.set_risk_level(relations.RISK_LEVEL.VERY_HIGH)

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.equipment.get(relations.EQUIPMENT_SLOT.PLATE).record.special_effect = artifacts_relations.ARTIFACT_EFFECT.GREAT_POWER

        with self.check_increased(self.hero.politics_power_multiplier):
            companion_record = companions_logic.create_random_companion_record(name='test-companion',
                                                                               state=companions_relations.STATE.ENABLED,
                                                                               abilities=companions_abilities_container.Container(start=(companions_effects.ABILITIES.KNOWN,)))
            companion = companions_logic.create_companion(companion_record)
            self.hero.set_companion(companion)

        with self.check_increased(self.hero.politics_power_multiplier):
            self.hero.abilities.add(nonbattle_abilities.DIPLOMATIC.get_id(), level=len(nonbattle_abilities.DIPLOMATIC.POWER_MULTIPLIER))
Пример #11
0
    def setUp(self):
        super(GetCompanionCreateTests, self).setUp()
        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)

        self.hero = self.storage.accounts_to_heroes[self.account_1.id]

        self.disabled_companion = companions_logic.create_random_companion_record(
            'disbled')
        self.manual_companion = companions_logic.create_random_companion_record(
            'manual', mode=companions_relations.MODE.MANUAL)

        self.effect = effects.GetCompanionCommon()
Пример #12
0
    def test_simple(self):

        rarities = set()

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items():
            companions_logic.create_random_companion_record('%s companion' % rarity,
                                                            mode=companions_relations.MODE.AUTOMATIC,
                                                            abilities=rarity_abilities,
                                                            state=companions_relations.STATE.ENABLED)


        for i in range(len(relations.CARD_TYPE.records)*10):
            card = self.hero.cards.get_new_card()
            rarities.add(card.type.rarity)

        self.assertTrue(len(relations.CARD_TYPE.records) > len(set(card.type for card in self.hero.cards.all_cards())) / 2)
        self.assertEqual(rarities, set(relations.RARITY.records))
Пример #13
0
    def test_exclude(self):
        cards = []

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items():
            companions_logic.create_random_companion_record('%s companion' % rarity,
                                                            mode=companions_relations.MODE.AUTOMATIC,
                                                            abilities=rarity_abilities,
                                                            state=companions_relations.STATE.ENABLED)

        for i in range(len([card_type for card_type in relations.CARD_TYPE.records if card_type.in_game])):
            card = self.hero.cards.get_new_card(exclude=cards)
            cards.append(card)
            self.assertTrue(card.type.in_game)

        self.assertEqual(self.hero.cards.get_new_card(exclude=cards), None)

        self.assertEqual(set(card.type for card in cards), set(card_type for card_type in relations.CARD_TYPE.records if card_type.in_game))
Пример #14
0
    def setUp(self):
        super(GetCompanionMixin, self).setUp()
        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)

        self.hero = self.storage.accounts_to_heroes[self.account_1.id]

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items(
        ):
            companions_logic.create_random_companion_record(
                '%s companion' % rarity,
                mode=companions_relations.MODE.AUTOMATIC,
                abilities=rarity_abilities,
                state=companions_relations.STATE.ENABLED)

        self.card = self.CARD.effect.create_card(type=self.CARD,
                                                 available_for_auction=True)
Пример #15
0
    def test_choose_ability__additional_companion_abilities(self):
        from the_tale.game.heroes.habilities import ABILITIES
        from the_tale.game.companions.abilities import effects as companions_effects
        from the_tale.game.companions.abilities import container as abilities_container
        from the_tale.game.companions import logic as companions_logic
        from the_tale.game.companions import relations as companions_relations

        abilities = [
            ability for ability in companions_effects.ABILITIES.records
            if (isinstance(ability.effect, companions_effects.BaseBattleAbility
                           ) and ability.effect.ABILITY.get_id() != 'hit')
        ]
        companion_ability = random.choice(abilities)

        all_abilities = [
            ability(level=ability.MAX_LEVEL)
            for ability in list(ABILITIES.values())
            if ability.get_id() != companion_ability.effect.ABILITY.get_id()
        ]

        active_abilities = set(ability.get_id()
                               for ability in list(ABILITIES.values())
                               if ability.ACTIVATION_TYPE.is_ACTIVE)

        companion_record = companions_logic.create_random_companion_record(
            'battle',
            abilities=abilities_container.Container(
                start=(companion_ability, )),
            state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(
            companions_logic.create_companion(companion_record))
        self.hero.health = 1  # allow regeneration

        actor = battle.Actor(self.hero, BattleContext())

        chosen_abilities = set()

        # mock abilities modify_attribute instead of hereos, since we test correct work of it
        def modify_attribute(self, modifier, value):
            if modifier.is_ADDITIONAL_ABILITIES:
                return all_abilities
            return value

        with mock.patch(
                'the_tale.game.heroes.habilities.AbilitiesPrototype.modify_attribute',
                modify_attribute):
            for i in range(1000):
                chosen_abilities.add(actor.choose_ability().get_id())

        self.assertEqual(len(active_abilities), len(chosen_abilities) + 1)
        self.assertEqual(
            active_abilities -
            set([companion_ability.effect.ABILITY.get_id()]), chosen_abilities)
Пример #16
0
    def setUp(self):
        super().setUp()
        game_logic.create_test_map()
        tt_api.debug_clear_service()

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items():
            companions_logic.create_random_companion_record('%s companion' % rarity,
                                                            mode=companions_relations.MODE.AUTOMATIC,
                                                            abilities=rarity_abilities,
                                                            state=companions_relations.STATE.ENABLED)


        self.cards = [objects.Card(cards.CARD.KEEPERS_GOODS_COMMON, uid=uuid.uuid4()),
                      objects.Card(cards.CARD.ADD_GOLD_COMMON, uid=uuid.uuid4()),
                      objects.Card(cards.CARD.KEEPERS_GOODS_LEGENDARY, uid=uuid.uuid4()),
                      cards.CARD.GET_COMPANION_UNCOMMON.effect.create_card(cards.CARD.GET_COMPANION_UNCOMMON, available_for_auction=True),
                      objects.Card(cards.CARD.KEEPERS_GOODS_COMMON, uid=uuid.uuid4()),
                      objects.Card(cards.CARD.ADD_GOLD_COMMON, uid=uuid.uuid4())]
Пример #17
0
    def setUp(self):
        super(GetCompanionMixin, self).setUp()
        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)

        self.hero = self.storage.accounts_to_heroes[self.account_1.id]

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.items():
            companions_logic.create_random_companion_record('%s companion' % rarity,
                                                            mode=companions_relations.MODE.AUTOMATIC,
                                                            abilities=rarity_abilities,
                                                            state=companions_relations.STATE.ENABLED)

        self.effect = self.EFFECT()

        self.card = self.effect.create_card(available_for_auction=True)

        self.hero.cards.add_card(self.card)
Пример #18
0
    def _test_companion_death_speed(self):
        current_time = game_prototypes.TimePrototype.get_current_time()

        companion_record = logic.create_random_companion_record(
            'test companion',
            state=relations.STATE.ENABLED,
            dedication=relations.DEDICATION.BRAVE)  #,#,;
        # abilities=abilities_container.Container(start=(effects.ABILITIES.BODYGUARD,)),# effects.ABILITIES.PUNY)),
        # dedication=relations.DEDICATION.HEROIC)
        # abilities=abilities_container.Container(common=(effects.ABILITIES.COWARDLY, )),
        # dedication=relations.DEDICATION.INDECISIVE)
        companion = logic.create_companion(companion_record)
        self.hero.set_companion(companion)
        # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.EGOISM)
        self.hero.preferences.set_companion_dedication(
            heroes_relations.COMPANION_DEDICATION.NORMAL)
        # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.ALTRUISM)
        # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.EVERY_MAN_FOR_HIMSELF)

        old_health = self.hero.companion.health

        print('defend_probability: ',
              self.hero.companion.defend_in_battle_probability)

        # for i in xrange(50):
        #     self.hero.randomized_level_up(increment_level=True)

        while self.hero.companion:
            self.hero.companion.coherence = 50

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

            self.hero.randomized_level_up()

            if not self.hero.is_alive:
                if hasattr(self.hero.actions.current_action, 'fast_resurrect'):
                    self.hero.actions.current_action.fast_resurrect()
                print('!')

            if self.hero.companion:
                if old_health != self.hero.companion.health:
                    print(
                        '%.2f:\t%s -> %s [%s] c%s' %
                        ((current_time.turn_number / c.TURNS_IN_HOUR / 24.0),
                         self.hero.companion.health -
                         self.hero.companion.max_health,
                         self.hero.companion.health, self.hero.companion.health
                         - old_health, self.hero.companion.coherence))

                old_health = self.hero.companion.health
Пример #19
0
    def test_exclude__different_data(self):
        cards = []

        companions_models.CompanionRecord.objects.all().delete()
        companions_storage.companions.refresh()

        for rarity, rarity_abilities in companions_helpers.RARITIES_ABILITIES.iteritems():
            companions_logic.create_random_companion_record(
                "%s companion" % rarity,
                mode=companions_relations.MODE.AUTOMATIC,
                abilities=rarity_abilities,
                state=companions_relations.STATE.ENABLED,
            )

        for i in xrange(len(relations.CARD_TYPE.records)):
            card = self.hero.cards.get_new_card(exclude=cards)
            cards.append(card)

        self.assertEqual(self.hero.cards.get_new_card(exclude=cards), None)

        cards[0].data = {"fake-data": True}
        self.assertEqual(cards[0].type, self.hero.cards.get_new_card(exclude=cards).type)

        self.assertEqual(set(card.type for card in cards), set(relations.CARD_TYPE.records))
    def set_hero_companion(self):
        from the_tale.game.companions import storage
        from the_tale.game.companions import models
        from the_tale.game.companions import logic

        COMPANION_NAME = 'test_hero_level_companion'

        for companion in storage.companions.all():
            if companion.name.startswith(COMPANION_NAME):
                models.CompanionRecord.objects.filter(id=companion.id).delete()
                storage.companions.refresh()
                break

        companion_record = logic.create_random_companion_record(COMPANION_NAME)

        self.hero.set_companion(logic.create_companion(companion_record))
    def set_hero_companion(self):
        from the_tale.game.companions import storage
        from the_tale.game.companions import models
        from the_tale.game.companions import logic

        COMPANION_NAME = u'test_hero_level_companion'

        for companion in storage.companions.all():
            if companion.name.startswith(COMPANION_NAME):
                models.CompanionRecord.objects.filter(id=companion.id).delete()
                storage.companions.refresh()
                break

        companion_record = logic.create_random_companion_record(COMPANION_NAME)

        self.hero.set_companion(logic.create_companion(companion_record))
Пример #22
0
    def _test_companion_death_speed(self):
        current_time = game_prototypes.TimePrototype.get_current_time()

        companion_record = logic.create_random_companion_record('test companion',
                                                                state=relations.STATE.ENABLED,
                                                                dedication=relations.DEDICATION.BRAVE)#,#,;
                                                                # abilities=abilities_container.Container(start=(effects.ABILITIES.BODYGUARD,)),# effects.ABILITIES.PUNY)),
                                                                # dedication=relations.DEDICATION.HEROIC)
                                                                # abilities=abilities_container.Container(common=(effects.ABILITIES.COWARDLY, )),
                                                                # dedication=relations.DEDICATION.INDECISIVE)
        companion = logic.create_companion(companion_record)
        self.hero.set_companion(companion)
        # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.EGOISM)
        self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.NORMAL)
        # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.ALTRUISM)
        # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.EVERY_MAN_FOR_HIMSELF)

        old_health = self.hero.companion.health

        print 'defend_probability: ', self.hero.companion.defend_in_battle_probability

        # for i in xrange(50):
        #     self.hero.randomized_level_up(increment_level=True)

        while self.hero.companion:
            self.hero.companion.coherence = 50

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

            self.hero.randomized_level_up()

            if not self.hero.is_alive:
                if hasattr(self.hero.actions.current_action, 'fast_resurrect'):
                    self.hero.actions.current_action.fast_resurrect()
                print '!'

            if self.hero.companion:
                if old_health != self.hero.companion.health:
                    print '%.2f:\t%s -> %s [%s] c%s' % ( (current_time.turn_number / c.TURNS_IN_HOUR / 24.0),
                                                          self.hero.companion.health - self.hero.companion.max_health,
                                                          self.hero.companion.health,
                                                          self.hero.companion.health - old_health,
                                                          self.hero.companion.coherence)

                old_health = self.hero.companion.health
Пример #23
0
def create_test_map():
    linguistics_logic.sync_static_restrictions()

    politic_power_storage.places.reset()
    politic_power_storage.persons.reset()

    tt_api_impacts.debug_clear_service()

    map_logic.create_test_map_info()

    p1 = places_logic.create_place(x=1, y=1, size=1, utg_name=names.generator().get_test_name(name='1x1'), race=relations.RACE.HUMAN)
    p2 = places_logic.create_place(x=3, y=3, size=3, utg_name=names.generator().get_test_name(name='10x10'), race=relations.RACE.HUMAN)
    p3 = places_logic.create_place(x=1, y=3, size=3, utg_name=names.generator().get_test_name(name='1x10'), race=relations.RACE.HUMAN)

    for place in places_storage.places.all():
        for i in range(3):
            persons_logic.create_person(place=place,
                                        race=relations.RACE.random(),
                                        gender=relations.GENDER.random(),
                                        type=persons_relations.PERSON_TYPE.random(),
                                        utg_name=names.generator().get_test_name())

    for place in places_storage.places.all():
        place.refresh_attributes()

    RoadPrototype.create(point_1=p1, point_2=p2).update()
    RoadPrototype.create(point_1=p2, point_2=p3).update()

    update_waymarks()

    nearest_cells.update_nearest_cells()

    mob_1 = mobs_logic.create_random_mob_record('mob_1')
    mob_2 = mobs_logic.create_random_mob_record('mob_2')
    mob_3 = mobs_logic.create_random_mob_record('mob_3')

    artifacts_logic.create_random_artifact_record('loot_1', mob=mob_1)
    artifacts_logic.create_random_artifact_record('loot_2', mob=mob_2)
    artifacts_logic.create_random_artifact_record('loot_3', mob=mob_3)

    artifacts_logic.create_random_artifact_record('helmet_1', type=artifacts_relations.ARTIFACT_TYPE.HELMET, mob=mob_1)
    artifacts_logic.create_random_artifact_record('plate_1', type=artifacts_relations.ARTIFACT_TYPE.PLATE, mob=mob_2)
    artifacts_logic.create_random_artifact_record('boots_1', type=artifacts_relations.ARTIFACT_TYPE.BOOTS, mob=mob_3)

    for equipment_slot in heroes_relations.EQUIPMENT_SLOT.records:
        if equipment_slot.default:
            artifacts_logic.create_random_artifact_record(equipment_slot.default, type=equipment_slot.artifact_type)

    companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED)

    return p1, p2, p3
Пример #24
0
    def setUp(self):
        super(InPlaceActionCompanionStealingTest, self).setUp()
        create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.action_idl = self.hero.actions.current_action

        self.action_inplace = prototypes.ActionInPlacePrototype.create(hero=self.hero)

        self.action_inplace.state = self.action_inplace.STATE.PROCESSED

        self.companion_record = companions_logic.create_random_companion_record('thief', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))
Пример #25
0
    def check_companion_exorcims(self, mob_type):
        self.companion_record = companions_logic.create_random_companion_record('exorcist',
                                                                                state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        mob_record = mobs_logic.create_random_mob_record('demon', type=mob_type)
        mob = mobs_objects.Mob(record_id=mob_record.id, level=self.hero.level, is_boss=False)

        self.hero.actions.pop_action()

        with self.check_delta(lambda: self.hero.statistics.pve_kills, 1):
            action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob)

        self.assertEqual(action_battle.percents, 1.0)
        self.assertEqual(action_battle.state, self.action_battle.STATE.PROCESSED)

        self.storage.process_turn(continue_steps_if_needed=False)

        self.assertEqual(self.hero.actions.current_action, self.action_idl)
Пример #26
0
    def test_healed_companion(self):
        self.companion_record = companions_logic.create_random_companion_record('companion', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        self.hero.companion.health = self.hero.companion.max_health

        while not self.hero.next_spending.is_HEAL_COMPANION:
            self.hero.switch_spending()

        money = self.hero.spend_amount

        self.hero.money = money + 666

        with self.check_not_changed(lambda: self.hero.statistics.money_spend):
            with self.check_not_changed(lambda: self.hero.statistics.money_spend_for_companions):
                with self.check_not_changed(lambda: self.hero.money):
                    self.storage.process_turn()

        self.storage._test_save()
Пример #27
0
    def test_companion_exorcims__not_demon(self):

        self.companion_record = companions_logic.create_random_companion_record('exorcist', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        not_demon_record = mobs_prototypes.MobRecordPrototype.create_random('demon', type=game_relations.BEING_TYPE.random(exclude=(game_relations.BEING_TYPE.DEMON, )))
        not_demon = mobs_prototypes.MobPrototype(record_id=not_demon_record.id, level=self.hero.level, is_boss=False)

        self.hero.actions.pop_action()

        with self.check_delta(lambda: self.hero.statistics.pve_kills, 0):
            action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=not_demon)

        self.assertEqual(action_battle.percents, 0.0)
        self.assertEqual(action_battle.state, self.action_battle.STATE.BATTLE_RUNNING)

        self.storage.process_turn(continue_steps_if_needed=False)

        self.assertEqual(self.hero.actions.current_action, action_battle)
Пример #28
0
    def setUp(self):
        super(InPlaceActionCompanionStealingTest, self).setUp()
        create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]
        self.hero.position.previous_place_id = None # test setting prevouse place in action constructor

        self.action_idl = self.hero.actions.current_action

        self.action_inplace = prototypes.ActionInPlacePrototype.create(hero=self.hero)

        self.action_inplace.state = self.action_inplace.STATE.PROCESSED

        self.companion_record = companions_logic.create_random_companion_record('thief', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))
Пример #29
0
    def setUp(self):
        super(InPlaceActionCompanionBuyMealTests, self).setUp()
        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.action_idl = self.hero.actions.current_action

        self.companion_record = companions_logic.create_random_companion_record('thief', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        self.hero._model.money = f.expected_gold_in_day(self.hero.level)

        self.hero.position.set_place(self.place_1)
        self.hero.position.visit_current_place()
        self.hero.position.set_place(self.place_2)
Пример #30
0
    def test_heal_companion(self):
        self.companion_record = companions_logic.create_random_companion_record('companion', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        self.hero.companion.health = 1

        while not self.hero.next_spending.is_HEAL_COMPANION:
            self.hero.switch_spending()

        money = self.hero.spend_amount

        self.hero.money = money + 666

        with self.check_increased(lambda: self.hero.companion.health):
            with self.check_delta(lambda: self.hero.money, -money):
                self.storage.process_turn()

        self.assertEqual(self.hero.statistics.money_spend, money)
        self.assertEqual(self.hero.statistics.money_spend_for_companions, money)

        self.storage._test_save()
Пример #31
0
    def test_choose_ability__additional_companion_abilities(self):
        from the_tale.game.heroes.habilities import ABILITIES
        from the_tale.game.companions.abilities import effects as companions_effects
        from the_tale.game.companions.abilities import container as abilities_container
        from the_tale.game.companions import logic as companions_logic
        from the_tale.game.companions import relations as companions_relations

        abilities = [ability for ability in companions_effects.ABILITIES.records
                     if ( isinstance(ability.effect, companions_effects.BaseBattleAbility) and
                          ability.effect.ABILITY.get_id() != 'hit' )]
        companion_ability = random.choice(abilities)

        all_abilities = [ability(level=ability.MAX_LEVEL)
                         for ability in ABILITIES.values()
                         if ability.get_id() != companion_ability.effect.ABILITY.get_id()]

        active_abilities = set(ability.get_id() for ability in ABILITIES.values() if ability.ACTIVATION_TYPE.is_ACTIVE)

        companion_record = companions_logic.create_random_companion_record(u'battle',
                                                                           abilities=abilities_container.Container(start=(companion_ability,)),
                                                                           state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(companion_record))
        self.hero.health = 1 # allow regeneration

        actor = battle.Actor(self.hero, BattleContext())

        chosen_abilities = set()

        # mock abilities modify_attribute instead of hereos, since we test correct work of it
        def modify_attribute(self, modifier, value):
            if modifier.is_ADDITIONAL_ABILITIES:
                return all_abilities
            return value

        with mock.patch('the_tale.game.heroes.habilities.AbilitiesPrototype.modify_attribute', modify_attribute):
            for i in xrange(1000):
                chosen_abilities.add(actor.choose_ability().get_id())

        self.assertEqual(len(active_abilities), len(chosen_abilities) + 1)
        self.assertEqual(active_abilities - set([companion_ability.effect.ABILITY.get_id()]), chosen_abilities)
Пример #32
0
    def setUp(self):
        super(InPlaceActionCompanionBuyMealTests, self).setUp()
        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.action_idl = self.hero.actions.current_action

        self.companion_record = companions_logic.create_random_companion_record('thief', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        self.hero.money = f.expected_gold_in_day(self.hero.level)

        self.hero.position.set_place(self.place_1)
        self.hero.position.update_previous_place()
        self.hero.position.set_place(self.place_2)

        self.hero.position.move_out_place()
Пример #33
0
    def setUp(self):
        super(UseCardTaskTests, self).setUp()

        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account = self.accounts_factory.create_account()
        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.building_1 = places_logic.create_building(person=self.place_1.persons[0], utg_name=names.generator().get_test_name('building-1-name'))

        environment.deinitialize()
        environment.initialize()

        self.highlevel = environment.workers.highlevel
        self.highlevel.process_initialize(0, 'highlevel')

        self.task_data = {'place_id': self.place_1.id,
                          'person_id': self.place_1.persons[0].id,
                          'building_id': self.building_1.id}

        self.companion = companions_logic.create_random_companion_record('test-companion', state=companions_relations.STATE.ENABLED)
Пример #34
0
    def test_heal_companion__swich_spending_on_full_health(self):
        self.companion_record = companions_logic.create_random_companion_record('companion', state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(companions_logic.create_companion(self.companion_record))

        while not self.hero.next_spending.is_HEAL_COMPANION:
            self.hero.switch_spending()

        self.hero.companion.health = self.hero.companion.max_health

        money = self.hero.spend_amount

        self.hero.money = money + 666

        with self.check_not_changed(lambda: self.hero.companion.health):
            with self.check_not_changed(lambda: self.hero.money):
                with mock.patch('the_tale.game.heroes.objects.Hero.switch_spending') as switch_spending:
                    self.storage.process_turn()

        self.assertEqual(switch_spending.call_count, 1)

        self.assertEqual(self.hero.statistics.money_spend, 0)
        self.assertEqual(self.hero.statistics.money_spend_for_companions, 0)

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

    map_logic.create_test_my_info()

    p1 = PlacePrototype.create( x=1, y=1, size=1, utg_name=names.generator.get_test_name(name='1x1'))
    p2 = PlacePrototype.create( x=3, y=3, size=3, utg_name=names.generator.get_test_name(name='10x10'))
    p3 = PlacePrototype.create( x=1, y=3, size=3, utg_name=names.generator.get_test_name(name='1x10'))

    for place in places_storage.all():
        place.sync_persons(force_add=True)

    RoadPrototype.create(point_1=p1, point_2=p2).update()
    RoadPrototype.create(point_1=p2, point_2=p3).update()

    update_waymarks()

    update_nearest_cells()

    mob_1 = MobRecordPrototype.create_random('mob_1')
    mob_2 = MobRecordPrototype.create_random('mob_2')
    mob_3 = MobRecordPrototype.create_random('mob_3')

    ArtifactRecordPrototype.create_random('loot_1', mob=mob_1)
    ArtifactRecordPrototype.create_random('loot_2', mob=mob_2)
    ArtifactRecordPrototype.create_random('loot_3', mob=mob_3)

    ArtifactRecordPrototype.create_random('helmet_1', type_=ARTIFACT_TYPE.HELMET, mob=mob_1)
    ArtifactRecordPrototype.create_random('plate_1', type_=ARTIFACT_TYPE.PLATE, mob=mob_2)
    ArtifactRecordPrototype.create_random('boots_1', type_=ARTIFACT_TYPE.BOOTS, mob=mob_3)

    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PANTS, type_=ARTIFACT_TYPE.PANTS)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.BOOTS, type_=ARTIFACT_TYPE.BOOTS)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PLATE, type_=ARTIFACT_TYPE.PLATE)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.GLOVES, type_=ARTIFACT_TYPE.GLOVES)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.WEAPON, type_=ARTIFACT_TYPE.MAIN_HAND)

    companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED)

    return p1, p2, p3
Пример #36
0
def create_test_map():
    linguistics_logic.sync_static_restrictions()

    map_logic.create_test_map_info()

    p1 = places_logic.create_place( x=1, y=1, size=1, utg_name=names.generator().get_test_name(name='1x1'), race=relations.RACE.HUMAN)
    p2 = places_logic.create_place( x=3, y=3, size=3, utg_name=names.generator().get_test_name(name='10x10'), race=relations.RACE.HUMAN)
    p3 = places_logic.create_place( x=1, y=3, size=3, utg_name=names.generator().get_test_name(name='1x10'), race=relations.RACE.HUMAN)

    for place in places_storage.places.all():
        for i in range(3):
            places_logic.add_person_to_place(place)

    RoadPrototype.create(point_1=p1, point_2=p2).update()
    RoadPrototype.create(point_1=p2, point_2=p3).update()

    update_waymarks()

    nearest_cells.update_nearest_cells()

    mob_1 = MobRecordPrototype.create_random('mob_1')
    mob_2 = MobRecordPrototype.create_random('mob_2')
    mob_3 = MobRecordPrototype.create_random('mob_3')

    ArtifactRecordPrototype.create_random('loot_1', mob=mob_1)
    ArtifactRecordPrototype.create_random('loot_2', mob=mob_2)
    ArtifactRecordPrototype.create_random('loot_3', mob=mob_3)

    ArtifactRecordPrototype.create_random('helmet_1', type_=ARTIFACT_TYPE.HELMET, mob=mob_1)
    ArtifactRecordPrototype.create_random('plate_1', type_=ARTIFACT_TYPE.PLATE, mob=mob_2)
    ArtifactRecordPrototype.create_random('boots_1', type_=ARTIFACT_TYPE.BOOTS, mob=mob_3)

    for equipment_slot in heroes_relations.EQUIPMENT_SLOT.records:
        if equipment_slot.default:
            ArtifactRecordPrototype.create_random(equipment_slot.default, type_=equipment_slot.artifact_type)

    companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED)

    return p1, p2, p3
Пример #37
0
def create_test_map():
    linguistics_logic.sync_static_restrictions()

    map_logic.create_test_map_info()

    p1 = places_logic.create_place( x=1, y=1, size=1, utg_name=names.generator().get_test_name(name='1x1'), race=relations.RACE.HUMAN)
    p2 = places_logic.create_place( x=3, y=3, size=3, utg_name=names.generator().get_test_name(name='10x10'), race=relations.RACE.HUMAN)
    p3 = places_logic.create_place( x=1, y=3, size=3, utg_name=names.generator().get_test_name(name='1x10'), race=relations.RACE.HUMAN)

    for place in places_storage.places.all():
        for i in range(3):
            places_logic.add_person_to_place(place)

    RoadPrototype.create(point_1=p1, point_2=p2).update()
    RoadPrototype.create(point_1=p2, point_2=p3).update()

    update_waymarks()

    nearest_cells.update_nearest_cells()

    mob_1 = MobRecordPrototype.create_random('mob_1')
    mob_2 = MobRecordPrototype.create_random('mob_2')
    mob_3 = MobRecordPrototype.create_random('mob_3')

    ArtifactRecordPrototype.create_random('loot_1', mob=mob_1)
    ArtifactRecordPrototype.create_random('loot_2', mob=mob_2)
    ArtifactRecordPrototype.create_random('loot_3', mob=mob_3)

    ArtifactRecordPrototype.create_random('helmet_1', type_=ARTIFACT_TYPE.HELMET, mob=mob_1)
    ArtifactRecordPrototype.create_random('plate_1', type_=ARTIFACT_TYPE.PLATE, mob=mob_2)
    ArtifactRecordPrototype.create_random('boots_1', type_=ARTIFACT_TYPE.BOOTS, mob=mob_3)

    for equipment_slot in heroes_relations.EQUIPMENT_SLOT.records:
        if equipment_slot.default:
            ArtifactRecordPrototype.create_random(equipment_slot.default, type_=equipment_slot.artifact_type)

    companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED)

    return p1, p2, p3
Пример #38
0
def create_test_map():
    linguistics_logic.sync_static_restrictions()

    map_logic.create_test_my_info()

    p1 = PlacePrototype.create(
        x=1, y=1, size=1, utg_name=names.generator.get_test_name(name='1x1'))
    p2 = PlacePrototype.create(
        x=3, y=3, size=3, utg_name=names.generator.get_test_name(name='10x10'))
    p3 = PlacePrototype.create(
        x=1, y=3, size=3, utg_name=names.generator.get_test_name(name='1x10'))

    for place in places_storage.all():
        place.sync_persons(force_add=True)

    RoadPrototype.create(point_1=p1, point_2=p2).update()
    RoadPrototype.create(point_1=p2, point_2=p3).update()

    update_waymarks()

    update_nearest_cells()

    mob_1 = MobRecordPrototype.create_random('mob_1')
    mob_2 = MobRecordPrototype.create_random('mob_2')
    mob_3 = MobRecordPrototype.create_random('mob_3')

    ArtifactRecordPrototype.create_random('loot_1', mob=mob_1)
    ArtifactRecordPrototype.create_random('loot_2', mob=mob_2)
    ArtifactRecordPrototype.create_random('loot_3', mob=mob_3)

    ArtifactRecordPrototype.create_random('helmet_1',
                                          type_=ARTIFACT_TYPE.HELMET,
                                          mob=mob_1)
    ArtifactRecordPrototype.create_random('plate_1',
                                          type_=ARTIFACT_TYPE.PLATE,
                                          mob=mob_2)
    ArtifactRecordPrototype.create_random('boots_1',
                                          type_=ARTIFACT_TYPE.BOOTS,
                                          mob=mob_3)

    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PANTS,
                                          type_=ARTIFACT_TYPE.PANTS)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.BOOTS,
                                          type_=ARTIFACT_TYPE.BOOTS)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PLATE,
                                          type_=ARTIFACT_TYPE.PLATE)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.GLOVES,
                                          type_=ARTIFACT_TYPE.GLOVES)
    ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.WEAPON,
                                          type_=ARTIFACT_TYPE.MAIN_HAND)

    companions_logic.create_random_companion_record(
        'companion_1',
        dedication=companions_relations.DEDICATION.HEROIC,
        state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record(
        'companion_2',
        dedication=companions_relations.DEDICATION.BOLD,
        state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record(
        'companion_3',
        dedication=companions_relations.DEDICATION.BOLD,
        state=companions_relations.STATE.DISABLED)

    return p1, p2, p3
Пример #39
0
 def test_rarities_abilities(self):
     for rarity, rarity_abilities in helpers.RARITIES_ABILITIES.iteritems():
         companion = logic.create_random_companion_record('%s companion' % rarity,
                                                          abilities=rarity_abilities)
         self.assertEqual(companion.rarity, rarity)
Пример #40
0
 def test_rarities_abilities(self):
     for rarity, rarity_abilities in helpers.RARITIES_ABILITIES.items():
         companion = logic.create_random_companion_record(
             '%s companion' % rarity, abilities=rarity_abilities)
         self.assertEqual(companion.rarity, rarity)