Exemplo n.º 1
0
def setUp(self):
    from the_tale.accounts import tt_api as accounts_tt_api

    from the_tale.accounts.achievements.storage import achievements_storage
    from the_tale.collections.storage import collections_storage, kits_storage, items_storage
    from the_tale.linguistics.storage import game_dictionary, game_lexicon, restrictions_storage

    from the_tale.game.prototypes import GameState
    from the_tale.game.persons import storage as persons_storage
    from the_tale.game.mobs import storage as mobs_storage
    from the_tale.game.companions import storage as companions_storage
    from the_tale.game.artifacts import storage as artifacts_storage
    from the_tale.game.heroes import storage as heroes_storage
    from the_tale.game.map.storage import map_info_storage
    from the_tale.game.places import storage as places_storage
    from the_tale.game.roads.storage import roads_storage, waymarks_storage

    accounts_tt_api.debug_clear_service()

    settings.refresh(force=True)

    heroes_storage.position_descriptions.clear()

    places_storage.places.clear()
    places_storage.buildings.clear()
    persons_storage.persons.clear()
    persons_storage.social_connections.clear()
    waymarks_storage.clear()
    roads_storage.clear()
    mobs_storage.mobs.clear()
    companions_storage.companions.clear()
    artifacts_storage.artifacts.clear()
    map_info_storage.clear()
    places_storage.resource_exchanges.clear()
    collections_storage.clear()
    kits_storage.clear()
    items_storage.clear()
    achievements_storage.clear()
    game_dictionary.clear()
    game_lexicon.clear()
    restrictions_storage.clear()

    GameState.start()

    from the_tale.blogs import conf as blogs_conf
    from the_tale.blogs import models as blogs_models

    for tag_id in blogs_conf.settings.DEFAULT_TAGS:
        blogs_models.Tag.objects.create(id=tag_id,
                                        name='{}'.format(tag_id),
                                        description='{}'.format(tag_id))
Exemplo n.º 2
0
def form_game_info(account=None, is_own=False, client_turns=None):
    from the_tale.accounts.prototypes import AccountPrototype
    from the_tale.game.prototypes import GameState
    from the_tale.game.pvp.prototypes import Battle1x1Prototype

    game_time = TimePrototype.get_current_time()

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

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

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

    return data
Exemplo n.º 3
0
def form_game_info(account=None, is_own=False, client_turns=None):
    from the_tale.accounts.prototypes import AccountPrototype
    from the_tale.game.prototypes import GameState
    from the_tale.game.pvp.prototypes import Battle1x1Prototype

    game_time = TimePrototype.get_current_time()

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

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

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

    return data
Exemplo n.º 4
0
    def cached_ui_info_for_hero(cls, account_id, recache_if_required,
                                patch_turns, for_last_turn):

        data = cache.get(cls.cached_ui_info_key_for_hero(account_id))

        if data is None:
            hero = cls.get_by_account_id(account_id)
            data = hero.ui_info(actual_guaranteed=False)

        cls.modify_ui_info_with_turn(data, for_last_turn=for_last_turn)

        if recache_if_required and cls.is_ui_continue_caching_required(
                data['ui_caching_started_at']) and GameState.is_working():
            environment.workers.supervisor.cmd_start_hero_caching(account_id)

        if patch_turns is not None and data['patch_turn'] in patch_turns:
            patch_fields = set(data['changed_fields'])
            for field in data.keys():
                if field not in patch_fields:
                    del data[field]
        else:
            data['patch_turn'] = None

        del data['changed_fields']

        return data
Exemplo n.º 5
0
    def test_initialization(self):
        from the_tale.common.postponed_tasks.models import PostponedTask
        from the_tale.common.postponed_tasks.prototypes import PostponedTaskPrototype, POSTPONED_TASK_STATE
        from the_tale.common.postponed_tasks.postponed_tasks import FakePostponedInternalTask

        PostponedTaskPrototype.create(FakePostponedInternalTask())

        self.assertEqual(
            PostponedTask.objects.filter(
                state=POSTPONED_TASK_STATE.WAITING).count(), 1)

        self.worker.process_initialize()

        self.assertEqual(
            PostponedTask.objects.filter(
                state=POSTPONED_TASK_STATE.WAITING).count(), 0)
        self.assertEqual(
            PostponedTask.objects.filter(
                state=POSTPONED_TASK_STATE.RESETED).count(), 1)

        self.assertEqual(self.worker.tasks, {})
        self.assertEqual(self.worker.accounts_for_tasks, {})
        self.assertEqual(self.worker.accounts_owners, {
            self.account_1.id: 'game_logic_1',
            self.account_2.id: 'game_logic_2'
        })
        self.assertEqual(self.worker.accounts_queues, {})
        self.assertTrue(self.worker.initialized)
        self.assertFalse(self.worker.wait_next_turn_answer)
        self.assertTrue(GameState.is_working())
