using CommonAI.Zone.Instance;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XmdsCommonServer.Plugin;
using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
namespace XmdsCommonSkill.Plugin.Buffs
{
///
/// 与其他单位关联.
///
public class XmdsBuff_UnitLink : XmdsBuffBase
{
///
/// 关联单位.
///
public XmdsVirtual LinkTarget = null;
public XmdsVirtual Owner = null;
public override int GetAbilityID()
{
return (int)XmdsCommon.Plugin.XmdsBuffProperties.XmdsBuffAbility.UnitLink;
}
public override void CopyTo(UnitBuff other)
{
var ret = other as XmdsBuff_UnitLink;
ret.LinkTarget = this.LinkTarget;
//不释放,可能会导致内存泄露.
this.LinkTarget = null;
base.CopyTo(other);
}
protected override void OnBuffBegin(XmdsCommonServer.Plugin.XmdsVirtual hitter, XmdsCommonServer.Plugin.XmdsVirtual attacker, InstanceUnit.BuffState state)
{
//通过编辑器设置无敌效果.
XmdsVirtual.FormatLog("单位 {0} 关联开始", hitter.mInfo.Name);
Owner = hitter;
if (LinkTarget != null)
{
LinkTarget.mUnit.OnDead += MUnit_OnDead;
}
}
private void MUnit_OnDead(InstanceUnit unit, InstanceUnit attacker)
{
if (Owner != null)
{
Owner.mUnit.removeBuff(BindBuffID);
}
if (LinkTarget != null)
{
LinkTarget.mUnit.OnDead -= MUnit_OnDead;
}
}
protected override void OnBuffEnd(XmdsCommonServer.Plugin.XmdsVirtual hitter, InstanceUnit.BuffState state, bool replace)
{
//通过编辑器设置无敌效果.
XmdsVirtual.FormatLog("单位 {0} 关联结束", hitter.mInfo.Name);
if (LinkTarget != null)
{
if (LinkTarget.mUnit.IsDead() == false)
{
LinkTarget.mUnit.kill(null, false);
}
LinkTarget = null;
}
Owner = null;
}
protected override void OnDispose()
{
this.LinkTarget = null;
this.Owner = null;
base.OnDispose();
}
}
}