TianShuBase.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using CommonAI.Data;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Formula;
  4. using CommonAI.Zone.Helper;
  5. using CommonAI.Zone.Instance;
  6. using CommonLang;
  7. using System;
  8. using XmdsCommon.Plugin;
  9. using XmdsCommonServer.Plugin;
  10. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  11. using XmdsCommonServer.XLS.Data;
  12. using XmdsCommonSkill.Plugin.Buffs;
  13. using XmdsCommonSkill.Plugin.Interface;
  14. using XmdsCommonSkill.Plugin.PassiveSkills.Magic;
  15. using static CommonAI.Zone.Instance.InstanceUnit;
  16. using static XmdsCommonSkill.Plugin.Buffs.XmdsBuff_SwordShadow;
  17. using static XmdsCommonSkill.Plugin.Interface.ComSpellTemplate;
  18. namespace XmdsCommonSkill.Plugin.Skills.Magic
  19. {
  20. /// <summary>
  21. /// 天数基础技能:每次攻击(怪物)时有X%的概率触发,使玩家的下一次普攻伤害提高Y%,持续时间Z秒,技能冷却时间S秒
  22. /// </summary>
  23. public abstract class TianShuBase : XmdsPassiveSkillBase
  24. {
  25. private static XmdsSkillValue mValueSet1; // 触发概率
  26. private static XmdsSkillValue mValueSet2; // 攻击百分比提高
  27. private static XmdsSkillValue mValueSet3; // buff持续时间
  28. private static XmdsSkillValue mValueSet4; // 冷却时间
  29. //本次触发时间
  30. private long mNextTirggerTime = 0;
  31. //buff有效截止时间
  32. private long mBuffValidEndTime = 0;
  33. private int mUUID_2;
  34. protected override void OnInit(GameSkill skillInfo, XmdsVirtual owner)
  35. {
  36. var pack = XmdsBuffFactory.GetInstance().GetXmdsBuffPack(this.GetBindBuffID());
  37. var buff = (XmdsBuff_Damage)pack.GetXmdsBuff(XmdsBuffProperties.XmdsBuffAbility.Damage);
  38. buff.mDamagePer = mValueSet2.GetValue(skillInfo.SkillLevel) + skillInfo.TalentSkillLevel1;
  39. var bt = pack.mBuffTemplate;
  40. pack.BindTemplateAndDispose();
  41. owner.RegistSendBuff(bt);
  42. // 伤害监听
  43. mUUID_2 = owner.RegistOnHitOther(OnHandleHitOther, skillInfo, true);
  44. mNextTirggerTime = CommonLang.CUtils.localTimeMS + mValueSet4.GetValue(skillInfo.SkillLevel);
  45. }
  46. protected override void OnSkillDataChange(GameSkill gs, XmdsVirtual unit)
  47. {
  48. var buff = (XmdsBuff_Damage)unit.GetRegisBuffVirtual(this.GetBindBuffID());
  49. buff.mDamagePer = mValueSet2.GetValue(gs.SkillLevel) + gs.TalentSkillLevel1;
  50. }
  51. private float OnHandleHitOther(float damage, XmdsVirtual hitted, XmdsVirtual attacker, AttackSource source,
  52. ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch)
  53. {
  54. if(source == null || source.FromBuff != null)
  55. {
  56. return damage;
  57. }
  58. // 对战玩家触发
  59. if (hitted != null && !hitted.IsPlayerUnit())
  60. {
  61. //如果buff生效了
  62. if(mBuffValidEndTime > CommonLang.CUtils.localTimeMS && source.FromSkillType == XmdsSkillType.normalAtk)
  63. {
  64. this.mBuffValidEndTime = 0; // 标记失效
  65. //hitted.mUnit.AddBuff(this.GetBindBuffID(), attacker.mUnit);
  66. this.launchEffectSpell(attacker, hitted, false);
  67. damage += damage * (mValueSet2.GetValue(skill.SkillLevel) + skill.TalentSkillLevel1) * XmdsUnitProp.PER;
  68. return damage;
  69. }
  70. if(mNextTirggerTime < CommonLang.CUtils.localTimeMS && attacker.mUnit.RandomN.Next(0, 10000) < mValueSet1.GetValue(skill.SkillLevel))
  71. {
  72. mNextTirggerTime = CommonLang.CUtils.localTimeMS + mValueSet4.GetValue(skill.SkillLevel);
  73. mBuffValidEndTime = CommonLang.CUtils.localTimeMS + mValueSet3.GetValue(skill.SkillLevel);
  74. // 释放法术特效
  75. this.launchEffectSpell(attacker, attacker, true);
  76. }
  77. }
  78. return damage;
  79. }
  80. protected override void OnDispose(XmdsVirtual owner)
  81. {
  82. owner.UnRegistOnHitOther(mUUID_2);
  83. }
  84. protected override void OnInitSkillParam()
  85. {
  86. XmdsSkillData data = XmdsDataMgr.GetInstance().GetXmdsSkillData(this.SkillID);
  87. InitData(data, out mValueSet1, XmdsSkillData.XmdsSkillDataKey.ValueSet);
  88. InitData(data, out mValueSet2, XmdsSkillData.XmdsSkillDataKey.ValueSet2);
  89. InitData(data, out mValueSet3, XmdsSkillData.XmdsSkillDataKey.ValueSet3);
  90. InitData(data, out mValueSet4, XmdsSkillData.XmdsSkillDataKey.ValueSet4);
  91. }
  92. protected virtual XmdsSpellID GetLaunchSpellID(bool self) { return 0; }
  93. protected void launchEffectSpell(XmdsVirtual launcher, XmdsVirtual target, bool self)
  94. {
  95. LaunchSpell spell = ComSpellTemplate.Instance().GetSpellByID(this.GetLaunchSpellID(self));
  96. launcher.mUnit.Parent.unitLaunchSpell(XmdsSkillType.none, launcher.mUnit, spell, target.mUnit.X, target.mUnit.Y, target.mUnit.ID);
  97. }
  98. protected virtual int GetBindBuffID()
  99. {
  100. return 0;
  101. }
  102. }
  103. }