Created
November 26, 2017 21:04
-
-
Save hellos3b/10fdec26c1899de3d4e0bc36dfea0f46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Creature { | |
public string Name { get; set; } | |
public int Level { get; set; } | |
public GearItem[] Gear { get; set; } | |
public CreatureType Type { get; set; } | |
public string GUID { get; set; } | |
public Color color { get; set; } | |
// Stats | |
public Stat STR; | |
public Stat INT; | |
public Stat DEF; | |
public Stat VIT; | |
public Stat SPD; | |
public Stat MGDEF; | |
// Bonuses from equipped gear that increase your stats | |
public Dictionary<BonusType, float> Bonuses; | |
public int MaxHealth = CreatureConfig.HEALTH_INCREASE; | |
public int Health = CreatureConfig.HEALTH_INCREASE; | |
public Creature() { | |
GUID = System.Guid.NewGuid().ToString(); | |
STR = new Stat(this); | |
INT = new Stat(this); | |
DEF = new Stat(this); | |
VIT = new Stat(this); | |
SPD = new Stat(this); | |
MGDEF = new Stat(this); | |
} | |
// Initialize the dict of bonuses from the enum with a value of 0 | |
void InitBonuses() { | |
Bonuses = new Dictionary<BonusType, float>(); | |
System.Array bonuses = System.Enum.GetValues(typeof(BonusType)); | |
foreach (BonusType type in bonuses) { | |
Bonuses[type] = 0; | |
} | |
} | |
// Iterate over equipped gear and set the bonus values in the dictionary | |
public void CalculateBonuses() { | |
InitBonuses(); | |
foreach (var gear in Gear) { | |
if (gear.Type == GearType.STR) { | |
Bonuses[BonusType.WEAPON_STR] += gear.Power; | |
} else if (gear.Type == GearType.INT) { | |
Bonuses[BonusType.WEAPON_INT] += gear.Power; | |
} else if (gear.Type == GearType.DEF) { | |
Bonuses[BonusType.WEAPON_DEF] += gear.Power; | |
} else if (gear.Type == GearType.VIT) { | |
Bonuses[BonusType.WEAPON_VIT] += gear.Power; | |
} | |
foreach(var bonus in gear.Bonus) { | |
Bonuses[bonus.Key] = Bonuses[bonus.Key] + bonus.Value; | |
} | |
} | |
} | |
// Getter by enum | |
public float Bonus(BonusType type) { | |
return Bonuses[type]; | |
} | |
// Reset maxhealth + heatlh | |
void UpdateHealth() { | |
MaxHealth = VIT * CreatureConfig.HEALTH_INCREASE; | |
Health = MaxHealth; | |
} | |
public GearItem GetGear(GearSlot slot) { | |
return Gear[(int)slot]; | |
} | |
// Find the difference of stats if equipped a different set of gear | |
public StatDiff GetGearStatDiff(GearItem[] gear) { | |
Creature c = Copy(); | |
c.Gear = gear; | |
c.CalculateBonuses(); | |
StatDiff diff = new StatDiff(); | |
diff.STR = c.GetAdjustedSTR() - GetAdjustedSTR(); | |
diff.DEF = c.GetAdjustedDEF() - GetAdjustedDEF(); | |
diff.INT = c.GetAdjustedINT() - GetAdjustedINT(); | |
diff.VIT = c.GetAdjustedVIT() - GetAdjustedVIT(); | |
diff.MGDEF = c.GetAdjustedMGDEF() - GetAdjustedMGDEF(); | |
diff.SPD = c.GetAdjustedSPD() - GetAdjustedSPD(); | |
return diff; | |
} | |
public Creature Copy() { | |
return new Creature { | |
Level = Level, | |
Gear = (GearItem[])Gear.Clone() | |
}; | |
} | |
public Creature EquipGear(GearSlot slot, GearItem gear) { | |
GearItem current = Gear[(int)slot]; | |
if (current.GUID != null) { | |
Database.AddGear(current); | |
} | |
Gear[(int)slot] = gear; | |
Database.RemoveGear(gear); | |
return this; | |
} | |
public int CalcAdjustedStat(float baseVal, BonusType bonus, BonusType bonusAmt) { | |
baseVal += Bonuses[bonusAmt]; | |
baseVal += baseVal * Bonuses[bonus]; | |
return (int)Mathf.Floor(baseVal); | |
} | |
public int CalcAdjustedStat(float baseVal, BonusType bonus) { | |
baseVal += baseVal * Bonuses[bonus]; | |
return (int)Mathf.Floor(baseVal); | |
} | |
public int GetAdjustedSTR() { | |
return CalcAdjustedStat(STR, BonusType.STR_BONUS, BonusType.WEAPON_STR); | |
} | |
public int GetAdjustedDEF() { | |
return CalcAdjustedStat(DEF, BonusType.DEF_BONUS, BonusType.WEAPON_DEF); | |
} | |
public int GetAdjustedVIT() { | |
return CalcAdjustedStat(VIT, BonusType.VIT_BONUS, BonusType.WEAPON_VIT); | |
} | |
public int GetAdjustedINT() { | |
return CalcAdjustedStat(INT, BonusType.INT_BONUS, BonusType.WEAPON_INT); | |
} | |
public int GetAdjustedSPD() { | |
return CalcAdjustedStat(SPD, BonusType.SPD_BONUS); | |
} | |
public int GetAdjustedMGDEF() { | |
return CalcAdjustedStat(MGDEF, BonusType.MGDEF_BONUS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment