XmdsSkill.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Instance;
  3. using CommonAI.Zone.Formula;
  4. using CommonAI.Zone.UnitTriggers;
  5. using CommonLang;
  6. using CommonLang.Log;
  7. using CommonLang.Property;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using XmdsCommon.Plugin;
  13. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  14. using CommonAI.Data;
  15. using XmdsCommonServer.XLS.Data;
  16. using XmdsCommonSkill.Plugin.CardSkill;
  17. using XmdsCommon.JSGModule.Interface;
  18. using XmdsCommonServer.Plugin.Base;
  19. using CommonAI.Zone.Helper;
  20. namespace XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills
  21. {
  22. #region Skill.
  23. public enum AbstractSkillType
  24. {
  25. Value1 = 0, //
  26. Value2 = 1, //
  27. Value3 = 2, //
  28. Value4 = 3, //
  29. }
  30. //技能老祖.
  31. public abstract class AbstractSkill : IComparable<AbstractSkill>
  32. {
  33. public AbstractSkill()
  34. {
  35. }
  36. public abstract int SkillID { get; }
  37. public int CompareTo(AbstractSkill obj)
  38. {
  39. SkillTypeAttribute desc_a = PropertyUtil.GetAttribute<SkillTypeAttribute>(this.GetType());
  40. SkillTypeAttribute desc_b = PropertyUtil.GetAttribute<SkillTypeAttribute>(obj.GetType());
  41. int r0 = desc_a.Category.CompareTo(desc_b.Category);
  42. if (r0 != 0)
  43. {
  44. return r0;
  45. }
  46. return this.SkillID - obj.SkillID;
  47. }
  48. public abstract void SkillDataChange(GameSkill gs, XmdsVirtual unit);
  49. public abstract int GetSkillValue(AbstractSkillType type);
  50. /// <summary>
  51. /// 初始化完所有技能回调
  52. /// </summary>
  53. public virtual void InitOver(XmdsVirtual unit, GameSkill info) { OnInitOver(unit, info); }
  54. protected virtual void OnInitOver(XmdsVirtual unit, GameSkill info) { }
  55. protected void InitData(XmdsSkillData data, out XmdsSkillValue v, XmdsSkillData.XmdsSkillDataKey key)
  56. {
  57. try
  58. {
  59. v = data.GetParamValue(key);
  60. }
  61. catch (Exception error)
  62. {
  63. XmdsBattleHelper.LogError(string.Format("Skill【{0}】InitSkillParam【{1}】 \r\nError:{2}", this.SkillID, key, error.ToString()));
  64. v = XmdsSkillValue.Default;
  65. }
  66. }
  67. //接口之前相互手动调用
  68. public virtual void DoSkillDispose(int skillID) { }
  69. }
  70. //技能基类.
  71. public abstract class UnitSkill : AbstractSkill {
  72. protected static Logger log = LoggerFactory.GetLogger("XmdsBattleSkill");
  73. //技能是否激活
  74. private bool mIsActive = true;
  75. public bool IsActive{get{return this.mIsActive;} set{this.mIsActive = value;}
  76. }
  77. /// <summary>
  78. /// 初始化主动技能
  79. /// </summary>
  80. public void Init(GameSkill info, XmdsVirtual unit, ref SkillTemplate template)
  81. {
  82. OnRegistEvent();
  83. OnBaseInit(info, unit, ref template);
  84. //伤害监听.
  85. if (unit != null)
  86. {
  87. unit.RegistCalDamage(OnCallDamageProcess, info, false, this.SkillID);
  88. //技能MP消耗预判.
  89. unit.RegistTryLaunchSkillEvent(OnUnitLaunchSkillEvent, info, false);
  90. //技能MP消耗.
  91. unit.RegistLaunchSkillOver(OnUnitLaunchSkillOver, info, false);
  92. }
  93. }
  94. //只调用一次的初始化
  95. public void InitSkillParam(XmdsSkillData skillData)
  96. {
  97. OnBaseDataInit(skillData);
  98. OnInitSkillParam();
  99. }
  100. public override void SkillDataChange(GameSkill gs, XmdsVirtual unit)
  101. {
  102. OnSkillDataChange(gs, unit);
  103. }
  104. protected virtual void OnSkillDataChange(GameSkill gs, XmdsVirtual unit)
  105. {
  106. }
  107. protected virtual void OnBaseDataInit(XmdsSkillData skillData) { }
  108. protected virtual void OnInitSkillParam()
  109. {
  110. }
  111. // 每次加载技能都会调用。初始化配置,针对于人物技能多重继承
  112. protected virtual void OnInitConfig()
  113. {
  114. }
  115. protected virtual void OnRegistEvent()
  116. {
  117. }
  118. protected virtual void OnBaseInit(GameSkill info, XmdsVirtual unit, ref SkillTemplate template)
  119. {
  120. }
  121. private int OnHitProcess(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result)
  122. {
  123. int ret = 0;
  124. //技能逻辑.
  125. return ret;
  126. }
  127. /// <summary>
  128. /// 计算伤害事件结果.
  129. /// </summary>
  130. /// <param name="attacker"></param>
  131. /// <param name="hitter"></param>
  132. /// <param name="source"></param>
  133. /// <param name="gs"></param>
  134. /// <param name="result"></param>
  135. /// <returns></returns>
  136. public virtual bool OnCallDamageProcess(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result, ref int damage)
  137. {
  138. return true;
  139. }
  140. /// <summary>
  141. /// 技能施放预判断.
  142. /// </summary>
  143. /// <param name="skill"></param>
  144. /// <param name="launcher"></param>
  145. /// <returns></returns>
  146. protected virtual bool OnUnitLaunchSkillEvent(GameSkill info, ref InstanceUnit.SkillState skill, XmdsVirtual launcher, ref InstanceUnit.LaunchSkillParam param)
  147. {
  148. return true;
  149. }
  150. /// <summary>
  151. /// 技能施放完成监听.
  152. /// </summary>
  153. /// <param name="costEnergy"></param>
  154. /// <param name="attacker"></param>
  155. /// <param name="state"></param>
  156. /// <returns></returns>
  157. protected virtual int OnUnitLaunchSkillOver(GameSkill info, XmdsCommonServer.Plugin.XmdsVirtual attacker, CommonAI.Zone.Instance.InstanceUnit.SkillState state)
  158. {
  159. return 0;
  160. }
  161. /// <summary>
  162. /// 输出错误日志.
  163. /// </summary>
  164. /// <param name="text"></param>
  165. protected virtual void LogError(string text = null)
  166. {
  167. if (text != null)
  168. {
  169. log.Error(string.Format("技能【{0}】配置错误:{1}", SkillID, text));
  170. }
  171. else
  172. {
  173. log.Error(string.Format("技能【{0}】配置错误", SkillID));
  174. }
  175. }
  176. public virtual bool SkillAutoLaunchTest(InstanceUnit.SkillState ss, XmdsVirtual launcher) { return true; }
  177. public void Update(int intervalMS, bool slowRefresh) { OnUpdate(intervalMS, slowRefresh); }
  178. protected virtual void OnUpdate(int intervalMS, bool slowRefresh) { }
  179. /// <summary>
  180. /// 技能被销毁.
  181. /// </summary>
  182. public virtual void Dispose() { }
  183. }
  184. #endregion
  185. #region PassiveSkills
  186. public abstract class UnitPassiveSkill : AbstractSkill
  187. {
  188. protected static Logger log = LoggerFactory.GetLogger("XmdsBattleSkill");
  189. public void Init(GameSkill skillInfo, XmdsVirtual owner)
  190. {
  191. this.OnInitConfig(skillInfo);
  192. OnInit(skillInfo, owner);
  193. }
  194. //只调用一次的初始化
  195. public void InitSkillParam()
  196. {
  197. OnInitSkillParam();
  198. }
  199. protected virtual void OnInitSkillParam()
  200. {
  201. }
  202. // 每次加载技能都会调用。初始化配置,针对于人物技能多重继承
  203. protected virtual void OnInitConfig(GameSkill skillInfo)
  204. {
  205. }
  206. public void Update(int intervalMS, bool slowRefresh) { OnUpdate(intervalMS, slowRefresh); }
  207. public void Dispose(XmdsVirtual owner) { OnDispose(owner); }
  208. protected virtual void OnDispose(XmdsVirtual owner) { }
  209. protected virtual void OnInit(GameSkill skillInfo, XmdsVirtual owner) { }
  210. protected virtual void OnUpdate(int intervalMS, bool slowRefresh) { }
  211. protected virtual void LogError(string text = null)
  212. {
  213. if (text != null) { log.Error(string.Format("被动技能【{0}】配置错误:{1}", SkillID, text)); }
  214. else { log.Error(string.Format("被动技能【{0}】配置错误", SkillID)); }
  215. }
  216. public virtual bool ValidParameter(int lv, float[] formula)
  217. {
  218. bool ret = false;
  219. if (lv > formula.Length || lv <= 0) { ret = false; LogError(); }
  220. else { ret = true; }
  221. return ret;
  222. }
  223. public virtual int GetCDTotalTime() { return 0; }
  224. public virtual int GetCDPassTime() { return 0; }
  225. public virtual void SetCDPassTime(int timeMS) { }
  226. public virtual int GetDecreaseTotalTimeMS() { return 0; }
  227. public virtual void SetDecreaseTotalTimeMS(int timeMS) { }
  228. public override void SkillDataChange(GameSkill gs, XmdsVirtual unit)
  229. {
  230. OnSkillDataChange(gs, unit);
  231. }
  232. protected virtual void OnSkillDataChange(GameSkill gs, XmdsVirtual unit)
  233. {
  234. }
  235. }
  236. #endregion
  237. #region BUFF.
  238. /// <summary>
  239. /// BUFF基类.
  240. /// </summary>
  241. public abstract class UnitBuff : XmdsBuffVirtual
  242. {
  243. //buff等级.
  244. private int mBuffLv = 0;
  245. //绑定编辑器BUFF.
  246. protected int BindBuffID = 0;
  247. /// <summary>
  248. /// 是否无效.
  249. /// </summary>
  250. protected bool mInvalid = false;
  251. /// <summary>
  252. /// 能力ID(决定buff作用.)
  253. /// </summary>
  254. public abstract int GetAbilityID();
  255. /// <summary>
  256. /// BUFF等级.
  257. /// </summary>
  258. public virtual int BuffLV
  259. {
  260. set
  261. {
  262. mBuffLv = value;
  263. }
  264. get
  265. {
  266. return mBuffLv;
  267. }
  268. }
  269. public int GetBindBuffID()
  270. {
  271. return this.BindBuffID;
  272. }
  273. protected virtual void OnBindTemplate(ref BuffTemplate buffTemplate)
  274. {
  275. }
  276. //重载BUFF模板,修改属性.
  277. public void OverrideTemplate(ref BuffTemplate buffTemplate)
  278. {
  279. BindBuffID = buffTemplate.ID;
  280. (buffTemplate.Properties as XmdsBuffProperties).addBuffVirtual(this);
  281. OnBindTemplate(ref buffTemplate);
  282. }
  283. public virtual void BuffBegin(XmdsVirtual hitter, XmdsVirtual attacker, InstanceUnit.BuffState state)
  284. {
  285. }
  286. public virtual void BuffEnd(XmdsVirtual hitter, InstanceUnit.BuffState state, bool replace)
  287. {
  288. }
  289. public virtual int BuffHit(XmdsVirtual hitter, XmdsVirtual attacker, AttackSource source, ref XmdsVirtual.AtkResult result)
  290. {
  291. return 0;
  292. }
  293. /// <summary>
  294. /// 是否有
  295. /// </summary>
  296. /// <returns></returns>
  297. public bool IsInvaild() { return mInvalid; }
  298. public virtual void CopyTo(UnitBuff other)
  299. {
  300. other.BindBuffID = this.BindBuffID;
  301. other.mBuffLv = this.mBuffLv;
  302. }
  303. public virtual void BuffUpdate(XmdsVirtual unit, InstanceUnit.BuffState state) { }
  304. }
  305. #endregion
  306. #region 事件监听.
  307. //监听事件.
  308. /// <summary>
  309. /// 产生伤害监听.
  310. /// </summary>
  311. public delegate float IOnHit(float damage, XmdsVirtual hitted, XmdsVirtual attacker, AttackSource source,
  312. ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch);
  313. /// <summary>
  314. /// 被动触发监听
  315. /// </summary>
  316. public delegate void IOnTriggerStart(XmdsVirtual unit, XmdsVirtual target, UnitTriggerTemplate trigger, GameSkill sk);
  317. /// <summary>
  318. /// 测试Buff监听.
  319. /// </summary>
  320. public delegate void IOnBuffEvent(XmdsVirtual unit, InstanceUnit.BuffState buff, string result, GameSkill sk);
  321. /// <summary>
  322. /// 测试技能监听.
  323. /// </summary>
  324. public delegate bool ITestLaunchSkill(XmdsVirtual unit, InstanceUnit.SkillState skill, GameSkill sk);
  325. /// <summary>
  326. ///伤害计算监听.
  327. /// </summary>
  328. /// <param name="attacker"></param>
  329. /// <param name="hitter"></param>
  330. /// <param name="source"></param>
  331. /// <returns></returns>
  332. public delegate bool ICalDamage(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result, ref int damage);
  333. /// <summary>
  334. ///仇恨计算监听.
  335. /// </summary>
  336. /// <param name="attacker"></param>
  337. /// <param name="hitter"></param>
  338. /// <param name="source"></param>
  339. /// <returns></returns>
  340. public delegate void ICalThreadValue(XmdsVirtual attacker, XmdsVirtual hitter, AttackSource source, GameSkill gs, ref XmdsCommonServer.Plugin.XmdsVirtual.AtkResult result);
  341. /// <summary>
  342. /// 技能释放完毕.
  343. /// </summary>
  344. /// <param name="attacker"></param>
  345. /// <param name="state"></param>
  346. /// <returns></returns>
  347. public delegate int ILaunchSkillOver(GameSkill info, XmdsVirtual attacker, CommonAI.Zone.Instance.InstanceUnit.SkillState state);
  348. /// <summary>
  349. /// 测试攻击目标监听.
  350. /// </summary>
  351. /// <param name="target"></param>
  352. /// <param name="sk"></param>
  353. /// <returns></returns>
  354. public delegate XmdsVirtual IGetAtkTarget(XmdsVirtual target, GameSkill sk);
  355. public delegate void IGetSkillDamageInfo(XmdsVirtual attacker, XmdsVirtual hitter,
  356. ref AttackSource source, GameSkill gs);
  357. /// <summary>
  358. /// 技能结束监听.
  359. /// </summary>
  360. /// <param name="owner"></param>
  361. /// <param name="state"></param>
  362. public delegate void IStateSkillEnd(XmdsVirtual owner, InstanceUnit.StateSkill state, GameSkill gs);
  363. /// <summary>
  364. /// 添加buff监听.
  365. /// </summary>
  366. /// <param name="buff"></param>
  367. /// <param name="attacker"></param>
  368. /// <param name="hitter"></param>
  369. public delegate bool ITryAddBuffEvent(ref BuffTemplate buff, XmdsVirtual attacker, XmdsVirtual hitter, GameSkill skill);
  370. public delegate bool IRemoveBuffEvent(ref BuffTemplate buff, XmdsVirtual player, BuffRemoveType type);
  371. /** 给其他玩家添加buff监听. */
  372. public delegate void ISendBuffEvent(BuffTemplate buff, XmdsVirtual attacker, XmdsVirtual hitter);
  373. /// <summary>
  374. /// 重定向Spell监听.
  375. /// </summary>
  376. /// <param name="spell"></param>
  377. /// <param name="launcher"></param>
  378. public delegate void ITrySendSpellEvent(GameSkill skill, XmdsVirtual launcher, LaunchSpell launch, ref SpellTemplate spell, ref JSGCreateSpellData createData, ref float startX, ref float startY);
  379. //法术释放完毕
  380. public delegate void ISendSpellOverEvent(LaunchSpell launch, XmdsVirtual launcher, SpellTemplate spell, GameSkill skill, float startX, float startY);
  381. /// <summary>
  382. /// 监听施放技能.
  383. /// </summary>
  384. /// <param name="skill"></param>
  385. /// <param name="launcher"></param>
  386. public delegate bool ITryLaunchSkillEvent(GameSkill skillInfo, ref InstanceUnit.SkillState skill, XmdsVirtual launcher, ref InstanceUnit.LaunchSkillParam param);
  387. /// <summary>
  388. /// 触发宠物提供给人物的技能能力
  389. /// 返回true,结束下层传递
  390. /// </summary>
  391. /// <param name="skill"></param>
  392. /// <param name="launcher"></param>
  393. public delegate bool ITriggerPetSkillEvent(GameSkill skillInfo, ref InstanceUnit.SkillState skill, XmdsVirtual launcher, ref InstanceUnit.LaunchSkillParam param);
  394. /// <summary>
  395. /// 技能被打断事件通知
  396. ///
  397. /// </summary>
  398. /// <param name="skill"></param>
  399. /// <param name="launcher"></param>
  400. public delegate bool ISkillBlockEvent(XmdsVirtual launcher, InstanceUnit.StateSkill skill, InstanceUnit.State newState);
  401. /**
  402. * hp < 0加血事件, sender: 发送者,hitter:被加血的人
  403. * hp > =0扣血, sender:攻击者,hitter: 要扣血的
  404. * */
  405. public delegate bool IAddOtherHPEvent(int hp, InstanceUnit sender, InstanceUnit hitter, AttackSource source, out int finalHP);
  406. //宠物承担主人伤害事件
  407. public delegate int IShareMasterDmgEvent(int hp, InstanceUnit sender, InstanceUnit unit, GameSkill info, ref bool isEndDispatch);
  408. //扣定力
  409. public delegate bool IReduceOtherMpEvent(int mp, InstanceUnit sender, InstanceUnit hitter, out int finalMP, AttackSource source);
  410. //得卡牌球
  411. public delegate bool ITryAddCardBallEvent(XmdsVirtual player, CreateCardBallSource type, CardType cardType);
  412. //释放卡牌技能
  413. public delegate bool ITriggerCardSkillEvent(XmdsVirtual player, XmdsVirtual hitter, GameSkill info, CardType cardType, int sameNums);
  414. public delegate bool IOnKillOtherUnitEvent(XmdsVirtual attacker, XmdsVirtual deader, GameSkill info);
  415. #endregion
  416. #region 战斗特殊事件.
  417. #endregion
  418. }