def test_move_change_place_coordinates_and_back(self):

        current_time = TimePrototype.get_current_time()

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

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

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

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

        self.assertEqual(self.hero.actions.current_action.TYPE,
                         prototypes.ActionInPlacePrototype.TYPE)
        self.assertTrue(not self.hero.position.is_walking)
        self.storage._test_save()
Beispiel #2
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

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

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

        self.hero.money += 1
        self.hero.preferences.set_mob(mobs_storage.all()[0])
        self.hero.preferences.set_place(self.p1)
        self.hero.preferences.set_friend(self.p1.persons[0])
        self.hero.preferences.set_enemy(self.p2.persons[0])
        self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Beispiel #3
0
    def use(self, task, storage, highlevel=None, **kwargs):  # pylint: disable=R0911,W0613

        card = objects.Card.deserialize(uuid.UUID(task.data['card']['id']),
                                        task.data['card']['data'])

        delta = card.data['direction'] * self.modificator

        place_id = task.data.get('value')

        if place_id not in places_storage.places:
            return task.logic_result(
                next_step=postponed_tasks.UseCardTask.STEP.ERROR,
                message='Город не найден.')

        if task.step.is_LOGIC:
            return task.logic_result(
                next_step=postponed_tasks.UseCardTask.STEP.HIGHLEVEL)

        elif task.step.is_HIGHLEVEL:
            place = places_storage.places[place_id]

            place.politic_power.change_power(place=place,
                                             hero_id=task.hero_id,
                                             has_in_preferences=True,
                                             power=delta)

            places_logic.save_place(place)
            places_storage.places.update_version()

            return task.logic_result(message='Влияние города изменено.')
Beispiel #4
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

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

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

        self.hero.money += 1
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.MOB, mobs_storage.mobs.all()[0])
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.PLACE, self.p1)
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.FRIEND, self.p1.persons[0])
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.ENEMY, self.p2.persons[0])
        self.hero.preferences.set(heroes_relations.PREFERENCE_TYPE.EQUIPMENT_SLOT, heroes_relations.EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Beispiel #5
0
    def use(self, task, storage, highlevel=None, **kwargs):  # pylint: disable=R0911,W0613

        place_id = task.data.get('value')

        if place_id not in places_storage.places:
            return task.logic_result(
                next_step=postponed_tasks.UseCardTask.STEP.ERROR,
                message='Город не найден.')

        if task.step.is_LOGIC:
            return task.logic_result(
                next_step=postponed_tasks.UseCardTask.STEP.HIGHLEVEL)

        elif task.step.is_HIGHLEVEL:
            place = places_storage.places[place_id]

            place.effects.add(
                effects.Effect(name='Хранитель {}'.format(
                    accounts_prototypes.AccountPrototype.get_by_id(
                        task.hero_id).nick),
                               attribute=places_relations.ATTRIBUTE.STABILITY,
                               value=self.modificator,
                               delta=place.attrs.stability_renewing_speed))

            place.refresh_attributes()

            places_logic.save_place(place)

            places_storage.places.update_version()

            return task.logic_result()
Beispiel #6
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

        persons_logic.sync_social_connections()

        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.hero.money += 1
        self.hero.preferences.set_mob(mobs_storage.all()[0])
        self.hero.preferences.set_place(self.p1)
        self.hero.preferences.set_friend(self.p1.persons[0])
        self.hero.preferences.set_enemy(self.p2.persons[0])
        self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Beispiel #7
0
    def setUp(self):
        super(QuestsTestBase, self).setUp()
        self.p1, self.p2, self.p3 = create_test_map()

        # add more persons, to lower conflicts
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p1)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p2)
        places_logic.add_person_to_place(self.p3)
        places_logic.add_person_to_place(self.p3)

        persons_logic.sync_social_connections()

        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.hero.money += 1
        self.hero.preferences.set_mob(mobs_storage.all()[0])
        self.hero.preferences.set_place(self.p1)
        self.hero.preferences.set_friend(self.p1.persons[0])
        self.hero.preferences.set_enemy(self.p2.persons[0])
        self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE)
        self.hero.position.set_place(self.p3)
        heroes_logic.save_hero(self.hero)

        self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY)
        places_logic.save_place(self.p2)

        self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH
        persons_logic.save_person(self.p1.persons[0])
