private void MoveHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                return;
            }
            UserAiStateInfo         info = user.GetAiStateInfo();
            AiData_UserSelf_General data = GetAiData(user);
            Vector3 targetPos            = info.TargetPos;
            Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D();

            if (null != data && !IsReached(srcPos, targetPos))
            {
                if (info.IsTargetPosChanged)
                {
                    info.IsTargetPosChanged = false;
                    data.FoundPath.Clear();
                }
                PathToTargetPro(user, data.FoundPath, targetPos, deltaTime);
            }
            else
            {
                user.GetMovementStateInfo().StopMove();
                NotifyUserMove(user);
                info.Time      = 0;
                info.Target    = 0;
                info.TargetPos = Vector3.Zero;
                data.Time      = 0;
                data.FoundPath.Clear();
                ChangeToState(user, (int)AiStateId.Idle);
            }
        }
Пример #2
0
        private void GoHomeHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            ChangeToState(npc, (int)AiStateId.Idle);
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > m_IntervalTime)
            {
                info.Time = 0;
                AiData_Demo_Melee data = GetAiData(npc);
                if (null != data)
                {
                    Vector3 targetPos     = info.HomePos;
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    if (powDistToHome <= 1)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        info.Time = 0;
                        ChangeToState(npc, (int)AiStateId.Idle);
                    }
                    else
                    {
                        AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, 100, true, this);
                    }
                }
            }
        }
Пример #3
0
 public void Execute(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
     if (user.GetAIEnable())
     {
         UserAiStateInfo userAi = user.GetAiStateInfo();
         if (userAi.CommandQueue.Count <= 0)
         {
             int curState = userAi.CurState;
             if (curState > (int)AiStateId.Invalid && curState < (int)AiStateId.MaxNum)
             {
                 UserAiStateHandler handler;
                 if (m_Handlers.TryGetValue(curState, out handler))
                 {
                     if (null != handler)
                     {
                         handler(user, aiCmdDispatcher, deltaTime);
                     }
                 }
                 else
                 {
                     LogSystem.Error("Illegal ai state: " + curState + " user:" + user.GetId());
                 }
             }
             else
             {
                 OnStateLogicInit(user, aiCmdDispatcher, deltaTime);
                 ChangeToState(user, (int)AiStateId.Idle);
             }
         }
         ExecuteCommandQueue(user, deltaTime);
     }
 }
        protected override void OnStateLogicInit(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            UserAiStateInfo info = user.GetAiStateInfo();

            info.HomePos = user.GetMovementStateInfo().GetPosition3D();
            info.Time    = 0;
            user.GetMovementStateInfo().IsMoving = false;
        }
        private void ActionDriveHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive data = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                    Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                    float   dist      = Geometry.Distance(srcPos, targetPos);
                    if (data.LastGfxState != npc.GfxStateFlag)
                    {
                        if (data.LastGfxState == (int)GfxCharacterState_Type.KnockDown && npc.GfxStateFlag == (int)GfxCharacterState_Type.GetUp)
                        {
                            // 起身
                            OnEvent(npc, (int)AiEventEnum.GET_UP, target, deltaTime);
                        }
                        data.LastGfxState = npc.GfxStateFlag;
                    }
                    if (npc.IsUnderControl())
                    {
                        data.ControlTime += deltaTime;
                        if (data.ControlTime > data.MaxControlTime && npc.CanDisControl())
                        {
                            data.ControlTime = 0;
                            OnEvent(npc, (int)AiEventEnum.CONTROL_TIME_OVERFLOW, target, deltaTime);
                        }
                        return;
                    }
                    ExecAiAction(npc, target, deltaTime);
                }
                else
                {
                    if (null != data.ActiveAction)
                    {
                        AiActionInfo aiActionInfo         = data.ActiveAction;
                        AiActionForceStopDelegate handler = GetAiActionForceStopHandler(aiActionInfo.Config.AiActionType);
                        if (null != handler)
                        {
                            handler(npc, target);
                        }
                    }
                    else
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                    }
                    ChangeToState(npc, (int)AiStateId.Pursuit);
                }
            }
        }
