XmdsVirtual.Skills.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855
  1. using CommonAI.data;
  2. using CommonAI.Data;
  3. using CommonAI.Zone;
  4. using CommonAI.Zone.Helper;
  5. using CommonAI.Zone.Instance;
  6. using CommonAI.ZoneClient;
  7. using CommonAI.ZoneServer.JSGModule;
  8. using CommonLang;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using XmdsCommon.EditorData;
  14. using XmdsCommon.JSGModule.Interface;
  15. using XmdsCommon.Plugin;
  16. using XmdsCommonServer.Message;
  17. using XmdsCommonServer.Plugin.Base;
  18. using XmdsCommonServer.Plugin.Units;
  19. using XmdsCommonServer.Plugin.XmdsSkillTemplate;
  20. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  21. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  22. using XmdsCommonServer.XLS.Data;
  23. using XmdsCommonSkill.Plugin.CardSkill;
  24. using static CommonAI.Zone.Instance.InstanceUnit;
  25. namespace XmdsCommonServer.Plugin
  26. {
  27. /// <summary>
  28. /// FileName: XmdsVirtual.cs
  29. /// Author: Alex.Yu
  30. /// Corporation:...
  31. /// Description:
  32. /// DateTime: 2015/5/12 10:20:46
  33. /// </summary>
  34. public partial class XmdsVirtual
  35. {
  36. //技能初始化辅助类.
  37. protected XmdsSkillHelper mSkillHelper = null;
  38. /// <summary>
  39. /// 初始化技能辅助类.
  40. /// </summary>
  41. public XmdsSkillHelper SkillHelper { get { return mSkillHelper; } }
  42. //卡牌技能类
  43. private IJSCardSkillModule mCardModule;
  44. //玩家本地缓存数据
  45. private IPlayerCache mPlayerCache;
  46. public IJSCardSkillModule CardModule { get { return mCardModule; } }
  47. private HashMap<int, BuffTemplate> mTrySendBuff = new HashMap<int, BuffTemplate>();
  48. private HashMap<int, SpellTemplate> mTrySendSpell = new HashMap<int, SpellTemplate>();
  49. private HashMap<int, SpellTemplate> mLaunchSpellOver = new HashMap<int, SpellTemplate>();
  50. //扩展字段
  51. //法师:标记剑影是否强化过
  52. public int extValue = 0;
  53. #region 技能相关.
  54. private void ReGetUnitSkills(List<GameSkill> ls, List<GameSkill> retList)
  55. {
  56. GameSkill gs = null;
  57. for (int i = ls.Count - 1; i >= 0; i--)
  58. {
  59. gs = ls[i];
  60. if (gs.SkillID == 0)
  61. {
  62. ls.RemoveAt(i);
  63. }
  64. else if (this.IsPlayerUnit() || getSkillType(ref gs))//玩家的技能来自游戏服,不管表格类型
  65. {
  66. retList.Add(gs);
  67. }
  68. }
  69. }
  70. private void CreateCreateCardModule()
  71. {
  72. // if (this.mCardModule == null)
  73. // {
  74. // if (this.mUnit.IsPlayer)
  75. // {
  76. // this.mCardModule = XmdsGlobalData.GetPlayerCardModule(this);
  77. // }
  78. // else if (this.mUnit.IsMonster && this.IsBoss())
  79. // {
  80. // this.mCardModule = new JSGMonsterCardModule(this);
  81. // }
  82. // else
  83. // {
  84. // this.mCardModule = new JSGOtherCardModule();
  85. // }
  86. // }
  87. }
  88. public void InitCardModule()
  89. {
  90. // this.mCardModule.Init(this);
  91. //
  92. // if(this.mUnit.VisibleInfo != null)
  93. // {
  94. // this.mUnit.VisibleInfo.setVisibleCardData(this.mCardModule.GetCardInterface());
  95. // }
  96. }
  97. protected void checkSkillData(XmdsUnitData data)
  98. {
  99. //过滤data 防止无效的gameSkill.
  100. List<GameSkill> retList = new List<GameSkill>();
  101. // 常规技能
  102. if (data.Skills != null && data.Skills.UnitSkills != null)
  103. {
  104. this.ReGetUnitSkills(data.Skills.UnitSkills, retList);
  105. }
  106. // 卡牌技能
  107. if(data.CardSkills != null && data.CardSkills.UnitSkills != null)
  108. {
  109. this.ReGetUnitSkills(data.CardSkills.UnitSkills, retList);
  110. }
  111. #region Mock数据.
  112. GameSkill gs = null;
  113. //如果为空判断为编辑器环境,走MOCK数据.
  114. //if (data.Skills == null || data.Skills.UnitSkills == null || data.Skills.UnitSkills.Count == 0)
  115. {
  116. //单位普攻.
  117. if (mInfo.BaseSkillID != null && mInfo.BaseSkillID.SkillID != 0)
  118. {
  119. gs = new GameSkill();
  120. gs.SkillID = this.mInfo.BaseSkillID.SkillID;
  121. gs.SkillType = XmdsSkillType.normalAtk;
  122. gs.SkillLevel = 1;
  123. retList.Add(gs);
  124. }
  125. //单位技能.
  126. for (int i = 0; i < this.mInfo.Skills.Count; i++)
  127. {
  128. gs = new GameSkill();
  129. gs.SkillID = this.mInfo.Skills[i].SkillID;
  130. gs.SkillLevel = 1;
  131. if (getSkillType(ref gs))
  132. {
  133. retList.Add(gs);
  134. }
  135. }
  136. if (data.Skills == null)
  137. {
  138. XmdsUnitSkillInfo info = new XmdsUnitSkillInfo();
  139. info.UnitSkills = retList;
  140. data.Skills = info;
  141. }
  142. else
  143. {
  144. data.Skills.UnitSkills = retList;
  145. }
  146. }
  147. #endregion
  148. if (mSkillHelper == null)
  149. {
  150. mSkillHelper = new XmdsSkillHelper();
  151. }
  152. }
  153. private bool getSkillType(ref GameSkill gs)
  154. {
  155. XmdsSkillData skillData = XmdsDataMgr.GetInstance().GetXmdsSkillData(gs.SkillID);
  156. if (skillData != null && skillData.SkillType > 0)
  157. {
  158. gs.SkillType = (XmdsSkillType)skillData.SkillType;
  159. return true;
  160. }
  161. else
  162. {
  163. SkillTemplate st = XmdsBattleSkill.GetSkillTemplate(gs.SkillID);
  164. if (st != null)
  165. {
  166. gs.SkillType = (st.Properties as XmdsSkillProperties).SkillType;
  167. return true;
  168. }
  169. else
  170. {
  171. log.Warn("checkSkillData 找不到单位:" + this.mUnit.Info.ID + ", 技能ID: " + gs.SkillID);
  172. }
  173. }
  174. return false;
  175. }
  176. //重新调用一下基础技能的initOver
  177. public bool ReInitOverBaseSkill(GameSkill info)
  178. {
  179. AbstractSkill baseSkill = this.SkillHelper.GetPlayerSkillById(this.SkillHelper.GetBaseSkillID());
  180. if (baseSkill == null)
  181. {
  182. log.Error("找不到单位基础技能:" + this.mUnit.PlayerUUID + ", 技能初始化:" + info.SkillID + ", 基础技能: " + this.SkillHelper.GetBaseSkillID());
  183. return false;
  184. }
  185. // 借用一下这个接口,懒得写新的了
  186. baseSkill.InitOver(this, info);
  187. return true;
  188. }
  189. //初始化技能.
  190. protected virtual void InitSkillInfo(XmdsUnitData data)
  191. {
  192. this.checkSkillData(data);
  193. mFinishSkillInit = true;
  194. mSkillHelper.InitSkill(data.Skills, this);
  195. }
  196. public bool ChangeSkill(int oldSkillID, int newSkillID, SkillLevelData skillData)
  197. {
  198. try
  199. {// 同技能只改表数值的话,无需重新init,赋值
  200. if (oldSkillID == newSkillID)
  201. {
  202. GameSkill gs = this.SkillHelper.GetGameSkill(newSkillID);
  203. if (gs == null)
  204. {
  205. log.Warn("相同技能替换,更新数值,技能不存在: " + newSkillID + ", " + this.mUnit.PlayerUUID);
  206. return false;
  207. }
  208. gs.SkillLevel = skillData.SkillLevel;
  209. gs.TalentSkillLevel1 = skillData.TalentSkillLevel1;
  210. gs.TalentSkillLevel2 = skillData.TalentSkillLevel2;
  211. gs.TalentSkillLevel3 = skillData.TalentSkillLevel3;
  212. if (gs.SkillType == XmdsSkillType.passive || gs.SkillType == XmdsSkillType.petGivePassive)
  213. {
  214. UnitPassiveSkill skill = this.mSkillHelper.GetPlayerSkillByIdExt(newSkillID);
  215. skill.SkillDataChange(gs, this);
  216. }
  217. else
  218. {
  219. UnitSkill skill = this.mSkillHelper.GetPlayerSkillById(newSkillID);
  220. skill.SkillDataChange(gs, this);
  221. }
  222. }
  223. else
  224. {
  225. GameSkill oldSkill = null;
  226. long skillCD = 0;
  227. if (oldSkillID > 0)
  228. {
  229. skillCD = this.GetSkillTimestampMS(oldSkillID);
  230. oldSkill = this.RemoveSkill(oldSkillID);
  231. }
  232. if (newSkillID > 0)
  233. {
  234. //激活指定技能.
  235. GameSkill gs = gs = new GameSkill();
  236. gs.SkillID = newSkillID;
  237. gs.SkillType = skillData.skillType;
  238. gs.SkillLevel = skillData.SkillLevel;
  239. gs.TalentSkillLevel1 = skillData.TalentSkillLevel1;
  240. gs.TalentSkillLevel2 = skillData.TalentSkillLevel2;
  241. gs.TalentSkillLevel3 = skillData.TalentSkillLevel3;
  242. gs.SkillTimestampMS = skillCD;
  243. gs.AutoLaunch = gs.SkillType != XmdsSkillType.cardSkill;
  244. if (gs.SkillType == XmdsSkillType.passive || gs.SkillType == XmdsSkillType.petGivePassive)
  245. {
  246. AbstractSkill skill = this.mSkillHelper.AddPassiveSkill(gs);
  247. }
  248. else
  249. {
  250. AbstractSkill skill = this.mSkillHelper.AddActiveSkill(gs, gs.SkillType == XmdsSkillType.normalAtk);
  251. // if (gs.SkillType == XmdsSkillType.cardSkill && this.CardModule != null)
  252. // {
  253. // //this.CardModule.InitSkill
  254. // }
  255. }
  256. //if (skillCD > 0)
  257. //{
  258. // SkillState skillState = this.SetSkillCD(newSkillID, skillCD);
  259. // if (skillState != null)
  260. // {
  261. // skillState.Reset();
  262. // }
  263. //}
  264. }
  265. }
  266. }
  267. catch (Exception e)
  268. {
  269. log.Warn("ChangeSkill catch: " + oldSkillID + ", " + newSkillID + ", " + e);
  270. }
  271. return true;
  272. }
  273. private void UpdateSkillHelper(int intervalMS, bool slowRefresh)
  274. {
  275. if (mSkillHelper != null)
  276. {
  277. mSkillHelper.Update(intervalMS, slowRefresh);
  278. }
  279. }
  280. #endregion
  281. public bool AllowAutoLaunch(int skillid)
  282. {
  283. bool ret = false;
  284. if (mSkillHelper != null)
  285. {
  286. var gs = mSkillHelper.GetGameSkill(skillid);
  287. if (gs != null)
  288. {
  289. ret = gs.AutoLaunch;
  290. }
  291. }
  292. return ret;
  293. }
  294. public bool TryLaunchSpell(LaunchSpell launch, ref SpellTemplate spell, out JSGCreateSpellData createData, ref float startX, ref float startY)
  295. {
  296. SpellTemplate redirect;
  297. if (mTrySendSpell.TryGetValue(spell.ID, out redirect))
  298. {
  299. spell = redirect;
  300. }
  301. DispatchTrySendSpellEvent(launch, ref spell, out createData, ref startX, ref startY);
  302. return true;
  303. }
  304. public bool TrySendBuff(ref BuffTemplate buff, XmdsVirtual target, out object tag)
  305. {
  306. //无敌中,负面BUFF无效.
  307. if (target.IsInvincible && buff.IsHarmful == true)
  308. {
  309. target.SendBattleHintNumberB2C(0, XmdsVirtual.UnitHitEventState.Immunity);
  310. tag = null;
  311. return false;
  312. }
  313. bool ret = true;
  314. tag = null;
  315. if (buff.IsHarmful == true)
  316. {
  317. //给别人施加debuff.
  318. this.OnHitOthter(target);
  319. }
  320. //无敌时不受负面BUFF影响.
  321. //if (target.mUnit.IsInvincible && buff.IsHarmful == true)
  322. //{
  323. // ret = false;
  324. //}
  325. if (ret == true)
  326. {
  327. //重定向buff.
  328. BuffTemplate redirect;
  329. if (mTrySendBuff.TryGetValue(buff.ID, out redirect))
  330. {
  331. buff = redirect;
  332. }
  333. var temp = buff.Properties as XmdsBuffProperties;
  334. List<XmdsBuffVirtual> list = temp.GetBuffVirtualList();
  335. //克隆BUFF能力.
  336. if (list != null && list.Count > 0)
  337. {
  338. List<XmdsBuffVirtual> cList = new List<XmdsBuffVirtual>();
  339. Type ctype = null;
  340. UnitBuff dst = null;
  341. UnitBuff src = null;
  342. for (int i = 0; i < list.Count; i++)
  343. {
  344. src = list[i] as UnitBuff;
  345. ctype = src.GetType();
  346. dst = CommonLang.Property.ReflectionUtil.CreateInstance(ctype) as UnitBuff;
  347. src.CopyTo(dst);
  348. cList.Add(dst);
  349. }
  350. tag = cList;
  351. }
  352. //判断能否添加.
  353. target.DispatchTryAddBuffEvent(ref buff, target, ref ret);
  354. }
  355. return ret;
  356. }
  357. public void SendAddBuffEvent(XmdsVirtual hitter, BuffTemplate buff)
  358. {
  359. //this.DispatchSendBuffEvent(buff, hitter);
  360. }
  361. public void RegistSendBuff(BuffTemplate buff)
  362. {
  363. //if(mTrySendBuff.ContainsKey(buff.ID))
  364. //{
  365. // FormatLog(CommonLang.Log.LoggerLevel.ERROR, "RegistSendBuff 重复利用buff : {0}, {1}", this.mInfo.Name, buff.ID);
  366. //}
  367. mTrySendBuff.Put(buff.ID, buff);
  368. }
  369. public void RegistSendSpell(SpellTemplate spell)
  370. {
  371. mTrySendSpell.Put(spell.ID, spell);
  372. }
  373. public BuffTemplate GetRegistBuff(int id)
  374. {
  375. BuffTemplate ret = null;
  376. if (mTrySendBuff.TryGetValue(id, out ret))
  377. {
  378. return ret;
  379. }
  380. return null;
  381. }
  382. public UnitBuff GetRegisBuffVirtual(int id, int index = 0)
  383. {
  384. if (index < 0) return null;
  385. UnitBuff ret = null;
  386. BuffTemplate bt = GetRegistBuff(id);
  387. XmdsBuffVirtual zbv = null;
  388. if (bt != null)
  389. {
  390. List<XmdsBuffVirtual> list = (bt.Properties as XmdsBuffProperties).GetBuffVirtualList();
  391. if (list != null && index < list.Count)
  392. {
  393. zbv = list[index];
  394. if (zbv != null)
  395. {
  396. ret = zbv as UnitBuff;
  397. }
  398. }
  399. }
  400. return ret;
  401. }
  402. /// <summary>
  403. /// 判断是否可放技能.
  404. /// </summary>
  405. /// <param name="skill"></param>
  406. /// <returns></returns>
  407. public virtual bool TryLaunchSkill(InstanceUnit.SkillState skill, ref InstanceUnit.LaunchSkillParam param)
  408. {
  409. #region
  410. if (!this.mUnit.IsCanLaunchSkill(skill.ID))
  411. {
  412. SendMsgToClient(CommonAI.XmdsConstConfig.TIPS_CAN_NOT_USE_SKILL);
  413. return false;
  414. }
  415. if (this.mUnit.IsCannotMove && skill.Data.ActionPriority < 0)
  416. {
  417. SendMsgToClient(CommonAI.XmdsConstConfig.CANNOT_LAUNCH_DISPACEMENTSKILL);
  418. return false;
  419. }
  420. //需要的能量是否足够(战士某些技能需要怒气)
  421. if(!this.LaunchSkillCheckTalentInfo(skill))
  422. {
  423. return false;
  424. }
  425. #endregion
  426. #region 普攻不能取消普攻.
  427. //TODO 屏蔽普攻不能取消普攻.
  428. /*
  429. if (this.mUnit.CurrentState is InstanceUnit.StateSkill)
  430. {
  431. if ((this.mUnit.CurrentState as InstanceUnit.StateSkill).SkillData.ID == skill.ID)
  432. {
  433. if (skill.Data.IsManuallyCancelable == false)
  434. {
  435. return false;
  436. }
  437. else
  438. {
  439. //直接交由skillstate.tryluanch判断.
  440. return true;
  441. }
  442. }
  443. }
  444. */
  445. #endregion
  446. //坐骑状态检查,如果是坐骑状态,主动切换骑乘.
  447. MountOnLaunchSkillCheck();
  448. bool ret = false;
  449. //XmdsSkillProperties prop = (XmdsSkillProperties)skill.Data.Properties;
  450. //if (prop.IsRandomNormalAttack)
  451. //{
  452. // skill.SetAutoIncreaseActionIndex(false);
  453. // byte k = (byte)(this.mUnit.RandomN.Next(0, skill.Data.ActionQueue.Count));
  454. // skill.SetActionIndex(k);
  455. //}
  456. DispatchTryLaunchSkillEvent(ref skill, ref ret, ref param);
  457. // 存储多段式技能判定
  458. if (ret && skill.CanStoreTimes)
  459. {
  460. ret = skill.OveryLayer > 0;
  461. }
  462. return ret;
  463. }
  464. /** 检测技能天赋信息 */
  465. public bool LaunchSkillCheckTalentInfo(InstanceUnit.SkillState skill)
  466. {
  467. //需要的能量是否足够(战士某些技能需要怒气)
  468. if (this.mUnit.IsPlayer && skill.ActionIndex == -1 && (this.GetUnitPro() == XmdsUnitPro.Sword || this.GetUnitPro() == XmdsUnitPro.Magic))
  469. {
  470. XmdsSkillValue data = XmdsGlobalData.GetTalentData(skill.Data.ID);
  471. if (data != null)
  472. {
  473. //天赋值
  474. if (data.GetValue(1) > 0 && this.Talent_Value() < data.GetValue(1))
  475. {
  476. return false;
  477. }
  478. //天赋等级
  479. if (!data.IsSingleCfg() && data.GetValue(2) > 0 && this.Talent_Lv() < data.GetValue(2))
  480. {
  481. return false;
  482. }
  483. }
  484. }
  485. return true;
  486. }
  487. #region 技能监听回调.
  488. //技能成功施放回调.
  489. private long mPreLaunchTime;
  490. private void OnLaunchSkillHandler(InstanceUnit obj, CommonAI.Zone.Instance.InstanceUnit.SkillState skill)
  491. {
  492. XmdsSkillProperties skillProp = skill.Data.Properties as XmdsSkillProperties;
  493. //增加Buff判断,部分buff效果可使技能使用效果发生变更.
  494. DispatchLaunchsSkillOverEvent(this, skill);
  495. //天赋点扣除
  496. if (this.mUnit.IsPlayer && skill.ActionIndex <= 0 && (this.GetUnitPro() == XmdsUnitPro.Sword || this.GetUnitPro() == XmdsUnitPro.Magic))
  497. {
  498. XmdsSkillValue data = XmdsGlobalData.GetTalentData(skill.Data.ID);
  499. if (data != null && data.GetValue() > 0)
  500. {
  501. if (!this.Talent_Use(data.GetValue()))
  502. {
  503. long timePass = System.DateTime.Now.Ticks - mPreLaunchTime;
  504. log.Warn("天赋扣除异常:" + this.mUnit.PlayerUUID + ", SceneID: " + this.mUnit.Parent.GetSceneID() + ", " + timePass);
  505. }
  506. }
  507. }
  508. //能量扣除.
  509. //mUnit.AddMP(-cost);
  510. mPreLaunchTime = System.DateTime.Now.Ticks;
  511. }
  512. //回调增加技能.
  513. private void OnSkillAddHandler(InstanceUnit unit, CommonAI.Zone.Instance.InstanceUnit.SkillState sk)
  514. {
  515. }
  516. //回调移除技能.
  517. private void OnSkillRemoveHandler(InstanceUnit unit, CommonAI.Zone.Instance.InstanceUnit.SkillState sk)
  518. {
  519. if (mSkillHelper != null)
  520. {
  521. mSkillHelper.RemoveSkill(sk);
  522. }
  523. }
  524. //状态机切换.
  525. private void OnStateChangedHandler(InstanceUnit obj, InstanceUnit.State old_state, InstanceUnit.State new_state)
  526. {
  527. if (old_state != null && old_state is InstanceUnit.StateSkill)
  528. {
  529. InstanceUnit.StateSkill stateSkill = old_state as InstanceUnit.StateSkill;
  530. //获得技能ID.
  531. int id = stateSkill.SkillData.ID;
  532. DispatchStateSkillEndEvent(this, stateSkill);
  533. }
  534. if (new_state is InstanceUnit.StatePickObject)
  535. {
  536. TakeOffMount();
  537. }
  538. }
  539. private void OnSkillHitTargetHandler()
  540. {
  541. //吸血,待完善
  542. }
  543. #endregion
  544. /// <summary>
  545. /// 检查当前buff状态,是否可添加.
  546. /// </summary>
  547. /// <returns></returns>
  548. private bool CanAddBuff(ref BuffTemplate buff, XmdsVirtual target)
  549. {
  550. bool ret = false;
  551. //获取当前BUFF是哪种能力.
  552. XmdsBuffProperties prop = buff.Properties as XmdsBuffProperties;
  553. //XmdsBuffProperties.XmdsBuffAbility ab = prop.BuffAbilityList;
  554. ////判断该种BUFF是否被约束.
  555. //switch (ab)
  556. //{
  557. // case XmdsBuffProperties.XmdsBuffAbility.FROZEN:
  558. // case XmdsBuffProperties.XmdsBuffAbility.STUN:
  559. // case XmdsBuffProperties.XmdsBuffAbility.Silent:
  560. // break;
  561. // default: break;
  562. //}
  563. return ret;
  564. }
  565. /// <summary>
  566. /// 外部获取当前技能状态信息,排除被动技能
  567. /// </summary>
  568. /// <returns></returns>
  569. public XmdsSkillStatusData GetSkillStatusData()
  570. {
  571. XmdsSkillStatusData ret = new XmdsSkillStatusData();
  572. ret.SkillTimestampMSMap = new HashMap<int, long>();
  573. //生成同步时间戳.
  574. long SkillTimestampMS = TimeUtil.GetTimestampMS();
  575. IEnumerable<InstanceUnit.SkillState> sslist = mUnit.SkillStatus;
  576. //主动技能.
  577. foreach (InstanceUnit.SkillState s in sslist)
  578. {
  579. if (s.ActionIndex > 0 && s.IsHasNext())
  580. {
  581. s.ForceIntoCD();
  582. }
  583. if(s.GetSkillType() == XmdsSkillType.cardSkill)
  584. {
  585. continue;
  586. }
  587. ret.SkillTimestampMSMap.Add(s.ID, SkillTimestampMS + s.TotalCDTime - s.PassTime);
  588. }
  589. //被动技能.
  590. //if (SkillHelper.mPassiveSkills != null)
  591. //{
  592. // for (int i = 0; i < SkillHelper.mPassiveSkills.Count; i++)
  593. // {
  594. // UnitPassiveSkill ups = SkillHelper.mPassiveSkills[i];
  595. // ret.SkillTimestampMSMap.Add(ups.SkillID, SkillTimestampMS + ups.GetCDTotalTime() - ups.GetCDPassTime());
  596. // }
  597. //}
  598. return ret;
  599. }
  600. public long GetSkillTimestampMS(int skillID)
  601. {
  602. InstanceUnit.SkillState ss = this.mUnit.getSkillState(skillID);
  603. if (ss != null)
  604. {
  605. long SkillTimestampMS = TimeUtil.GetTimestampMS() + ss.TotalCDTime - ss.PassTime;
  606. return SkillTimestampMS;
  607. }
  608. return 0;
  609. }
  610. private int CalSkillCDTime(long timestamp)
  611. {
  612. long curTime = TimeUtil.GetTimestampMS();
  613. long dif = timestamp - curTime;
  614. return (int)dif;
  615. }
  616. private InstanceUnit.SkillState SetSkillCD(int skillid, long timestamp)
  617. {
  618. InstanceUnit.SkillState ss = this.mUnit.getSkillState(skillid);
  619. if (ss == null)
  620. {
  621. return null;
  622. }
  623. int time = CalSkillCDTime(timestamp);
  624. //大于0代表还处于CD中.
  625. if (time > 0 && time <= ss.TotalCDTime)
  626. {
  627. ss.IsInMutilTime = false;
  628. this.mUnit.SetSkillPassTime(skillid, ss.TotalCDTime - time);
  629. }
  630. return ss;
  631. }
  632. private void SetSkillCDDecreasePercent(int skillid, int percent)
  633. {
  634. if (percent == 0)
  635. {
  636. return;
  637. }
  638. InstanceUnit.SkillState ss = this.mUnit.getSkillState(skillid);
  639. if (ss == null)
  640. {
  641. return;
  642. }
  643. int cd = ss.Data.CoolDownMS;
  644. int dt = (int)(cd * (percent * 1.0f / XmdsDamageCalculator.PERER));
  645. ss.AddDecreaseTotalTimeMS(dt);
  646. }
  647. public void DestorySkill()
  648. {
  649. if (mSkillHelper != null)
  650. {
  651. mSkillHelper.Dispose();
  652. mSkillHelper = null;
  653. }
  654. foreach (var buf in mTrySendBuff.Values)
  655. {
  656. var bvlist = (buf.Properties as XmdsBuffProperties).GetBuffVirtualList();
  657. foreach (var bv in bvlist)
  658. {
  659. bv.Dispose();
  660. }
  661. bvlist.Clear();
  662. }
  663. mTrySendBuff.Clear();
  664. mTrySendSpell.Clear();
  665. }
  666. /// <summary>
  667. /// 技能信息辅助类.
  668. /// </summary>
  669. public class XmdsSkillHelper
  670. {
  671. //普通技能.
  672. private SkillTemplate mBaseSkill = null;
  673. //单位拥有的技能.
  674. private HashMap<int, GameSkill> mSkillMap = null;
  675. //单位自己的主动技能模板.
  676. private HashMap<int, SkillTemplate> mActiveSkillTemplateMap = null;
  677. //单位拥有的被动技能.
  678. internal List<UnitPassiveSkill> mPassiveSkills = null;
  679. //单位拥有的主动技能.
  680. internal List<UnitSkill> mActiveSkills = null;
  681. //宿主.
  682. private XmdsVirtual mOwner = null;
  683. public XmdsSkillHelper()
  684. {
  685. //主动技能表.
  686. if (mActiveSkillTemplateMap == null)
  687. {
  688. mActiveSkillTemplateMap = new HashMap<int, SkillTemplate>();
  689. }
  690. if (mActiveSkills == null)
  691. {
  692. mActiveSkills = new List<UnitSkill>();
  693. }
  694. }
  695. public void InitSkill(XmdsUnitSkillInfo sks, XmdsVirtual owner)
  696. {
  697. if (mSkillMap != null) { mSkillMap.Clear(); }
  698. else { mSkillMap = new HashMap<int, GameSkill>(); }
  699. mOwner = owner;
  700. //主动技能初始化.
  701. if (sks != null)
  702. {
  703. InitSkill(sks.UnitSkills);
  704. }
  705. }
  706. public String GetAllSkills()
  707. {
  708. String skillText = "";
  709. foreach (KeyValuePair<int, GameSkill> pair in mSkillMap)
  710. {
  711. skillText += pair.Key + ", ";
  712. }
  713. return skillText;
  714. }
  715. /// <summary>
  716. /// 获得主动、被动技能列表.
  717. /// </summary>
  718. /// <param name="src"></param>
  719. /// <param name="active"></param>
  720. /// <param name="passive"></param>
  721. private void GetActivePassiveSkillList(List<GameSkill> src, ref List<GameSkill> active, ref List<GameSkill> passive)
  722. {
  723. GameSkill gs = null;
  724. for (int i = 0; i < src.Count; i++)
  725. {
  726. gs = src[i];
  727. if (JSGModule.IsActiveSkill(gs.SkillType))
  728. {
  729. active.Add(gs);
  730. }
  731. else if (JSGModule.IsPassiveSkill(gs.SkillType))
  732. {
  733. passive.Add(gs);
  734. }
  735. }
  736. }
  737. #region 主动技能.
  738. /// <summary>
  739. /// 初始化主动技能.
  740. /// </summary>
  741. /// <param name="gameSkills"></param>
  742. public void InitActiveSkills(List<GameSkill> gameSkills)
  743. {
  744. try
  745. {
  746. if (gameSkills == null || gameSkills.Count == 0) { return; }
  747. //需要判断BUFF状态,记录单位技能信息.
  748. GameSkill gs = null;
  749. UnitSkill us = null;
  750. SkillTemplate st = null;
  751. for (int i = 0; i < gameSkills.Count; i++)
  752. {
  753. gs = gameSkills[i];
  754. if (mSkillMap.ContainsKey(gameSkills[i].SkillID))
  755. {
  756. continue;
  757. }
  758. //主动技能初始化只有初始化成功的技能会在技能MAP中.
  759. //存放技能等级信息.
  760. mSkillMap.Add(gameSkills[i].SkillID, gameSkills[i]);
  761. us = InitXmdsSkillScript(gs, ref st);
  762. if (us != null && st != null)
  763. {
  764. mActiveSkillTemplateMap.Add(st.ID, st);
  765. //UnitSkill us = XmdsBattleSkill.GetUnitSkill(gs.SkillID);
  766. mActiveSkills.Add(us);
  767. //if(st.ID != us.SkillID)
  768. //{
  769. // log.Warn("初始化技能,使用脚本不一致, 技能" + st.ID + ", 使用:" + us.SkillID);
  770. //}
  771. }
  772. else
  773. {
  774. FormatLog(string.Format("XmdsVirtual.Skill can not find SkillScript {0},", gs.SkillID));
  775. }
  776. }
  777. #region 重置单位技能.
  778. List<SkillTemplate> temp = new List<SkillTemplate>();
  779. for (int i = 0; i < gameSkills.Count; i++)
  780. {
  781. gs = gameSkills[i];
  782. if (mActiveSkillTemplateMap.TryGetValue(gs.SkillID, out st))
  783. {
  784. //分辨出普通攻击.
  785. if (gs.SkillType == XmdsSkillType.normalAtk)
  786. {
  787. mBaseSkill = st;
  788. }
  789. else
  790. {
  791. temp.Add(st);
  792. }
  793. }
  794. }
  795. if (temp.Count > 0 || mBaseSkill != null)
  796. {
  797. //重置技能.
  798. mOwner.mUnit.InitSkills(mBaseSkill, temp.ToArray());
  799. }
  800. for (int i = 0; i < temp.Count; i++)
  801. {
  802. if (mSkillMap.TryGetValue(temp[i].ID, out gs))
  803. {
  804. mOwner.SetSkillCD(temp[i].ID, gs.SkillTimestampMS);
  805. mOwner.SetSkillCDDecreasePercent(temp[i].ID, gs.SkillCDDecreasePercent);
  806. // 人物, 宠物的技能是否自动释放走配置表
  807. if (mOwner is XmdsVirtual_Player || mOwner is XmdsVirtual_Pet)
  808. {
  809. SkillState skillState = mOwner.mUnit.getSkillState(temp[i].ID);
  810. if (skillState != null)
  811. {
  812. skillState.setAutoLaunch(gs.AutoLaunch);
  813. }
  814. }
  815. }
  816. }
  817. //UnitSkillList.Clear();
  818. //UnitSkillList = null;
  819. #endregion
  820. }
  821. catch (Exception error)
  822. {
  823. FormatLog(CommonLang.Log.LoggerLevel.ERROR, "单位【{0}】初始化技能错误:{1}", mOwner.mInfo.Name, error.ToString());
  824. }
  825. }
  826. public void notifyActiveSkillInitOver(List<GameSkill> gameSkills)
  827. {
  828. if (mActiveSkills == null)
  829. {
  830. return;
  831. }
  832. for (int i = 0; i < mActiveSkills.Count; i++)
  833. {
  834. GameSkill gameSkill = null;
  835. for (int j = 0; j < gameSkills.Count; j++)
  836. {
  837. if (mActiveSkills[i].SkillID == gameSkills[j].SkillID)
  838. {
  839. gameSkill = gameSkills[j];
  840. break;
  841. }
  842. }
  843. mActiveSkills[i].InitOver(mOwner, gameSkill);
  844. }
  845. }
  846. public void notifyPassiveSkillInitOver(List<GameSkill> gameSkills)
  847. {
  848. if (mPassiveSkills == null)
  849. {
  850. return;
  851. }
  852. for (int i = 0; i < mPassiveSkills.Count; i++)
  853. {
  854. GameSkill gameSkill = null;
  855. for (int j = 0; j < gameSkills.Count; j++)
  856. {
  857. if (mPassiveSkills[i].SkillID == gameSkills[j].SkillID)
  858. {
  859. gameSkill = gameSkills[j];
  860. break;
  861. }
  862. }
  863. mPassiveSkills[i].InitOver(mOwner, gameSkill);
  864. }
  865. }
  866. //public bool changeActiveSkill(int oldSkillID, int newSkillID)
  867. //{
  868. // try
  869. // {
  870. // if (oldSkillID == 0 || oldSkillID == newSkillID)
  871. // {
  872. // return false;
  873. // }
  874. // GameSkill oldSkill = mSkillMap.Get(oldSkillID);
  875. // GameSkill newSkill = mSkillMap.Get(newSkillID);
  876. // if (oldSkill == null || newSkill != null)
  877. // {
  878. // return false;
  879. // }
  880. // oldSkill.SkillID = newSkillID;
  881. // newSkill = oldSkill;
  882. // SkillTemplate st = null;
  883. // UnitSkill us = InitXmdsSkillScript(newSkill, ref st);
  884. // if (us == null || st == null)
  885. // {
  886. // FormatLog(string.Format("XmdsVirtual.Skill can not find SkillScript {0},", newSkill.SkillID));
  887. // return false;
  888. // }
  889. // mSkillMap.Remove(oldSkillID);
  890. // mSkillMap.Add(newSkillID, newSkill);
  891. // mActiveSkillTemplateMap.Remove(oldSkillID);
  892. // mActiveSkillTemplateMap.Add(us.SkillID, st);
  893. // for (int i = 0; i < mActiveSkills.Count; i++)
  894. // {
  895. // if (mActiveSkills[i].SkillID == oldSkillID)
  896. // {
  897. // mActiveSkills.RemoveAt(i);
  898. // mActiveSkills.Add(us);
  899. // break;
  900. // }
  901. // }
  902. // #region 重置单位技能.
  903. // List<SkillTemplate> temp = new List<SkillTemplate>();
  904. // if (mActiveSkillTemplateMap.TryGetValue(newSkillID, out st))
  905. // {
  906. // //分辨出普通攻击.
  907. // if (newSkill.SkillType == XmdsSkillType.normalAtk)
  908. // {
  909. // mBaseSkill = st;
  910. // }
  911. // else
  912. // {
  913. // temp.Add(st);
  914. // }
  915. // }
  916. // if (temp.Count > 0 || mBaseSkill != null)
  917. // {
  918. // //重置技能.
  919. // mOwner.mUnit.InitSkills(mBaseSkill, temp.ToArray());
  920. // }
  921. // // 人物, 宠物的技能是否自动释放走配置表
  922. // if (mOwner is XmdsVirtual_Player || mOwner is XmdsVirtual_Pet)
  923. // {
  924. // SkillState skillState = mOwner.mUnit.getSkillState(newSkill.SkillID);
  925. // if (skillState != null)
  926. // {
  927. // skillState.setAutoLaunch(newSkill.AutoLaunch);
  928. // }
  929. // }
  930. // mOwner.SetSkillCD(st.ID, newSkill.SkillTimestampMS);
  931. // mOwner.SetSkillCDDecreasePercent(st.ID, newSkill.SkillCDDecreasePercent);
  932. // for (int i = 0; i < mActiveSkills.Count; i++)
  933. // {
  934. // if (mActiveSkills[i].SkillID == newSkillID)
  935. // {
  936. // mActiveSkills[i].InitOver(mOwner, newSkill);
  937. // break;
  938. // }
  939. // }
  940. // #endregion
  941. // }
  942. // catch (Exception error)
  943. // {
  944. // FormatLog(CommonLang.Log.LoggerLevel.ERROR, "单位【{0}】初始化技能错误:{1}", mOwner.mInfo.Name, error.ToString());
  945. // return false;
  946. // }
  947. // return true;
  948. //}
  949. private UnitSkill InitXmdsSkillScript(GameSkill gs, ref SkillTemplate st)
  950. {
  951. UnitSkill us = null;
  952. try
  953. {
  954. //获取技能脚本.
  955. us = XmdsBattleSkill.GetUnitSkill(gs.SkillID);
  956. //如果UnitSkill为NULL,则读取默认脚本.
  957. if (us == null)
  958. {
  959. //FormatLog(CommonLang.Log.LoggerLevel.INFO, string.Format("单位{0}主动技能{1}未找到脚本,使用默认脚本代替", mOwner.mInfo.TemplateID, gs.SkillID));
  960. us = XmdsBattleSkill.GetUnitSkill(XmdsBattleSkill.DefaultSkillScriptID);
  961. // 宠物或者人物如果没有配置对应的技能文件,就设置为不自动释放技能
  962. if (this.mOwner is XmdsVirtual_Pet || this.mOwner is XmdsVirtual_Player)
  963. {
  964. gs.AutoLaunch = false;
  965. }
  966. }
  967. //主动技能特殊逻辑初始化.
  968. st = XmdsBattleSkill.GetSkillTemplate(gs.SkillID);
  969. if (st == null)
  970. {
  971. FormatLog(CommonLang.Log.LoggerLevel.ERROR, string.Format("未找到技能模板{0}", gs.SkillID));
  972. }
  973. //对技能进行脚本重铸.
  974. us.Init(gs, mOwner, ref st);
  975. }
  976. catch (Exception err)
  977. {
  978. log.Error("InitXmdsSkillScript异常, 技能id" + gs.SkillID + ", 单位ID: " + mOwner.mInfo.TemplateID + ", e : " + err);
  979. }
  980. return us;
  981. }
  982. #endregion
  983. #region 被动技能技能.
  984. //初始化被动技能.
  985. public void InitPassiveSkills(List<GameSkill> skills)
  986. {
  987. try
  988. {
  989. if (skills == null || skills.Count == 0) { return; }
  990. mPassiveSkills = new List<UnitPassiveSkill>();
  991. UnitPassiveSkill sk = null;
  992. for (int i = 0; i < skills.Count; i++)
  993. {
  994. if (mSkillMap.ContainsKey(skills[i].SkillID))
  995. {
  996. continue;
  997. }
  998. sk = InitXmdsPassiveSkillScript(skills[i]);
  999. mSkillMap.Add(skills[i].SkillID, skills[i]);
  1000. mPassiveSkills.Add(sk);
  1001. SetPassiveSkillCD(sk, skills[i].SkillTimestampMS);
  1002. SetPassiveSkillCDDecrease(sk, skills[i].SkillCDDecreasePercent);
  1003. }
  1004. }
  1005. catch (Exception error)
  1006. {
  1007. FormatLog(CommonLang.Log.LoggerLevel.ERROR, "单位【{0}】初始化被动技能错误:{1}", mOwner.mInfo.Name, error.ToString());
  1008. }
  1009. }
  1010. private void SetPassiveSkillCD(UnitPassiveSkill sk, long timestamp)
  1011. {
  1012. int time = mOwner.CalSkillCDTime(timestamp);
  1013. //大于0代表还处于CD中.
  1014. if (time > 0 && time <= sk.GetCDTotalTime())
  1015. {
  1016. sk.SetCDPassTime(sk.GetCDTotalTime() - time);
  1017. }
  1018. }
  1019. private void SetPassiveSkillCDDecrease(UnitPassiveSkill sk, int timeMS)
  1020. {
  1021. if (sk != null)
  1022. {
  1023. int t = (int)(timeMS * 1.0f / XmdsDamageCalculator.PERER);
  1024. int oldt = sk.GetDecreaseTotalTimeMS();
  1025. int newt = oldt + t;
  1026. sk.SetDecreaseTotalTimeMS(newt);
  1027. }
  1028. }
  1029. //初始化被动技能脚本.
  1030. private UnitPassiveSkill InitXmdsPassiveSkillScript(GameSkill gs)
  1031. {
  1032. UnitPassiveSkill ret = null;
  1033. try
  1034. {
  1035. ret = XmdsBattleSkill.GetPassiveSkill(gs.SkillID);
  1036. if (ret == null)
  1037. {
  1038. throw new Exception("被动技能脚本未找到:" + this.mOwner.mUnit.PlayerUUID);
  1039. }
  1040. else
  1041. {
  1042. ret.Init(gs, mOwner);
  1043. }
  1044. }
  1045. catch (Exception err)
  1046. {
  1047. ThrowXmdsException(gs.SkillID, mOwner.mInfo.TemplateID, err.ToString());
  1048. }
  1049. return ret;
  1050. }
  1051. /// <summary>
  1052. /// 报错方法.
  1053. /// </summary>
  1054. /// <param name="skill"></param>
  1055. /// <param name="unit"></param>
  1056. /// <param name="error"></param>
  1057. private void ThrowXmdsException(int skill, int unit, string error)
  1058. {
  1059. string msg = string.Format("XmdsSkill Init Error id : SkillID = {0} UnitID = {1},Error = {2}", skill, unit, error.ToString());
  1060. log.Error(msg);
  1061. throw new Exception(msg);
  1062. }
  1063. //更新技能状态.
  1064. private void UpdatePassiveSkills(int intervalMS, bool slowRefresh)
  1065. {
  1066. if (mPassiveSkills != null)
  1067. {
  1068. for (int i = 0; i < mPassiveSkills.Count; i++)
  1069. {
  1070. mPassiveSkills[i].Update(intervalMS, slowRefresh);
  1071. }
  1072. }
  1073. }
  1074. private void UpdateActiveSkills(int intervalMS, bool slowRefresh)
  1075. {
  1076. if (mActiveSkills != null)
  1077. {
  1078. for (int i = 0; i < mActiveSkills.Count; i++)
  1079. {
  1080. UnitSkill skillInfo = mActiveSkills[i];
  1081. if (skillInfo == null || !skillInfo.IsActive)
  1082. {
  1083. continue;
  1084. }
  1085. skillInfo.Update(intervalMS, slowRefresh);
  1086. }
  1087. }
  1088. }
  1089. #endregion
  1090. #region 常用API.
  1091. /// <summary>
  1092. /// 是否有该技能.
  1093. /// </summary>
  1094. /// <param name="id"></param>
  1095. /// <returns></returns>
  1096. public bool ContainSkill(int id)
  1097. {
  1098. return mSkillMap.ContainsKey(id);
  1099. }
  1100. /// <summary>
  1101. /// 获取技能信息.
  1102. /// </summary>
  1103. /// <param name="id"></param>
  1104. /// <returns></returns>
  1105. public GameSkill GetGameSkill(int id)
  1106. {
  1107. GameSkill ret = null;
  1108. mSkillMap.TryGetValue(id, out ret);
  1109. return ret;
  1110. }
  1111. //获取玩家技能
  1112. public UnitSkill GetPlayerSkillById(int skillId)
  1113. {
  1114. if (mActiveSkills == null)
  1115. {
  1116. return null;
  1117. }
  1118. for (int i = 0; i < mActiveSkills.Count; i++)
  1119. {
  1120. if (mActiveSkills[i].SkillID == skillId)
  1121. {
  1122. return mActiveSkills[i];
  1123. }
  1124. }
  1125. return null;
  1126. }
  1127. //获取玩家技能
  1128. public UnitPassiveSkill GetPlayerSkillByIdExt(int skillId)
  1129. {
  1130. if (mPassiveSkills == null)
  1131. {
  1132. return null;
  1133. }
  1134. for (int i = 0; i < mPassiveSkills.Count; i++)
  1135. {
  1136. if (mPassiveSkills[i].SkillID == skillId)
  1137. {
  1138. return mPassiveSkills[i];
  1139. }
  1140. }
  1141. return null;
  1142. }
  1143. /// <summary>
  1144. /// 获取主动技能模板.
  1145. /// </summary>
  1146. /// <param name="id"></param>
  1147. /// <returns></returns>
  1148. public SkillTemplate GetUnitSkillTemplate(int id)
  1149. {
  1150. SkillTemplate ret = null;
  1151. mActiveSkillTemplateMap.TryGetValue(id, out ret);
  1152. return ret;
  1153. }
  1154. public void RemoveSkill(CommonAI.Zone.Instance.InstanceUnit.SkillState sk)
  1155. {
  1156. if (mSkillMap != null)
  1157. {
  1158. GameSkill gs = null;
  1159. if (mSkillMap.TryGetValue(sk.ID, out gs))
  1160. {
  1161. mOwner.RemoveEventBySkillID(gs.SkillID);
  1162. mSkillMap.Remove(sk.ID);
  1163. }
  1164. for (int i = 0; i < mActiveSkills.Count; i++)
  1165. {
  1166. if (mActiveSkills[i].SkillID == sk.ID)
  1167. {
  1168. mActiveSkills.RemoveAt(i);
  1169. break;
  1170. }
  1171. }
  1172. }
  1173. if (mActiveSkillTemplateMap != null)
  1174. {
  1175. mActiveSkillTemplateMap.RemoveByKey(sk.ID);
  1176. mActiveSkillTemplateMap.Remove(sk.ID);
  1177. }
  1178. }
  1179. public void Update(int intervalMS, bool slowRefresh)
  1180. {
  1181. UpdatePassiveSkills(intervalMS, slowRefresh);
  1182. //2021.11.02优化:主动技能慢刷新,打开需要注明原因
  1183. if(slowRefresh)
  1184. {
  1185. UpdateActiveSkills(intervalMS, slowRefresh);
  1186. }
  1187. }
  1188. public int GetBaseSkillID()
  1189. {
  1190. if (mBaseSkill != null)
  1191. {
  1192. return mBaseSkill.ID;
  1193. }
  1194. return 0;
  1195. }
  1196. /// <summary>
  1197. /// 增加技能.
  1198. /// </summary>
  1199. /// <param name="list"></param>
  1200. public void AddSkill(List<GameSkill> list)
  1201. {
  1202. if (list != null && list.Count > 0)
  1203. {
  1204. List<GameSkill> active = new List<GameSkill>();
  1205. List<GameSkill> passive = new List<GameSkill>();
  1206. GetActivePassiveSkillList(list, ref active, ref passive);
  1207. GameSkill gs = null;
  1208. //主动技能.
  1209. for (int i = 0; i < active.Count; i++)
  1210. {
  1211. gs = active[i];
  1212. AddActiveSkill(gs);
  1213. }
  1214. for (int i = 0; i < passive.Count; i++)
  1215. {
  1216. gs = passive[i];
  1217. AddPassiveSkill(gs);
  1218. }
  1219. }
  1220. }
  1221. public UnitSkill AddActiveSkill(GameSkill gs, bool is_default = false)
  1222. {
  1223. SkillTemplate st = null;
  1224. UnitSkill us = null;
  1225. //存放技能等级信息.
  1226. mSkillMap.Put(gs.SkillID, gs);
  1227. us = InitXmdsSkillScript(gs, ref st);
  1228. if (st != null)
  1229. {
  1230. if (mActiveSkillTemplateMap == null)
  1231. {
  1232. mActiveSkillTemplateMap = new HashMap<int, SkillTemplate>();
  1233. }
  1234. mActiveSkillTemplateMap.Put(st.ID, st);
  1235. //us = XmdsBattleSkill.GetUnitSkill(gs.SkillID);
  1236. mOwner.mUnit.AddSkill(st, gs.AutoLaunch, is_default);
  1237. SkillState skillState = mOwner.SetSkillCD(gs.SkillID, gs.SkillTimestampMS);
  1238. mOwner.SetSkillCDDecreasePercent(gs.SkillID, gs.SkillCDDecreasePercent);
  1239. if (skillState != null)
  1240. {
  1241. skillState.Reset(true);
  1242. }
  1243. if (us != null)
  1244. {
  1245. mActiveSkills.Add(us);
  1246. us.InitOver(mOwner, gs);
  1247. }
  1248. }
  1249. return us;
  1250. }
  1251. public UnitPassiveSkill AddPassiveSkill(GameSkill gs)
  1252. {
  1253. UnitPassiveSkill ups = InitXmdsPassiveSkillScript(gs);
  1254. mSkillMap.Put(gs.SkillID, gs);
  1255. SetPassiveSkillCD(ups, gs.SkillTimestampMS);
  1256. SetPassiveSkillCDDecrease(ups, gs.SkillCDDecreasePercent);
  1257. if (mPassiveSkills == null)
  1258. {
  1259. mPassiveSkills = new List<UnitPassiveSkill>();
  1260. }
  1261. mPassiveSkills.Add(ups);
  1262. ups.InitOver(mOwner, gs);
  1263. return ups;
  1264. }
  1265. /// <summary>
  1266. /// 减少技能.
  1267. /// </summary>
  1268. /// <param name="list"></param>
  1269. public void RemoveSkill(List<GameSkill> list)
  1270. {
  1271. if (list != null && list.Count > 0)
  1272. {
  1273. List<GameSkill> active = new List<GameSkill>();
  1274. List<GameSkill> passive = new List<GameSkill>();
  1275. GetActivePassiveSkillList(list, ref active, ref passive);
  1276. GameSkill gs = null;
  1277. //主动技能.
  1278. for (int i = 0; i < active.Count; i++)
  1279. {
  1280. gs = active[i];
  1281. RemoveActiveSkill(gs.SkillID);
  1282. }
  1283. //删除被动技能.
  1284. for (int i = 0; i < passive.Count; i++)
  1285. {
  1286. if (mSkillMap.TryGetValue(passive[i].SkillID, out gs))
  1287. {
  1288. RemovePassiveSkill(gs.SkillID);
  1289. }
  1290. }
  1291. }
  1292. }
  1293. public void RemoveActiveSkill(int skillID)
  1294. {
  1295. if (mBaseSkill != null && skillID == mBaseSkill.ID)
  1296. {
  1297. mBaseSkill = null;
  1298. }
  1299. mOwner.mUnit.RemoveSkill(skillID); //调用该API收到remove事件再删除技能.
  1300. }
  1301. public void RemovePassiveSkill(int skillID)
  1302. {
  1303. mSkillMap.RemoveByKey(skillID);
  1304. for (int k = 0; k < mPassiveSkills.Count; k++)
  1305. {
  1306. if (mPassiveSkills[k].SkillID == skillID)
  1307. {
  1308. mPassiveSkills[k].Dispose(mOwner);
  1309. mPassiveSkills.RemoveAt(k);
  1310. mOwner.RemoveEventBySkillID(skillID);
  1311. break;
  1312. }
  1313. }
  1314. }
  1315. /// <summary>
  1316. /// 初始化技能.
  1317. /// </summary>
  1318. /// <param name="list"></param>
  1319. private void InitSkill(List<GameSkill> list)
  1320. {
  1321. List<GameSkill> active = new List<GameSkill>();
  1322. List<GameSkill> passive = new List<GameSkill>();
  1323. if (list.Count == 0)
  1324. {
  1325. return;
  1326. }
  1327. else if (this.mOwner.mUnit.IsPlayer)
  1328. {
  1329. //玩家有一些特殊的逻辑放到天赋被动里面
  1330. }
  1331. GetActivePassiveSkillList(list, ref active, ref passive);
  1332. InitPassiveSkills(passive);
  1333. InitActiveSkills(active);
  1334. //通知技能,初始化完成
  1335. notifyActiveSkillInitOver(active);
  1336. notifyPassiveSkillInitOver(passive);
  1337. this.mOwner.InitCardModule();
  1338. }
  1339. /// <summary>
  1340. /// 重置技能.
  1341. /// </summary>
  1342. /// <param name="list"></param>
  1343. public void ResetSkill(List<GameSkill> list, XmdsVirtual owner)
  1344. {
  1345. //1清除所有技能.
  1346. ClearSkill();
  1347. if (mSkillMap == null)
  1348. {
  1349. mSkillMap = new HashMap<int, GameSkill>();
  1350. }
  1351. mOwner = owner;
  1352. //2重新初始化技能.
  1353. InitSkill(list);
  1354. }
  1355. public void ReplaceSkill(List<GameSkill> list)
  1356. {
  1357. if (list == null) { return; }
  1358. GameSkill gs = null;
  1359. GameSkill new_gs = null;
  1360. for (int i = 0; i < list.Count; i++)
  1361. {
  1362. new_gs = list[i];
  1363. gs = null;
  1364. mSkillMap.TryGetValue(new_gs.SkillID, out gs);
  1365. if (gs != null)
  1366. {
  1367. gs.SkillLevel = new_gs.SkillLevel;
  1368. gs.TalentSkillLevel1 = new_gs.TalentSkillLevel1;
  1369. gs.TalentSkillLevel2 = new_gs.TalentSkillLevel2;
  1370. gs.TalentSkillLevel3 = new_gs.TalentSkillLevel3;
  1371. if (gs.SkillType == XmdsSkillType.passive)
  1372. {
  1373. if (mPassiveSkills != null)
  1374. {
  1375. for (int k = 0; k < mPassiveSkills.Count; k++)
  1376. {
  1377. if (mPassiveSkills[k].SkillID == gs.SkillID)
  1378. {
  1379. //去除原有CD修改值.
  1380. SetPassiveSkillCDDecrease(mPassiveSkills[k], -gs.SkillCDDecreasePercent);
  1381. //重新设置CD修改值.
  1382. SetPassiveSkillCDDecrease(mPassiveSkills[k], new_gs.SkillCDDecreasePercent);
  1383. //技能效果变化.
  1384. mPassiveSkills[k].SkillDataChange(gs, mOwner);
  1385. }
  1386. }
  1387. }
  1388. }
  1389. else
  1390. {
  1391. //去除原有CD修改值.
  1392. mOwner.SetSkillCDDecreasePercent(gs.SkillID, -gs.SkillCDDecreasePercent);
  1393. //重新设置CD修改值.
  1394. mOwner.SetSkillCDDecreasePercent(new_gs.SkillID, new_gs.SkillCDDecreasePercent);
  1395. for (int k = 0; k < mActiveSkills.Count; k++)
  1396. {
  1397. if (mActiveSkills[k].SkillID == new_gs.SkillID)
  1398. {
  1399. mActiveSkills[k].SkillDataChange(new_gs, mOwner);
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. gs.SkillCDDecreasePercent = new_gs.SkillCDDecreasePercent;
  1405. }
  1406. }
  1407. }
  1408. /// <summary>
  1409. /// 清理技能.
  1410. /// </summary>
  1411. public void ClearSkill()
  1412. {
  1413. List<GameSkill> ret = new List<GameSkill>();
  1414. GameSkill g = null;
  1415. if (mSkillMap != null)
  1416. {
  1417. foreach (KeyValuePair<int, GameSkill> pair in mSkillMap)
  1418. {
  1419. g = new GameSkill();
  1420. g.SkillID = pair.Key;
  1421. g.SkillType = pair.Value.SkillType;
  1422. ret.Add(g);
  1423. }
  1424. RemoveSkill(ret);
  1425. }
  1426. }
  1427. public void Dispose()
  1428. {
  1429. ClearSkill();
  1430. mBaseSkill = null;
  1431. if (mSkillMap != null)
  1432. {
  1433. mSkillMap.Clear();
  1434. mSkillMap = null;
  1435. }
  1436. if (mActiveSkillTemplateMap != null)
  1437. {
  1438. mActiveSkillTemplateMap.Clear();
  1439. mActiveSkillTemplateMap = null;
  1440. }
  1441. if (mPassiveSkills != null)
  1442. {
  1443. mPassiveSkills.Clear();
  1444. mPassiveSkills = null;
  1445. }
  1446. mOwner = null;
  1447. }
  1448. #endregion
  1449. #region 特殊硬编码技能.
  1450. #endregion
  1451. }
  1452. /// <summary>
  1453. /// 技能状态信息.
  1454. /// </summary>
  1455. public class XmdsSkillStatusData
  1456. {
  1457. /// <summary>
  1458. /// 技能(技能ID,到期时间戳).
  1459. /// </summary>.
  1460. public HashMap<int, long> SkillTimestampMSMap = null;
  1461. }
  1462. //-----------------------职业天赋相关的接口-----------------------
  1463. public virtual IPlayerCache GetPlayerCache()
  1464. {
  1465. return this.mPlayerCache;
  1466. }
  1467. public virtual void SetPlayerCache(IPlayerCache cache)
  1468. {
  1469. this.mPlayerCache = cache;
  1470. }
  1471. public virtual void Talent__Add(int value)
  1472. {
  1473. if (this.mPlayerCache != null)
  1474. {
  1475. this.mPlayerCache.AddTalentValue(value);
  1476. }
  1477. }
  1478. public virtual bool Talent_Use(int value)
  1479. {
  1480. if (this.mPlayerCache != null)
  1481. {
  1482. return this.mPlayerCache.UseTalentValue(value);
  1483. }
  1484. return false;
  1485. }
  1486. public virtual int Talent_Value()
  1487. {
  1488. return mPlayerCache == null ? 0 : mPlayerCache.GetTalentValue();
  1489. }
  1490. public virtual int Talent_Lv()
  1491. {
  1492. return mPlayerCache == null ? 0 : mPlayerCache.GetTalentLv();
  1493. }
  1494. public virtual bool Talent_Refresh(bool notify = true)
  1495. {
  1496. if (this.mPlayerCache != null)
  1497. {
  1498. return this.mPlayerCache.Refresh(notify);
  1499. }
  1500. return false;
  1501. }
  1502. //---------------------------------------------------------------------
  1503. #region BUFF跨场景.
  1504. /*
  1505. /// <summary>
  1506. /// BUFF信息集合.
  1507. /// </summary>
  1508. public class XmdsBuffStatus
  1509. {
  1510. public List<XmdsBuffStatusData> mDatas = null;
  1511. }
  1512. /// <summary>
  1513. /// Buff状态信息.
  1514. /// </summary>
  1515. public class XmdsBuffStatusData
  1516. {
  1517. /// <summary>
  1518. /// BUFF模板.
  1519. /// </summary>
  1520. public int BuffTemplateID = 0;
  1521. /// <summary>
  1522. /// BUFF时间戳.
  1523. /// </summary>
  1524. public long BuffTimestampMS = 0;
  1525. }
  1526. */
  1527. #endregion
  1528. #region 技能API测试功能.
  1529. protected void Mock_RemoveSkill(int skillID)
  1530. {
  1531. PlayerSkillChangeEventR2B evt = new PlayerSkillChangeEventR2B();
  1532. evt.OperateID = PlayerSkillChangeEventR2B.SkillOperate.Remove;
  1533. List<GameSkill> list = new List<GameSkill>();
  1534. GameSkill gs = new GameSkill();
  1535. gs.SkillID = skillID;
  1536. list.Add(gs);
  1537. evt.SkillList = list;
  1538. OnPlayerSkillsChanged(evt);
  1539. }
  1540. protected void Mock_AddSkill(int skillID)
  1541. {
  1542. PlayerSkillChangeEventR2B evt = new PlayerSkillChangeEventR2B();
  1543. evt.OperateID = PlayerSkillChangeEventR2B.SkillOperate.Add;
  1544. List<GameSkill> list = new List<GameSkill>();
  1545. GameSkill gs = new GameSkill();
  1546. gs.SkillID = skillID;
  1547. gs.SkillLevel = 1;
  1548. gs.SkillType = XmdsSkillType.active;
  1549. list.Add(gs);
  1550. evt.SkillList = list;
  1551. OnPlayerSkillsChanged(evt);
  1552. }
  1553. protected void Mock_ResetSkill(List<GameSkill> list)
  1554. {
  1555. PlayerSkillChangeEventR2B evt = new PlayerSkillChangeEventR2B();
  1556. evt.OperateID = PlayerSkillChangeEventR2B.SkillOperate.Reset;
  1557. evt.SkillList = list;
  1558. OnPlayerSkillsChanged(evt);
  1559. }
  1560. protected void Mock_ReplaceSkill(List<GameSkill> list)
  1561. {
  1562. PlayerSkillChangeEventR2B evt = new PlayerSkillChangeEventR2B();
  1563. evt.OperateID = PlayerSkillChangeEventR2B.SkillOperate.Replace;
  1564. evt.SkillList = list;
  1565. OnPlayerSkillsChanged(evt);
  1566. }
  1567. #endregion
  1568. }
  1569. }