示例#1
0
    /// <summary>
    /// 是否远离要跟随的玩家
    /// </summary>
    /// <returns></returns>
    public bool ConditionIsFarAwayFollowActor()
    {
        if (ConditionIsHaveFollowInfo() == false)
        {
            return(false);
        }

        Vector3 followPos = Vector3.zero;

        if (RunningProperty.FollowActor != null)
        {
            followPos = RunningProperty.FollowActor.transform.position;
        }
        else
        {
            followPos = RunningProperty.FollowBackupPosition;
        }

        if (Vector3.Equals(followPos, Vector3.zero))
        {
            return(false);
        }

        if (AIHelper.DistanceSquare(RunningProperty.SelfActorPos, followPos) >= (150.0f))
        {
            return(true);
        }

        return(false);
    }
示例#2
0
    public override bool ConditionIsNeedFollowPlayer()
    {
        Monster monster = RunningProperty.SelfActor as Monster;

        if (monster == null)
        {
            return(false);
        }

        if (monster.Camp == LocalPlayer.NowCamp)
        {
            if (AIHelper.DistanceSquare(monster.CenterSpawnPos, RunningProperty.SelfActorPos) >= (monster.MotionRadius * monster.MotionRadius))
            {
                return(true);
            }

            if (RunningProperty.TargetActor == null)
            {
                return(true);
            }

            return(false);
        }

        return(base.ConditionIsNeedFollowPlayer());
    }
示例#3
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);
    }
示例#4
0
    public override bool ConditionIsNeedFollowPlayer()
    {
        Actor localPlayer = Game.GetInstance().GetLocalPlayer();

        if (localPlayer == null)
        {
            return(false);
        }

        float distance = AIHelper.DistanceSquare(RunningProperty.SelfActorPos, localPlayer.transform.position);

        if (distance > 20.0f)
        {
            return(true);
        }

        return(false);
    }
示例#5
0
    /// <summary>
    /// 是否看到本地玩家
    /// </summary>
    /// <returns></returns>
    public bool ConditionIsSeeLocalPlayer()
    {
        Actor localPlayer = Game.GetInstance().GetLocalPlayer();

        if (localPlayer == null || !localPlayer.IsResLoaded)
        {
            return(false);
        }

        float distance = AIHelper.DistanceSquare(RunningProperty.SelfActorPos, localPlayer.transform.position);


        if (distance > RunningProperty.ViewRange * RunningProperty.ViewRange)
        {
            return(false);
        }

        return(true);
    }
示例#6
0
    public override bool ConditionIsNeedPatrol()
    {
        if (RunningProperty.TargetActor == null)
        {
            return(true);
        }

        Monster monster = RunningProperty.SelfActor as Monster;

        if (monster == null)
        {
            return(false);
        }

        if (RunningProperty.AI.Machine.CurrentStateType == BehaviourMachine.State.ESCAPE)
        {
            return(false);
        }

        if (monster.Camp == LocalPlayer.NowCamp)
        {
            return(false);
        }

        if (ConditionTargetIsInAttackRange())
        {
            return(false);
        }

        if (AIHelper.DistanceSquare(monster.CenterSpawnPos, RunningProperty.SelfActorPos) >= (monster.MaxChaseDistance * monster.MaxChaseDistance))
        {
            return(true);
        }

        //目标对象是否超出最大追击距离
        if (AIHelper.DistanceSquare(monster.CenterSpawnPos, RunningProperty.TargetActorPos) >= (monster.MaxChaseDistance * monster.MaxChaseDistance))
        {
            return(true);
        }

        return(false);
    }
示例#7
0
    /// <summary>
    /// 与父亲的距离是否少于一定的距离
    /// </summary>
    /// <param name="distanceSquare"></param>
    /// <returns></returns>
    public bool ConditionIsNearParentActor(float distanceSquare)
    {
        Vector3 parentPos = Vector3.zero;

        if (RunningProperty.SelfActor != null && RunningProperty.SelfActor.ParentActor != null && RunningProperty.SelfActor.ParentActor.transform != null)
        {
            parentPos = RunningProperty.SelfActor.ParentActor.transform.position;
        }

        if (Vector3.Equals(parentPos, Vector3.zero))
        {
            return(false);
        }

        if (AIHelper.DistanceSquare(RunningProperty.SelfActor.transform.position, parentPos) <= distanceSquare)
        {
            return(true);
        }

        return(false);
    }
示例#8
0
    /// <summary>
    /// 是否离开运动范围
    /// </summary>
    /// <returns></returns>
    public bool ConditionIsAwayMotionArea()
    {
        Monster monster = RunningProperty.SelfActor as Monster;

        if (monster == null)
        {
            return(false);
        }

        if (InstanceManager.Instance.IsPlayerVSPlayerType)
        {
            return(false);
        }

        if (AIHelper.DistanceSquare(monster.CenterSpawnPos, RunningProperty.SelfActorPos) >= (monster.MotionRadius * monster.MotionRadius))
        {
            return(true);
        }

        return(false);
    }
示例#9
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);
    }
示例#10
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);
    }
示例#11
0
    public override Actor GetDefaultTargetActor()
    {
        Monster monster = mRunningProperty.SelfActor as Monster;

        if (monster == null)
        {
            return(null);
        }

        //if (monster is Pet)
        //{
        //    if (!SceneHelp.Instance.IsInSingleInstance())
        //    {
        //        return null;
        //    }
        //}

        Actor targetActor = null;
        float shortest    = float.MaxValue;
        Actor localPlayer = Game.GetInstance().GetLocalPlayer();

        // 有没有强制目标
        //Spartan.MonsterGroupInfo monsterGroupInfo = monster.SpartanMonsterGroupInfo;

        //if(monsterGroupInfo != null)
        //{
        //    targetActor = NpcManager.Instance.GetNpcByNpcId((uint)monsterGroupInfo.TargetNpcId);

        //    if(targetActor != null && !targetActor.IsActorInvisiable)
        //    {
        //        return targetActor;
        //    }
        //}

        float viewRange = mRunningProperty.ViewRange * mRunningProperty.ViewRange;

        if (InstanceManager.Instance.IsPlayerVSPlayerType)
        {
            if (mRunningProperty.SelfActor.ParentActor == null)
            {
                return(null);
            }

            foreach (var item in ActorManager.Instance.PlayerSet)
            {
                Actor oppositeActor = null;

                if (item.Value.UID != mRunningProperty.SelfActor.ParentActor.UID)
                {
                    oppositeActor = item.Value;
                    float distanceSquare = AIHelper.DistanceSquare(mRunningProperty.SelfActorPos, item.Value.transform.position);
                    shortest = distanceSquare;

                    foreach (var son in oppositeActor.SonActors)
                    {
                        if (son == null || son.IsDead() || son.IsActorInvisiable)
                        {
                            continue;
                        }

                        distanceSquare = AIHelper.DistanceSquare(mRunningProperty.SelfActorPos, son.transform.position);

                        if (distanceSquare < shortest)
                        {
                            shortest      = distanceSquare;
                            oppositeActor = son;
                        }
                    }

                    return(oppositeActor);
                }
            }
        }
        //else if (InstanceManager.Instance.InstanceType == GameConst.WAR_TYPE_ARENA)
        //{
        //    if (mRunningProperty.SelfActor.ParentActor == null)
        //    {
        //        return null;
        //    }

        //    foreach (var item in ActorManager.Instance.ActorSet)
        //    {
        //        if(item.Value.IsActorInvisiable)
        //        {
        //            continue;
        //        }

        //        if (item.Value.UID != mRunningProperty.SelfActor.ParentActor.UID)
        //        {
        //            return item.Value;
        //        }
        //    }
        //}

        // 是玩家队友
        if (localPlayer != null && monster.Camp == localPlayer.Camp)
        {
            Dictionary <UnitID, Actor> monsters = ActorManager.Instance.MonsterSet;

            // 计算出最短距离
            foreach (var item in monsters)
            {
                if (item.Value == null)
                {
                    continue;
                }

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

                if (item.Value == mRunningProperty.SelfActor.ParentActor || item.Value.IsActorInvisiable)
                {
                    continue;
                }

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

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

                if (mRunningProperty.SelfActor.ParentActor != null)
                {
                    if (item.Value.ParentActor == mRunningProperty.SelfActor.ParentActor)
                    {
                        continue;
                    }
                }

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

            if (InstanceManager.Instance.InstanceType == GameConst.WAR_TYPE_WILD)
            {
                if (localPlayer != null && localPlayer.WildState == Actor.EWildState.Kill)
                {
                    Dictionary <UnitID, Actor> players = ActorManager.Instance.PlayerSet;

                    // Linq
                    //monsters = monsters.Concat(players).ToDictionary(k => k.Key, v => v.Value);

                    // 计算出最短距离
                    foreach (var item in players)
                    {
                        if (item.Value == null)
                        {
                            continue;
                        }

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

                        if (item.Value == mRunningProperty.SelfActor.ParentActor || item.Value.IsActorInvisiable)
                        {
                            continue;
                        }

                        if (mRunningProperty.SelfActor.ParentActor != null)
                        {
                            if (!mRunningProperty.SelfActor.ParentActor.CheckCanAttackOtherPlayer(item.Value))
                            {
                                continue;
                            }
                        }

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

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

            return(targetActor);
        }

        // 先检测当前目标有没有脱离视野范围
        if (mRunningProperty.TargetActor != null && !mRunningProperty.TargetActor.IsActorInvisiable)
        {
            float distance = AIHelper.DistanceSquare(mRunningProperty.TargetActor.transform.position, mRunningProperty.SelfActorPos);

            if (distance <= viewRange && !mRunningProperty.TargetActor.IsActorInvisiable)
            {
                return(mRunningProperty.TargetActor);
            }
        }

        targetActor = Game.GetInstance().GetLocalPlayer();

        if (targetActor != null)
        {
            shortest = AIHelper.DistanceSquare(targetActor.transform.position, mRunningProperty.SelfActorPos);
        }
        else
        {
            shortest = float.MaxValue;
        }

        // 检测召唤出来的怪物
        Dictionary <UnitID, Actor> summonMonsters = ActorManager.Instance.SummonMonsterSet;

        foreach (var item in summonMonsters)
        {
            Monster monster2 = item.Value as Monster;

            if (monster2 == null)
            {
                continue;
            }

            if (monster2.BeSummonedType == Monster.BeSummonType.BE_SUMMON_BY_MONSTER)
            {
                continue;
            }

            if (monster2.IsActorInvisiable)
            {
                continue;
            }

            float distance = AIHelper.DistanceSquare(item.Value.transform.position, mRunningProperty.SelfActorPos);

            if (distance > viewRange || distance > shortest)
            {
                continue;
            }

            shortest    = distance;
            targetActor = item.Value;
        }

        // 检测场景内的NPC
        var allNpc = NpcManager.Instance.AllNpc;

        foreach (var item in allNpc)
        {
            NpcPlayer npc = item.Value.BindActor as NpcPlayer;
            if (npc.NpcData.Relationship != Neptune.Relationship.FRIENDLY)
            {
                continue;
            }

            float distance = AIHelper.DistanceSquare(npc.transform.position, mRunningProperty.SelfActorPos);

            if (distance > viewRange || distance > shortest)
            {
                continue;
            }

            if (npc.IsActorInvisiable)
            {
                continue;
            }

            shortest    = distance;
            targetActor = npc;
        }

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

        return(targetActor);
    }
示例#12
0
    public override Actor GetDefaultTargetActor()
    {
        Actor targetActor = null;

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

        NpcPlayer npc = mRunningProperty.SelfActor as NpcPlayer;

        if (npc == null)
        {
            return(null);
        }

        if (npc.NpcData.Relationship == Neptune.Relationship.FRIENDLY)
        {
            Dictionary <UnitID, Actor> monsters = ActorManager.Instance.MonsterSet;

            // 计算出最短距离

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

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

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

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

            return(targetActor);
        }
        else if (npc.NpcData.Relationship == Neptune.Relationship.NEUTRAL)
        {
            return(null);
        }
        else if (npc.NpcData.Relationship == Neptune.Relationship.HOSTILE)
        {
            foreach (var item in ActorManager.Instance.PlayerSet)
            {
                if (item.Value.IsDead() || (item.Value.gameObject.activeSelf == false))
                {
                    continue;
                }

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

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

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

            return(targetActor);
        }

        return(base.GetDefaultTargetActor());
    }