Пример #6
0
        protected override void OnStateLogicInit(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time = 0;
            npc.GetMovementStateInfo().IsMoving = false;
            info.HomePos = npc.GetMovementStateInfo().GetPosition3D();
            info.Target  = 0;
        }
        protected override void OnStateLogicInit(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time = 0;
            npc.GetMovementStateInfo().IsMoving = false;
            info.Target = 0;
            BlackBoard_SmallMouse blackBoradInfo = GetBlackBorad(npc);

            blackBoradInfo.AddAliveNpc(npc.GetId());
        }
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_ActionDrive 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();
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    // 遇敌是播放特效, 逗留两秒。
                    if (data.WaitTime <= npc.MeetEnemyStayTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack);
                            data.HasMeetEnemy = true;
                        }
                        TrySeeTarget(npc, target);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    // 走向目标1.5秒
                    if (data.MeetEnemyWalkTime < npc.MeetEnemyWalkTime)
                    {
                        data.MeetEnemyWalkTime += deltaTime;
                        NotifyNpcWalk(npc);
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                        return;
                    }
                    ChangeToState(npc, (int)AiStateId.ActionDrive);
                }
                else
                {
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
Пример #9
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                info.Time = 0;
                if (GetAiData(npc).HasPatrolData)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    ChangeToState(npc, (int)AiStateId.PatrolCommand);
                }
                else
                {
                    CharacterInfo target = null;
                    if (info.IsExternalTarget)
                    {
                        target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                        if (null == target)
                        {
                            target = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_ENEMY);
                            if (null != target)
                            {
                                info.Target = target.GetId();
                            }
                        }
                    }
                    else
                    {
                        target = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_ENEMY);
                        if (null != target)
                        {
                            info.Target = target.GetId();
                        }
                    }
                    if (null != target)
                    {
                        NotifyNpcTargetChange(npc);
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        info.Time = 0;
                        ChangeToState(npc, (int)AiStateId.Pursuit);
                    }
                }
            }
        }
        private void PathFindingCommandHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            // Path has found.
            if (!npc.UnityPathFinding)
            {
                return;
            }

            if (npc.PathFindingFinished)
            {
                // npc.PathFindingFinished = false;
                NpcAiStateInfo info = npc.GetAiStateInfo();
                ChangeToState(npc, info.PreviousState);
            }
        }
Пример #11
0
        protected virtual void OnStateLogicInit(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time = 0;
            npc.GetMovementStateInfo().IsMoving = false;
            info.HomePos = npc.GetMovementStateInfo().GetPosition3D();
            info.Target  = 0;
            if (!string.IsNullOrEmpty(info.AiParam[0]))
            {
                if (int.Parse(info.AiParam[0]) == 1)
                {
                    AiLogicUtility.InitPatrolData(npc, this);
                }
            }
        }
        private void PathFindingCommandHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            // Path has found.
            if (!user.UnityPathFinding)
            {
                return;
            }

            if (!user.PathFindingFinished)
            {
                return;
            }

            user.PathFindingFinished = false;
            UserAiStateInfo info = user.GetAiStateInfo();

            ChangeToState(user, info.PreviousState);
        }
Пример #13
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo    info = npc.GetAiStateInfo();
            AiData_Demo_Melee 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();
                    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
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                }
            }
        }
        private void IdleHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                return;
            }
            UserAiStateInfo info = user.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                info.Time = 0;
                CharacterInfo target = null;
                if (info.IsAttacked && m_AttackRangeLast > 0)
                {
                    if (info.Target > 0 /* || info.TargetPos != Vector3.Zero*/)
                    {
                        target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(user, info.Target);
                        if (null == target)
                        {
                            info.Target = 0;
                            target      = AiLogicUtility.GetNearstTargetHelper(user, CharacterRelation.RELATION_ENEMY);
                        }
                    }
                    if (null != target)
                    {
                        info.Time         = 0;
                        info.Target       = target.GetId();
                        info.IsAttacked   = false;
                        info.AttackRange  = m_AttackRangeLast;
                        m_AttackRangeLast = 0;
                        ChangeToState(user, (int)AiStateId.Combat);
                    }
                }
            }
        }
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo         info = npc.GetAiStateInfo();
            AiData_Npc_CommonMelee 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();
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    // 遇敌是播放特效, 逗留两秒。
                    if (data.WaitTime <= npc.MeetEnemyStayTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack);
                            data.HasMeetEnemy = true;
                        }
                        TrySeeTarget(npc, target);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    // 走向目标1.5秒
                    if (data.MeetEnemyWalkTime < npc.MeetEnemyWalkTime)
                    {
                        data.MeetEnemyWalkTime += deltaTime;
                        NotifyNpcWalk(npc);
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            if (!npc.UnityPathFinding)
                            {
                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                            }
                            else
                            {
                                if (!npc.PathFindingFinished)
                                {
                                    GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos);
                                    ChangeToState(npc, (int)AiStateId.PathFinding);
                                }
                                else
                                {
                                    npc.PathFindingFinished = false;
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                            }
                        }
                        return;
                    }

                    // 大于攻击距离 跑向目标
                    if (powDist > m_AttackRange * m_AttackRange && 0 == data.CurAiAction)
                    {
                        npc.IsTaunt = false;
                        NotifyNpcRun(npc);
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            if (!npc.UnityPathFinding)
                            {
                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                            }
                            else
                            {
                                if (!npc.PathFindingFinished)
                                {
                                    GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos);
                                    ChangeToState(npc, (int)AiStateId.PathFinding);
                                }
                                else
                                {
                                    npc.PathFindingFinished = false;
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                            }
                        }
                    }
                    else
                    {
                        //小于攻击距离
                        if (data.CurAiAction == (int)AiAction.NONE)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            data.CurAiAction = (int)GetNextAction();
                        }
                        switch (data.CurAiAction)
                        {
                        case (int)AiAction.SKILL:
                            if (0 >= data.SkillToCast)
                            {
                                data.SkillToCast = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist));
                            }
                            if (0 >= data.SkillToCast || !AiLogicUtility.CanCastSkill(npc, data.SkillToCast, target))
                            {
                                info.Time += deltaTime;
                                if (info.Time > m_IntervalTime)
                                {
                                    info.Time = 0;
                                    NotifyNpcRun(npc);
                                    if (!npc.UnityPathFinding)
                                    {
                                        AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                    }
                                    else
                                    {
                                        if (!npc.PathFindingFinished)
                                        {
                                            GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos);
                                            ChangeToState(npc, (int)AiStateId.PathFinding);
                                        }
                                        else
                                        {
                                            npc.PathFindingFinished = false;
                                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                npc.GetMovementStateInfo().IsMoving = false;
                                NotifyNpcMove(npc);
                                if (TryCastSkill(npc, data.SkillToCast, target))
                                {
                                    data.CurAiAction = 0;
                                    data.SkillToCast = -1;
                                }
                            }
                            break;

                        case (int)AiAction.STAND:
                            data.ChaseStandTime += deltaTime;
                            TrySeeTarget(npc, target);
                            if (data.ChaseStandTime > m_ChaseWalkMaxTime)
                            {
                                data.ChaseStandTime = 0;
                                data.CurAiAction    = 0;
                            }
                            break;

                        case (int)AiAction.TAUNT:
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            npc.IsTaunt     = true;
                            data.TauntTime += deltaTime;
                            TrySeeTarget(npc, target);
                            if (data.TauntTime > m_TauntTime)
                            {
                                npc.IsTaunt      = false;
                                data.TauntTime   = 0;
                                data.CurAiAction = 0;
                            }
                            break;

                        case (int)AiAction.WALK:
                            data.ChaseWalkTime += deltaTime;
                            info.Time          += deltaTime;
                            if (info.Time > m_IntervalTime)
                            {
                                info.Time = 0;
                                NotifyNpcWalk(npc);
                                if (!npc.UnityPathFinding)
                                {
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                                else
                                {
                                    if (!npc.PathFindingFinished)
                                    {
                                        GfxSystem.NpcCommonMeleePathToTarget(npc, targetPos);
                                        ChangeToState(npc, (int)AiStateId.PathFinding);
                                    }
                                    else
                                    {
                                        npc.PathFindingFinished = false;
                                        AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                    }
                                }
                            }
                            if (data.ChaseWalkTime > m_ChaseStandMaxTime)
                            {
                                data.ChaseWalkTime = 0;
                                data.CurAiAction   = 0;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
 private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
     AiLogicUtility.CommonIdleHandler(npc, aiCmdDispatcher, deltaTime, this);
 }
Пример #17
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead() ||
                npc.GetSkillStateInfo().IsSkillActivated())
            {
                npc.GetMovementStateInfo().IsMoving = false;
                NotifyNpcMove(npc);
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();
            AiData_Npc_BossDevilWarrior data = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    if (npc.IsUnderControl())
                    {
                        data.ControlTime += deltaTime;
                        if (data.ControlTime >= m_MaxControlTime && npc.CanDisControl() && AiLogicUtility.CanCastSkill(npc, data.DecontrolSkill, target))
                        {
                            NotifyNpcAddImpact(npc, m_DisControlImpact);
                            data.ControlTime = 0;
                            TryCastSkill(npc, data.DecontrolSkill, target, false);
                            data.CurSkillCombo      = data.DecontrolCombo;
                            data.CurSkillComboIndex = 0;
                        }
                        return;
                    }
                    float   dist          = (float)npc.GetActualProperty().AttackRange;
                    float   distGoHome    = (float)npc.GohomeRange;
                    Vector3 targetPos     = target.GetMovementStateInfo().GetPosition3D();
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    // 遇敌是播放特效, 逗留两秒。
                    if (data.WaitTime <= m_ResponseTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack);
                            data.HasMeetEnemy = true;
                        }
                        TrySeeTarget(npc, target);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    if (null != data.CurSkillCombo)
                    {
                        if (data.CurSkillCombo.Length > data.CurSkillComboIndex)
                        {
                            TryCastSkill(npc, data.CurSkillCombo[data.CurSkillComboIndex], target);
                            data.CurSkillComboIndex = data.CurSkillComboIndex + 1;
                        }
                        else
                        {
                            data.CurSkillCombo      = null;
                            data.CurSkillComboIndex = 0;
                        }
                    }
                    // 大于攻击距离 跑向目标
                    if (powDist > m_AttackRange * m_AttackRange)
                    {
                        if ((int)GfxCharacterState_Type.HitFly == target.GfxStateFlag)
                        {
                            if (TryCastSkill(npc, data.FlyRangeSkill, target))
                            {
                                return;
                            }
                        }
                        else
                        {
                            if (TryCastSkill(npc, data.RangeSkill, target))
                            {
                                return;
                            }
                        }
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            NotifyNpcRun(npc);
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                    else
                    {
                        if ((int)GfxCharacterState_Type.HitFly == target.GfxStateFlag)
                        {
                            if (TryCastSkill(npc, data.FlyMeeleSkill, target))
                            {
                                return;
                            }
                        }
                        else
                        {
                            if (TryCastSkill(npc, data.MeeleSkill, target))
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
        private void EscapeHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                return;
            }
            NpcAiStateInfo    info = npc.GetAiStateInfo();
            AiData_Npc_Bluelf data = GetAiData(npc);

            if (null != data)
            {
                data.EscapeTime += deltaTime;
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                    Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist   = Geometry.DistanceSquare(srcPos, targetPos);
                    if (powDist < m_SafeRange * m_SafeRange)
                    {
                        Vector3 escapePos = Vector3.Zero;
                        if (AiLogicUtility.GetEscapeTargetPos(npc, target, 3.0f, ref escapePos))
                        {
                            info.Time += deltaTime;
                            if (info.Time > m_IntervalTime)
                            {
                                NotifyNpcRun(npc);
                                info.Time = 0;
                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, escapePos, m_IntervalTime, true, this);
                            }
                        }
                        else
                        {
                            LogSystem.Debug("Can't find WalkAble place");
                        }
                    }
                    else
                    {
                        TryCastSkill(npc, GetCanCastSkillId(npc, (float)Math.Sqrt(powDist)), target);
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        info.Time       = 0;
                        data.EscapeTime = 0;
                        ChangeToState(npc, (int)AiStateId.Pursuit);
                    }
                }
                else
                {
                    NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
                if (data.EscapeTime > m_MaxEscapeTime)
                {
                    data.EscapeTime = 0;
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Pursuit);
                }
            }
        }
Пример #19
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                npc.GetMovementStateInfo().IsMoving = false;
                NotifyNpcMove(npc);
                return;
            }
            NpcAiStateInfo        info = npc.GetAiStateInfo();
            AiData_Npc_CommonBoss data = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    if (npc.GetSkillStateInfo().IsSkillActivated())
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        data.LastUseSkillTime = TimeUtility.GetServerMilliseconds();
                        return;
                    }
                    if (npc.IsUnderControl())
                    {
                        data.ControlTime += deltaTime;
                        if (data.ControlTime >= m_MaxControlTime && npc.CanDisControl() && AiLogicUtility.CanCastSkill(npc, m_DisControlSkillId, target))
                        {
                            NotifyNpcAddImpact(npc, m_DisControlImpactId);
                            data.ControlTime = 0;
                            TryCastSkill(npc, m_DisControlSkillId, target, false);
                        }
                        return;
                    }
                    float   dist          = (float)npc.GetActualProperty().AttackRange;
                    float   distGoHome    = (float)npc.GohomeRange;
                    Vector3 targetPos     = target.GetMovementStateInfo().GetPosition3D();
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    // 遇敌是播放特效, 逗留两秒。
                    if (data.WaitTime <= m_ResponseTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack);
                            data.HasMeetEnemy = true;
                        }
                        TrySeeTarget(npc, target);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    int  skillId = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist));
                    long curTime = TimeUtility.GetServerMilliseconds();
                    if (-1 != skillId && curTime - data.LastUseSkillTime > m_SkillInterval && AiLogicUtility.CanCastSkill(npc, skillId, target))
                    {
                        if (TryCastSkill(npc, skillId, target, true))
                        {
                            NotifyNpcAddImpact(npc, m_SuperArmorImpactId);
                        }
                    }
                    else
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                }
                else
                {
                    NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
Пример #20
0
 protected abstract void OnStateLogicInit(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime);
Пример #21
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > m_IntervalTime)
            {
                info.Time = 0;
                DropOutInfo dropInfo = npc.GetAiStateInfo().AiDatas.GetData <DropOutInfo>();
                if (null != dropInfo)
                {
                    if (npc.IsBorning)
                    {
                        Vector3 curPos = npc.GetMovementStateInfo().GetPosition3D();
                        if (dropInfo.BornTarget == Vector3.Zero)
                        {
                            double tempAngle = CrossEngineHelper.Random.NextFloat() * Math.PI;
                            float  length    = CrossEngineHelper.Random.NextFloat() * 3.0f;
                            dropInfo.BornTarget = curPos + new Vector3((float)Math.Cos(tempAngle), 0, (float)Math.Sin(tempAngle)) * length;
                            dropInfo.BornAngle  = (float)tempAngle;
                        }
                        //npc.GetMovementStateInfo().SetMoveDir(dropInfo.BornAngle);
                        //npc.GetMovementStateInfo().IsMoving = true;
                        //NotifyNpcWalk(npc);
                        return;
                    }
                    else
                    {
                        if (!dropInfo.IsBornOver)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                        }
                    }
                }
                UserInfo target = null;
                target = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_FRIEND, AiTargetType.USER) as UserInfo;
                if (null != target && !npc.NeedDelete)
                {
                    Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                    Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                    float   dis       = Geometry.Distance(srcPos, targetPos);
                    float   angle     = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                    if (dis <= m_AttractRange && dis > m_PickUpRange)
                    {
                        // 吸取
                        float move = npc.GetActualProperty().MoveSpeed *m_IntervalTime / 1000;
                        npc.GetMovementStateInfo().SetMoveDir(angle);
                        //npc.GetMovementStateInfo().PositionY = targetPos.Y + (1 - dis / m_AttractRange) * m_Height;
                        //npc.GetMovementStateInfo().SetPosition2D(srcPos.X + move * (float)Math.Cos(angle), srcPos.Z + move * (float)Math.Sin(angle));
                        npc.GetMovementStateInfo().IsMoving = true;
                        NotifyNpcRun(npc);
                    }
                    else if (dis <= m_PickUpRange)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        string path = "";
                        if (null != dropInfo)
                        {
                            switch (dropInfo.DropType)
                            {
                            case DropOutType.GOLD:
                                target.Money += dropInfo.Value;
                                target.UserManager.FireGainMoneyEvent(target.GetId(), dropInfo.Value);
                                path = "ef_head";
                                break;

                            case DropOutType.HP:
                                int addHp = (int)(target.GetActualProperty().HpMax *dropInfo.Value / 100.0f);
                                if (target.GetActualProperty().HpMax > addHp + target.Hp)
                                {
                                    target.SetHp(Operate_Type.OT_Relative, addHp);
                                }
                                else
                                {
                                    target.SetHp(Operate_Type.OT_Absolute, target.GetActualProperty().HpMax);
                                }
                                target.UserManager.FireDamageEvent(target.GetId(), -1, false, false, addHp, 0);
                                path = "Bone_Root";
                                break;

                            case DropOutType.MP:
                                int addEnergy = (int)(target.GetActualProperty().EnergyMax *dropInfo.Value / 100.0f);
                                if (target.GetActualProperty().EnergyMax > addEnergy + target.Energy)
                                {
                                    target.SetEnergy(Operate_Type.OT_Relative, addEnergy);
                                }
                                else
                                {
                                    target.SetEnergy(Operate_Type.OT_Absolute, target.GetActualProperty().EnergyMax);
                                }
                                target.UserManager.FireDamageEvent(target.GetId(), -1, false, false, 0, addEnergy);
                                path = "Bone_Root";
                                break;

                            case DropOutType.MULT_GOLD:
                                target.Money += dropInfo.Value;
                                target.UserManager.FireGainMoneyEvent(target.GetId(), dropInfo.Value);
                                path = "ef_head";
                                break;
                            }
                            if (null != OnDropoutPlayEffect)
                            {
                                OnDropoutPlayEffect(target, npc, dropInfo.Particle, path, (int)dropInfo.DropType, dropInfo.Value);
                            }
                        }
                        npc.NeedDelete = true;
                    }
                }
            }
        }
Пример #22
0
        private void PursuitHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                user.GetMovementStateInfo().IsMoving = false;
                return;
            }
            if (user.IsUnderControl())
            {
                user.GetMovementStateInfo().IsMoving = false;
                return;
            }
            if (user.GetSkillStateInfo().IsSkillActivated())
            {
                user.GetMovementStateInfo().IsMoving = false;
                return;
            }
            UserAiStateInfo         info = user.GetAiStateInfo();
            AiData_UserSelf_General data = GetAiData(user);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(user, info.Target);
                if (null != target)
                {
                    float   dist          = (float)user.GetActualProperty().AttackRange;
                    float   distGoHome    = (float)user.GohomeRange;
                    Vector3 targetPos     = target.GetMovementStateInfo().GetPosition3D();
                    Vector3 srcPos        = user.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    TryCastSkill(user, target, powDist);
                    // 大于攻击距离 跑向目标
                    if (powDist > m_AttackRange * m_AttackRange)
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            if (!user.UnityPathFinding)
                            {
                                AiLogicUtility.PathToTargetWithoutObstacle(user, data.FoundPath, targetPos, m_IntervalTime, true, this);
                            }
                            else
                            {
                                if (info.PreviousState != (int)AiStateId.PathFinding)
                                {
                                    user.PathFindingFinished = false;
                                    GfxSystem.UserSelfGeneralPathToTarget(user, targetPos);
                                    ChangeToState(user, (int)AiStateId.PathFinding);
                                }
                                else
                                {
                                    AiLogicUtility.PathToTargetWithoutObstacle(user, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                            }
                        }
                    }
                    else
                    {
                        user.GetMovementStateInfo().IsMoving = false;
                        NotifyUserMove(user);
                    }
                }
                else
                {
                    user.GetMovementStateInfo().IsMoving = false;
                    NotifyUserMove(user);
                    info.Time = 0;
                    ChangeToState(user, (int)AiStateId.Idle);
                }
            }
        }
