123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using CommonAI.Zone;
- using CommonAI.Zone.Helper;
- using CommonAI.Zone.Instance;
- using CommonLang;
- namespace XmdsCommonServer.Plugin.Units
- {
- /// <summary>
- /// 召唤单位,目前召唤单位AI与宠物相同,先继承自宠物.
- /// </summary>
- 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<InstanceUnit>.AllocAutoRelease())
- {
- //找到离自己最近的单位攻击.
- Parent.getObjectsRoundRange<InstanceUnit>(Collider.Object_BlockBody_TouchRound, X, Y, Info.GuardRange, list, AoiStatus);
- DoAndRemoveCollection.UpdateAndRemove<InstanceUnit>(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;
- }
- }
- }
|