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

        self.person_1_1 = self.place1.persons[0]
        self.person_2_1, self.person_2_2 = self.place2.persons[0:2]
        self.person_3_1 = self.place3.persons[0]

        self.account = self.accounts_factory.create_account()

        politic_power_logic.add_power_impacts(persons_logic.tt_power_impacts(person_inner_circle=True,
                                                                             place_inner_circle=True,
                                                                             actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                                                                             actor_id=self.account.id,
                                                                             person=self.person_1_1,
                                                                             amount=100,
                                                                             fame=0))
        politic_power_logic.add_power_impacts(persons_logic.tt_power_impacts(person_inner_circle=True,
                                                                             place_inner_circle=True,
                                                                             actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                                                                             actor_id=self.account.id,
                                                                             person=self.person_2_2,
                                                                             amount=100,
                                                                             fame=0))

        persons_logic.create_social_connection(connection_type=persons_relations.SOCIAL_CONNECTION_TYPE.PARTNER,
                                               person_1=self.person_1_1,
                                               person_2=self.person_2_1)

        self.bill_data = PersonRemoveSocialConnection(person_1_id=self.person_1_1.id,
                                                      person_2_id=self.person_2_1.id)
        self.bill = BillPrototype.create(self.account1, 'bill-1-caption', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
Exemplo n.º 2
0
    def setUp(self):
        super(PersonMoveTests, self).setUp()

        self.person_1, self.person_2, self.person_3 = self.place1.persons[0:3]

        self.account = self.accounts_factory.create_account()

        politic_power_logic.add_power_impacts(
            persons_logic.tt_power_impacts(
                person_inner_circle=True,
                place_inner_circle=True,
                actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                actor_id=self.account.id,
                person=self.person_1,
                amount=100,
                fame=0))

        politic_power_logic.add_power_impacts(
            persons_logic.tt_power_impacts(
                person_inner_circle=True,
                place_inner_circle=True,
                actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                actor_id=self.account.id,
                person=self.person_2,
                amount=100,
                fame=0))

        self.bill_data = PersonMove(person_id=self.person_1.id,
                                    new_place_id=self.place2.id)
        self.bill = BillPrototype.create(
            self.account1,
            'bill-1-caption',
            self.bill_data,
            chronicle_on_accepted='chronicle-on-accepted')
Exemplo n.º 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='Город не найден.')

        impacts = [
            tt_api_impacts.PowerImpact.hero_2_place(
                type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE,
                hero_id=task.hero.id,
                place_id=place_id,
                amount=delta)
        ]

        politic_power_logic.add_power_impacts(impacts)

        return task.logic_result(message='Влияние города изменено.')
Exemplo n.º 4
0
    def _finish_quest(self, finish, hero):

        experience = self.current_info.experience
        experience_bonus = self.current_info.experience_bonus

        hero.add_experience(experience)
        hero.add_experience(experience_bonus, without_modifications=True)

        hero.statistics.change_quests_done(1)

        if hero.companion:
            hero.companion.add_experience(c.COMPANIONS_COHERENCE_EXP_PER_QUEST)

        power_impacts = []

        for object_uid, result in finish.results.items():

            object_fact = self.knowledge_base[object_uid]

            if isinstance(object_fact, facts.Person):
                person_id = object_fact.externals['id']

                if result == QUEST_RESULTS.FAILED:
                    hero.quests.add_interfered_person(person_id)

                person_habits_change_source = persons_storage.persons[
                    person_id].attrs.on_quest_habits.get(result)

                if person_habits_change_source:
                    self.hero.update_habits(person_habits_change_source)

                power = self.finish_quest_person_power(result, object_uid)

                power_impacts.extend(
                    persons_logic.impacts_from_hero(
                        self.hero, persons_storage.persons[person_id], power))

            elif isinstance(object_fact, facts.Place):
                power = self.finish_quest_place_power(result, object_uid)

                power_impacts.extend(
                    places_logic.impacts_from_hero(
                        self.hero,
                        places_storage.places[object_fact.externals['id']],
                        power))

            else:
                raise exceptions.UnknownPowerRecipientError(
                    recipient=object_fact)

        politic_power_logic.add_power_impacts(power_impacts)

        for marker, default in self.current_info.used_markers.items():
            for change_source in HABIT_CHANGE_SOURCE.records:
                if change_source.quest_marker == marker and change_source.quest_default == default:
                    self.hero.update_habits(change_source)

        self.quests_stack.pop()
Exemplo n.º 5
0
 def give_power_to_place(self, place, power, fame):
     impacts = places_logic.tt_power_impacts(
         inner_circle=False,
         actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
         actor_id=666,
         place=place,
         amount=power,
         fame=fame)
     politic_power_logic.add_power_impacts(impacts)
Exemplo n.º 6
0
def update_job(job, actor_id):

    power = job.load_power(actor_id)

    if not job.is_completed(power):
        return ()

    inner_circle = job.load_inner_circle(actor_id)

    job_effect = job.get_apply_effect_method(power)

    effect_kwargs = {
        'actor_type': 'place',
        'actor_name': job.get_project_name(actor_id),
        'positive_heroes': inner_circle.positive_heroes,
        'negative_heroes': inner_circle.negative_heroes,
        'job_power': job.get_job_power(actor_id)
    }

    effect_kwargs.update(job.get_objects(actor_id))

    after_update_operations = job_effect(**effect_kwargs)

    effects_priorities = dict(job.get_effects_priorities(actor_id))

    if job.effect in effects_priorities:
        del effects_priorities[job.effect]

    new_effect = utils_logic.random_value_by_priority(
        effects_priorities.items())

    if power.positive > power.negative:
        impact = tt_api_impacts.PowerImpact(
            type=tt_api_impacts.IMPACT_TYPE.JOB,
            actor_type=job.ACTOR_TYPE,
            actor_id=actor_id,
            target_type=job.POSITIVE_TARGET_TYPE,
            target_id=actor_id,
            amount=-power.positive)
    else:
        impact = tt_api_impacts.PowerImpact(
            type=tt_api_impacts.IMPACT_TYPE.JOB,
            actor_type=job.ACTOR_TYPE,
            actor_id=actor_id,
            target_type=job.NEGATIVE_TARGET_TYPE,
            target_id=actor_id,
            amount=-power.negative)

    politic_power_logic.add_power_impacts([impact])

    job.name = create_name(job.ACTOR, new_effect)
    job.created_at_turn = turn.number()
    job.effect = new_effect
    job.power_required = job.NORMAL_POWER * new_effect.power_modifier

    return after_update_operations
Exemplo n.º 7
0
def add_fame(hero_id, fames):
    impacts = []

    for place_id, fame in fames:
        impacts.append(
            tt_api_impacts.PowerImpact(
                type=tt_api_impacts.IMPACT_TYPE.FAME,
                actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                actor_id=hero_id,
                target_type=tt_api_impacts.OBJECT_TYPE.PLACE,
                target_id=place_id,
                amount=fame))

    politic_power_logic.add_power_impacts(impacts)
Exemplo n.º 8
0
    def apply(self, bill=None):
        if not self.has_meaning():
            return

        if self.power_bonus.bonus == 0:
            return

        impacts = list(
            places_logic.tt_power_impacts(
                inner_circle=False,
                actor_type=tt_api_impacts.OBJECT_TYPE.BILL,
                actor_id=bill.id,
                place=self.place,
                amount=self.power_bonus.bonus,
                fame=0))

        politic_power_logic.add_power_impacts(impacts)
Exemplo n.º 9
0
    def test_apply_effects(self):
        hero_id = self.accounts_factory.create_account().id

        politic_power_logic.add_power_impacts([tt_api_impacts.PowerImpact(type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE,
                                                                          actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                                                                          actor_id=hero_id,
                                                                          target_type=tt_api_impacts.OBJECT_TYPE.PLACE,
                                                                          target_id=self.place_1.id,
                                                                          amount=1)])

        self.give_power([(hero_id, self.job.power_required)])

        operations = logic.update_job(self.job, self.place_1.id)

        self.assertTrue(operations)

        for operation in operations:
            operation()
Exemplo n.º 10
0
    def give_power(self, impacts):
        impacts_to_apply = []

        for hero_id, impact in impacts:
            if impact > 0:
                impacts_to_apply.append(tt_api_impacts.PowerImpact(type=tt_api_impacts.IMPACT_TYPE.JOB,
                                                                   actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                                                                   actor_id=hero_id,
                                                                   target_type=self.job.POSITIVE_TARGET_TYPE,
                                                                   target_id=self.place_1.id,
                                                                   amount=impact))
            else:
                impacts_to_apply.append(tt_api_impacts.PowerImpact(type=tt_api_impacts.IMPACT_TYPE.JOB,
                                                                   actor_type=tt_api_impacts.OBJECT_TYPE.HERO,
                                                                   actor_id=hero_id,
                                                                   target_type=self.job.NEGATIVE_TARGET_TYPE,
                                                                   target_id=self.place_1.id,
                                                                   amount=-impact))

        politic_power_logic.add_power_impacts(impacts_to_apply)
Exemplo n.º 11
0
    def setUp(self):
        super(RacesTests, self).setUp()
        self.p1, self.p2, self.p3 = game_logic.create_test_map()

        for person in persons_storage.persons.all():
            politic_power_logic.add_power_impacts([
                tt_api_impacts.PowerImpact.hero_2_person(
                    type=tt_api_impacts.IMPACT_TYPE.OUTER_CIRCLE,
                    hero_id=666,
                    person_id=person.id,
                    amount=1000),
                tt_api_impacts.PowerImpact.hero_2_person(
                    type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE,
                    hero_id=777,
                    person_id=person.id,
                    amount=2000)
            ])
            person.attrs.demographics_pressure = 1

        politic_power_storage.persons.reset()