public void Load() { PartySave partySave = PlanetSave.GameStateSave; moneyStock = partySave.moneyStock; List <GivedItemSave> outGived; ArrayExtensions.ToList(partySave.GivedItems, out outGived); foreach (GivedItemSave item in outGived) { for (int i = 0; i < item.givedItems.Length; i++) { GiveItem(item.npcName, item.givedItems[i]); } } List <InventoryItemSave> outInventory; ArrayExtensions.ToList(partySave.items, out outInventory); foreach (InventoryItemSave item in outInventory) { for (int i = 0; i < item.nb; i++) { AddFromType(item.type); } } for (int i = 0; i < PlanetSave.GameStateSave.knowsItem.Length; i++) { AddKnowFromType(PlanetSave.GameStateSave.knowsItem[i]); } Events.Instance.Raise(new OnUpdateInventory()); }
public void SaveLoadDoesNotMaintainsReferencesForNonPartyMemberCastedBuffs() { Party party = new Party(); Character dummy = CharacterList.TestEnemy(); Character buffCaster = CharacterList.TestEnemy(); Character buffRecipient = CharacterList.TestEnemy(); Poison poison = new Poison(); Debug.Log("BuffcasterID: " + buffCaster.Id); poison.Caster = new BuffParams(buffCaster.Stats, buffCaster.Id); buffRecipient.Buffs.AddBuff(poison); party.AddMember(dummy); party.AddMember(CharacterList.TestEnemy()); party.AddMember(buffRecipient); PartySave retrieved = FromJson <PartySave>(ToJson(party.GetSaveObject())); Party party2 = new Party(); party2.InitFromSaveObject(retrieved); List <Character> a = party.ToList(); List <Character> b = party.ToList(); Character caster = b[1]; Character target = b[2]; Assert.IsTrue(party.Equals(party2)); Assert.AreEqual(party, party2); Assert.AreNotSame(party.Collection.ToList()[1].Stats, party.Collection.ToList()[2].Buffs.ToList()[0].BuffCaster); }
public void SaveLoadMaintainsBonusesFromEquipmentAndBuffsForPartyMemberCastedBuffs() { Party party = new Party(); Character dummy = CharacterList.TestEnemy(); Character buffCaster = CharacterList.TestEnemy(); buffCaster.Inventory.ForceAdd(new BrokenSword()); buffCaster.Equipment.AddEquip(buffCaster.Inventory, new BuffParams(buffCaster.Stats, buffCaster.Id), new BrokenSword()); buffCaster.AddBuff(new StrengthBoost()); Character buffRecipient = CharacterList.TestEnemy(); StrengthScalingPoison poison = new StrengthScalingPoison(); Debug.Log("BuffcasterID: " + buffCaster.Id); poison.Caster = new BuffParams(buffCaster.Stats, buffCaster.Id); buffRecipient.Buffs.AddBuff(poison); party.AddMember(dummy); party.AddMember(CharacterList.TestEnemy()); party.AddMember(buffRecipient); party.AddMember(buffCaster); PartySave retrieved = FromJson <PartySave>(ToJson(party.GetSaveObject())); Party party2 = new Party(); party2.InitFromSaveObject(retrieved); Assert.AreEqual(buffCaster.Stats, party2.Collection.ToArray()[3].Stats); Assert.AreEqual(buffCaster.Buffs, party2.Collection.ToArray()[3].Buffs); }
/// <summary> /// Setup the PartySave from the serialized object. /// </summary> /// <param name="saveObject">Save object representing the state of the party.</param> public void InitFromSaveObject(PartySave saveObject) { List <Character> memList = new List <Character>(); // Inventory setup this.Shared.InitFromSaveObject(saveObject.Inventory); // Setup everything EXCEPT buffs for (int i = 0; i < saveObject.Characters.Count; i++) { CharacterSave charSave = saveObject.Characters[i]; Character restored = new Character(this.Shared); // Inventory restored.InitFromSaveObject(charSave); // Everything else but buffs memList.Add(restored); } // Setup buffs (which need members inited to make) // memList index should match saveObject.Characters index! for (int i = 0; i < memList.Count; i++) { Character c = memList[i]; c.Equipment.SetupTemporarySaveFields(memList); c.Equipment.InitFromSaveObject(saveObject.Characters[i].Equipment); c.Buffs.SetupTemporarySaveFields(memList); c.Buffs.InitFromSaveObject(saveObject.Characters[i].Buffs); // Assumes matching indices } // Add members foreach (Character c in memList) { members.Add(c); } }
public void SaveLoadMaintainsEquipmentBonusesForNonPartyMemberCastedBuffs() { Party party = new Party(); Character dummy = CharacterList.TestEnemy(); Character buffCaster = CharacterList.TestEnemy(); buffCaster.Inventory.ForceAdd(new BrokenSword()); buffCaster.Equipment.AddEquip(buffCaster.Inventory, new BuffParams(buffCaster.Stats, buffCaster.Id), new BrokenSword()); Character buffRecipient = CharacterList.TestEnemy(); StrengthScalingPoison poison = new StrengthScalingPoison(); Debug.Log("BuffcasterID: " + buffCaster.Id); poison.Caster = new BuffParams(buffCaster.Stats, buffCaster.Id); buffRecipient.Buffs.AddBuff(poison); party.AddMember(dummy); party.AddMember(CharacterList.TestEnemy()); party.AddMember(buffRecipient); PartySave retrieved = FromJson <PartySave>(ToJson(party.GetSaveObject())); Party party2 = new Party(); party2.InitFromSaveObject(retrieved); int spoofedStrength = party2.Collection.ToArray()[2].Buffs.ToArray()[0].BuffCaster.GetEquipmentBonus(StatType.STRENGTH); Assert.AreEqual(spoofedStrength, (new BrokenSword()).Stats[StatType.STRENGTH]); Debug.Log("" + spoofedStrength); }
// Create a party save representation of this party private static PartySave CreatePartySave() { PartySave save = new PartySave(); save.partyID = partyID; save.partyUnits = partyUnits.ToArray(); return(save); }
private void LoadingCharactersInPartyThrowsNoErrors(int characterCount) { Party party = new Party(); for (int i = 0; i < characterCount; i++) { party.AddMember(CharacterList.TestEnemy()); } string json = ToJson(party.GetSaveObject()); PartySave partySave = JsonUtility.FromJson <PartySave>(json); Party party2 = new Party(); party2.InitFromSaveObject(partySave); }
public void EquippedItemsAreSaved() { Character dummy = CharacterList.TestEnemy(); dummy.Inventory.ForceAdd(new BrokenSword()); dummy.Equipment.AddEquip(dummy.Inventory, new BuffParams(dummy.Stats, dummy.Id), new BrokenSword()); Party party = new Party(); party.AddMember(dummy); PartySave ps = party.GetSaveObject(); PartySave retrieved = FromJson <PartySave>(ToJson(party.GetSaveObject())); Party party2 = new Party(); party2.InitFromSaveObject(retrieved); Assert.AreEqual(party, party2); }
public void SaveLoadMaintainsBonusesFromEquipmentAndBuffsForNonPartyMemberCastedBuffs() { Party party = new Party(); Character dummy = CharacterList.TestEnemy(); Character buffCaster = CharacterList.TestEnemy(); buffCaster.Inventory.ForceAdd(new BrokenSword()); buffCaster.Equipment.AddEquip(buffCaster.Inventory, new BuffParams(buffCaster.Stats, buffCaster.Id), new BrokenSword()); buffCaster.AddBuff(new StrengthBoost()); Character buffRecipient = CharacterList.TestEnemy(); StrengthScalingPoison poison = new StrengthScalingPoison(); Debug.Log("BuffcasterID: " + buffCaster.Id); poison.Caster = new BuffParams(buffCaster.Stats, buffCaster.Id); buffRecipient.Buffs.AddBuff(poison); int initialStrength = buffCaster.Stats.GetStatCount(Stats.Get.TOTAL, StatType.STRENGTH); Assert.AreEqual(buffCaster.Stats.GetMultiplicativeBuffBonus(StatType.STRENGTH), StrengthBoost.STRENGTH_INCREASE_AMOUNT); Assert.AreEqual(buffCaster.Stats.GetFlatEquipmentBonus(StatType.STRENGTH), new BrokenSword().StatBonuses[StatType.STRENGTH]); party.AddMember(dummy); party.AddMember(CharacterList.TestEnemy()); party.AddMember(buffRecipient); PartySave retrieved = FromJson <PartySave>(ToJson(party.GetSaveObject())); Party party2 = new Party(); party2.InitFromSaveObject(retrieved); Stats spoofedCasterStats = party2.Collection.ToArray()[2].Buffs.ToArray()[0].BuffCaster; int spoofedStrength = spoofedCasterStats.GetStatCount(Stats.Get.TOTAL, StatType.STRENGTH); Assert.AreEqual(buffCaster.Stats.GetStatCount(Stats.Get.MOD, StatType.STRENGTH), spoofedCasterStats.GetStatCount(Stats.Get.MOD, StatType.STRENGTH)); Assert.AreEqual(StrengthBoost.STRENGTH_INCREASE_AMOUNT, spoofedCasterStats.GetMultiplicativeBuffBonus(StatType.STRENGTH)); Assert.AreEqual(new BrokenSword().StatBonuses[StatType.STRENGTH], spoofedCasterStats.GetFlatEquipmentBonus(StatType.STRENGTH)); Assert.AreEqual(buffCaster.Stats.GetStatCount(Stats.Get.TOTAL, StatType.STRENGTH), spoofedStrength); Assert.AreEqual(buffCaster.Stats, spoofedCasterStats); }
// Save this party to a file public static void SaveParty() { try { // 0: Get file path string saveFilePath = GetFilePath(partyID); // 1: Create save instance PartySave save = CreatePartySave(); // 2: Save file and close file stream BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(saveFilePath); bf.Serialize(file, save); Debug.Log("Party_" + partyID + " saved to " + saveFilePath); file.Close(); // 3: Ending save // Post save operations if necessary } catch (System.FormatException e) { Debug.Log(e); } }
// Load party from file, returns success public static bool LoadParty(int ID) { // 0: Get file path string saveFilePath = GetFilePath(ID); if (File.Exists(saveFilePath)) { try { // 1: Load file and close file stream BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(saveFilePath, FileMode.Open); PartySave save = (PartySave)bf.Deserialize(file); file.Close(); // 2: Set party from save SetPartyFromSave(save); return(true); } catch (System.FormatException e) { Debug.Log(e); } } return(false); }
// Sets this party from a party save representation private static void SetPartyFromSave(PartySave save) { partyID = save.partyID; partyUnits = new List <Unit>(save.partyUnits); }