using CommonAI.Zone;
using CommonAI.Zone.Helper;
using CommonAI.Zone.Instance;
using CommonLang;
namespace XmdsCommonServer.Plugin.Units
{
///
/// 召唤单位,目前召唤单位AI与宠物相同,先继承自宠物.
///
public class XmdsInstanceSummonUnit : XmdsInstancePet //InstanceGuard, ViewTrigger.ViewTriggerListener, ISummonedUnit
{
public override bool IntersectObj { get { return false; } }
public XmdsInstanceSummonUnit(InstanceZone zone, UnitInfo info, string name, int force, int level)
: base(zone, info, name, force, level)
{
}
public InstanceUnit BindUnit { get; set; }
protected override void onAdded(bool pointLv)
{
base.onAdded(pointLv);
if(this.Info.SumType == CommonAI.Data.SummonType.attack)
{
base.SetFollowMode(XmdsCommon.Plugin.XmdsPetConifg.XmdsPetFollowMode.ActiveAtk);
}
}
public override bool IsMonster { get { return true; } }
override protected void onUpdate(bool slowRefresh)
{
base.onUpdate(slowRefresh);
if (BindUnit != null)
{
if (X != BindUnit.X || Y != BindUnit.Y)
{
setPos(BindUnit.X, BindUnit.Y, false);
}
}
if ((PassTimeMS >= Info.LifeTimeMS) || (SummonerUnit != null && !SummonerUnit.IsActive))
{
kill(null, false);
}
}
public override void InitSkills(LaunchSkill baseSkill, params LaunchSkill[] skills)
{
if (this.Virtual == null ||
(this.Virtual as XmdsVirtual).IsFinishSkillInit() == false)
{
return;
}
base.InitSkills(baseSkill, skills);
}
// 各种填坑,宠物机制被改的贼特殊,贼恶心
protected override bool IsCanAttack(InstanceUnit unit) { return true; }
public override bool IsPet { get { return false; } }
public override bool IsPlayerUnit { get { return false; } }
protected override bool IsPetCanAttack() { return true; }
protected override void followMasterChangeSpeed(float speedChag) { }
protected override bool CheckFollowMaster()
{
if(this.Info.SumType == CommonAI.Data.SummonType.MoveToMaster || this.Info.SumType == CommonAI.Data.SummonType.AwaitMaster)
{
return false;
}
return true;
}
public override bool checkOutOffBattle()
{
if (CurrentState is StateIdle)
{
return true;
}
return false;
}
protected override void Disposing()
{
BindUnit = null;
base.Disposing();
}
protected override bool TryAtkSelfEnemy()
{
bool ret = false;
using (var list = ListObjectPool.AllocAutoRelease())
{
//找到离自己最近的单位攻击.
Parent.getObjectsRoundRange(Collider.Object_BlockBody_TouchRound, X, Y, Info.GuardRange, list, AoiStatus);
DoAndRemoveCollection.UpdateAndRemove(list, (InstanceUnit u) =>
{
return !u.IsActive;
});
if (list != null && list.Count > 0)
{
list.Sort((a, b) =>
{
//选距离最近的单位.
float da = CMath.getDistanceSquare(a.X, a.Y, this.X, this.Y);
float db = CMath.getDistanceSquare(b.X, b.Y, this.X, this.Y);
return (int)(da - db);
});
foreach (SkillState skill in SkillStatus)
{
if (skill.LaunchSkill.AutoLaunch && skill.TryLaunch())
{
foreach (InstanceUnit u in list)
{
if (this.IsCanAttack(u) && Parent.IsAttackable(this, u, skill.Data.ExpectTarget, AttackReason.Attack, skill.Data))
{
//是否在守卫范围内.
if (CheckInAtkRange(u, this.Info.GuardRange + skill.Data.AttackRange))
{
//检测是否有可释放技能//
if (tryAutoLaunch(skill, u))
{
return true;
}
}
}
}
}
}
}
}
return ret;
}
}
}