YotogiSkillSystem.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using wf;
  5. using Yotogis;
  6. namespace MaidStatus
  7. {
  8. public class YotogiSkillSystem
  9. {
  10. public YotogiSkillSystem(Status status)
  11. {
  12. this.status = status;
  13. this.skillDatas_ = new SortedDictionary<int, YotogiSkillData>();
  14. this.datas = new ReadOnlySortedDictionary<int, YotogiSkillData>(this.skillDatas_);
  15. this.oldSkillDatas_ = new SortedDictionary<int, YotogiSkillData>();
  16. this.oldDatas = new ReadOnlySortedDictionary<int, YotogiSkillData>(this.oldSkillDatas_);
  17. }
  18. public ReadOnlySortedDictionary<int, YotogiSkillData> datas { get; protected set; }
  19. public ReadOnlySortedDictionary<int, YotogiSkillData> oldDatas { get; protected set; }
  20. public Status status { get; protected set; }
  21. public YotogiSkillData Add(int skillId)
  22. {
  23. if (Skill.Contains(skillId))
  24. {
  25. return this.Add(Skill.Get(skillId));
  26. }
  27. if (Skill.Old.Contains(skillId))
  28. {
  29. return this.Add(Skill.Old.Get(skillId));
  30. }
  31. return null;
  32. }
  33. public YotogiSkillData Add(Skill.Old.Data data)
  34. {
  35. if (data == null)
  36. {
  37. return null;
  38. }
  39. YotogiSkillData yotogiSkillData = null;
  40. if (!this.oldSkillDatas_.ContainsKey(data.id))
  41. {
  42. if (data.newData == null)
  43. {
  44. yotogiSkillData = new YotogiSkillData();
  45. yotogiSkillData.oldData = data;
  46. yotogiSkillData.expSystem.SetExreienceList(new List<int>(data.skill_exp_table));
  47. this.oldSkillDatas_.Add(data.id, yotogiSkillData);
  48. }
  49. else
  50. {
  51. yotogiSkillData = this.Add(data.newData);
  52. }
  53. }
  54. return yotogiSkillData;
  55. }
  56. public YotogiSkillData Add(Skill.Data data)
  57. {
  58. if (data == null)
  59. {
  60. return null;
  61. }
  62. YotogiSkillData yotogiSkillData = null;
  63. if (!this.skillDatas_.ContainsKey(data.id))
  64. {
  65. yotogiSkillData = new YotogiSkillData();
  66. yotogiSkillData.data = data;
  67. yotogiSkillData.oldData = data.oldData;
  68. yotogiSkillData.expSystem.SetExreienceList(new List<int>(data.skill_exp_table));
  69. this.skillDatas_.Add(data.id, yotogiSkillData);
  70. if (yotogiSkillData.oldData != null)
  71. {
  72. this.oldSkillDatas_.Add(data.id, yotogiSkillData);
  73. }
  74. }
  75. return yotogiSkillData;
  76. }
  77. public void Remove(Skill.Data data)
  78. {
  79. if (data != null)
  80. {
  81. this.Remove(data.id);
  82. }
  83. }
  84. public void Remove(Skill.Old.Data data)
  85. {
  86. if (data != null)
  87. {
  88. this.Remove(data.id);
  89. }
  90. }
  91. public void Remove(int skillId)
  92. {
  93. if (this.skillDatas_.ContainsKey(skillId))
  94. {
  95. this.skillDatas_.Remove(skillId);
  96. }
  97. if (this.oldSkillDatas_.ContainsKey(skillId))
  98. {
  99. this.oldSkillDatas_.Remove(skillId);
  100. }
  101. }
  102. public void Clear()
  103. {
  104. this.skillDatas_.Clear();
  105. this.oldSkillDatas_.Clear();
  106. }
  107. public bool Contains(int skillId)
  108. {
  109. return this.datas.ContainsKey(skillId) || (this.oldDatas != null && this.oldDatas.ContainsKey(skillId));
  110. }
  111. public YotogiSkillData Get(int skillId)
  112. {
  113. return (!this.datas.ContainsKey(skillId)) ? ((this.oldDatas == null || !this.oldDatas.ContainsKey(skillId)) ? null : this.oldDatas.Get(skillId)) : this.datas.Get(skillId);
  114. }
  115. public void Serialize(BinaryWriter binary)
  116. {
  117. binary.Write((short)this.skillDatas_.Count);
  118. foreach (KeyValuePair<int, YotogiSkillData> keyValuePair in this.skillDatas_)
  119. {
  120. binary.Write(keyValuePair.Key);
  121. keyValuePair.Value.Serialize(binary);
  122. }
  123. binary.Write((short)this.oldSkillDatas_.Count);
  124. foreach (KeyValuePair<int, YotogiSkillData> keyValuePair2 in this.oldSkillDatas_)
  125. {
  126. binary.Write(keyValuePair2.Key);
  127. bool flag = !this.skillDatas_.ContainsKey(keyValuePair2.Key);
  128. binary.Write(flag);
  129. if (flag)
  130. {
  131. keyValuePair2.Value.Serialize(binary);
  132. }
  133. }
  134. }
  135. public void Deserialize(BinaryReader binary, int version)
  136. {
  137. Func<int, YotogiSkillData> func = delegate(int skillId)
  138. {
  139. YotogiSkillData yotogiSkillData3 = new YotogiSkillData();
  140. yotogiSkillData3.data = Skill.Get(skillId);
  141. yotogiSkillData3.oldData = Skill.Old.Get(skillId);
  142. if (yotogiSkillData3.data != null)
  143. {
  144. yotogiSkillData3.expSystem.SetExreienceList(new List<int>(yotogiSkillData3.data.skill_exp_table));
  145. }
  146. else if (yotogiSkillData3.oldData != null)
  147. {
  148. yotogiSkillData3.expSystem.SetExreienceList(new List<int>(yotogiSkillData3.oldData.skill_exp_table));
  149. }
  150. return yotogiSkillData3;
  151. };
  152. this.skillDatas_.Clear();
  153. int num = (int)binary.ReadInt16();
  154. for (int i = 0; i < num; i++)
  155. {
  156. int num2 = binary.ReadInt32();
  157. YotogiSkillData yotogiSkillData = func(num2);
  158. yotogiSkillData.Deserialize(binary, version);
  159. if (yotogiSkillData.data != null || yotogiSkillData.oldData != null)
  160. {
  161. this.skillDatas_.Add(num2, yotogiSkillData);
  162. }
  163. }
  164. this.oldSkillDatas_.Clear();
  165. num = (int)binary.ReadInt16();
  166. for (int j = 0; j < num; j++)
  167. {
  168. int num3 = binary.ReadInt32();
  169. bool flag = binary.ReadBoolean();
  170. if (flag)
  171. {
  172. YotogiSkillData yotogiSkillData2 = func(num3);
  173. yotogiSkillData2.Deserialize(binary, version);
  174. if (yotogiSkillData2.data != null || yotogiSkillData2.oldData != null)
  175. {
  176. this.oldSkillDatas_.Add(num3, yotogiSkillData2);
  177. }
  178. }
  179. else if (this.skillDatas_.ContainsKey(num3) && (Skill.Contains(num3) || Skill.Old.Contains(num3)))
  180. {
  181. this.oldSkillDatas_.Add(num3, this.skillDatas_[num3]);
  182. }
  183. }
  184. Dictionary<int, YotogiSkillData> dictionary = new Dictionary<int, YotogiSkillData>();
  185. Dictionary<int, YotogiSkillData> dictionary2 = new Dictionary<int, YotogiSkillData>();
  186. Dictionary<int, YotogiSkillData> dictionary3 = new Dictionary<int, YotogiSkillData>();
  187. for (int k = 0; k < 2; k++)
  188. {
  189. SortedDictionary<int, YotogiSkillData> sortedDictionary = (k != 0) ? this.oldSkillDatas_ : this.skillDatas_;
  190. foreach (KeyValuePair<int, YotogiSkillData> keyValuePair in sortedDictionary)
  191. {
  192. YotogiSkillData value = keyValuePair.Value;
  193. int id = value.id;
  194. if (value.data != null && value.oldData == null && !dictionary2.ContainsKey(id))
  195. {
  196. dictionary2.Add(id, keyValuePair.Value);
  197. }
  198. else if (value.data == null && value.oldData != null && !dictionary3.ContainsKey(id))
  199. {
  200. dictionary3.Add(id, keyValuePair.Value);
  201. }
  202. else if (value.data != null && value.oldData != null && !dictionary.ContainsKey(id))
  203. {
  204. dictionary.Add(id, keyValuePair.Value);
  205. }
  206. }
  207. }
  208. this.skillDatas_.Clear();
  209. this.oldSkillDatas_.Clear();
  210. foreach (KeyValuePair<int, YotogiSkillData> keyValuePair2 in dictionary)
  211. {
  212. this.skillDatas_.Add(keyValuePair2.Key, keyValuePair2.Value);
  213. this.oldSkillDatas_.Add(keyValuePair2.Key, keyValuePair2.Value);
  214. }
  215. foreach (KeyValuePair<int, YotogiSkillData> keyValuePair3 in dictionary2)
  216. {
  217. this.skillDatas_.Add(keyValuePair3.Key, keyValuePair3.Value);
  218. }
  219. foreach (KeyValuePair<int, YotogiSkillData> keyValuePair4 in dictionary3)
  220. {
  221. this.oldSkillDatas_.Add(keyValuePair4.Key, keyValuePair4.Value);
  222. }
  223. }
  224. protected SortedDictionary<int, YotogiSkillData> skillDatas_;
  225. protected SortedDictionary<int, YotogiSkillData> oldSkillDatas_;
  226. }
  227. }