BattleBuff.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. public class BattleBuff
  6. {
  7. #region properties
  8. int repeatCastingEffectInstanceId = 0;
  9. int singEffectInstanceId = 0;
  10. bool mHasBeenStop = false;
  11. bool mExecuteDelayHurt = false;
  12. float mCurTime = 0;
  13. //float mTotalTime;
  14. int mEventIdx = 0;
  15. BuffData mBuffData;
  16. Fighter mFighter;
  17. BaseBattle mBattle;
  18. BaseSkill mSkill;
  19. int skillLv = 1;
  20. //float mSingTotalTime = 0;
  21. //TimeDelayManager<SkillActionAttackInfo> mDelayAttackInfo;
  22. //TimeDelayManager<SkillActionAttackInfo> mDelayAttackEffect;
  23. FrameDelayManager<SkillActionAttackInfo> mDelayAttackInfo;
  24. FrameDelayManager<SkillActionAttackInfo> mDelayAttackEffect;
  25. List<int> mTriggeredEffects;
  26. List<Fighter> mTempHitFighters = new List<Fighter>();
  27. List<SkillHitFighterInfo> mHitFighterInfoList;
  28. List<SkillActionFrameEvent> mWaitEndEventList = null;
  29. List<int> mSingEffectList = new List<int>();
  30. Fighter mTarget = null;
  31. int totalHurtCnt = 1;
  32. int hurtTimes = 0;
  33. bool changeSpeed = false;
  34. private bool mIsEnhance = false; //是否为增强buff
  35. private float mCastingTime = 0;
  36. private List<stDamageParam> mDamageList = new List<stDamageParam>();
  37. private int mFrame;
  38. public int Frame
  39. {
  40. get { return mFrame; }
  41. }
  42. private int mTotalFrame;
  43. public int TotalFrame
  44. {
  45. get { return mTotalFrame; }
  46. }
  47. private int mSingTotalFrame = 0;
  48. #endregion
  49. #region public_fields
  50. public Fighter OwnerFighter { get { return mFighter; } }
  51. public BaseSkill Skill { get { return mSkill; } }
  52. //记录buff 释放源
  53. private Fighter mSourceFighter;
  54. public Fighter SourceFighter { get { return mSourceFighter; } }
  55. public void SetSourceFighter(Fighter pSourceFighter)//设置释放源
  56. {
  57. if (null == mSourceFighter)
  58. mSourceFighter = pSourceFighter;
  59. }
  60. public Fighter GetSourceFighter()//获取释放源
  61. {
  62. if (null != mSourceFighter)//没有释放源 就取buff挂在角色
  63. return mSourceFighter;
  64. else
  65. return OwnerFighter;
  66. }
  67. public int BuffId { get { return mBuffData.buffID; } }
  68. public int SortValue { get { return mBuffData.sortValue; } }
  69. public bool Expired { get { return mFrame > mTotalFrame; } }
  70. public bool HasBeenStop { get { return mHasBeenStop; } }
  71. public bool IsHide { get; private set; }
  72. public Target_Select_Rule BuffTargetType { get { return mBuffData.funTargetType; } }
  73. public TargetFilterRule FilterRule { get { return mBuffData.filterRule; } }
  74. public BuffData Data { get { return mBuffData; } }
  75. private int mCastFrameCnt = 0;
  76. public int CastFrameCnt
  77. {
  78. get { return mCastFrameCnt; }
  79. }
  80. public bool IsEnhance
  81. {
  82. get { return mIsEnhance; }
  83. set { mIsEnhance = value; }
  84. }
  85. int mEffectEventIdx = 0;
  86. private List<SkillActionFrameEvent> mEffectActionEventList = null;
  87. private bool bCheckMark = false;
  88. //目标伤害总值
  89. private Dictionary<int, int> mDicTotalDamage = new Dictionary<int, int>();
  90. #endregion
  91. public BattleBuff(BuffData buffData, Fighter fighter, BaseSkill skill)
  92. {
  93. mCastingTime = Time.realtimeSinceStartup;
  94. mCastFrameCnt = Time.frameCount;
  95. mBuffData = buffData;
  96. mFighter = fighter;
  97. mBattle = fighter.Battle;
  98. mSkill = skill;
  99. mDicTotalDamage.Clear();
  100. bCheckMark = false;
  101. if (mSkill != null)
  102. {
  103. mSingTotalFrame = (int)((Fix64)mSkill.SingTotalTime * (Fix64)Constants.frame_to_time);
  104. skillLv = mSkill.Level;
  105. mBuffData.SetLevel(skillLv);
  106. }
  107. else
  108. {
  109. skillLv = buffData.BuffLevel;//由技能buff 触发的buff 使用上一个buff 等级
  110. }
  111. mCurTime = 0;
  112. Fix64 fAttrAttackSpeedPercent = (Fix64)SDataUtil.InvConvert(mFighter.AttrAttackSpeedPercent);
  113. Fix64 fSkillAttackSpeedPercent = (Fix64)SDataUtil.InvConvert(mFighter.SkillAttackSpeedPercent);
  114. mTotalFrame = (int)(mBuffData.totalFrame * Fix64.Max(Fix64.One - fAttrAttackSpeedPercent, (Fix64)0.3f) * Fix64.Max(Fix64.One - fSkillAttackSpeedPercent, (Fix64)0.3f));
  115. mFrame = 0;
  116. totalHurtCnt = mBuffData.multiHurtCnt;
  117. mTriggeredEffects = new List<int>();
  118. mWaitEndEventList = new List<SkillActionFrameEvent>();
  119. mDelayAttackInfo = new FrameDelayManager<SkillActionAttackInfo>(PerformAttackInfo);
  120. mDelayAttackEffect = new FrameDelayManager<SkillActionAttackInfo>(PerformAttackEffect);
  121. RefreshFrameEvents();
  122. CheckSkillAnimSpeed();
  123. }
  124. private void RefreshFrameEvents()
  125. {
  126. SkillActionFrameEvent fe = mBuffData.SingFrameEvent;
  127. if (fe == null) return;
  128. int deltaFrame = mSingTotalFrame - fe.initEndFrame;
  129. fe.initEndFrame = fe.initEndFrame + deltaFrame;
  130. for (int idx = 0; idx < mBuffData.ActionFrameEvents.Length; idx++)
  131. {
  132. SkillActionFrameEvent evt = mBuffData.ActionFrameEvents[idx];
  133. if (evt != fe && evt.bAffectBySing)
  134. {
  135. evt.initStartFrame = evt.initStartFrame + deltaFrame;
  136. evt.initStartTime = (Fix64)evt.initStartTime + (Fix64)deltaFrame / (Fix64)Constants.frame_to_time;
  137. if (evt.initEndFrame > 0)
  138. {
  139. evt.initEndFrame = evt.initEndFrame + deltaFrame;
  140. evt.initEndTime = (Fix64)evt.initEndTime + (Fix64)deltaFrame / (Fix64)Constants.frame_to_time;
  141. }
  142. }
  143. }
  144. }
  145. private void CheckSkillAnimSpeed()
  146. {
  147. bool isSingSkill = mSkill != null ? mSkill.IsSingSkill : false;
  148. if (!isSingSkill)
  149. {
  150. for (int idx = 0; idx < mBuffData.ActionFrameEvents.Length; idx++)
  151. {
  152. SkillActionFrameEvent evt = mBuffData.ActionFrameEvents[idx];
  153. Fix64 fAttrAttackSpeedPercent = (Fix64)SDataUtil.InvConvert(mFighter.AttrAttackSpeedPercent);
  154. Fix64 fSkillAttackSpeedPercent = (Fix64)SDataUtil.InvConvert(mFighter.SkillAttackSpeedPercent);
  155. evt.startFrame = (int)(evt.initStartFrame * Fix64.Max(Fix64.One - fAttrAttackSpeedPercent, (Fix64)0.3f) * Fix64.Max(Fix64.One - fSkillAttackSpeedPercent, (Fix64)0.3f));
  156. evt.endFrame = (int)(evt.initEndFrame * Fix64.Max(Fix64.One - fAttrAttackSpeedPercent, (Fix64)0.3f) * Fix64.Max(Fix64.One - fSkillAttackSpeedPercent, (Fix64)0.3f));
  157. evt.startTime = evt.initStartTime * Fix64.Max(Fix64.One - fAttrAttackSpeedPercent, (Fix64)0.3f) * Fix64.Max(Fix64.One - fSkillAttackSpeedPercent, (Fix64)0.3f);
  158. evt.endTime = evt.initEndTime * Fix64.Max(Fix64.One - fAttrAttackSpeedPercent, (Fix64)0.3f) * Fix64.Max(Fix64.One - fSkillAttackSpeedPercent, (Fix64)0.3f);
  159. }
  160. }
  161. else
  162. {
  163. for (int idx = 0; idx < mBuffData.ActionFrameEvents.Length; idx++)
  164. {
  165. SkillActionFrameEvent evt = mBuffData.ActionFrameEvents[idx];
  166. evt.startFrame = evt.initStartFrame;
  167. evt.endFrame = evt.initEndFrame;
  168. evt.startTime = evt.initStartTime;
  169. evt.endTime = evt.initEndTime;
  170. }
  171. }
  172. }
  173. public void Start()
  174. {
  175. bCheckMark = false;
  176. mCurTime = 0;
  177. mFrame = 0;
  178. SelectTarget();
  179. //if (BattleMgr.Instance.Battle.IsPlayRecord || BattleMgr.Instance.Battle.IsKillingBoss)
  180. // DebugHelper.LogError(this.BuffId + "-------------Fighter=" + mFighter.Id + " start:" + Time.frameCount);
  181. }
  182. public void Stop()
  183. {
  184. if (mHasBeenStop)
  185. return;
  186. if (!BattleMgr.Instance.Battle.IsPlayRecord && BattleMgr.Instance.Battle.Recorder != null)
  187. {
  188. if (mSkill != null)
  189. {
  190. BattleMgr.Instance.Battle.Recorder.RecordFighterSkillData(mSkill.Id, mCastingTime, mFighter.Actor.ID, mFighter.Actor.BaseId, (int)mFighter.TeamSide, mDamageList);
  191. }
  192. }
  193. if (Data.removeFunAfterStop)
  194. {
  195. for (int idx = Data.BuffFunList.Count - 1; idx >= 0; idx--)
  196. {
  197. mFighter.FuncMgr.RemoveDurationFunEvent(Data.BuffFunList[idx].id, Data.BuffFunList[idx].Group);
  198. }
  199. }
  200. mFighter.RemoveFunctionPoint(BuffId);
  201. if (changeSpeed)
  202. mFighter.StateData.SetAnimSpeed(1);
  203. for (int i = 0; i < mTriggeredEffects.Count; i++)
  204. EffectManager.Instance.RemoveEffectByInstanceID(mTriggeredEffects[i]);
  205. EndRepeatingCasting();
  206. mDelayAttackEffect.Clear();
  207. mDelayAttackInfo.Clear();
  208. mWaitEndEventList.Clear();
  209. mHasBeenStop = true;
  210. mDelayAttackEffect = null;
  211. mDelayAttackInfo = null;
  212. changeSpeed = false;
  213. mDicTotalDamage.Clear();
  214. }
  215. //public void AddTotalTime(float time)
  216. //{
  217. // mTotalTime += time;
  218. //}
  219. public void AddTotalFrame(int frame)
  220. {
  221. mTotalFrame += frame;
  222. }
  223. public void Update(float deltaTime)
  224. {
  225. if (mHasBeenStop)
  226. return;
  227. //角色存在禁止释放技能 通过AI释放的SKILL 没有延迟伤害 跑三帧打断停止
  228. if (mFrame >= Constants.s_protectframe && !mExecuteDelayHurt && (mSkill != null) && mSkill.IsAutoSkill && mFighter.FuncMgr.HaveForbidSkillFunc())
  229. {
  230. Stop();
  231. return;
  232. }
  233. //角色存在打断效果 跑三帧打断停止
  234. if (mFrame >= Constants.s_protectframe && mFighter.FuncMgr.HaveBuffFunction(Buff_Function_Type.Break))
  235. {
  236. Stop();
  237. return;
  238. }
  239. //if (mCurTime <= mTotalTime)
  240. // {
  241. // mDelayAttackInfo.Update(deltaTime);
  242. // mDelayAttackEffect.Update(deltaTime);
  243. // UpdateFrame(deltaTime);
  244. // CheckEndFrame();
  245. // }
  246. // else
  247. // {
  248. // Stop();
  249. // }
  250. if (mFrame <= mTotalFrame)
  251. {
  252. if(null != mDelayAttackInfo)
  253. mDelayAttackInfo.Update();
  254. if(null != mDelayAttackEffect)
  255. mDelayAttackEffect.Update();
  256. //UpdateTime(deltaTime);
  257. UpdateFrame();
  258. CheckEndFrame();
  259. }
  260. else
  261. {
  262. Stop();
  263. }
  264. }
  265. private void UpdateFrame()
  266. {
  267. while (mEventIdx < mBuffData.ActionFrameEvents.Length && !mHasBeenStop)
  268. {
  269. if (mBuffData.ActionFrameEvents[mEventIdx].startFrame > mFrame)
  270. break;
  271. SkillActionFrameEvent fe = mBuffData.ActionFrameEvents[mEventIdx++];
  272. if (ProcessEvent(fe) && fe.endFrame > 0)
  273. {
  274. mWaitEndEventList.Add(fe);
  275. }
  276. }
  277. mFrame++;
  278. }
  279. //private void UpdateTime(float deltaTime)
  280. //{
  281. // while (mEffectEventIdx < mEffectActionEventList.Count && !mHasBeenStop)
  282. // {
  283. // if (mEffectActionEventList[mEffectEventIdx].startTime > mCurTime)
  284. // break;
  285. // SkillActionFrameEvent fe = mEffectActionEventList[mEffectEventIdx++];
  286. // ProcessEventWithTime(fe);
  287. // }
  288. // mCurTime += deltaTime;
  289. //}
  290. private void CheckEndFrame()
  291. {
  292. for (int idx = mWaitEndEventList.Count - 1; idx >= 0; idx--)
  293. {
  294. SkillActionFrameEvent fe = mWaitEndEventList[idx];
  295. if (fe.endFrame <= mFrame)
  296. {
  297. ProcessEndEvent(fe);
  298. mWaitEndEventList.RemoveAt(idx);
  299. }
  300. }
  301. }
  302. //private bool ProcessEventWithTime(SkillActionFrameEvent frameEv)
  303. //{
  304. // bool canProcess = true;
  305. // if (mFrame >= Constants.s_protectframe && mSkill != null && mSkill.IsAutoSkill && mFighter.FuncMgr.HaveForbidSkillFunc())
  306. // {
  307. // canProcess = false;
  308. // }
  309. // switch (frameEv.eventType)
  310. // {
  311. // case SkillActionFrameEventType.FE_PlayEffect:
  312. // if (mFighter.Ctrl != null)
  313. // {
  314. // int effectId = frameEv.GetN(Constants.s_skillaction_frame_key_effect);
  315. // int effectInstanceID = EffectManager.Instance.PlayEffect(effectId, mFighter, mFighter);
  316. // if (effectInstanceID >= 0)
  317. // mTriggeredEffects.Add(effectInstanceID);
  318. // }
  319. // break;
  320. // }
  321. // return canProcess;
  322. //}
  323. private bool ProcessEvent(SkillActionFrameEvent frameEv)
  324. {
  325. if (null == mFighter)
  326. return false;
  327. bool canProcess = true;
  328. bool bforbidSkill = false;
  329. if (null != mFighter.FuncMgr && mFighter.FuncMgr.HaveForbidSkillFunc())
  330. bforbidSkill = true;
  331. if (mFrame >= Constants.s_protectframe && mSkill != null && mSkill.IsAutoSkill && bforbidSkill)
  332. {
  333. canProcess = false;
  334. }
  335. try
  336. {
  337. switch (frameEv.eventType)
  338. {
  339. case SkillActionFrameEventType.FE_ShakeCamera:
  340. float leftRightVal = frameEv.GetN("leftright") * 0.01f;
  341. float upDownVal = frameEv.GetN("updown") * 0.01f;
  342. float forwardbackward = frameEv.GetN("forwardbackward") * 0.01f;
  343. float shakeTime = frameEv.GetN("time") * 0.01f;
  344. int cycle = frameEv.GetN("cycle");
  345. if (cycle > 0 && shakeTime > 0)
  346. {
  347. BattleCamera.Instance.Shake(leftRightVal, upDownVal, forwardbackward, shakeTime, cycle);
  348. }
  349. break;
  350. case SkillActionFrameEventType.FE_ChangeCamera:
  351. Vector3 camPos = StringUtil.convertVector3(frameEv.GetStr(Constants.s_skillaction_frame_key_cam_pos));
  352. Vector3 camRot = StringUtil.convertVector3(frameEv.GetStr(Constants.s_skillaction_frame_key_cam_rot));
  353. int camFov = frameEv.GetN(Constants.s_skillaction_frame_key_cam_fov);
  354. BattleCamera.Instance.SetCameraPosAndRot(camPos, camRot, camFov);
  355. break;
  356. case SkillActionFrameEventType.FE_PlaySound:
  357. if (null != mFighter && mFighter.Ctrl != null)
  358. {
  359. string sound = frameEv.GetStr(Constants.s_skillaction_frame_key_sound);
  360. if (!string.IsNullOrEmpty(sound))
  361. {
  362. MusicMgr.Instance.PlayFightSound(sound);
  363. }
  364. }
  365. break;
  366. case SkillActionFrameEventType.FE_PlayEffect:
  367. if (null != mFighter && mFighter.Ctrl != null)
  368. {
  369. int effectId = frameEv.GetN(Constants.s_skillaction_frame_key_effect);
  370. int effectInstanceID = EffectManager.Instance.PlayEffect(effectId, mFighter, mFighter);
  371. if (effectInstanceID >= 0)
  372. mTriggeredEffects.Add(effectInstanceID);
  373. }
  374. break;
  375. case SkillActionFrameEventType.FE_PlaySkillAnim:
  376. if (canProcess)
  377. {
  378. if(null != mFighter.StateData)
  379. {
  380. mFighter.StateData.PlayAnim(frameEv.GetStr("animName"));
  381. int animSpeed = frameEv.GetN("animSpeed");
  382. if (animSpeed > 0)
  383. {
  384. changeSpeed = true;
  385. mFighter.StateData.SetAnimSpeed(animSpeed * 0.01f);
  386. }
  387. }
  388. }
  389. break;
  390. case SkillActionFrameEventType.FE_Move:
  391. {
  392. FighterMoveType moveType = (FighterMoveType)frameEv.GetN(Constants.s_skillaction_frame_key_move_type);
  393. Fix64 speed = frameEv.GetN(Constants.s_skillaction_frame_key_move_speed) * (Fix64)0.01f;
  394. Fix64 acceleration = frameEv.GetN(Constants.s_skillaction_frame_key_move_acceleration) * (Fix64)0.01f;
  395. Fix64 dist = frameEv.GetN(Constants.s_skillaction_frame_key_move_dist) * (Fix64)0.01f;
  396. int angle = frameEv.GetN(Constants.s_skillaction_frame_key_move_orientation);
  397. FixVector3 v3SelfPos = new FixVector3(mFighter.Position);
  398. if (null != mFighter.StateData && null != mFighter.StateData.SkillStateData
  399. && null != mFighter.StateData.SkillStateData.MoveProcessor)
  400. {
  401. if (moveType == FighterMoveType.Jump)
  402. {
  403. mFighter.StateData.SkillStateData.MoveProcessor.Start(speed, acceleration, v3SelfPos + FixVector3.Up * dist);
  404. }
  405. else if (moveType == FighterMoveType.Sprint_Target)
  406. {
  407. FixVector3 v3TargetPos = new FixVector3(mTarget.Position);
  408. FixVector3 v3TargetForward = new FixVector3(mTarget.Forward);
  409. FixVector3 destPos = v3TargetPos + v3TargetForward * dist;
  410. mFighter.StateData.SkillStateData.MoveProcessor.Start(speed, acceleration, destPos);
  411. }
  412. else if (moveType == FighterMoveType.Sprint_Position)
  413. {
  414. //旋转 之后修改计算
  415. FixVector3 eulerAngle = new FixVector3(mFighter.EulerAngle);
  416. eulerAngle.y += angle;
  417. mFighter.SetRotation(Quaternion.Euler(eulerAngle.ToVector3()));
  418. FixVector3 SelfForward = new FixVector3(mFighter.Ctrl.transform.forward);
  419. FixVector3 destPos = v3SelfPos + SelfForward * dist;
  420. mFighter.StateData.SkillStateData.MoveProcessor.Start(speed, acceleration, destPos);
  421. }
  422. }
  423. }
  424. break;
  425. case SkillActionFrameEventType.FE_Buff:
  426. int buffId = frameEv.GetN(Constants.s_skillaction_frame_key_buffid);
  427. int rate = frameEv.GetN(Constants.s_skillaction_frame_key_rate);
  428. if (buffId > 0)
  429. {
  430. int random = (int)(mBattle.RandomValue(true) * 100);
  431. if (random <= rate)
  432. {
  433. BattleBuff pBuff = mFighter.CastBuff(null, buffId, skillLv);
  434. if (null != pBuff)
  435. {
  436. Fighter pFighter = GetSourceFighter(); //获取源 设置新BUFF源
  437. pBuff.SetSourceFighter(pFighter);
  438. }
  439. }
  440. }
  441. break;
  442. case SkillActionFrameEventType.FE_Summon:
  443. if (canProcess)
  444. {
  445. int npcId = frameEv.GetN(Constants.s_skillaction_frame_key_npcId);
  446. int npcPos = frameEv.GetN(Constants.s_skillaction_frame_key_npcPos);
  447. if (mSkill != null && npcId > 0 && npcPos > 0)
  448. {
  449. Fighter f = mSkill.PopSummonActor(npcId, npcPos);
  450. if (f != null && null != f.Actor && null != mFighter.CurrentBattleField)
  451. {
  452. f.Actor.SetLevel(mBattle.CurLevelMonsterLv);
  453. Vector3 pos, rot;
  454. mFighter.CurrentBattleField.GetFieldSummonPos(f.PositionValue, out pos, out rot);
  455. f.Spawn(pos, Vector3.forward, Quaternion.Euler(rot));
  456. f.SetRotation(Quaternion.Euler(rot));
  457. if(null != f.Ctrl)
  458. f.Ctrl.SetLayer(LayerMask.NameToLayer(BattleCamera.FighterLayerName));
  459. }
  460. }
  461. }
  462. break;
  463. case SkillActionFrameEventType.FE_Skill_Sing:
  464. if (canProcess)
  465. {
  466. SkillActionAttackInfo attackInfo = frameEv.CreateAttackInfo();
  467. mFighter.BeginSing(frameEv.GetStr("animName"), attackInfo.hitEffect);
  468. }
  469. break;
  470. case SkillActionFrameEventType.FE_Repeat_Caster:
  471. if (canProcess)
  472. {
  473. BeginRepeatCasting(frameEv);
  474. }
  475. break;
  476. case SkillActionFrameEventType.FE_Hit:
  477. if (canProcess)
  478. {
  479. SkillActionAttackInfo attackInfo = frameEv.CreateAttackInfo();
  480. PerformAttackInfo(attackInfo);
  481. }
  482. break;
  483. case SkillActionFrameEventType.FE_Bullet:
  484. if (canProcess)
  485. {
  486. FireBullet(frameEv);
  487. }
  488. break;
  489. case SkillActionFrameEventType.FE_Delay_Hurt:
  490. {
  491. if (canProcess)
  492. {
  493. SkillActionAttackInfo attackInfo = frameEv.CreateAttackInfo();
  494. if(null != attackInfo && null != mBuffData)
  495. {
  496. totalHurtCnt = attackInfo.delayHurtCount;
  497. mBuffData.multiHurtIntervalTime = attackInfo.delayHurtDelayFrame / Constants.frame_to_time;
  498. for (int idx = 0; idx < attackInfo.delayHurtCount; idx++)
  499. {
  500. //mDelayAttackEffect.Add(attackInfo, (idx * attackInfo.delayHurtIntervalFrame)/ Constants.frame_to_time);
  501. //mDelayAttackInfo.Add(attackInfo,(idx*attackInfo.delayHurtIntervalFrame + attackInfo.delayHurtDelayFrame) / Constants.frame_to_time);
  502. if(null != mDelayAttackEffect)
  503. mDelayAttackEffect.Add(attackInfo, idx * attackInfo.delayHurtIntervalFrame);
  504. if (null != mDelayAttackInfo)
  505. mDelayAttackInfo.Add(attackInfo, idx * attackInfo.delayHurtIntervalFrame + attackInfo.delayHurtDelayFrame);
  506. }
  507. }
  508. }
  509. mExecuteDelayHurt = true;
  510. }
  511. break;
  512. case SkillActionFrameEventType.FE_SELECT_TARGET:
  513. mFighter.SelectTarget = null;
  514. SelectTarget();
  515. break;
  516. case SkillActionFrameEventType.FE_SWITCH_SKILL:
  517. if (canProcess)
  518. {
  519. SwitchSkill(frameEv);
  520. }
  521. break;
  522. case SkillActionFrameEventType.FE_Clone:
  523. if (canProcess)
  524. {
  525. int npcId = frameEv.GetN(Constants.s_skillaction_frame_key_npcId);
  526. int npcPos = frameEv.GetN(Constants.s_skillaction_frame_key_npcPos);
  527. Vector3 position = StringUtil.convertVector3(Constants.s_skillaction_frame_key_position);
  528. Vector3 rotation = StringUtil.convertVector3(Constants.s_skillaction_frame_key_rotation);
  529. if (npcId > 0 && npcPos > 0)
  530. {
  531. Fighter f = null;
  532. if (mSkill != null)
  533. {
  534. f = mSkill.PopSummonActor(npcId, npcPos);
  535. }
  536. else if (null != mFighter.Actor && BuffId == mFighter.Actor.RageId)
  537. {
  538. f = mFighter.RageCloneBoss;
  539. }
  540. if (f != null && null != mFighter.CurrentBattleField && null != f.StateData)
  541. {
  542. if (null != f.Actor && null != mFighter.Actor)
  543. {
  544. f.Actor.SetLevel(mFighter.Actor.Level);
  545. f.Actor.IsBoss = true;
  546. }
  547. int bornEffectId = frameEv.GetN(Constants.s_skillaction_frame_key_effect);
  548. f.BornEffectId = bornEffectId;
  549. f.IsCloned = true;
  550. Vector3 pos, rot;
  551. mFighter.CurrentBattleField.GetFieldSummonPos(npcPos, out pos, out rot);
  552. Quaternion r = Quaternion.identity;
  553. if (rotation.FEqual(Vector3.zero, 0.01f))
  554. {
  555. r = Quaternion.Euler(rot);
  556. }
  557. else
  558. {
  559. r = Quaternion.Euler(rotation);
  560. }
  561. if (position.FEqual(Vector3.zero, 0.01f))
  562. {
  563. f.Spawn(pos, Vector3.forward, r);
  564. }
  565. else
  566. {
  567. f.Spawn(position, Vector3.forward, r);
  568. }
  569. if (rotation.FEqual(Vector3.zero, 0.01f))
  570. {
  571. f.SetRotation(Quaternion.Euler(rot));
  572. }
  573. else
  574. {
  575. f.SetRotation(Quaternion.Euler(rotation));
  576. }
  577. f.StateData.IsRageStatus = mFighter.StateData.IsRageStatus;
  578. if(null != mBattle && null != mBattle.CurBattleField)
  579. mBattle.CurBattleField.RemoveFighter(mFighter);
  580. mFighter.Dispose();
  581. Stop();
  582. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_CLONE_NEW_BOSS, f));
  583. }
  584. }
  585. }
  586. break;
  587. case SkillActionFrameEventType.FE_ChangeSkyboxMat:
  588. if (canProcess)
  589. {
  590. string switchScene = frameEv.GetStr(Constants.s_skillaction_frame_key_switchscene);
  591. if (!string.IsNullOrEmpty(switchScene))
  592. {
  593. EventMgr.DispatchEvent<string>(new CoreEvent<string>(ECoreEventType.EID_SHOW_SCENE_GO, switchScene));
  594. }
  595. string matName = frameEv.GetStr(Constants.s_skillaction_frame_key_material_name);
  596. EventMgr.DispatchEvent<string>(new CoreEvent<string>(ECoreEventType.EID_CHAGNE_SKYBOX_MATERIAL, matName));
  597. }
  598. break;
  599. case SkillActionFrameEventType.FE_PlayPrefab:
  600. {
  601. string prefabName = frameEv.GetStr(Constants.s_skillaction_frame_key_prefabname);
  602. if (!string.IsNullOrEmpty(prefabName))
  603. {
  604. EventMgr.DispatchEvent<string>(new CoreEvent<string>(ECoreEventType.EID_PLAY_SKILL_PREFAB, prefabName));
  605. }
  606. string sound = frameEv.GetStr(Constants.s_skillaction_frame_key_sound);
  607. if (!string.IsNullOrEmpty(sound))
  608. {
  609. MusicMgr.Instance.PlayFightSound(sound);
  610. }
  611. }
  612. break;
  613. case SkillActionFrameEventType.FE_BattleUI_Visible:
  614. {
  615. int visFlag = frameEv.GetN(Constants.s_skillaction_frame_key_battleui_visible);
  616. EventMgr.DispatchEvent<bool>(new CoreEvent<bool>(ECoreEventType.EID_BattleUI_Visible, visFlag > 0 ? true : false));
  617. }
  618. break;
  619. case SkillActionFrameEventType.FE_HideFighters:
  620. {
  621. if(null != mBattle && null != mBattle.CurBattleField)
  622. mBattle.CurBattleField.HideFighters();
  623. }
  624. break;
  625. case SkillActionFrameEventType.FE_ShowFighters:
  626. {
  627. if (null != mBattle && null != mBattle.CurBattleField)
  628. mBattle.CurBattleField.ShowFighters();
  629. }
  630. break;
  631. }
  632. }
  633. catch (System.Exception e)
  634. {
  635. Debug.LogError(e);
  636. }
  637. return canProcess;
  638. }
  639. private void ProcessEndEvent(SkillActionFrameEvent frameEv)
  640. {
  641. switch (frameEv.eventType)
  642. {
  643. case SkillActionFrameEventType.FE_Skill_Sing:
  644. {
  645. mFighter.EndSing();
  646. }
  647. break;
  648. case SkillActionFrameEventType.FE_Repeat_Caster:
  649. {
  650. EndRepeatingCasting();
  651. }
  652. break;
  653. case SkillActionFrameEventType.FE_Move:
  654. {
  655. FighterMoveType moveType = (FighterMoveType)frameEv.GetN(Constants.s_skillaction_frame_key_move_type);
  656. if(moveType == FighterMoveType.Jump)
  657. {
  658. FixVector3 pos =new FixVector3(mFighter.Position);
  659. pos.y = (Fix64)mFighter.CurrentBattleField.FloorY;
  660. mFighter.StateData.SkillStateData.MoveProcessor.Start(Fix64.Zero, (Fix64)Constants.gravity, pos);
  661. }
  662. }
  663. break;
  664. case SkillActionFrameEventType.FE_PlayPrefab:
  665. {
  666. string prefabName = frameEv.GetStr(Constants.s_skillaction_frame_key_prefabname);
  667. if (!string.IsNullOrEmpty(prefabName))
  668. {
  669. EventMgr.DispatchEvent<string>(new CoreEvent<string>(ECoreEventType.EID_CLOSE_SKILL_PREFAB, prefabName));
  670. }
  671. }
  672. break;
  673. }
  674. }
  675. private bool isCasting = false;
  676. private void BeginRepeatCasting(SkillActionFrameEvent frameEv)
  677. {
  678. SkillActionAttackInfo attackInfo = frameEv.CreateAttackInfo();
  679. mFighter.StateData.PlayAnim(frameEv.GetStr("animName"));
  680. if(attackInfo.hitEffect > 0)
  681. {
  682. repeatCastingEffectInstanceId = EffectManager.Instance.PlayEffect((int)attackInfo.hitEffect, mFighter, mFighter);
  683. if (repeatCastingEffectInstanceId > 0)
  684. mTriggeredEffects.Add(repeatCastingEffectInstanceId);
  685. }
  686. mFighter.ShowCasting((frameEv.endFrame - frameEv.startFrame) / Constants.frame_to_time, true);
  687. isCasting = true;
  688. }
  689. private void EndRepeatingCasting()
  690. {
  691. if(isCasting)
  692. {
  693. if (repeatCastingEffectInstanceId > 0)
  694. {
  695. EffectManager.Instance.RemoveEffectByInstanceID(repeatCastingEffectInstanceId);
  696. mTriggeredEffects.Remove(repeatCastingEffectInstanceId);
  697. repeatCastingEffectInstanceId = 0;
  698. }
  699. mFighter.ShowCasting(0, false);
  700. isCasting = false;
  701. }
  702. }
  703. private void FireBullet(SkillActionFrameEvent frameEv)
  704. {
  705. if (mTempHitFighters == null || mTempHitFighters.Count == 0) return;
  706. SkillActionAttackInfo info = frameEv.CreateAttackInfo();
  707. if (info.bulletID == 0) return;
  708. for (int idx =0; idx < mTempHitFighters.Count;idx++)
  709. {
  710. Fighter f = mTempHitFighters[idx];
  711. if (f == mFighter || f.IsDisposed || !f.IsAlive) continue;
  712. mFighter.StateData.SkillStateData.BulletMgr.Add(mFighter, f, info,this);
  713. }
  714. }
  715. private void SwitchSkill(SkillActionFrameEvent frameEv)
  716. {
  717. if (mTempHitFighters == null || mTempHitFighters.Count == 0) return;
  718. SkillActionAttackInfo info = frameEv.CreateAttackInfo();
  719. PerformAttackInfo(info);
  720. }
  721. private void SelectTarget()
  722. {
  723. bool reselect = false;
  724. if(mFighter.StateData.IsSneer &&
  725. (FilterRule.teamType == FilterTeamType.Team_Type_Enemy) &&
  726. (BuffTargetType == Target_Select_Rule.Target_Select_OnlyOne ||
  727. BuffTargetType == Target_Select_Rule.Target_Select_RandomOne ||
  728. BuffTargetType == Target_Select_Rule.Target_Select_RandomOne_Prior_Front ||
  729. BuffTargetType == Target_Select_Rule.Target_Select_RandomOne_Prior_Back))
  730. {
  731. DurationFunctionEvent evt = mFighter.FuncMgr.GetFunctionByType(Buff_Function_Type.Sneer);
  732. if(evt != null)
  733. {
  734. mTempHitFighters.Clear();
  735. mTempHitFighters.Add(evt.Caster);
  736. RotateToTarget(evt.Caster);
  737. }
  738. else
  739. {
  740. reselect = true;
  741. }
  742. }
  743. else
  744. {
  745. reselect = true;
  746. }
  747. if(reselect)
  748. {
  749. mTarget = GetBeHitFightersByAttackInfo();
  750. if (mTarget != null)
  751. {
  752. RotateToTarget(mTarget);
  753. }
  754. }
  755. }
  756. #region BeHitFighter TotalDamage
  757. private int GetTotalDamageByHitFighterIndex(int nIdx)
  758. {
  759. bool bIsFind = mDicTotalDamage.ContainsKey(nIdx);
  760. if(!bIsFind)
  761. {
  762. mDicTotalDamage.Add(nIdx, 0);
  763. }
  764. return mDicTotalDamage[nIdx];
  765. }
  766. private void AddTotalDamageByHitFighterIndex(int nIdx,int nDamage)
  767. {
  768. bool bIsFind = mDicTotalDamage.ContainsKey(nIdx);
  769. if (!bIsFind)
  770. {
  771. mDicTotalDamage.Add(nIdx, nDamage);
  772. return;
  773. }
  774. mDicTotalDamage[nIdx] += nDamage;
  775. }
  776. #endregion
  777. public void PerformAttackInfo(SkillActionAttackInfo attackInfo)
  778. {
  779. attackInfo.skill = mSkill;
  780. if (mHitFighterInfoList == null)
  781. mHitFighterInfoList = new List<SkillHitFighterInfo>();
  782. else
  783. mHitFighterInfoList.Clear();
  784. //mFighter.ProcessTriggerBuff(BuffTriggerType.Trigger_Attack);
  785. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_Fighter_Attack, mFighter));
  786. hurtTimes++;
  787. for (int idx = 0; idx < mTempHitFighters.Count; idx++)
  788. {
  789. Fighter pCaster = GetSourceFighter();//伤害计算 采用源
  790. mHitFighterInfoList.Add(new SkillHitFighterInfo(pCaster, mTempHitFighters[idx],BuffId, attackInfo));
  791. }
  792. CheckMark();
  793. for (int idx = 0; idx < mHitFighterInfoList.Count; idx++)
  794. {
  795. if (mHasBeenStop) return;
  796. SkillHitFighterInfo hitInfo = mHitFighterInfoList[idx];
  797. ExecuteFunction(hitInfo, idx);
  798. if(attackInfo.buffID > 0)
  799. {
  800. int random = (int)(mBattle.RandomValue(true) * 100);
  801. if (random <= attackInfo.rate)
  802. {
  803. BattleBuff pBuff = hitInfo.Target.CastBuff(null, attackInfo.buffID);
  804. if (null != pBuff)
  805. {
  806. Fighter pFighter = GetSourceFighter(); //获取源 设置新BUFF源
  807. pBuff.SetSourceFighter(pFighter);
  808. }
  809. }
  810. }
  811. mDamageList.Add(hitInfo.HitParam);
  812. }
  813. MusicMgr.Instance.PlayFightSound(attackInfo.sound);
  814. }
  815. //子彈攻击
  816. public void PerformBullteAttackInfo(SkillActionAttackInfo attackInfo,Fighter pBullteTarget)
  817. {
  818. attackInfo.skill = mSkill;
  819. if (mHitFighterInfoList == null)
  820. mHitFighterInfoList = new List<SkillHitFighterInfo>();
  821. else
  822. mHitFighterInfoList.Clear();
  823. //mFighter.ProcessTriggerBuff(BuffTriggerType.Trigger_Attack);
  824. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_Fighter_Attack, mFighter));
  825. hurtTimes++;
  826. if(null != pBullteTarget)
  827. {
  828. Fighter pCaster = GetSourceFighter();//伤害计算 采用源
  829. mHitFighterInfoList.Add(new SkillHitFighterInfo(pCaster, pBullteTarget, BuffId, attackInfo));
  830. }
  831. CheckMark();
  832. for (int idx = 0; idx < mHitFighterInfoList.Count; idx++)
  833. {
  834. if (mHasBeenStop) return;
  835. SkillHitFighterInfo hitInfo = mHitFighterInfoList[idx];
  836. ExecuteFunction(hitInfo, idx);
  837. if (attackInfo.buffID > 0)
  838. {
  839. int random = (int)(mBattle.RandomValue(true) * 100);
  840. if (random <= attackInfo.rate)
  841. {
  842. BattleBuff pBuff = hitInfo.Target.CastBuff(null, attackInfo.buffID);
  843. if (null != pBuff)
  844. {
  845. Fighter pFighter = GetSourceFighter(); //获取源 设置新BUFF源
  846. pBuff.SetSourceFighter(pFighter);
  847. }
  848. }
  849. }
  850. mDamageList.Add(hitInfo.HitParam);
  851. }
  852. MusicMgr.Instance.PlayFightSound(attackInfo.sound);
  853. }
  854. private void PerformAttackEffect(SkillActionAttackInfo attackInfo)
  855. {
  856. for (int idx = 0; idx < mTempHitFighters.Count; idx++)
  857. {
  858. Fighter target = mTempHitFighters[idx];
  859. target.Ctrl.DoBeHitEffect(attackInfo.effect, mFighter);
  860. }
  861. }
  862. private void ExecuteFunction(SkillHitFighterInfo hitInfo,int nIdx)
  863. {
  864. bool isDamage = false;
  865. Fighter pCaster = hitInfo.Caster;
  866. for (int idx = 0; idx < mBuffData.BuffFunList.Count; idx++)
  867. {
  868. if (mHasBeenStop) break;
  869. BuffFunctionData data = mBuffData.BuffFunList[idx];
  870. if (data.IsInstantFunc)
  871. {
  872. if(data.buffType == BattleBuffType.Hurt)
  873. {
  874. isDamage = true;
  875. mFighter.FuncMgr.AddFunctionEvent(BuffId,data, pCaster, hitInfo);
  876. }
  877. else
  878. {
  879. hitInfo.Target.FuncMgr.AddFunctionEvent(BuffId,data, pCaster, hitInfo);
  880. }
  881. }
  882. else
  883. {
  884. hitInfo.Target.FuncMgr.AddFunctionEvent(BuffId,data, pCaster, hitInfo);
  885. }
  886. }
  887. if (hitInfo.Target == null || hitInfo.Target.IsDisposed || !hitInfo.Target.IsAlive || !isDamage)
  888. {
  889. mFighter.FuncMgr.RemoveFunctionByBuffType(BattleBuffType.Hurt);
  890. if(hitInfo.Target!=null && !hitInfo.Target.IsDisposed && hitInfo.Target.IsAlive)
  891. hitInfo.Target.Ctrl.DoBeHitEffect(hitInfo.AttackInfo.hitEffect, hitInfo.Caster);
  892. return;
  893. }
  894. SInt damage = hitInfo.CalculateDamage(mBuffData.damageType,mBuffData.hitType);
  895. if (!mBuffData.ignoreMultiHurt)
  896. {
  897. hitInfo.AttackInfo.multiHitCount = totalHurtCnt;
  898. hitInfo.AttackInfo.multiHitIntervalTime = mBuffData.multiHurtIntervalTime;
  899. }
  900. else
  901. {
  902. hurtTimes = 0;
  903. }
  904. if (BattleMgr.Instance.Battle.CanPrintLog)
  905. DebugHelper.LogError(this.BuffId + "-------------Fighter=" + mFighter.Name + " target:" + hitInfo.Target.Name + " damage=" + damage + " IsPerfactDodge:" + hitInfo.IsPerfectDodge + " IsDodge:" + hitInfo.IsDodge + " IsCrit:" + hitInfo.IsCrit + " 无敌:" + hitInfo.Target.StateData.IsInvincible);
  906. //累计当前伤害
  907. int nTotalDamge = GetTotalDamageByHitFighterIndex(nIdx);
  908. hitInfo.Target.ProcessBeHit(hitInfo, hurtTimes, nTotalDamge);
  909. hitInfo.SetRealDamage((int)hitInfo.Damage);
  910. AddTotalDamageByHitFighterIndex(nIdx, (int)hitInfo.Damage);
  911. mFighter.FuncMgr.RemoveFunctionByBuffType(BattleBuffType.Hurt);
  912. if (mFighter.Statistics != null)
  913. mFighter.Statistics.StatHitInfo(hitInfo);
  914. //反伤伤害数据
  915. if (hitInfo.ReflectDamage > 0)
  916. {
  917. pCaster.ProcessReflectDamage(hitInfo.ReflectDamage, mSkill!=null?mSkill.SkillName:"", hitInfo.Target);
  918. }
  919. //吸收伤害
  920. if (hitInfo.SuckDamge > 0)
  921. {
  922. hitInfo.Target.ProcessSuckDamage(hitInfo.SuckDamge, mSkill != null ? mSkill.SkillName : "", pCaster);
  923. }
  924. }
  925. private Fighter GetBeHitFightersByAttackInfo()
  926. {
  927. mTempHitFighters.Clear();
  928. List<Fighter> filterFighters = FilterTargets(mFighter.CurrentBattleField.Fighters);
  929. bool hasFront, hasback;
  930. CheckTargetInfo(filterFighters,out hasFront, out hasback);
  931. if(BuffTargetType == Target_Select_Rule.Target_Select_All)
  932. {
  933. for(int idx =0; idx < filterFighters.Count;idx++)
  934. {
  935. var f = filterFighters[idx];
  936. mTempHitFighters.Add(f);
  937. }
  938. }
  939. else if (BuffTargetType == Target_Select_Rule.Target_Select_Self)
  940. {
  941. if(mFighter.IsAlive)
  942. mTempHitFighters.Add(mFighter);
  943. }
  944. else if(BuffTargetType == Target_Select_Rule.Target_Select_Owner_And_Pet)
  945. {
  946. if (mFighter.IsAlive)
  947. mTempHitFighters.Add(mFighter);
  948. if(mFighter.IsPlayer)
  949. {
  950. if(mFighter.UsedPetId > 0)
  951. {
  952. Fighter pet = mFighter.Battle.FighterMgr.GetFighterByID(mFighter.UsedPetId, mFighter.TeamSide);
  953. if(pet!=null && pet.IsAlive)
  954. {
  955. mTempHitFighters.Add(pet);
  956. }
  957. }
  958. }
  959. else if(mFighter.IsPet)
  960. {
  961. Fighter owner = mFighter.Battle.FighterMgr.GetFighterByID(mFighter.OwnerId, mFighter.TeamSide);
  962. if(owner != null && owner.IsAlive)
  963. {
  964. mTempHitFighters.Add(owner);
  965. }
  966. }
  967. }
  968. else if(BuffTargetType == Target_Select_Rule.Target_Select_Owner)
  969. {
  970. Fighter owner = mFighter.Battle.FighterMgr.GetFighterByID(mFighter.OwnerId, mFighter.TeamSide);
  971. if(owner != null)
  972. {
  973. if(owner.IsAlive)
  974. mTempHitFighters.Add(owner);
  975. }
  976. else
  977. {
  978. if(mFighter.IsAlive)
  979. mTempHitFighters.Add(mFighter);
  980. }
  981. }
  982. else if(IsSingleTarget(BuffTargetType))
  983. {
  984. Fighter fighter = SkillSelectHelper.SelectTargetsByRules(mFighter, filterFighters, BuffTargetType, OnBeforeFilter, OnAfterCompare);
  985. if (fighter != null)
  986. {
  987. mTempHitFighters.Add(fighter);
  988. }
  989. }
  990. else if(BuffTargetType == Target_Select_Rule.Target_Select_Exclude_Self)
  991. {
  992. for (int idx = 0; idx < filterFighters.Count; idx++)
  993. {
  994. Fighter f = filterFighters[idx];
  995. if (f == mFighter) continue;
  996. mTempHitFighters.Add(f);
  997. }
  998. }
  999. else if(BuffTargetType == Target_Select_Rule.Target_Select_RandomOne)
  1000. {
  1001. if (filterFighters.Count >= 1)
  1002. {
  1003. int idx = (int)(BattleMgr.Instance.Battle.RandomValue(false) * filterFighters.Count);
  1004. Fighter f = filterFighters[idx];
  1005. mTempHitFighters.Clear();
  1006. mTempHitFighters.Add(f);
  1007. }
  1008. }
  1009. else if(BuffTargetType == Target_Select_Rule.Target_Select_RandomOne_Prior_Front ||
  1010. BuffTargetType == Target_Select_Rule.Target_Select_RandomOne_Prior_Back)
  1011. {
  1012. for (int idx = 0; idx < filterFighters.Count; idx++)
  1013. {
  1014. Fighter f = filterFighters[idx];
  1015. if (BuffTargetType == Target_Select_Rule.Target_Select_RandomOne_Prior_Front)
  1016. {
  1017. if (f.IsFront || !hasFront)
  1018. mTempHitFighters.Add(f);
  1019. }
  1020. else if (BuffTargetType == Target_Select_Rule.Target_Select_RandomOne_Prior_Back)
  1021. {
  1022. if (f.IsBack || !hasback)
  1023. mTempHitFighters.Add(f);
  1024. }
  1025. }
  1026. if (mTempHitFighters.Count > 1)
  1027. {
  1028. int idx = (int)((BattleMgr.Instance.Battle.RandomValue(false) * (mTempHitFighters.Count * 50) / 50.0f));
  1029. Fighter f = mTempHitFighters[idx];
  1030. mTempHitFighters.Clear();
  1031. mTempHitFighters.Add(f);
  1032. }
  1033. }
  1034. else if(BuffTargetType == Target_Select_Rule.Target_Select_Pos_Prior_Front ||
  1035. BuffTargetType == Target_Select_Rule.Target_Select_Pos_Prior_Back)
  1036. {
  1037. for (int idx = 0; idx < filterFighters.Count; idx++)
  1038. {
  1039. Fighter f = filterFighters[idx];
  1040. if (BuffTargetType == Target_Select_Rule.Target_Select_Pos_Prior_Front)
  1041. {
  1042. if (f.IsFront || !hasFront)
  1043. mTempHitFighters.Add(f);
  1044. }
  1045. else if (BuffTargetType == Target_Select_Rule.Target_Select_Pos_Prior_Back)
  1046. {
  1047. if (f.IsBack || !hasback)
  1048. mTempHitFighters.Add(f);
  1049. }
  1050. }
  1051. }
  1052. if (mFighter.SelectTarget!=null && mTempHitFighters.Contains(mFighter.SelectTarget))
  1053. {
  1054. return mFighter.SelectTarget;
  1055. }
  1056. Fighter target = null;
  1057. float dist = 100000f;
  1058. for(int idx =0; idx < mTempHitFighters.Count;idx++)
  1059. {
  1060. float d = Vector3.Distance(mTempHitFighters[idx].Position, mFighter.Position);
  1061. if(d < dist)
  1062. {
  1063. d = dist;
  1064. target = mTempHitFighters[idx];
  1065. }
  1066. }
  1067. return target;
  1068. }
  1069. private List<Fighter> temp1 = null;
  1070. private List<Fighter> temp2 = null;
  1071. private List<Fighter> FilterTargets(List<Fighter> fighters)
  1072. {
  1073. if (fighters == null || fighters.Count == 0) return null;
  1074. if (temp1 == null)
  1075. temp1 = new List<Fighter>();
  1076. else
  1077. temp1.Clear();
  1078. if (temp2 == null)
  1079. temp2 = new List<Fighter>();
  1080. else
  1081. temp2.Clear();
  1082. for (int idx = 0; idx < fighters.Count; idx++)
  1083. {
  1084. var f = fighters[idx];
  1085. if (!f.IsAlive) continue;
  1086. if (FilterRule.teamType == FilterTeamType.Team_Type_Self_Team)
  1087. {
  1088. if(f.TeamSide == mFighter.TeamSide)
  1089. {
  1090. temp1.Add(f);
  1091. }
  1092. }
  1093. else if (FilterRule.teamType == FilterTeamType.Team_Type_Enemy)
  1094. {
  1095. if (f.TeamSide != mFighter.TeamSide)
  1096. {
  1097. temp1.Add(f);
  1098. }
  1099. }
  1100. }
  1101. for(int idx =0; idx < temp1.Count;idx++)
  1102. {
  1103. var f = temp1[idx];
  1104. if(FilterRule.actorType == FilterActorType.Actor_Type_All ||
  1105. (int)FilterRule.actorType == (int)f.Actor.AType ||
  1106. (FilterRule.actorType == FilterActorType.Actor_Type_Hero_Fellow && f.IsPlayer))
  1107. {
  1108. temp2.Add(f);
  1109. }
  1110. else if (FilterRule.actorType == FilterActorType.Actor_Type_Exclude_Pet)
  1111. {
  1112. if (!f.IsPet)
  1113. {
  1114. temp2.Add(f);
  1115. }
  1116. }
  1117. }
  1118. if(FilterRule.paramType == FilterParamType.Param_Type_None) return temp2;
  1119. if(FilterRule.paramType == FilterParamType.Param_Type_Profession)
  1120. {
  1121. temp1.Clear();
  1122. for(int idx = 0; idx < temp2.Count;idx++)
  1123. {
  1124. var f = temp2[idx];
  1125. if(FilterRule.paramVal == -1 || FilterRule.paramVal == (int)f.ProfType)
  1126. {
  1127. temp1.Add(f);
  1128. }
  1129. }
  1130. }
  1131. else if(FilterRule.paramType == FilterParamType.Param_Type_Nature)
  1132. {
  1133. temp1.Clear();
  1134. for(int idx =0; idx < temp2.Count;idx++)
  1135. {
  1136. var f = temp2[idx];
  1137. if(FilterRule.paramVal == -1 || FilterRule.paramVal == f.NatureId)
  1138. {
  1139. temp1.Add(f);
  1140. }
  1141. }
  1142. }
  1143. else if(FilterRule.paramType == FilterParamType.Param_Type_PetId)
  1144. {
  1145. temp1.Clear();
  1146. for (int idx = 0; idx < temp2.Count; idx++)
  1147. {
  1148. var f = temp2[idx];
  1149. if (FilterRule.paramVal == f.Actor.BaseId)
  1150. {
  1151. temp1.Add(f);
  1152. }
  1153. }
  1154. }
  1155. return temp1;
  1156. }
  1157. private void CheckTargetInfo(List<Fighter> fighters,out bool hasFront,out bool hasBack)
  1158. {
  1159. hasFront = false;
  1160. hasBack = false;
  1161. for (int idx = 0; idx < fighters.Count;idx++)
  1162. {
  1163. Fighter f = fighters[idx];
  1164. if (f == null || !f.IsAlive) continue;
  1165. if (!hasFront)
  1166. hasFront = f.IsFront;
  1167. if (!hasBack)
  1168. hasBack = f.IsBack;
  1169. }
  1170. }
  1171. private bool IsSingleTarget(Target_Select_Rule targetType)
  1172. {
  1173. return targetType == Target_Select_Rule.Target_Select_OnlyOne ||
  1174. targetType == Target_Select_Rule.Target_Select_LeastBlood ||
  1175. targetType == Target_Select_Rule.Target_Select_Most_NegativeBuff ||
  1176. targetType == Target_Select_Rule.Target_Select_Most_LeastLifePercent ||
  1177. targetType == Target_Select_Rule.Target_Select_MostLife;
  1178. }
  1179. private bool OnBeforeFilter(Fighter fighter)
  1180. {
  1181. bool ret = SkillSelectHelper.CheckTargetSelectable(mSkill, mFighter, fighter);
  1182. return ret;
  1183. }
  1184. private int OnAfterCompare(Fighter fighter1, Fighter fighter2, Target_Select_Rule rule)
  1185. {
  1186. return SkillSelectHelper.CompareFighterByRule(mFighter, fighter1, fighter2,rule);
  1187. }
  1188. private void RotateToTarget(Fighter target)
  1189. {
  1190. if (target == null) return;
  1191. mFighter.SelectTarget = target;
  1192. Vector3 pos = target.Position;
  1193. if(target.TeamSide == mFighter.TeamSide)
  1194. {
  1195. int maxRotate = GlobalConfig.Instance.GetConfigIntValue(GlobalConfig.c_maxRotate_InTeam);
  1196. Vector3 dir = pos - mFighter.Position;
  1197. float angle = Vector3.Dot(mFighter.Forward, dir);
  1198. if(angle >= Mathf.Cos(maxRotate))
  1199. {
  1200. mFighter.LookAt(pos);
  1201. }
  1202. }
  1203. else
  1204. {
  1205. mFighter.LookAt(pos);
  1206. }
  1207. }
  1208. private void CheckMark()
  1209. {
  1210. if (bCheckMark) return;
  1211. bCheckMark = true;
  1212. if (mBuffData.markData != null)
  1213. {
  1214. var markData = mBuffData.markData;
  1215. if(markData.markVal > 0)
  1216. {
  1217. if (markData.markTargetType == 1)
  1218. {
  1219. mFighter.AddMark(markData.markId, markData.markVal);
  1220. }
  1221. else if (markData.markTargetType == 2)
  1222. {
  1223. for (int idx = 0; idx < mHitFighterInfoList.Count; idx++)
  1224. {
  1225. var target = mHitFighterInfoList[idx].Target;
  1226. target.AddMark(markData.markId, markData.markVal);
  1227. }
  1228. }
  1229. }
  1230. else
  1231. {
  1232. if(mBuffData.markExtendList != null)
  1233. {
  1234. int extendBuffId = 0;
  1235. for(int idx = mBuffData.markExtendList.Count - 1; idx>=0; idx--)
  1236. {
  1237. var extendMark = mBuffData.markExtendList[idx];
  1238. if (markData.markTargetType == 1)
  1239. {
  1240. if(mFighter.HasMarkNLayer(markData.markId,extendMark.id))
  1241. {
  1242. extendBuffId = extendMark.val;
  1243. if(markData.markVal < 0)
  1244. {
  1245. mFighter.DecMark(markData.markId, extendMark.id);
  1246. }
  1247. }
  1248. }
  1249. else if (markData.markTargetType == 2 && mHitFighterInfoList.Count > 0)
  1250. {
  1251. for (int i = 0; i < mHitFighterInfoList.Count; i++)
  1252. {
  1253. var target = mHitFighterInfoList[i].Target;
  1254. if(target.HasMarkNLayer(markData.markId, extendMark.id))
  1255. {
  1256. extendBuffId = extendMark.val;
  1257. if(markData.markVal < 0)
  1258. {
  1259. target.DecMark(markData.markId, extendMark.id);
  1260. }
  1261. break;
  1262. }
  1263. }
  1264. }
  1265. if(extendBuffId > 0)
  1266. {
  1267. break;
  1268. }
  1269. }
  1270. if(extendBuffId > 0)
  1271. {
  1272. BattleBuff pBuff = mFighter.CastBuff(null, extendBuffId, skillLv);
  1273. if (null != pBuff)
  1274. {
  1275. Fighter pFighter = GetSourceFighter(); //获取源 设置新BUFF源
  1276. pBuff.SetSourceFighter(pFighter);
  1277. }
  1278. Stop();
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. }