-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.cs
More file actions
138 lines (118 loc) · 5.17 KB
/
Move.cs
File metadata and controls
138 lines (118 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Linq;
using System.Xml;
using EnumBuilder;
using Microsoft.Xna.Framework.Content;
namespace PokeMan
{
[Serializable]
public class Move : IDisplayable
{
public int LoadAmount = 0;
private ElementEnum element;
private string name;
private int power;
private int accuracy;
private int id;
public SpriteAnimation Animation;
public string Name { get => name; private set => name = value; }
public int Power { get => power; private set => power = value; }
public int Accuracy { get => accuracy; private set => accuracy = value; }
/// <summary>
/// Creates a new move for use in battle, using the Moves.XML file
/// </summary>
/// <param name="id">ID: identifies the specific move that the user wants to use</param>
public Move(int id)
{
this.id = id;
XmlDocument doc = new XmlDocument();
doc.Load("../../../Content/Xml/Moves.xml");
var node = doc.DocumentElement.SelectSingleNode("/Moves");
node = node.Cast<XmlNode>().First(a => int.Parse(a.Attributes["id"].Value) == id);
Name = node.Attributes["name"].Value;
Power = int.Parse(node.Attributes["power"].Value);
Accuracy = int.Parse(node.Attributes["accuracy"].Value);
element = (ElementEnum)Enum.Parse(typeof(ElementEnum), node.Attributes["element"].Value);
}
public void LoadAssets(ContentManager contMan)
{
//Loads animation sprites based off xml doc
XmlDocument doc = new XmlDocument();
doc.Load("../../../Content/Xml/Moves.xml");
var node = doc.DocumentElement.SelectSingleNode("/Moves");
node = node.Cast<XmlNode>().First(a => int.Parse(a.Attributes["id"].Value) == id);
node = node.SelectSingleNode("Animation");
int j = 0;
var t = new Texture2D[node.ChildNodes.Count];
foreach (XmlNode m in node.SelectNodes("Frame"))
{
t[j++] = contMan.Load<Texture2D>($"{node.Attributes["path"].Value}{m.InnerText}");
}
Animation = new SpriteAnimation(t, uint.Parse(node.Attributes["inverseSpeed"].Value));
LoadAmount = 1;
}
/// <summary>
/// Makes an attack against "enemy" pokeman with "user" pokeman
/// Calc based on https://bulbapedia.bulbagarden.net/wiki/Damage
/// </summary>
/// <param name="user"></param>
/// <param name="enemy"></param>
public void DoMove(PokeMan user, PokeMan enemy)
{
//enemy.TakeDmg((int)(power * GetElementMultiplier(user.Element, element, enemy.Element)));
// https://bulbapedia.bulbagarden.net/wiki/Damage
enemy.TakeDmg((int)(((((((2 * user.lvl) / 5) + 2) * Power * user.AttackStat / enemy.DefenceStat) / 50) + 2) * GetElementMultiplier(user.Element, element, enemy.Element)));
}
/// <summary>
/// Calculates the dmg based on the users pokemans "attacking" stat, the "move" number and the "defending" pokemans stats
/// </summary>
/// <param name="attacking"></param>
/// <param name="move"></param>
/// <param name="defending"></param>
/// <returns></returns>
private static float GetElementMultiplier(ElementEnum attacking, ElementEnum move, ElementEnum defending)
{
float result = 1f;
if (attacking == move)
result *= 2f;
//Loads weaknesses based off xml doc
XmlDocument doc = new XmlDocument();
doc.Load("../../../Content/Xml/Elements.xml");
var node = doc.DocumentElement.SelectSingleNode("/Elements");
foreach (XmlNode n in node.SelectNodes("Element"))
{
if ((ElementEnum)Enum.Parse(typeof(ElementEnum), n.Attributes["name"].Value, true) == defending)
{
foreach (XmlNode m in n.SelectNodes("Weakness"))
{
if ((ElementEnum)Enum.Parse(typeof(ElementEnum), m.Attributes["name"].Value, true) == move)
result *= 2f;
}
}
if ((ElementEnum)Enum.Parse(typeof(ElementEnum), n.Attributes["name"].Value, true) == move)
{
foreach (XmlNode m in n.SelectNodes("Weakness"))
{
if ((ElementEnum)Enum.Parse(typeof(ElementEnum), m.Attributes["name"].Value, true) == defending)
result *= 0.5f;
}
}
}
return result;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(Animation, Vector2.Zero, Color.White);
}
/// <summary>
/// Stores this moves name as a string (to display in battle scene after a move)
/// </summary>
/// <returns></returns>
public override string ToString()
{
return this.Name;
}
}
}