/// <summary> /// Deserialization Constructor /// </summary> public AbilityData(AbilityPacket abilityPacket) { this.id = new SaveableGuid(abilityPacket.abilityId); this.ability = RpgDataRegistry.Instance.SearchAbility(this.id.GuidData); Debug.Assert(this.ability != null, "An AbilityData instance could not be serialized because the definition file was not found! ID: " + abilityPacket.abilityId); }
/// <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> /// Initialized the RPG Data Type. Only runs once. /// </summary> public void Init() { if (!this.isGuidInitialized) { this.id = new SaveableGuid(true); this.isGuidInitialized = true; } }
/// <summary> /// Constructor needs an XpProgressor /// </summary> public XpData(XpProgressor newXpProgressor) { Debug.Assert(newXpProgressor != null, "XpData's constructor is being given a null XpProgressor!"); this.xpProgressor = newXpProgressor; this.xpProgressorId = new SaveableGuid(newXpProgressor.Id); this.level = 1; this.xp = 0; this.xpToNextLevel = newXpProgressor.InitialOldXtnl; this.currentLevelMultiplier = newXpProgressor.LevelMultiplier; this.currentOldValueMultiplier = newXpProgressor.OldXtnlMultiplier; this.xpToNextLevel = this.CalculateXpProgression(this.level, this.xpToNextLevel); }
/// <summary> /// Deserialization constructor /// </summary> public XpData(XpPacket xpDataPacket) { Debug.Assert(xpDataPacket != null, "XpData's constructor is being given a null XpPacket!"); this.xpProgressorId = new SaveableGuid(xpDataPacket.xpProgessorId); this.xpProgressor = RpgDataRegistry.Instance.SearchXpProgressor(this.xpProgressorId.GuidData); Debug.Assert(this.xpProgressor != null, "Deserializaing XpData failed because the XpProgressor was not found! ID: " + xpDataPacket.xpProgessorId); this.level = xpDataPacket.level; this.xp = xpDataPacket.xp; this.xpToNextLevel = xpDataPacket.xpToNextLevel; this.currentLevelMultiplier = xpDataPacket.currentLevelMultiplier; this.currentOldValueMultiplier = xpDataPacket.currentOldValueMultiplier; }
/// <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(); }
/// <summary> /// Deserialization Constructor /// </summary> public StatData(StatPacket statPacket, List <StatData> appliedStats) { Debug.Assert(statPacket != null, "New StatData being given a null StatPacket!"); Debug.Assert(appliedStats != null, "New StatData being given null list of applied stats!"); this.statId = new SaveableGuid(statPacket.statId); this.statReference = RpgDataRegistry.Instance.SearchAnyStat(this.statId.GuidData); Debug.Assert(this.statReference != null, "Could not deserialize a stat because its definition cannot be found. ID: " + statPacket.statId); this.type = this.statReference.GetStatType(); this.rawSpPool = statPacket.rawSpPool; this.useFactor = statPacket.useFactor; this.characterAppliedStats = appliedStats; // Initialize the SpDeriver switch (this.type) { case StatType.Base: this.linkedStatsDerivedPool = new BaseSpDeriver(this.statReference as BaseStat); break; case StatType.Secondary: this.linkedStatsDerivedPool = new SecondarySpDeriver(this.statReference as SecondaryStat); break; case StatType.Skill: this.linkedStatsDerivedPool = new SkillSpDeriver(this.statReference as SkillStat); break; default: Debug.LogError("Somebody added a new entry into the enum StatType"); break; } // Initialize the AbilityAggregator this.abilityModifications = new AbilityAggregator(this.statId.GuidData); }
/// <summary> /// Constructor needs an Ability and an AbilityModifier that is a part of that Ability /// </summary> public AbilityModifierData(AbilityModifier newModifier, Ability newAbility) { this.abilityId = new SaveableGuid(newAbility.Id); this.modifierIndex = -1; int indexTally = 0; foreach (AbilityModifier m in newAbility.StatModifiers) { if (ReferenceEquals(m, newModifier)) { this.abilityModifier = m; this.modifierIndex = indexTally; break; } indexTally++; } Debug.Assert(this.modifierIndex > -1, "AbilityModifierData for the Ability " + newAbility.Name + " could not find the proper AbilityModifier!"); }
/// <summary> /// StatData Constructor needs the stat definition file and the RpgCharacter's list of stats /// </summary> public StatData(AbstractStat newStat, List <StatData> appliedStats) { Debug.Assert(newStat != null, "New StatData being given a null AbstractStat!"); Debug.Assert(appliedStats != null, "New StatData being given null list of applied stats!"); this.statReference = newStat; this.characterAppliedStats = appliedStats; this.statId = new SaveableGuid(newStat.Id); this.type = newStat.GetStatType(); this.rawSpPool = 0; this.useFactor = 1; // Initialize the SpDeriver switch (this.type) { case StatType.Base: this.linkedStatsDerivedPool = new BaseSpDeriver(newStat as BaseStat); break; case StatType.Secondary: this.linkedStatsDerivedPool = new SecondarySpDeriver(newStat as SecondaryStat); break; case StatType.Skill: this.linkedStatsDerivedPool = new SkillSpDeriver(newStat as SkillStat); break; default: Debug.LogError("Somebody added a new entry into the enum StatType"); break; } // Initialize the AbilityAggregator this.abilityModifications = new AbilityAggregator(this.statId.GuidData); }
/// <summary> /// Constructor needs the Stat's ID being held in StatData /// </summary> public AbilityAggregator(Guid newStatId) { this.statId = new SaveableGuid(newStatId); }
/// <summary> /// Constructor needs an Ability /// </summary> public AbilityData(Ability newAbility) { this.ability = newAbility; this.id = new SaveableGuid(newAbility.Id); }
/// <summary> /// Base constructor needs the Guid represented by the StatData holding this deriver /// </summary> public AbstractSpDeriver(Guid newStatId) { this.statId = new SaveableGuid(newStatId); }