def create(cls, person, utg_name): from the_tale.game.map.places.storage import buildings_storage building = buildings_storage.get_by_person_id(person.id) if building: return building # remove any destroyed buildings for person cls._model_class.objects.filter(person_id=person.id).delete() x, y = random.choice( list(cls.get_available_positions(person.place.x, person.place.y))) model = Building.objects.create( x=x, y=y, data=s11n.to_json({'name': utg_name.serialize()}), place=person.place._model, person=person._model, state=BUILDING_STATE.WORKING, created_at_turn=TimePrototype.get_current_turn_number(), type=person.type.building_type) prototype = cls(model=model) buildings_storage.add_item(prototype.id, prototype) buildings_storage.update_version() return prototype
def create(cls, person, utg_name): from the_tale.game.map.places.storage import buildings_storage building = buildings_storage.get_by_person_id(person.id) if building: return building # remove any destroyed buildings for person cls._model_class.objects.filter(person_id=person.id).delete() x, y = random.choice(list(cls.get_available_positions(person.place.x, person.place.y))) model = Building.objects.create(x=x, y=y, data=s11n.to_json({'name': utg_name.serialize()}), place=person.place._model, person=person._model, state=BUILDING_STATE.WORKING, created_at_turn=TimePrototype.get_current_turn_number(), type=person.type.building_type) prototype = cls(model=model) buildings_storage.add_item(prototype.id, prototype) buildings_storage.update_version() return prototype
def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613 building_id = task.data.get('building_id') if building_id is None: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if task.step.is_LOGIC: if building_id not in buildings_storage: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) if not buildings_storage[building_id].need_repair: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) if not task.hero.can_repair_building: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) critical = random.uniform(0, 1) < task.hero.might_crit_chance task.data['critical'] = critical task.hero.cards.change_help_count(1) if critical: task.hero.add_message('angel_ability_building_repair_crit', hero=task.hero) else: task.hero.add_message('angel_ability_building_repair', hero=task.hero) return task.logic_result( next_step=ComplexChangeTask.STEP.HIGHLEVEL) elif task.step.is_HIGHLEVEL: if building_id not in buildings_storage: return task.logic_result( next_step=ComplexChangeTask.STEP.ERROR) building = buildings_storage[building_id] building.repair() if task.data.get('critical'): # repair second time building.repair() building.save() buildings_storage.update_version() return task.logic_result(next_step=ComplexChangeTask.STEP.SUCCESS)
def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613 building_id = task.data.get('building_id') if building_id is None: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if task.step.is_LOGIC: if building_id not in buildings_storage: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if not buildings_storage[building_id].need_repair: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) if not task.hero.can_repair_building: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) critical = random.uniform(0, 1) < task.hero.might_crit_chance task.data['critical'] = critical task.hero.cards.change_help_count(1) if critical: task.hero.add_message('angel_ability_building_repair_crit', hero=task.hero) else: task.hero.add_message('angel_ability_building_repair', hero=task.hero) return task.logic_result(next_step=ComplexChangeTask.STEP.HIGHLEVEL) elif task.step.is_HIGHLEVEL: if building_id not in buildings_storage: return task.logic_result(next_step=ComplexChangeTask.STEP.ERROR) building = buildings_storage[building_id] building.repair() if task.data.get('critical'): # repair second time building.repair() building.save() buildings_storage.update_version() return task.logic_result(next_step=ComplexChangeTask.STEP.SUCCESS)
def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613 building_id = task.data.get('building_id') if building_id not in buildings_storage: 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: building = buildings_storage[building_id] while building.need_repair: building.repair() building.save() buildings_storage.update_version() return task.logic_result()
def use(self, task, storage, highlevel=None, **kwargs): # pylint: disable=R0911,W0613 building_id = task.data.get('building_id') if building_id not in buildings_storage: 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: building = buildings_storage[building_id] while building.need_repair: building.repair() building.save() buildings_storage.update_version() return task.logic_result()
def save(self): from the_tale.game.map.places.storage import buildings_storage self._model.data = s11n.to_json(self.data) self._model.save() buildings_storage.update_version()
def destroy(self): from the_tale.game.map.places.storage import buildings_storage self.state = BUILDING_STATE.DESTROYED self.save() buildings_storage.update_version() buildings_storage.refresh()
def save(self): from the_tale.game.map.places.storage import buildings_storage self._model.data = s11n.to_json(self.data) self._model.save() buildings_storage.update_version()
def destroy(self): from the_tale.game.map.places.storage import buildings_storage self.state = BUILDING_STATE.DESTROYED self.save() buildings_storage.update_version() buildings_storage.refresh()