BaseSkill.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public enum SummonPositionRule
  5. {
  6. Summon_PR_NearCaster = 0,
  7. Summon_PR_NearTarget = 1,
  8. Summon_PR_SelfTeam = 2,
  9. Summon_PR_EnemyTeam = 3,
  10. }
  11. public class BaseSkill
  12. {
  13. protected SkillData mSkillData;
  14. protected int mSkillLv = 0;
  15. int mTypeId = 0;
  16. List<BuffData> mBuffList = new List<BuffData>();
  17. public List<BuffData> BuffList { get { return mBuffList; } }
  18. #region Properties
  19. private int mId;
  20. public int Id { get { return mId; } }
  21. public int Level
  22. {
  23. get { return mSkillLv; }
  24. }
  25. public int SkillTypeID { get { return mTypeId; } set { mTypeId = value; } }
  26. public string SkillName { get { return mSkillData.skillName; } }
  27. public int SpCost { get { return mSkillData.spCost; } }
  28. public bool IsNormalAttack { get { return SkillTypeID == SkillType.NormalAttack; } }
  29. public bool IsAutoSkill { get { return SkillTypeID >= SkillType.Attack1 && SkillTypeID <= SkillType.Attack4; } }
  30. public bool IsEnabled { get { return IsValid && Level > 0; } }
  31. public bool IsValid { get { return mSkillData != null && mSkillData.valid; } }
  32. //是否为被动技能
  33. public bool IsPassiveSkill { get { return mSkillData.skillTriggerType == SkillTriggerType.Passive_Trigger; } }
  34. public bool CanBreak { get { return mSkillData.skillTriggerType == SkillTriggerType.Casting_Sing || mSkillData.skillTriggerType == SkillTriggerType.Continuous_Casting_NoSing || mSkillData.skillTriggerType == SkillTriggerType.Continuous_Casting_Sing; } }
  35. public SkillData SkillDataInfo { get { return mSkillData; } }
  36. //是否为多段技能
  37. public bool IsMultiSkill { get { /*return mSkillData.attackNum > 1;*/ return false; } }
  38. public string SkillAnimName { get; private set; }
  39. public string SkillSingAnimName { get; private set; }
  40. public float SingTotalTime
  41. {
  42. get;set;
  43. }
  44. public bool IsSingSkill { get; private set; }
  45. public float Duration { get { return SingTotalTime + mSkillData.preCastingTime + mSkillData.castingTime + mSkillData.postCastingTime; } }
  46. private List<ValType> mSummonNpcs = null;
  47. public List<ValType> SummonActors {
  48. get
  49. {
  50. return mSummonNpcs;
  51. }
  52. }
  53. private List<ValType> mSummonBosses = null;
  54. public List<ValType> SummonBosses
  55. {
  56. get { return mSummonBosses; }
  57. }
  58. private List<Fighter> mSummonActorInsts = null;
  59. public List<Fighter> SummonActorInsts
  60. {
  61. get { return mSummonActorInsts; }
  62. }
  63. private bool mbDisposed = false;
  64. private string mEventFileName;
  65. private bool mIsEnhance = false;
  66. public bool IsEnhance
  67. {
  68. get { return mIsEnhance; }
  69. set { mIsEnhance = value; }
  70. }
  71. private int mTriggerRate = 100;
  72. public int TriggerRate
  73. {
  74. get { return mTriggerRate; }
  75. set { mTriggerRate = value; }
  76. }
  77. #endregion
  78. private ProfessionType mJobType;
  79. private int mJobStage;
  80. private int mJobBranch;
  81. public BaseSkill(int id,int level, int skillTypeId,int gender, ProfessionType jobType,int jobStage,int jobBranch)
  82. {
  83. mTypeId = skillTypeId;
  84. mId = id;
  85. mSkillData = new SkillData(id,level);
  86. mSkillLv = level;
  87. mIsEnhance = false;
  88. mJobType = jobType;
  89. mJobStage = jobStage;
  90. mJobBranch = jobBranch;
  91. LoadBuffData(gender,jobType,jobStage,jobBranch);
  92. }
  93. public void SetLevel(int level)
  94. {
  95. if (mSkillLv == level) return;
  96. mSkillLv = level;
  97. mSkillData = new SkillData(mId, level);
  98. }
  99. void LoadBuffData(int gender, ProfessionType jobType, int jobStage, int jobBranch)
  100. {
  101. mBuffList.Clear();
  102. if (mSkillData.buffIds!=null)
  103. {
  104. for(int idx =0; idx < mSkillData.buffIds.Length;idx++)
  105. {
  106. BuffData buffData = new BuffData(mSkillData.buffIds[idx], gender,jobType,jobStage,jobBranch);
  107. mBuffList.Add(buffData);
  108. }
  109. }
  110. }
  111. void ParseExtendBuff()
  112. {
  113. for (int idx = 0; idx < mBuffList.Count; idx++)
  114. {
  115. BuffData buffData = mBuffList[idx];
  116. if (buffData.extendBuffs != null)
  117. {
  118. for (int jdx = 0; jdx < buffData.extendBuffs.Count; jdx++)
  119. {
  120. BattlePrepareManager.Instance.PrecacheBuff(buffData.extendBuffs[jdx].id, (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
  121. }
  122. }
  123. if(buffData.markExtendList != null)
  124. {
  125. for(int jdx = 0; jdx < buffData.markExtendList.Count;jdx++)
  126. {
  127. BattlePrepareManager.Instance.PrecacheBuff(buffData.markExtendList[jdx].val, (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
  128. }
  129. }
  130. }
  131. if (mSkillData.triggerBuffs != null && mSkillData.triggerBuffs.Count > 0)
  132. {
  133. for (int idx = 0; idx < mSkillData.triggerBuffs.Count; idx++)
  134. {
  135. SkillTriggerBuffInfo triggerBuffInfo = mSkillData.triggerBuffs[idx];
  136. if (triggerBuffInfo.buffId > 0)
  137. {
  138. BattlePrepareManager.Instance.PrecacheBuff(triggerBuffInfo.buffId, (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
  139. }
  140. }
  141. }
  142. if(mSkillData.extendBuffIds != null && mSkillData.extendBuffIds.Count > 0)
  143. {
  144. for(int idx =0; idx < mSkillData.extendBuffIds.Count;idx++)
  145. {
  146. if(mSkillData.extendBuffIds[idx] > 0)
  147. {
  148. BattlePrepareManager.Instance.PrecacheBuff(mSkillData.extendBuffIds[idx], (int)(Role_Gender.Male), mJobType, mJobStage, mJobBranch);
  149. }
  150. }
  151. }
  152. }
  153. List<int> effects = new List<int>();
  154. List<int> bulletActors = new List<int>();
  155. List<int> buffs = new List<int>();
  156. List<string> sounds = new List<string>();
  157. List<string> prefabs = new List<string>();
  158. void ParseSkillData(Fighter owner)
  159. {
  160. for (int i = 0; i < mBuffList.Count; i++)
  161. {
  162. BuffData buffData = mBuffList[i];
  163. if (buffData.ActionFrameEvents == null || buffData.ActionFrameEvents.Length == 0) continue;
  164. for (int idx = 0; idx < buffData.ActionFrameEvents.Length; idx++)
  165. {
  166. SkillActionFrameEvent ev = buffData.ActionFrameEvents[idx];
  167. switch (ev.eventType)
  168. {
  169. case SkillActionFrameEventType.FE_PlaySound:
  170. {
  171. string sound = ev.GetStr(Constants.s_skillaction_frame_key_sound);
  172. if (!string.IsNullOrEmpty(sound) && !sounds.Contains(sound))
  173. {
  174. sounds.Add(sound);
  175. }
  176. break;
  177. }
  178. case SkillActionFrameEventType.FE_PlayEffect:
  179. case SkillActionFrameEventType.FE_PlayUnscaleTimeEffect:
  180. {
  181. int v = ev.GetN(Constants.s_skillaction_frame_key_effect);
  182. if (v > 0 && !effects.Contains(v))
  183. effects.Add(v);
  184. break;
  185. }
  186. case SkillActionFrameEventType.FE_PlayEffectEx:
  187. {
  188. int v = (int)ev.GetN(Constants.s_skillaction_frame_key_effect);
  189. if (v > 0 && !effects.Contains(v))
  190. effects.Add(v);
  191. break;
  192. }
  193. case SkillActionFrameEventType.FE_Hit:
  194. case SkillActionFrameEventType.FE_Skill_Sing:
  195. case SkillActionFrameEventType.FE_Repeat_Caster:
  196. case SkillActionFrameEventType.FE_Delay_Hurt:
  197. case SkillActionFrameEventType.FE_Bullet:
  198. {
  199. SkillActionAttackInfo attackInfo = ev.CreateAttackInfo();
  200. if (attackInfo != null)
  201. {
  202. if (attackInfo.bulletID > 0 && !bulletActors.Contains(attackInfo.bulletID))
  203. {
  204. bulletActors.Add(attackInfo.bulletID);
  205. }
  206. if (attackInfo.hitEffect > 0 && !effects.Contains(attackInfo.hitEffect))
  207. {
  208. effects.Add(attackInfo.hitEffect);
  209. }
  210. if (attackInfo.effect > 0 && !effects.Contains(attackInfo.effect))
  211. {
  212. effects.Add(attackInfo.effect);
  213. }
  214. if (!string.IsNullOrEmpty(attackInfo.sound) && !sounds.Contains(attackInfo.sound))
  215. {
  216. sounds.Add(attackInfo.sound);
  217. }
  218. if (attackInfo.buffID > 0 && !buffs.Contains(attackInfo.buffID))
  219. {
  220. buffs.Add(attackInfo.buffID);
  221. }
  222. }
  223. break;
  224. }
  225. case SkillActionFrameEventType.FE_Buff:
  226. {
  227. int buffId = ev.GetN(Constants.s_skillaction_frame_key_buffid);
  228. if (buffId > 0 && !buffs.Contains(buffId))
  229. buffs.Add(buffId);
  230. break;
  231. }
  232. case SkillActionFrameEventType.FE_Summon:
  233. {
  234. int npcPos = ev.GetN(Constants.s_skillaction_frame_key_npcPos);
  235. int npcId = ev.GetN(Constants.s_skillaction_frame_key_npcId);
  236. if (mSummonNpcs == null)
  237. mSummonNpcs = new List<ValType>();
  238. if (npcId > 0)
  239. {
  240. ValType val = new ValType(npcId, npcPos);
  241. mSummonNpcs.Add(val);
  242. }
  243. break;
  244. }
  245. case SkillActionFrameEventType.FE_Clone:
  246. {
  247. int npcPos = ev.GetN(Constants.s_skillaction_frame_key_npcPos);
  248. int npcId = ev.GetN(Constants.s_skillaction_frame_key_npcId);
  249. int bornEffectId = ev.GetN(Constants.s_skillaction_frame_key_effect);
  250. if (bornEffectId > 0 && !effects.Contains(bornEffectId))
  251. {
  252. effects.Add(bornEffectId);
  253. }
  254. if (owner.IsBoss)
  255. {
  256. if (mSummonBosses == null)
  257. mSummonBosses = new List<ValType>();
  258. if (npcId > 0)
  259. {
  260. ValType val = new ValType(npcId, npcPos);
  261. mSummonBosses.Add(val);
  262. }
  263. }
  264. else
  265. {
  266. if (mSummonNpcs == null)
  267. mSummonNpcs = new List<ValType>();
  268. if (npcId > 0)
  269. {
  270. ValType val = new ValType(npcId, owner.PositionValue);
  271. mSummonNpcs.Add(val);
  272. }
  273. }
  274. }
  275. break;
  276. case SkillActionFrameEventType.FE_PlayPrefab:
  277. {
  278. string prefabName = ev.GetStr(Constants.s_skillaction_frame_key_prefabname);
  279. if (!string.IsNullOrEmpty(prefabName) && !prefabs.Contains(prefabName))
  280. prefabs.Add(prefabName);
  281. string sound = ev.GetStr(Constants.s_skillaction_frame_key_sound);
  282. if (!string.IsNullOrEmpty(sound) && !sounds.Contains(sound))
  283. {
  284. sounds.Add(sound);
  285. }
  286. }
  287. break;
  288. default:
  289. break;
  290. }
  291. }
  292. for (int idx = 0; idx < buffData.BuffFunList.Count; idx++)
  293. {
  294. var data = buffData.BuffFunList[idx];
  295. if (data.effectId > 0 && !effects.Contains(data.effectId))
  296. {
  297. effects.Add(data.effectId);
  298. }
  299. if (data.endeffectId > 0 && !effects.Contains(data.endeffectId))
  300. {
  301. effects.Add(data.endeffectId);
  302. }
  303. }
  304. }
  305. }
  306. public void Prepare(Fighter owner)
  307. {
  308. effects.Clear();
  309. bulletActors.Clear();
  310. buffs.Clear();
  311. sounds.Clear();
  312. prefabs.Clear();
  313. ParseExtendBuff();
  314. ParseSkillData(owner);
  315. BattlePrepareManager.Instance.PrecacheEffects(effects.ToArray());
  316. BattlePrepareManager.Instance.PrecacheBullets(bulletActors.ToArray());
  317. BattlePrepareManager.Instance.PrecacheBuffs(buffs.ToArray(),owner.Gender,owner.ProfType,owner.JobStage,owner.JobBranch);
  318. BattlePrepareManager.Instance.PrecacheUIPrefabs(prefabs.ToArray());
  319. MusicMgr.Instance.PreloadFightSound(sounds.ToArray());
  320. }
  321. public void Load(int gender, ProfessionType jobType, int jobStage, int jobBranch)
  322. {
  323. effects.Clear();
  324. bulletActors.Clear();
  325. buffs.Clear();
  326. sounds.Clear();
  327. prefabs.Clear();
  328. ParseExtendBuff();
  329. ParseSkillData(null);
  330. BattlePrepareManager.Instance.PrecacheEffects(effects.ToArray());
  331. BattlePrepareManager.Instance.PrecacheBullets(bulletActors.ToArray());
  332. BattlePrepareManager.Instance.PrecacheBuffs(buffs.ToArray(), gender,jobType,jobStage,jobBranch);
  333. BattlePrepareManager.Instance.PrecacheUIPrefabs(prefabs.ToArray());
  334. MusicMgr.Instance.PreloadFightSound(sounds.ToArray());
  335. }
  336. public float GetBuffRate(BuffData buffData)
  337. {
  338. if (buffData.rate == 0)
  339. return 1;
  340. return buffData.rate;
  341. }
  342. public void AddSummonActor (Fighter summon)
  343. {
  344. if (mSummonActorInsts == null)
  345. mSummonActorInsts = new List<Fighter>();
  346. mSummonActorInsts.Add(summon);
  347. }
  348. public void Dispose()
  349. {
  350. if (mbDisposed)
  351. return;
  352. if (mSkillData != null)
  353. {
  354. mSkillData.Dispose();
  355. mSkillData = null;
  356. }
  357. for(int idx =0; idx < mBuffList.Count;idx++)
  358. {
  359. mBuffList[idx].Dispose();
  360. }
  361. mBuffList.Clear();
  362. if (mSummonActorInsts != null)
  363. mSummonActorInsts.Clear();
  364. mSummonActorInsts = null;
  365. mbDisposed = true;
  366. }
  367. public float GetSkillDist(int professionType)
  368. {
  369. if (SkillDataInfo == null) return 0;
  370. float dist;
  371. SkillDataInfo.skillDistDic.TryGetValue(professionType, out dist);
  372. return dist;
  373. }
  374. public SkillTriggerBuffInfo GetTriggerBuffByType(BuffTriggerType type)
  375. {
  376. if (mSkillData == null) return default(SkillTriggerBuffInfo);
  377. if (mSkillData.triggerBuffs == null || mSkillData.triggerBuffs.Count == 0) return default(SkillTriggerBuffInfo);
  378. for(int idx =0; idx < mSkillData.triggerBuffs.Count;idx++)
  379. {
  380. if (mSkillData.triggerBuffs[idx].type == type) return mSkillData.triggerBuffs[idx];
  381. }
  382. return default(SkillTriggerBuffInfo);
  383. }
  384. public bool HasBuff(int buffId)
  385. {
  386. if (mSkillData == null) return false;
  387. if (mSkillData.buffIds == null || mSkillData.buffIds.Length == 0) return false;
  388. for(int idx =0; idx < mSkillData.buffIds.Length;idx++)
  389. {
  390. if (mSkillData.buffIds[idx] == buffId) return true;
  391. }
  392. return false;
  393. }
  394. public Fighter PopSummonActor(int npcId,int npcPos)
  395. {
  396. if (mSummonActorInsts == null)
  397. return null;
  398. for(int idx =0; idx < mSummonActorInsts.Count;idx++)
  399. {
  400. Fighter f = mSummonActorInsts[idx];
  401. if(f.Actor.BaseId == npcId && f.PositionValue == npcPos)
  402. {
  403. return f;
  404. }
  405. }
  406. return null;
  407. }
  408. public JSONObject ToJson()
  409. {
  410. JSONObject json = new JSONObject();
  411. json.Add(mId);
  412. json.Add(mSkillLv);
  413. json.Add(mTriggerRate);
  414. return json;
  415. }
  416. }