当前位置: 首页>>代码示例>>Python>>正文


Python LogicStorage.process_turn方法代码示例

本文整理汇总了Python中the_tale.game.logic_storage.LogicStorage.process_turn方法的典型用法代码示例。如果您正苦于以下问题:Python LogicStorage.process_turn方法的具体用法?Python LogicStorage.process_turn怎么用?Python LogicStorage.process_turn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在the_tale.game.logic_storage.LogicStorage的用法示例。


在下文中一共展示了LogicStorage.process_turn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LongTeleportTests

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class LongTeleportTests(CardsTestMixin, testcase.TestCase):
    CARD = effects.LongTeleport

    def setUp(self):
        super(LongTeleportTests, self).setUp()
        self.place_1, self.place_2, self.place_3 = create_test_map()

        result, account_1_id, bundle_id = register_user("test_user", "[email protected]", "111111")

        self.account_1 = AccountPrototype.get_by_id(account_1_id)

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

        self.hero = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero.position.set_place(self.place_1)

        self.card = self.CARD()

    @mock.patch("the_tale.game.heroes.objects.Hero.is_battle_start_needed", lambda self: False)
    def test_moving(self):
        self.assertFalse(self.hero.actions.current_action.TYPE.is_MOVE_TO)

        result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
        self.assertEqual(
            (result, step, postsave_actions), (ComplexChangeTask.RESULT.FAILED, ComplexChangeTask.STEP.ERROR, ())
        )

    @mock.patch("the_tale.game.heroes.objects.Hero.is_battle_start_needed", lambda self: False)
    def test_use(self):
        actions_prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.place_3)

        self.storage.process_turn(continue_steps_if_needed=False)

        self.assertTrue(self.hero.actions.current_action.state == actions_prototypes.ActionMoveToPrototype.STATE.MOVING)

        self.assertTrue(self.hero.position.percents < 1)

        result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
        self.assertEqual(
            (result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())
        )

        self.assertTrue(self.hero.position.place.id, self.place_3.id)

    @mock.patch("the_tale.game.heroes.objects.Hero.is_battle_start_needed", lambda self: False)
    def test_use__wrong_state(self):
        actions_prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.place_3)
        self.assertTrue(self.hero.actions.current_action.state != actions_prototypes.ActionMoveToPrototype.STATE.MOVING)

        with self.check_not_changed(lambda: self.hero.actions.current_action.percents):
            result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
            self.assertEqual(
                (result, step, postsave_actions), (ComplexChangeTask.RESULT.FAILED, ComplexChangeTask.STEP.ERROR, ())
            )

        self.assertTrue(self.hero.position.place.id, self.place_1.id)
开发者ID:Jazzis18,项目名称:the-tale,代码行数:59,代码来源:test_teleports.py

示例2: AddExperienceTestMixin

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class AddExperienceTestMixin(CardsTestMixin):
    CARD = None

    def setUp(self):
        super(AddExperienceTestMixin, self).setUp()
        create_test_map()

        result, account_1_id, bundle_id = register_user('test_user', '[email protected]', '111111')

        self.account_1 = AccountPrototype.get_by_id(account_1_id)

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

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

        self.card = self.CARD()


    @mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.is_short_quest_path_required', False)
    @mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.is_first_quest_path_required', False)
    def test_use(self):
        self.action_quest = ActionQuestPrototype.create(hero=self.hero)
        quests_helpers.setup_quest(self.hero)

        self.assertTrue(self.hero.quests.has_quests)

        old_ui_experience = self.hero.quests.current_quest.current_info.ui_info(self.hero)['experience']

        with mock.patch('the_tale.game.quests.container.QuestsContainer.mark_updated') as mark_updated:
            with self.check_not_changed(lambda: self.hero.experience):
                with self.check_not_changed(lambda: self.hero.level):
                    with self.check_not_changed(lambda: self.hero.quests.current_quest.current_info.experience):
                        with self.check_delta(lambda: self.hero.quests.current_quest.current_info.experience_bonus, self.CARD.EXPERIENCE):
                            result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
                            self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ()))

        self.assertEqual(mark_updated.call_count, 1)

        while self.hero.quests.has_quests:
            self.assertEqual(self.hero.quests.current_quest.quests_stack[0].experience_bonus, self.CARD.EXPERIENCE)
            self.assertEqual(self.hero.quests.current_quest.quests_stack[0].ui_info(self.hero)['experience'], old_ui_experience + self.CARD.EXPERIENCE)
            self.storage.process_turn()

    def test_no_quest(self):
        self.assertFalse(self.hero.quests.has_quests)

        result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
        self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.FAILED, ComplexChangeTask.STEP.ERROR, ()))
