def create(cls, uuid, level, utg_name, description, abilities, terrains, type, archetype=game_relations.ARCHETYPE.NEUTRAL, editor=None, state=MOB_RECORD_STATE.DISABLED, global_action_probability=0): from the_tale.game.mobs.storage import mobs_storage model = MobRecord.objects.create(uuid=uuid, level=level, name=utg_name.normal_form(), type=type, archetype=archetype, data=s11n.to_json({'name': utg_name.serialize(), 'global_action_probability': global_action_probability}), description=description, abilities=s11n.to_json(list(abilities)), terrains=s11n.to_json([terrain.value for terrain in terrains]), state=state, editor=editor._model if editor else None) prototype = cls(model) linguistics_logic.sync_restriction(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=prototype.id, name=prototype.name) mobs_storage.add_item(prototype.id, prototype) mobs_storage.update_version() return prototype
def quest_test_method(self): # defends from first quest rule self.hero.statistics.change_quests_done(1) heroes_logic.save_hero(self.hero) test_upgrade_equipment = random.randint( 0, 1) # test child quest or upgrade equipment for SearchSmith while self.hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests: if quest == SearchSmith and test_upgrade_equipment: self.hero.money = QuestPrototype.upgrade_equipment_cost( self.hero) * 2 self.hero.next_spending = heroes_relations.ITEMS_OF_EXPENDITURE.INSTANT_HEAL self.storage.process_turn() turn.increment() # test if quest is serializable s11n.to_json(self.hero.quests.current_quest.serialize()) self.complete_quest() self.assertEqual(self.hero.actions.current_action.TYPE, ActionIdlenessPrototype.TYPE) if quest == SearchSmith and test_upgrade_equipment: self.assertTrue( self.hero.statistics.money_spend_for_artifacts > 0 or self.hero.statistics.money_spend_for_sharpening > 0)
def quest_test_method(self): # defends from first quest rule self.hero.statistics.change_quests_done(1) self.hero.save() current_time = TimePrototype.get_current_time() test_upgrade_equipment = random.randint(0, 1) # test child quest or upgrade equipment for SearchSmith while self.hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests: if quest == SearchSmith and test_upgrade_equipment: self.hero._model.money = QuestPrototype.upgrade_equipment_cost(self.hero) * 2 self.hero._model.next_spending = ITEMS_OF_EXPENDITURE.INSTANT_HEAL self.storage.process_turn() current_time.increment_turn() # test if quest is serializable s11n.to_json(self.hero.quests.current_quest.serialize()) self.complete_quest() self.assertEqual(self.hero.actions.current_action.TYPE, ActionIdlenessPrototype.TYPE) if quest == SearchSmith and test_upgrade_equipment: self.assertTrue(self.hero.statistics.money_spend_for_artifacts > 0 or self.hero.statistics.money_spend_for_sharpening > 0)
def create( cls, uuid, level, utg_name, description, abilities, terrains, type, archetype=game_relations.ARCHETYPE.NEUTRAL, editor=None, state=relations.MOB_RECORD_STATE.DISABLED, global_action_probability=0, communication_verbal=game_relations.COMMUNICATION_VERBAL.CAN_NOT, communication_gestures=game_relations.COMMUNICATION_GESTURES. CAN_NOT, communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC. CAN_NOT, intellect_level=game_relations.INTELLECT_LEVEL.NONE, is_mercenary=True, is_eatable=True): from the_tale.game.mobs.storage import mobs_storage model = models.MobRecord.objects.create( uuid=uuid, level=level, name=utg_name.normal_form(), type=type, archetype=archetype, data=s11n.to_json({ 'name': utg_name.serialize(), 'global_action_probability': global_action_probability }), description=description, abilities=s11n.to_json(list(abilities)), terrains=s11n.to_json([terrain.value for terrain in terrains]), state=state, editor=editor._model if editor else None, communication_verbal=communication_verbal, communication_gestures=communication_gestures, communication_telepathic=communication_telepathic, intellect_level=intellect_level, is_mercenary=is_mercenary, is_eatable=is_eatable) prototype = cls(model) linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=prototype.id, name=prototype.name) mobs_storage.add_item(prototype.id, prototype) mobs_storage.update_version() return prototype
def create(cls, turn_number, width, height, terrain, world): # pylint: disable=R0914 from the_tale.game.map.generator.descriptors import UICells terrain_percents = {} terrain_squares = collections.defaultdict(int) for y in range(0, height): for x in range(0, width): cell = world.generator.cell_info(x, y) if cell.height < -0.2: terrain_squares[MAP_STATISTICS.LOWLANDS] += 1 elif cell.height < 0.3: terrain_squares[MAP_STATISTICS.PLAINS] += 1 else: terrain_squares[MAP_STATISTICS.UPLANDS] += 1 if cell.vegetation == VEGETATION_TYPE.DESERT: terrain_squares[MAP_STATISTICS.DESERTS] += 1 elif cell.vegetation == VEGETATION_TYPE.GRASS: terrain_squares[MAP_STATISTICS.GRASS] += 1 else: terrain_squares[MAP_STATISTICS.FORESTS] += 1 total_cells = width * height terrain_percents = dict((id_.value, float(square) / total_cells) for id_, square in terrain_squares.items()) person_race_percents = get_person_race_percents( persons_storage.persons.all()) race_percents = get_race_percents(places_storage.places.all()) #race to cities percents race_cities = dict((race.value, 0) for race in RACE.records) for place_model in Place.objects.all(): place = places_logic.load_place(place_model=place_model) race_cities[place.race.value] += 1 statistics = { 'terrain_percents': terrain_percents, 'person_race_percents': person_race_percents, 'race_percents': race_percents, 'race_cities': race_cities } model = MapInfo.objects.create( turn_number=turn_number, width=width, height=height, terrain=s11n.to_json([[cell.value for cell in row] for row in terrain]), cells=s11n.to_json(UICells.create(world.generator).serialize()), world=world._model, statistics=s11n.to_json(statistics)) return cls(model)
def save(self): self._model.saved_at_turn = TimePrototype.get_current_turn_number() self._model.saved_at = datetime.datetime.now() self.serialize_companion() self._model.data = s11n.to_json(self.data) if self.bag.updated: self.bag.serialize() if self.equipment.updated: self._model.raw_power_physic = self.power.physic self._model.raw_power_magic = self.power.magic self.equipment.serialize() if self.abilities.updated: self.abilities.serialize() if self.places_history.updated: self.places_history.serialize() if self.cards.updated: self.cards.serialize() if self.messages.updated: self._model.messages = s11n.to_json(self.messages.serialize()) self.messages.updated = False if self.diary.updated: self.diary.serialize() if self.actions.updated: self.actions.on_save() self._model.actions = s11n.to_json(self.actions.serialize()) self.actions.updated = False if self.quests.updated: self._model.quest_created_time = self.quests.min_quest_created_time self.quests.serialize() if self.pvp.updated: self.pvp.serialize() if self.preferences.updated: self._model.preferences = s11n.to_json( self.preferences.serialize()) self.preferences.updated = False self._model.stat_politics_multiplier = self.politics_power_multiplier( ) if self.can_change_all_powers() else 0 database.raw_save(self._model)
def save(self): self._model.saved_at_turn = TimePrototype.get_current_turn_number() self._model.saved_at = datetime.datetime.now() self.serialize_companion() self._model.data = s11n.to_json(self.data) if self.bag.updated: self.bag.serialize() if self.equipment.updated: self._model.raw_power_physic = self.power.physic self._model.raw_power_magic = self.power.magic self.equipment.serialize() if self.abilities.updated: self.abilities.serialize() if self.places_history.updated: self.places_history.serialize() if self.cards.updated: self.cards.serialize() if self.messages.updated: self._model.messages = s11n.to_json(self.messages.serialize()) self.messages.updated = False if self.diary.updated: self.diary.serialize() if self.actions.updated: self.actions.on_save() self._model.actions = s11n.to_json(self.actions.serialize()) self.actions.updated = False if self.quests.updated: self._model.quest_created_time = self.quests.min_quest_created_time self.quests.serialize() if self.pvp.updated: self.pvp.serialize() if self.preferences.updated: self._model.preferences = s11n.to_json(self.preferences.serialize()) self.preferences.updated = False self._model.stat_politics_multiplier = self.politics_power_multiplier() if self.can_change_all_powers() else 0 database.raw_save(self._model)
def create(cls, turn_number, width, height, terrain, world): # pylint: disable=R0914 from the_tale.game.map.generator.descriptors import UICells terrain_percents = {} terrain_squares = collections.defaultdict(int) for y in xrange(0, height): for x in xrange(0, width): cell = world.generator.cell_info(x, y) if cell.height < -0.2: terrain_squares[MAP_STATISTICS.LOWLANDS] += 1 elif cell.height < 0.3: terrain_squares[MAP_STATISTICS.PLAINS] += 1 else: terrain_squares[MAP_STATISTICS.UPLANDS] += 1 if cell.vegetation == VEGETATION_TYPE.DESERT: terrain_squares[MAP_STATISTICS.DESERTS] += 1 elif cell.vegetation == VEGETATION_TYPE.GRASS: terrain_squares[MAP_STATISTICS.GRASS] += 1 else: terrain_squares[MAP_STATISTICS.FORESTS] += 1 total_cells = width * height terrain_percents = dict( (id_.value, float(square) / total_cells) for id_, square in terrain_squares.items()) person_race_percents = get_person_race_percents(persons_storage.filter(state=PERSON_STATE.IN_GAME)) race_percents = get_race_percents(places_storage.all()) #race to cities percents race_cities = dict( (race.value, 0) for race in RACE.records) for place_model in Place.objects.all(): place = PlacePrototype(place_model) race_cities[place.race.value] += 1 statistics = {'terrain_percents': terrain_percents, 'person_race_percents': person_race_percents, 'race_percents': race_percents, 'race_cities': race_cities} model = MapInfo.objects.create(turn_number=turn_number, width=width, height=height, terrain=s11n.to_json([ [cell.value for cell in row] for row in terrain]), cells=s11n.to_json(UICells.create(world.generator).serialize()), world=world._model, statistics=s11n.to_json(statistics)) return cls(model)
def create_mob_record(uuid, level, utg_name, description, abilities, terrains, type, archetype, editor, state, communication_verbal, communication_gestures, communication_telepathic, intellect_level, structure, features, movement, body, size, orientation, weapons, is_mercenary, is_eatable): from the_tale.game.mobs import storage data = { 'name': utg_name.serialize(), 'structure': structure.value, 'features': [feature.value for feature in features], 'movement': movement.value, 'body': body.value, 'size': size.value, 'orientation': orientation.value, 'weapons': [weapon.serialize() for weapon in weapons] } model = models.MobRecord.objects.create( uuid=uuid, level=level, name=utg_name.normal_form(), type=type, archetype=archetype, data=s11n.to_json(data), description=description, abilities=s11n.to_json(list(abilities)), terrains=s11n.to_json([terrain.value for terrain in terrains]), state=state, editor_id=editor.id if editor else None, communication_verbal=communication_verbal, communication_gestures=communication_gestures, communication_telepathic=communication_telepathic, intellect_level=intellect_level, is_mercenary=is_mercenary, is_eatable=is_eatable) mob_record = construct_from_model(model) linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=mob_record.id, name=mob_record.name) storage.mobs.add_item(mob_record.id, mob_record) storage.mobs.update_version() return mob_record
def create_companion_record(utg_name, description, type, max_health, dedication, archetype, mode, abilities, state=relations.STATE.DISABLED): model = models.CompanionRecord.objects.create(state=state, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, data=s11n.to_json({ 'description': description, 'name': utg_name.serialize(), 'abilities': abilities.serialize() })) companion_record = objects.CompanionRecord.from_model(model) storage.companions.add_item(companion_record.id, companion_record) storage.companions.update_version() linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION, external_id=companion_record.id, name=companion_record.name) return companion_record
def save(self): self._model.internal_data = s11n.to_json( self.internal_logic.serialize()) self._model.internal_state = self._model.internal_state if isinstance( self._model.internal_state, int) else self._model.internal_state.value self._model.save()
def handle(self, *args, **options): info = currencies.get_currencies_info(project_settings.CURRENCIES_BASE, project_settings.CURRENCIES_LIST) settings[portal_settings.SETTINGS_CURRENCIES_INFO_KEY] = s11n.to_json( info)
def update_companion_record(companion, utg_name, description, type, max_health, dedication, archetype, mode, abilities): companion.set_utg_name(utg_name) companion.description = description companion.type = type companion.max_health = max_health companion.dedication = dedication companion.archetype = archetype companion.mode = mode companion.abilities = abilities models.CompanionRecord.objects.filter(id=companion.id).update( state=companion.state, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, data=s11n.to_json({ 'description': description, 'name': utg_name.serialize(), 'abilities': abilities.serialize() }), updated_at=datetime.datetime.now()) storage.companions.update_version() linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION, external_id=companion.id, name=companion.name)
def handle(self, *args, **options): print 'refresh CDNs' info = cdn.get_cdns_info(project_settings.CDNS) settings[portal_settings.SETTINGS_CDN_INFO_KEY] = s11n.to_json(info)
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()
def save_building(building, new=False): from the_tale.game.places import storage data = {'name': building.utg_name.serialize()} arguments = { 'x': building.x, 'y': building.y, 'created_at_turn': building.created_at_turn, 'state': building.state, 'type': building.type, 'integrity': building.integrity, 'place_id': building.place.id, 'person_id': building.person.id, 'data': s11n.to_json(data) } if new: building_model = models.Building.objects.create(**arguments) building.id = building_model.id storage.buildings.add_item(building.id, building) else: models.Building.objects.filter(id=building.id).update(**arguments) storage.buildings.update_version()
def update_companion_record(companion, utg_name, description, type, max_health, dedication, archetype, mode, abilities): companion.set_utg_name(utg_name) companion.description = description companion.type = type companion.max_health = max_health companion.dedication = dedication companion.archetype = archetype companion.mode = mode companion.abilities = abilities models.CompanionRecord.objects.filter(id=companion.id).update(state=companion.state, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, data=s11n.to_json({'description': description, 'name': utg_name.serialize(), 'abilities': abilities.serialize()}), updated_at=datetime.datetime.now()) storage.companions.update_version() linguistics_logic.sync_restriction(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION, external_id=companion.id, name=companion.name)
def create(cls, owner, caption, rationale, bill, chronicle_on_accepted): model = Bill.objects.create(owner=owner._model, type=bill.type, caption=caption, rationale=rationale, created_at_turn=TimePrototype.get_current_turn_number(), technical_data=s11n.to_json(bill.serialize()), state=BILL_STATE.VOTING, chronicle_on_accepted=chronicle_on_accepted, votes_for=1) # author always wote for bill bill_prototype = cls(model) text = u'Обсуждение [url="%s%s"]закона[/url]' % (project_settings.SITE_URL, reverse('game:bills:show', args=[model.id]) ) thread = ThreadPrototype.create(SubCategoryPrototype.get_by_uid(bills_settings.FORUM_CATEGORY_UID), caption=caption, author=get_system_user(), text=bill_prototype.bill_info_text(text), technical=True, markup_method=MARKUP_METHOD.POSTMARKUP) model.forum_thread = thread._model model.save() ActorPrototype.update_actors(bill_prototype, bill_prototype.data.actors) VotePrototype.create(owner, bill_prototype, VOTE_TYPE.FOR) signals.bill_created.send(sender=cls, bill=bill_prototype) return bill_prototype
def create(cls, storage, hero_1, hero_2, bundle_id): cls.prepair_bot(hero_1, hero_2) cls.prepair_bot(hero_2, hero_1) hero_1_old_health = hero_1.health hero_2_old_health = hero_2.health hero_1.health = hero_1.max_health cls.reset_hero_info(hero_1) hero_2.health = hero_2.max_health cls.reset_hero_info(hero_2) with transaction.atomic(): model = MetaAction.objects.create(type=cls.TYPE, percents=0, data=s11n.to_json({'hero_1_old_health': hero_1_old_health, 'hero_2_old_health': hero_2_old_health}), bundle_id=bundle_id, state=cls.STATE.BATTLE_RUNNING ) member_1 = MetaActionMemberPrototype.create(meta_action_model=model, hero_model=hero_1._model, role=cls.ROLES.HERO_1) member_2 = MetaActionMemberPrototype.create(meta_action_model=model, hero_model=hero_2._model, role=cls.ROLES.HERO_2) meta_action = cls(model, members=[member_1, member_2]) meta_action.set_storage(storage) meta_action.add_message('meta_action_arena_pvp_1x1_start', duelist_1=hero_1, duelist_2=hero_2) return meta_action
def create(cls, person, utg_name): from the_tale.game.places import storage building = storage.buildings.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 = models.Building.objects.create( x=x, y=y, data=s11n.to_json({'name': utg_name.serialize()}), place_id=person.place_id, person_id=person.id, state=relations.BUILDING_STATE.WORKING, created_at_turn=TimePrototype.get_current_turn_number(), type=person.type.building_type) prototype = cls(model=model) storage.buildings.add_item(prototype.id, prototype) storage.buildings.update_version() return prototype
def create_companion_record(utg_name, description, type, max_health, dedication, archetype, mode, abilities, state=relations.STATE.DISABLED): model = models.CompanionRecord.objects.create(state=state, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, data=s11n.to_json({'description': description, 'name': utg_name.serialize(), 'abilities': abilities.serialize()})) companion_record = objects.CompanionRecord.from_model(model) storage.companions.add_item(companion_record.id, companion_record) storage.companions.update_version() linguistics_logic.sync_restriction(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION, external_id=companion_record.id, name=companion_record.name) return companion_record
def create(cls, w, h): generator = deworld.World(w=w, h=h, config=deworld.BaseConfig) model = WorldInfo.objects.create( data=s11n.to_json(generator.serialize())) return cls(model)
def save_person(person, new=False): data = { "name": person.utg_name.serialize(), "job": person.job.serialize(), "politic_power": person.politic_power.serialize(), "moved_at_turn": person.moved_at_turn, "attributes": person.attrs.serialize(), "personality": {"cosmetic": person.personality_cosmetic.value, "practical": person.personality_practical.value}, } arguments = { "place_id": person.place_id, "gender": person.gender, "race": person.race, "type": person.type, "data": s11n.to_json(data), "created_at_turn": person.created_at_turn, "updated_at_turn": person.updated_at_turn, } if new: person_model = models.Person.objects.create(**arguments) person.id = person_model.id # TODO: that string was in .create method, is it needed here? person.place.persons_changed_at_turn = game_protypes.TimePrototype.get_current_turn_number() storage.persons.add_item(person.id, person) else: models.Person.objects.filter(id=person.id).update(**arguments) storage.persons.update_version()
def create(cls, person, utg_name): from the_tale.game.places import storage building = storage.buildings.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 = models.Building.objects.create(x=x, y=y, data=s11n.to_json({'name': utg_name.serialize()}), place_id=person.place_id, person_id=person.id, state=relations.BUILDING_STATE.WORKING, created_at_turn=TimePrototype.get_current_turn_number(), type=person.type.building_type) prototype = cls(model=model) storage.buildings.add_item(prototype.id, prototype) storage.buildings.update_version() return prototype
def create(cls, task_logic, live_time=None): model = PostponedTask.objects.create(internal_type=task_logic.TYPE, internal_state=task_logic.state if isinstance(task_logic.state, int) else task_logic.state.value, internal_data=s11n.to_json(task_logic.serialize()), live_time=live_time) return cls(model=model)
def change_cards(account_id, operation_type, to_add=(), to_remove=(), storage=relations.STORAGE.FAST): operations = [] for card in to_remove: operations.append( storage_pb2.Operation(destroy=storage_pb2.OperationDestroy( item_id=card.uid.hex, owner_id=account_id, operation_type=operation_type))) for card in to_add: operations.append( storage_pb2.Operation(create=storage_pb2.OperationCreate( item_id=card.uid.hex, owner_id=account_id, storage_id=storage.value, base_type=card.item_base_type, full_type=card.item_full_type, data=s11n.to_json(card.serialize()), operation_type=operation_type))) tt_api.sync_request(url=conf.settings.TT_STORAGE_APPLY_URL, data=storage_pb2.ApplyRequest(operations=operations), AnswerType=storage_pb2.ApplyResponse)
def save_person(person, new=False): data = {'name': person.utg_name.serialize(), 'job': person.job.serialize(), 'politic_power': person.politic_power.serialize(), 'moved_at_turn': person.moved_at_turn, 'attributes': person.attrs.serialize(), 'personality': {'cosmetic': person.personality_cosmetic.value, 'practical': person.personality_practical.value}} arguments = {'place_id': person.place_id, 'gender': person.gender, 'race': person.race, 'type': person.type, 'data': s11n.to_json(data), 'created_at_turn': person.created_at_turn, 'updated_at_turn': person.updated_at_turn} if new: person_model = models.Person.objects.create(**arguments) person.id = person_model.id # TODO: that string was in .create method, is it needed here? person.place.persons_changed_at_turn = game_protypes.TimePrototype.get_current_turn_number() storage.persons.add_item(person.id, person) else: models.Person.objects.filter(id=person.id).update(**arguments) storage.persons.update_version()
def save_person(person, new=False): data = {'name': person.utg_name.serialize(), 'job': person.job.serialize(), 'moved_at_turn': person.moved_at_turn, 'attributes': person.attrs.serialize(), 'personality': {'cosmetic': person.personality_cosmetic.value, 'practical': person.personality_practical.value}} arguments = {'place_id': person.place_id, 'gender': person.gender, 'race': person.race, 'type': person.type, 'data': s11n.to_json(data), 'created_at_turn': person.created_at_turn, 'updated_at_turn': person.updated_at_turn} if new: person_model = models.Person.objects.create(**arguments) person.id = person_model.id # TODO: that string was in .create method, is it needed here? person.place.persons_changed_at_turn = turn.number() storage.persons.add_item(person.id, person) else: models.Person.objects.filter(id=person.id).update(**arguments) storage.persons.update_version()
def create(cls, key, raw_template, utg_template, verificators, author, parent=None, restrictions=frozenset(), state=relations.TEMPLATE_STATE.ON_REVIEW): model = cls._db_create( key=key, state=state, raw_template=raw_template, author=None if author is None else author._model, parent=None if parent is None else parent._model, data=s11n.to_json({ 'verificators': [v.serialize() for v in verificators], 'template': utg_template.serialize(), 'restrictions': list(restrictions), 'groups': lexicon_logic.get_verificators_groups(key=key) })) prototype = cls(model) prototype.update_errors_status(force_update=True) prototype.sync_restrictions() environment.workers.linguistics_manager.cmd_game_lexicon_changed() return prototype
def create(cls, account): # pylint: disable=R0914 from the_tale.game.relations import GENDER, RACE from the_tale.game.actions.prototypes import ActionIdlenessPrototype from the_tale.game.logic_storage import LogicStorage start_place = places_storage.random_place() race = random.choice(RACE.records) gender = random.choice((GENDER.MASCULINE, GENDER.FEMININE)) current_turn_number = TimePrototype.get_current_turn_number() utg_name = names.generator.get_name(race, gender) hero = Hero.objects.create( created_at_turn=current_turn_number, saved_at_turn=current_turn_number, active_state_end_at=account.active_end_at, premium_state_end_at=account.premium_end_at, account=account._model, gender=gender, race=race, is_fast=account.is_fast, is_bot=account.is_bot, abilities=s11n.to_json(AbilitiesPrototype.create().serialize()), messages=s11n.to_json(messages.JournalContainer().serialize()), diary=s11n.to_json(messages.DiaryContainer().serialize()), settings_approved=False, next_spending=relations.ITEMS_OF_EXPENDITURE.BUYING_ARTIFACT, health=f.hp_on_lvl(1), energy=c.ANGEL_ENERGY_MAX, energy_bonus=heroes_settings.START_ENERGY_BONUS, pos_place=start_place._model, data=s11n.to_json({'name': utg_name.serialize()})) hero = cls(model=hero) HeroPreferencesPrototype.create( hero, energy_regeneration_type=hero.preferences.energy_regeneration_type, risk_level=relations.RISK_LEVEL.NORMAL, archetype=game_relations.ARCHETYPE.NEUTRAL, companion_dedication=relations.COMPANION_DEDICATION.NORMAL, companion_empathy=relations.COMPANION_EMPATHY.ORDINAL) return hero
def update_companion_record(companion, utg_name, description, type, max_health, dedication, archetype, mode, abilities, communication_verbal, communication_gestures, communication_telepathic, intellect_level, structure, features, movement, body, size, weapons): companion.set_utg_name(utg_name) companion.description = description companion.type = type companion.max_health = max_health companion.dedication = dedication companion.archetype = archetype companion.mode = mode companion.abilities = abilities companion.communication_verbal = communication_verbal companion.communication_gestures = communication_gestures companion.communication_telepathic = communication_telepathic companion.intellect_level = intellect_level companion.structure = structure companion.features = features companion.movement = movement companion.body = body companion.size = size companion.weapons = weapons data = { 'description': description, 'name': utg_name.serialize(), 'abilities': abilities.serialize(), 'structure': structure.value, 'features': [feature.value for feature in features], 'movement': movement.value, 'body': body.value, 'size': size.value, 'weapons': [weapon.serialize() for weapon in weapons] } models.CompanionRecord.objects.filter(id=companion.id).update( state=companion.state, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, communication_verbal=communication_verbal, communication_gestures=communication_gestures, communication_telepathic=communication_telepathic, intellect_level=intellect_level, data=s11n.to_json(data), updated_at=datetime.datetime.now()) storage.companions.update_version() linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION, external_id=companion.id, name=companion.name)
def create(cls, account): # pylint: disable=R0914 from the_tale.game.relations import GENDER, RACE from the_tale.game.actions.prototypes import ActionIdlenessPrototype from the_tale.game.logic_storage import LogicStorage start_place = places_storage.random_place() race = random.choice(RACE.records) gender = random.choice((GENDER.MASCULINE, GENDER.FEMININE)) current_turn_number = TimePrototype.get_current_turn_number() utg_name = names.generator.get_name(race, gender) hero = Hero.objects.create(created_at_turn=current_turn_number, saved_at_turn=current_turn_number, active_state_end_at=account.active_end_at, premium_state_end_at=account.premium_end_at, account=account._model, gender=gender, race=race, is_fast=account.is_fast, is_bot=account.is_bot, abilities=s11n.to_json(AbilitiesPrototype.create().serialize()), messages=s11n.to_json(messages.JournalContainer().serialize()), diary=s11n.to_json(messages.DiaryContainer().serialize()), settings_approved=False, next_spending=relations.ITEMS_OF_EXPENDITURE.BUYING_ARTIFACT, health=f.hp_on_lvl(1), energy=c.ANGEL_ENERGY_MAX, energy_bonus=heroes_settings.START_ENERGY_BONUS, pos_place = start_place._model, data=s11n.to_json({'name': utg_name.serialize()})) hero = cls(model=hero) HeroPreferencesPrototype.create(hero, energy_regeneration_type=hero.preferences.energy_regeneration_type, risk_level=relations.RISK_LEVEL.NORMAL, archetype=game_relations.ARCHETYPE.NEUTRAL, companion_dedication=relations.COMPANION_DEDICATION.NORMAL, companion_empathy=relations.COMPANION_EMPATHY.ORDINAL) return hero
def create_companion_record(utg_name, description, type, max_health, dedication, archetype, mode, abilities, communication_verbal, communication_gestures, communication_telepathic, intellect_level, structure, features, movement, body, size, orientation, weapons, state=relations.STATE.DISABLED): data = { 'description': description, 'name': utg_name.serialize(), 'abilities': abilities.serialize(), 'structure': structure.value, 'features': [feature.value for feature in features], 'movement': movement.value, 'body': body.value, 'size': size.value, 'orientation': orientation.value, 'weapons': [weapon.serialize() for weapon in weapons] } model = models.CompanionRecord.objects.create( state=state, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, communication_verbal=communication_verbal, communication_gestures=communication_gestures, communication_telepathic=communication_telepathic, intellect_level=intellect_level, data=s11n.to_json(data)) companion_record = objects.CompanionRecord.from_model(model) storage.companions.add_item(companion_record.id, companion_record) storage.companions.update_version() linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION, external_id=companion_record.id, name=companion_record.name) return companion_record
def handle(self, *args, **options): LINGUISTICS_FORMATTERS = {key.value: linguistics_logic.ui_format(key.ui_text) for key in linguistics_keys.LEXICON_KEY.records if key.ui_text is not None} with open(game_settings.JS_CONSTNATS_FILE_LOCATION, 'w') as f: f.write(jinja2.render('game/js_constants.js', context={'actor_type': s11n.to_json({a.name: a.value for a in ACTOR_TYPE.records}), 'gender_to_text': s11n.to_json(dict(GENDER.select('value', 'text'))), 'gender_to_str': s11n.to_json(dict(GENDER.select('value', 'name'))), 'person_type_to_text': s11n.to_json(dict(PERSON_TYPE.select('value', 'text'))), 'race_to_text': s11n.to_json(dict(RACE.select('value', 'text'))), 'race_to_str': s11n.to_json(dict(RACE.select('value', 'name'))), 'game_state': s11n.to_json(dict(GAME_STATE.select('name', 'value'))), 'ARTIFACT_TYPE': artifacts_relations.ARTIFACT_TYPE, 'NO_EFFECT': artifacts_relations.ARTIFACT_EFFECT.NO_EFFECT, 'EFFECTS': EFFECTS, 'ARTIFACT_RARITY': artifacts_relations.RARITY, 'CARD_RARITY': cards_relations.RARITY, 'CARDS_EFFECTS': cards_effects.EFFECTS, 'ABILITY_TYPE': ABILITY_TYPE, 'SPRITES': SPRITES, 'CELL_SIZE': map_settings.CELL_SIZE, 'LINGUISTICS_FORMATTERS': LINGUISTICS_FORMATTERS }))
def save_mob_record(mob): from the_tale.game.mobs import storage if id(mob) != id(storage.mobs[mob.id]): raise exceptions.SaveNotRegisteredMobError(mob=mob.id) data = { 'name': mob.utg_name.serialize(), 'structure': mob.structure.value, 'features': [feature.value for feature in mob.features], 'movement': mob.movement.value, 'body': mob.body.value, 'size': mob.size.value, 'orientation': mob.orientation.value, 'weapons': [weapon.serialize() for weapon in mob.weapons] } arguments = { 'data': s11n.to_json(data), 'abilities': s11n.to_json(list(mob.abilities)), 'terrains': s11n.to_json([terrain.value for terrain in mob.terrains]), 'editor_id': mob.editor_id, 'level': mob.level, 'uuid': mob.uuid, 'description': mob.description, 'state': mob.state, 'type': mob.type, 'archetype': mob.archetype, 'communication_verbal': mob.communication_verbal, 'communication_gestures': mob.communication_gestures, 'communication_telepathic': mob.communication_telepathic, 'intellect_level': mob.intellect_level, 'is_mercenary': mob.is_mercenary, 'is_eatable': mob.is_eatable } models.MobRecord.objects.filter(id=mob.id).update(**arguments) linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=mob.id, name=mob.name) storage.mobs._update_cached_data(mob) storage.mobs.update_version()
def update_actual_bills(self): from the_tale.game.bills import logic as bills_logic self._model.actual_bills = s11n.to_json(bills_logic.actual_bills_accepted_timestamps(self.id)) self.save() del self.actual_bills self.cmd_update_hero()
def create(cls, task_logic, live_time=None): model = PostponedTask.objects.create( internal_type=task_logic.TYPE, internal_state=task_logic.state if isinstance( task_logic.state, int) else task_logic.state.value, internal_data=s11n.to_json(task_logic.serialize()), live_time=live_time) return cls(model=model)
def update_with_account_data(self, is_fast, premium_end_at, active_end_at, ban_end_at, might, actual_bills): del self.actual_bills self.is_fast = is_fast self.active_state_end_at = active_end_at self.premium_state_end_at = premium_end_at self.ban_state_end_at = ban_end_at self.might = might self._model.actual_bills = s11n.to_json(actual_bills)
def save(self): from the_tale.game.map.places.storage import places_storage self.races.serialize() self._model.data = s11n.to_json(self.data) self._model.save(force_update=True) places_storage.update_version()
def test_load__removed_by_child(self): self.request_login(self.superuser.email) data = {'words': [self.child_word.serialize()]} with self.check_changed(lambda: storage.game_dictionary.version): self.check_ajax_ok(self.client.post(self.requested_url, {'words': s11n.to_json(data)})) self.assertFalse(prototypes.WordPrototype._db_filter(id__in=[self.parent.id, self.child.id]).exists())
def create(cls, uuid, level, utg_name, description, abilities, terrains, type, archetype=game_relations.ARCHETYPE.NEUTRAL, editor=None, state=MOB_RECORD_STATE.DISABLED, global_action_probability=0): from the_tale.game.mobs.storage import mobs_storage model = MobRecord.objects.create( uuid=uuid, level=level, name=utg_name.normal_form(), type=type, archetype=archetype, data=s11n.to_json({ 'name': utg_name.serialize(), 'global_action_probability': global_action_probability }), description=description, abilities=s11n.to_json(list(abilities)), terrains=s11n.to_json([terrain.value for terrain in terrains]), state=state, editor=editor._model if editor else None) prototype = cls(model) linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=prototype.id, name=prototype.name) mobs_storage.add_item(prototype.id, prototype) mobs_storage.update_version() return prototype
def create(cls, handler, now=False): model = cls._model_class.objects.create(state=MESSAGE_STATE.WAITING, handler=s11n.to_json(handler.serialize())) prototype = cls(model=model) if now: environment.workers.message_sender.cmd_send_now(prototype.id) return prototype
def create(cls, uuid, level, utg_name, description, abilities, terrains, type, archetype=game_relations.ARCHETYPE.NEUTRAL, editor=None, state=relations.MOB_RECORD_STATE.DISABLED, global_action_probability=0, communication_verbal=game_relations.COMMUNICATION_VERBAL.CAN_NOT, communication_gestures=game_relations.COMMUNICATION_GESTURES.CAN_NOT, communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.CAN_NOT, intellect_level=game_relations.INTELLECT_LEVEL.NONE, is_mercenary=True, is_eatable=True): from the_tale.game.mobs.storage import mobs_storage model = models.MobRecord.objects.create(uuid=uuid, level=level, name=utg_name.normal_form(), type=type, archetype=archetype, data=s11n.to_json({'name': utg_name.serialize(), 'global_action_probability': global_action_probability}), description=description, abilities=s11n.to_json(list(abilities)), terrains=s11n.to_json([terrain.value for terrain in terrains]), state=state, editor=editor._model if editor else None, communication_verbal=communication_verbal, communication_gestures=communication_gestures, communication_telepathic=communication_telepathic, intellect_level=intellect_level, is_mercenary=is_mercenary, is_eatable=is_eatable) prototype = cls(model) linguistics_logic.sync_restriction(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=prototype.id, name=prototype.name) mobs_storage.add_item(prototype.id, prototype) mobs_storage.update_version() return prototype
def create(cls, handler, now=False): model = cls._model_class.objects.create(state=MESSAGE_STATE.WAITING, handler=s11n.to_json( handler.serialize())) prototype = cls(model=model) if now: environment.workers.message_sender.cmd_send_now(prototype.id) return prototype
def reserve_lot(account_id, good, price): model = models.Lot.objects.create(type=good.type, good_uid=good.uid, seller_id=account_id, name=good.name, state=relations.LOT_STATE.RESERVED, price=price, commission=get_commission(price), closed_at=datetime.datetime.now() + datetime.timedelta(days=conf.settings.LOT_LIVE_TIME), data=s11n.to_json({'good': good.serialize()}), group_id=good.group().id) return objects.Lot.from_model(model)
def to_model_fields(self): data = {'type': self.type, 'name': self.name, 'seller': self.seller_id, 'buyer': self.buyer_id, 'state': self.state, 'good_uid': self.good.uid, 'data': s11n.to_json({'good': self.good.serialize()}), 'price': self.price, 'closed_at': self.closed_at, 'commission': self.commission, 'group_id': self.group_id} return data
def create(cls, utg_word, parent=None, author=None, state=relations.WORD_STATE.ON_REVIEW): model = cls._db_create(type=utg_word.type, state=state, normal_form=utg_word.normal_form(), forms=s11n.to_json(utg_word.serialize()), parent=parent._model if parent is not None else None, author=author._model if author is not None else None) prototype = cls(model) environment.workers.linguistics_manager.cmd_game_dictionary_changed() return prototype
def save(self): from the_tale.linguistics import storage self._model.forms = s11n.to_json(self.utg_word.serialize()) self._model.normal_form = self.utg_word.normal_form() self._model.updated_at = datetime.datetime.now() super(WordPrototype, self).save() if self.state.is_IN_GAME: storage.game_dictionary.update_version() storage.game_dictionary.refresh() environment.workers.linguistics_manager.cmd_game_dictionary_changed()
def save(self): from the_tale.game.artifacts.storage import artifacts_storage if id(self) != id(artifacts_storage[self.id]): raise exceptions.SaveNotRegisteredArtifactError(mob=self.id) linguistics_logic.sync_restriction(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.ARTIFACT, external_id=self.id, name=self.name) self._model.data = s11n.to_json(self.data) self._model.save() artifacts_storage._update_cached_data(self) artifacts_storage.update_version()
def test_sync(self): self.assertEqual(len(self.storage._data), 3) self.assertNotEqual(self.p1.attrs.size, 7) place = Place.objects.get(id=self.p1.id) data = s11n.from_json(place.data) data['attributes']['size'] = 7 place.data = s11n.to_json(data) place.save() self.storage.sync() self.assertNotEqual(self.storage[self.p1.id].attrs.size, 7) self.storage.sync(force=True) self.assertEqual(self.storage[self.p1.id].attrs.size, 7)
def create(cls, x, y, size, utg_name, race=RACE.HUMAN, is_frontier=False): from the_tale.game.map.places.storage import places_storage model = Place.objects.create( x=x, y=y, created_at_turn=TimePrototype.get_current_turn_number(), data=s11n.to_json({'name': utg_name.serialize()}), is_frontier=is_frontier, race=race, size=size) prototype = cls(model) places_storage.add_item(prototype.id, prototype) places_storage.update_version() return prototype
def create( cls, uuid, level, utg_name, description, type_, power_type, mob=None, editor=None, state=relations.ARTIFACT_RECORD_STATE.DISABLED, rare_effect=relations.ARTIFACT_EFFECT.NO_EFFECT, epic_effect=relations.ARTIFACT_EFFECT.NO_EFFECT, special_effect=relations.ARTIFACT_EFFECT.NO_EFFECT, ): from the_tale.game.artifacts.storage import artifacts_storage model = ArtifactRecord.objects.create( uuid=uuid, level=level, name=utg_name.normal_form(), description=description, data=s11n.to_json({"name": utg_name.serialize()}), mob=mob._model if mob else None, type=type_, power_type=power_type, rare_effect=rare_effect, epic_effect=epic_effect, special_effect=special_effect, state=state, editor=editor._model if editor else None, ) prototype = cls(model) linguistics_logic.sync_restriction( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.ARTIFACT, external_id=prototype.id, name=prototype.name, ) artifacts_storage.add_item(prototype.id, prototype) artifacts_storage.update_version() return prototype