예제 #1
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                info.Time = 0;
                CharacterInfo target = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_ENEMY);
                if (null != target)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    info.Time   = 0;
                    info.Target = target.GetId();
                    ChangeToState(npc, (int)AiStateId.Combat);
                    NotifyNpcTargetChange(npc);
                }
                else
                {
                }
            }
        }
예제 #2
0
        internal static Msg_RC_NpcMove BuildNpcMoveMessage(NpcInfo npc)
        {
            Msg_RC_NpcMove npcMoveBuilder = new Msg_RC_NpcMove();

            if (npc.GetMovementStateInfo().IsMoving)
            {
                npcMoveBuilder.npc_id         = npc.GetId();
                npcMoveBuilder.is_moving      = true;
                npcMoveBuilder.move_direction = (float)npc.GetMovementStateInfo().GetMoveDir();
                npcMoveBuilder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir();
                npcMoveBuilder.cur_pos_x      = npc.GetMovementStateInfo().GetPosition3D().X;
                npcMoveBuilder.cur_pos_z      = npc.GetMovementStateInfo().GetPosition3D().Z;
                NpcAiStateInfo data = npc.GetAiStateInfo();
                npcMoveBuilder.target_pos_x         = npc.GetMovementStateInfo().TargetPosition.X;
                npcMoveBuilder.target_pos_z         = npc.GetMovementStateInfo().TargetPosition.Z;
                npcMoveBuilder.velocity_coefficient = (float)npc.VelocityCoefficient;
                npcMoveBuilder.velocity             = npc.GetActualProperty().MoveSpeed;
                npcMoveBuilder.move_mode            = (int)npc.GetMovementStateInfo().MovementMode;
            }
            else
            {
                npcMoveBuilder.npc_id    = npc.GetId();
                npcMoveBuilder.is_moving = false;
                npcMoveBuilder.cur_pos_x = npc.GetMovementStateInfo().GetPosition3D().X;
                npcMoveBuilder.cur_pos_z = npc.GetMovementStateInfo().GetPosition3D().Z;
            }
            return(npcMoveBuilder);
        }
예제 #3
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            NpcAiStateInfo info = npc.GetAiStateInfo();

            npc.GetMovementStateInfo().IsMoving = false;
            ChangeToState(npc, (int)AiStateId.Wait);
        }
예제 #4
0
 public void Execute(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
     if (npc.GetAIEnable())
     {
         NpcAiStateInfo npcAi = npc.GetAiStateInfo();
         if (npcAi.CommandQueue.Count <= 0)
         {
             int curState = npcAi.CurState;
             if (curState > (int)AiStateId.Invalid && curState < (int)AiStateId.MaxNum)
             {
                 if (m_Handlers.ContainsKey(curState))
                 {
                     NpcAiStateHandler handler = m_Handlers[curState];
                     if (null != handler)
                     {
                         handler(npc, aiCmdDispatcher, deltaTime);
                     }
                 }
                 else
                 {
                     LogSystem.Error("Illegal ai state: " + curState + " npc:" + npc.GetId());
                 }
             }
             else
             {
                 OnStateLogicInit(npc, aiCmdDispatcher, deltaTime);
                 ChangeToState(npc, (int)AiStateId.Idle);
             }
         }
         ExecuteCommandQueue(npc, deltaTime);
     }
 }
예제 #5
0
        private void MoveHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                npc.GetMovementStateInfo().IsMoving = false;
                ChangeToState(npc, (int)AiStateId.Wait);
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 10)
            {
                info.Time = 0;
                Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                Vector3 startPos  = info.HomePos;
                Vector3 targetPos = npc.GetMovementStateInfo().TargetPosition;
                if (!IsReached(srcPos, targetPos))
                {
                    float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                    npc.GetMovementStateInfo().SetMoveDir(angle);
                    npc.GetMovementStateInfo().IsMoving = true;
                }
            }
        }
예제 #6
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo        info = npc.GetAiStateInfo();
            AiData_PvpNpc_General data = GetAiData(npc);

            if (null != data)
            {
                npc.GetMovementStateInfo().IsMoving = false;
                if (data.PatrolPath.HavePathPoint)
                {
                    info.HomePos = npc.GetMovementStateInfo().GetPosition3D();
                    info.Time    = 0;
                    data.FoundPath.Clear();
                    ChangeToState(npc, (int)AiStateId.Patrol);
                }
                else
                {
                    ChangeToState(npc, (int)AiStateId.Combat);
                }
            }
        }
예제 #7
0
        private void GoHomeHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                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;
                    ScriptRuntime.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);
                    }
                }
            }
        }
예제 #8
0
        protected override void OnStateLogicInit(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.HomePos = npc.GetMovementStateInfo().GetPosition3D();
            info.Time    = 0;
            info.Target  = 0;
            npc.GetMovementStateInfo().IsMoving = false;
        }
예제 #9
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);
                }
            }
        }
예제 #10
0
        internal static Msg_RC_NpcTarget BuildNpcTargetMessage(NpcInfo npc)
        {
            Msg_RC_NpcTarget npcFaceTargetBuilder = null;
            NpcAiStateInfo   data = npc.GetAiStateInfo();

            if (null != data && data.Target > 0)
            {
                npcFaceTargetBuilder           = new Msg_RC_NpcTarget();
                npcFaceTargetBuilder.npc_id    = npc.GetId();
                npcFaceTargetBuilder.target_id = data.Target;
            }
            return(npcFaceTargetBuilder);
        }
예제 #11
0
        protected override void OnStateLogicInit(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            NpcAiStateInfo        info = npc.GetAiStateInfo();
            AiData_PvpNpc_General data = GetAiData(npc);

            if (null != data)
            {
                info.Time = 0;
                npc.GetMovementStateInfo().IsMoving = false;
                info.HomePos = npc.GetMovementStateInfo().GetPosition3D();
                info.Target  = 0;
            }
        }
예제 #12
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                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);
                    }
                }
            }
        }
예제 #13
0
        private void InitPatrolData(NpcInfo npc)
        {
            AiData_ForPatrolCommand data = new AiData_ForPatrolCommand();

            data.IsLoopPatrol = true;
            List <Vector3> path = new List <Vector3>();
            NpcAiStateInfo info = npc.GetAiStateInfo();

            path = Converter.ConvertVector3DList(info.AiParam[1]);
            data.PatrolPath.SetPathPoints(npc.GetAiStateInfo().HomePos, path);
            npc.GetAiStateInfo().AiDatas.AddData <AiData_ForPatrolCommand>(data);
            AiData_Demo_Melee aiData = GetAiData(npc);

            aiData.HasPatrolData = true;
        }
예제 #14
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            float rps = npc.GetActualProperty().Rps;

            if (rps > 0.001f && info.Time > 1000 / rps)
            {
                info.Time = 0;
                bool          toIdle = false;
                CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                if (null != target && npc.SpatialSystem.CanShoot(npc.SpaceObject, target.GetMovementStateInfo().GetPosition3D()))
                {
                    ScriptRuntime.Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                    ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                    float powDist  = Geometry.DistanceSquare(srcPos, targetPos);
                    float dist     = (float)npc.GetActualProperty().AttackRange;
                    float distView = (float)npc.ViewRange;
                    if (powDist < dist * dist)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                    }
                    else if (powDist < distView * distView)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                    }
                    else
                    {
                        toIdle = true;
                    }
                }
                else
                {
                    toIdle = true;
                }
                if (toIdle)
                {
                    info.Time = 0;
                    npc.GetMovementStateInfo().IsMoving = false;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
예제 #15
0
        private AiData_PveNpc_Monster_CloseCombat GetAiData(NpcInfo npc)
        {
            AiData_PveNpc_Monster_CloseCombat data = npc.GetAiStateInfo().AiDatas.GetData <AiData_PveNpc_Monster_CloseCombat>();

            if (null == data)
            {
                NpcAiStateInfo info = npc.GetAiStateInfo();
                data = new AiData_PveNpc_Monster_CloseCombat();
                data.FastMoveImpact     = int.Parse(info.AiParam[0]);
                data.PreAttackImpact    = int.Parse(info.AiParam[1]);
                data.PreAttackDistance  = int.Parse(info.AiParam[2]);
                data.StandShootDistance = int.Parse(info.AiParam[3]);
                npc.GetAiStateInfo().AiDatas.AddData(data);
            }
            return(data);
        }
예제 #16
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                info.Time = 0;
                npc.GetMovementStateInfo().IsMoving = false;
                ChangeToState(npc, (int)AiStateId.PatrolCommand);
            }
        }
예제 #17
0
        private void PatrolHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                info.Time = 0;
                AiData_PvpNpc_General data = GetAiData(npc);
                if (null != data)
                {
                    CharacterInfo interestestTarget = GetInterestestTargetHelper(npc, CharacterRelation.RELATION_ENEMY);
                    if (null != interestestTarget)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        info.Time   = 0;
                        info.Target = interestestTarget.GetId();
                        data.FoundPath.Clear();
                        ChangeToState(npc, (int)AiStateId.Pursuit);
                    }
                    else
                    {
                        ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
                        if (!data.PatrolPath.IsReached(srcPos))
                        {
                            PathToTargetWithoutObstacle(npc, data.FoundPath, data.PatrolPath.CurPathPoint, 100);
                        }
                        else
                        {
                            data.PatrolPath.UseNextPathPoint();
                            data.FoundPath.Clear();
                            if (!data.PatrolPath.HavePathPoint)
                            {
                                info.Time = 0;
                                ChangeToState(npc, (int)AiStateId.Idle);
                            }
                        }
                        info.HomePos = npc.GetMovementStateInfo().GetPosition3D();
                    }
                }
            }
        }
예제 #18
0
        private void ExecuteCommandQueue(NpcInfo npc, long deltaTime)
        {
            NpcAiStateInfo npcAi = npc.GetAiStateInfo();

            while (npcAi.CommandQueue.Count > 0)
            {
                IAiCommand cmd = npcAi.CommandQueue.Peek();
                if (cmd.Execute(deltaTime))
                {
                    npcAi.CommandQueue.Dequeue();
                }
                else
                {
                    break;
                }
            }
        }
예제 #19
0
        private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo     info = npc.GetAiStateInfo();
            AiData_PveNpc_Trap data = GetAiData(npc);

            if (null != data)
            {
                info.Time += deltaTime;
                if (info.Time > 100)
                {
                    info.Time = 0;
                    if (data.HideImpact > 0)
                    {
                        ImpactInfo impactInfo = npc.GetSkillStateInfo().GetImpactInfoById(data.HideImpact);
                        if (null == impactInfo)
                        {
                            ServerNpcImpact(npc, data.HideImpact, npc);
                        }
                    }
                    IList <ISpaceObject> objs = npc.SpatialSystem.GetObjectInCircle(npc.GetMovementStateInfo().GetPosition3D(), data.RadiusOfTrigger);
                    foreach (ISpaceObject obj in objs)
                    {
                        if (obj.GetObjType() == SpatialObjType.kNPC || obj.GetObjType() == SpatialObjType.kUser)
                        {
                            CharacterInfo charInfo = obj.RealObject as CharacterInfo;
                            if (null != charInfo)
                            {
                                if (CharacterInfo.GetRelation(npc, charInfo) == CharacterRelation.RELATION_ENEMY)
                                {
                                    info.Time   = 0;
                                    info.Target = charInfo.GetId();
                                    ChangeToState(npc, (int)AiStateId.Combat);
                                    NotifyNpcTargetChange(npc);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #20
0
        private void InitIdleAnim(NpcInfo npc)
        {
            NpcAiStateInfo info = npc.GetAiStateInfo();

            if (null != info)
            {
                List <int> anims = Converter.ConvertNumericList <int>(info.AiParam[1]);
                if (null != OnSetNpcIdleAnim)
                {
                    OnSetNpcIdleAnim(npc, anims);
                }
                if (!string.IsNullOrEmpty(info.AiParam[2]))
                {
                    AiData_Demo_Melee aiData = GetAiData(npc);
                    aiData.MeetEnemyAnim = (Animation_Type)int.Parse(info.AiParam[2]);
                }
            }
        }
예제 #21
0
        private AiData_PveNpc_Monster GetAiData(NpcInfo npc)
        {
            AiData_PveNpc_Monster data = npc.GetAiStateInfo().AiDatas.GetData <AiData_PveNpc_Monster>();

            if (null == data)
            {
                NpcAiStateInfo info = npc.GetAiStateInfo();
                data = new AiData_PveNpc_Monster();
                SkillInfo skillInfo = npc.GetSkillStateInfo().GetSkillInfoByIndex(0);
                if (null != skillInfo)
                {
                    data.Skill = skillInfo.SkillId;
                }
                data.ShootDistance = int.Parse(info.AiParam[0]);
                npc.GetAiStateInfo().AiDatas.AddData(data);
            }
            return(data);
        }
예제 #22
0
        private AiData_PveNpc_Trap GetAiData(NpcInfo npc)
        {
            AiData_PveNpc_Trap data = npc.GetAiStateInfo().AiDatas.GetData <AiData_PveNpc_Trap>();

            if (null == data)
            {
                NpcAiStateInfo info = npc.GetAiStateInfo();
                data = new AiData_PveNpc_Trap();
                data.RadiusOfTrigger = int.Parse(info.AiParam[0]);
                data.RadiusOfDamage  = int.Parse(info.AiParam[1]);
                data.DamageCount     = int.Parse(info.AiParam[2]);
                data.ImpactToMyself  = int.Parse(info.AiParam[3]);
                data.Impact1ToTarget = int.Parse(info.AiParam[4]);
                data.Impact2ToTarget = int.Parse(info.AiParam[5]);
                data.HideImpact      = int.Parse(info.AiParam[6]);
                npc.GetAiStateInfo().AiDatas.AddData(data);
            }
            return(data);
        }
예제 #23
0
        //确定新的攻击目标:小兵优先
        private CharacterInfo GetNewTarget(NpcInfo npc)
        {
            NpcAiStateInfo info      = npc.GetAiStateInfo();
            CharacterInfo  npcTarget = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_ENEMY, AiTargetType.NPC);

            if (null != npcTarget)
            {
                return(npcTarget);
            }
            else
            {
                CharacterInfo userTarget = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_ENEMY, AiTargetType.USER);
                if (null != userTarget)
                {
                    return(userTarget);
                }
            }
            return(null);
        }
예제 #24
0
        private void GoHomeHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                info.Time = 0;
                AiData_PvpNpc_General data = GetAiData(npc);
                if (null != data)
                {
                    Vector3 targetPos            = info.HomePos;
                    ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
                    float powDistToHome          = Geometry.DistanceSquare(srcPos, info.HomePos);
                    if (powDistToHome <= 1)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        info.Time = 0;
                        data.FoundPath.Clear();
                        ChangeToState(npc, (int)AiStateId.Patrol);
                    }
                    else
                    {
                        PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, 100);

                        /*
                         * float angle = MathUtil.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                         * npc.GetMovementStateInfo().SetFaceDir(angle);
                         * npc.GetMovementStateInfo().SetMoveDir(angle);
                         * npc.GetMovementStateInfo().TargetPosition = targetPos;
                         * npc.GetMovementStateInfo().IsMoving = true;
                         */
                    }
                }
            }
        }
예제 #25
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;
            if (!string.IsNullOrEmpty(info.AiParam[0]))
            {
                if (int.Parse(info.AiParam[0]) == 0)
                {
                    InitPatrolData(npc);
                }
                else if (int.Parse(info.AiParam[0]) == 1)
                {
                    InitIdleAnim(npc);
                }
            }
            npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, GetWalkSpeed(npc));
            npc.GetMovementStateInfo().MovementMode = MovementMode.LowSpeed;
        }
예제 #26
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo     info = npc.GetAiStateInfo();
            AiData_PveNpc_Trap data = GetAiData(npc);

            if (null != data && !data.IsTriggered)
            {
                CharacterInfo source = npc.SceneContext.GetCharacterInfoById(npc.CreatorId);
                if (null != source)
                {
                    if (data.ImpactToMyself > 0)
                    {
                        ServerNpcImpact(source, data.ImpactToMyself, npc);
                    }
                    CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                    if (null != target)
                    {
                        if (data.Impact1ToTarget > 0)
                        {
                            ServerNpcImpact(source, data.Impact1ToTarget, target);
                        }
                        if (data.Impact2ToTarget > 0)
                        {
                            ServerNpcImpact(source, data.Impact2ToTarget, target);
                        }
                    }
                    int ct = 1;
                    IList <ISpaceObject> objs = npc.SpatialSystem.GetObjectInCircle(npc.GetMovementStateInfo().GetPosition3D(), data.RadiusOfTrigger);
                    foreach (ISpaceObject obj in objs)
                    {
                        if (obj.GetObjType() == SpatialObjType.kNPC || obj.GetObjType() == SpatialObjType.kUser)
                        {
                            CharacterInfo charInfo = obj.RealObject as CharacterInfo;
                            if (null != charInfo)
                            {
                                if (CharacterInfo.GetRelation(npc, charInfo) == CharacterRelation.RELATION_ENEMY)
                                {
                                    if (ct < data.DamageCount)
                                    {
                                        if (data.Impact1ToTarget > 0)
                                        {
                                            ServerNpcImpact(source, data.Impact1ToTarget, charInfo);
                                        }
                                        if (data.Impact2ToTarget > 0)
                                        {
                                            ServerNpcImpact(source, data.Impact2ToTarget, charInfo);
                                        }
                                        ++ct;
                                    }
                                }
                            }
                        }
                    }
                }
                data.IsTriggered = true;
            }
        }
예제 #27
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead() || npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            NpcAiStateInfo        info   = npc.GetAiStateInfo();
            bool                  toIdle = false;
            AiData_PveNpc_Monster data   = GetAiData(npc);

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(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;
                        NotifyNpcMove(npc);
                        info.Time = 0;
                        data.Time = 0;
                        ChangeToState(npc, (int)AiStateId.Combat);
                    }
                    else if (powDistToHome < distGoHome * distGoHome)//追击
                    {
                        info.Time += deltaTime;
                        if (info.Time > 100)
                        {
                            info.Time = 0;
                            if (AiLogicUtility.GetWalkablePosition(target, npc, ref targetPos))
                            {
                                AiLogicUtility.PathToTarget(npc, data.FoundPath, targetPos, 100, true, this);
                            }
                            else
                            {
                                npc.GetMovementStateInfo().IsMoving = false;
                                NotifyNpcMove(npc);
                            }
                        }
                    }
                    else
                    {
                        toIdle = true;
                    }
                }
                else
                {
                    toIdle = true;
                }
                if (toIdle)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }
예제 #28
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                AiData_PveNpc_Monster data = GetAiData(npc);
                if (null != data)
                {
                    data.Time += info.Time;
                    info.Time  = 0;
                    bool          goHome = false;
                    CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                    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);
                        float dir           = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                        npc.GetMovementStateInfo().SetFaceDir(dir);
                        if (powDist < data.ShootDistance * data.ShootDistance)
                        {
                            float rps = npc.GetActualProperty().Rps;
                            if (rps > 0.001f && data.Time > 1000 / rps)
                            {
                                data.Time = 0;
                            }
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            goHome = true;
                        }
                        else if (powDist < dist * dist /*&& SkillSystem.Instance.CanStartSkill(npc, data.Skill)*/)
                        {
                            ServerNpcSkill(npc, data.Skill, target, targetPos, dir);

                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            goHome = true;
                        }
                        else if (powDistToHome < distGoHome * distGoHome)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                        else
                        {
                            goHome = true;
                        }
                    }
                    else
                    {
                        goHome = true;
                    }
                    if (goHome)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);

                        info.Time = 0;
                        ChangeToState(npc, (int)AiStateId.GoHome);
                    }
                }
            }
        }