开发者ID:Alkalit,项目名称:the-tale,代码行数:51,代码来源:test_add_experience.py

示例3: GameTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class GameTest(testcase.TestCase):
    def test_statistics_consistency(self):

        create_test_map()

        result, account_id, bundle_id = register_user("test_user")

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]

        current_time = TimePrototype.get_current_time()

        for i in xrange(10000):
            self.storage.process_turn()
            current_time.increment_turn()

        self.assertEqual(self.hero.money, self.hero.statistics.money_earned - self.hero.statistics.money_spend)
开发者ID:lshestov,项目名称:the-tale,代码行数:20,代码来源:test_game.py

示例4: FirstStepsActionTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class FirstStepsActionTest(testcase.TestCase):
    def setUp(self):
        super(FirstStepsActionTest, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account(is_fast=True)

        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

        with self.check_calls_count("the_tale.game.heroes.logic.push_message_to_diary", 1):
            self.action_first_steps = ActionFirstStepsPrototype.create(hero=self.hero)

    def test_create(self):
        self.assertEqual(self.action_idl.leader, False)
        self.assertEqual(self.action_first_steps.leader, True)
        self.assertEqual(self.action_first_steps.bundle_id, self.action_idl.bundle_id)
        self.storage._test_save()

    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()
开发者ID:Tiendil,项目名称:the-tale,代码行数:49,代码来源:test_action_fist_steps.py

示例5: MetaProxyActionForArenaPvP1x1Tests

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class MetaProxyActionForArenaPvP1x1Tests(testcase.TestCase, PvPTestsMixin):

    @mock.patch('the_tale.game.actions.prototypes.ActionBase.get_description', lambda self: 'abrakadabra')
    def setUp(self):
        super(MetaProxyActionForArenaPvP1x1Tests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(self.account_1.id))
        self.storage.load_account_data(AccountPrototype.get_by_id(self.account_2.id))

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.action_idl_1 = self.hero_1.actions.current_action
        self.action_idl_2 = self.hero_2.actions.current_action

        self.pvp_create_battle(self.account_1, self.account_2, BATTLE_1X1_STATE.PROCESSING)
        self.pvp_create_battle(self.account_2, self.account_1, BATTLE_1X1_STATE.PROCESSING)

        self.bundle_id = 666

        meta_action_battle = meta_actions.ArenaPvP1x1.create(self.storage, self.hero_1, self.hero_2)

        self.action_proxy_1 = ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=self.bundle_id, meta_action=meta_action_battle)
        self.action_proxy_2 = ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=self.bundle_id, meta_action=meta_action_battle)

        self.storage.merge_bundles([self.action_idl_1.bundle_id, self.action_idl_2.bundle_id], self.bundle_id)

        self.meta_action_battle = self.storage.meta_actions.values()[0]


    def tearDown(self):
        pass

    # renamed to fix segmentation fault
    def test_z_create(self):
        self.assertFalse(self.action_idl_1.leader)
        self.assertFalse(self.action_idl_2.leader)
        self.assertTrue(self.action_proxy_1.leader)
        self.assertTrue(self.action_proxy_2.leader)
        self.assertEqual(self.hero_1.actions.number, 2)
        self.assertEqual(self.hero_2.actions.number, 2)

        self.assertNotEqual(self.action_proxy_1.bundle_id, self.action_idl_1.bundle_id)
        self.assertNotEqual(self.action_proxy_2.bundle_id, self.action_idl_2.bundle_id)
        self.assertEqual(self.action_proxy_1.bundle_id, self.action_proxy_2.bundle_id)

        self.assertEqual(self.action_proxy_1.meta_action, self.action_proxy_2.meta_action)
        self.assertEqual(self.action_proxy_1.meta_action, self.meta_action_battle)

        self.assertEqual(len(self.storage.meta_actions), 1)

    def test_one_action_step_one_meta_step(self):
        with mock.patch('the_tale.game.actions.meta_actions.ArenaPvP1x1._process') as meta_action_process_counter:
            self.action_proxy_1.process()

        self.assertEqual(meta_action_process_counter.call_count, 1)

    def test_two_actions_step_one_meta_step(self):
        with mock.patch('the_tale.game.actions.meta_actions.ArenaPvP1x1._process') as meta_action_process_counter:
            self.action_proxy_1.process()
            self.action_proxy_2.process()

        self.assertEqual(meta_action_process_counter.call_count, 1)

    def test_two_actions_step_one_meta_step_from_storage(self):
        with mock.patch('the_tale.game.actions.meta_actions.ArenaPvP1x1._process') as meta_action_process_counter:
            self.storage.process_turn()

        self.assertEqual(meta_action_process_counter.call_count, 1)

    def test_success_processing(self):
        self.action_proxy_1.process()

        self.assertEqual(self.action_proxy_1.percents, self.meta_action_battle.percents)
        self.assertNotEqual(self.action_proxy_2.percents, self.meta_action_battle.percents)

    def test_full_battle(self):
        current_time = TimePrototype.get_current_time()

        while self.action_proxy_1.state != meta_actions.ArenaPvP1x1.STATE.PROCESSED:
            self.storage.process_turn(continue_steps_if_needed=False)
            current_time.increment_turn()

        self.assertEqual(self.meta_action_battle.state, meta_actions.ArenaPvP1x1.STATE.PROCESSED)
        self.assertTrue(self.hero_1.is_alive and self.hero_2.is_alive)

        self.assertTrue(self.action_idl_1.leader)
        self.assertTrue(self.action_idl_2.leader)

    def test_get_meta_action__without_storage(self):
        self.action_proxy_1.storage = None
        self.assertNotEqual(self.action_proxy_1.meta_action, None)

    def test_get_meta_action__no_meta_action(self):
#.........这里部分代码省略.........
开发者ID:alexudracul,项目名称:the-tale,代码行数:103,代码来源:test_action_meta_proxy.py

示例6: GetArtifactMixin

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class GetArtifactMixin(CardsTestMixin):
    CARD = None
    RARITIES = None
    HAS_USELESS = False

    def setUp(self):
        super(GetArtifactMixin, self).setUp()
        create_test_map()

        result, account_1_id, bundle_id = register_user('test_user', '[email protected]', '111111')

        self.account_1 = AccountPrototype.get_by_id(account_1_id)

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

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

        self.card = self.CARD()


    def test_use(self):

        rarities = set()

        has_useless = False

        for i in xrange(10000):
            result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
            self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ()))

            artifact = self.hero.bag.values()[0]
            self.hero.bag.pop_artifact(artifact)

            rarities.add(artifact.rarity)
            has_useless = has_useless or artifact.type.is_USELESS

        self.assertEqual(has_useless, self.HAS_USELESS)
        self.assertEqual(rarities, self.RARITIES)


    def test_use__full_bag(self):
        with self.check_delta(lambda: self.hero.bag.occupation, 1000):
            for i in xrange(1000):
                result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
                self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ()))


    def test_use_when_trading(self):
        from the_tale.game.actions.prototypes import ActionTradingPrototype

        action_idl = self.hero.actions.current_action
        action_trade = ActionTradingPrototype.create(hero=self.hero)

        result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero))
        self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ()))

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

        self.assertTrue(action_trade.replane_required)

        self.storage.process_turn(continue_steps_if_needed=False)

        self.assertEqual(self.hero.actions.current_action, action_idl)

        self.assertEqual(self.hero.bag.occupation, 1)
开发者ID:alexudracul,项目名称:the-tale,代码行数:68,代码来源:test_get_artifact.py

示例7: GeneralTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]

