示例#1
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);
                    }
                }
            }
        }
        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);
                }
            }
        }
示例#3
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
                {
                }
            }
        }
示例#4
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;
                }
            }
        }
示例#5
0
 private void GoHomeHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
 {
     if (npc.IsDead())
     {
         return;
     }
     ChangeToState(npc, (int)AiStateId.Idle);
 }
示例#6
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);
                }
            }
        }
示例#7
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);
                    }
                }
            }
        }
示例#8
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);
                }
            }
        }
示例#9
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);
            }
        }
示例#10
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();
                    }
                }
            }
        }
示例#11
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;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#12
0
        internal static void Execute(object msg, User user)
        {
            Msg_CR_DeleteDeadNpc ddn_msg = msg as Msg_CR_DeleteDeadNpc;

            if (null == ddn_msg)
            {
                return;
            }
            Scene scene = user.OwnRoom.GetActiveScene();

            if (null != scene)
            {
                NpcInfo npc = scene.NpcManager.GetNpcInfo(ddn_msg.npc_id);
                if (null != npc && npc.IsDead())
                {
                    npc.GfxDead = true;
                }
            }
        }
示例#13
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;
                         */
                    }
                }
            }
        }
示例#14
0
        private void GoHomeHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            AiData_PveNpc_Monster_CloseCombat data = GetAiData(npc);

            if (null != data)
            {
                if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.FastMoveImpact))
                {
                    ServerNpcStopImpact(npc, data.FastMoveImpact);
                }
                if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact))
                {
                    ServerNpcStopImpact(npc, data.PreAttackImpact);
                }
            }
            ChangeToState(npc, (int)AiStateId.Idle);
        }
示例#15
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_PvpNpc_General data = GetAiData(npc);
                if (null != data)
                {
                    data.Time         += info.Time;
                    data.ThinkingTime += info.Time;
                    //ai配置参数  小兵思考时间
                    long thinkingTime = int.Parse(info.AiParam[2]);
                    //大于思考时间 重新选择新的目标
                    if (data.ThinkingTime > thinkingTime)
                    {
                        CharacterInfo interestestTarget = GetInterestestTargetHelper(npc, CharacterRelation.RELATION_ENEMY);
                        if (null != interestestTarget && info.Target != interestestTarget.GetId())
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time         = 0;
                            data.Time         = 0;
                            data.ThinkingTime = 0;
                            info.Target       = interestestTarget.GetId();
                            return;
                        }
                    }
                    info.Time = 0;
                    bool          changeTarget = false;
                    CharacterInfo target       = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
                    if (null != target)
                    {
                        float dist       = (float)(npc.GetActualProperty().AttackRange *npc.AttackRangeCoefficient);
                        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 && npc.SpatialSystem.CanShoot(npc.SpaceObject, target.GetMovementStateInfo().GetPosition3D()))
                        {
                            float rps = npc.GetActualProperty().Rps;
                            if (rps > 0.001f && data.Time > 1000 / rps)
                            {
                                data.Time = 0;
                                float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                                npc.GetMovementStateInfo().SetFaceDir(dir);
                                npc.GetMovementStateInfo().SetMoveDir(dir);
                                if (npc.CanShoot())
                                {
                                    aiCmdDispatcher.NpcFace(npc, this);
                                }
                            }
                        }
                        else if (powDistToHome < distGoHome * distGoHome)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time = 0;
                            data.FoundPath.Clear();
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                        else
                        {
                            changeTarget = true;
                        }
                    }
                    else
                    {
                        changeTarget = true;
                    }
                    if (changeTarget)
                    {
                        data.FoundPath.Clear();
                        target = GetInterestestTargetHelper(npc, CharacterRelation.RELATION_ENEMY);
                        if (null != target)
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time   = 0;
                            info.Target = target.GetId();
                            ChangeToState(npc, (int)AiStateId.Pursuit);
                        }
                        else
                        {
                            npc.GetMovementStateInfo().IsMoving = false;
                            NotifyNpcMove(npc);
                            info.Time    = 0;
                            info.HomePos = GetHomePosition(npc, data);
                            ChangeToState(npc, (int)AiStateId.GoHome);
                        }
                    }
                }
                else
                {
                    info.Time = 0;
                }
            }
        }
