public override void DoAction(PlayerCharacter character, Selectable select) { PlayerData pdata = PlayerData.Get(); Construction construction = select.GetComponent <Construction>(); if (construction != null) { ItemData take_item = construction.data.take_item_data; InventoryData inv_data = character.Inventory.GetValidInventory(take_item, 1); if (take_item != null && inv_data != null) { BuiltConstructionData bdata = pdata.GetConstructed(construction.GetUID()); float durability = bdata != null ? bdata.durability : take_item.durability; inv_data.AddItem(take_item.id, 1, durability, select.GetUID()); select.Destroy(); } } Character acharacter = select.GetComponent <Character>(); if (acharacter != null) { ItemData take_item = acharacter.data.take_item_data; InventoryData inv_data = character.Inventory.GetValidInventory(take_item, 1); if (take_item != null && inv_data != null) { TrainedCharacterData cdata = pdata.GetCharacter(acharacter.GetUID()); inv_data.AddItem(take_item.id, 1, take_item.durability, select.GetUID()); select.Destroy(); } } }
private void OnBuild() { if (data != null) { TrainedCharacterData cdata = PlayerData.Get().AddCharacter(data.id, SceneNav.GetCurrentScene(), transform.position, transform.rotation); unique_id.unique_id = cdata.uid; } }
//Create a totally new one that will be added to save file public static Character Create(CharacterData data, Vector3 pos) { Quaternion rot = Quaternion.Euler(0f, 180f, 0f); TrainedCharacterData ditem = PlayerData.Get().AddCharacter(data.id, SceneNav.GetCurrentScene(), pos, rot); GameObject build = Instantiate(data.character_prefab, pos, rot); Character unit = build.GetComponent <Character>(); unit.data = data; unit.was_spawned = true; unit.unique_id.unique_id = ditem.uid; return(unit); }
public TrainedCharacterData AddCharacter(string character_id, string scene, Vector3 pos, Quaternion rot) { TrainedCharacterData citem = new TrainedCharacterData(); citem.uid = UniqueID.GenerateUniqueID(); citem.character_id = character_id; citem.scene = scene; citem.pos = pos; citem.rot = rot; trained_characters[citem.uid] = citem; return(citem); }
//Spawn an existing one in the save file (such as after loading) public static Character Spawn(string uid, Transform parent = null) { TrainedCharacterData tcdata = PlayerData.Get().GetCharacter(uid); if (tcdata != null && tcdata.scene == SceneNav.GetCurrentScene()) { CharacterData cdata = CharacterData.Get(tcdata.character_id); if (cdata != null) { GameObject cobj = Instantiate(cdata.character_prefab, tcdata.pos, tcdata.rot); cobj.transform.parent = parent; Character character = cobj.GetComponent <Character>(); character.data = cdata; character.was_spawned = true; character.unique_id.unique_id = uid; return(character); } } return(null); }
public void SetCharacterPosition(string uid, string scene, Vector3 pos, Quaternion rot) { TrainedCharacterData cdata = GetCharacter(uid); if (cdata != null) { cdata.scene = scene; cdata.pos = pos; cdata.rot = rot; } else { //Characters that were not spawned are saved as scene objects SceneObjectData sobj = GetOrCreateSceneObject(uid, scene); if (sobj != null) { sobj.pos = pos; sobj.rot = rot; } } }