def deserialize(cls, data): # we do not save abilities and after load, mob can has differen abilities levels # if mob record is desabled or deleted, get another random record from . import storage record = storage.mobs.get_by_uuid(data['id']) level = data['level'] if record is None or record.state.is_DISABLED: record = random.choice(storage.mobs.get_all_mobs_for_level(level)) abilities = cls._produce_abilities(record, level) return cls(record_id=record.id, level=level, health=data['health'], is_boss=data.get('is_boss', False), abilities=abilities, action_type=actions_relations.ACTION_TYPE( data['action_type']) if 'action_type' in data else actions_relations.ACTION_TYPE.BATTLE_PVE_1X1, terrain=map_relations.TERRAIN(data['terrain']) if 'terrain' in data else map_relations.TERRAIN.PLANE_GRASS)
def construct_from_model(model): data = s11n.from_json(model.data) abilities = frozenset(s11n.from_json(model.abilities)) terrains = frozenset( map_relations.TERRAIN(terrain) for terrain in s11n.from_json(model.terrains)) features = frozenset( beings_relations.FEATURE(feature) for feature in data.get('features', ())) weapons = [ artifacts_objects.Weapon.deserialize(weapon_data) for weapon_data in data.get('weapons', ()) ] mob = objects.MobRecord( id=model.id, editor_id=model.editor_id, level=model.level, uuid=model.uuid, description=model.description, state=model.state, type=model.type, archetype=model.archetype, communication_verbal=model.communication_verbal, communication_gestures=model.communication_gestures, communication_telepathic=model.communication_telepathic, intellect_level=model.intellect_level, is_mercenary=model.is_mercenary, is_eatable=model.is_eatable, abilities=abilities, terrains=terrains, structure=beings_relations.STRUCTURE(data.get('structure', 0)), features=features, movement=beings_relations.MOVEMENT(data.get('movement', 0)), body=beings_relations.BODY(data.get('body', 0)), size=beings_relations.SIZE(data.get('size', 0)), orientation=beings_relations.ORIENTATION(data.get('orientation', 0)), weapons=weapons, utg_name=utg_words.Word.deserialize(data['name'])) return mob
def get_terrains(self): if not hasattr(self, '_terrains'): self._terrains = frozenset( map_relations.TERRAIN(terrain) for terrain in s11n.from_json(self._model.terrains)) return self._terrains