Пример #23
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead() ||
                npc.GetSkillStateInfo().IsSkillActivated())
            {
                npc.GetMovementStateInfo().IsMoving = false;
                NotifyNpcMove(npc);
                return;
            }
            NpcAiStateInfo    info = npc.GetAiStateInfo();
            AiData_Npc_Bluelf data = GetAiData(npc);

            if (null != data)
            {
                if (npc.IsUnderControl())
                {
                    data.ControlTime += deltaTime;
                    if (data.ControlTime >= m_MaxControlTime && npc.CanDisControl())
                    {
                        NotifyNpcAddImpact(npc, m_SuperAmorImpact);
                        data.ControlTime = 0;
                    }
                    return;
                }
                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();
                    Vector3 srcPos        = npc.GetMovementStateInfo().GetPosition3D();
                    float   powDist       = Geometry.DistanceSquare(srcPos, targetPos);
                    float   powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    // 遇敌是播放特效, 短暂逗留。
                    if (data.WaitTime <= m_ResponseTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            NotifyNpcMeetEnemy(npc, Animation_Type.AT_Attack);
                            data.HasMeetEnemy = true;
                        }
                        TrySeeTarget(npc, target);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    int randomNum = CrossEngineHelper.Random.Next(0, 10);
                    // 大于攻击距离 跑向目标
                    if (powDist > m_AttackRange * m_AttackRange && 0 == data.CurAiAction)
                    {
                        if (randomNum < 8)
                        {
                            TryCastSkill(npc, m_DisSkill, target);
                            return;
                        }
                        else if (randomNum < 9)
                        {
                            TryCastSkill(npc, m_CommonSkill, target);
                            return;
                        }
                        npc.IsTaunt = false;
                        NotifyNpcRun(npc);
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                    else
                    {
                        //小于攻击距离
                        if (data.CurAiAction == (int)AiAction.NONE)
                        {
                            if (randomNum < 7)
                            {
                                TryCastSkill(npc, m_CommonSkill, target);
                                return;
                            }
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            data.CurAiAction = (int)GetNextAction();
                        }
                        switch (data.CurAiAction)
                        {
                        case (int)AiAction.SKILL:
                            int skillId = GetCanCastSkillId(npc, (float)Math.Sqrt(powDist));
                            if (-1 == skillId)
                            {
                                info.Time += deltaTime;
                                if (info.Time > m_IntervalTime)
                                {
                                    info.Time = 0;
                                    NotifyNpcRun(npc);
                                    AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                                }
                            }
                            else
                            {
                                npc.GetMovementStateInfo().IsMoving = false;
                                NotifyNpcMove(npc);
                                if (TryCastSkill(npc, skillId, target))
                                {
                                    data.CurAiAction = 0;
                                }
                            }
                            break;

                        case (int)AiAction.STAND:
                            data.ChaseStandTime += deltaTime;
                            TrySeeTarget(npc, target);
                            if (data.ChaseStandTime > m_ChaseWalkMaxTime)
                            {
                                data.ChaseStandTime = 0;
                                data.CurAiAction    = 0;
                            }
                            break;

                        case (int)AiAction.TAUNT:
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            npc.IsTaunt     = true;
                            data.TauntTime += deltaTime;
                            TrySeeTarget(npc, target);
                            if (data.TauntTime > m_TauntTime)
                            {
                                npc.IsTaunt      = false;
                                data.TauntTime   = 0;
                                data.CurAiAction = 0;
                            }
                            break;

                        case (int)AiAction.WALK:
                            data.ChaseWalkTime += deltaTime;
                            info.Time          += deltaTime;
                            if (info.Time > m_IntervalTime)
                            {
                                info.Time = 0;
                                NotifyNpcWalk(npc);
                                AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                            }
                            if (data.ChaseWalkTime > m_ChaseWalkMaxTime)
                            {
                                data.ChaseWalkTime = 0;
                                data.CurAiAction   = 0;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
 private void PatrolCommandHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
     AiLogicUtility.DoPatrolCommandState(npc, aiCmdDispatcher, deltaTime, this);
 }
 private void PursuitCommandHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
     AiLogicUtility.DoPursuitCommandState(user, aiCmdDispatcher, deltaTime, this);
 }
Пример #26
0
 private void PatrolCommandHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
 }
        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();
                        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)
                                {
                                    PathToTargetPro(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;
                    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;
                            PathToTargetPro(user, data.FoundPath, targetPos, deltaTime);
                        }
                    }
                }
            }
        }