Exemplo n.º 6
0
def setUp(self):
    from the_tale.accounts.achievements.storage import achievements_storage
    from the_tale.collections.storage import collections_storage, kits_storage, items_storage
    from the_tale.linguistics.storage import game_dictionary, game_lexicon, restrictions_storage

    from the_tale.game.prototypes import GameState
    from the_tale.game.persons import storage as persons_storage
    from the_tale.game.mobs.storage import mobs_storage
    from the_tale.game.companions import storage as companions_storage
    from the_tale.game.artifacts.storage import artifacts_storage
    from the_tale.game.heroes import storage as heroes_storage
    from the_tale.game.map.storage import map_info_storage
    from the_tale.game.places import storage as places_storage
    from the_tale.game.roads.storage import roads_storage, waymarks_storage

    settings.refresh(force=True)

    heroes_storage.position_descriptions.clear()

    places_storage.places.clear()
    places_storage.buildings.clear()
    persons_storage.persons.clear()
    persons_storage.social_connections.clear()
    waymarks_storage.clear()
    roads_storage.clear()
    mobs_storage.clear()
    companions_storage.companions.clear()
    artifacts_storage.clear()
    map_info_storage.clear()
    places_storage.resource_exchanges.clear()
    collections_storage.clear()
    kits_storage.clear()
    items_storage.clear()
    achievements_storage.clear()
    game_dictionary.clear()
    game_lexicon.clear()
    restrictions_storage.clear()

    GameState.start()

    from the_tale.blogs import conf as blogs_conf
    from the_tale.blogs import models as blogs_models

    for tag_id in blogs_conf.settings.DEFAULT_TAGS:
        blogs_models.Tag.objects.create(id=tag_id, name='{}'.format(tag_id), description='{}'.format(tag_id))
Exemplo n.º 7
0
def setUp(self):
    from the_tale.accounts.achievements.storage import achievements_storage
    from the_tale.collections.storage import collections_storage, kits_storage, items_storage
    from the_tale.linguistics.storage import game_dictionary, game_lexicon, restrictions_storage

    from the_tale.game.prototypes import GameState
    from the_tale.game.persons import storage as persons_storage
    from the_tale.game.mobs.storage import mobs_storage
    from the_tale.game.companions import storage as companions_storage
    from the_tale.game.artifacts.storage import artifacts_storage
    from the_tale.game.heroes import storage as heroes_storage
    from the_tale.game.map.storage import map_info_storage
    from the_tale.game.map.places.storage import places_storage, buildings_storage, resource_exchange_storage
    from the_tale.game.map.roads.storage import roads_storage, waymarks_storage

    settings.refresh(force=True)

    heroes_storage.position_descriptions.clear()

    places_storage.clear()
    buildings_storage.clear()
    persons_storage.persons_storage.clear()
    persons_storage.social_connections.clear()
    waymarks_storage.clear()
    roads_storage.clear()
    mobs_storage.clear()
    companions_storage.companions.clear()
    artifacts_storage.clear()
    map_info_storage.clear()
    resource_exchange_storage.clear()
    collections_storage.clear()
    kits_storage.clear()
    items_storage.clear()
    achievements_storage.clear()
    game_dictionary.clear()
    game_lexicon.clear()
    restrictions_storage.clear()

    GameState.start()