示例#16
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);
                    }
                }
            }
        }
示例#17
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);
                    }
                }
            }
        }
示例#18
0
        private void TickRecover()
        {
            float            hp_coefficient = 1.0f;
            float            mp_coefficient = 1.0f;
            Data_SceneConfig scene_data     = SceneConfigProvider.Instance.GetSceneConfigById(m_SceneResId);

            if (null != scene_data)
            {
                hp_coefficient = scene_data.m_RecoverHpCoefficient;
                mp_coefficient = scene_data.m_RecoverMpCoefficient;
            }
            for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                UserInfo info = linkNode.Value;
                if (!info.IsDead())
                {
                    float hpRecover = info.GetActualProperty().HpRecover *hp_coefficient;
                    float epRecover = info.GetActualProperty().EnergyRecover *mp_coefficient;
                    if (hpRecover > 0.0001)
                    {
                        if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax)
                        {
                            info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax);
                        }
                        else
                        {
                            info.SetHp(Operate_Type.OT_Relative, (int)hpRecover);
                        }
                    }
                    if (epRecover > 0.0001)
                    {
                        if (info.Energy + (int)epRecover >= info.GetActualProperty().EnergyMax)
                        {
                            info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax);
                        }
                        else
                        {
                            info.SetEnergy(Operate_Type.OT_Relative, (int)epRecover);
                        }
                    }
                    if (hpRecover > 0.0001 || epRecover > 0.0001)
                    {
                        Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info);
                        NotifyAreaUser(info, builder, false);
                    }
                }
            }
            for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (!info.IsDead())
                {
                    float hpRecover = info.GetActualProperty().HpRecover;
                    float npRecover = info.GetActualProperty().EnergyRecover;
                    if (hpRecover > 0.0001)
                    {
                        if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax)
                        {
                            info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax);
                        }
                        else
                        {
                            info.SetHp(Operate_Type.OT_Relative, (int)hpRecover);
                        }
                    }
                    if (npRecover > 0.0001)
                    {
                        if (info.Energy + (int)npRecover >= info.GetActualProperty().EnergyMax)
                        {
                            info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax);
                        }
                        else
                        {
                            info.SetEnergy(Operate_Type.OT_Relative, (int)npRecover);
                        }
                    }
                    if (hpRecover > 0.0001 || npRecover > 0.0001)
                    {
                        Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info);
                        NotifyAreaUser(info, builder, false);
                    }
                }
            }
        }
