Skill_910050.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using CommonAI;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Helper;
  4. using CommonAI.Zone.Instance;
  5. using CommonLang;
  6. using CommonLang.Geometry;
  7. using System;
  8. using XmdsCommon.Plugin;
  9. using XmdsCommonServer.Plugin;
  10. using XmdsCommonServer.Plugin.Units;
  11. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  12. using XmdsCommonServer.XLS.Data;
  13. using XmdsCommonSkill.Plugin.Buffs;
  14. using XmdsCommonSkill.Plugin.PassiveSkills.Magic;
  15. using static CommonAI.Zone.Instance.InstanceUnit;
  16. using static XmdsCommonSkill.Plugin.Buffs.XmdsBuff_SwordShadow;
  17. namespace XmdsCommonSkill.Plugin.Skills.Magic
  18. {
  19. /// <summary>
  20. /// 控制一名随机玩家,使该玩家眩晕,并攻击队友。其他玩家需要在指定时间内击杀掉A玩家分身,否则该玩家会死,BOSS也会回血
  21. /// </summary>
  22. public class Skill_910050 : XmdsSkillBase
  23. {
  24. public static readonly int ID = 910050;
  25. public override int SkillID { get { return ID; } }
  26. private static readonly int Buff_ID = (int)XmdsBuffBase.XmdsBuffList.COM_SLIENT;
  27. private static readonly int mSummonRange = 2; // 召唤物检测半径
  28. public static XmdsSkillValue mSummonTime; // 召唤时间
  29. public static XmdsSkillValue mSummonPropPrecent; // 分身属性万分比
  30. public static XmdsSkillValue mFinalAddHP; // 分身消失时,boss回血比例
  31. private long mSummonStartTime = 0;
  32. //被禁锢的玩家
  33. private XmdsVirtual mBindPlayer;
  34. //召唤分身
  35. private InstanceUnit mSummonUnit;
  36. //主人
  37. private XmdsVirtual mOwner;
  38. protected override void OnInit(GameSkill info, XmdsVirtual unit, ref SkillTemplate template)
  39. {
  40. // Buff修改
  41. var pack = XmdsBuffFactory.GetInstance().GetXmdsBuffPack(Buff_ID);
  42. var bt = pack.mBuffTemplate;
  43. bt.LifeTimeMS = mSummonTime.GetValue() + 2000; //默认比召唤物的时间长2s
  44. bt.IsHarmful = true;
  45. pack.BindTemplateAndDispose();
  46. unit.RegistSendBuff(bt);
  47. this.mOwner = unit;
  48. }
  49. protected override void OnSkillLogicEvent(BattleParams param)
  50. {
  51. param.UseDamageType = CommonAI.Data.DamageType.None;
  52. XmdsVirtual_Monster materMonster = param.Attacker as XmdsVirtual_Monster;
  53. if (materMonster.GetSummonUnitListCount() > 0)
  54. {
  55. return ;
  56. }
  57. //如果之前已经绑定了某个玩家,移除该玩家buff
  58. if (mBindPlayer != null && mBindPlayer.mUnit.IsActive)
  59. {
  60. mBindPlayer.mUnit.removeBuff(Buff_ID);
  61. mBindPlayer = null;
  62. }
  63. XmdsVirtual hitterPlayer = param.Hitter;
  64. if (hitterPlayer.mUnit.IsPet) //如果是宠物,目标为玩家
  65. {
  66. hitterPlayer = (param.Hitter as XmdsVirtual_Pet).GetMaster();
  67. }
  68. XmdsUnitProperties prop = hitterPlayer.mUnit.Properties as XmdsUnitProperties;
  69. String showName = prop.ServerData.BaseInfo.name + "-分身";
  70. UnitInfo info = (UnitInfo)hitterPlayer.mUnit.Info.Clone();
  71. info.ID = XmdsConstConfig.DEFAULT_PLAYER_TEMPLATE_ID;
  72. info.UType = UnitInfo.UnitType.TYPE_SUMMON;
  73. info.Name = showName;
  74. info.RebirthTimeMS = 0;
  75. info.LifeTimeMS = mSummonTime.GetValue();
  76. XmdsUnitProperties unitProp = (info.Properties as XmdsUnitProperties);
  77. unitProp.LoadDataConfig = false;
  78. //分身属性调整. 攻防血
  79. unitProp.ServerData.Prop.BaseAttack = CUtils.CastInt(unitProp.ServerData.Prop.BaseAttack * XmdsUnitProp.PER * mSummonPropPrecent.GetValue());
  80. unitProp.ServerData.Prop.BaseDefence = CUtils.CastInt(unitProp.ServerData.Prop.BaseDefence * XmdsUnitProp.PER * mSummonPropPrecent.GetValue());
  81. unitProp.ServerData.Prop.BaseMaxHP = CUtils.CastInt(unitProp.ServerData.Prop.BaseMaxHP * XmdsUnitProp.PER * mSummonPropPrecent.GetValue());
  82. unitProp.ServerData.Prop.HP = unitProp.ServerData.Prop.BaseMaxHP;
  83. this.ProcessSummonUnit(param.Attacker, hitterPlayer, info, showName);
  84. }
  85. protected bool ProcessSummonUnit(XmdsVirtual attacker, XmdsVirtual hitter, UnitInfo info, String showName)
  86. {
  87. AddUnitEvent aue = null;
  88. var pos = attacker.mUnit.Parent.PathFinder.FindNearRandomMoveableNode(
  89. attacker.mUnit.RandomN, attacker.mUnit.X, attacker.mUnit.Y, mSummonRange, true);
  90. mSummonUnit = attacker.mUnit.Parent.AddUnit(
  91. info, info.Name,
  92. attacker.mUnit.Force, attacker.GetUnitLv(),
  93. pos.PosX, pos.PosY,
  94. attacker.mUnit.Direction,
  95. out aue,
  96. attacker.mUnit, showName);
  97. if(mSummonUnit == null)
  98. {
  99. log.Warn("Skill_910050添加召唤物失败:" + info.ID);
  100. return false;
  101. }
  102. // 监听召唤物死亡
  103. mSummonUnit.OnDead += onSummonDead;
  104. (attacker as XmdsVirtual_Monster).AddSummonUnitList(mSummonUnit.Virtual as XmdsVirtual);
  105. //目标玩家死亡监听
  106. hitter.mUnit.AddBuff(Buff_ID, attacker.mUnit, 0, true);
  107. this.mBindPlayer = hitter;
  108. this.mSummonStartTime = CommonLang.CUtils.localTimeMS;
  109. mBindPlayer.mUnit.OnDead += onBindPlayerDead;
  110. return true;
  111. }
  112. private void onSummonDead(InstanceUnit unit, InstanceUnit attacker)
  113. {
  114. mSummonUnit.OnDead -= onSummonDead;
  115. if (mBindPlayer != null && mBindPlayer.mUnit.IsActive && mBindPlayer.mUnit.GetBuffByID(Buff_ID) != null)
  116. {
  117. long summonTimePass = CommonLang.CUtils.localTimeMS - this.mSummonStartTime + 500;
  118. mBindPlayer.mUnit.removeBuff(Buff_ID);
  119. //判断是否到召唤截止时间了
  120. if (summonTimePass >= mSummonTime.GetValue())
  121. {
  122. //杀死目标玩家
  123. mBindPlayer.mUnit.kill();
  124. //boss回血
  125. this.mOwner.mUnit.AddHP(CUtils.CastInt(this.mOwner.mUnit.MaxHP * XmdsUnitProp.PER * mFinalAddHP.GetValue()), null);
  126. }
  127. else
  128. {
  129. // 分身被击杀了
  130. }
  131. this.mBindPlayer = null;
  132. this.mSummonStartTime = 0;
  133. }
  134. }
  135. private void onBindPlayerDead(InstanceUnit unit, InstanceUnit attacker)
  136. {
  137. if(mBindPlayer != null)
  138. {
  139. mBindPlayer.mUnit.OnDead -= onBindPlayerDead;
  140. mBindPlayer.mUnit.removeBuff(Buff_ID);
  141. }
  142. }
  143. protected override void OnInitConfig()
  144. {
  145. XmdsSkillData data = XmdsDataMgr.GetInstance().GetXmdsSkillData(ID);
  146. InitData(data, out mSummonTime, XmdsSkillData.XmdsSkillDataKey.ValueSet);
  147. InitData(data, out mSummonPropPrecent, XmdsSkillData.XmdsSkillDataKey.ValueSet2);
  148. InitData(data, out mFinalAddHP, XmdsSkillData.XmdsSkillDataKey.ValueSet3);
  149. }
  150. }
  151. }