Пример #28
0
 private void IdleHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
     AiLogicUtility.CommonIdleHandler(user, aiCmdDispatcher, deltaTime, this);
 }
        private void CombatHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (user.IsDead())
            {
                return;
            }
            UserAiStateInfo info = user.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                AiData_UserSelf_General data = GetAiData(user);
                if (null != data)
                {
                    data.Time += info.Time;
                    info.Time  = 0;
                    //info.IsAttacked = false;
                    CharacterInfo target    = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(user, info.Target);
                    Vector3       targetPos = Vector3.Zero;
                    float         dist      = info.AttackRange;
                    if (null != target)
                    {
                        targetPos = target.GetMovementStateInfo().GetPosition3D();
                    }
                    else
                    {
                        targetPos = info.TargetPos;
                    }
                    Vector3 srcPos  = user.GetMovementStateInfo().GetPosition3D();
                    float   powDist = Geometry.DistanceSquare(srcPos, targetPos);
                    if (!info.IsAttacked)
                    {
                        if (powDist < dist * dist)
                        {
                            data.Time         = 0;
                            m_AttackRangeLast = info.AttackRange;
                            info.AttackRange  = 0;
                            info.IsAttacked   = true;
                            float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            user.GetMovementStateInfo().SetFaceDir(dir);
                            user.GetMovementStateInfo().SetMoveDir(dir);
                            if (null != target)
                            {
                                if (null != OnUserStartAttack)
                                {
                                    OnUserStartAttack(user, targetPos.X, targetPos.Y, targetPos.Z);
                                }
                            }
                            else
                            {
                                NotifyUserSkill(user, 1);
                                info.IsAttacked = false;
                            }
                            ///
                            user.GetMovementStateInfo().StopMove();
                            NotifyUserMove(user);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(user, (int)AiStateId.Idle);
                        }
                        else
                        {
                            user.GetMovementStateInfo().StopMove();
                            NotifyUserMove(user);
                            info.Time       = 0;
                            info.IsAttacked = false;
                            data.FoundPath.Clear();
                            ChangeToState(user, (int)AiStateId.Pursuit);
                        }
                    }
                }
                else
                {
                    info.Time = 0;
                }
            }
        }
Пример #30
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (!CanAiControl(npc))
            {
                npc.GetMovementStateInfo().IsMoving = false;
                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;
                    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;
                        Vector3 targetPos     = target.GetMovementStateInfo().GetPosition3D();
                        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;
                            long  curTime = TimeUtility.GetServerMilliseconds();
                            float dir     = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            NotifyNpcFace(npc, dir);
                            //if (rps > 0.001f && curTime - data.LastUseSkillTime > 1000 / rps) {
                            data.Time             = 0;
                            data.LastUseSkillTime = curTime;
                            List <SkillInfo> skillInfos = npc.GetSkillStateInfo().GetAllSkill();
                            if (skillInfos.Count > 0)
                            {
                                int index = CrossEngineHelper.Random.Next(skillInfos.Count);
                                if (null != skillInfos[index])
                                {
                                    NotifyNpcSkill(npc, skillInfos[index].SkillId);
                                }
                            }
                            //}
                        }
                        else
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                    }
                }
                else
                {
                    info.Time = 0;
                }
            }
        }