示例#19
0
        private void TickNpcs()
        {
            List <NpcInfo> deletes        = new List <NpcInfo>();
            List <NpcInfo> deletes2       = new List <NpcInfo>();
            Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead();

            for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next)
            {
                NpcInfo info = linkNode.Value;
                if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged || info.GetLegacyStateInfo().LegacyChanged)
                {
                    NpcAttrCalculator.Calc(info);
                    info.LevelChanged = false;
                    info.GetSkillStateInfo().BuffChanged          = false;
                    info.GetEquipmentStateInfo().EquipmentChanged = false;
                    info.GetLegacyStateInfo().LegacyChanged       = false;
                }
                // 伙伴自动掉血
                if ((int)NpcTypeEnum.Partner == info.NpcType)
                {
                    UserInfo owner = UserManager.GetUserInfo(info.OwnerId);
                    if (null != owner)
                    {
                        PartnerInfo pi = owner.GetPartnerInfo();
                        if (null != pi && TimeUtility.GetServerMilliseconds() - pi.LastTickTime > pi.TickInterval)
                        {
                            info.SetHp(Operate_Type.OT_Relative, (int)pi.GetHpCostPerTick(info.GetActualProperty().HpMax));
                            pi.LastTickTime = TimeUtility.GetServerMilliseconds();
                        }
                    }
                }
                if (info.NeedDelete)
                {
                    deletes2.Add(info);
                }
                else if (info.IsDead())
                {
                    if (info.DeadTime <= 0)
                    {
                        info.DeadTime = TimeUtility.GetServerMilliseconds();
                        //击杀收益计算
                        CalcKillIncome(info);
                        //解除控制
                        ReleaseControl(info);
                        //发送npc死亡消息
                        npcDeadBuilder.npc_id = info.GetId();
                        NotifyAllUser(npcDeadBuilder);

                        if (info.IsCombatNpc())
                        {
                            m_StorySystem.SendMessage("objkilled", info.GetId(), GetBattleNpcCount());
                            m_StorySystem.SendMessage(string.Format("npckilled:{0}", info.GetUnitId()), info.GetId(), GetBattleNpcCount());
                            if (info.GetUnitId() > 0)
                            {
                                if (m_IsAttemptScene)
                                {
                                    if ((int)NpcTypeEnum.BigBoss == info.NpcType)
                                    {
                                        TryFireAllNpcKilled();
                                    }
                                }
                                else
                                {
                                    TryFireAllNpcKilled();
                                }
                            }
                        }
                    }
                    else if (TimeUtility.GetServerMilliseconds() - info.DeadTime > info.ReleaseTime && info.GfxDead)
                    {
                        deletes.Add(info);
                    }
                }
                if (info.IsBorning && IsNpcBornOver(info))
                {
                    info.IsBorning = false;
                    info.SetAIEnable(true);
                    info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible);
                }
                CheckNpcOwnerId(info);
            }
            if (deletes.Count > 0)
            {
                Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc();
                foreach (NpcInfo ni in deletes)
                {
                    //发送npc消失消息
                    destroyNpcBuilder.npc_id           = ni.GetId();
                    destroyNpcBuilder.need_play_effect = true;
                    NotifyAllUser(destroyNpcBuilder);
                    //删除npc
                    NpcManager.RemoveNpc(ni.GetId());
                    LogSystem.Debug("Npc {0}  name {1} is deleted.", ni.GetId(), ni.GetName());
                }
            }
            if (deletes2.Count > 0)
            {
                Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc();
                foreach (NpcInfo ni in deletes2)
                {
                    //发送npc消失消息
                    destroyNpcBuilder.npc_id           = ni.GetId();
                    destroyNpcBuilder.need_play_effect = false;
                    NotifyAllUser(destroyNpcBuilder);
                    //删除npc
                    NpcManager.RemoveNpc(ni.GetId());
                    LogSystem.Debug("Npc {0}  name {1} is deleted.", ni.GetId(), ni.GetName());
                }
            }
            NpcManager.ExecuteDelayAdd();
        }
示例#20
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();
            //ai配置参数
            long maxPursuitTime = int.Parse(info.AiParam[0]);
            long minPursuitTime = int.Parse(info.AiParam[1]);
            //
            bool goHome = false;

            info.Time += deltaTime;
            CharacterInfo         target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target);
            AiData_PvpNpc_General data   = GetAiData(npc);

            if (null != target && info.Time <= maxPursuitTime && null != data)
            {
                if (info.Time >= minPursuitTime)
                {
                    //超过最小追击时间,尝试换攻击目标
                    CharacterInfo interestestTarget = GetInterestestTargetHelper(npc, CharacterRelation.RELATION_ENEMY);
                    if (null != interestestTarget && interestestTarget != target)
                    {
                        info.Time   = 0;
                        info.Target = interestestTarget.GetId();
                        data.FoundPath.Clear();
                        target = interestestTarget;
                    }
                }
                float   dist                 = (float)(npc.GetActualProperty().AttackRange *npc.AttackRangeCoefficient);
                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.SpatialSystem.CanShoot(npc.SpaceObject, target.GetMovementStateInfo().GetPosition3D()))
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.Combat);
                    NotifyNpcMove(npc);
                }
                else if (powDistToHome < distGoHome * distGoHome)
                {
                    if (AiLogicUtility.GetWalkablePosition(target, npc, ref targetPos))
                    {
                        PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, deltaTime);
                    }
                    else
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        NotifyNpcMove(npc);
                    }
                }
                else
                {
                    goHome = true;
                }
            }
            else
            {
                goHome = true;
            }
            if (goHome)
            {
                npc.GetMovementStateInfo().IsMoving = false;
                NotifyNpcMove(npc);
                info.Time    = 0;
                info.HomePos = GetHomePosition(npc, data);
                data.FoundPath.Clear();
                ChangeToState(npc, (int)AiStateId.GoHome);
            }
        }
