1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-19 02:46:35 -05:00
OpenDiablo2/OpenDiablo2.Common.UT/UT_PlayerState.cs
nicholasdechiara 55f8f3ef34 Mob and Playerstate (#31)
* Filled out eLevelId enum
- Added OpenDiablo2.Core.UT unit test project
- Added ELevelIdHelper class which contains code that generates the enum from the mpq data
- Added a unit test that verifies EngineDataManager works
- Added a unit test that runs the ELevelIdHelper generate function
- Renamed some enum values for constistency (e.g. Act1_Town -> Act1_Town1, as it is in the mpq)
* Retargeted OpenDiablo2.Core.UT to .net Framework 4.6.1
* Added TestConsole
TestConsole currently only supports writing the elevelids enum to a file
Also, removed elevelids generation unit test
* PlayerState and MobState
2018-11-29 21:20:29 -05:00

73 lines
2.9 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenDiablo2.Common.Models.Mobs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OpenDiablo2.Common.UT
{
[TestClass]
public class UT_PlayerState
{
private PlayerState MakePlayer()
{
HeroTypeConfig herotypeconfig = new HeroTypeConfig(vitality: 20, strength: 20, dexterity: 20,
energy: 20, health: 50, mana: 40, stamina: 30,
perlevelhealth: 3, perlevelmana: 1.5, perlevelstamina: 1,
pervitalityhealth: 2, pervitalitystamina: 1, perenergymana: 1.5,
baseatkrating: -30, basedefrating: -30, perdexterityatkrating: 5, perdexteritydefrating: 4);
LevelExperienceConfig expconfig = new LevelExperienceConfig(new List<int>()
{
0, // level 0
0, // level 1
500, // level 2
1500, // level 3
2250,
4125,
});
PlayerState ps = new PlayerState("player1", id: 1, level: 1, x: 0, y: 0,
vitality: herotypeconfig.StartingVitality,
strength: herotypeconfig.StartingStrength,
energy: herotypeconfig.StartingEnergy,
dexterity: herotypeconfig.StartingDexterity,
experience: 0,
herotype: Enums.eHero.Amazon,
heroconfig: herotypeconfig,
expconfig: expconfig);
return ps;
}
[TestMethod]
public void PlayerLevelUpTest()
{
PlayerState ps = MakePlayer();
int level1hp = ps.GetHealthMax();
int level1mana = ps.GetManaMax();
int level1stamina = ps.GetStaminaMax();
Assert.IsFalse(ps.AddExperience(499)); // not quite enough
Assert.IsTrue(ps.AddExperience(1)); // there we go
int level2hp = ps.GetHealthMax();
int level2mana = ps.GetManaMax();
int level2stamina = ps.GetStaminaMax();
Assert.IsFalse(ps.AddExperience(999)); // not quite enough
Assert.IsTrue(ps.AddExperience(1)); // there we go
int level3hp = ps.GetHealthMax();
int level3mana = ps.GetManaMax();
int level3stamina = ps.GetStaminaMax();
// this should update the player's health, mana, and stamina
Assert.AreEqual(level1hp + 3, level2hp);
Assert.AreEqual(level1mana + 1, level2mana);
Assert.AreEqual(level1stamina + 1, level2stamina);
Assert.AreEqual(level2hp + 3, level3hp);
Assert.AreEqual(level2mana + 2, level3mana); // because 2->3 is an odd levelup, should get 2
// more mana on this level (1.5 = +1 on even levels, +2 on odd)
Assert.AreEqual(level2stamina + 1, level3stamina);
}
}
}