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


Python LogicStorage.release_account_data方法代码示例

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


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

示例1: LogicStorageTests

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

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

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

        self.storage = LogicStorage()

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

        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        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.bundle_1_id = self.action_idl_1.bundle_id
        self.bundle_2_id = self.action_idl_2.bundle_id


    def test_load_account_data(self):
        self.assertEqual(len(self.storage.heroes), 2)
        self.assertEqual(len(self.storage.accounts_to_heroes), 2)
        self.assertEqual(self.storage.bundles_to_accounts, {self.hero_1.actions.current_action.bundle_id: set([self.account_1.id]),
                                                            self.hero_2.actions.current_action.bundle_id: set([self.account_2.id])})

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

        self.assertEqual(self.action_idl_1.storage, self.storage)
        self.assertEqual(action_regenerate.storage, self.storage)

        storage = LogicStorage()
        storage.load_account_data(AccountPrototype.get_by_id(self.account_1.id))
        storage.load_account_data(AccountPrototype.get_by_id(self.account_2.id))
        self.assertEqual(len(storage.heroes), 2)
        self.assertEqual(len(storage.accounts_to_heroes), 2)
        self.assertEqual(storage.bundles_to_accounts, {self.hero_1.actions.current_action.bundle_id: set([self.account_1.id]),
                                                       self.hero_2.actions.current_action.bundle_id: set([self.account_2.id])})


    def test_load_account_data_with_meta_action(self):
        bundle_id = 666

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

        proxy_action_1 = actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_1, _bundle_id=bundle_id, meta_action=meta_action_battle)
        proxy_action_2 = actions_prototypes.ActionMetaProxyPrototype.create(hero=self.hero_2, _bundle_id=bundle_id, meta_action=meta_action_battle)

        self.assertEqual(len(self.storage.meta_actions), 1)
        self.assertEqual(len(self.storage.meta_actions_to_actions), 1)
        self.assertEqual(self.storage.meta_actions_to_actions[meta_action_battle.uid], set([LogicStorage.get_action_uid(proxy_action_1),
                                                                                            LogicStorage.get_action_uid(proxy_action_2)]))

        self.storage.save_changed_data()

        self.assertIs(self.hero_1.actions.current_action.meta_action, self.hero_2.actions.current_action.meta_action)
        self.assertIs(self.hero_1.actions.current_action.saved_meta_action, self.hero_2.actions.current_action.saved_meta_action)

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

        self.assertEqual(len(storage.meta_actions), 1)
        self.assertEqual(len(storage.meta_actions_to_actions), 1)
        self.assertEqual(storage.meta_actions_to_actions[meta_action_battle.uid], set([LogicStorage.get_action_uid(proxy_action_1),
                                                                                       LogicStorage.get_action_uid(proxy_action_2)]))

        self.assertEqual(storage.bundles_to_accounts, {self.hero_1.actions.current_action.bundle_id: set([self.account_1.id, self.account_2.id])})

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

        self.assertIs(hero_1.actions.current_action.meta_action, hero_2.actions.current_action.meta_action)
        self.assertIsNot(hero_1.actions.current_action.saved_meta_action, hero_2.actions.current_action.saved_meta_action)
        self.assertEqual(hero_1.actions.current_action.saved_meta_action.serialize(), hero_2.actions.current_action.saved_meta_action.serialize())


    def test_add_duplicate_hero(self):
        self.assertRaises(exceptions.HeroAlreadyRegisteredError, self.storage._add_hero, self.hero_1)


    def test_action_release_account_data(self):

        actions_prototypes.ActionRegenerateEnergyPrototype.create(hero=self.hero_1)

        self.storage.skipped_heroes.add(self.hero_1.id)

        self.storage.release_account_data(self.account_1.id)

        self.assertEqual(len(self.storage.heroes), 1)
        self.assertEqual(len(self.storage.accounts_to_heroes), 1)
        self.assertEqual(self.storage.bundles_to_accounts, {self.hero_2.actions.current_action.bundle_id: set([self.account_2.id])})
        self.assertEqual(self.storage.heroes.values()[0].id, self.hero_2.id)
        self.assertFalse(self.storage.skipped_heroes)

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

