/// <summary> /// Constructor requires an XpProgressor, starting HP, maximum HP, and optionally, a name /// </summary> public RpgCharacterData(Guid newId, XpProgressor newXpProgressor, int newHP, int newMaxHp, GlobalSpAssignmentType typeOfSpAssignment, string newName = RpgCharacterData.DefaultName) { Debug.Assert(newXpProgressor != null, "RpgCharacterData consturctor is being given a null XpProgressor!"); if (string.IsNullOrEmpty(newName)) { Debug.LogWarning("RpgCharacterData constructor was given a null or empty new name string"); newName = RpgCharacterData.DefaultName; } if (newMaxHp <= 0) { if (newMaxHp != 0) { newMaxHp = -newMaxHp; Debug.LogWarning("A new RPG Character " + newName + " was given negative Max HP. Negating to positive."); } else { newMaxHp = RpgCharacterData.DefaultHealthPoints; Debug.LogWarning("A new RPG Character " + newName + " was given 0 Max HP. As this is not allowed, the new HP will be " + RpgCharacterData.DefaultHealthPoints.ToString()); } } if (newHP <= 0) { if (newHP != 0) { newHP = -newHP; Debug.LogWarning("A new RPG Character " + newName + " was given negative HP. Negating to positive."); } else { newHP = newMaxHp; Debug.LogWarning("A new RPG Character " + newName + " was given 0 HP. As this is not allowed at start, the new HP will be the same as the given Max HP"); } } this.id = new SaveableGuid(newId); this.name = newName; this.hp = newHP; this.maxHp = newMaxHp; this.additionalMaxHp = 0; this.unallocatedSpPool = 0; this.assignmentType = typeOfSpAssignment; this.xpData = new XpData(newXpProgressor); this.appliedAbilities = new List <AbilityData>(); this.appliedStats = new List <StatData>(); this.numOfStats = 0; this.numOfAbilities = 0; this.UpdateReadOnlyStatsList(); this.UpdateReadOnlyAbilitiesList(); }
/// <summary> /// Deserialization Constructor /// </summary> public RpgCharacterData(RpgCharacterPacket rpgCharacterPacket) { Debug.Assert(rpgCharacterPacket != null, "RpgCharacterData could not be deserialized because the packet was null!"); this.id = new SaveableGuid(rpgCharacterPacket.id); this.name = rpgCharacterPacket.name; this.hp = rpgCharacterPacket.hp; this.maxHp = rpgCharacterPacket.maxHp; this.additionalMaxHp = rpgCharacterPacket.additionalMaxHp; this.unallocatedSpPool = rpgCharacterPacket.unallocatedSpPool; this.assignmentType = rpgCharacterPacket.assignmentType; this.xpData = new XpData(rpgCharacterPacket.xpDataPacket); this.appliedStats = new List <StatData>(); this.appliedAbilities = new List <AbilityData>(); this.numOfStats = rpgCharacterPacket.appliedStats.Count; this.numOfAbilities = rpgCharacterPacket.appliedAbilities.Count; // Deserialize abilties first, so we can just loop through stats later to apply abilities foreach (AbilityPacket abilityPacket in rpgCharacterPacket.appliedAbilities) { AbilityData newAbility = new AbilityData(abilityPacket); this.appliedAbilities.Add(newAbility); } foreach (StatPacket statPacket in rpgCharacterPacket.appliedStats) { StatData newStat = new StatData(statPacket, this.appliedStats); this.appliedStats.Add(newStat); // Apply all abilities that this new stat takes foreach (AbilityData ability in this.appliedAbilities) { newStat.ApplyOneAbility(ability); } } this.RecalculateAllLinkedStatsPools(); this.UpdateReadOnlyStatsList(); this.UpdateReadOnlyAbilitiesList(); }