예제 #29
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            float rps = npc.GetActualProperty().Rps;

            if (rps > 0.001f && info.Time > 1000 / rps)
            {
                info.Time = 0;
                AiData_PveNpc_General data = GetAiData(npc);
                if (null != data)
                {
                    bool          goHome = false;
                    CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                    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 dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            npc.GetMovementStateInfo().SetFaceDir(dir);
                            npc.GetMovementStateInfo().SetMoveDir(dir);
                            if (npc.CanShoot() && !npc.GetSkillStateInfo().IsSkillActivated())
                            {
                                Data_NpcConfig npcConfig = NpcConfigProvider.Instance.GetNpcConfigById(npc.GetLinkId());
                                if (null == npcConfig)
                                {
                                    return;
                                }
                                if (npcConfig.m_SkillList.Count >= 1)
                                {
                                    ServerNpcSkill(npc, npcConfig.m_SkillList[0], target, targetPos, dir);
                                }
                            }
                        }
                        else if (powDistToHome < distGoHome * distGoHome)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                        else
                        {
                            goHome = true;
                        }
                    }
                    else
                    {
                        goHome = true;
                    }
                    if (goHome)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                        info.Time = 0;
                        ChangeToState(npc, (int)AiStateId.GoHome);
                    }
                }
            }
        }
예제 #30
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            float rps = npc.GetActualProperty().Rps;

            if (rps > 0.001f && info.Time > 1000 / rps)
            {
                info.Time = 0;
                CheckImpact(npc);
                bool toIdle = false;
                //修改确定攻击目标的逻辑
                CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                if (null != target && npc.SpatialSystem.CanShoot(npc.SpaceObject, target.GetMovementStateInfo().GetPosition3D()))
                {
                    ScriptRuntime.Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D();
                    ScriptRuntime.Vector3 srcPos    = npc.GetMovementStateInfo().GetPosition3D();
                    float powDist = Geometry.DistanceSquare(srcPos, targetPos); //npc与目标距离
                    float dist    = (float)npc.GetActualProperty().AttackRange; //攻击范围
                    //float distView = (float)npc.ViewRange;                      //视野范围
                    if (powDist < dist * dist)
                    {
                        //在攻击范围内
                        float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                        npc.GetMovementStateInfo().IsMoving = false;
                        npc.GetMovementStateInfo().SetFaceDir(dir);
                        npc.GetMovementStateInfo().SetMoveDir(dir);
                        if (npc.CanShoot())
                        {
                            aiCmdDispatcher.NpcFace(npc, this);
                        }
                    }
                    else
                    {
                        //如果原目标已经超出了攻击范围,防御塔应当重新进行探测,而不是跳转到Idle状态
                        CharacterInfo newTarget = GetNewTarget(npc);
                        if (null != newTarget)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            info.Time   = 0;
                            info.Target = newTarget.GetId();
                        }
                        else
                        {
                            toIdle = true;
                        }
                    }
                }
                else
                {
                    //如果原目标死亡或不可攻击,防御塔应当首先重新进行探测,而不是跳转到Idle状态
                    //若找到新目标,则进行攻击
                    //若没有心目标。则进入Idle状态
                    CharacterInfo newTarget = GetNewTarget(npc);
                    if (null != newTarget)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        info.Time   = 0;
                        info.Target = newTarget.GetId();
                    }
                    else
                    {
                        toIdle = true;
                    }
                }
                if (toIdle)
                {
                    info.Time = 0;
                    npc.GetMovementStateInfo().IsMoving = false;
                    ChangeToState(npc, (int)AiStateId.Idle);
                }
            }
        }