InvGameItem.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine;
  5. [Serializable]
  6. public class InvGameItem
  7. {
  8. public InvGameItem(int id)
  9. {
  10. this.mBaseItemID = id;
  11. }
  12. public InvGameItem(int id, InvBaseItem bi)
  13. {
  14. this.mBaseItemID = id;
  15. this.mBaseItem = bi;
  16. }
  17. public int baseItemID
  18. {
  19. get
  20. {
  21. return this.mBaseItemID;
  22. }
  23. }
  24. public InvBaseItem baseItem
  25. {
  26. get
  27. {
  28. if (this.mBaseItem == null)
  29. {
  30. this.mBaseItem = InvDatabase.FindByID(this.baseItemID);
  31. }
  32. return this.mBaseItem;
  33. }
  34. }
  35. public string name
  36. {
  37. get
  38. {
  39. if (this.baseItem == null)
  40. {
  41. return null;
  42. }
  43. return this.quality.ToString() + " " + this.baseItem.name;
  44. }
  45. }
  46. public float statMultiplier
  47. {
  48. get
  49. {
  50. float num = 0f;
  51. switch (this.quality)
  52. {
  53. case InvGameItem.Quality.Broken:
  54. num = 0f;
  55. break;
  56. case InvGameItem.Quality.Cursed:
  57. num = -1f;
  58. break;
  59. case InvGameItem.Quality.Damaged:
  60. num = 0.25f;
  61. break;
  62. case InvGameItem.Quality.Worn:
  63. num = 0.9f;
  64. break;
  65. case InvGameItem.Quality.Sturdy:
  66. num = 1f;
  67. break;
  68. case InvGameItem.Quality.Polished:
  69. num = 1.1f;
  70. break;
  71. case InvGameItem.Quality.Improved:
  72. num = 1.25f;
  73. break;
  74. case InvGameItem.Quality.Crafted:
  75. num = 1.5f;
  76. break;
  77. case InvGameItem.Quality.Superior:
  78. num = 1.75f;
  79. break;
  80. case InvGameItem.Quality.Enchanted:
  81. num = 2f;
  82. break;
  83. case InvGameItem.Quality.Epic:
  84. num = 2.5f;
  85. break;
  86. case InvGameItem.Quality.Legendary:
  87. num = 3f;
  88. break;
  89. }
  90. float num2 = (float)this.itemLevel / 50f;
  91. return num * Mathf.Lerp(num2, num2 * num2, 0.5f);
  92. }
  93. }
  94. public Color color
  95. {
  96. get
  97. {
  98. Color result = Color.white;
  99. switch (this.quality)
  100. {
  101. case InvGameItem.Quality.Broken:
  102. result = new Color(0.4f, 0.2f, 0.2f);
  103. break;
  104. case InvGameItem.Quality.Cursed:
  105. result = Color.red;
  106. break;
  107. case InvGameItem.Quality.Damaged:
  108. result = new Color(0.4f, 0.4f, 0.4f);
  109. break;
  110. case InvGameItem.Quality.Worn:
  111. result = new Color(0.7f, 0.7f, 0.7f);
  112. break;
  113. case InvGameItem.Quality.Sturdy:
  114. result = new Color(1f, 1f, 1f);
  115. break;
  116. case InvGameItem.Quality.Polished:
  117. result = NGUIMath.HexToColor(3774856959u);
  118. break;
  119. case InvGameItem.Quality.Improved:
  120. result = NGUIMath.HexToColor(2480359935u);
  121. break;
  122. case InvGameItem.Quality.Crafted:
  123. result = NGUIMath.HexToColor(1325334783u);
  124. break;
  125. case InvGameItem.Quality.Superior:
  126. result = NGUIMath.HexToColor(12255231u);
  127. break;
  128. case InvGameItem.Quality.Enchanted:
  129. result = NGUIMath.HexToColor(1937178111u);
  130. break;
  131. case InvGameItem.Quality.Epic:
  132. result = NGUIMath.HexToColor(2516647935u);
  133. break;
  134. case InvGameItem.Quality.Legendary:
  135. result = NGUIMath.HexToColor(4287627519u);
  136. break;
  137. }
  138. return result;
  139. }
  140. }
  141. public List<InvStat> CalculateStats()
  142. {
  143. List<InvStat> list = new List<InvStat>();
  144. if (this.baseItem != null)
  145. {
  146. float statMultiplier = this.statMultiplier;
  147. List<InvStat> stats = this.baseItem.stats;
  148. int i = 0;
  149. int count = stats.Count;
  150. while (i < count)
  151. {
  152. InvStat invStat = stats[i];
  153. int num = Mathf.RoundToInt(statMultiplier * (float)invStat.amount);
  154. if (num != 0)
  155. {
  156. bool flag = false;
  157. int j = 0;
  158. int count2 = list.Count;
  159. while (j < count2)
  160. {
  161. InvStat invStat2 = list[j];
  162. if (invStat2.id == invStat.id && invStat2.modifier == invStat.modifier)
  163. {
  164. invStat2.amount += num;
  165. flag = true;
  166. break;
  167. }
  168. j++;
  169. }
  170. if (!flag)
  171. {
  172. list.Add(new InvStat
  173. {
  174. id = invStat.id,
  175. amount = num,
  176. modifier = invStat.modifier
  177. });
  178. }
  179. }
  180. i++;
  181. }
  182. List<InvStat> list2 = list;
  183. if (InvGameItem.<>f__mg$cache0 == null)
  184. {
  185. InvGameItem.<>f__mg$cache0 = new Comparison<InvStat>(InvStat.CompareArmor);
  186. }
  187. list2.Sort(InvGameItem.<>f__mg$cache0);
  188. }
  189. return list;
  190. }
  191. [SerializeField]
  192. private int mBaseItemID;
  193. public InvGameItem.Quality quality = InvGameItem.Quality.Sturdy;
  194. public int itemLevel = 1;
  195. private InvBaseItem mBaseItem;
  196. [CompilerGenerated]
  197. private static Comparison<InvStat> <>f__mg$cache0;
  198. public enum Quality
  199. {
  200. Broken,
  201. Cursed,
  202. Damaged,
  203. Worn,
  204. Sturdy,
  205. Polished,
  206. Improved,
  207. Crafted,
  208. Superior,
  209. Enchanted,
  210. Epic,
  211. Legendary,
  212. _LastDoNotUse
  213. }
  214. }