Ejemplo n.º 1
0
    def save(self):
        from the_tale.game.persons.storage import persons_storage

        self._model.data = s11n.to_json(self.data)
        self._model.save()

        persons_storage.update_version()
Ejemplo n.º 2
0
    def save(self):
        from the_tale.game.persons.storage import persons_storage

        self._model.data = s11n.to_json(self.data)
        self._model.save()

        persons_storage.update_version()
Ejemplo n.º 3
0
    def create_place(self, x, y, size, roads_to, persons=(), name_forms=None, is_frontier=False): # pylint: disable=R0914

        place_power = int(max(place.power for place in places_storage.all()) * float(size) / places_settings.MAX_SIZE)

        place_power_steps = int(places_settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
        place_power_per_step = (place_power / place_power_steps) + 1

        place = PlacePrototype.create( x=x,
                                       y=y,
                                       utg_name=name_forms.word,
                                       is_frontier=is_frontier,
                                       size=size)

        initial_turn = TimePrototype.get_current_turn_number() - places_settings.POWER_HISTORY_LENGTH
        for i in xrange(place_power_steps):
            place.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(place_power_per_step))

        for person_name_forms, power_percent, race, gender, tp in persons:
            person = PersonPrototype.create(place=place,
                                            race=race,
                                            gender=gender,
                                            tp=tp,
                                            name_forms=person_name_forms)

            person_power = place_power * power_percent
            person_power_steps = int(persons_conf.settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
            person_power_per_step = (person_power / person_power_steps) + 1
            initial_turn = TimePrototype.get_current_turn_number() - persons_conf.settings.POWER_HISTORY_LENGTH
            for i in xrange(person_power_steps):
                person.push_power(int(initial_turn+i*c.MAP_SYNC_TIME), int(person_power_per_step))
            person.save()

        place.sync_persons(force_add=True)

        power_delta = self.INITIAL_PERSON_POWER

        for person in place.persons:
            person.fill_power_evenly(power_delta)
            person.save()
            power_delta /= 2

        place.sync_race()
        place.save()

        for destination in roads_to:
            Road.objects.create(point_1=place._model, point_2=destination._model)

        persons_storage.update_version()
        places_storage.update_version()
        roads_storage.update_version()

        persons_storage.refresh()
        places_storage.refresh()
        roads_storage.refresh()

        return place
Ejemplo n.º 4
0
    def create(cls, place, race, tp, utg_name, gender, state=None):
        from the_tale.game.persons.storage import persons_storage

        instance = Person.objects.create(place=place._model,
                                         state=state if state is not None else PERSON_STATE.IN_GAME,
                                         race=race,
                                         type=tp,
                                         gender=gender,
                                         name=utg_name.normal_form(),
                                         data=s11n.to_json({'name': utg_name.serialize()}),
                                         created_at_turn=TimePrototype.get_current_turn_number())

        prototype = cls(model=instance)

        persons_storage.add_item(prototype.id, prototype)
        persons_storage.update_version()

        prototype.place.persons_changed_at_turn = TimePrototype.get_current_turn_number()

        return prototype
Ejemplo n.º 5
0
    def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613

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

        if person_id not in persons_storage:
            return task.logic_result(next_step=UseCardTask.STEP.ERROR, message=u'Советник не найден.')

        person = persons_storage[person_id]

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

        elif task.step.is_HIGHLEVEL:

            person.push_power_positive(TimePrototype.get_current_turn_number(), self.BONUS)

            person.save()

            persons_storage.update_version()

            return task.logic_result()
Ejemplo n.º 6
0
    def create(cls, place, race, tp, utg_name, gender, state=None):
        from the_tale.game.persons.storage import persons_storage

        instance = Person.objects.create(
            place=place._model,
            state=state if state is not None else PERSON_STATE.IN_GAME,
            race=race,
            type=tp,
            gender=gender,
            name=utg_name.normal_form(),
            data=s11n.to_json({'name': utg_name.serialize()}),
            created_at_turn=TimePrototype.get_current_turn_number())

        prototype = cls(model=instance)

        persons_storage.add_item(prototype.id, prototype)
        persons_storage.update_version()

        prototype.place.persons_changed_at_turn = TimePrototype.get_current_turn_number(
        )

        return prototype
Ejemplo n.º 7
0
    def use(self, task, storage, highlevel=None, **kwargs):  # pylint: disable=R0911,W0613

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

        if person_id not in persons_storage:
            return task.logic_result(next_step=UseCardTask.STEP.ERROR,
                                     message=u'Советник не найден.')

        person = persons_storage[person_id]

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

        elif task.step.is_HIGHLEVEL:

            person.push_power_positive(TimePrototype.get_current_turn_number(),
                                       self.BONUS)

            person.save()

            persons_storage.update_version()

            return task.logic_result()
Ejemplo n.º 8
0
    def create_map(self): # pylint: disable=R0914, R0915

        Place.objects.all().delete()
        Road.objects.all().delete()

        p1x1   = self.create_place(1,  1,  size=1)
        p14x1  = self.create_place(14, 1,  size=1)
        p27x1  = self.create_place(27, 1,  size=6)
        p5x3   = self.create_place(5,  3,  size=5)
        p1x9   = self.create_place(1,  9,  size=6)
        p5x12  = self.create_place(5,  12, size=1)
        p3x17  = self.create_place(3,  17, size=10)
        p10x18 = self.create_place(10, 18, size=3)
        p11x11 = self.create_place(11, 11, size=4)
        p11x6  = self.create_place(11, 6,  size=4)
        p19x5  = self.create_place(19, 5,  size=3)
        p20x8  = self.create_place(20, 8,  size=9)
        p24x8  = self.create_place(24, 8,  size=10)
        p17x12 = self.create_place(17, 12, size=2)
        p19x17 = self.create_place(19, 17, size=8)
        p24x13 = self.create_place(24, 13, size=1)
        p27x13 = self.create_place(27, 13, size=1)
        p28x19 = self.create_place(28, 19, size=3)

        self.create_road(p1x1,   p5x3)
        self.create_road(p5x3,   p1x9)
        self.create_road(p5x3,   p11x6)
        self.create_road(p1x9,   p5x12)
        self.create_road(p5x12,  p3x17)
        self.create_road(p5x12,  p11x11)
        self.create_road(p3x17,  p10x18)
        self.create_road(p11x11, p10x18)
        self.create_road(p11x11, p11x6)
        self.create_road(p11x11, p19x17)
        self.create_road(p11x11, p17x12)
        self.create_road(p11x11, p20x8)
        self.create_road(p11x6,  p14x1)
        self.create_road(p14x1,  p27x1)
        self.create_road(p27x1,  p24x8)
        self.create_road(p24x8,  p20x8)
        self.create_road(p24x8,  p24x13)
        self.create_road(p24x8,  p27x13)
        self.create_road(p20x8,  p19x5)
        self.create_road(p20x8,  p17x12)
        self.create_road(p19x17, p24x13)
        self.create_road(p28x19, p24x13)
        self.create_road(p28x19, p27x13)

        places_storage.update_version()
        roads_storage.update_version()

        for place in places_storage.all():
            place.sync_persons(force_add=True)

        persons_storage.update_version()

        terrain = []
        for y in xrange(0, map_settings.HEIGHT): # pylint: disable=W0612
            row = []
            terrain.append(row)
            for x in xrange(0, map_settings.WIDTH): # pylint: disable=W0612
                row.append(TERRAIN.PLANE_GREENWOOD)

        map_info_storage.set_item(MapInfoPrototype.create(turn_number=0,
                                                          width=map_settings.WIDTH,
                                                          height=map_settings.HEIGHT,
                                                          terrain=terrain,
                                                          world=WorldInfoPrototype.create(w=map_settings.WIDTH, h=map_settings.HEIGHT)))

        map_info_storage.update_version()
Ejemplo n.º 9
0
    def create_place(self,
                     x,
                     y,
                     size,
                     roads_to,
                     persons=(),
                     name_forms=None,
                     is_frontier=False):  # pylint: disable=R0914

        place_power = int(
            max(place.power for place in places_storage.all()) * float(size) /
            places_settings.MAX_SIZE)

        place_power_steps = int(places_settings.POWER_HISTORY_LENGTH /
                                c.MAP_SYNC_TIME)
        place_power_per_step = (place_power / place_power_steps) + 1

        place = PlacePrototype.create(x=x,
                                      y=y,
                                      utg_name=name_forms.word,
                                      is_frontier=is_frontier,
                                      size=size)

        initial_turn = TimePrototype.get_current_turn_number(
        ) - places_settings.POWER_HISTORY_LENGTH
        for i in xrange(place_power_steps):
            place.push_power(int(initial_turn + i * c.MAP_SYNC_TIME),
                             int(place_power_per_step))

        for person_name_forms, power_percent, race, gender, tp in persons:
            person = PersonPrototype.create(place=place,
                                            race=race,
                                            gender=gender,
                                            tp=tp,
                                            name_forms=person_name_forms)

            person_power = place_power * power_percent
            person_power_steps = int(
                persons_conf.settings.POWER_HISTORY_LENGTH / c.MAP_SYNC_TIME)
            person_power_per_step = (person_power / person_power_steps) + 1
            initial_turn = TimePrototype.get_current_turn_number(
            ) - persons_conf.settings.POWER_HISTORY_LENGTH
            for i in xrange(person_power_steps):
                person.push_power(int(initial_turn + i * c.MAP_SYNC_TIME),
                                  int(person_power_per_step))
            person.save()

        place.sync_persons(force_add=True)

        power_delta = self.INITIAL_PERSON_POWER

        for person in place.persons:
            person.fill_power_evenly(power_delta)
            person.save()
            power_delta /= 2

        place.sync_race()
        place.save()

        for destination in roads_to:
            Road.objects.create(point_1=place._model,
                                point_2=destination._model)

        persons_storage.update_version()
        places_storage.update_version()
        roads_storage.update_version()

        persons_storage.refresh()
        places_storage.refresh()
        roads_storage.refresh()

        return place
Ejemplo n.º 10
0
    def create_map(self):  # pylint: disable=R0914, R0915

        Place.objects.all().delete()
        Road.objects.all().delete()

        p1x1 = self.create_place(1, 1, size=1)
        p14x1 = self.create_place(14, 1, size=1)
        p27x1 = self.create_place(27, 1, size=6)
        p5x3 = self.create_place(5, 3, size=5)
        p1x9 = self.create_place(1, 9, size=6)
        p5x12 = self.create_place(5, 12, size=1)
        p3x17 = self.create_place(3, 17, size=10)
        p10x18 = self.create_place(10, 18, size=3)
        p11x11 = self.create_place(11, 11, size=4)
        p11x6 = self.create_place(11, 6, size=4)
        p19x5 = self.create_place(19, 5, size=3)
        p20x8 = self.create_place(20, 8, size=9)
        p24x8 = self.create_place(24, 8, size=10)
        p17x12 = self.create_place(17, 12, size=2)
        p19x17 = self.create_place(19, 17, size=8)
        p24x13 = self.create_place(24, 13, size=1)
        p27x13 = self.create_place(27, 13, size=1)
        p28x19 = self.create_place(28, 19, size=3)

        self.create_road(p1x1, p5x3)
        self.create_road(p5x3, p1x9)
        self.create_road(p5x3, p11x6)
        self.create_road(p1x9, p5x12)
        self.create_road(p5x12, p3x17)
        self.create_road(p5x12, p11x11)
        self.create_road(p3x17, p10x18)
        self.create_road(p11x11, p10x18)
        self.create_road(p11x11, p11x6)
        self.create_road(p11x11, p19x17)
        self.create_road(p11x11, p17x12)
        self.create_road(p11x11, p20x8)
        self.create_road(p11x6, p14x1)
        self.create_road(p14x1, p27x1)
        self.create_road(p27x1, p24x8)
        self.create_road(p24x8, p20x8)
        self.create_road(p24x8, p24x13)
        self.create_road(p24x8, p27x13)
        self.create_road(p20x8, p19x5)
        self.create_road(p20x8, p17x12)
        self.create_road(p19x17, p24x13)
        self.create_road(p28x19, p24x13)
        self.create_road(p28x19, p27x13)

        places_storage.update_version()
        roads_storage.update_version()

        for place in places_storage.all():
            place.sync_persons(force_add=True)

        persons_storage.update_version()

        terrain = []
        for y in xrange(0, map_settings.HEIGHT):  # pylint: disable=W0612
            row = []
            terrain.append(row)
            for x in xrange(0, map_settings.WIDTH):  # pylint: disable=W0612
                row.append(TERRAIN.PLANE_GREENWOOD)

        map_info_storage.set_item(
            MapInfoPrototype.create(turn_number=0,
                                    width=map_settings.WIDTH,
                                    height=map_settings.HEIGHT,
                                    terrain=terrain,
                                    world=WorldInfoPrototype.create(
                                        w=map_settings.WIDTH,
                                        h=map_settings.HEIGHT)))

        map_info_storage.update_version()