#.........这里部分代码省略.........
        self.hero.companion.health = 1
        self.check_heal_companion_in_choices(True)

    @mock.patch('the_tale.game.actions.prototypes.ActionIdlenessPrototype.HELP_CHOICES', set((HELP_CHOICES.HEAL_COMPANION, HELP_CHOICES.MONEY)))
    def test_help_choice_has_heal_companion__for_low_health_with_alternative(self):
        companion_record = companions_storage.companions.enabled_companions().next()
        self.hero.set_companion(companions_logic.create_companion(companion_record))
        self.hero.companion.health = 1
        self.check_heal_companion_in_choices(True)


    def check_stock_up_energy_in_choices(self, result):
        stock_found = False
        for i in xrange(1000):
            stock_found = stock_found or (self.action_idl.get_help_choice() == HELP_CHOICES.STOCK_UP_ENERGY)

        self.assertEqual(stock_found, result)

    @mock.patch('the_tale.game.actions.prototypes.ActionIdlenessPrototype.HELP_CHOICES', set((HELP_CHOICES.STOCK_UP_ENERGY, HELP_CHOICES.MONEY)))
    def test_help_choice_has_stock_up_energy__can_stock(self):
        self.hero.energy_charges = 0
        self.check_stock_up_energy_in_choices(True)

    @mock.patch('the_tale.game.actions.prototypes.ActionIdlenessPrototype.HELP_CHOICES', set((HELP_CHOICES.STOCK_UP_ENERGY, HELP_CHOICES.MONEY)))
    def test_help_choice_has_stock_up_energy__can_not_stock(self):
        self.hero.energy_bonus = c.ANGEL_FREE_ENERGY_MAXIMUM
        self.check_stock_up_energy_in_choices(False)

    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_help_choice_heal_not_in_choices_for_dead_hero(self):

        self.hero.health = 1
        self.hero.save()

        self.assertTrue(HELP_CHOICES.HEAL in self.action_idl.help_choices)

        self.hero.kill()
        self.hero.save()

        self.assertFalse(HELP_CHOICES.HEAL in self.action_idl.help_choices)

    def test_action_default_serialization(self):
        # class TestAction(ActionBase):
        #     TYPE = 'test-action'

        default_action = TestAction( hero=self.hero,
                                     bundle_id=self.bundle_id,
                                     state=TestAction.STATE.UNINITIALIZED)

        self.assertEqual(default_action.serialize(), {'bundle_id': self.bundle_id,
                                                      'state': TestAction.STATE.UNINITIALIZED,
                                                      'percents': 0.0,
                                                      'description': None,
                                                      'type': TestAction.TYPE.value,
                                                      'created_at_turn': TimePrototype.get_current_turn_number()})

        self.assertEqual(default_action, TestAction.deserialize(self.hero, default_action.serialize()))
开发者ID:Alkalit,项目名称:the-tale,代码行数:69,代码来源:test_general.py

示例8: Worker

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class Worker(workers.BaseWorker):
    STOP_SIGNAL_REQUIRED = False

    def initialize(self):
        # worker initialized by supervisor
        pass

    def cmd_initialize(self, turn_number, worker_id):
        self.send_cmd('initialize', {'turn_number': turn_number, 'worker_id': worker_id})

    def process_initialize(self, turn_number, worker_id):

        if self.initialized:
            self.logger.warn('WARNING: game already initialized, do reinitialization')

        self.storage = LogicStorage()

        self.initialized = True
        self.turn_number = turn_number
        self.queue = []
        self.worker_id = worker_id

        self.logger.info('GAME INITIALIZED')

        environment.workers.supervisor.cmd_answer('initialize', self.worker_id)

    def cmd_next_turn(self, turn_number):
        return self.send_cmd('next_turn', data={'turn_number': turn_number})

    # @profile.profile_decorator('/home/tie/repos/mine/the-tale/profile.info')
    def process_next_turn(self, turn_number):

        self.turn_number += 1

        if turn_number != self.turn_number:
            raise LogicException('dessinchonization: workers turn number (%d) not equal to command turn number (%d)' % (self.turn_number, turn_number))


        if TimePrototype.get_current_turn_number() != self.turn_number:
            raise LogicException('dessinchonization: workers turn number (%d) not equal to saved turn number (%d)' % (self.turn_number,
                                                                                                                      TimePrototype.get_current_turn_number()))

        self.storage.process_turn(logger=self.logger)
        self.storage.save_changed_data(logger=self.logger)

        for hero_id in self.storage.skipped_heroes:
            hero = self.storage.heroes[hero_id]
            if hero.actions.current_action.bundle_id in self.storage.ignored_bundles:
                continue
            environment.workers.supervisor.cmd_account_release_required(hero.account_id)

        environment.workers.supervisor.cmd_answer('next_turn', self.worker_id)

        if game_settings.COLLECT_GARBAGE and self.turn_number % game_settings.COLLECT_GARBAGE_PERIOD == 0:
            self.logger.info('GC: start')
            gc.collect()
            self.logger.info('GC: end')

    def release_account(self, account_id):
        if account_id not in self.storage.accounts_to_heroes:
            environment.workers.supervisor.cmd_account_released(account_id)
            return

        hero = self.storage.accounts_to_heroes[account_id]
        bundle_id = hero.actions.current_action.bundle_id

        if bundle_id in self.storage.ignored_bundles:
            return

        with self.storage.on_exception(self.logger,
                                       message='LogicWorker.process_release_account catch exception, while processing hero %d, try to save all bundles except %d',
                                       data=(hero.id, bundle_id),
                                       excluded_bundle_id=bundle_id):
            self.storage.release_account_data(account_id)
            environment.workers.supervisor.cmd_account_released(account_id)

    def cmd_stop(self):
        return self.send_cmd('stop')

    def process_stop(self):
        # no need to save data, since they automaticaly saved on every turn
        self.initialized = False
        self.storage.save_all(logger=self.logger)
        environment.workers.supervisor.cmd_answer('stop', self.worker_id)
        self.stop_required = True
        self.logger.info('LOGIC STOPPED')

    def cmd_register_account(self, account_id):
        return self.send_cmd('register_account', {'account_id': account_id})

    def process_register_account(self, account_id):
        from the_tale.accounts.prototypes import AccountPrototype
        account = AccountPrototype.get_by_id(account_id)
        if account is None:
            raise LogicException('can not get account with id "%d"' % (account_id,))
        self.storage.load_account_data(account)

    def cmd_release_account(self, account_id):
        return self.send_cmd('release_account', {'account_id': account_id})

