Ejemplo n.º 1
0
    public static Actor GetSelfNearestSummonMonsterTargetActor(AIRunningProperty runningProperty)
    {
        if (runningProperty == null)
        {
            return(null);
        }

        Actor targetActor = null;

        float shortest  = float.MaxValue;
        float viewRange = runningProperty.ViewRange * runningProperty.ViewRange;

        // 若开启了PK模式,同条件下,敌对玩家优先级高于怪物
        if (PKModeManagerEx.Instance.PKMode != GameConst.PK_MODE_PEACE)
        {
            targetActor = GetNearestActor(runningProperty, xc.ActorManager.Instance.PlayerSet, runningProperty.SelfActor.transform.position);
            if (targetActor == null)
            {
                targetActor = GetNearestActor(runningProperty, xc.ActorManager.Instance.MonsterSet, runningProperty.SelfActor.transform.position);
            }
        }
        else
        {
            Dictionary <UnitID, Actor> actors = xc.ActorManager.Instance.ActorSet;
            targetActor = GetNearestActor(runningProperty, actors, runningProperty.SelfActor.transform.position);
        }

        return(targetActor);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 找最近的可以自动采集的采集物
    /// </summary>
    /// <param name="runningProperty"></param>
    /// <returns></returns>
    public static CollectionObject GetNearstAutoCollectableCollectionObject(AIRunningProperty runningProperty)
    {
        if (runningProperty == null)
        {
            return(null);
        }

        float            shortest            = float.MaxValue;
        Vector3          selfActorPos        = runningProperty.SelfActorPos;
        CollectionObject retCollectionObject = null;

        Dictionary <int, CollectionObject> collectionObjects = xc.Dungeon.CollectionObjectManager.Instance.CollectionObjects;

        foreach (CollectionObject collectionObject in collectionObjects.Values)
        {
            if (collectionObject == null || collectionObject.BindGameObject == null || collectionObject.BindGameObject.transform == null)
            {
                continue;
            }

            CollectionObjectBehaviour collectionObjectBehaviour = collectionObject.BindGameObject.GetComponent <CollectionObjectBehaviour>();
            if (collectionObjectBehaviour == null)
            {
                continue;
            }

            // 婚宴食物是否能采集
            if (collectionObjectBehaviour.Class == "wedding_foods" && MarryManager.Instance.WeddingFoodsCanBeCollected == false)
            {
                continue;
            }

            // 婚宴宝箱是否能采集
            if (collectionObjectBehaviour.Class == "wedding_bos" && MarryManager.Instance.WeddingBoxCanBeCollected == false)
            {
                continue;
            }

            Vector3 pos = collectionObject.BindGameObject.transform.position;
            if (!TargetPositionHeightIsAbnormal(pos))
            {
                continue;
            }
            if (!InstanceHelper.CanWalkTo(pos))
            {
                continue;
            }

            float distanceSquare = AIHelper.DistanceSquare(selfActorPos, pos);
            if (distanceSquare < shortest)
            {
                shortest            = distanceSquare;
                retCollectionObject = collectionObject;
            }
        }

        return(retCollectionObject);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// 构造函数 抽象类不建议是public构造函数
    /// </summary>
    /// <param name="parent"></param>
    protected BehaviourAI(Actor parent)
    {
        mRunningProperty                      = new AIRunningProperty();
        mRunningProperty.SelfActor            = parent;
        mRunningProperty.OriginalSelfActorPos = parent.transform.position;
        mRunningProperty.AI                   = this;
        mRunningProperty.ViewRange            = GetActorViewRange();
        mPathWalker = new AIActorPathWalker(parent);

        mMachine = new BehaviourMachine(this);
        mAmbient = new AIAmbientState(this);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 找最近的可以寻路的触发器
    /// </summary>
    /// <param name="runningProperty"></param>
    /// <returns></returns>
    public static Vector3 GetNearestNeedNavigateColliderPosition(AIRunningProperty runningProperty)
    {
        if (runningProperty == null)
        {
            return(Vector3.zero);
        }

        float   shortest     = float.MaxValue;
        Vector3 selfActorPos = runningProperty.SelfActorPos;
        Vector3 targetPos    = Vector3.zero;

        List <xc.Dungeon.ColliderObject> colliderObjects = xc.Dungeon.ColliderObjectManager.Instance.GetNeedNavigateColliderObjects();

        foreach (xc.Dungeon.ColliderObject colliderObject in colliderObjects)
        {
            if (colliderObject == null || colliderObject.BindGameObject == null || colliderObject.BindGameObject.transform == null)
            {
                continue;
            }

            Vector3 pos = colliderObject.BindGameObject.transform.position;
            if (!TargetPositionHeightIsAbnormal(pos))
            {
                continue;
            }

            float distanceSquare = AIHelper.DistanceSquare(selfActorPos, pos);
            if (distanceSquare < shortest)
            {
                shortest  = distanceSquare;
                targetPos = pos;
            }
        }

        return(targetPos);
    }
Ejemplo n.º 5
0
 public BehaviourEscapeFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.ESCAPE)
 {
     mRunningProperty = data;
 }
Ejemplo n.º 6
0
 public static Actor GetNearestActor(AIRunningProperty runningProperty, Dictionary <UnitID, Actor> actors)
 {
     return(GetNearestActor(runningProperty, actors, runningProperty.SelfActorPos));
 }
 public BehaviourAttackFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.ATTACK)
 {
     mRunningProperty = data;
 }
Ejemplo n.º 8
0
    public static Actor GetNearestActor(AIRunningProperty runningProperty, Dictionary <UnitID, Actor> actors, Vector3 targetPos)
    {
        if (actors == null || runningProperty == null)
        {
            return(null);
        }

        Actor targetActor = null;

        float shortest  = float.MaxValue;
        float viewRange = runningProperty.ViewRange * runningProperty.ViewRange;

        bool show_tips = false;

        // 计算出最短距离

        foreach (var item in actors)
        {
            if (item.Value == null)
            {
                continue;
            }

            if (item.Value.transform == null)
            {
                continue;
            }

            if (!TargetPositionHeightIsAbnormal(item.Value.transform.position))
            {
                continue;
            }

            if (runningProperty.SelfActor is LocalPlayer || runningProperty.SelfActor.ParentActor is LocalPlayer)
            {
                show_tips = false;
                if (PKModeManagerEx.Instance.IsLocalPlayerCanAttackActor(item.Value, ref show_tips) == false)
                {
                    continue;
                }
            }

            if (item.Value.IsDead() || (item.Value.gameObject.activeSelf == false))
            {
                continue;
            }

            if (item.Value.IsActorInvisiable)
            {
                continue;
            }

            if (item.Value is Pet)
            {
                continue;
            }

            if (item.Value.Camp == runningProperty.SelfActor.Camp)
            {
                continue;
            }

            float distanceSquare = AIHelper.DistanceSquare(targetPos, item.Value.transform.position);
            if (distanceSquare < shortest)
            {
                shortest    = distanceSquare;
                targetActor = item.Value;
            }
        }

        if (shortest > viewRange)
        {
            targetActor = null;
        }

        return(targetActor);
    }
 public BehaviourFollowFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.FOLLOW)
 {
     mRunningProperty = data;
 }
Ejemplo n.º 10
0
 public BehaviourWalkFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.WALK)
 {
     mRunningProperty = data;
 }
Ejemplo n.º 11
0
 public BehaviourEmptyFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.EMPTY)
 {
     mRunningProperty = data;
 }
Ejemplo n.º 12
0
 public BehaviourPatrolFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.PATROL)
 {
     mRunningProperty = data;
 }
Ejemplo n.º 13
0
 public BehaviourChaseTargetFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.CHASETARGET)
 {
     mRunningProperty = data;
 }
Ejemplo n.º 14
0
 public BehaviourRunFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.RUN)
 {
     mRunningProperty = data;
     mLastPos         = mRunningProperty.SelfActorPos;
 }
Ejemplo n.º 15
0
 public BehaviourStandFiniteState(AIRunningProperty data)
     : base(BehaviourMachine.State.STAND)
 {
     mRunningProperty = data;
 }