示例2: UsePvPAbilityTests

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

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

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

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

        self.account_1 = AccountPrototype.get_by_id(account_1_id)
        self.account_2 = AccountPrototype.get_by_id(account_2_id)

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

        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.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.ability = random.choice(ABILITIES.values())

        self.task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=self.ability.TYPE)

    def test_create(self):
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.UNPROCESSED)
        self.assertEqual(self.task.battle_id, self.battle.id)
        self.assertEqual(self.task.account_id, self.account_1.id)
        self.assertEqual(self.task.ability_id, self.ability.TYPE)

    def test_serialize(self):
        self.assertEqual(self.task.serialize(), UsePvPAbilityTask.deserialize(self.task.serialize()).serialize())

    def test_process_battle_not_found(self):
        Battle1x1Prototype._db_all().delete()
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.BATTLE_FINISHED)

    def test_process_hero_not_found(self):
        self.storage.release_account_data(self.account_1.id)
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.HERO_NOT_FOUND)

    def test_wrong_ability_id(self):
        task = UsePvPAbilityTask(battle_id=self.battle.id, account_id=self.account_1.id, ability_id=u'wrong_ability_id')
        task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(task.state, USE_PVP_ABILITY_TASK_STATE.WRONG_ABILITY_ID)

    def test_no_resources(self):
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.NO_ENERGY)

    def test_process_success(self):
        self.hero_1.pvp.set_energy(1)

        old_hero_1_last_message = self.hero_1.messages.messages[-1]
        old_hero_2_last_message = self.hero_2.messages.messages[-1]

        self.assertEqual(self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(self.task.state, USE_PVP_ABILITY_TASK_STATE.PROCESSED)

        self.assertNotEqual(old_hero_1_last_message, self.hero_1.messages.messages[-1])
        self.assertNotEqual(old_hero_2_last_message, self.hero_2.messages.messages[-1])

        self.assertNotEqual(old_hero_1_last_message.ui_info()[-1], self.hero_1.messages.ui_info()[-1][2])
        self.assertEqual(old_hero_2_last_message.ui_info()[-1], self.hero_2.messages.ui_info()[-1][2])

        self.assertEqual(self.hero_1.pvp.energy, 0)
开发者ID:Alkalit,项目名称:the-tale,代码行数:74,代码来源:test_use_pvp_ability_task.py

示例3: Worker

# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import release_account_data [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

示例4: SayInBattleLogTests

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

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

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

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

        self.account_1 = AccountPrototype.get_by_id(account_1_id)
        self.account_2 = AccountPrototype.get_by_id(account_2_id)

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

        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.battle = Battle1x1Prototype.create(self.account_1)
        self.battle.set_enemy(self.account_2)
        self.battle.save()

        self.task = SayInBattleLogTask(battle_id=self.battle.id, text=u'some pvp message')

    def test_create(self):
        self.assertEqual(self.task.state, SAY_IN_HERO_LOG_TASK_STATE.UNPROCESSED)
        self.assertEqual(self.task.battle_id, self.battle.id)

    def test_serialize(self):
        self.assertEqual(self.task.serialize(), SayInBattleLogTask.deserialize(self.task.serialize()).serialize())

    def test_process_account_hero_not_found(self):
        self.storage.release_account_data(self.account_1.id)
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, SAY_IN_HERO_LOG_TASK_STATE.ACCOUNT_HERO_NOT_FOUND)

    def test_process_battle_not_found(self):
        self.storage.release_account_data(self.account_1.id)
        self.battle.remove()
        self.task.process(FakePostpondTaskPrototype(), self.storage)
        self.assertEqual(self.task.state, SAY_IN_HERO_LOG_TASK_STATE.BATTLE_NOT_FOUND)

    def test_process_success(self):
        old_hero_1_last_message = self.hero_1.messages.messages[-1]
        old_hero_2_last_message = self.hero_2.messages.messages[-1]

        self.assertEqual(self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(self.task.state, SAY_IN_HERO_LOG_TASK_STATE.PROCESSED)

        self.assertNotEqual(old_hero_1_last_message, self.hero_1.messages.messages[-1])
        self.assertNotEqual(old_hero_2_last_message, self.hero_2.messages.messages[-1])

    def test_process_success_without_second_hero(self):
        old_hero_1_last_message = self.hero_1.messages.messages[-1]
        old_hero_2_last_message = self.hero_2.messages.messages[-1]

        self.storage.release_account_data(self.account_2.id)
        self.assertEqual(self.task.process(FakePostpondTaskPrototype(), self.storage), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)

        self.assertEqual(self.task.state, SAY_IN_HERO_LOG_TASK_STATE.PROCESSED)
        self.assertNotEqual(old_hero_1_last_message, self.hero_1.messages.messages[-1])
        self.assertEqual(old_hero_2_last_message, self.hero_2.messages.messages[-1])
开发者ID:Alkalit,项目名称:the-tale,代码行数:66,代码来源:test_say_in_battle_log.py


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