#.........这里部分代码省略.........
开发者ID:Alkalit,项目名称:the-tale,代码行数:103,代码来源:logic.py

示例9: RegenerateEnergyActionTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class RegenerateEnergyActionTest(testcase.TestCase):

    def setUp(self):
        super(RegenerateEnergyActionTest, self).setUp()
        create_test_map()

        result, account_id, bundle_id = register_user('test_user')

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]
        self.action_idl = self.hero.actions.current_action

        self.action_regenerate = ActionRegenerateEnergyPrototype.create(hero=self.hero)

    def tearDown(self):
        pass

    def test_create(self):
        self.assertEqual(self.action_idl.leader, False)
        self.assertEqual(self.action_regenerate.leader, True)
        self.assertEqual(self.action_regenerate.bundle_id, self.action_idl.bundle_id)
        self.storage._test_save()

    def test_not_ready(self):
        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action, self.action_regenerate)
        self.storage._test_save()

    @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', False)
    def test_full(self):
        self.hero.change_energy(-self.hero.energy)

        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.assertEqual(self.hero.energy, self.hero.preferences.energy_regeneration_type.amount)
        self.assertEqual(self.hero.need_regenerate_energy, False)
        self.assertEqual(self.hero.last_energy_regeneration_at_turn, TimePrototype.get_current_turn_number()-1)

        self.storage._test_save()

    @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', True)
    def test_full__double_energy(self):
        self.hero.change_energy(-self.hero.energy)

        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.assertEqual(self.hero.energy, self.hero.preferences.energy_regeneration_type.amount * 2)
        self.assertEqual(self.hero.need_regenerate_energy, False)
        self.assertEqual(self.hero.last_energy_regeneration_at_turn, TimePrototype.get_current_turn_number()-1)

        self.storage._test_save()
开发者ID:Jazzis18,项目名称:the-tale,代码行数:65,代码来源:test_action_regenerate_energy.py

示例10: InPlaceActionCompanionStealingTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class InPlaceActionCompanionStealingTest(testcase.TestCase):

    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))


    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_money', lambda self: True)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_item', lambda self: True)
    def test_no_companion(self):
        self.hero.remove_companion()

        with contextlib.nested(
                self.check_not_changed(lambda: self.hero.bag.occupation),
                self.check_not_changed(lambda: self.hero.money),
                self.check_not_changed(lambda: self.hero.statistics.money_earned_from_companions),
                self.check_not_changed(lambda: self.hero.statistics.artifacts_had),
                self.check_not_changed(lambda: self.hero.statistics.loot_had),
                self.check_not_changed(lambda: len(self.hero.journal))
                ):
            self.storage.process_turn(continue_steps_if_needed=False)

    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_money', lambda self: True)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_item', lambda self: True)
    def test_place_not_changed(self):
        self.hero.position.update_previous_place()

        with contextlib.nested(
                self.check_not_changed(lambda: self.hero.bag.occupation),
                self.check_not_changed(lambda: self.hero.money),
                self.check_not_changed(lambda: self.hero.statistics.money_earned_from_companions),
                self.check_not_changed(lambda: self.hero.statistics.artifacts_had),
                self.check_not_changed(lambda: self.hero.statistics.loot_had),
                self.check_not_changed(lambda: len(self.hero.journal))
                ):
            self.storage.process_turn(continue_steps_if_needed=False)

    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_money', lambda self: True)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_item', lambda self: False)
    def test_steal_money(self):
        with contextlib.nested(
                self.check_not_changed(lambda: self.hero.bag.occupation),
                self.check_increased(lambda: self.hero.money),
                self.check_increased(lambda: self.hero.statistics.money_earned_from_companions),
                self.check_not_changed(lambda: self.hero.statistics.artifacts_had),
                self.check_not_changed(lambda: self.hero.statistics.loot_had),
                self.check_increased(lambda: len(self.hero.journal))
                ):
            self.storage.process_turn(continue_steps_if_needed=False)


    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_money', lambda self: False)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_item', lambda self: True)
    @mock.patch('the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 0)
    def test_steal_item__loot(self):
        with contextlib.nested(
                self.check_increased(lambda: self.hero.bag.occupation),
                self.check_not_changed(lambda: self.hero.money),
                self.check_not_changed(lambda: self.hero.statistics.money_earned_from_companions),
                self.check_not_changed(lambda: self.hero.statistics.artifacts_had),
                self.check_delta(lambda: self.hero.statistics.loot_had, 1),
                self.check_increased(lambda: len(self.hero.journal))
                ):
            self.storage.process_turn(continue_steps_if_needed=False)


    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_money', lambda self: False)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_item', lambda self: True)
    @mock.patch('the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 1)
    def test_steal_item__artifact(self):
        with contextlib.nested(
                self.check_increased(lambda: self.hero.bag.occupation),
                self.check_not_changed(lambda: self.hero.money),
                self.check_not_changed(lambda: self.hero.statistics.money_earned_from_companions),
                self.check_delta(lambda: self.hero.statistics.artifacts_had, 1),
                self.check_not_changed(lambda: self.hero.statistics.loot_had),
                self.check_increased(lambda: len(self.hero.journal))
                ):
            self.storage.process_turn(continue_steps_if_needed=False)



    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_steal_money', lambda self: False)
#.........这里部分代码省略.........
开发者ID:Jazzis18,项目名称:the-tale,代码行数:103,代码来源:test_action_inplace.py

示例11: InPlaceActionSpendMoneyTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class InPlaceActionSpendMoneyTest(testcase.TestCase):

    def setUp(self):
        super(InPlaceActionSpendMoneyTest, self).setUp()
        create_test_map()

        result, account_id, bundle_id = register_user('test_user')

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]
        self.action_idl = self.hero.actions.current_action

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


    def test_no_money(self):

        self.hero.money = 1
        self.storage.process_turn()
        self.assertEqual(self.hero.money, 1)
        self.assertEqual(self.hero.statistics.money_spend, 0)
        self.storage._test_save()

    @mock.patch('the_tale.game.heroes.objects.Hero.buy_price', lambda hero: -100)
    def test_buy_price_less_than_zero(self):
        money = self.hero.spend_amount
        self.hero.money = money

        self.assertEqual(self.action_inplace.try_to_spend_money(), 1)
        self.assertEqual(self.hero.statistics.money_spend, 1)

    def test_instant_heal(self):
        while not self.hero.next_spending.is_INSTANT_HEAL:
            self.hero.switch_spending()

        money = self.hero.spend_amount

        self.hero.money = money + 666
        self.hero.health = 1
        self.storage.process_turn()
        self.assertEqual(self.hero.money, 666)
        self.assertEqual(self.hero.health, self.hero.max_health)

        self.assertEqual(self.hero.statistics.money_spend, money)
        self.assertEqual(self.hero.statistics.money_spend_for_heal, money)
        self.storage._test_save()

    def test_instant_heal__switch_on_full_health(self):
        while not self.hero.next_spending.is_INSTANT_HEAL:
            self.hero.switch_spending()

        money = self.hero.spend_amount

        self.hero.money = money + 666
        self.hero.health = self.hero.max_health

        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.money, money + 666)
        self.assertEqual(self.hero.health, self.hero.max_health)

        self.assertEqual(self.hero.statistics.money_spend, 0)
        self.assertEqual(self.hero.statistics.money_spend_for_heal, 0)
        self.storage._test_save()

    def test_instant_heal__too_much_health(self):
        while not self.hero.next_spending.is_INSTANT_HEAL:
            self.hero.switch_spending()

        money = self.hero.spend_amount
        health = (self.hero.max_health * c.SPEND_MONEY_FOR_HEAL_HEALTH_FRACTION) + 1

        self.hero.money = money + 666
        self.hero.health = health
        self.storage.process_turn()
        self.assertTrue(self.hero.money, money + 666)
        self.assertEqual(self.hero.health, health)

        self.assertEqual(self.hero.statistics.money_spend, 0)
        self.assertEqual(self.hero.statistics.money_spend_for_heal, 0)
        self.storage._test_save()

    def test_instant_heal__low_health(self):
        while not self.hero.next_spending.is_INSTANT_HEAL:
            self.hero.switch_spending()

        money = self.hero.spend_amount
        health = (self.hero.max_health * c.SPEND_MONEY_FOR_HEAL_HEALTH_FRACTION) - 1

        self.hero.money = money
        self.hero.health = health
        self.storage.process_turn()
        self.assertEqual(self.hero.money, 0)
        self.assertEqual(self.hero.health, self.hero.max_health)

        self.assertEqual(self.hero.statistics.money_spend, money)
        self.assertEqual(self.hero.statistics.money_spend_for_heal, money)