Beispiel #8
0
    def setUp(self):
        super(PlaceDescriptionTests, self).setUp()

        self.place = places_storage.places.all()[0]
        self.place.description = 'old description'
        places_logic.save_place(self.place)

        self.place_2 = places_storage.places.all()[1]

        self.bill_data = PlaceDescripton(place_id=self.place.id, description='new description')
        self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
    def setUp(self):
        super(PlaceDescriptionTests, self).setUp()

        self.place = places_storage.places.all()[0]
        self.place.description = 'old description'
        places_logic.save_place(self.place)

        self.place_2 = places_storage.places.all()[1]

        self.bill_data = PlaceDescripton(place_id=self.place.id, description='new description')
        self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
    def test_has_meaning__duplicate_description(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceDescripton.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.place.description = 'new description'
        places_logic.save_place(self.place)

        self.assertFalse(self.bill.has_meaning())
Beispiel #11
0
    def test_has_meaning__duplicate_modifier(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceModifier.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.bill.data.place.set_modifier(self.bill.data.modifier_id)

        places_logic.save_place(self.bill.data.place)

        self.assertFalse(self.bill.has_meaning())
    def test_has_meaning__duplicate_modifier(self):
        VotePrototype.create(self.account2, self.bill, False)
        VotePrototype.create(self.account3, self.bill, True)

        form = PlaceModifier.ModeratorForm({'approved': True})
        self.assertTrue(form.is_valid())
        self.bill.update_by_moderator(form)

        self.bill.data.place.set_modifier(self.bill.data.modifier_id)

        places_logic.save_place(self.bill.data.place)

        self.assertFalse(self.bill.has_meaning())
Beispiel #13
0
    def test_has_meaning__duplicate_description(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.place.description = 'new description'
        places_logic.save_place(self.place)

        self.assertFalse(self.bill.has_meaning())
    def test_has_meaning__duplicate_description(self):
        VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST)
        VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR)

        data = self.bill.user_form_initials
        data['approved'] = True
        form = self.bill.data.get_moderator_form_update(data)

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

        self.place.description = 'new description'
        places_logic.save_place(self.place)

        self.assertFalse(self.bill.has_meaning())
Beispiel #15
0
    def use(self, task, storage, highlevel=None, **kwargs):  # pylint: disable=R0911,W0613

        place_id = task.data.get("place_id")

        if place_id not in places_storage.places:
            return task.logic_result(next_step=UseCardTask.STEP.ERROR, message=u"Город не найден.")

        if task.step.is_LOGIC:
            return task.logic_result(next_step=UseCardTask.STEP.HIGHLEVEL)

        elif task.step.is_HIGHLEVEL:
            place = places_storage.places[place_id]

            place.politic_power.change_power(
                place=place, hero_id=task.hero_id, has_in_preferences=True, power=self.BONUS
            )

            places_logic.save_place(place)
            places_storage.places.update_version()

            return task.logic_result()
Beispiel #16
0
    def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613

        place_id = task.data.get('place_id')

        if place_id not in places_storage.places:
            return task.logic_result(next_step=UseCardTask.STEP.ERROR, message='Город не найден.')

        if task.step.is_LOGIC:
            return task.logic_result(next_step=UseCardTask.STEP.HIGHLEVEL)

        elif task.step.is_HIGHLEVEL:
            place = places_storage.places[place_id]

            place.attrs.keepers_goods += self.GOODS
            place.refresh_attributes()

            places_logic.save_place(place)

            places_storage.places.update_version()

            return task.logic_result()
Beispiel #17
0
    def test_has_meaning__no_master_with_race(self):
        with mock.patch('the_tale.game.persons.objects.Person.race',
                        game_relations.RACE.GOBLIN):
            VotePrototype.create(self.account2, self.bill,
                                 relations.VOTE_TYPE.AGAINST)
            VotePrototype.create(self.account3, self.bill,
                                 relations.VOTE_TYPE.FOR)

            data = self.bill.user_form_initials
            data['approved'] = True
            form = self.bill.data.get_moderator_form_update(data)

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

        self.bill.data.place.race = self.bill.data.new_race

        places_logic.save_place(self.bill.data.place)

        with mock.patch('the_tale.game.persons.objects.Person.race',
                        game_relations.RACE.ELF):
            self.assertFalse(self.bill.has_meaning())
Beispiel #18
0
    def use(self, task, storage, highlevel=None, **kwargs):  # pylint: disable=R0911,W0613

        place_id = task.data.get('place_id')

        if place_id not in places_storage.places:
            return task.logic_result(next_step=UseCardTask.STEP.ERROR,
                                     message='Город не найден.')

        if task.step.is_LOGIC:
            return task.logic_result(next_step=UseCardTask.STEP.HIGHLEVEL)

        elif task.step.is_HIGHLEVEL:
            place = places_storage.places[place_id]

            place.attrs.keepers_goods += self.GOODS
            place.refresh_attributes()

            places_logic.save_place(place)

            places_storage.places.update_version()

            return task.logic_result()
Beispiel #19
0
    def test_move_change_place_coordinates_and_back(self):

        current_time = TimePrototype.get_current_time()

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

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

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

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

        self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE)
        self.assertTrue(not self.hero.position.is_walking)
        self.storage._test_save()
Beispiel #20
0
    def use(self, task, storage, highlevel=None, **kwargs):  # pylint: disable=R0911,W0613

        place_id = task.data.get('place_id')

        if place_id not in places_storage.places:
            return task.logic_result(next_step=UseCardTask.STEP.ERROR,
                                     message='Город не найден.')

        if task.step.is_LOGIC:
            return task.logic_result(next_step=UseCardTask.STEP.HIGHLEVEL)

        elif task.step.is_HIGHLEVEL:
            place = places_storage.places[place_id]

            place.politic_power.change_power(place=place,
                                             hero_id=task.hero_id,
                                             has_in_preferences=True,
                                             power=self.BONUS)

            places_logic.save_place(place)
            places_storage.places.update_version()

            return task.logic_result()
Beispiel #21
0
 def apply(self, bill=None):
     if self.has_meaning():
         self.place.description = self.description
         places_logic.save_place(self.place)
Beispiel #22
0
 def apply(self, bill=None):
     if self.has_meaning():
         self.place.set_utg_name(self.name_forms)
         places_logic.save_place(self.place)
Beispiel #23
0
 def apply(self, bill=None):
     if self.has_meaning():
         self.place.race = self.new_race
         places_logic.save_place(self.place)
Beispiel #24
0
 def apply(self, bill=None):
     if self.has_meaning():
         self.place.set_modifier(self.modifier_id)
         places_logic.save_place(self.place)
 def apply(self, bill=None):
     if self.has_meaning():
         self.place.set_modifier(self.modifier_id)
         places_logic.save_place(self.place)
Beispiel #26
0
 def apply(self, bill=None):
     if self.has_meaning():
         self.place.description = self.description
         places_logic.save_place(self.place)