using CommonAI.Zone.Instance; using CommonAI.Zone.Formula; using System; using System.Collections.Generic; using System.Linq; using System.Text; using XmdsCommon.Plugin; using XmdsCommonServer.Plugin; using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills; using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator; using CommonLang; using CommonAI.Data; namespace XmdsCommonSkill.Plugin.Buffs { /// /// 攻击范围回血 /// public class XmdsBuff_AttackRoundAddHP : XmdsBuffBase { public int totalAddHp = -1; //-1为不限制 public float damageToHp = 0.1f; public int AddHPRange = 5; //回复范围 //buff创建者 private XmdsVirtual buffSender = null; private int mHandleUUID = 0; public override int GetAbilityID() { return (int)XmdsCommon.Plugin.XmdsBuffProperties.XmdsBuffAbility.Attack_RoundAddHP; } public override void CopyTo(UnitBuff other) { var ret = other as XmdsBuff_AttackRoundAddHP; ret.totalAddHp = this.totalAddHp; ret.damageToHp = this.damageToHp; ret.AddHPRange = this.AddHPRange; base.CopyTo(other); } protected override void OnBuffBegin(XmdsCommonServer.Plugin.XmdsVirtual hitter, XmdsCommonServer.Plugin.XmdsVirtual attacker, InstanceUnit.BuffState state) { this.buffSender = attacker; //注册监听. mHandleUUID = hitter.RegistOnHitOther(OnHandleHitOther, null); } protected override void OnBuffEnd(XmdsCommonServer.Plugin.XmdsVirtual hitter, InstanceUnit.BuffState state, bool replace) { //取消监听. hitter.UnRegistOnHitOther(mHandleUUID); } //单位被攻击时,判断是否符合条件触发BUFF效果. private float OnHandleHitOther(float damage, XmdsVirtual hitted, XmdsVirtual attacker, AttackSource source, ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch) { int AddHP = CUtils.CastInt(damage * this.damageToHp); if (AddHP > 0) { if(totalAddHp != -1) { AddHP = Math.Min(AddHP, totalAddHp); totalAddHp -= AddHP; if(totalAddHp <= 0) { hitted.mUnit.removeBuff(this.BindBuffID); } } //血量平分 //治疗自己和队友 using (var list = ListObjectPool.AllocAutoRelease()) { attacker.mUnit.Parent.getObjectsRoundRange( (obj, dx, dy, dr) => { var u = obj as InstanceUnit; //己方单位. if (attacker.IsAllies(u.Virtual as XmdsVirtual, true, true)) { return CMath.includeRoundPoint(dx, dy, dr, u.X, u.Y); } return false; }, attacker.mUnit.X, attacker.mUnit.Y, AddHPRange, list, attacker.mUnit.AoiStatus); if(list.Count > 0) { int avgAdd = Math.Max(1, AddHP / list.Count); //加血 & 加速 for (int i = 0; i < list.Count; i++) { list[i].AddHP(avgAdd, attacker.mUnit); } } } } return damage; } protected override void OnDispose() { base.OnDispose(); } } }