#.........这里部分代码省略.........
开发者ID:Jazzis18,项目名称:the-tale,代码行数:103,代码来源:test_action_inplace.py

示例12: InPlaceActionCompanionBuyMealTests

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class InPlaceActionCompanionBuyMealTests(testcase.TestCase):

    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()

    @mock.patch('the_tale.game.heroes.objects.Hero.companion_money_for_food_multiplier', 1)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_eat', lambda hero: True)
    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)

    @mock.patch('the_tale.game.heroes.objects.Hero.companion_money_for_food_multiplier', 0.5)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_eat', lambda hero: True)
    def test_buy_meal(self):
        self.hero.position.last_place_visited_turn = TimePrototype.get_current_turn_number() - c.TURNS_IN_HOUR * 12
        with contextlib.nested( self.check_decreased(lambda: self.hero.money),
                                self.check_increased(lambda: self.hero.statistics.money_spend_for_companions) ):
            prototypes.ActionInPlacePrototype.create(hero=self.hero)

    def check_not_used(self):
        with contextlib.nested(
                self.check_not_changed(lambda: self.hero.money),
                self.check_not_changed(lambda: self.hero.statistics.money_spend_for_companions)):
            prototypes.ActionInPlacePrototype.create(hero=self.hero)

    @mock.patch('the_tale.game.heroes.objects.Hero.companion_money_for_food_multiplier', 0.5)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_eat', lambda hero: True)
    def test_no_turns_since_last_visit(self):
        self.hero.position.last_place_visited_turn = TimePrototype.get_current_turn_number()
        self.check_not_used()

    @mock.patch('the_tale.game.heroes.objects.Hero.companion_money_for_food_multiplier', 66666666)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_eat', lambda hero: True)
    def test_not_enough_money(self):
        self.hero.position.last_place_visited_turn = TimePrototype.get_current_turn_number() - 1000

        with contextlib.nested( self.check_delta(lambda: self.hero.money, -self.hero.money),
                                self.check_delta(lambda: self.hero.statistics.money_spend_for_companions, self.hero.money )):
            prototypes.ActionInPlacePrototype.create(hero=self.hero)

    @mock.patch('the_tale.game.heroes.objects.Hero.companion_money_for_food_multiplier', 66666666)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_eat', lambda hero: True)
    def test_no_money(self):
        self.hero.money = 0
        self.check_not_used()


    @mock.patch('the_tale.game.heroes.objects.Hero.companion_money_for_food_multiplier', 0.5)
    @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_eat', lambda hero: False)
    def test_companion_does_not_eat(self):
        self.check_not_used()
开发者ID:Jazzis18,项目名称:the-tale,代码行数:80,代码来源:test_action_inplace.py

示例13: InPlaceActionTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]

#.........这里部分代码省略.........
                self.hero.position.previous_place_id = None
                self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place)

                with mock.patch('the_tale.game.places.habits.Honor.interval', honor):
                    with mock.patch('the_tale.game.places.habits.Peacefulness.interval', peacefulness):
                        with self.check_delta(self.hero.diary.messages_number, 1):
                            prototypes.ActionInPlacePrototype.create(hero=self.hero)


        self.storage._test_save()

    @mock.patch('the_tale.game.balance.constants.PLACE_HABITS_EVENT_PROBABILITY', 0.0)
    def test_habit_event__no_event(self):
        self.hero.position.previous_place_id = None

        self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place)

        with self.check_not_changed(lambda: len(self.hero.diary.messages)):
            prototypes.ActionInPlacePrototype.create(hero=self.hero)

        self.storage._test_save()

    @mock.patch('the_tale.game.balance.constants.PLACE_HABITS_EVENT_PROBABILITY', 1.0)
    def test_habit_event__not_visit(self):
        self.hero.position.update_previous_place()
        self.assertEqual(self.hero.position.place, self.hero.position.previous_place)

        with self.check_not_changed(lambda: len(self.hero.diary.messages)):
            prototypes.ActionInPlacePrototype.create(hero=self.hero)

        self.storage._test_save()

    def test_processed(self):
        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.position.previous_place, self.hero.position.place)
        self.storage._test_save()

    def test_regenerate_energy_action_create(self):
        self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.PRAY)
        self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0])
        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 3)
        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE)
        self.storage._test_save()

    def test_regenerate_energy_action_not_create_for_sacrifice(self):
        self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.SACRIFICE)
        self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0])
        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.storage._test_save()

    def test_heal_action_create(self):
        self.hero.health = 1
        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 3)
        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRestPrototype.TYPE)
        self.storage._test_save()

    @mock.patch('the_tale.game.companions.objects.Companion.need_heal', True)
    def test_heal_companion_action_create(self):
        companion_record = companions_storage.companions.enabled_companions().next()
        self.hero.set_companion(companions_logic.create_companion(companion_record))
开发者ID:Jazzis18,项目名称:the-tale,代码行数:70,代码来源:test_action_inplace.py

示例14: IdlenessActionTest

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class IdlenessActionTest(testcase.TestCase):

    def setUp(self):
        super(IdlenessActionTest, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user')

        self.account = AccountPrototype.get_by_id(account_id)
        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

    def tearDown(self):
        pass


    def test_create(self):
        self.assertEqual(self.action_idl.leader, True)
        self.assertEqual(self.action_idl.percents, 1.0)
        self.storage._test_save()


    def test_first_quest(self):
        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE)
        self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST)
        self.assertEqual(self.action_idl.bundle_id, self.hero.account_id)
        self.storage._test_save()


    def test_reset_percents_on_quest_end(self):
        self.action_idl.percents = 1.0
        self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST
        self.storage.process_turn(continue_steps_if_needed=False)
        self.assertEqual(self.action_idl.percents, 0.0)


    def test_inplace(self):
        self.action_idl.percents = 1.0
        self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST
        self.storage.process_turn(continue_steps_if_needed=False)
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE)
        self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.IN_PLACE)
        self.storage._test_save()

    def test_waiting(self):
        self.action_idl.percents = 0.0
        self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.IN_PLACE
        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 1)
        self.assertEqual(self.hero.actions.current_action, self.action_idl)
        self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.WAITING)
        self.storage._test_save()

    def test_regenerate_energy_action_create(self):
        self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.PRAY)
        self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0])
        self.action_idl.percents = 0.0
        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE)
        self.storage._test_save()

    def test_regenerate_energy_action_not_create_for_sacrifice(self):
        self.action_idl.percents = 0
        self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.SACRIFICE)
        self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0])
        self.storage.process_turn()
        self.assertEqual(len(self.hero.actions.actions_list), 1)
        self.assertEqual(self.hero.actions.current_action, self.action_idl)
        self.storage._test_save()


    def test_full_waiting(self):
        self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.WAITING
        self.action_idl.percents = 0

        current_time = TimePrototype.get_current_time()

        for i in xrange(c.TURNS_TO_IDLE*self.hero.level):
            self.storage.process_turn()
            current_time.increment_turn()
            self.assertEqual(len(self.hero.actions.actions_list), 1)
            self.assertEqual(self.hero.actions.current_action, self.action_idl)

        self.storage.process_turn()

        self.assertEqual(len(self.hero.actions.actions_list), 2)
        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE)
        self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST)

        self.storage._test_save()

#.........这里部分代码省略.........
开发者ID:alexudracul,项目名称:the-tale,代码行数:103,代码来源:test_action_idleness.py

示例15: CommonTests

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import process_turn [as 别名]
class CommonTests(testcase.TestCase):

    def setUp(self):
        super(CommonTests, 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]


    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)


    @mock.patch('the_tale.game.companions.objects.Companion.max_coherence', 100)
    @mock.patch('the_tale.game.heroes.habilities.companions.THOUGHTFUL.MULTIPLIER', [1, 1, 1, 1, 1])
    @mock.patch('the_tale.game.heroes.habilities.companions._CompanionHealBase.PROBABILITY', [0, 0, 0, 0, 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
开发者ID:Alkalit,项目名称:the-tale,代码行数:72,代码来源:test_common.py


注:本文中的the_tale.game.logic_storage.LogicStorage.process_turn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。