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_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 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_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 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, 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 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_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 enable_companion_record(companion): companion.state = relations.STATE.ENABLED models.CompanionRecord.objects.filter(id=companion.id).update(state=companion.state, 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 enable_companion_record(companion): companion.state = relations.STATE.ENABLED models.CompanionRecord.objects.filter(id=companion.id).update( state=companion.state, 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_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 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 save(self): from the_tale.game.mobs.storage import mobs_storage if id(self) != id(mobs_storage[self.id]): raise exceptions.SaveNotRegisteredMobError(mob=self.id) self._model.data = s11n.to_json(self.data) self._model.save() linguistics_logic.sync_restriction(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=self.id, name=self.name) mobs_storage._update_cached_data(self) mobs_storage.update_version()
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
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 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, 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, 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
def test_sync_restriction__exists(self): group = random.choice(relations.TEMPLATE_RESTRICTION_GROUP.records) restriction = logic.create_restriction(group=group, external_id=666, name=u'bla-bla-name') with self.check_not_changed(models.Restriction.objects.count): with self.check_changed(lambda: storage.restrictions_storage._version): with self.check_not_changed(storage.restrictions_storage.__len__): synced_restriction = logic.sync_restriction(group=group, external_id=666, name=u'new-name') self.assertEqual(synced_restriction.name, u'new-name') model = models.Restriction.objects.get(id=restriction.id) loaded_restriction = objects.Restriction.from_model(model) self.assertEqual(loaded_restriction, synced_restriction)