Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using GrimoireEngine.Framework.Game;
  4. using GrimoireEngine.Framework.Interfaces;
  5. using GrimoireEngine.Framework.Logic;
  6. using GrimoireEngine.Framework.Maths;
  7.  
  8. namespace GrimoireEngine.Framework.Collections
  9. {
  10. public class PrimaryAttributes : IEquatable<PrimaryAttributes>, ICopy<PrimaryAttributes>
  11. {
  12. private int _strength;
  13. private int _agility;
  14. private int _stamina;
  15. private int _intellect;
  16. private int _wisdom;
  17. private int _spirit;
  18. private int _luck;
  19.  
  20. public const int Minimum = GameConstants.MinimumAttribute;
  21. public const int Maximum = GameConstants.MaximumAttribute;
  22. private static AttributeType[] _keys = (AttributeType[])Enum.GetValues(typeof(AttributeType));
  23.  
  24. public AttributeType[] Keys
  25. {
  26. get
  27. {
  28. return _keys;
  29. }
  30. }
  31.  
  32. public int Total
  33. {
  34. get
  35. {
  36. return _strength + _agility + _stamina + _intellect + _wisdom + _spirit + _luck;
  37. }
  38. }
  39.  
  40. public int Strength
  41. {
  42. get { return _strength; }
  43. set { _strength = Clamp(value); }
  44. }
  45.  
  46. public int Agility
  47. {
  48. get { return _agility; }
  49. set { _agility = Clamp(value); }
  50. }
  51.  
  52. public int Stamina
  53. {
  54. get { return _stamina; }
  55. set { _stamina = Clamp(value); }
  56. }
  57.  
  58. public int Intellect
  59. {
  60. get { return _intellect; }
  61. set { _intellect = Clamp(value); }
  62. }
  63.  
  64. public int Wisdom
  65. {
  66. get { return _wisdom; }
  67. set { _wisdom = Clamp(value); }
  68. }
  69.  
  70. public int Spirit
  71. {
  72. get { return _spirit; }
  73. set { _spirit = Clamp(value); }
  74. }
  75.  
  76. public int Luck
  77. {
  78. get { return _luck; }
  79. set { _luck = Clamp(value); }
  80. }
  81.  
  82. public AttributeType Highest
  83. {
  84. get
  85. {
  86. int value = (Minimum - 1);
  87. AttributeType highest = AttributeType.Strength;
  88. for (int i = 0; i < this.Keys.Length; i++)
  89. {
  90. int attributeValue = GetAttribute(this.Keys[i]);
  91. if (attributeValue > value)
  92. {
  93. highest = this.Keys[i];
  94. value = attributeValue;
  95. }
  96. }
  97. return highest;
  98. }
  99. }
  100.  
  101. public AttributeType Lowest
  102. {
  103. get
  104. {
  105. int value = (Maximum + 1);
  106. AttributeType lowest = AttributeType.Strength;
  107. for (int i = 0; i < this.Keys.Length; i++)
  108. {
  109. int attributeValue = GetAttribute(this.Keys[i]);
  110. if (attributeValue < value)
  111. {
  112. lowest = this.Keys[i];
  113. value = attributeValue;
  114. }
  115. }
  116. return lowest;
  117. }
  118. }
  119.  
  120. public PrimaryAttributes()
  121. {
  122.  
  123. }
  124.  
  125. public PrimaryAttributes(int strength, int agility, int stamina, int intellect, int wisdom, int spirit,
  126. int luck)
  127. {
  128. Copy(strength,agility,stamina,intellect,wisdom,spirit,luck);
  129. }
  130.  
  131. public void Copy(int strength, int agility, int stamina, int intellect, int wisdom, int spirit,
  132. int luck)
  133. {
  134. this.Strength = strength;
  135. this.Agility = agility;
  136. this.Stamina = stamina;
  137. this.Intellect = intellect;
  138. this.Wisdom = wisdom;
  139. this.Spirit = spirit;
  140. this.Luck = luck;
  141. }
  142.  
  143. /// <summary>
  144. ///
  145. /// </summary>
  146. /// <returns></returns>
  147. public int GetHealth()
  148. {
  149. return ((_stamina + GetSpiritModifier()) * 24);
  150. }
  151.  
  152. public int GetAttackpower()
  153. {
  154. return (_strength + ((_agility + (_spirit * 2)) / 2));
  155. }
  156.  
  157. public int GetSpellpower()
  158. {
  159. return (_intellect + ((_wisdom + (_spirit * 2)) / 2));
  160. }
  161.  
  162. public int GetSpiritModifier()
  163. {
  164. return (_spirit / 2);
  165. }
  166.  
  167. public float GetCriticalstrike()
  168. {
  169. return ((_luck / 5f) / 100f);
  170. }
  171.  
  172. public int GetAttribute(AttributeType attribute, bool includeSpiritModifier = false)
  173. {
  174. switch (attribute)
  175. {
  176. case AttributeType.Strength:
  177. return includeSpiritModifier ? (this._strength + GetSpiritModifier()) : this._strength;
  178. case AttributeType.Agility:
  179. return includeSpiritModifier ? (this._agility + GetSpiritModifier()) : this._agility;
  180. case AttributeType.Stamina:
  181. return includeSpiritModifier ? (this._stamina + GetSpiritModifier()) : this._stamina;
  182. case AttributeType.Intellect:
  183. return includeSpiritModifier ? (this._intellect + GetSpiritModifier()) : this._intellect;
  184. case AttributeType.Wisdom:
  185. return includeSpiritModifier ? (this._wisdom + GetSpiritModifier()) : this._wisdom;
  186. case AttributeType.Spirit:
  187. return includeSpiritModifier ? (this._spirit + GetSpiritModifier()) : this._spirit;
  188. case AttributeType.Luck:
  189. return includeSpiritModifier ? (this._luck + GetSpiritModifier()) : this._luck;
  190. default:
  191. throw new ArgumentOutOfRangeException(nameof(attribute), attribute, null);
  192. }
  193. }
  194.  
  195. public void SetAttribute(AttributeType attribute, int value)
  196. {
  197. switch (attribute)
  198. {
  199. case AttributeType.Strength:
  200. Strength = value;
  201. break;
  202. case AttributeType.Agility:
  203. Agility = value;
  204. break;
  205. case AttributeType.Stamina:
  206. Stamina = value;
  207. break;
  208. case AttributeType.Intellect:
  209. Intellect = value;
  210. break;
  211. case AttributeType.Wisdom:
  212. Wisdom = value;
  213. break;
  214. case AttributeType.Spirit:
  215. Spirit = value;
  216. break;
  217. case AttributeType.Luck:
  218. Luck = value;
  219. break;
  220. default:
  221. throw new ArgumentOutOfRangeException(nameof(attribute), attribute, null);
  222. }
  223. }
  224.  
  225. public void Multiply(AttributeType attribute, float multiplier)
  226. {
  227. SetAttribute(attribute, (int)(GetAttribute(attribute) * multiplier));
  228. }
  229.  
  230. public void IncreaseAttribute(AttributeType attribute, int amount)
  231. {
  232. SetAttribute(attribute, GetAttribute(attribute) + amount);
  233. }
  234.  
  235. public void DecreaseAttribute(AttributeType attribute, int amount)
  236. {
  237. SetAttribute(attribute, GetAttribute(attribute) - amount);
  238. }
  239.  
  240. public void Clear()
  241. {
  242. _strength = Minimum;
  243. _agility = Minimum;
  244. _stamina = Minimum;
  245. _intellect = Minimum;
  246. _wisdom = Minimum;
  247. _spirit = Minimum;
  248. _luck = Minimum;
  249. }
  250.  
  251. public void Clear(AttributeType attribute)
  252. {
  253. SetAttribute(attribute, 0);
  254. }
  255.  
  256. public Dictionary<AttributeType, int> ToDictionary()
  257. {
  258. Dictionary<AttributeType, int> attributes = new Dictionary<AttributeType, int>
  259. {
  260. {AttributeType.Strength, _strength},
  261. {AttributeType.Agility, _agility},
  262. {AttributeType.Stamina, _stamina},
  263. {AttributeType.Intellect, _intellect},
  264. {AttributeType.Wisdom, _wisdom},
  265. {AttributeType.Spirit, _spirit},
  266. {AttributeType.Luck, _luck},
  267. };
  268. return attributes;
  269. }
  270.  
  271. public void Add(PrimaryAttributes other)
  272. {
  273. this.Strength += other._strength;
  274. this.Agility += other._agility;
  275. this.Stamina += other._stamina;
  276. this.Intellect += other._intellect;
  277. this.Wisdom += other._wisdom;
  278. this.Spirit += other._spirit;
  279. this.Luck += other._luck;
  280. }
  281.  
  282. public void Subtract(PrimaryAttributes other)
  283. {
  284. this.Strength -= other._strength;
  285. this.Agility -= other._agility;
  286. this.Stamina -= other._stamina;
  287. this.Intellect -= other._intellect;
  288. this.Wisdom -= other._wisdom;
  289. this.Spirit -= other._spirit;
  290. this.Luck -= other._luck;
  291. }
  292.  
  293. private static int Clamp(int value)
  294. {
  295. return GrimoireMathHelper.Clamp(value, Minimum, Maximum);
  296. }
  297.  
  298. public void Copy(PrimaryAttributes other)
  299. {
  300. _strength = other._strength;
  301. _agility = other._agility;
  302. _stamina = other._stamina;
  303. _intellect = other._intellect;
  304. _wisdom = other._wisdom;
  305. _spirit = other._spirit;
  306. _luck = other._luck;
  307. }
  308.  
  309. public PrimaryAttributes MakeCopy()
  310. {
  311. PrimaryAttributes attributes = new PrimaryAttributes();
  312. attributes.Copy(this);
  313. return attributes;
  314. }
  315.  
  316. public bool Equals(PrimaryAttributes other)
  317. {
  318. return other != null && (
  319. _strength == other._strength &&
  320. _agility == other._agility &&
  321. _stamina == other._stamina &&
  322. _intellect == other._intellect &&
  323. _wisdom == other._wisdom &&
  324. _spirit == other._spirit &&
  325. _luck == other._luck);
  326. }
  327.  
  328. public override bool Equals(object obj)
  329. {
  330. return obj != null && Equals((PrimaryAttributes)obj);
  331. }
  332.  
  333. public override int GetHashCode()
  334. {
  335. unchecked
  336. {
  337. int hashCode = _strength;
  338. hashCode = (hashCode * 397) ^ _agility;
  339. hashCode = (hashCode * 397) ^ _stamina;
  340. hashCode = (hashCode * 397) ^ _intellect;
  341. hashCode = (hashCode * 397) ^ _wisdom;
  342. hashCode = (hashCode * 397) ^ _spirit;
  343. hashCode = (hashCode * 397) ^ _luck;
  344. return hashCode;
  345. }
  346. }
  347. }
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement