public void TestGetPenaltyByGame() { D2Game g = new D2Game(); // expansion g.LODFlag = 1; // normal g.Difficulty = 0; Assert.AreEqual(0, ResistancePenalty.GetPenaltyByGame(g)); // nm g.Difficulty = 1; Assert.AreEqual(-40, ResistancePenalty.GetPenaltyByGame(g)); // hell g.Difficulty = 2; Assert.AreEqual(-100, ResistancePenalty.GetPenaltyByGame(g)); // classic g.LODFlag = 0; // normal g.Difficulty = 0; Assert.AreEqual(0, ResistancePenalty.GetPenaltyByGame(g)); // nm g.Difficulty = 1; Assert.AreEqual(-20, ResistancePenalty.GetPenaltyByGame(g)); // hell g.Difficulty = 2; Assert.AreEqual(-50, ResistancePenalty.GetPenaltyByGame(g)); }
/// <summary> /// fill the player data by dictionary /// </summary> /// <param name="dict"></param> /// <param name="resistancPenalty"></param> internal void ParseStats(Dictionary <StatIdentifier, D2Stat> data, Dictionary <StatIdentifier, D2Stat> itemData, D2GameInfo gameInfo) { // Don't update stats while dead. if (IsDead) { return; } CharClass = (CharacterClass)gameInfo.Player.eClass; int penalty = (int)ResistancePenalty.GetPenaltyByGameDifficulty((GameDifficulty)gameInfo.Game.Difficulty); Func <StatIdentifier, int> getStat = statID => { D2Stat stat; // Get the value if if the key exists, else assume zero. return(data.TryGetValue(statID, out stat) ? stat.Value : 0); }; Func <StatIdentifier, int> getItemStat = statID => { D2Stat stat; // Get the value if if the key exists, else assume zero. return(itemData.TryGetValue(statID, out stat) ? stat.Value : 0); }; Level = getStat(StatIdentifier.Level); Experience = getStat(StatIdentifier.Experience); VelocityPercent = getStat(StatIdentifier.VelocityPercent); AttackRate = getStat(StatIdentifier.AttackRate); Strength = getStat(StatIdentifier.Strength); Dexterity = getStat(StatIdentifier.Dexterity); Vitality = getStat(StatIdentifier.Vitality); Energy = getStat(StatIdentifier.Energy); Defense = getStat(StatIdentifier.Defense); int maxFire = BASE_MAX_RESIST + getStat(StatIdentifier.ResistFireMax); int maxCold = BASE_MAX_RESIST + getStat(StatIdentifier.ResistColdMax); int maxLightning = BASE_MAX_RESIST + getStat(StatIdentifier.ResistLightningMax); int maxPoison = BASE_MAX_RESIST + getStat(StatIdentifier.ResistPoisonMax); FireResist = Utility.Clamp(getStat(StatIdentifier.ResistFire) + penalty, MIN_RESIST, maxFire); ColdResist = Utility.Clamp(getStat(StatIdentifier.ResistCold) + penalty, MIN_RESIST, maxCold); LightningResist = Utility.Clamp(getStat(StatIdentifier.ResistLightning) + penalty, MIN_RESIST, maxLightning); PoisonResist = Utility.Clamp(getStat(StatIdentifier.ResistPoison) + penalty, MIN_RESIST, maxPoison); FasterHitRecovery = getItemStat(StatIdentifier.FasterHitRecovery); FasterRunWalk = getItemStat(StatIdentifier.FasterRunWalk); FasterCastRate = getItemStat(StatIdentifier.FasterCastRate); IncreasedAttackSpeed = getItemStat(StatIdentifier.IncreasedAttackSpeed); Gold = getStat(StatIdentifier.Gold); GoldStash = getStat(StatIdentifier.GoldStash); }