示例#1
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo        info   = npc.GetAiStateInfo();
            bool                  goHome = false;
            AiData_PveNpc_General data   = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    float   dist                 = (float)npc.GetActualProperty().AttackRange;
                    float   distGoHome           = (float)npc.GohomeRange;
                    Vector3 targetPos            = target.GetMovementStateInfo().GetPosition3D();
                    ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
                    float powDist                = Geometry.DistanceSquare(srcPos, targetPos);
                    float powDistToHome          = Geometry.DistanceSquare(srcPos, info.HomePos);
                    if (powDist < dist * dist)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        info.Time = 0;
                        data.Time = 0;
                        ChangeToState(npc, (int)AiStateId.Combat);
                        NotifyNpcMove(npc);
                    }
                    else if (true) // 目标存活的情况下屏蔽掉gohome。
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                    else
                    {
                        goHome = true;
                    }
                }
                else
                {
                    goHome = true;
                }
                if (goHome)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    data.Time = 0;
                    ChangeToState(npc, (int)AiStateId.GoHome);
                }
            }
        }
        private void PursuitHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                return;
            }
            UserAiStateInfo         info = user.GetAiStateInfo();
            AiData_UserSelf_General data = GetAiData(user);

            if (null != data)
            {
                if (info.Target > 0)
                {
                    CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(user, info.Target);
                    if (null != target)
                    {
                        float   dist                 = info.AttackRange - 1.0f;
                        Vector3 targetPos            = target.GetMovementStateInfo().GetPosition3D();
                        ScriptRuntime.Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D();
                        float powDist                = Geometry.DistanceSquare(srcPos, targetPos);
                        if (powDist < dist * dist)
                        {
                            user.GetMovementStateInfo().IsMoving = false;
                            info.Time = 0;
                            data.Time = 0;
                            ChangeToState(user, (int)AiStateId.Combat);
                            NotifyUserMove(user);
                        }
                        else
                        {
                            info.Time += deltaTime;
                            if (info.Time > 100)
                            {
                                info.Time = 0;
                                CharacterInfo target2 = GetCanAttackUserTarget(user);
                                if (null == target2)
                                {
                                    AiLogicUtility.GetNearstTargetHelper(user, CharacterRelation.RELATION_ENEMY);
                                }
                                if (null == target2 || target == target2)
                                {
                                    PathToTarget(user, data.FoundPath, targetPos, deltaTime);
                                }
                                else
                                {
                                    info.Target = target2.GetId();
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        user.GetMovementStateInfo().StopMove();
                        NotifyUserMove(user);
                        info.Time = 0;
                        data.Time = 0;
                        data.FoundPath.Clear();
                        ChangeToState(user, (int)AiStateId.Idle);
                    }
                }
                else
                {
                    float   dist                 = info.AttackRange;
                    Vector3 targetPos            = info.TargetPos;
                    ScriptRuntime.Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D();
                    float powDist                = Geometry.DistanceSquare(srcPos, targetPos);
                    if (powDist < dist * dist)
                    {
                        user.GetMovementStateInfo().IsMoving = false;
                        info.Time = 0;
                        data.Time = 0;
                        ChangeToState(user, (int)AiStateId.Combat);
                        NotifyUserMove(user);
                    }
                    else
                    {
                        info.Time += deltaTime;
                        if (info.Time > 100)
                        {
                            info.Time = 0;
                            PathToTarget(user, data.FoundPath, targetPos, deltaTime);
                        }
                    }
                }
            }
        }
示例#3
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > m_IntervalTime)
            {
                AiData_Demo_Melee data = GetAiData(npc);
                if (null != data)
                {
                    data.Time += info.Time;
                    info.Time  = 0;
                    bool          goHome = false;
                    CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                    //CharacterInfo target = AiLogicUtility.GetInterestestTargetHelper(npc, CharacterRelation.RELATION_ENEMY, AiTargetType.USER);
                    if (null != target)
                    {
                        float dist       = (float)npc.GetActualProperty().AttackRange;
                        float distGoHome = (float)npc.GohomeRange;
                        ScriptRuntime.Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                        ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                        float powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                        float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                        if (powDist < dist * dist)
                        {
                            float rps = npc.GetActualProperty().Rps;
                            if (rps > 0.001f && data.Time > 1000 / rps)
                            {
                                data.Time = 0;
                                float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                                NotifyNpcFace(npc, dir);
                                //npc.GetMovementStateInfo().SetMoveDir(dir);
                                if (powDist < (npc.ViewRange - 1.0f) * (npc.ViewRange - 1.0f))
                                {
                                    if (0 == data.SkillToCast)
                                    {
                                        data.SkillToCast = GetNextSkill();
                                    }
                                    if (null != OnNpcSkill)
                                    {
                                        float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                                        if (Geometry.IsSameDouble(angle, npc.GetMovementStateInfo().GetFaceDir()))
                                        {
                                            OnNpcSkill(npc, data.SkillToCast, target);
                                            data.SkillToCast = 0;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            data.SkillToCast = 0;
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                    }
                    else
                    {
                        goHome = true;
                    }
                    if (goHome)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        info.Time = 0;
                        ChangeToState(npc, (int)AiStateId.GoHome);
                    }
                }
                else
                {
                    info.Time = 0;
                }
            }
        }
示例#4
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo    info   = npc.GetAiStateInfo();
            bool              goHome = false;
            AiData_Demo_Melee data   = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    if (data.WaitTime <= m_ResponseTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            if (null != OnNpcMeetEnemy)
                            {
                                OnNpcMeetEnemy(npc, data.MeetEnemyAnim);
                            }
                            data.HasMeetEnemy = true;
                        }
                        float angle = Geometry.GetYAngle(npc.GetMovementStateInfo().GetPosition2D(), target.GetMovementStateInfo().GetPosition2D());
                        NotifyNpcFace(npc, angle);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    data.WalkTime += deltaTime;
                    if (data.WalkTime < 4000)
                    {
                        npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, GetWalkSpeed(npc));
                        npc.GetMovementStateInfo().MovementMode = MovementMode.LowSpeed;
                    }
                    else
                    {
                        npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, GetRunSpeed(npc));
                        npc.GetMovementStateInfo().MovementMode = MovementMode.HighSpeed;
                    }
                    float   dist                 = (float)npc.GetActualProperty().AttackRange;
                    float   distGoHome           = (float)npc.GohomeRange;
                    Vector3 targetPos            = target.GetMovementStateInfo().GetPosition3D();
                    ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
                    float powDist                = Geometry.DistanceSquare(srcPos, targetPos);
                    if (0 == data.SkillToCast)
                    {
                        data.SkillToCast = GetNextSkill();
                    }
                    if (powDist < (npc.ViewRange - m_TauntDis) * (npc.ViewRange - m_TauntDis))
                    {
                        if (m_Taunt == data.SkillToCast)
                        {
                            float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            if (Geometry.IsSameDouble(angle, npc.GetMovementStateInfo().GetFaceDir()))
                            {
                                OnNpcSkill(npc, data.SkillToCast, target);
                                data.SkillToCast = 0;
                            }
                        }
                    }
                    float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    if (powDist < dist * dist)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        info.Time = 0;
                        data.Time = 0;
                        npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, GetRunSpeed(npc));
                        npc.GetMovementStateInfo().MovementMode = MovementMode.HighSpeed;
                        ChangeToState(npc, (int)AiStateId.Combat);
                        NotifyNpcMove(npc);
                    }
                    else
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                }
                else
                {
                    goHome = true;
                }
                if (goHome)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    data.Time = 0;
                    npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, 3.5f);
                    ChangeToState(npc, (int)AiStateId.Combat);
                    ChangeToState(npc, (int)AiStateId.GoHome);
                }
            }
        }