public void Execute(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.GetAIEnable()) { UserAiStateInfo userAi = user.GetAiStateInfo(); if (userAi.CommandQueue.Count <= 0) { int curState = userAi.CurState; if (curState > (int)AiStateId.Invalid && curState < (int)AiStateId.MaxNum) { UserAiStateHandler handler; if (m_Handlers.TryGetValue(curState, out handler)) { if (null != handler) { handler(user, aiCmdDispatcher, deltaTime); } } else { LogSystem.Error("Illegal ai state: " + curState + " user:" + user.GetId()); } } else { OnStateLogicInit(user, aiCmdDispatcher, deltaTime); ChangeToState(user, (int)AiStateId.Idle); } } ExecuteCommandQueue(user, deltaTime); } }
private void MoveHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); AiData_UserSelf_General data = GetAiData(user); Vector3 targetPos = info.TargetPos; Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); if (null != data && !IsReached(srcPos, targetPos)) { if (info.IsTargetPosChanged) { info.IsTargetPosChanged = false; data.FoundPath.Clear(); } PathToTargetPro(user, data.FoundPath, targetPos, deltaTime); } else { user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; info.Target = 0; info.TargetPos = Vector3.Zero; data.Time = 0; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Idle); } }
protected override void OnStateLogicInit(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { UserAiStateInfo info = user.GetAiStateInfo(); info.HomePos = user.GetMovementStateInfo().GetPosition3D(); info.Time = 0; user.GetMovementStateInfo().IsMoving = false; }
private void PushSkill(UserInfo playerself, Vector3 targetpos, float attackrange) { if (null != playerself && Vector3.Zero != targetpos) { UserAiStateInfo info = playerself.GetAiStateInfo(); RevokeSkill(playerself, info); info.Time = 0; info.TargetPos = targetpos; info.AttackRange = attackrange; info.IsAttacked = false; info.ChangeToState((int)AiStateId.Combat); } }
private void RevokeSkill(UserInfo playerself, UserAiStateInfo aiInfo) { if (null == playerself || null == aiInfo) { return; } StopFindPath(playerself, aiInfo); aiInfo.Target = 0; aiInfo.IsAttacked = false; aiInfo.Time = 0; aiInfo.TargetPos = Vector3.Zero; aiInfo.AttackRange = 0; aiInfo.ChangeToState((int)AiStateId.Idle); }
private void Combat(UserInfo playerself, int targetId, float attackrange) { if (null != playerself && m_lastSelectObjId != targetId) { UserAiStateInfo info = playerself.GetAiStateInfo(); if ((int)AiStateId.Move == info.CurState) { StopFindPath(playerself, info); } info.Time = 0; info.Target = targetId; info.IsAttacked = false; info.AttackRange = attackrange; info.ChangeToState((int)AiStateId.Combat); } }
public static void ExecPlayerSelfMoveCommand(float x, float y, float z) { Vector3 pos = new Vector3(); pos.x = x; pos.y = y; pos.z = z; UserInfo user = WorldSystem.Instance.GetPlayerSelf(); if (null != user) { if (!user.UnityPathFinding) { List <Vector3> waypoints = user.SpatialSystem.FindPath(user.GetMovementStateInfo().GetPosition3D(), pos, 1); waypoints.Add(pos); UserAiStateInfo aiInfo = user.GetAiStateInfo(); AiData_ForMoveCommand data = aiInfo.AiDatas.GetData <AiData_ForMoveCommand>(); if (null == data) { data = new AiData_ForMoveCommand(waypoints); aiInfo.AiDatas.AddData(data); } data.WayPoints = waypoints; data.Index = 0; data.EstimateFinishTime = 0; data.IsFinish = false; aiInfo.ChangeToState((int)AiStateId.MoveCommand); } else { UserAiStateInfo aiInfo = user.GetAiStateInfo(); AiData_ForMoveCommand data = aiInfo.AiDatas.GetData <AiData_ForMoveCommand>(); if (null == data) { data = new AiData_ForMoveCommand(null); aiInfo.AiDatas.AddData(data); } user.PathFindingFinished = false; user.GetAiStateInfo().ChangeToState((int)AiStateId.PathFinding); user.GetAiStateInfo().PreviousState = (int)AiStateId.MoveCommand; GfxSystem.ForMoveCommandPathToTarget(user, pos); } } }
private void ExecuteCommandQueue(UserInfo user, long deltaTime) { UserAiStateInfo userAi = user.GetAiStateInfo(); while (userAi.CommandQueue.Count > 0) { IAiCommand cmd = userAi.CommandQueue.Peek(); if (cmd.Execute(deltaTime)) { userAi.CommandQueue.Dequeue(); } else { break; } } }
private void PathFindingCommandHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { // Path has found. if (!user.UnityPathFinding) { return; } if (!user.PathFindingFinished) { return; } user.PathFindingFinished = false; UserAiStateInfo info = user.GetAiStateInfo(); ChangeToState(user, info.PreviousState); }
private void StopAiMove() { UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (null != playerself) { UserAiStateInfo aiInfo = playerself.GetAiStateInfo(); if (aiInfo.CurState == (int)AiStateId.MoveCommand || aiInfo.CurState == (int)AiStateId.PursuitCommand || aiInfo.CurState == (int)AiStateId.PatrolCommand) { aiInfo.Time = 0; aiInfo.Target = 0; aiInfo.AiDatas.RemoveData <AiData_ForMoveCommand>(); aiInfo.AiDatas.RemoveData <AiData_ForPursuitCommand>(); aiInfo.AiDatas.RemoveData <AiData_ForPatrolCommand>(); aiInfo.ChangeToState((int)AiStateId.Idle); ClientScriptSystem.Instance.SendMessage("aimovestopped"); } } }
private void FindPath(Vector3 targetpos) { UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (playerself != null && !playerself.IsDead()) { if (Vector3.Zero == targetpos) { return; } UserAiStateInfo aiInfo = playerself.GetAiStateInfo(); if (null != aiInfo) { StopFindPath(playerself, aiInfo); } aiInfo.TargetPos = targetpos; aiInfo.ChangeToState((int)AiStateId.Move); } }
private void StopFindPath(UserInfo playerself, UserAiStateInfo aiInfo) { if (null == playerself || null == aiInfo) { return; } AiData_UserSelf_General data = playerself.GetAiStateInfo().AiDatas.GetData <AiData_UserSelf_General>(); if (null == data) { data = new AiData_UserSelf_General(); playerself.GetAiStateInfo().AiDatas.AddData(data); } playerself.GetMovementStateInfo().IsMoving = false; aiInfo.Time = 0; data.Time = 0; data.FoundPath.Clear(); aiInfo.ChangeToState((int)AiStateId.Idle); }
private void PathToTargetPro(UserInfo user, AiPathData data, Vector3 pathTargetPos, long deltaTime) { if (!user.UnityPathFinding) { PathToTarget(user, data, pathTargetPos, deltaTime); } else { UserAiStateInfo info = user.GetAiStateInfo(); if (info.PreviousState != (int)AiStateId.PathFinding) { user.PathFindingFinished = false; GfxSystem.UserSelfGeneralPathToTarget(user, pathTargetPos); ChangeToState(user, (int)AiStateId.PathFinding); } else { PathToTarget(user, data, pathTargetPos, deltaTime); } } }
private void IdleHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; CharacterInfo target = null; if (info.IsAttacked && m_AttackRangeLast > 0) { if (info.Target > 0 /* || info.TargetPos != Vector3.Zero*/) { target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(user, info.Target); if (null == target) { info.Target = 0; target = AiLogicUtility.GetNearstTargetHelper(user, CharacterRelation.RELATION_ENEMY); } } if (null != target) { info.Time = 0; info.Target = target.GetId(); info.IsAttacked = false; info.AttackRange = m_AttackRangeLast; m_AttackRangeLast = 0; ChangeToState(user, (int)AiStateId.Combat); } } } }
private void TouchHandle(int what, GestureArgs e) { try { UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (null == playerself || null == e) { return; } CharacterView view = EntityManager.Instance.GetUserViewById(playerself.GetId()); if (null != playerself.SkillController && playerself.SkillController.GetSkillControlMode() != SkillControlMode.kTouch) { return; } if ((int)TouchEvent.Cesture == what) { string ename = e.name; if (GestureEvent.OnSingleTap.ToString() == ename) { if (EnableMoveInput) { if (WorldSystem.Instance.IsPureClientScene() || WorldSystem.Instance.IsPveScene()) { if (e.selectedObjID < 0) { playerself.SkillController.AddBreakSkillTask(); if (InputType.Touch == e.inputType) { FindPath(new Vector3(e.airWelGamePosX, e.airWelGamePosY, e.airWelGamePosZ)); } else if (InputType.Joystick == e.inputType) { UpdateMoveState(playerself, new Vector3(e.airWelGamePosX, e.airWelGamePosY, e.airWelGamePosZ), e.towards); } UpdateTowards(playerself, e.towards); } else { Combat(playerself, e.selectedObjID, e.attackRange); } m_lastSelectObjId = e.selectedObjID; /// // GfxSystem.PublishGfxEvent("Op_InputEffect", "Input", GestureEvent.OnSingleTap, e.airWelGamePosX, e.airWelGamePosY, e.airWelGamePosZ, e.selectedObjID < 0 ? false : true, true); } else if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene()) { if (e.selectedObjID < 0) { if (InputType.Touch == e.inputType) { NetworkSystem.Instance.SyncPlayerMoveToPos(new Vector3(e.airWelGamePosX, e.airWelGamePosY, e.airWelGamePosZ)); } else if (InputType.Joystick == e.inputType) { UpdateMoveState(playerself, new Vector3(e.airWelGamePosX, e.airWelGamePosY, e.airWelGamePosZ), e.towards); playerself.SkillController.AddBreakSkillTask(); } } else { NetworkSystem.Instance.SyncPlayerMoveToAttack(e.selectedObjID, e.attackRange); } } } } else if (GestureEvent.OnFingerMove.ToString() == ename) { if (EnableMoveInput) { if (view.ObjectInfo.IsGfxMoveControl && !view.ObjectInfo.IsGfxRotateControl) { UpdateTowards(playerself, e.towards); } } } else if (GestureEvent.OnSkillStart.ToString() == ename) { if (null != playerself) { UserAiStateInfo info = playerself.GetAiStateInfo(); if ((int)AiStateId.Move == info.CurState) { StopFindPath(playerself, info); } } } else if (GestureEvent.OnEasyGesture.ToString() == ename) { Vector3 targetpos = new Vector3(e.startGamePosX, e.startGamePosY, e.startGamePosZ); if (Vector3.Zero != targetpos) { PushSkill(playerself, targetpos, e.attackRange); } } } } catch (Exception ex) { LogicSystem.LogFromGfx("[Error]:Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
internal void Tick() { long now = TimeUtility.GetServerMilliseconds(); m_LastTickIntervalMs = now - m_LastTickTime; m_LastTickTime = now; if (WorldSystem.Instance.IsObserver && !WorldSystem.Instance.IsFollowObserver) { bool keyPressed = false; float x = 0.5f, y = 0.5f; if (GfxSystem.IsKeyPressed(Keyboard.Code.A)) { x = 0.1f; keyPressed = true; } else if (GfxSystem.IsKeyPressed(Keyboard.Code.D)) { x = 0.9f; keyPressed = true; } if (GfxSystem.IsKeyPressed(Keyboard.Code.W)) { y = 0.1f; keyPressed = true; } else if (GfxSystem.IsKeyPressed(Keyboard.Code.S)) { y = 0.9f; keyPressed = true; } if (keyPressed) { WorldSystem.Instance.UpdateObserverCamera(x, y); } return; } UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (null == playerself) { return; } // if move input is disable // MotionStatus is MoveStop, and MotionChanged is reflect the change accordingly if (EnableMoveInput) { if (!IsKeyboardControl()) { CheckJoystickControl(); } } if (!m_IsJoystickControl) { pm_.Update(EnableMoveInput); } MovementStateInfo msi = playerself.GetMovementStateInfo(); Vector3 pos = msi.GetPosition3D(); //LogSystem.Debug("Pos : {0}, Dir : {1}", pos.ToString(), playerself.GetMovementStateInfo().GetFaceDir()); bool reface = false; if (m_LastTickIsSkillMoving && !msi.IsSkillMoving) { reface = true; } //操作同步机制改为发给服务器同时本地就开始执行(服务器转发给其它客户端,校验失败则同时发回原客户端进行位置调整) Vector3 mouse_pos = new Vector3(GfxSystem.GetMouseX(), GfxSystem.GetMouseY(), GfxSystem.GetMouseZ()); if (pm_.MotionStatus == PlayerMovement.Motion.Moving || pm_.JoyStickMotionStatus == PlayerMovement.Motion.Moving) { if (pm_.MotionChanged || pm_.JoyStickMotionChanged || !m_LastTickIsMoving) { StopAiMove(); playerself.SkillController.AddBreakSkillTask(); float moveDir = RoundMoveDir(pm_.MoveDir); //GfxSystem.GfxLog("PlayerControl.Tick MoveDir:{0} RoundMoveDir:{1}", pm_.MoveDir, moveDir); if (!m_LastTickIsMoving || !Geometry.IsSameFloat(moveDir, m_lastMoveDir)) { msi.SetMoveDir(moveDir); //ControlSystemOperation.AdjustCharacterMoveDir(playerself.GetId(), moveDir); msi.IsMoving = true; msi.TargetPosition = Vector3.Zero; if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene()) { NetworkSystem.Instance.SyncPlayerMoveStart(moveDir); } } if (EnableRotateInput) { if (reface || !m_LastTickIsMoving || !Geometry.IsSameFloat(pm_.MoveDir, m_lastDir)) { msi.SetFaceDir(pm_.MoveDir); //ControlSystemOperation.AdjustCharacterFaceDir(playerself.GetId(), pm_.MoveDir); msi.SetWantFaceDir(pm_.MoveDir); if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene()) { NetworkSystem.Instance.SyncFaceDirection(pm_.MoveDir); } } } m_lastDir = pm_.MoveDir; m_lastMoveDir = moveDir; } m_LastTickIsMoving = true; } else { if (m_LastTickIsMoving) { playerself.SkillController.CancelBreakSkillTask(); playerself.GetMovementStateInfo().IsMoving = false; if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene()) { NetworkSystem.Instance.SyncPlayerMoveStop(); } if (EnableRotateInput) { if (reface) { msi.SetFaceDir(m_lastDir); //ControlSystemOperation.AdjustCharacterFaceDir(playerself.GetId(), m_lastDir); msi.SetWantFaceDir(m_lastDir); if (WorldSystem.Instance.IsPvpScene() || WorldSystem.Instance.IsMultiPveScene()) { NetworkSystem.Instance.SyncFaceDirection(m_lastDir); } } } } m_LastTickIsMoving = false; } m_LastTickIsSkillMoving = msi.IsSkillMoving; old_mouse_pos_ = mouse_pos_; mouse_pos_.X = GfxSystem.GetMouseX(); mouse_pos_.Y = GfxSystem.GetMouseY(); UserAiStateInfo aiInfo = playerself.GetAiStateInfo(); if (null != aiInfo && (int)AiStateId.Idle == aiInfo.CurState) { m_lastSelectObjId = -1; } }
private void PursuitHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); AiData_UserSelf_General data = GetAiData(user); if (null != data) { if (info.Target > 0) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(user, info.Target); if (null != target) { float dist = info.AttackRange - 1.0f; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (powDist < dist * dist) { user.GetMovementStateInfo().IsMoving = false; info.Time = 0; data.Time = 0; ChangeToState(user, (int)AiStateId.Combat); NotifyUserMove(user); } else { info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; CharacterInfo target2 = GetCanAttackUserTarget(user); if (null == target2) { AiLogicUtility.GetNearstTargetHelper(user, CharacterRelation.RELATION_ENEMY); } if (null == target2 || target == target2) { PathToTargetPro(user, data.FoundPath, targetPos, deltaTime); } else { info.Target = target2.GetId(); return; } } } } else { user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; data.Time = 0; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Idle); } } else { float dist = info.AttackRange; Vector3 targetPos = info.TargetPos; Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (powDist < dist * dist) { user.GetMovementStateInfo().IsMoving = false; info.Time = 0; data.Time = 0; ChangeToState(user, (int)AiStateId.Combat); NotifyUserMove(user); } else { info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; PathToTargetPro(user, data.FoundPath, targetPos, deltaTime); } } } } }
private void PathToTarget(UserInfo user, AiPathData data, Vector3 pathTargetPos, long deltaTime) { UserAiStateInfo info = user.GetAiStateInfo(); if (null != data) { data.UpdateTime += deltaTime; Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float dir = user.GetMovementStateInfo().GetMoveDir(); bool findObstacle = false; bool havePathPoint = data.HavePathPoint; if (havePathPoint) {//沿路点列表移动的逻辑 Vector3 targetPos = data.CurPathPoint; if (!data.IsReached(srcPos)) {//向指定路点移动(避让移动过程) user.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); if (!Geometry.IsSameDouble(angle, user.GetMovementStateInfo().GetMoveDir())) { user.GetMovementStateInfo().SetFaceDir(angle); user.GetMovementStateInfo().SetMoveDir(angle); user.GetMovementStateInfo().IsMoving = true; NotifyUserMove(user); } } else {//改变路点或结束沿路点移动 data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; user.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); user.GetMovementStateInfo().SetFaceDir(angle); user.GetMovementStateInfo().SetMoveDir(angle); user.GetMovementStateInfo().IsMoving = true; NotifyUserMove(user); } else { data.Clear(); } } } if (!user.UnityPathFinding) { if (!havePathPoint || findObstacle) {//获得路点过程(寻路) data.Clear(); Vector3 targetPos = pathTargetPos; if (Geometry.DistanceSquare(srcPos, targetPos) > 400) { targetPos = user.SpatialSystem.CalcNearstReachablePoint(srcPos, targetPos, 20); } bool canGo = true; /* * if (!user.SpatialSystem.GetCellMapView(user.AvoidanceRadius).CanPass(targetPos)) { * if (!AiLogicUtility.GetWalkablePosition(user.SpatialSystem.GetCellMapView(user.AvoidanceRadius), targetPos, srcPos, ref targetPos)) * canGo = false; * }*/ if (canGo) { List <Vector3> posList = null; if (user.SpatialSystem.CanPass(user.SpaceObject, targetPos)) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = user.SpatialSystem.FindPath(srcPos, targetPos, user.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 1000) { // LogSystem.Warn("pvp FindPath consume {0} us,user:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, user.GetId(), srcPos.ToString(), targetPos.ToString(), user.AvoidanceRadius, user.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); targetPos = data.CurPathPoint; user.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); user.GetMovementStateInfo().SetFaceDir(angle); user.GetMovementStateInfo().SetMoveDir(angle); user.GetMovementStateInfo().IsMoving = true; NotifyUserMove(user); } else { user.GetMovementStateInfo().IsMoving = false; NotifyUserMove(user); } } else { user.GetMovementStateInfo().IsMoving = false; NotifyUserMove(user); } } } else { if (!havePathPoint || findObstacle) { user.GetMovementStateInfo().IsMoving = false; NotifyUserMove(user); } } } }
public static void ExecObjMoveCommand(int objId, float x, float y, float z) { Vector3 pos = new Vector3(x, y, z); CharacterInfo obj = WorldSystem.Instance.GetCharacterById(objId); UserInfo user = obj as UserInfo; if (null != user) { if (!user.UnityPathFinding) { List <Vector3> waypoints = user.SpatialSystem.FindPath(user.GetMovementStateInfo().GetPosition3D(), pos, 1); waypoints.Add(pos); UserAiStateInfo aiInfo = user.GetAiStateInfo(); AiData_ForMoveCommand data = aiInfo.AiDatas.GetData <AiData_ForMoveCommand>(); if (null == data) { data = new AiData_ForMoveCommand(waypoints); aiInfo.AiDatas.AddData(data); } data.WayPoints = waypoints; data.Index = 0; data.EstimateFinishTime = 0; data.IsFinish = false; aiInfo.ChangeToState((int)AiStateId.MoveCommand); } else { UserAiStateInfo aiInfo = user.GetAiStateInfo(); AiData_ForMoveCommand data = aiInfo.AiDatas.GetData <AiData_ForMoveCommand>(); if (null == data) { data = new AiData_ForMoveCommand(null); aiInfo.AiDatas.AddData(data); } user.PathFindingFinished = false; user.GetAiStateInfo().ChangeToState((int)AiStateId.PathFinding); user.GetAiStateInfo().PreviousState = (int)AiStateId.MoveCommand; GfxSystem.ForMoveCommandPathToTarget(user, pos); } } else { NpcInfo npc = obj as NpcInfo; if (null != npc) { if (!npc.UnityPathFinding) { List <Vector3> waypoints = npc.SpatialSystem.FindPath(npc.GetMovementStateInfo().GetPosition3D(), pos, 1); waypoints.Add(pos); NpcAiStateInfo aiInfo = npc.GetAiStateInfo(); AiData_ForMoveCommand data = aiInfo.AiDatas.GetData <AiData_ForMoveCommand>(); if (null == data) { data = new AiData_ForMoveCommand(waypoints); aiInfo.AiDatas.AddData(data); } data.WayPoints = waypoints; data.Index = 0; data.EstimateFinishTime = 0; data.IsFinish = false; aiInfo.ChangeToState((int)AiStateId.MoveCommand); } else { NpcAiStateInfo aiInfo = npc.GetAiStateInfo(); AiData_ForMoveCommand data = aiInfo.AiDatas.GetData <AiData_ForMoveCommand>(); if (null == data) { data = new AiData_ForMoveCommand(null); aiInfo.AiDatas.AddData(data); } npc.PathFindingFinished = false; npc.GetAiStateInfo().ChangeToState((int)AiStateId.PathFinding); npc.GetAiStateInfo().PreviousState = (int)AiStateId.MoveCommand; GfxSystem.ForMoveCommandPathToTarget(npc, pos); } } } }
private void CombatHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 100) { AiData_UserSelf_General data = GetAiData(user); if (null != data) { data.Time += info.Time; info.Time = 0; //info.IsAttacked = false; CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(user, info.Target); Vector3 targetPos = Vector3.Zero; float dist = info.AttackRange; if (null != target) { targetPos = target.GetMovementStateInfo().GetPosition3D(); } else { targetPos = info.TargetPos; } Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (!info.IsAttacked) { if (powDist < dist * dist) { data.Time = 0; m_AttackRangeLast = info.AttackRange; info.AttackRange = 0; info.IsAttacked = true; float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); user.GetMovementStateInfo().SetFaceDir(dir); user.GetMovementStateInfo().SetMoveDir(dir); if (null != target) { if (null != OnUserStartAttack) { OnUserStartAttack(user, targetPos.X, targetPos.Y, targetPos.Z); } } else { NotifyUserSkill(user, 1); info.IsAttacked = false; } /// user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Idle); } else { user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; info.IsAttacked = false; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Pursuit); } } } else { info.Time = 0; } } }
private void PursuitHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { user.GetMovementStateInfo().IsMoving = false; return; } if (user.IsUnderControl()) { user.GetMovementStateInfo().IsMoving = false; return; } if (user.GetSkillStateInfo().IsSkillActivated()) { user.GetMovementStateInfo().IsMoving = false; return; } UserAiStateInfo info = user.GetAiStateInfo(); AiData_UserSelf_General data = GetAiData(user); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(user, info.Target); if (null != target) { float dist = (float)user.GetActualProperty().AttackRange; float distGoHome = (float)user.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); TryCastSkill(user, target, powDist); // 大于攻击距离 跑向目标 if (powDist > m_AttackRange * m_AttackRange) { info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; if (!user.UnityPathFinding) { AiLogicUtility.PathToTargetWithoutObstacle(user, data.FoundPath, targetPos, m_IntervalTime, true, this); } else { if (info.PreviousState != (int)AiStateId.PathFinding) { user.PathFindingFinished = false; GfxSystem.UserSelfGeneralPathToTarget(user, targetPos); ChangeToState(user, (int)AiStateId.PathFinding); } else { AiLogicUtility.PathToTargetWithoutObstacle(user, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } } else { user.GetMovementStateInfo().IsMoving = false; NotifyUserMove(user); } } else { user.GetMovementStateInfo().IsMoving = false; NotifyUserMove(user); info.Time = 0; ChangeToState(user, (int)AiStateId.Idle); } } }