SkillActionData.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Mono.Xml;
  5. using System.Security;
  6. public class ActionEventParam
  7. {
  8. public int startFrame;
  9. public int endFrame;
  10. public int eventType;
  11. public bool bAffectBySing;
  12. public List<FrameEventParam> frameParams;
  13. public void Dispose()
  14. {
  15. if (frameParams != null)
  16. frameParams.Clear();
  17. frameParams = null;
  18. }
  19. }
  20. public class ActionEventData
  21. {
  22. private int mId;
  23. public int Id
  24. {
  25. get { return mId; }
  26. }
  27. private int mTotalFrame = 0;
  28. public int TotalFrame
  29. {
  30. get { return mTotalFrame; }
  31. }
  32. private int mJobType;
  33. public int JobType
  34. {
  35. get { return mJobType; }
  36. }
  37. private int mJobStage;
  38. public int JobStage
  39. {
  40. get { return mJobStage; }
  41. }
  42. private int mJobBranch;
  43. public int JobBranch
  44. {
  45. get { return mJobBranch; }
  46. }
  47. private int mGender;
  48. public int Gender
  49. {
  50. get { return mGender; }
  51. }
  52. private bool mIsFemale = false;
  53. private bool mIsMale = false;
  54. public bool IsFemale
  55. {
  56. get { return mIsFemale; }
  57. }
  58. public bool IsMale
  59. {
  60. get { return mIsMale; }
  61. }
  62. public List<ActionEventParam> ActionEventList
  63. {
  64. get; private set;
  65. }
  66. public ActionEventData(int id,int totalFrame,int gender,int jobType,int jobStage,int jobBranch)
  67. {
  68. this.mId = id;
  69. this.mTotalFrame = totalFrame;
  70. this.mGender = gender;
  71. this.mJobType = jobType;
  72. this.mJobStage = jobStage;
  73. this.mJobBranch = jobBranch;
  74. this.mIsFemale = (gender & (int)Role_Gender.Female) == (int)Role_Gender.Female;
  75. this.mIsMale = (gender & (int)Role_Gender.Male) == (int)Role_Gender.Male;
  76. }
  77. public void AddEvent(ActionEventParam eve)
  78. {
  79. if(ActionEventList == null)
  80. {
  81. ActionEventList = new List<ActionEventParam>();
  82. }
  83. ActionEventList.Add(eve);
  84. }
  85. public void Dispose()
  86. {
  87. if (ActionEventList != null)
  88. {
  89. for(int idx =0; idx < ActionEventList.Count; idx++)
  90. {
  91. ActionEventList[idx].Dispose();
  92. }
  93. ActionEventList.Clear();
  94. ActionEventList = null;
  95. }
  96. }
  97. }
  98. //技能配置xml
  99. public class SkillActionEventCfgMgr : Singleton<SkillActionEventCfgMgr>
  100. {
  101. List<ActionEventData> mBuffEvents = new List<ActionEventData>();
  102. public override void Init()
  103. {
  104. base.Init();
  105. ReadEventCfg();
  106. }
  107. public override void UnInit()
  108. {
  109. base.UnInit();
  110. }
  111. void ReadEventCfg()
  112. {
  113. mBuffEvents.Clear();
  114. foreach (var p in ConfigMgr.Instance.XmlConfigDict)
  115. {
  116. string frameEventName = p.Key;
  117. if (!frameEventName.Contains("buff_")) continue;
  118. if(!ReadBuffEventFile(p.Value))
  119. {
  120. DebugHelper.LogError(frameEventName+" 加载有问题");
  121. }
  122. }
  123. }
  124. bool ReadBuffEventFile(string ta)
  125. {
  126. if (ta == null) return false;
  127. SecurityParser doc = new SecurityParser();
  128. try
  129. {
  130. doc.LoadXml(ta);
  131. }
  132. catch (System.Exception e)
  133. {
  134. return false;
  135. }
  136. SecurityElement root = doc.SelectSingleNode("FrameEvent");
  137. if (root == null || root.Children == null) return false;
  138. for (int idx = 0; idx < root.Children.Count; idx++)
  139. {
  140. var buffNode = root.Children[idx] as SecurityElement;
  141. string idStr = buffNode.Attribute("id");
  142. int id = int.Parse(idStr);
  143. string frameStr = buffNode.Attribute("endFrame");
  144. int frame = int.Parse(frameStr);
  145. int gender = 3;
  146. if (!int.TryParse(buffNode.Attribute("gender"), out gender))
  147. {
  148. gender = 3;
  149. }
  150. int jobBranch = 0;
  151. int jobStage = 0;
  152. int jobType = 0;
  153. string tempStr = buffNode.Attribute("jobBranch");
  154. if(!string.IsNullOrEmpty(tempStr))
  155. {
  156. int.TryParse(tempStr, out jobBranch);
  157. }
  158. tempStr = buffNode.Attribute("jobStage");
  159. if(!string.IsNullOrEmpty(tempStr))
  160. {
  161. int.TryParse(tempStr, out jobStage);
  162. }
  163. tempStr = buffNode.Attribute("jobType");
  164. if(!string.IsNullOrEmpty(tempStr))
  165. {
  166. int.TryParse(tempStr, out jobType);
  167. }
  168. if (buffNode.Children == null) continue;
  169. ActionEventData aed = new ActionEventData(id, frame,gender,jobType,jobStage,jobBranch);
  170. for (int jdx = 0; jdx < buffNode.Children.Count; jdx++)
  171. {
  172. var eventNode = buffNode.Children[jdx] as SecurityElement;
  173. ActionEventParam aep = new ActionEventParam();
  174. int.TryParse(eventNode.Attribute("startFrame"), out aep.startFrame);
  175. int.TryParse(eventNode.Attribute("endFrame"), out aep.endFrame);
  176. int.TryParse(eventNode.Attribute("type"), out aep.eventType);
  177. bool.TryParse(eventNode.Attribute("affectBySing"), out aep.bAffectBySing);
  178. aep.frameParams = new List<FrameEventParam>();
  179. if (eventNode.Children != null)
  180. {
  181. for (int kdx = 0; kdx < eventNode.Children.Count; kdx++)
  182. {
  183. var paramNode = eventNode.Children[kdx] as SecurityElement;
  184. FrameEventParam param = new FrameEventParam();
  185. param.name = paramNode.Attribute("name");
  186. string valueType = paramNode.Attribute("valueType");
  187. if (string.IsNullOrEmpty(valueType))
  188. {
  189. param.sValue = paramNode.Attribute("value");
  190. }
  191. else if (valueType.CompareTo("int") == 0)
  192. {
  193. int.TryParse(paramNode.Attribute("value"), out param.nValue);
  194. }
  195. else if (valueType.CompareTo("float") == 0)
  196. {
  197. float.TryParse(paramNode.Attribute("value"), out param.fValue);
  198. }
  199. else
  200. {
  201. param.sValue = paramNode.Attribute("value");
  202. }
  203. aep.frameParams.Add(param);
  204. }
  205. }
  206. aed.AddEvent(aep);
  207. }
  208. mBuffEvents.Add(aed);
  209. }
  210. return true;
  211. }
  212. public ActionEventData GetActionEventData(int id,int gender,int jobType,int jobStage,int jobBranch)
  213. {
  214. bool isFemale = gender == (int)Role_Gender.Female;
  215. for(int idx =0; idx < mBuffEvents.Count;idx++)
  216. {
  217. var temp = mBuffEvents[idx];
  218. if(isFemale)
  219. {
  220. if (temp.Id == id && temp.IsFemale && temp.JobType == jobType && temp.JobStage == jobStage && temp.JobBranch == jobBranch)
  221. {
  222. return temp;
  223. }
  224. }
  225. else
  226. {
  227. if (temp.Id == id && temp.IsMale && temp.JobType == jobType && temp.JobStage == jobStage && temp.JobBranch == jobBranch)
  228. {
  229. return temp;
  230. }
  231. }
  232. }
  233. for(int idx =0; idx < mBuffEvents.Count;idx++)
  234. {
  235. var temp = mBuffEvents[idx];
  236. if(isFemale)
  237. {
  238. if (temp.Id == id && temp.IsFemale)
  239. return temp;
  240. }
  241. else
  242. {
  243. if (temp.Id == id && temp.IsMale)
  244. return temp;
  245. }
  246. }
  247. for(int idx =0; idx < mBuffEvents.Count;idx++)
  248. {
  249. var temp = mBuffEvents[idx];
  250. if (temp.Id == id) return temp;
  251. }
  252. return null;
  253. }
  254. public void Clear()
  255. {
  256. mBuffEvents.Clear();
  257. }
  258. }