/// <summary>Finds the average health curve between the race and class health curves (rounded up)</summary> /// <param name="raceCurve_">The designated health curve for the character's race</param> /// <param name="classCurve_">The designated health curve for the character's class</param> /// <returns>The health curve between the two</returns> private HealthCurveTypes FindHealthCurveAverage(HealthCurveTypes raceCurve_, HealthCurveTypes classCurve_) { //Converting the health curve enums to numeric values int rc = (int)raceCurve_; int cc = (int)classCurve_; //Finding the average between the two, rounded up int average = (rc + cc); if (average % 2 != 0) { average++; } average = average / 2; //Converting the average back into an enum return((HealthCurveTypes)average); }
//Function called from TrackTimePassage to get the amount of health a character will gain private int GetHealthToAdd(HealthCurveTypes type_) { //The amount of health to add that is returned int healthToAdd = 0; //The health curve that we use based on the progression type HealthCurve curveToUse = this.healthCurveTypes[0]; //Looping through all of our health curves until we find one that matches the designated type for (int l = 0; l < this.healthCurveTypes.Count; ++l) { //If we find a match, we set it as the curve to use and break the loop if (this.healthCurveTypes[l].curveType == type_) { curveToUse = this.healthCurveTypes[l]; break; } } //Finding the difference in health between the min and max for this curve int minMaxCurve = curveToUse.maxHealthGiven - curveToUse.minHealthGiven; //Getting the value along the curve to multiply based on the number of days passed float percent = (1f * this.currentDaysPassed) / (1f * this.healthIncreasesUntilMax); percent = curveToUse.curveBetweenMinMax.Evaluate(percent); //Adding the amount based on our curve progress and the minimum health to give healthToAdd += Mathf.RoundToInt(minMaxCurve * percent); healthToAdd += curveToUse.minHealthGiven; //Looping through for each die roll for random amount of health int diceResult = 0; for (int d = 0; d < curveToUse.diceRolled; ++d) { //Adding the die roll value to the amount of health to add based on the sides on the die diceResult += Random.Range(1, curveToUse.numberOfDiceSides + 1); } //If we roll twice and take the best result, we roll again if (curveToUse.rollTwiceTakeBest) { int secondRoll = 0; for (int b = 0; b < curveToUse.diceRolled; ++b) { secondRoll += Random.Range(1, curveToUse.numberOfDiceSides + 1); } //If this second roll is better than the original dice roll, it becomes the new dice roll value if (diceResult < secondRoll) { diceResult = secondRoll; } } //If we roll twice and take the worst result, we roll again else if (curveToUse.rollTwiceTakeWorst) { int secondRoll = 0; for (int w = 0; w < curveToUse.diceRolled; ++w) { secondRoll += Random.Range(1, curveToUse.numberOfDiceSides + 1); } //If this second roll is worse than the original dice roll, it becomes the new dice roll value if (diceResult > secondRoll) { diceResult = secondRoll; } } //returning the total health return(healthToAdd + diceResult); }
//Constructor for this class public CharacterSaveData(Character characterToSave_) { //Setting variables from Character.cs this.charName = characterToSave_.charName; this.className = characterToSave_.className; //Setting variables from RaceTypes.cs this.race = characterToSave_.charRaceTypes.race; this.subtypeList = characterToSave_.charRaceTypes.subtypeList; //Setting variables from Skills.cs this.strength = characterToSave_.charSkills.GetSkillStatLevelValue(SkillStats.Strength); this.finesse = characterToSave_.charSkills.GetSkillStatLevelValue(SkillStats.Finesse); this.willpower = characterToSave_.charSkills.GetSkillStatLevelValue(SkillStats.Willpower); this.spirit = characterToSave_.charSkills.GetSkillStatLevelValue(SkillStats.Spirit); this.unarmed = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Unarmed); this.daggers = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Daggers); this.swords = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Swords); this.mauls = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Mauls); this.poles = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Poles); this.bows = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Bows); this.shields = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Shields); this.arcaneMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.ArcaneMagic); this.enchantMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.EnchantMagic); this.holyMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.HolyMagic); this.darkMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.DarkMagic); this.fireMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.FireMagic); this.waterMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.WaterMagic); this.windMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.WindMagic); this.electricMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.ElectricMagic); this.stoneMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.StoneMagic); //Setting variables from PhysicalState.cs this.maxHP = characterToSave_.charPhysState.maxHealth; this.currentHP = characterToSave_.charPhysState.currentHealth; this.corruptionLevel = characterToSave_.charPhysState.corruptionLevel; //Setting variables from CombatStats.cs this.currentInitiativeSpeed = characterToSave_.charCombatStats.currentInitiativeSpeed; this.startingCol = characterToSave_.charCombatStats.startingPositionCol; this.startingRow = characterToSave_.charCombatStats.startingPositionRow; this.accuracy = characterToSave_.charCombatStats.accuracy; this.evasion = characterToSave_.charCombatStats.evasion; this.combatEffects = new List <string>(); for (int ce = 0; ce < characterToSave_.charCombatStats.combatEffects.Count; ++ce) { this.combatEffects.Add(JsonUtility.ToJson(characterToSave_.charCombatStats.combatEffects[ce])); } //Setting variables from ActionList.cs PrefabIDTagData actionIDData; if (characterToSave_.charActionList.actionSlot1 != null) { actionIDData = new PrefabIDTagData(characterToSave_.charActionList.actionSlot1.GetComponent <IDTag>()); this.action1 = JsonUtility.ToJson(actionIDData); } if (characterToSave_.charActionList.actionSlot2 != null) { actionIDData = new PrefabIDTagData(characterToSave_.charActionList.actionSlot2.GetComponent <IDTag>()); this.action2 = JsonUtility.ToJson(actionIDData); } if (characterToSave_.charActionList.actionSlot3 != null) { actionIDData = new PrefabIDTagData(characterToSave_.charActionList.actionSlot3.GetComponent <IDTag>()); this.action3 = JsonUtility.ToJson(actionIDData); } if (characterToSave_.charActionList.actionSlot4 != null) { actionIDData = new PrefabIDTagData(characterToSave_.charActionList.actionSlot4.GetComponent <IDTag>()); this.action4 = JsonUtility.ToJson(actionIDData); } if (characterToSave_.charActionList.actionSlot5 != null) { actionIDData = new PrefabIDTagData(characterToSave_.charActionList.actionSlot5.GetComponent <IDTag>()); this.action5 = JsonUtility.ToJson(actionIDData); } if (characterToSave_.charActionList.ultimateAction != null) { actionIDData = new PrefabIDTagData(characterToSave_.charActionList.ultimateAction.GetComponent <IDTag>()); this.ultimateAction = JsonUtility.ToJson(actionIDData); } this.rechargingSpells = new List <string>(); for (int rs = 0; rs < characterToSave_.charActionList.rechargingSpells.Count; ++rs) { this.rechargingSpells.Add(JsonUtility.ToJson(characterToSave_.charActionList.rechargingSpells[rs])); } //Setting all of the equipped object references if (characterToSave_.charEquipment.helm != null) { this.helmObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charEquipment.helm.GetComponent <IDTag>())); } if (characterToSave_.charEquipment.body != null) { this.chestObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charEquipment.body.GetComponent <IDTag>())); } if (characterToSave_.charEquipment.trinket != null) { this.trinketObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charEquipment.trinket.GetComponent <IDTag>())); } if (characterToSave_.charEquipment.leftHand != null) { this.leftHandObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charEquipment.leftHand.GetComponent <IDTag>())); } if (characterToSave_.charEquipment.rightHand != null) { this.rightHandObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charEquipment.rightHand.GetComponent <IDTag>())); } //Looping through all of the character perks to save their object references this.perkNames = new List <string>(); for (int p = 0; p < characterToSave_.charPerks.allPerks.Count; ++p) { //Making sure the current perk isn't null if (characterToSave_.charPerks.allPerks[p] != null) { //Saving this perk's ID tag info this.perkNames.Add(JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charPerks.allPerks[p].GetComponent <IDTag>()))); } } //Setting variables from LevelTracker.cs this.level = characterToSave_.levelTracker.level; this.exp = characterToSave_.levelTracker.currentEXP; this.healthCurve = characterToSave_.levelTracker.defaultHealthCurve; this.healthCurveMod = characterToSave_.levelTracker.healthCurveMod; this.combatsWonLevel = characterToSave_.levelTracker.combatsWonLevel; this.spacesMovedLevel = characterToSave_.levelTracker.spacesMovedLevel; this.damageDealtLevel = characterToSave_.levelTracker.damageDealtLevel; this.damageTakenLevel = characterToSave_.levelTracker.damageTakenLevel; this.skillsUsedLevel = characterToSave_.levelTracker.skillsUsedLevel; this.armorValuesLevel = characterToSave_.levelTracker.armorValuesLevel; this.healthAvgLevel = characterToSave_.levelTracker.healthAvgLevel; this.combatsWonLifetime = characterToSave_.levelTracker.combatsWonLifetime; this.spacesMovedLifetime = characterToSave_.levelTracker.spacesMovedLifetime; this.damageDealtLifetime = characterToSave_.levelTracker.damageDealtLifetime; this.damageTakenLifetime = characterToSave_.levelTracker.damageTakenLifetime; this.skillsUsedLifetime = characterToSave_.levelTracker.skillsUsedLifetime; this.armorValuesLifetime = characterToSave_.levelTracker.armorValuesLifetime; this.healthAvgLifetime = characterToSave_.levelTracker.healthAvgLifetime; }
//Constructor for this class public CharacterSaveData(Character characterToSave_) { //Setting variables from Character.cs this.firstName = characterToSave_.firstName; this.lastName = characterToSave_.lastName; this.sex = characterToSave_.sex; //Setting variables from RaceTypes.cs this.race = characterToSave_.charRaceTypes.race; this.subtypeList = characterToSave_.charRaceTypes.subtypeList; //Setting variables from Skills.cs this.unarmed = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Unarmed); this.daggers = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Daggers); this.swords = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Swords); this.mauls = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Mauls); this.poles = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Poles); this.bows = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Bows); this.shields = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Shields); this.arcaneMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.ArcaneMagic); this.holyMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.HolyMagic); this.darkMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.DarkMagic); this.fireMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.FireMagic); this.waterMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.WaterMagic); this.windMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.WindMagic); this.electricMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.ElectricMagic); this.stoneMagic = characterToSave_.charSkills.GetSkillLevelValue(SkillList.StoneMagic); this.survivalist = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Survivalist); this.social = characterToSave_.charSkills.GetSkillLevelValue(SkillList.Social); //Setting variables from PhysicalState.cs this.maxHP = characterToSave_.charPhysState.maxHealth; this.currentHP = characterToSave_.charPhysState.currentHealth; this.maxFood = characterToSave_.charPhysState.maxFood; this.currentFood = characterToSave_.charPhysState.currentFood; this.maxWater = characterToSave_.charPhysState.maxWater; this.currentWater = characterToSave_.charPhysState.currentWater; this.maxSleep = characterToSave_.charPhysState.maxSleep; this.currentSleep = characterToSave_.charPhysState.currentSleep; this.requireFood = characterToSave_.charPhysState.requiresFood; this.requireWater = characterToSave_.charPhysState.requiresWater; this.requireSleep = characterToSave_.charPhysState.requiresSleep; this.startingHealthCurve = characterToSave_.charPhysState.startingHealthCurve; this.healthCurveLevels = characterToSave_.charPhysState.healthCurveLevels; this.highestHealthPercent = characterToSave_.charPhysState.highestHealthPercent; this.highestFoodPercent = characterToSave_.charPhysState.highestFoodPercent; this.highestWaterPercent = characterToSave_.charPhysState.highestWaterPercent; this.highestSleepPercent = characterToSave_.charPhysState.highestSleepPercent; this.trackingHealthPercents = characterToSave_.charPhysState.trackingHealthPercents; this.trackingFoodPercents = characterToSave_.charPhysState.trackingFoodPercents; this.trackingWaterPercents = characterToSave_.charPhysState.trackingWaterPercents; this.trackingSleepPercents = characterToSave_.charPhysState.trackingSleepPercents; //Setting variables from CombatStats.cs this.currentInitiativeSpeed = characterToSave_.charCombatStats.currentInitiativeSpeed; this.startingCol = characterToSave_.charCombatStats.startingPositionCol; this.startingRow = characterToSave_.charCombatStats.startingPositionRow; this.accuracy = characterToSave_.charCombatStats.accuracy; this.evasion = characterToSave_.charCombatStats.evasion; this.combatEffects = new List <string>(); for (int ce = 0; ce < characterToSave_.charCombatStats.combatEffects.Count; ++ce) { this.combatEffects.Add(JsonUtility.ToJson(characterToSave_.charCombatStats.combatEffects[ce])); } //Setting variables from ActionList.cs this.defaultActions = new List <string>(); for (int da = 0; da < characterToSave_.charActionList.defaultActions.Count; ++da) { PrefabIDTagData actionIDData = new PrefabIDTagData(characterToSave_.charActionList.defaultActions[da].GetComponent <IDTag>()); this.defaultActions.Add(JsonUtility.ToJson(actionIDData)); } this.rechargingSpells = new List <string>(); for (int rs = 0; rs < characterToSave_.charActionList.rechargingSpells.Count; ++rs) { this.rechargingSpells.Add(JsonUtility.ToJson(characterToSave_.charActionList.rechargingSpells[rs])); } //Setting variables from CharacterSprites.cs this.ourSprites = characterToSave_.charSprites.allSprites; //Setting all of the equipped object references if (characterToSave_.charInventory.helm != null) { this.helmObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.helm.GetComponent <IDTag>())); } if (characterToSave_.charInventory.chestPiece != null) { this.chestObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.chestPiece.GetComponent <IDTag>())); } if (characterToSave_.charInventory.leggings != null) { this.legObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.leggings.GetComponent <IDTag>())); } if (characterToSave_.charInventory.gloves != null) { this.gloveObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.gloves.GetComponent <IDTag>())); } if (characterToSave_.charInventory.shoes != null) { this.shoeObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.shoes.GetComponent <IDTag>())); } if (characterToSave_.charInventory.cloak != null) { this.cloakObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.cloak.GetComponent <IDTag>())); } if (characterToSave_.charInventory.necklace != null) { this.necklaceObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.necklace.GetComponent <IDTag>())); } if (characterToSave_.charInventory.ring != null) { this.ringObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.ring.GetComponent <IDTag>())); } if (characterToSave_.charInventory.leftHand != null) { this.leftHandObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.leftHand.GetComponent <IDTag>())); } if (characterToSave_.charInventory.rightHand != null) { this.rightHandObj = JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charInventory.rightHand.GetComponent <IDTag>())); } //Looping through all of the character inventory items to save their object references this.inventorySlots = new List <string>(); this.stackedItems = new List <string>(); for (int i = 0; i < characterToSave_.charInventory.itemSlots.Count; ++i) { //Making sure the current inventory object isn't null if (characterToSave_.charInventory.itemSlots[i] != null) { //Reference to the item's IDTag component IDTag itemTag = characterToSave_.charInventory.itemSlots[i].GetComponent <IDTag>(); //Saving the IDTag info this.inventorySlots.Add(JsonUtility.ToJson(new PrefabIDTagData(itemTag))); //If the current item is a stack if (characterToSave_.charInventory.itemSlots[i].currentStackSize > 1) { //Creating a new InventoryItemStackData class to store the item stack InventoryItemStackData stack = new InventoryItemStackData(i, itemTag, characterToSave_.charInventory.itemSlots[i].currentStackSize); //Adding a serialized version of the stack data to our list of stacked items this.stackedItems.Add(JsonUtility.ToJson(stack)); } } //If the current item is null, we set a null slot to keep the empty space else { this.inventorySlots.Add(""); } } //Looping through all of the character perks to save their object references this.perkNames = new List <string>(); for (int p = 0; p < characterToSave_.charPerks.allPerks.Count; ++p) { //Making sure the current perk isn't null if (characterToSave_.charPerks.allPerks[p] != null) { //Saving this perk's ID tag info this.perkNames.Add(JsonUtility.ToJson(new PrefabIDTagData(characterToSave_.charPerks.allPerks[p].GetComponent <IDTag>()))); } } }