Exemplo n.º 8
0
def setUp(self):
    from the_tale.accounts.achievements.storage import achievements_storage
    from the_tale.collections.storage import collections_storage, kits_storage, items_storage
    from the_tale.linguistics.storage import game_dictionary, game_lexicon, restrictions_storage

    from the_tale.game.prototypes import GameState
    from the_tale.game.persons import storage as persons_storage
    from the_tale.game.mobs.storage import mobs_storage
    from the_tale.game.companions import storage as companions_storage
    from the_tale.game.artifacts.storage import artifacts_storage
    from the_tale.game.heroes import storage as heroes_storage
    from the_tale.game.map.storage import map_info_storage
    from the_tale.game.map.places.storage import places_storage, buildings_storage, resource_exchange_storage
    from the_tale.game.map.roads.storage import roads_storage, waymarks_storage

    settings.refresh(force=True)

    heroes_storage.position_descriptions.clear()

    places_storage.clear()
    buildings_storage.clear()
    persons_storage.persons_storage.clear()
    persons_storage.social_connections.clear()
    waymarks_storage.clear()
    roads_storage.clear()
    mobs_storage.clear()
    companions_storage.companions.clear()
    artifacts_storage.clear()
    map_info_storage.clear()
    resource_exchange_storage.clear()
    collections_storage.clear()
    kits_storage.clear()
    items_storage.clear()
    achievements_storage.clear()
    game_dictionary.clear()
    game_lexicon.clear()
    restrictions_storage.clear()

    GameState.start()
Exemplo n.º 9
0
    def test_initialization(self):
        from the_tale.common.postponed_tasks import PostponedTask, PostponedTaskPrototype, POSTPONED_TASK_STATE, FakePostponedInternalTask

        PostponedTaskPrototype.create(FakePostponedInternalTask())

        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.WAITING).count(), 1)

        self.worker.process_initialize()

        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.WAITING).count(), 0)
        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.RESETED).count(), 1)

        self.assertEqual(self.worker.tasks, {})
        self.assertEqual(self.worker.accounts_for_tasks, {})
        self.assertEqual(self.worker.accounts_owners, {self.account_1.id: 'game_logic_1', self.account_2.id: 'game_logic_2'})
        self.assertEqual(self.worker.accounts_queues, {})
        self.assertTrue(self.worker.initialized)
        self.assertFalse(self.worker.wait_next_turn_answer)
        self.assertTrue(GameState.is_working())
Exemplo n.º 10
0
    def cached_ui_info_for_hero(cls, account_id, recache_if_required, patch_turns, for_last_turn):
        from . import logic

        data = cache.get(cls.cached_ui_info_key_for_hero(account_id))

        if data is None:
            hero = logic.load_hero(account_id=account_id)
            data = hero.ui_info(actual_guaranteed=False)

        cls.modify_ui_info_with_turn(data, for_last_turn=for_last_turn)

        if recache_if_required and cls.is_ui_continue_caching_required(data['ui_caching_started_at']) and GameState.is_working():
            amqp_environment.environment.workers.supervisor.cmd_start_hero_caching(account_id)

        if patch_turns is not None and data['patch_turn'] in patch_turns:
            patch_fields = set(data['changed_fields'])
            for field in data.keys():
                if field not in patch_fields:
                    del data[field]
        else:
            data['patch_turn'] = None

        del data['changed_fields']

        return data
Exemplo n.º 11
0
 def process_no_cmd(self):
     if GameState.is_working():
         self.logger.info('send next turn command')
         environment.workers.supervisor.cmd_next_turn()
Exemplo n.º 12
0
 def test_force_stop(self):
     self.worker.process_initialize()
     self.worker._force_stop()
     self.assertTrue(GameState.is_stopped())
Exemplo n.º 13
0
 def test_no_state(self):
     self.assertTrue(GameState.is_stopped())
     self.assertFalse(GameState.is_working())
Exemplo n.º 14
0
 def process_no_cmd(self):
     if GameState.is_working():
         self.logger.info('send next turn command')
         environment.workers.supervisor.cmd_next_turn()
Exemplo n.º 15
0
 def test_working(self):
     GameState.start()
     self.assertFalse(GameState.is_stopped())
     self.assertTrue(GameState.is_working())
Exemplo n.º 16
0
 def test_no_state(self):
     self.assertTrue(GameState.is_stopped())
     self.assertFalse(GameState.is_working())
Exemplo n.º 17
0
 def test_working(self):
     GameState.start()
     self.assertFalse(GameState.is_stopped())
     self.assertTrue(GameState.is_working())