示例#21
0
        private void CombatHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

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

            if (null != data)
            {
                CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target);
                if (null != target)
                {
                    if (data.WaitTime <= m_ResponseTime)
                    {
                        if (!data.HasMeetEnemy)
                        {
                            if (null != OnNpcMeetEnemy)
                            {
                                OnNpcMeetEnemy(npc, data.MeetEnemyAnim);
                            }
                            data.HasMeetEnemy = true;
                        }
                        float angle = Geometry.GetYAngle(npc.GetMovementStateInfo().GetPosition2D(), target.GetMovementStateInfo().GetPosition2D());
                        NotifyNpcFace(npc, angle);
                        data.WaitTime += deltaTime;
                        return;
                    }
                    data.WalkTime += deltaTime;
                    if (data.WalkTime < 4000)
                    {
                        npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, GetWalkSpeed(npc));
                        npc.GetMovementStateInfo().MovementMode = MovementMode.LowSpeed;
                    }
                    else
                    {
                        npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, GetRunSpeed(npc));
                        npc.GetMovementStateInfo().MovementMode = MovementMode.HighSpeed;
                    }
                    float   dist                 = (float)npc.GetActualProperty().AttackRange;
                    float   distGoHome           = (float)npc.GohomeRange;
                    Vector3 targetPos            = target.GetMovementStateInfo().GetPosition3D();
                    ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
                    float powDist                = Geometry.DistanceSquare(srcPos, targetPos);
                    if (0 == data.SkillToCast)
                    {
                        data.SkillToCast = GetNextSkill();
                    }
                    if (powDist < (npc.ViewRange - m_TauntDis) * (npc.ViewRange - m_TauntDis))
                    {
                        if (m_Taunt == data.SkillToCast)
                        {
                            float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z));
                            if (Geometry.IsSameDouble(angle, npc.GetMovementStateInfo().GetFaceDir()))
                            {
                                OnNpcSkill(npc, data.SkillToCast, target);
                                data.SkillToCast = 0;
                            }
                        }
                    }
                    float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos);
                    if (powDist < dist * dist)
                    {
                        npc.GetMovementStateInfo().IsMoving = false;
                        info.Time = 0;
                        data.Time = 0;
                        npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, GetRunSpeed(npc));
                        npc.GetMovementStateInfo().MovementMode = MovementMode.HighSpeed;
                        ChangeToState(npc, (int)AiStateId.Combat);
                        NotifyNpcMove(npc);
                    }
                    else
                    {
                        info.Time += deltaTime;
                        if (info.Time > m_IntervalTime)
                        {
                            info.Time = 0;
                            AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this);
                        }
                    }
                }
                else
                {
                    goHome = true;
                }
                if (goHome)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);
                    info.Time = 0;
                    data.Time = 0;
                    npc.GetActualProperty().SetMoveSpeed(Operate_Type.OT_Absolute, 3.5f);
                    ChangeToState(npc, (int)AiStateId.Combat);
                    ChangeToState(npc, (int)AiStateId.GoHome);
                }
            }
        }
示例#23
0
        private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime)
        {
            if (npc.IsDead() || npc.GetSkillStateInfo().IsSkillActivated())
            {
                return;
            }
            NpcAiStateInfo info   = npc.GetAiStateInfo();
            bool           goHome = false;
            AiData_PveNpc_Monster_CloseCombat 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)//进入移动攻击状态
                    {
                        if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact))
                        {
                            ServerNpcStopImpact(npc, data.PreAttackImpact);
                        }
                        info.Time = 0;
                        data.FoundPath.Clear();
                        data.Time = (long)(1000.0f / npc.GetActualProperty().Rps);
                        ChangeToState(npc, (int)AiStateId.Combat);
                    }
                    else if (powDist < data.PreAttackDistance * data.PreAttackDistance) //预热状态
                    {
                        if (null == npc.GetSkillStateInfo().GetImpactInfoById(data.FastMoveImpact))
                        {
                            ServerNpcImpact(npc, data.FastMoveImpact, npc);
                        }
                        if (null == npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact))
                        {
                            ServerNpcImpact(npc, data.PreAttackImpact, npc);
                        }
                        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 if (powDistToHome < distGoHome * distGoHome)//追击
                    {
                        if (data.TestFlag != 3)
                        {
                            data.TestFlag = 3;
                        }
                        if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.FastMoveImpact))
                        {
                            ServerNpcStopImpact(npc, data.FastMoveImpact);
                        }
                        if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact))
                        {
                            ServerNpcStopImpact(npc, data.PreAttackImpact);
                        }
                        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
                    {
                        goHome = true;
                    }
                }
                else
                {
                    goHome = true;
                }
                if (goHome)
                {
                    npc.GetMovementStateInfo().IsMoving = false;
                    NotifyNpcMove(npc);

                    info.Time = 0;
                    ChangeToState(npc, (int)AiStateId.GoHome);
                }
            }
        }
示例#24
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);
                }
            }
        }
示例#25
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);
                }
            }
        }
示例#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
        public static void DoPatrolCommandState(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime, AbstractNpcStateLogic logic)
        {
            if (npc.IsDead())
            {
                return;
            }
            NpcAiStateInfo info = npc.GetAiStateInfo();

            info.Time += deltaTime;
            if (info.Time > 100)
            {
                long intervalTime = info.Time;
                info.Time = 0;
                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)
                {
                    logic.NotifyNpcTargetChange(npc);
                    npc.GetMovementStateInfo().IsMoving = false;
                    logic.NotifyNpcMove(npc);
                    info.Time = 0;
                    AiData_ForPatrolCommand data = GetAiDataForPatrolCommand(npc);
                    if (null != data)
                    {
                        data.FoundPath.Clear();
                    }
                    logic.ChangeToState(npc, (int)AiStateId.Pursuit);
                }
                else
                {
                    AiData_ForPatrolCommand data = GetAiDataForPatrolCommand(npc);
                    if (null != data)
                    {
                        ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D();
                        if (data.PatrolPath.HavePathPoint && !data.PatrolPath.IsReached(srcPos))
                        {
                            PathToTargetWithoutObstacle(npc, data.FoundPath, data.PatrolPath.CurPathPoint, intervalTime, true, logic);
                        }
                        else
                        {
                            data.PatrolPath.UseNextPathPoint();
                            data.FoundPath.Clear();
                            if (!data.PatrolPath.HavePathPoint)
                            {
                                if (data.IsLoopPatrol)
                                {
                                    data.PatrolPath.Restart();
                                }
                                else
                                {
                                    info.Time = 0;
                                    logic.ChangeToState(npc, (int)AiStateId.Idle);
                                }
                            }
                        }
                        info.HomePos = npc.GetMovementStateInfo().GetPosition3D();
                    }
                    else
                    {
                        info.Time = 0;
                        logic.ChangeToState(npc, (int)AiStateId.Idle);
                    }
                }
            }
        }