Fighter.cs 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. public struct stBuffParam
  4. {
  5. public int teamSide;
  6. public long actorId;
  7. public bool isBoss;
  8. public string buffIcon;
  9. public int pointNum;
  10. public stBuffParam(eTeamType teamSide,long id, bool boss, string icon, int num)
  11. {
  12. this.teamSide = (int)teamSide;
  13. this.actorId = id;
  14. this.isBoss = boss;
  15. this.buffIcon = icon;
  16. this.pointNum = num;
  17. }
  18. }
  19. public struct PlayerActorBattleAttr
  20. {
  21. public SFloat STR;
  22. public SFloat AGI;
  23. public SFloat INT;
  24. public SFloat VIT;
  25. public SFloat DEX;
  26. public SFloat LUK;
  27. public SFloat life;
  28. public SFloat sp;
  29. public SFloat minAttack;
  30. public SFloat attack;
  31. public SFloat minMagicAttack;
  32. public SFloat magic_attack;
  33. public SFloat defense;
  34. public SFloat magic_defense;
  35. public SFloat crit;
  36. public SFloat dodge;
  37. public SFloat hit;
  38. public SFloat ten;
  39. public SFloat attackSpeed;
  40. public SFloat GodPower; //真实伤害
  41. public SFloat defPercent;
  42. public SFloat magicDefPercent;
  43. public SFloat penetration; //忽视物防
  44. public SFloat magic_penetration; //忽视魔防
  45. public SFloat physicDamagePercent; //物伤百分比
  46. public SFloat magicDamagePercent; //魔法伤害百分比
  47. public SFloat antiPhysicDamPercent; //抗物伤百分比
  48. public SFloat antiMagicDamPercent; //抗魔防伤害百分比
  49. public SFloat critDamagePercent; //暴击伤害百分比
  50. public SFloat physicDamageReflectPercent; //物理伤害反射百分比
  51. public SFloat magicDamageReflectPercent; //魔法伤害反射百分比
  52. public SFloat fixedSingTimePercent; //固定吟唱时间修改百分比
  53. public SFloat variableSingTimePercent; //可变吟唱时间修改百分比
  54. public SFloat[] natureDamagePercent;
  55. public SFloat[] antiNatureDamagePercent;
  56. public List<TriggerBuffData> triggerBuffs;
  57. public CastSkillData castSkillData;
  58. public void Init(ActorData actor, SFloat lifeRatio, int atkFactor, int magicAtkFactor, int hpFactor, int spFactor)
  59. {
  60. STR = actor.STR;
  61. AGI = actor.AGI;
  62. INT = actor.INT;
  63. VIT = actor.VIT;
  64. DEX = actor.DEX;
  65. LUK = actor.LUK;
  66. life = actor.Life * lifeRatio * (1 + hpFactor * 0.01f);
  67. //Debug.LogFormat(" Life Actor Id ={0} Final Hp = {1} Svr HP = {2}", actor.ID.ToString(), actor.Life.ToString(),
  68. // actor.GetSeverSecondAttr(ActorData.Attr_Life));
  69. sp = actor.Sp * (1 + spFactor * 0.01f);
  70. minAttack = actor.MinAttack * (1 + atkFactor * 0.01f);
  71. attack = actor.Attack * (1 + atkFactor * 0.01f);
  72. minMagicAttack = actor.MinMagicAttack * (1 + magicAtkFactor * 0.01f);
  73. magic_attack = actor.MagicAttack * (1 + magicAtkFactor * 0.01f);
  74. if (life < 0) life = 0;
  75. if (sp < 0) sp = 0;
  76. if (minAttack < 0) minAttack = 0;
  77. if (attack < 0) attack = 0;
  78. if (minMagicAttack < 0) minMagicAttack = 0;
  79. if (magic_attack < 0) magic_attack = 0;
  80. defense = actor.Defense;
  81. magic_defense = actor.MagicDefense;
  82. crit = actor.Crit;
  83. critDamagePercent = actor.CritDamagePercent;
  84. dodge = actor.Dodge;
  85. hit = actor.Hit;
  86. ten = actor.Ten;
  87. attackSpeed = actor.AttackSpeed;
  88. penetration = actor.Penetration;
  89. magic_penetration = actor.MagicPenetration;
  90. defPercent = actor.DefPercent;
  91. magicDefPercent = actor.MagicDefPercent;
  92. GodPower = actor.GodPower; //GetAdditionalAttr(ActorData.Attr_GodPow);
  93. physicDamagePercent = actor.GetAdditionalAttrPercent(ActorData.Attr_PhysicDamage_Percent);
  94. magicDamagePercent = actor.GetAdditionalAttrPercent(ActorData.Attr_MagicDamage_Percent);
  95. antiPhysicDamPercent = actor.GetAdditionalAttrPercent(ActorData.Attr_Anti_PhysicDamage_Percent);
  96. antiMagicDamPercent = actor.GetAdditionalAttrPercent(ActorData.Attr_Anti_MagicDamage_Percent);
  97. physicDamageReflectPercent = actor.GetAdditionalAttrPercent(ActorData.Attr_PhysicDamageReflect_Percent);
  98. magicDamageReflectPercent = actor.GetAdditionalAttrPercent(ActorData.Attr_MagicDamageReflect_Percent);
  99. fixedSingTimePercent = actor.GetAdditionalAttrPercent(ActorData.Attr_FixedSingTime_Percent);
  100. variableSingTimePercent = actor.GetAdditionalAttrPercent(ActorData.Attr_VariableSingTime_Percent);
  101. castSkillData = actor.CastSkillParam;
  102. natureDamagePercent = new SFloat[(int)Nature_Type.Max - 1];
  103. antiNatureDamagePercent = new SFloat[(int)Nature_Type.Max - 1];
  104. for (int idx = (int)Nature_Type.None; idx < (int)Nature_Type.Max; idx++)
  105. {
  106. natureDamagePercent[idx - 1] = actor.GetAdditionalAttrPercent(70 + idx);
  107. antiNatureDamagePercent[idx - 1] = actor.GetAdditionalAttrPercent(80 + idx);
  108. }
  109. if (triggerBuffs == null)
  110. triggerBuffs = new List<TriggerBuffData>();
  111. else
  112. triggerBuffs.Clear();
  113. if (actor.TriggerBuffs != null)
  114. {
  115. triggerBuffs.AddRange(actor.TriggerBuffs);
  116. }
  117. if (actor.DropBuffList != null)
  118. {
  119. triggerBuffs.AddRange(actor.DropBuffList);
  120. }
  121. for (int idx = 0; idx < triggerBuffs.Count; idx++)
  122. {
  123. triggerBuffs[idx].ResetData();
  124. }
  125. //DebugLog(actor);
  126. }
  127. public void DebugLog(ActorData pActor)
  128. {
  129. string strLog = string.Format("名字 = {0} \n", pActor.Name);
  130. strLog += string.Format("STR 力量 = {0} \n", STR.ToString());
  131. strLog += string.Format("AGI 敏捷 = {0} \n", AGI.ToString());
  132. strLog += string.Format("INT 智力 = {0} \n", INT.ToString());
  133. strLog += string.Format("VIT 体质 = {0} \n", VIT.ToString());
  134. strLog += string.Format("DEX 灵巧 = {0} \n", DEX.ToString());
  135. strLog += string.Format("LUK 幸运 = {0} \n", LUK.ToString());
  136. strLog += string.Format("life 生命 = {0} \n", life.ToString());
  137. strLog += string.Format("sp 蓝量 = {0} \n", sp.ToString());
  138. strLog += string.Format("minAttack 最小物攻 = {0} \n", minAttack.ToString());
  139. strLog += string.Format("attack 物攻 = {0} \n", attack.ToString());
  140. strLog += string.Format("minMagicAttack 最少魔攻 = {0} \n", minMagicAttack.ToString());
  141. strLog += string.Format("magic_attack 魔攻 = {0} \n", magic_attack.ToString());
  142. strLog += string.Format("defense 物防 = {0} \n", defense.ToString());
  143. strLog += string.Format("magic_defense 魔防 = {0} \n", magic_defense.ToString());
  144. strLog += string.Format("crit 暴击 = {0} \n", crit.ToString());
  145. strLog += string.Format("critDamagePercent 暴击伤害百分比 = {0} \n", critDamagePercent.ToString());
  146. strLog += string.Format("dodge 闪避 = {0} \n", dodge.ToString());
  147. strLog += string.Format("hit 命中 = {0} \n", hit.ToString());
  148. strLog += string.Format("Ten 韧性 = {0} \n", ten.ToString());
  149. strLog += string.Format("AttackSpeed 攻击速度 = {0} \n", attackSpeed.ToString());
  150. strLog += string.Format("penetration 忽视物防 = {0} \n", penetration.ToString());
  151. strLog += string.Format("magic_penetration 忽视魔防 = {0} \n", magic_penetration.ToString());
  152. strLog += string.Format("defPercent 物防百分比 = {0} \n", defPercent.ToString());
  153. strLog += string.Format("magicDefPercent 魔防百分比 = {0} \n", magicDefPercent.ToString());
  154. strLog += string.Format("GodPower 神威值 = {0} \n", GodPower.ToString());
  155. strLog += string.Format("physicDamagePercent 物伤加成/减免百分比 = {0} \n", physicDamagePercent.ToString());
  156. strLog += string.Format("magicDamagePercent 魔伤加成/魔免百分比 = {0} \n", magicDamagePercent.ToString());
  157. strLog += string.Format("antiPhysicDamPercent 物抗伤加成 = {0} \n", antiPhysicDamPercent.ToString());
  158. strLog += string.Format("antiMagicDamPercent 魔抗伤加成 = {0} \n", antiMagicDamPercent.ToString());
  159. strLog += string.Format("physicDamageReflectPercent 物理伤害反射百分比 = {0} \n", physicDamageReflectPercent.ToString());
  160. strLog += string.Format("magicDamageReflectPercent 魔法伤害反射百分比 = {0} \n", magicDamageReflectPercent.ToString());
  161. strLog += string.Format("fixedSingTimePercent 固定吟唱时间修改百分比 = {0} \n", fixedSingTimePercent.ToString());
  162. strLog += string.Format("variableSingTimePercent 可变吟唱时间修改百分比 = {0} \n", variableSingTimePercent.ToString());
  163. for (int idx = (int)Nature_Type.None; idx < (int)Nature_Type.Max; idx++)
  164. {
  165. string strInfo = "无";
  166. switch (idx)
  167. {
  168. case (int)Nature_Type.Nature_Water:
  169. strInfo = "水";
  170. break;
  171. case (int)Nature_Type.Nature_Ground:
  172. strInfo = "地";
  173. break;
  174. case (int)Nature_Type.Nature_Fire:
  175. strInfo = "火";
  176. break;
  177. case (int)Nature_Type.Nature_Wind:
  178. strInfo = "风";
  179. break;
  180. case (int)Nature_Type.Nature_Saint:
  181. strInfo = "圣";
  182. break;
  183. case (int)Nature_Type.Nature_Dark:
  184. strInfo = "暗";
  185. break;
  186. case (int)Nature_Type.Nature_Read:
  187. strInfo = "念";
  188. break;
  189. }
  190. strLog += string.Format("{0} = {1} --- {2} \n", strInfo, natureDamagePercent[idx - 1].ToString(), antiNatureDamagePercent[idx - 1]);
  191. }
  192. for (int i = ActorData.Attr_Life; i <= ActorData.Attr_CastAcceleration; i++)
  193. {
  194. strLog += string.Format("Server AtrrKey = {0} ,Value = {1}\n", i.ToString(), pActor.GetSeverSecondAttr(i).ToString());
  195. }
  196. Debug.Log(strLog);
  197. }
  198. }
  199. public class Fighter : LogicTransform
  200. {
  201. static ulong AutoIncreaseInstanceID;
  202. public static void ResetInstanceID()
  203. {
  204. AutoIncreaseInstanceID = 0;
  205. }
  206. public static string BuildFighterGoName(int id, eTeamType side, bool isSummon,bool isPet)
  207. {
  208. string prefix = "fighter_";
  209. if (isPet)
  210. prefix = "pet_";
  211. else if (isSummon)
  212. prefix = "summon_";
  213. return prefix + (side == eTeamType.Friend ? "l_" : "r_") + id;
  214. }
  215. public static Fighter CreateFighter(FighterManager fighterMgr, ActorData actor, eTeamType side, Fighter summonOwner = null)
  216. {
  217. Fighter fighter = new Fighter(fighterMgr);
  218. fighter.InitGo(BuildFighterGoName(actor.BaseId, side, summonOwner != null,actor.IsPet));
  219. fighter.Initialize(actor, side, summonOwner);
  220. fighter.Prepare();
  221. return fighter;
  222. }
  223. Fighter(FighterManager mgr)
  224. {
  225. InstanceId = ++AutoIncreaseInstanceID;
  226. mFighterMgr = mgr;
  227. MoveSpeed = GlobalConfig.Instance.GetConfigIntValue(GlobalConfig.c_walkspeed_configid);
  228. mFunPointBuffs = new Dictionary<int, int>();
  229. }
  230. #region fields
  231. FighterManager mFighterMgr;
  232. FighterAi mAi;
  233. PassiveMove mPassiveMove;
  234. FighterStateData mStateData;
  235. FighterBuffManager mBuffMgr;
  236. FighterBuffFunctionMgr mFuncMgr;
  237. FighterGoCtrl mCtrl;
  238. PlayerActorBattleAttr mActorBattleAttr;
  239. //Fighter2DBloodBar mBloodBarHud;
  240. FighterHPBar mHpBarHud;
  241. SkillName2D mSkillNameHud;
  242. RageEffect2D mRageEffectHud;
  243. Dictionary<int,int> mFunPointBuffs = null;
  244. Dictionary<int, int> mSkillBuffPoints = new Dictionary<int, int>();
  245. #endregion //fields
  246. #region property
  247. public ulong InstanceId { get; private set; }
  248. public FighterManager FighterMgr { get { return mFighterMgr; } }
  249. public BaseBattle Battle { get { return mFighterMgr.Battle; } }
  250. public ActorData Actor { get; private set; }
  251. public FighterStateData StateData { get { return mStateData; } }
  252. public BaseSkill CurrentSkill { get { return mStateData.CurrentSkill; } }
  253. public FighterAi AI { get { return mAi; } }
  254. public BattleField CurrentBattleField { get; private set; }
  255. public long Id { get { return Actor.ID; } }
  256. public string Name { get { return Actor.Name; } }
  257. public eTeamType TeamSide { get; private set; }
  258. public bool IsTeamMember { get { return TeamSide == eTeamType.Friend; } }
  259. public Position_Type PositionType { get { return Actor.PositionRule; } }
  260. public int PositionValue { get { return Actor.PositionValue; } }
  261. public ProfessionType ProfType { get { return Actor.Profession; } }
  262. public int JobStage
  263. {
  264. get { return Actor.JobStage; }
  265. }
  266. public int JobBranch
  267. {
  268. get { return Actor.JobBranch; }
  269. }
  270. public int Level { get { return Actor.Level; } }
  271. public Fighter SelectTarget { get; set; }
  272. public Fighter HitTarget { get; set; }
  273. public float MoveSpeed { get; set; } //移动速度
  274. public int NatureId { get { return Actor.NatureId; } }
  275. public int Gender { get { return Actor.Gender; } }
  276. private int mBornEffectId = 0;
  277. public int BornEffectId
  278. {
  279. get { return mBornEffectId; }
  280. set { mBornEffectId = value; }
  281. }
  282. public Vector3 EulerAngle
  283. {
  284. get { return Ctrl != null ? Ctrl.transform.rotation.eulerAngles : Vector3.zero; }
  285. }
  286. public int NegativeBuffCnt
  287. {
  288. get
  289. {
  290. return mFuncMgr != null ? mFuncMgr.NegativeFunCnt : 0;
  291. }
  292. }
  293. private bool bIgnoreLife = false;
  294. public bool IgnoreLife
  295. {
  296. get { return bIgnoreLife; }
  297. set { bIgnoreLife = value; }
  298. }
  299. public int SeatId { get; set; }
  300. //当前携带的宠物ID
  301. private long mUsedPetId = 0;
  302. public long UsedPetId
  303. {
  304. get { return mUsedPetId; }
  305. set { mUsedPetId = value; }
  306. }
  307. //宠物主人ID
  308. private long mOwnerId = 0;
  309. public long OwnerId
  310. {
  311. get { return mOwnerId; }
  312. set { mOwnerId = value; }
  313. }
  314. public CastSkillData CastSkill
  315. {
  316. get
  317. {
  318. return mActorBattleAttr.castSkillData;
  319. }
  320. }
  321. public string IdleSound { get { return Actor.IdleSound; } }
  322. public string RunSound { get { return Actor.RunSound; } }
  323. public string DieSound { get { return Actor.DieSound; } }
  324. public string HitSound { get { return Actor.HitSound; } }
  325. public int RageCloneBossId
  326. {
  327. get;private set;
  328. }
  329. public Fighter RageCloneBoss
  330. {
  331. get; set;
  332. }
  333. public FighterStatistics Statistics
  334. {
  335. get
  336. {
  337. if (mStateData != null && mStateData.SkillStateData != null)
  338. {
  339. return mStateData.SkillStateData.Statistics;
  340. }
  341. return null;
  342. }
  343. }
  344. private List<TriggerBuffData> mTriggerBuffs;
  345. private int mTotalTakeDamage = 0;
  346. public int TotalTakeDamage
  347. {
  348. get { return mTotalTakeDamage; }
  349. }
  350. #endregion
  351. #region battle_attr
  352. public SLong MaxLife { get; set; }
  353. public SInt MaxSp { get; private set; }
  354. public SLong Life {
  355. get
  356. {
  357. return mStateData.Life;
  358. }
  359. set {
  360. mStateData.Life = System.Math.Min(value, MaxLife);
  361. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_Fighter_HP_Lower, this));
  362. }
  363. }
  364. public SFloat Sp {
  365. get
  366. {
  367. return mActorBattleAttr.sp;
  368. }
  369. set
  370. {
  371. mActorBattleAttr.sp = Mathf.Min(value, MaxSp);
  372. if (mActorBattleAttr.sp < 0)
  373. mActorBattleAttr.sp = 0;
  374. }
  375. }
  376. public SFloat DEX {
  377. get {
  378. return mActorBattleAttr.DEX;
  379. }
  380. }
  381. public SFloat STR
  382. {
  383. get
  384. {
  385. SFloat str = mActorBattleAttr.STR;
  386. //DebugHelper.LogWarning("************fighter:"+this.Name+" STR:" + str + " fixed value:"+ GetBuffFunctionValue(Buff_Function_Type.STR_Change_Value));
  387. return str;
  388. }
  389. }
  390. public SFloat INT
  391. {
  392. get
  393. {
  394. return mActorBattleAttr.INT;
  395. }
  396. }
  397. public SFloat AGI
  398. {
  399. get
  400. {
  401. return mActorBattleAttr.AGI;
  402. }
  403. }
  404. public SFloat LUK
  405. {
  406. get
  407. {
  408. return mActorBattleAttr.LUK;
  409. }
  410. }
  411. public SFloat VIT
  412. {
  413. get
  414. {
  415. return mActorBattleAttr.VIT;
  416. }
  417. }
  418. public SFloat GodPower
  419. {
  420. get { return mActorBattleAttr.GodPower; }
  421. }
  422. public SFloat Attack
  423. {
  424. get
  425. {
  426. SFloat attack = mActorBattleAttr.attack;
  427. if (IsNpc)
  428. {
  429. float detlaAttack = mActorBattleAttr.attack - mActorBattleAttr.minAttack;
  430. attack = mActorBattleAttr.minAttack + Battle.RandomValue(true) * detlaAttack;
  431. //attack = Battle.RandomValue(mActorBattleAttr.minAttack, mActorBattleAttr.attack, true);
  432. }
  433. SFloat AllBuffPercentValue = GetBuffPercentValue(Buff_Function_Type.Attack_Change_Percent);
  434. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.Attack_Change_ByTargetCostHpPercent);
  435. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.Attack_Change_BySourceCostHpPercent);
  436. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.Attack_Change_ByTargetCurHpPercent);
  437. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.Attack_Change_BySourceCurHpPercent);
  438. SFloat AllBuffFunctionValue = GetBuffFunctionValue(Buff_Function_Type.Attack_Change_Value);
  439. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.Attack_Change_ByTargetAttr);
  440. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.Attack_Change_BySourceAttr);
  441. attack = attack * Mathf.Max(1 + AllBuffPercentValue, 0.01f); //持续
  442. attack = Mathf.Max(attack + AllBuffFunctionValue, 1);
  443. //if(IsNpc)
  444. // Debug.Log($"---------attack = {attack}---------");
  445. return attack;
  446. }
  447. }
  448. public SFloat MagicAttack
  449. {
  450. get
  451. {
  452. SFloat magicAttack = mActorBattleAttr.magic_attack;
  453. if (IsNpc)
  454. {
  455. float detlaAttack = mActorBattleAttr.magic_attack - mActorBattleAttr.minMagicAttack;
  456. magicAttack = mActorBattleAttr.minAttack + Battle.RandomValue(true) * detlaAttack;
  457. //magicAttack = Battle.RandomValue(mActorBattleAttr.minMagicAttack, mActorBattleAttr.magic_attack, true);
  458. }
  459. SFloat AllBuffPercentValue = GetBuffPercentValue(Buff_Function_Type.MagicAttack_Change_Percent);
  460. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.MagicAttack_Change_ByTargetCostHpPercent);
  461. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.MagicAttack_Change_BySourceCostHpPercent);
  462. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.MagicAttack_Change_ByTargetCurHpPercent);
  463. AllBuffPercentValue += GetBuffPercentValue(Buff_Function_Type.MagicAttack_Change_BySourceCurHpPercent);
  464. SFloat AllBuffFunctionValue = GetBuffFunctionValue(Buff_Function_Type.MagicAttack_Change_Value);
  465. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.MagicAttack_Change_ByTargetAttr);
  466. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.MagicAttack_Change_BySourceAttr);
  467. magicAttack = magicAttack * Mathf.Max(1 + AllBuffPercentValue, 0.01f);
  468. magicAttack = Mathf.Max(magicAttack + AllBuffFunctionValue, 1);
  469. return magicAttack;
  470. }
  471. }
  472. public SFloat Defense
  473. {
  474. get
  475. {
  476. SFloat AllBuffPercentValue = GetBuffPercentValue(Buff_Function_Type.Phyx_Defense_Change_Percent);
  477. SFloat AllBuffFunctionValue = GetBuffFunctionValue(Buff_Function_Type.Phyx_Defense_Change_Value);
  478. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.AttackDefense_Change_ByTargetAttr);
  479. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.AttackDefense_Change_BySourceAttr);
  480. SFloat def = mActorBattleAttr.defense * Mathf.Max(1 + AllBuffPercentValue, 0.01f) + AllBuffFunctionValue;
  481. return Mathf.Max(def, 0.01f);
  482. }
  483. }
  484. public SFloat MagicDefense
  485. {
  486. get
  487. {
  488. SFloat AllBuffPercentValue = GetBuffPercentValue(Buff_Function_Type.Magic_Defense_Change_Percent);
  489. SFloat AllBuffFunctionValue = GetBuffFunctionValue(Buff_Function_Type.Magic_Defense_Change_Value);
  490. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.MagicDefense_Change_ByTargetAttr);
  491. AllBuffFunctionValue += GetBuffFunctionValue(Buff_Function_Type.MagicDefense_Change_BySourceAttr);
  492. SFloat def = mActorBattleAttr.magic_defense * Mathf.Max(1 + AllBuffPercentValue, 0.01f) + AllBuffFunctionValue;
  493. return Mathf.Max(def, 0.01f);
  494. }
  495. }
  496. public SFloat DefPercent { get { return mActorBattleAttr.defPercent; } }
  497. public SFloat MagicDefPercent { get { return mActorBattleAttr.magicDefPercent; } }
  498. public SFloat IgnoreDefense
  499. {
  500. get
  501. {
  502. return mActorBattleAttr.penetration + GetBuffFunctionValue(Buff_Function_Type.IgnorePhysicDefense_Change_Value);
  503. }
  504. }
  505. public SFloat IgnoreMagicDefense
  506. {
  507. get
  508. {
  509. return mActorBattleAttr.magic_penetration + GetBuffFunctionValue(Buff_Function_Type.IgnoreMagicDefense_Change_Value);
  510. }
  511. }
  512. public SFloat Crit
  513. {
  514. get
  515. {
  516. SFloat crit = mActorBattleAttr.crit * (1 + GetBuffPercentValue(Buff_Function_Type.Crit_Change_Percent)) + GetBuffFunctionValue(Buff_Function_Type.Crit_Change_Value);
  517. return crit;
  518. }
  519. }
  520. public SFloat CritDamagePercent
  521. {
  522. get
  523. {
  524. return mActorBattleAttr.critDamagePercent + GetBuffFunctionValue(Buff_Function_Type.CritDamagePercent_Change_Value);
  525. }
  526. }
  527. public SFloat PhysicDamagePercent
  528. {
  529. get
  530. {
  531. return mActorBattleAttr.physicDamagePercent + GetBuffFunctionValue(Buff_Function_Type.PhysicDamagePercent_Change_Value);
  532. }
  533. }
  534. public SFloat MagicDamagePercent
  535. {
  536. get
  537. {
  538. return mActorBattleAttr.magicDamagePercent + GetBuffFunctionValue(Buff_Function_Type.MagicDamagePercent_Change_Value);
  539. }
  540. }
  541. public SFloat AntiPhysicDamPercent
  542. {
  543. get
  544. {
  545. return mActorBattleAttr.antiPhysicDamPercent + GetBuffFunctionValue(Buff_Function_Type.AntiPhysicDamagePercent_Change_Value);
  546. }
  547. }
  548. public SFloat AntiMagicDamPercent
  549. {
  550. get
  551. {
  552. return mActorBattleAttr.antiMagicDamPercent + GetBuffFunctionValue(Buff_Function_Type.AntiMagicDamagePercent_Change_Value);
  553. }
  554. }
  555. public SFloat PhysicDamageReflectPercent
  556. {
  557. get
  558. {
  559. return mActorBattleAttr.physicDamageReflectPercent + GetBuffFunctionValue(Buff_Function_Type.PhysicDamageReflectPercent_Change_Value);
  560. }
  561. }
  562. public SFloat MagicDamageReflectPercent
  563. {
  564. get
  565. {
  566. return mActorBattleAttr.magicDamageReflectPercent + GetBuffFunctionValue(Buff_Function_Type.MagicDamageReflectPercent_Change_Value);
  567. }
  568. }
  569. public SFloat FixedSingTimePercent { get { return mActorBattleAttr.fixedSingTimePercent; } }
  570. public SFloat VariableSingTimePercent { get { return mActorBattleAttr.variableSingTimePercent; } }
  571. public SFloat Hit
  572. {
  573. get
  574. {
  575. return mActorBattleAttr.hit * (1 + GetBuffPercentValue(Buff_Function_Type.Hit_Change_Percent)) + GetBuffFunctionValue(Buff_Function_Type.Hit_Change_Value);
  576. }
  577. }
  578. public SFloat Dodge
  579. {
  580. get
  581. {
  582. return mActorBattleAttr.dodge * (1 + GetBuffPercentValue(Buff_Function_Type.Dodge_Change_Percent)) + GetBuffFunctionValue(Buff_Function_Type.Dodge_Change_Value);
  583. }
  584. }
  585. //韧性
  586. public SFloat Ten
  587. {
  588. get
  589. {
  590. return mActorBattleAttr.ten * (1 + GetBuffPercentValue(Buff_Function_Type.Ten_Change_Percent)) + GetBuffFunctionValue(Buff_Function_Type.Ten_Change_Value);
  591. }
  592. }
  593. public SFloat PerfectDodgeRate
  594. {
  595. get
  596. {
  597. SFloat a = BattleFormulaParamMgr.Instance.GetParam(15);
  598. SFloat ratio = Mathf.Floor(LUK * a + 1) * 0.01f;
  599. return ratio;
  600. }
  601. }
  602. public SFloat AttackCD
  603. {
  604. get
  605. {
  606. SFloat a = BattleFormulaParamMgr.Instance.GetParam(26);
  607. SFloat b = BattleFormulaParamMgr.Instance.GetParam(27);
  608. SFloat attackCd = mActorBattleAttr.attackSpeed * (1 + GetBuffPercentValue(Buff_Function_Type.AttackCD_Change_Percent)) + GetBuffFunctionValue(Buff_Function_Type.AttackCD_Change_Value);
  609. attackCd = (Mathf.Max(a - attackCd, 0)) * b;
  610. return attackCd;
  611. }
  612. }
  613. public SFloat FixedSingDecreasePercent { get { return 0; } }
  614. public SFloat VariableSingDecreasePercent { get { return 0; } }
  615. //属性提升攻速百分比
  616. public SFloat AttrAttackSpeedPercent
  617. {
  618. get
  619. {
  620. SFloat a = BattleFormulaParamMgr.Instance.GetParam(29);
  621. SFloat b = BattleFormulaParamMgr.Instance.GetParam(30);
  622. SFloat attackSpeedPercent = (AGI * a + DEX * b) * 0.01f;
  623. return attackSpeedPercent;
  624. }
  625. }
  626. //技能提升攻速百分比
  627. public SFloat SkillAttackSpeedPercent
  628. {
  629. get
  630. {
  631. return GetBuffPercentValue(Buff_Function_Type.AttackSpeed_Change_Percent);
  632. }
  633. }
  634. #endregion
  635. private bool bAIEnabled = true;
  636. public bool IsAiEnabled
  637. {
  638. get { return bAIEnabled; }
  639. set { bAIEnabled = value; }
  640. }
  641. #region
  642. public Fighter SummonOwner { get; private set; }
  643. public BaseSkill[] Skills { get { return Actor.SkillMgr.Skills; } }
  644. public BaseSkill[] NormalSkills { get { return Actor.SkillMgr.NormalSkills; } }
  645. public List<BaseSkill> RandomSkills { get { return Actor.SkillMgr.RandomSkills; } }
  646. public List<BaseSkill> PassiveSkills { get{ return Actor.SkillMgr.PassiveSkills; } }
  647. public int SkillCnt { get { return Actor.SkillMgr.SkillCnt; } }
  648. public GameObject Go { get; private set; }
  649. public FighterGoCtrl Ctrl { get { return mCtrl; } }
  650. public PassiveMove PassiveMove { get { return mPassiveMove; } }
  651. public FighterBuffManager BuffMgr
  652. {
  653. get
  654. {
  655. if (mBuffMgr == null)
  656. mBuffMgr = mStateData.BuffMgr;
  657. return mBuffMgr;
  658. }
  659. }
  660. public FighterBuffFunctionMgr FuncMgr
  661. {
  662. get
  663. {
  664. if (mFuncMgr == null)
  665. mFuncMgr = mStateData.FuncMgr;
  666. return mFuncMgr;
  667. }
  668. }
  669. public PlayerActorBattleAttr ActorBattleAttr { get { return mActorBattleAttr; } }
  670. public float DyingTime { get { return CurrentStateId == FighterStateType.Die ? mStateData.DyingTime : 0; } }
  671. public float TimeFromLastHit { get { return mStateData.TimeFromLastBeHit; } }
  672. public bool IsSummoned { get { return SummonOwner != null; } }
  673. public bool IsSpawned { get; private set; }
  674. public bool IsDisposed { get; private set; }
  675. public bool IsDestroy { get; private set; }
  676. public bool IsFront { get { return Actor.PositionRule == Position_Type.Position_Front; } }
  677. public bool IsMiddle { get { return Actor.PositionRule == Position_Type.Position_Middle; } }
  678. public bool IsBack { get { return Actor.PositionRule == Position_Type.Position_Back; } }
  679. public bool IsAlive { get { return mStateData.IsAlive; } }
  680. public bool AIEnable {
  681. get { return mAi != null && mAi.Enabled; }
  682. set {
  683. if (AIEnable != value) {
  684. if (value) {
  685. if (mAi == null)
  686. mAi = new FighterAi(this);
  687. mAi.Enabled = true;
  688. } else {
  689. if (mAi != null)
  690. mAi.Enabled = false;
  691. }
  692. }
  693. }
  694. }
  695. public float FloorY { get { return CurrentBattleField != null ? CurrentBattleField.FloorY : Position.y; } }
  696. public bool IsFighting { get; private set; }
  697. public bool IsVisible {
  698. get { return Ctrl != null && Ctrl.IsVisible; }
  699. set {
  700. if (Ctrl != null)
  701. Ctrl.IsVisible = value;
  702. }
  703. }
  704. public bool IsUndead { get { return mStateData.IsUnead; } set { mStateData.IsUnead = value; } }
  705. public bool IsIdle { get { return CurrentStateId == FighterStateType.Idle; } }
  706. public bool IsComing { get { return CurrentStateId == FighterStateType.Coming; } }
  707. public bool IsNavRun { get { return CurrentStateId == FighterStateType.NavRun; } }
  708. public bool IsRun { get { return CurrentStateId == FighterStateType.Run; } }
  709. public bool IsBoss { get { return Actor != null && Actor.IsBoss; } }
  710. public bool IsNpc { get { return Actor.IsNpc; } }
  711. public bool IsHero { get { return Actor.IsHero; } }
  712. public bool IsPetHero { get { return null != Actor as PetBossActorData; } }
  713. public bool IsFellow { get { return Actor.IsFellow; } }
  714. public bool IsSword { get { return Actor.Profession == ProfessionType.Pro_Type_Sword; } }
  715. public bool IsMagic { get { return Actor.Profession == ProfessionType.Pro_Type_Magic; } }
  716. public bool IsPriest { get { return Actor.Profession == ProfessionType.Pro_Type_Priest; } }
  717. public bool IsHunter { get { return Actor.Profession == ProfessionType.Pro_Type_Hunter; } }
  718. public bool IsThief { get { return Actor.Profession == ProfessionType.Pro_Type_Thief; } }
  719. public bool IsGround { get { return mStateData.IsGround; } }
  720. public float ModelSize { get { return Actor.AvatarData.modelSize; } }
  721. public bool IsMainRole { get { return Actor.IsMainRole; } }
  722. public bool IsPlayer { get { return IsHero || IsFellow; } }
  723. public bool IsPet { get { return Actor.IsPet; } }
  724. private bool bIsCloned = false;
  725. public bool IsCloned
  726. {
  727. get { return bIsCloned; }
  728. set { bIsCloned = value; }
  729. }
  730. public bool InSkillSinged
  731. {
  732. get { return mStateData != null && mStateData.IsSing; }
  733. }
  734. public bool IsTargetable {
  735. get {
  736. if (!IsSpawned || IsDisposed)
  737. return false;
  738. if (IsAlive)
  739. return true;
  740. if (DyingTime > 2)
  741. return false;
  742. return true;
  743. }
  744. }
  745. public FighterStateType CurrentStateId { get { return mStateData.StateId; } }
  746. private Vector3 mDestPosition = Vector3.zero;
  747. public Vector3 DestPosition { get { return mDestPosition; } }
  748. private float mSpeedRatio = 1;
  749. public float SpeedRatio {
  750. get { return mSpeedRatio; }
  751. set { mSpeedRatio = value; }
  752. }
  753. private float mNormalAttackCdRatio = 1.0f;
  754. public float NormalAttackCdRatio { get { return mNormalAttackCdRatio; } }
  755. private int mReadyPosOrder = 1;
  756. public int ReadyPosOrder
  757. {
  758. get { return mReadyPosOrder; }
  759. set { mReadyPosOrder = value; }
  760. }
  761. //记录传送之前的位置
  762. private Vector3 mPreTransferPos = Vector3.zero;
  763. public Vector3 PreTransferPos
  764. {
  765. get { return mPreTransferPos; }
  766. set { mPreTransferPos = value; }
  767. }
  768. public float ComingTime
  769. {
  770. get;private set;
  771. }
  772. #endregion //property
  773. #region public_methods
  774. public void ForceIdle()
  775. {
  776. mStateData.ChangeState(FighterStateType.Idle);
  777. }
  778. public void ForceComing(float comingTime)
  779. {
  780. ComingTime = comingTime;
  781. mStateData.ChangeState(FighterStateType.Coming);
  782. }
  783. public void ForceGround()
  784. {
  785. if (CurrentBattleField != null)
  786. SetPosition(Position.SetY(CurrentBattleField.FloorY));
  787. }
  788. public void ForceBreak()
  789. {
  790. if (!IsAlive) return;
  791. mStateData.ChangeState(FighterStateType.Break);
  792. ShowSkillBreak();
  793. }
  794. public bool AutoChaseTo(Fighter target,float stopDist)
  795. {
  796. if (target == null) return false;
  797. if (!Battle.IsPlayRecord && Battle.Recorder != null)
  798. {
  799. Battle.Recorder.RecordFighterMove(this, target, stopDist);
  800. }
  801. return ChaseTo(target, stopDist);
  802. }
  803. public bool ChaseTo(Fighter target,float stopDist)
  804. {
  805. return mStateData.ProcessTrigger(FighterStateTriggerType.Run, new FighterStateRunParam(target,target.Position, stopDist));
  806. }
  807. public bool AutoMoveTo(Vector3 pos,bool force=false)
  808. {
  809. mDestPosition = pos;
  810. if (Ctrl != null)
  811. {
  812. Ctrl.SetStopDistance(0);
  813. }
  814. if (mStateData.StateId == FighterStateType.NavRun) {
  815. mStateData.State.OnDataChanged();
  816. RunToWithNav(mDestPosition);
  817. return true;
  818. }
  819. if(!force)
  820. {
  821. return mStateData.ProcessTrigger(FighterStateTriggerType.NavRun, new FighterStateRunParam(null, pos, 0));
  822. }
  823. else
  824. {
  825. mStateData.ChangeState(FighterStateType.NavRun, new FighterStateRunParam(null, pos, 0));
  826. return true;
  827. }
  828. }
  829. public void RunToWithNav(Vector3 pos)
  830. {
  831. LookAt(pos);
  832. if (Ctrl != null)
  833. {
  834. Ctrl.RunToWithNav(pos);
  835. }
  836. }
  837. public void OnEnterField(BattleField field)
  838. {
  839. CurrentBattleField = field;
  840. SyncActorData();
  841. }
  842. public void OnLeaveField(BattleField field)
  843. {
  844. if (CurrentBattleField != field)
  845. return;
  846. OnFightingEnd();
  847. mStateData.Clear();
  848. AIEnable = false;
  849. IsFighting = false;
  850. mTotalTakeDamage = 0;
  851. if (IsAlive && !IsDisposed)
  852. ForceIdle();
  853. CurrentBattleField = null;
  854. mRecordJson = null;
  855. }
  856. //开始战斗
  857. public void OnFightingStart()
  858. {
  859. if (!IsAlive || IsDisposed)
  860. {
  861. DebugHelper.LogError(this.Name);
  862. return;
  863. }
  864. ForceIdle();
  865. AIEnable = bAIEnabled;
  866. IsFighting = true;
  867. mTotalTakeDamage = 0;
  868. if (!Battle.IsPlayRecord && Battle.Recorder != null)
  869. Battle.Recorder.RecordFighterStartFighting(this);
  870. //if(mBloodBarHud!=null)
  871. // mBloodBarHud.Fight();
  872. if (mHpBarHud != null)
  873. mHpBarHud.Fight();
  874. if (mSkillNameHud != null)
  875. mSkillNameHud.Fight();
  876. if (mRageEffectHud != null)
  877. {
  878. mRageEffectHud.Fight();
  879. }
  880. if(mStateData.SkillStateData != null)
  881. {
  882. mStateData.SkillStateData.OnFightingStart();
  883. }
  884. if (Ctrl != null)
  885. Ctrl.EnableNavAgent(false);
  886. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_FIGHTER_ENTERCOMBAT, this));
  887. RefreshLife();
  888. RefreshSp();
  889. }
  890. public void CheckPassiveSkill()
  891. {
  892. if (!Battle.IsPlayRecord)
  893. {
  894. if (PassiveSkills != null)
  895. {
  896. for (int i = 0; i < PassiveSkills.Count; i++)
  897. {
  898. BaseSkill passiveSkill = PassiveSkills[i];
  899. if (passiveSkill != null)
  900. {
  901. if (passiveSkill.BuffList != null)
  902. {
  903. for (int idx = 0; idx < passiveSkill.BuffList.Count; idx++)
  904. {
  905. CastBuff(passiveSkill, passiveSkill.BuffList[idx]);
  906. }
  907. }
  908. if (Battle.Recorder != null)
  909. {
  910. Battle.Recorder.RecordFighterPassiveSkill(this, passiveSkill.Id);
  911. }
  912. }
  913. }
  914. }
  915. }
  916. else
  917. {
  918. Battle.Recorder.ProcessFrameRecord(BattleRecorder.RecordType.FighterPassiveSkill, this);
  919. }
  920. }
  921. public void DoPassiveSkill(int skillId)
  922. {
  923. BaseSkill passiveSkill = GetPassiveSkill(skillId);
  924. if(passiveSkill != null)
  925. {
  926. if (passiveSkill.BuffList != null)
  927. {
  928. for (int idx = 0; idx < passiveSkill.BuffList.Count; idx++)
  929. {
  930. CastBuff(passiveSkill, passiveSkill.BuffList[idx]);
  931. }
  932. }
  933. }
  934. if (BattleMgr.Instance.Battle.CanPrintLog)
  935. DebugHelper.LogError("------fighter:" + this.Id + " PassiveSkill: " + skillId);
  936. }
  937. public BaseSkill GetPassiveSkill(int skillId)
  938. {
  939. if (PassiveSkills == null) return null;
  940. for (int idx = 0; idx < PassiveSkills.Count; idx++)
  941. {
  942. if (PassiveSkills[idx].Id == skillId)
  943. return PassiveSkills[idx];
  944. }
  945. return null;
  946. }
  947. //战斗结束
  948. public void OnFightingEnd()
  949. {
  950. if (IsDisposed)
  951. return;
  952. if(StateData.IsRageStatus)
  953. {
  954. SetRageStatus(false);
  955. }
  956. mTotalTakeDamage = 0;
  957. AIEnable = false;
  958. IsFighting = false;
  959. //mBloodBarHud.Deactive();
  960. if (mHpBarHud != null)
  961. mHpBarHud.Deactive();
  962. if (mSkillNameHud != null)
  963. mSkillNameHud.Deactive();
  964. if (mRageEffectHud != null)
  965. {
  966. mRageEffectHud.Deactive();
  967. }
  968. if (AI!=null)
  969. AI.Reset();
  970. if (BuffMgr != null)
  971. BuffMgr.OnFightingEnd();
  972. if(FuncMgr!=null)
  973. {
  974. FuncMgr.OnFightingEnd();
  975. }
  976. if (Ctrl != null)
  977. Ctrl.EnableNavAgent(true);
  978. }
  979. //进入狂暴状态
  980. public void OnEnterRage()
  981. {
  982. if (!IsAlive) return;
  983. BuffData buffData = BattlePrepareManager.Instance.PopBuffData(Actor.RageId);
  984. CastBuff(null,buffData);
  985. }
  986. public SFloat GetAttrByType(int attrType)
  987. {
  988. switch(attrType)
  989. {
  990. case ActorData.Attr_Life:
  991. return Life;
  992. case ActorData.Attr_Sp:
  993. return Sp;
  994. case ActorData.Attr_Attack:
  995. return Attack;
  996. case ActorData.Attr_MagicAttack:
  997. return MagicAttack;
  998. case ActorData.Attr_Defense:
  999. return Defense;
  1000. case ActorData.Attr_MagicDefense:
  1001. return MagicDefense;
  1002. case ActorData.Attr_AttackSpeed:
  1003. return AttackCD;
  1004. case ActorData.Attr_Hit:
  1005. return Hit;
  1006. case ActorData.Attr_Dodge:
  1007. return Dodge;
  1008. case ActorData.Attr_Crit:
  1009. return Crit;
  1010. case ActorData.Attr_Ten:
  1011. return Ten;
  1012. case ActorData.Attr_STR:
  1013. return STR;
  1014. case ActorData.Attr_AGI:
  1015. return AGI;
  1016. case ActorData.Attr_INT:
  1017. return INT;
  1018. case ActorData.Attr_VIT:
  1019. return VIT;
  1020. case ActorData.Attr_DEX:
  1021. return DEX;
  1022. case ActorData.Attr_LUK:
  1023. return LUK;
  1024. case ActorData.Attr_MaxHp:
  1025. return MaxLife;
  1026. case ActorData.Attr_MaxSp:
  1027. return MaxSp;
  1028. case ActorData.Attr_GodPow:
  1029. return GodPower;
  1030. }
  1031. return 0;
  1032. }
  1033. //多项属性和
  1034. public SFloat GetAttrByType(int[] attrTypes)
  1035. {
  1036. if(null == attrTypes)
  1037. return 0;
  1038. SFloat value = 0;
  1039. for(int i=0;i<attrTypes.Length;i++)
  1040. {
  1041. value += GetAttrByType(attrTypes[i]);
  1042. }
  1043. return value;
  1044. }
  1045. public bool HaveBuffFunction(Buff_Function_Type buff_function)
  1046. {
  1047. if (IsDisposed)
  1048. return false;
  1049. return FuncMgr.HaveBuffFunction(buff_function);
  1050. }
  1051. public bool IsSuckDamage(Damage_Type DmgType, out SFloat SuckPrecent, out int nMaxSuck)
  1052. {
  1053. bool IsSuckDamage = false;
  1054. SuckPrecent = 0;
  1055. nMaxSuck = 0;
  1056. if (DmgType == Damage_Type.Attack_Type_Magic)
  1057. {
  1058. IsSuckDamage = FuncMgr.GetSuckDamage(Buff_Function_Type.Hurt_MagicAttack_SuckDamage, out SuckPrecent, out nMaxSuck);
  1059. }
  1060. else if(DmgType == Damage_Type.Attack_Type_Physic)
  1061. {
  1062. IsSuckDamage = FuncMgr.GetSuckDamage(Buff_Function_Type.Hurt_Attack_SuckDamage, out SuckPrecent, out nMaxSuck);
  1063. }
  1064. return IsSuckDamage;
  1065. }
  1066. public bool HaveBuffType(int typeid)
  1067. {
  1068. if (IsDisposed)
  1069. return false;
  1070. return FuncMgr.HaveBuffType((BattleBuffType)typeid);
  1071. }
  1072. public void RemoveFunctionByFunType(Buff_Function_Type funType)
  1073. {
  1074. if (IsDisposed)
  1075. return;
  1076. FuncMgr.RemoveFunctionByFunType(funType);
  1077. }
  1078. public SFloat GetBuffFunctionValue(Buff_Function_Type buff_function)
  1079. {
  1080. if (IsDisposed)
  1081. return 0;
  1082. return FuncMgr.GetBuffValue(buff_function) + GetMarkFunVal(buff_function);
  1083. }
  1084. public SFloat GetBuffPercentValue(Buff_Function_Type buff_function)
  1085. {
  1086. if (IsDisposed)
  1087. return 0;
  1088. return FuncMgr.GetBuffValue(buff_function) * 0.01f + GetMarkFunPercent(buff_function);
  1089. }
  1090. public SFloat GetMarkFunVal(Buff_Function_Type type)
  1091. {
  1092. if (IsDisposed)
  1093. return 0;
  1094. return mStateData.MMarkMgr.GetFunValue(type);
  1095. }
  1096. public SFloat GetMarkFunPercent(Buff_Function_Type type)
  1097. {
  1098. if (IsDisposed)
  1099. return 0;
  1100. return mStateData.MMarkMgr.GetFunPercent(type);
  1101. }
  1102. public void Dispose()
  1103. {
  1104. if (IsDisposed)
  1105. return;
  1106. ClearSkillBuffPoints();
  1107. ClearTriggerBuff();
  1108. SeatId = 0;
  1109. mNormalAttackCdRatio = 1.0f;
  1110. IsDisposed = true;
  1111. IsVisible = false;
  1112. IsSpawned = false;
  1113. mUsedPetId = 0;
  1114. mOwnerId = 0;
  1115. bIsCloned = false;
  1116. if (CurrentBattleField != null)
  1117. CurrentBattleField.RemoveFighter(this);
  1118. //mBloodBarHud.Dispose();
  1119. if (mHpBarHud != null)
  1120. mHpBarHud.Dispose();
  1121. if (mSkillNameHud != null)
  1122. mSkillNameHud.Dispose();
  1123. if (mRageEffectHud != null)
  1124. {
  1125. mRageEffectHud.Dispose();
  1126. }
  1127. mStateData.Clear();
  1128. if (Ctrl != null)
  1129. Ctrl.OnDisposed();
  1130. CurrentBattleField = null;
  1131. SelectTarget = null;
  1132. HitTarget = null;
  1133. }
  1134. public void Destroy()
  1135. {
  1136. if (IsDestroy)
  1137. return;
  1138. ClearSkillBuffPoints();
  1139. ClearTriggerBuff();
  1140. SeatId = 0;
  1141. IsDisposed = true;
  1142. IsDestroy = true;
  1143. IsVisible = false;
  1144. IsSpawned = false;
  1145. bIsCloned = false;
  1146. mUsedPetId = 0;
  1147. mOwnerId = 0;
  1148. mAi = null;
  1149. mPassiveMove = null;
  1150. SelectTarget = null;
  1151. HitTarget = null;
  1152. if(mHpBarHud!=null)
  1153. {
  1154. mHpBarHud.Destroy();
  1155. mHpBarHud = null;
  1156. }
  1157. if (mSkillNameHud != null)
  1158. {
  1159. mSkillNameHud.Destroy();
  1160. mSkillNameHud = null;
  1161. }
  1162. if (mRageEffectHud != null)
  1163. {
  1164. mRageEffectHud.Destroy();
  1165. mRageEffectHud = null;
  1166. }
  1167. if (CurrentBattleField != null)
  1168. CurrentBattleField.RemoveFighter(this);
  1169. CurrentBattleField = null;
  1170. mStateData.Dispose();
  1171. FighterState.UnregistCacheFighterState(this);
  1172. if (Ctrl != null) {
  1173. Ctrl.Destroy();
  1174. mCtrl = null;
  1175. }
  1176. if(null != Go)
  1177. Go.Destroy();
  1178. Go = null;
  1179. }
  1180. //自动跑到战斗位置
  1181. public bool AutoRunToFieldFightPosition(Vector3 diff)
  1182. {
  1183. if (CurrentBattleField == null)
  1184. return false;
  1185. if (!IsIdle)
  1186. return false;
  1187. if (IsFighting && !CanMove())
  1188. return false;
  1189. return false;
  1190. }
  1191. public bool CanMove()
  1192. {
  1193. if (HaveBuffFunction(Buff_Function_Type.Frozen) || HaveBuffFunction(Buff_Function_Type.Stiff))
  1194. return false;
  1195. return true;
  1196. }
  1197. public BattleBuff CastBuff(BaseSkill skill,int buffId)
  1198. {
  1199. return CastBuff(skill, buffId, skill!=null?skill.Level:1);
  1200. }
  1201. public BattleBuff CastBuff(BaseSkill skill, BuffData buffData)
  1202. {
  1203. if (CurrentBattleField == null) return null; //不在战场的人释放buff是不合理的
  1204. if (buffData == null) return null;
  1205. return BuffMgr.AddBuff(skill, buffData);
  1206. }
  1207. public BattleBuff CastBuff(BaseSkill skill, int buffId,int skillLv)
  1208. {
  1209. if (CurrentBattleField == null) return null; //不在战场的人释放buff是不合理的
  1210. BuffData buffData = BattlePrepareManager.Instance.PopBuffData(buffId);
  1211. if (buffData == null)
  1212. {
  1213. DebugHelper.LogError("buffId:" + buffId + " 配置不存在");
  1214. return null;
  1215. }
  1216. buffData.SetLevel(skillLv);
  1217. return CastBuff(skill, buffData);
  1218. }
  1219. public BaseSkill GetSkill(int seqId)
  1220. {
  1221. if(IsPet || IsPetHero)
  1222. {
  1223. return Actor.SkillMgr.GetRandomSkill(seqId);
  1224. }
  1225. else
  1226. {
  1227. return Actor.SkillMgr.GetSkill(seqId);
  1228. }
  1229. }
  1230. public BaseSkill GetSkill(int seqId, int skillId)
  1231. {
  1232. if(IsPet || IsPetHero)
  1233. {
  1234. return Actor.SkillMgr.GetRandomSkillById(seqId,skillId);
  1235. }
  1236. else
  1237. {
  1238. return Actor.SkillMgr.GetSkill(seqId, skillId);
  1239. }
  1240. }
  1241. public void FixedUpdate(float deltaTime)
  1242. {
  1243. if (!IsSpawned || IsDisposed || Actor.IsDisposed)
  1244. return;
  1245. if (CurrentBattleField == null)
  1246. return;
  1247. if (!IsFighting && CurrentBattleField.IsFightingState)
  1248. {
  1249. OnFightingStart();
  1250. }
  1251. mStateData.Update(deltaTime, CurrentBattleField.IsFightingState);
  1252. if(mPassiveMove!=null)
  1253. mPassiveMove.Update(deltaTime);
  1254. //if (mBloodBarHud!=null)
  1255. // mBloodBarHud.LateUpdate(deltaTime);
  1256. if (mHpBarHud != null)
  1257. mHpBarHud.LateUpdate(deltaTime);
  1258. if (mSkillNameHud != null)
  1259. mSkillNameHud.LateUpdate(deltaTime);
  1260. if (mRageEffectHud != null)
  1261. {
  1262. mRageEffectHud.LateUpdate();
  1263. }
  1264. }
  1265. public void Spawn(Vector3 position, Vector3 forward, Quaternion rot, bool enterBattleField = true)
  1266. {
  1267. if (IsSpawned) {
  1268. SetPosition(position);
  1269. LookForward(forward);
  1270. ForceSync(Ctrl.transform);
  1271. return;
  1272. }
  1273. if (Ctrl != null && !Ctrl.IsLoaded)
  1274. {
  1275. Ctrl.Load();
  1276. }
  1277. IsSpawned = true;
  1278. IsDisposed = false;
  1279. //if(mBloodBarHud!=null)
  1280. // mBloodBarHud.Prepare();
  1281. if (mHpBarHud != null)
  1282. mHpBarHud.Prepare();
  1283. if (mSkillNameHud != null)
  1284. mSkillNameHud.Prepare();
  1285. if (mRageEffectHud != null)
  1286. {
  1287. mRageEffectHud.Prepare();
  1288. }
  1289. FighterMgr.OnFighterSpawned(this);
  1290. SetPosition(position);
  1291. LookForward(forward);
  1292. if (Ctrl != null)
  1293. {
  1294. Ctrl.OnSpawned();
  1295. }
  1296. if (enterBattleField && Battle != null && Battle.CurBattleField != null)
  1297. Battle.CurBattleField.AddFighter(this);
  1298. ForceSync(Ctrl.transform);
  1299. InitFighterBattleAttr();
  1300. ForceIdle();
  1301. SetRotation(rot);
  1302. if (!Battle.IsPlayRecord && Battle.Recorder != null)
  1303. Battle.Recorder.RecordFighterSpawn(this);
  1304. }
  1305. public override void SetPosition(Vector3 position)
  1306. {
  1307. float floorY = 0.1f;
  1308. if (CurrentBattleField != null)
  1309. {
  1310. if (position.y < CurrentBattleField.FloorY)
  1311. position.y = CurrentBattleField.FloorY;
  1312. floorY = CurrentBattleField.FloorY;
  1313. }
  1314. else//没有战斗的情况
  1315. {
  1316. floorY = position.y;
  1317. }
  1318. Position = position;
  1319. mStateData.IsGround = position.y.FEqual(floorY,0.5f);
  1320. }
  1321. public void SyncPosition(Vector3 position)
  1322. {
  1323. SetPosition(position);
  1324. if (Ctrl != null) {
  1325. ForceSync(Ctrl.transform);
  1326. Ctrl.SetShadowVisible(mStateData.IsGround);
  1327. }
  1328. }
  1329. public override void SetRotation(Quaternion rot)
  1330. {
  1331. base.SetRotation(rot);
  1332. if (Ctrl != null)
  1333. Ctrl.OnRotationChanged(rot);
  1334. }
  1335. public override void LookForward(Vector3 forward, Vector3 up = default(Vector3))
  1336. {
  1337. base.LookForward(forward, up);
  1338. if (Ctrl != null)
  1339. Ctrl.OnForwardChanged();
  1340. }
  1341. public void OnGoDestroy()
  1342. {
  1343. Go = null;
  1344. mCtrl = null;
  1345. }
  1346. public void OnKillEnemy(Fighter fighter)
  1347. {
  1348. if (fighter != null && fighter.TeamSide != TeamSide)
  1349. AddRage(0);
  1350. }
  1351. public void ProcessSelfKill()
  1352. {
  1353. BuffMgr.Clear();
  1354. IsUndead = false;
  1355. Life = 0;
  1356. }
  1357. public bool DoBeHit(int hitMoveType,Fix64 initSpeed, Fix64 acceleration, FixVector3 movePos, Fix64 stiffTime)
  1358. {
  1359. return mStateData.ProcessTrigger(FighterStateTriggerType.BeHit, new FighterStateBeHitParam(hitMoveType, initSpeed, acceleration,movePos,stiffTime), hitMoveType);
  1360. }
  1361. public bool CanDoTriggerAction(FighterStateTriggerType triggerType)
  1362. {
  1363. return mStateData.State != null && mStateData.State.GetTriggerNextState(triggerType) != FighterStateType.None;
  1364. }
  1365. public void ResetNormalSkillCd()
  1366. {
  1367. mStateData.SkillStateData.ResetNormalAttackCd();
  1368. }
  1369. public bool CheckDoSkill(int skillType, out BaseSkill skill)
  1370. {
  1371. return CanDoSkill(skillType, out skill) && mStateData.ProcessTrigger(FighterStateTriggerType.Attack, new FighterStateAttackParam(skillType,skill), skillType);
  1372. }
  1373. public bool ForceDoSkill(int skillType, int skillId)
  1374. {
  1375. BaseSkill skill = GetSkill(skillType, skillId);
  1376. if (skill == null) return false;
  1377. //if (BattleMgr.Instance.Battle.IsPlayRecord)
  1378. // DebugHelper.LogError(string.Format("<color=#0000ff>{0} castskill= {1} skillType={2}, stateFrame={3}, state={4}</color>", this.Name, skillId, skillType, CurrentBattleField.CurrentStateFrame, mStateData.StateId));
  1379. return mStateData.ProcessTrigger(FighterStateTriggerType.Attack, new FighterStateAttackParam(skillType, skill), skillType);
  1380. }
  1381. public void Relive(float lifePercent)
  1382. {
  1383. ResetLife();
  1384. if (Ctrl != null)
  1385. Ctrl.OnRelive();
  1386. if (CurrentBattleField != null)
  1387. CurrentBattleField.OnFighterRelive(this);
  1388. FighterMgr.OnFighterRelive(this);
  1389. }
  1390. public void ResetLife()
  1391. {
  1392. Life = (long)MaxLife;
  1393. Sp = Mathf.RoundToInt(MaxSp);
  1394. //mBloodBarHud.OnActorRevive();
  1395. if (mSkillNameHud != null)
  1396. mSkillNameHud.OnActorRevive();
  1397. if (mRageEffectHud != null)
  1398. {
  1399. mRageEffectHud.OnActorRevive();
  1400. }
  1401. }
  1402. public void OnDie()
  1403. {
  1404. if (Ctrl != null)
  1405. Ctrl.OnDie();
  1406. if (CurrentBattleField != null)
  1407. CurrentBattleField.OnFighterDie(this);
  1408. //if(mBloodBarHud!=null)
  1409. // mBloodBarHud.OnActorDead();
  1410. if (mHpBarHud != null)
  1411. mHpBarHud.OnActorDead();
  1412. if (mSkillNameHud != null)
  1413. mSkillNameHud.OnActorDead();
  1414. if (mRageEffectHud != null)
  1415. {
  1416. mRageEffectHud.OnActorDead();
  1417. }
  1418. FighterMgr.OnFighterDie(this);
  1419. }
  1420. BaseSkill mSkill = null;
  1421. public bool CanDoSkill(int skillType,out BaseSkill skill)
  1422. {
  1423. skill = null;
  1424. if (Actor.IsDisposed)
  1425. return false;
  1426. if(mStateData.SkillStateData == null)
  1427. {
  1428. DebugHelper.LogError(this.Name + " CAST SKILL");
  1429. return false;
  1430. }
  1431. mSkill = GetSkill(skillType);
  1432. if (mSkill == null) return false;
  1433. if (!PreCheckCanDoSkill(mSkill))
  1434. {
  1435. //DebugHelper.LogWarning(this.Name + "PreCheckCanDoSkill 不能执行");
  1436. return false;
  1437. }
  1438. if (mStateData.SkillStateData.GetCd(skillType) > 0)
  1439. {
  1440. //DebugHelper.LogWarning(this.Name + "CD 未到");
  1441. return false;
  1442. }
  1443. if (Sp < mSkill.SkillDataInfo.spCost) {
  1444. // DebugHelper.LogWarning(this.Name + "不能执行");
  1445. return false;
  1446. }
  1447. ReSelectTarget(mSkill);
  1448. if (mStateData.SkillStateData.TargetFighter == null)
  1449. {
  1450. //DebugHelper.LogWarning(this.Name+"目标不存在");
  1451. return false;
  1452. }
  1453. Vector3 targetP = mStateData.SkillStateData.TargetFighter.Position;
  1454. targetP.y = 0;
  1455. Vector3 tempP = this.Position;
  1456. tempP.y = 0;
  1457. float dist = Vector3.Distance(targetP, tempP);
  1458. float stopDist = mSkill.GetSkillDist((int)ProfType) + this.ModelSize + mStateData.SkillStateData.TargetFighter.ModelSize;
  1459. //DebugHelper.LogError(Name + " "+ dist +" skillDist:"+ stopDist + " target:"+ mStateData.SkillStateData.TargetFighter.Name);
  1460. if ((dist - stopDist) > 0.1f)
  1461. {
  1462. if(!FuncMgr.HaveForbidMoveFunc())
  1463. {
  1464. Vector3 dir = (targetP - tempP).normalized;
  1465. AutoChaseTo(mStateData.SkillStateData.TargetFighter, stopDist);
  1466. }
  1467. return false;
  1468. }
  1469. skill = mSkill;
  1470. return true;
  1471. }
  1472. public void ProcessTriggerSkillBuff(Fighter caster, BaseSkill skill, BuffTriggerType type)
  1473. {
  1474. if (skill == null) return;
  1475. if (this != caster) return;
  1476. SkillTriggerBuffInfo buffInfo = skill.GetTriggerBuffByType(type);
  1477. if (buffInfo.buffId > 0 && buffInfo.ratio > 0)
  1478. {
  1479. float randomV = Battle.RandomValue(true);
  1480. if (randomV <= buffInfo.ratio)
  1481. {
  1482. CastBuff(null, buffInfo.buffId,skill.Level);
  1483. }
  1484. }
  1485. }
  1486. public void ProcessTriggerBuff(Fighter caster,BuffTriggerType type)
  1487. {
  1488. if (mTriggerBuffs == null) return;
  1489. int curFrame = Battle.CurBattleField.CurrentStateFrame;
  1490. for (int idx = 0; idx < mTriggerBuffs.Count; idx++)
  1491. {
  1492. TriggerBuffData buffData = mTriggerBuffs[idx];
  1493. if (buffData.TriggerType != type)
  1494. continue;
  1495. if (!CheckPassiveBuffCaster(buffData, caster))
  1496. continue;
  1497. if (BuffTriggerType.Trigger_FixedTime == type)//固定间隔触发 不需要CD
  1498. {
  1499. buffData.DoUpdateTrigger(this, curFrame);
  1500. continue;
  1501. }
  1502. if ((buffData.TriggerType == BuffTriggerType.Trigger_Begin_Fighting || buffData.CanTrigger(curFrame)) &&
  1503. buffData.CanCheckCondition(caster))
  1504. {
  1505. buffData.DoTrigger(this,curFrame);
  1506. if (BattleMgr.Instance.Battle.CanPrintLog)
  1507. {
  1508. DebugHelper.LogError(string.Format("{0} trigger passivebuff {1} caster:{2}, frame:{3}",
  1509. this.Name,
  1510. buffData.BuffId,
  1511. caster.Name,
  1512. CurrentBattleField.CurrentStateFrame));
  1513. }
  1514. }
  1515. }
  1516. }
  1517. public void AddTriggerBuffData(TriggerBuffData data)
  1518. {
  1519. if (mTriggerBuffs == null)
  1520. mTriggerBuffs = new List<TriggerBuffData>();
  1521. mTriggerBuffs.Add(data);
  1522. }
  1523. public void RemoveTriggerBuffData(int buffId)
  1524. {
  1525. if (mTriggerBuffs == null) return;
  1526. for(int idx = mTriggerBuffs.Count -1; idx >= 0; idx--)
  1527. {
  1528. if(mTriggerBuffs[idx].BuffId == buffId)
  1529. {
  1530. mTriggerBuffs.RemoveAt(idx);
  1531. }
  1532. }
  1533. }
  1534. private bool CheckPassiveBuffCaster(TriggerBuffData data,Fighter caster)
  1535. {
  1536. if (caster == null) return false;
  1537. if(data.CasterType == BuffTriggerCasterType.self)
  1538. {
  1539. return this == caster;
  1540. }else if(data.CasterType == BuffTriggerCasterType.target)
  1541. {
  1542. return this.SelectTarget == caster;
  1543. }else if(data.CasterType == BuffTriggerCasterType.friends)
  1544. {
  1545. return this.TeamSide == caster.TeamSide;
  1546. }else if(data.CasterType == BuffTriggerCasterType.enemies)
  1547. {
  1548. return this.TeamSide != caster.TeamSide;
  1549. }else if(data.CasterType == BuffTriggerCasterType.host)
  1550. {
  1551. return this.IsPet && this.TeamSide == caster.TeamSide && this.OwnerId == caster.Id;
  1552. }
  1553. return false;
  1554. }
  1555. //-------------------------------------------------
  1556. public void ProcessBeHit(SkillHitFighterInfo hitInfo, int seq,int lastDamage)
  1557. {
  1558. if (hitInfo.Target != this)
  1559. return;
  1560. bool kill = ProcessDamage(hitInfo);
  1561. if (kill)
  1562. {
  1563. Battle.Output(OutputType.Dead, this);
  1564. }
  1565. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_Fighter_BeHit, this));
  1566. if (hitInfo.Damage > 0)
  1567. {
  1568. if (HaveBuffFunction(Buff_Function_Type.Sleep))
  1569. RemoveFunctionByFunType(Buff_Function_Type.Sleep);
  1570. if (hitInfo.HitBreakCheckFlag)
  1571. {
  1572. FixVector3 hitMoveDestPos = FixVector3.Zero;
  1573. //if (!hitInfo.HitflyCheckFlag)
  1574. // hitMoveDestPos.y = Fix64.Zero;
  1575. Fix64 acceleration = Fix64.Zero;
  1576. FixVector3 v3SelfPos = new FixVector3(this.Position);
  1577. FixVector3 v3TargetPos = new FixVector3(hitInfo.Caster.Position);
  1578. if (hitInfo.AttackInfo.hitMoveType > 0)
  1579. {
  1580. if (hitInfo.AttackInfo.hitMoveType == (int)FighterMoveType.Beat_Back)
  1581. {
  1582. FixVector3 dir = v3SelfPos - v3TargetPos;
  1583. dir.Normalize();
  1584. dir.y = Fix64.Zero;
  1585. hitMoveDestPos = dir * (Fix64)hitInfo.AttackInfo.hitMoveDist + v3SelfPos;
  1586. hitMoveDestPos.y = (Fix64)CurrentBattleField.FloorY;
  1587. acceleration = (Fix64)hitInfo.AttackInfo.hitMoveAcceleration;
  1588. }
  1589. else if (hitInfo.AttackInfo.hitMoveType == (int)FighterMoveType.Beat_Fly)
  1590. {
  1591. FixVector3 dir = FixVector3.Up;
  1592. hitMoveDestPos = dir * (Fix64)hitInfo.AttackInfo.hitMoveDist + v3SelfPos;
  1593. acceleration = (Fix64)hitInfo.AttackInfo.hitMoveAcceleration;
  1594. }
  1595. }
  1596. DoBeHit(hitInfo.AttackInfo.hitMoveType, (Fix64)hitInfo.AttackInfo.hitMoveInitSpeed, acceleration, hitMoveDestPos, (Fix64)hitInfo.AttackInfo.stiffTime);
  1597. }
  1598. }
  1599. if (Ctrl != null)
  1600. Ctrl.OnBeHit(hitInfo, seq);
  1601. if(Statistics!=null)
  1602. Statistics.StatBeHitInfo(hitInfo);
  1603. if (kill && hitInfo.Caster != null && !hitInfo.Caster.IsDisposed)
  1604. {
  1605. hitInfo.Caster.OnKillEnemy(this);
  1606. if(hitInfo.AttackInfo.skill!=null)
  1607. {
  1608. EventMgr.DispatchEvent<Fighter, BaseSkill>(new CoreEvent<Fighter, BaseSkill>(ECoreEventType.EID_Fighter_Kill, hitInfo.Caster, hitInfo.AttackInfo.skill));
  1609. }
  1610. }
  1611. if (hitInfo.Damage > 0)
  1612. {
  1613. mTotalTakeDamage += Mathf.RoundToInt(hitInfo.Damage);
  1614. UIEventParamFighterHurt hurtParam = new UIEventParamFighterHurt(hitInfo.Caster, this,
  1615. Mathf.RoundToInt(hitInfo.Damage),
  1616. hitInfo.IsCrit,
  1617. hitInfo.AttackInfo.skill!=null ? hitInfo.AttackInfo.skill.SkillTypeID : 0,
  1618. hitInfo.AttackInfo.multiHitCount,
  1619. hitInfo.AttackInfo.multiHitIntervalTime,
  1620. seq,
  1621. hitInfo.AttackInfo.skill!=null ? hitInfo.AttackInfo.skill.Id:0,
  1622. hitInfo.BuffId,lastDamage);
  1623. EventMgr.DispatchEvent<UIEventParamFighterHurt>(new CoreEvent<UIEventParamFighterHurt>(ECoreEventType.EID_FIGHTER_HURT, hurtParam));
  1624. if(hitInfo.IsCrit)
  1625. {
  1626. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_Fighter_Damage_FromCrit, this));
  1627. }
  1628. }
  1629. }
  1630. public void ProcessReflectDamage(SFloat damage,string skillName,Fighter caster)
  1631. {
  1632. if (!IsAlive || damage == 0)
  1633. return;
  1634. if (StateData.IsInvincible)//无敌
  1635. return;
  1636. //SInt lifeBefore = Life;
  1637. bool isAliveBefore = IsAlive;
  1638. SInt oldDamage = Mathf.CeilToInt(damage);
  1639. if (caster.Statistics != null)
  1640. caster.Statistics.StatReflectInfo(caster, oldDamage);
  1641. if (Statistics != null)
  1642. Statistics.StatReflectHurtInfo(this, oldDamage);
  1643. damage = FuncMgr.DamageOnShield(oldDamage);
  1644. if (!IgnoreLife)
  1645. {
  1646. Life -= (int)damage;
  1647. }
  1648. if (damage > 0)
  1649. {
  1650. Battle.Output(OutputType.Damage, caster, this, skillName, (int)damage);
  1651. if (HaveBuffFunction(Buff_Function_Type.Sleep))
  1652. RemoveFunctionByFunType(Buff_Function_Type.Sleep);
  1653. mTotalTakeDamage += Mathf.RoundToInt(damage);
  1654. }
  1655. bool kill = isAliveBefore && !IsAlive;
  1656. if (kill)
  1657. {
  1658. Battle.Output(OutputType.Dead, this);
  1659. if(caster != null && !caster.IsDisposed)
  1660. {
  1661. caster.OnKillEnemy(this);
  1662. }
  1663. }
  1664. UIEventParamFighterHurt hurtParam = new UIEventParamFighterHurt(caster, this, Mathf.RoundToInt(damage), false, 0, 1, 1, 1, 0, 0, 0);
  1665. EventMgr.DispatchEvent<UIEventParamFighterHurt>(new CoreEvent<UIEventParamFighterHurt>(ECoreEventType.EID_FIGHTER_HURT, hurtParam));
  1666. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_Fighter_BeHit, this));
  1667. if (BattleMgr.Instance.Battle.CanPrintLog)
  1668. {
  1669. DebugHelper.LogError(string.Format("{0} 对 {1} 的反伤伤害值是{2}", caster.Name, this.Name, (int)damage));
  1670. }
  1671. }
  1672. //吸收伤害
  1673. public void ProcessSuckDamage(SFloat damage, string skillName, Fighter caster)
  1674. {
  1675. if (null == StateData)
  1676. return;
  1677. if (!IsAlive || damage == 0)
  1678. return;
  1679. if (damage > 0)
  1680. {
  1681. Life += (int)damage;
  1682. RefreshLife();
  1683. EventMgr.DispatchEvent<object[]>(new CoreEvent<object[]>(ECoreEventType.EID_FIGHTER_HEAL, new object[] { this, (int)damage }));
  1684. }
  1685. }
  1686. public void ProcessStiff(bool stiff)
  1687. {
  1688. if (Ctrl != null)
  1689. Ctrl.ProcessStiff(stiff);
  1690. }
  1691. public void ProcessVertigo(bool grey)
  1692. {
  1693. if (Ctrl != null)
  1694. Ctrl.ProcessVertigo(grey);
  1695. }
  1696. public void ProcessSlow(bool bSlow)
  1697. {
  1698. if (Ctrl != null)
  1699. Ctrl.ProcesssSpecularColor(bSlow,new Color(31.0f/255, 128.0f/255, 245.0f/255));
  1700. }
  1701. public void AddRage(int val)
  1702. {
  1703. //if (IsCaptain)
  1704. // Rage += val;
  1705. //else {
  1706. // Fighter captain = TeamSide == 0 ? FighterMgr.LeftCaptain : FighterMgr.RightCaptain;
  1707. // if (captain != null && captain.IsSpawned && !captain.IsDisposed && captain.IsAlive)
  1708. // captain.Rage += val;
  1709. //}
  1710. }
  1711. public void ReSelectTarget(BaseSkill skill)
  1712. {
  1713. mStateData.SkillStateData.TargetFighter = TrySelect(skill);
  1714. }
  1715. public void EndSkill(bool breakFlag= false)
  1716. {
  1717. if(breakFlag && mStateData.CurrentSkill!=null)
  1718. {
  1719. if(Statistics!=null)
  1720. Statistics.OnBreakSkill(this, mStateData.CurrentSkill.SkillTypeID);
  1721. //TriggerBuffByType(mStateData.CurrentSkill, SkillTriggerBuffType.Skill_Interrtupted_Trigger);
  1722. EventMgr.DispatchEvent<Fighter, BaseSkill>(new CoreEvent<Fighter, BaseSkill>(ECoreEventType.EID_Fighter_Skill_Broken, this, mStateData.CurrentSkill));
  1723. }
  1724. ShowSkillBreak();
  1725. mStateData.EndSkill();
  1726. }
  1727. public bool ChangeSkill(int fromSkill,int toSkill)
  1728. {
  1729. return Actor.SkillMgr.ChangeSkill(fromSkill, toSkill);
  1730. }
  1731. Fighter TrySelect(BaseSkill skill)
  1732. {
  1733. float dis = 100000;
  1734. Fighter fighter = null;
  1735. List<Fighter> fighters = CurrentBattleField.Fighters;
  1736. for(int idx =0; idx < fighters.Count;idx++)
  1737. {
  1738. Fighter f = fighters[idx];
  1739. if (f == null || f.TeamSide == TeamSide || f.IsDisposed || !f.IsAlive) continue;
  1740. if (skill.BuffList.Count > 0 &&
  1741. (skill.BuffList[0].filterRule.actorType != FilterActorType.Actor_Type_All &&
  1742. skill.BuffList[0].filterRule.actorType != FilterActorType.Actor_Type_Pet) &&
  1743. f.IsPet)
  1744. continue;
  1745. float dist = Vector3.Distance(this.Position, f.Position) - (ModelSize + f.ModelSize);
  1746. if(dist < dis)
  1747. {
  1748. dis = dist;
  1749. fighter = f;
  1750. }
  1751. }
  1752. return fighter;
  1753. }
  1754. #endregion
  1755. void Initialize(ActorData actor, eTeamType side, Fighter summonOwner)
  1756. {
  1757. FighterState.RegistCacheFighterState(this);
  1758. mPassiveMove = new PassiveMove(this);
  1759. mStateData = new FighterStateData(this);
  1760. IsDisposed = false;
  1761. IsSpawned = false;
  1762. Actor = actor;
  1763. Actor.FighterInstanceId = InstanceId;
  1764. TeamSide = side;
  1765. SummonOwner = summonOwner;
  1766. mBornEffectId = Actor.BornEffectId;
  1767. SyncActorData();
  1768. //mDelayBeHitInfo = new TimeDelayManager<SkillHitFighterInfo>(ProcessDelayBeHit);
  1769. if (IsBoss)
  1770. {
  1771. if (mRageEffectHud == null)
  1772. {
  1773. mRageEffectHud = new RageEffect2D();
  1774. mRageEffectHud.Born(this);
  1775. }
  1776. }
  1777. if (Actor.ShowHpBar)
  1778. {
  1779. if (mHpBarHud == null)
  1780. {
  1781. mHpBarHud = new FighterHPBar();
  1782. mHpBarHud.Born(this);
  1783. }
  1784. }
  1785. if (!Constants.isOffline)
  1786. {
  1787. if (mSkillNameHud == null)
  1788. {
  1789. mSkillNameHud = new SkillName2D();
  1790. mSkillNameHud.Born(this);
  1791. }
  1792. }
  1793. }
  1794. public void ResetActor(ActorData actor)
  1795. {
  1796. Actor = actor;
  1797. SyncActorData();
  1798. }
  1799. private JSONObject mRecordJson = null;
  1800. public JSONObject RecordJson
  1801. {
  1802. get { return mRecordJson; }
  1803. }
  1804. public void SyncActorData()
  1805. {
  1806. mRecordJson = Actor.ToJson();
  1807. int atkFactor = 0, magicAtkFactor = 0, hpFactor = 0, spFactor = 0;
  1808. BattleMgr.Instance.Battle.GetBattleFactors(out magicAtkFactor, out atkFactor, out hpFactor, out spFactor);
  1809. if (TeamSide == eTeamType.Enemy)
  1810. {
  1811. spFactor = 0;
  1812. }
  1813. else
  1814. {
  1815. atkFactor = 0;
  1816. magicAtkFactor = 0;
  1817. hpFactor = 0;
  1818. }
  1819. mActorBattleAttr.Init(Actor,BattleMgr.Instance.Battle.FighterLifeRatio, atkFactor, magicAtkFactor, hpFactor, spFactor);
  1820. MaxLife = Mathf.RoundToInt(mActorBattleAttr.life);
  1821. MaxSp = Mathf.RoundToInt(mActorBattleAttr.sp);
  1822. mTriggerBuffs = mActorBattleAttr.triggerBuffs;
  1823. InitFighterBattleAttr();
  1824. if (-1 != BattleMgr.Instance.Battle.BattleBeginMarkId)
  1825. AddMark(BattleMgr.Instance.Battle.BattleBeginMarkId, 1);
  1826. if (!Actor.HasPet)
  1827. {
  1828. UsedPetId = 0;
  1829. }
  1830. InitScale();
  1831. }
  1832. public void InitScale()
  1833. {
  1834. if (IsPet)
  1835. {
  1836. float fScale = Actor.GetScale();
  1837. SetScale(fScale);
  1838. ForceSync(Ctrl.transform);
  1839. }
  1840. }
  1841. public SFloat GetNatureDamagePercent(int natureId)
  1842. {
  1843. if (natureId < (int)Nature_Type.None || natureId >= (int)Nature_Type.Max) return 0;
  1844. return mActorBattleAttr.natureDamagePercent[natureId - 1] + GetBuffFunctionValue(Buff_Function_Type.Nature_None_Change_Value + natureId - 1);
  1845. }
  1846. public SFloat GetAntiNatureDamagePercent(int natureId)
  1847. {
  1848. if (natureId < (int)Nature_Type.None || natureId >= (int)Nature_Type.Max) return 0;
  1849. return mActorBattleAttr.antiNatureDamagePercent[natureId - 1] + GetBuffFunctionValue(Buff_Function_Type.AntiNature_None_Change_Value + natureId - 1);
  1850. }
  1851. void InitFighterBattleAttr()
  1852. {
  1853. Life = MaxLife;
  1854. Sp = MaxSp;
  1855. IgnoreLife = Actor.IgnoreLife;
  1856. }
  1857. void InitGo(string name)
  1858. {
  1859. Go = new GameObject();
  1860. Go.transform.SetParent(Battle != null? BattleMgr.Instance.transform: null);
  1861. Go.transform.localPosition = Vector3.zero;
  1862. Go.transform.localEulerAngles = Vector3.zero;
  1863. Go.transform.localScale = Vector3.one;
  1864. Layer = LayerMask.NameToLayer(BattleCamera.FighterLayerName);
  1865. mCtrl = Go.AddComponent<FighterGoCtrl>();
  1866. mCtrl.Fighter = this;
  1867. ForceSync(Go.transform);
  1868. Go.name = name;
  1869. }
  1870. bool ProcessDamage(SkillHitFighterInfo hitInfo)
  1871. {
  1872. if (!IsAlive)
  1873. return false;
  1874. //SInt lifeBefore = Life;
  1875. bool isAliveBefore = IsAlive;
  1876. if (hitInfo.Damage > 0)
  1877. {
  1878. SInt oldDamage = Mathf.CeilToInt(hitInfo.Damage);
  1879. hitInfo.Damage = FuncMgr.DamageOnShield(oldDamage);
  1880. if(!IgnoreLife)
  1881. {
  1882. Life -= (int)hitInfo.Damage;
  1883. }
  1884. hitInfo.Absorb = (float)oldDamage - hitInfo.Damage;
  1885. }
  1886. string skillName = null;
  1887. if(hitInfo.Skill!=null && !hitInfo.Skill.IsNormalAttack)
  1888. {
  1889. skillName = hitInfo.Skill.SkillName;
  1890. }
  1891. if(hitInfo.Damage > 0)
  1892. Battle.Output(OutputType.Damage, hitInfo.Caster, hitInfo.Target, skillName, (int)hitInfo.Damage);
  1893. if (BattleMgr.Instance.Battle.CanPrintLog)
  1894. {
  1895. DebugHelper.LogError(string.Format("<color=#ffff00>{0} pos = {5} frame={6} skillName={4} Absorb = {1}-----Damage = {2} ---- Life = {3}</color>", this.Id, hitInfo.Absorb, hitInfo.Damage, Life, hitInfo.Skill != null ? hitInfo.Skill.SkillName : "", PositionValue, CurrentBattleField.CurrentStateFrame));
  1896. }
  1897. return isAliveBefore && !IsAlive;
  1898. }
  1899. void Prepare()
  1900. {
  1901. if(Skills!=null)
  1902. {
  1903. foreach (var skill in Skills)
  1904. {
  1905. if (skill != null && skill.IsEnabled)
  1906. skill.Prepare(this);
  1907. }
  1908. }
  1909. if(NormalSkills!=null)
  1910. {
  1911. foreach (var skill in NormalSkills)
  1912. {
  1913. if (skill != null && skill.IsEnabled)
  1914. skill.Prepare(this);
  1915. }
  1916. }
  1917. if(RandomSkills!=null)
  1918. {
  1919. for(int idx =0; idx < RandomSkills.Count;idx++)
  1920. {
  1921. if (RandomSkills[idx] != null && RandomSkills[idx].IsEnabled)
  1922. RandomSkills[idx].Prepare(this);
  1923. }
  1924. }
  1925. if(PassiveSkills!=null)
  1926. {
  1927. for(int idx =0; idx < PassiveSkills.Count;idx++)
  1928. {
  1929. PassiveSkills[idx].Prepare(this);
  1930. }
  1931. }
  1932. if (Actor.RageId > 0)
  1933. {
  1934. var buffData = BattlePrepareManager.Instance.PrecacheBuff(Actor.RageId,Gender,ProfType,JobStage,JobBranch);
  1935. if(buffData!=null)
  1936. this.RageCloneBossId = buffData.cloneBossId;
  1937. }
  1938. if(Actor.TriggerBuffs != null)
  1939. {
  1940. for(int idx =0; idx < Actor.TriggerBuffs.Count;idx++)
  1941. {
  1942. BattlePrepareManager.Instance.PrecacheBuff(Actor.TriggerBuffs[idx].BuffId,Gender,ProfType,JobStage,JobBranch);
  1943. }
  1944. }
  1945. //Debug.Log("=======DropBuffList 1==========");
  1946. if (Actor.DropBuffList != null)
  1947. {
  1948. //Debug.Log("=======DropBuffList 来了==========");
  1949. for(int idx =0; idx < Actor.DropBuffList.Count;idx++)
  1950. {
  1951. BuffData buffData = BattlePrepareManager.Instance.PrecacheBuff(Actor.DropBuffList[idx].BuffId, Gender, ProfType, JobStage, JobBranch);
  1952. buffData.SetFunData(Actor.DropBuffList[idx].FunParamStr);
  1953. }
  1954. }
  1955. if(Actor.SkillMgr.AlternativeSkills!=null)
  1956. {
  1957. for(int idx =0; idx < Actor.SkillMgr.AlternativeSkills.Count;idx++)
  1958. {
  1959. Actor.SkillMgr.AlternativeSkills[idx].Prepare(this);
  1960. }
  1961. }
  1962. }
  1963. public void PrecacheBuff()
  1964. {
  1965. if (Actor.DropBuffList != null)
  1966. {
  1967. Debug.Log("======PrecacheBuff=DropBuffList 来了=========="+ Actor.DropBuffList.Count);
  1968. for (int idx = 0; idx < Actor.DropBuffList.Count; idx++)
  1969. {
  1970. BuffData buffData = BattlePrepareManager.Instance.PrecacheBuff(Actor.DropBuffList[idx].BuffId, Gender, ProfType, JobStage, JobBranch);
  1971. buffData.SetFunData(Actor.DropBuffList[idx].FunParamStr);
  1972. }
  1973. mTriggerBuffs.AddRange(Actor.DropBuffList);
  1974. Actor.DropBuffList.Clear();
  1975. }
  1976. }
  1977. bool PreCheckCanDoSkill(BaseSkill skill)
  1978. {
  1979. if (skill == null || !skill.IsEnabled)
  1980. {
  1981. //DebugHelper.LogError("技能不可用,不能执行");
  1982. return false;
  1983. }
  1984. if (!IsFighting || !IsAlive)
  1985. {
  1986. //DebugHelper.LogError("PreCheckCanDoSkill:"+ IsFighting+" isalive:"+IsAlive);
  1987. return false;
  1988. }
  1989. if (mStateData.IsStark)
  1990. {
  1991. //DebugHelper.Log("stark state!!!");
  1992. return false;
  1993. }
  1994. return true;
  1995. }
  1996. public Vector3 GetSkillNamePos()
  1997. {
  1998. Vector3 pos = Vector3.zero;
  1999. //if (mBloodBarHud != null)
  2000. //{
  2001. // pos = mBloodBarHud.BloodPos;
  2002. // if (mBloodBarHud.BloodIsVisible)
  2003. // pos.y += mBloodBarHud.BloodHeight;
  2004. //}
  2005. return pos;
  2006. }
  2007. int lastAddFrame = 0;
  2008. public void AddFunctionPoint(int pointBuffId,int pointVal,int buffLevel)
  2009. {
  2010. if (lastAddFrame == Time.frameCount) return;
  2011. int maxPoint = BattleFormulaParamMgr.Instance.GetFunPoint(pointBuffId);
  2012. if (mFunPointBuffs.ContainsKey(pointBuffId))
  2013. {
  2014. mFunPointBuffs[pointBuffId] = mFunPointBuffs[pointBuffId] + pointVal;
  2015. BattleBuff buff = BuffMgr.GetBuff(pointBuffId);
  2016. if(buff == null)
  2017. {
  2018. CastBuff(null, pointBuffId, buffLevel);
  2019. }
  2020. else
  2021. {
  2022. BuffData buffData = BattlePrepareManager.Instance.PopBuffData(pointBuffId);
  2023. buff.AddTotalFrame(buffData.totalFrame);
  2024. //buff.AddTotalTime(buffData.totalTime);
  2025. }
  2026. }
  2027. else
  2028. {
  2029. BuffData buffData = BattlePrepareManager.Instance.PopBuffData(pointBuffId);
  2030. mFunPointBuffs.Add(pointBuffId, pointVal);
  2031. CastBuff(null, pointBuffId, buffLevel);
  2032. }
  2033. if (mFunPointBuffs[pointBuffId] > maxPoint)
  2034. {
  2035. mFunPointBuffs[pointBuffId] = maxPoint;
  2036. }
  2037. lastAddFrame = Time.frameCount;
  2038. ShowPointBuffIcon(pointBuffId);
  2039. //DebugHelper.LogError(this.Name + " pointbuffid:" + pointBuffId + " point:" + mFunPointBuffs[pointBuffId]);
  2040. }
  2041. int lastDetuctFrame = 0;
  2042. public void DetuctFunctionPoint(int pointBuffId, int pointVal)
  2043. {
  2044. if (lastDetuctFrame == Time.frameCount) return;
  2045. if(mFunPointBuffs.ContainsKey(pointBuffId))
  2046. {
  2047. mFunPointBuffs[pointBuffId] = mFunPointBuffs[pointBuffId] - pointVal;
  2048. ShowPointBuffIcon(pointBuffId);
  2049. }
  2050. if(mFunPointBuffs[pointBuffId] <= 0)
  2051. {
  2052. RemovePointBuffIcon(pointBuffId);
  2053. mFunPointBuffs.Remove(pointBuffId);
  2054. BattleBuff buff = BuffMgr.GetBuff(pointBuffId);
  2055. if(buff!=null)
  2056. {
  2057. buff.Stop();
  2058. }
  2059. }
  2060. lastDetuctFrame = Time.frameCount;
  2061. }
  2062. public void RemoveFunctionPoint(int pointBuffId)
  2063. {
  2064. if (mFunPointBuffs.ContainsKey(pointBuffId))
  2065. {
  2066. RemovePointBuffIcon(pointBuffId);
  2067. mFunPointBuffs.Remove(pointBuffId);
  2068. }
  2069. }
  2070. public void ShowPointBuffIcon(int pointBuffId)
  2071. {
  2072. int maxPoint = BattleFormulaParamMgr.Instance.GetFunPoint(pointBuffId);
  2073. if (maxPoint <= 1) return;
  2074. BuffData buffData = BattlePrepareManager.Instance.PopBuffData(pointBuffId);
  2075. if (buffData != null)
  2076. ShowBuffIcon(buffData.icon, mFunPointBuffs[pointBuffId]);
  2077. }
  2078. public void RemovePointBuffIcon(int pointBuffId)
  2079. {
  2080. BuffData buffData = BattlePrepareManager.Instance.PopBuffData(pointBuffId);
  2081. if (buffData != null)
  2082. RemoveBuffIcon(buffData.icon);
  2083. }
  2084. public int GetFunctionPoint(int pointBuffId)
  2085. {
  2086. if (mFunPointBuffs.ContainsKey(pointBuffId))
  2087. return mFunPointBuffs[pointBuffId];
  2088. return 0;
  2089. }
  2090. public void ShowSkillName(string skillName)
  2091. {
  2092. if (string.IsNullOrEmpty(skillName)) return;
  2093. if (mSkillNameHud != null)
  2094. mSkillNameHud.OnShowSkillName(skillName);
  2095. }
  2096. public void ShowBuffIcon(string icon,int num)
  2097. {
  2098. if(IsBoss || IsPlayer)
  2099. {
  2100. stBuffParam buff = new stBuffParam(this.TeamSide,this.Id,IsBoss, icon, num);
  2101. EventMgr.DispatchEvent<stBuffParam>(new CoreEvent<stBuffParam>(ECoreEventType.EID_SHOW_BUFF_ICON, buff));
  2102. }
  2103. }
  2104. public void RemoveBuffIcon(string icon)
  2105. {
  2106. if (IsBoss || IsPlayer)
  2107. {
  2108. stBuffParam buff = new stBuffParam(this.TeamSide,this.Id, IsBoss, icon, 0);
  2109. EventMgr.DispatchEvent<stBuffParam>(new CoreEvent<stBuffParam>(ECoreEventType.EID_REMOVE_BUFF_ICON, buff));
  2110. }
  2111. }
  2112. public void RefreshLife()
  2113. {
  2114. //if (mBloodBarHud != null)
  2115. // mBloodBarHud.OnLifeChanged(this.Life,this.MaxLife);
  2116. if (mHpBarHud != null)
  2117. mHpBarHud.OnLifeChanged(this.Life, this.MaxLife);
  2118. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_FIGHTER_LIFE_CHANGED, this));
  2119. }
  2120. public void RefreshSp()
  2121. {
  2122. //if (mBloodBarHud != null)
  2123. // mBloodBarHud.OnSpChanged(this.Sp,this.MaxSp);
  2124. EventMgr.DispatchEvent<Fighter>(new CoreEvent<Fighter>(ECoreEventType.EID_FIGHTER_ENERGY_CHAGNED, this));
  2125. }
  2126. int mSingEffectInstanceId = 0;
  2127. public void BeginSing(string animName, int effectId)
  2128. {
  2129. if(StateData!=null)
  2130. StateData.BeginSing(animName);
  2131. if (mSkillNameHud != null)
  2132. mSkillNameHud.OnBeginSing((StateData.SingTotalFrame / Constants.frame_to_time));
  2133. if (effectId > 0 && mSingEffectInstanceId == 0)
  2134. {
  2135. mSingEffectInstanceId = EffectManager.Instance.PlayEffect(effectId, this, this);
  2136. }
  2137. }
  2138. public void RefreshSingProgress(float totalTime, float leftTime)
  2139. {
  2140. if (mSkillNameHud != null)
  2141. mSkillNameHud.OnUpdateSing(totalTime, leftTime);
  2142. }
  2143. public void EndSing()
  2144. {
  2145. if (mSkillNameHud != null)
  2146. mSkillNameHud.OnEndSing();
  2147. if (mSingEffectInstanceId > 0)
  2148. {
  2149. EffectManager.Instance.RemoveEffectByInstanceID(mSingEffectInstanceId);
  2150. mSingEffectInstanceId = 0;
  2151. }
  2152. }
  2153. public void ShowCasting(float time,bool vis)
  2154. {
  2155. if (mSkillNameHud != null)
  2156. mSkillNameHud.OnCasting(time, vis);
  2157. }
  2158. public void ShowSkillBreak()
  2159. {
  2160. if (mSkillNameHud != null)
  2161. mSkillNameHud.OnSkillBreak();
  2162. }
  2163. public void SetRageStatus(bool inRage)
  2164. {
  2165. if (StateData != null)
  2166. StateData.IsRageStatus = inRage;
  2167. //if (mRageEffectHud != null)//取消狂暴飘字
  2168. // mRageEffectHud.OnShowRage(inRage);
  2169. EventMgr.DispatchEvent<bool>(new CoreEvent<bool>(ECoreEventType.EID_BOSS_IN_RAGE, inRage));
  2170. }
  2171. public void CheckSkillEnhance(BaseSkill skill,bool preview = false)
  2172. {
  2173. if (skill == null) return;
  2174. skill.IsEnhance = false;
  2175. SkillData skillData = skill.SkillDataInfo;
  2176. if(skillData.pointBuffId > 0 && skillData.buffPointType != BuffPointType.None)
  2177. {
  2178. int buffId = skillData.pointBuffId;
  2179. if(skillData.buffPointType == BuffPointType.AddPoint)
  2180. {
  2181. if(!preview)
  2182. {
  2183. if (skillData.pointBuffParams != null && skillData.pointBuffParams.Length > 0)
  2184. {
  2185. int point = skillData.pointBuffParams[0];
  2186. if (mSkillBuffPoints.ContainsKey(buffId))
  2187. {
  2188. mSkillBuffPoints[buffId] = mSkillBuffPoints[buffId] + point;
  2189. }
  2190. else
  2191. {
  2192. mSkillBuffPoints.Add(buffId, point);
  2193. }
  2194. }
  2195. }
  2196. }else if(skillData.buffPointType == BuffPointType.OwnPoint)
  2197. {
  2198. skill.IsEnhance = HasSkillBuffPoint(buffId);
  2199. }else if(skillData.buffPointType == BuffPointType.DetectPoint)
  2200. {
  2201. int point = 0;
  2202. mSkillBuffPoints.TryGetValue(buffId, out point);
  2203. if (skillData.pointBuffParams != null && skillData.pointBuffParams.Length > 0 && point > 0)
  2204. {
  2205. for (int idx = skillData.pointBuffParams.Length - 1; idx >= 0; idx--)
  2206. {
  2207. if (skillData.pointBuffParams[idx] <= point)
  2208. {
  2209. if(!preview)
  2210. {
  2211. if (mSkillBuffPoints.ContainsKey(buffId))
  2212. {
  2213. mSkillBuffPoints[buffId] = mSkillBuffPoints[buffId] - skillData.pointBuffParams[idx];
  2214. }
  2215. }
  2216. skill.IsEnhance = true;
  2217. break;
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. }
  2224. public bool HasSkillBuffPoint(int buffId)
  2225. {
  2226. int point = 0;
  2227. mSkillBuffPoints.TryGetValue(buffId, out point);
  2228. return point > 0;
  2229. }
  2230. public void ClearSkillBuffPoints()
  2231. {
  2232. mSkillBuffPoints.Clear();
  2233. }
  2234. public void ClearTriggerBuff()
  2235. {
  2236. if(mTriggerBuffs != null)
  2237. {
  2238. mTriggerBuffs.Clear();
  2239. mTriggerBuffs = null;
  2240. }
  2241. }
  2242. public void SyncPetPosition(Vector3 petPos,bool syncNavAgent = false,bool enableNavAgent = true)
  2243. {
  2244. if (UsedPetId > 0)
  2245. {
  2246. Fighter pet = FighterMgr.GetFighterByID(UsedPetId, TeamSide);
  2247. if (pet != null)
  2248. {
  2249. if (syncNavAgent)
  2250. {
  2251. pet.Ctrl.EnableNavAgent(enableNavAgent);
  2252. }
  2253. pet.SyncPosition(petPos);
  2254. }
  2255. }
  2256. }
  2257. public void SyncPetMoveDestPos(Vector3 petPos, bool syncNavAgent = false, bool enableNavAgent = true)
  2258. {
  2259. if (UsedPetId > 0)
  2260. {
  2261. Fighter pet = FighterMgr.GetFighterByID(UsedPetId,TeamSide);
  2262. if (pet != null && null != pet.Actor)
  2263. {
  2264. if (syncNavAgent)
  2265. {
  2266. pet.Ctrl.EnableNavAgent(enableNavAgent);
  2267. }
  2268. pet.AutoMoveTo(petPos);
  2269. }
  2270. }
  2271. }
  2272. public void AddPveMark()
  2273. {
  2274. if (null == Actor.PveMark)
  2275. return;
  2276. //Debug.Log("Add Mark!!!!!!!!!!!!!");
  2277. AddMark(Actor.PveMark.m_nMarkid, Actor.PveMark.m_nMarkNum);
  2278. }
  2279. public void AddMark(int markId,int layer)
  2280. {
  2281. if (mStateData.MMarkMgr == null) return;
  2282. if (!IsAlive || IsDisposed || IsDestroy) return;
  2283. mStateData.MMarkMgr.AddMark(markId, layer);
  2284. }
  2285. public void DecMark(int markId,int layer)
  2286. {
  2287. if (mStateData.MMarkMgr == null) return;
  2288. if (!IsAlive || IsDisposed || IsDestroy) return;
  2289. mStateData.MMarkMgr.ClearMark(markId, layer);
  2290. }
  2291. public bool HasMarkNLayer(int markId,int layer)
  2292. {
  2293. if (mStateData.MMarkMgr == null) return false;
  2294. if (!IsAlive || IsDisposed || IsDestroy) return false;
  2295. return mStateData.MMarkMgr.HasNLayerMark(markId, layer);
  2296. }
  2297. public void SetAttr(int type)
  2298. {
  2299. //int atkFactor = 0, magicAtkFactor = 0, hpFactor = 0, spFactor = 0;
  2300. //BattleMgr.Instance.Battle.GetBattleFactors(out magicAtkFactor, out atkFactor, out hpFactor, out spFactor);
  2301. //if (TeamSide == eTeamType.Enemy)
  2302. //{
  2303. // spFactor = 0;
  2304. //}
  2305. //else
  2306. //{
  2307. // atkFactor = 0;
  2308. // magicAtkFactor = 0;
  2309. // hpFactor = 0;
  2310. //}
  2311. //float lifeRatio = BattleMgr.Instance.Battle.FighterLifeRatio;
  2312. switch (type)
  2313. {
  2314. case ActorData.Attr_Life:
  2315. {
  2316. mActorBattleAttr.life = Actor.Life;// * lifeRatio * (1 + hpFactor * 0.01f);
  2317. if (mActorBattleAttr.life > long.MaxValue)
  2318. {
  2319. MaxLife = long.MaxValue;
  2320. }
  2321. else
  2322. {
  2323. MaxLife = System.Convert.ToInt64(Actor.Life);
  2324. }
  2325. Life = MaxLife;
  2326. Debug.Log($"---------Life = {Life}-- Actor.Life = {Actor.Life}------");
  2327. //Debug.Log($"----lifeRatio = {lifeRatio}-----Life = {Life}-- Actor.Life = {Actor.Life}---hpFactor = {hpFactor}---");
  2328. }
  2329. break;
  2330. case ActorData.Attr_Sp:
  2331. {
  2332. }
  2333. break;
  2334. case ActorData.Attr_Attack:
  2335. {
  2336. mActorBattleAttr.minAttack = Actor.MinAttack;// * (1 + atkFactor * 0.01f);
  2337. mActorBattleAttr.attack = Actor.Attack;// * (1 + atkFactor * 0.01f);
  2338. }
  2339. break;
  2340. case ActorData.Attr_MagicAttack:
  2341. {
  2342. mActorBattleAttr.minMagicAttack = Actor.MinMagicAttack;// * (1 + magicAtkFactor * 0.01f);
  2343. mActorBattleAttr.magic_attack = Actor.MagicAttack;// * (1 + magicAtkFactor * 0.01f);
  2344. }
  2345. break;
  2346. case ActorData.Attr_Defense:
  2347. {
  2348. mActorBattleAttr.defense = Actor.Defense;
  2349. }
  2350. break;
  2351. case ActorData.Attr_MagicDefense:
  2352. {
  2353. mActorBattleAttr.magic_defense = Actor.MagicDefense;
  2354. }
  2355. break;
  2356. case ActorData.Attr_Hit:
  2357. {
  2358. mActorBattleAttr.hit = Actor.Hit;
  2359. }
  2360. break;
  2361. case ActorData.Attr_Crit:
  2362. {
  2363. mActorBattleAttr.crit = Actor.Crit;
  2364. }
  2365. break;
  2366. case ActorData.Attr_Dodge:
  2367. {
  2368. mActorBattleAttr.dodge = Actor.Dodge;
  2369. }
  2370. break;
  2371. case ActorData.Attr_Ten:
  2372. {
  2373. mActorBattleAttr.ten = Actor.Ten;
  2374. }
  2375. break;
  2376. case ActorData.Attr_AttackSpeed:
  2377. {
  2378. mActorBattleAttr.attackSpeed = Actor.AttackSpeed;
  2379. }
  2380. break;
  2381. case ActorData.Attr_CastAcceleration:
  2382. {
  2383. }
  2384. break;
  2385. case ActorData.Attr_GodPow:
  2386. {
  2387. mActorBattleAttr.GodPower = Actor.GodPower;
  2388. }
  2389. break;
  2390. default:
  2391. break;
  2392. }
  2393. }
  2394. }