public static void ChangeScene(int sceneId) { LogSystem.Info("GameControler.ChangeScene {0}", sceneId); WorldSystem.Instance.ChangeNextScene(sceneId); }
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(); }
public static bool CanControl(CharacterInfo obj, out float offsetDir) { bool ret = false; offsetDir = 0; if (null != obj) { float moveDir = obj.GetMovementStateInfo().GetMoveDir(); Vector2 pos = obj.GetMovementStateInfo().GetPosition2D(); int lastAdjust = WorldSystem.Instance.LastMoveDirAdjust; float dir = CalcDir(moveDir, c_PI / 4); if (lastAdjust >= 0 && CanGo(obj, pos.X, pos.Y, dir)) { offsetDir = c_PI / 4; LogSystem.Debug("MoveController CanGo:{0}+{1}, last adjust:{2}", moveDir, offsetDir, lastAdjust); lastAdjust = 1; ret = true; } else { LogSystem.Debug("MoveController try CanGo failed:{0}->{1}, last adjust:{2}", moveDir, dir, lastAdjust); dir = CalcDir(moveDir, -c_PI / 4); if (lastAdjust <= 0 && CanGo(obj, pos.X, pos.Y, dir)) { offsetDir = -c_PI / 4; LogSystem.Debug("MoveController CanGo:{0}+{1}, last adjust:{2}", moveDir, offsetDir, lastAdjust); lastAdjust = -1; ret = true; } else { LogSystem.Debug("MoveController try CanGo failed:{0}->{1}, last adjust:{2}", moveDir, dir, lastAdjust); dir = CalcDir(moveDir, c_PI / 2); if (lastAdjust >= 0 && CanGo(obj, pos.X, pos.Y, dir)) { offsetDir = c_PI / 2; LogSystem.Debug("MoveController CanGo:{0}+{1}, last adjust:{2}", moveDir, offsetDir, lastAdjust); lastAdjust = 1; ret = true; } else { LogSystem.Debug("MoveController try CanGo failed:{0}->{1}, last adjust:{2}", moveDir, dir, lastAdjust); dir = CalcDir(moveDir, -c_PI / 2); if (lastAdjust <= 0 && CanGo(obj, pos.X, pos.Y, dir)) { offsetDir = -c_PI / 2; LogSystem.Debug("MoveController CanGo:{0}+{1}, last adjust:{2}", moveDir, offsetDir, lastAdjust); lastAdjust = -1; ret = true; } else { LogSystem.Debug("MoveController try CanGo failed:{0}->{1}, last adjust:{2}", moveDir, dir, lastAdjust); } } } } if (ret) { WorldSystem.Instance.LastMoveDirAdjust = lastAdjust; } else { LogSystem.Debug("MoveController Can't adjust for {0}", moveDir); } } return(ret); }
private void BuildImpl() { m_BuildStack.Push(0); m_BuildStack.Push(m_PointNum); m_BuildStack.Push(0); while (m_BuildStack.Count >= 3) { int begin = m_BuildStack.Pop(); int end = m_BuildStack.Pop(); int node = m_BuildStack.Pop(); m_KdTree[node].m_Begin = begin; m_KdTree[node].m_End = end; float minX = m_Points[begin].X; float maxX = minX; float minZ = m_Points[begin].Z; float maxZ = minZ; for (int i = begin + 1; i < end; ++i) { float newX = m_Points[i].X; float newZ = m_Points[i].Z; if (minX > newX) { minX = newX; } else if (maxX < newX) { maxX = newX; } if (minZ > newZ) { minZ = newZ; } else if (maxZ < newZ) { maxZ = newZ; } } m_KdTree[node].m_MinX = minX; m_KdTree[node].m_MaxX = maxX; m_KdTree[node].m_MinZ = minZ; m_KdTree[node].m_MaxZ = maxZ; if (end - begin > c_MaxLeafSize) { bool isVertical = (maxX - minX > maxZ - minZ); float splitValue = (isVertical ? 0.5f * (maxX + minX) : 0.5f * (maxZ + minZ)); int left = begin; int right = end; while (left < right) { while (left < right && (isVertical ? m_Points[left].X : m_Points[left].Z) < splitValue) { ++left; } while (right > left && (isVertical ? m_Points[right - 1].X : m_Points[right - 1].Z) >= splitValue) { --right; } if (left < right) { Vector3 tmp = m_Points[left]; m_Points[left] = m_Points[right - 1]; m_Points[right - 1] = tmp; ++left; --right; } } if (left == end) { --left; } int leftSize = left - begin; if (leftSize == 0) { ++leftSize; ++left; } m_KdTree[node].m_Left = node + 1; m_KdTree[node].m_Right = node + 1 + (2 * leftSize - 1); if (m_KdTree[node].m_Left >= m_MaxNodeNum || m_KdTree[node].m_Right >= m_MaxNodeNum) { LogSystem.Error("PointKdTree Error, node:{0} left:{1} right:{2} leftSize:{3} begin:{4} end:{5} maxNodeNum:{6}", node, left, right, leftSize, begin, end, m_MaxNodeNum); } m_BuildStack.Push(m_KdTree[node].m_Left); m_BuildStack.Push(left); m_BuildStack.Push(begin); m_BuildStack.Push(m_KdTree[node].m_Right); m_BuildStack.Push(end); m_BuildStack.Push(left); } } }
public static void PathToTargetWithoutObstacle(NpcInfo npc, AiPathData data, Vector3 pathTargetPos, long deltaTime, bool faceIsMoveFir, AbstractNpcStateLogic logic) { NpcAiStateInfo info = npc.GetAiStateInfo(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); if (null != data) { data.Clear(); data.UpdateTime += deltaTime; Vector3 targetPos = pathTargetPos; List <Vector3> posList = null; bool canPass = npc.SpatialSystem.CanPass(npc.SpaceObject, targetPos); if (canPass) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = npc.SpatialSystem.FindPath(srcPos, targetPos, npc.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve FindPath consume {0} us,npc:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, npc.GetId(), srcPos.ToString(), targetPos.ToString(), npc.AvoidanceRadius, npc.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); } else { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } bool havePathPoint = data.HavePathPoint; if (havePathPoint)//沿路点列表移动的逻辑 { targetPos = data.CurPathPoint; if (!data.IsReached(srcPos))//向指定路点移动(避让移动过程) { float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); Vector3 prefVelocity = (float)npc.GetActualProperty().MoveSpeed *new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); Vector3 v = new Vector3(targetPos.X - srcPos.X, 0, targetPos.Z - srcPos.Z); v.Normalize(); Vector3 velocity = npc.SpaceObject.GetVelocity(); float speedSquare = (float)npc.GetActualProperty().MoveSpeed *(float)npc.GetActualProperty().MoveSpeed; long stTime = TimeUtility.GetElapsedTimeUs(); Vector3 newVelocity = npc.SpatialSystem.ComputeVelocity(npc.SpaceObject, v, (float)deltaTime / 1000, (float)npc.GetActualProperty().MoveSpeed, (float)npc.GetRadius(), data.IsUsingAvoidanceVelocity); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve ComputeVelocity consume {0} us,npc:{1} velocity:{2} newVelocity:{3} deltaTime:{4} speed:{5} pos:{6}", calcTime, npc.GetId(), velocity.ToString(), newVelocity.ToString(), deltaTime, npc.GetActualProperty().MoveSpeed, npc.GetMovementStateInfo().GetPosition3D().ToString()); } if (data.UpdateTime > 500) { data.UpdateTime = 0; float newAngle = Geometry.GetYAngle(new Vector2(0, 0), new Vector2(newVelocity.X, newVelocity.Z)); npc.GetMovementStateInfo().SetMoveDir(newAngle); if (faceIsMoveFir) { logic.NotifyNpcFace(npc, newAngle); } newVelocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + newVelocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); } else { data.UpdateTime += deltaTime; } } else//改变路点或结束沿路点移动 { data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetMoveDir(angle); if (faceIsMoveFir) { logic.NotifyNpcFace(npc, angle); } npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { npc.GetMovementStateInfo().IsMoving = false; data.Clear(); } } } } }
public static void PathToTarget(NpcInfo npc, AiPathData data, Vector3 pathTargetPos, long deltaTime, bool faceIsMoveFir, AbstractNpcStateLogic logic) { NpcAiStateInfo info = npc.GetAiStateInfo(); if (null != data) { data.UpdateTime += deltaTime; ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float dir = npc.GetMovementStateInfo().GetMoveDir(); bool findObstacle = false; bool havePathPoint = data.HavePathPoint; if (havePathPoint)//沿路点列表移动的逻辑 { Vector3 targetPos = data.CurPathPoint; if (!data.IsReached(srcPos))//向指定路点移动(避让移动过程) { float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); Vector3 prefVelocity = (float)npc.GetActualProperty().MoveSpeed *new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); Vector3 v = new Vector3(targetPos.X - srcPos.X, 0, targetPos.Z - srcPos.Z); v.Normalize(); Vector3 velocity = npc.SpaceObject.GetVelocity(); float speedSquare = (float)npc.GetActualProperty().MoveSpeed *(float)npc.GetActualProperty().MoveSpeed; long stTime = TimeUtility.GetElapsedTimeUs(); Vector3 newVelocity = npc.SpatialSystem.ComputeVelocity(npc.SpaceObject, v, (float)deltaTime / 1000, (float)npc.GetActualProperty().MoveSpeed, (float)npc.GetRadius(), data.IsUsingAvoidanceVelocity); findObstacle = !AiLogicUtility.IsWalkable(npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius), srcPos, newVelocity); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve ComputeVelocity consume {0} us,npc:{1} velocity:{2} newVelocity:{3} deltaTime:{4} speed:{5} pos:{6}", calcTime, npc.GetId(), velocity.ToString(), newVelocity.ToString(), deltaTime, npc.GetActualProperty().MoveSpeed, npc.GetMovementStateInfo().GetPosition3D().ToString()); } if (Geometry.DistanceSquare(newVelocity, new Vector3()) <= speedSquare * 0.25f)//避让计算的移动速度变小(说明没有更好的保持原速的选择,停止) { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else if (findObstacle)//当前移动方向遇到阻挡,停止移动,触发寻路 { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else if (data.UpdateTime > 1000)//避让速度改变每秒一次(表现上更像人类一些) { data.UpdateTime = 0; float newAngle = Geometry.GetYAngle(new Vector2(0, 0), new Vector2(newVelocity.X, newVelocity.Z)); npc.GetMovementStateInfo().SetMoveDir(newAngle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(newAngle); } newVelocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + newVelocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = true; } else if (Geometry.DistanceSquare(velocity, newVelocity) > 9.0f) //没有到速度改变周期,但避让方向需要大幅调整 { if (Geometry.Dot(newVelocity, prefVelocity) > 0) //如果是调整为与目标方向一致,则进行调整 { float newAngle = Geometry.GetYAngle(new Vector2(0, 0), new Vector2(newVelocity.X, newVelocity.Z)); npc.GetMovementStateInfo().SetMoveDir(newAngle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(newAngle); } newVelocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + newVelocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = true; } else//如果调整为远离目标方向,则停止 { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else if (!npc.GetMovementStateInfo().IsMoving&& velocity.LengthSquared() > speedSquare * 0.25f)//正常移动过程,继续移动 { velocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + velocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else//改变路点或结束沿路点移动 { data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetMoveDir(angle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(angle); } npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { data.Clear(); } } } if (!havePathPoint || findObstacle)//获得路点过程(寻路) { data.Clear(); Vector3 targetPos = pathTargetPos; bool canGo = true; if (!npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius).CanPass(targetPos)) { if (!AiLogicUtility.GetWalkablePosition(npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius), targetPos, srcPos, ref targetPos)) { canGo = false; } } if (canGo) { List <Vector3> posList = null; bool canPass = npc.SpatialSystem.CanPass(npc.SpaceObject, targetPos); if (canPass) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = npc.SpatialSystem.FindPath(srcPos, targetPos, npc.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve FindPath consume {0} us,npc:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, npc.GetId(), srcPos.ToString(), targetPos.ToString(), npc.AvoidanceRadius, npc.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetMoveDir(angle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(angle); } npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } } }
public static void LogCallStack() { StackTrace trace = new StackTrace(); LogSystem.Debug("LogCallStack:\n{0}\n", trace.ToString()); }
private void PathToTargetWithoutObstacle(NpcInfo npc, AiPathData data, Vector3 pathTargetPos, long deltaTime) { NpcAiStateInfo info = npc.GetAiStateInfo(); if (null != data) { data.UpdateTime += deltaTime; ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float dir = npc.GetMovementStateInfo().GetMoveDir(); bool findObstacle = false; bool havePathPoint = data.HavePathPoint; if (havePathPoint)//沿路点列表移动的逻辑 { Vector3 targetPos = data.CurPathPoint; if (!data.IsReached(srcPos))//向指定路点移动(避让移动过程) { float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); Vector3 prefVelocity = (float)npc.GetActualProperty().MoveSpeed *new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); Vector3 v = new Vector3(targetPos.X - srcPos.X, 0, targetPos.Z - srcPos.Z); v.Normalize(); Vector3 velocity = npc.SpaceObject.GetVelocity(); float speedSquare = (float)npc.GetActualProperty().MoveSpeed *(float)npc.GetActualProperty().MoveSpeed; long stTime = TimeUtility.GetElapsedTimeUs(); Vector3 newVelocity = npc.SpatialSystem.ComputeVelocity(npc.SpaceObject, v, (float)deltaTime / 1000, (float)npc.GetActualProperty().MoveSpeed, (float)npc.GetRadius(), data.IsUsingAvoidanceVelocity); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pvp ComputeVelocity consume {0} us,npc:{1} velocity:{2} newVelocity:{3} deltaTime:{4} speed:{5} pos:{6}", calcTime, npc.GetId(), velocity.ToString(), newVelocity.ToString(), deltaTime, npc.GetActualProperty().MoveSpeed, npc.GetMovementStateInfo().GetPosition3D().ToString()); for (LinkedListNode <UserInfo> node = npc.UserManager.Users.FirstValue; null != node; node = node.Next) { UserInfo userInfo = node.Value; if (null != userInfo) { LogSystem.Warn("===>User:{0} Pos:{1}", userInfo.GetId(), userInfo.GetMovementStateInfo().GetPosition3D().ToString()); } } for (LinkedListNode <NpcInfo> node = npc.NpcManager.Npcs.FirstValue; null != node; node = node.Next) { NpcInfo npcInfo = node.Value; if (null != npcInfo) { LogSystem.Warn("===>Npc:{0} Pos:{1}", npcInfo.GetId(), npcInfo.GetMovementStateInfo().GetPosition3D().ToString()); } } } if (findObstacle)//当前移动方向遇到阻挡,停止移动,触发寻路 { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else if (!npc.GetMovementStateInfo().IsMoving&& velocity.LengthSquared() > speedSquare * 0.25f)//正常移动过程,继续移动 { velocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + velocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else//改变路点或结束沿路点移动 { data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetFaceDir(angle); npc.GetMovementStateInfo().SetMoveDir(angle); npc.GetMovementStateInfo().IsMoving = true; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { data.Clear(); } } } if (!havePathPoint || findObstacle)//获得路点过程(寻路) { data.Clear(); Vector3 targetPos = pathTargetPos; bool canGo = true; if (canGo) { List <Vector3> posList = null; bool canPass = npc.SpatialSystem.CanPass(npc.SpaceObject, targetPos); if (canPass) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = npc.SpatialSystem.FindPath(srcPos, targetPos, npc.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pvp FindPath consume {0} us,npc:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, npc.GetId(), srcPos.ToString(), targetPos.ToString(), npc.AvoidanceRadius, npc.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetFaceDir(angle); npc.GetMovementStateInfo().SetMoveDir(angle); npc.GetMovementStateInfo().IsMoving = true; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } } }
public void ResetViewed(int radius) { m_Viewed = new bool[radius * 2 + 1, radius * 2 + 1]; LogSystem.Debug("FovViewed reset."); }
private void PathToTarget(UserInfo user, AiPathData data, Vector3 pathTargetPos, long deltaTime) { UserAiStateInfo info = user.GetAiStateInfo(); if (null != data) { data.UpdateTime += deltaTime; ScriptRuntime.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 (!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); } } } }
internal void StartSkill(int objId, int skillId) { CharacterInfo obj = CurScene.SceneContext.GetCharacterInfoById(objId); if (null != obj) { SkillInstanceInfo inst = NewSkillInstance(skillId); if (null != inst) { obj.GetSkillStateInfo().SetCurSkillInfo(skillId); SkillInfo skillInfo = obj.GetSkillStateInfo().GetCurSkillInfo(); if (null != skillInfo) { if (MakeSkillCast(obj, skillInfo)) { ArkCrossEngineMessage.Msg_RC_SyncProperty propBuilder = DataSyncUtility.BuildSyncPropertyMessage(obj); Scene scene = obj.SceneContext.CustomData as Scene; if (null != scene) { scene.NotifyAllUser(propBuilder); } } else { skillInfo.m_EnableImpactsToMyself = null; skillInfo.m_EnableImpactsToOther = null; skillInfo.m_LeftEnableMoveCount = 0; skillInfo.m_LeftEnableImpactsToMyself.Clear(); skillInfo.m_LeftEnableImpactsToOther.Clear(); return; } skillInfo.IsSkillActivated = true; m_SkillLogicInfos.Add(new SkillLogicInfo(objId, inst)); SkillLogicInfo logicInfo = m_SkillLogicInfos.Find(info => info.SenderId == objId && info.SkillId == skillId); if (null != logicInfo) { //目前没有与技能释放者相关的分析属性,对每个技能暂时只需要分析一次 if (null == skillInfo.m_EnableImpactsToMyself || null == skillInfo.m_EnableImpactsToOther) { if (!logicInfo.SkillInst.AlreadyAnalyzed) { logicInfo.SkillInst.Analyze(obj); foreach (int skill in logicInfo.SkillInst.SummonNpcSkills) { List <int> impacts = AnalyzeNpcSkills(skill, logicInfo.SkillInst); logicInfo.SkillInst.EnableImpactsToOther.AddRange(impacts); } } skillInfo.m_EnableMoveCount = logicInfo.SkillInst.EnableMoveCount; skillInfo.m_MaxMoveDistance = logicInfo.SkillInst.MaxMoveDelta; skillInfo.m_EnableImpactsToOther = logicInfo.SkillInst.EnableImpactsToOther; skillInfo.m_EnableImpactsToMyself = logicInfo.SkillInst.EnableImpactsToMyself; skillInfo.m_EnableSummonNpcs = logicInfo.SkillInst.SummonNpcs; /* * LogSys.Log(LOG_TYPE.WARN, "Skill {0} EnableMoveCount {1} MaxMoveDistanceSqr {2}\n\tEnableImpactsToOther {3}\n\tEnableImpactsToMyself {4}\n\tSummonNpcSkills {5}", skillId, skillInfo.m_EnableMoveCount, skillInfo.m_MaxMoveDistanceSqr, * string.Join<int>(",", skillInfo.m_EnableImpactsToOther), * string.Join<int>(",", skillInfo.m_EnableImpactsToMyself), * string.Join<int>(",", logicInfo.SkillInst.SummonNpcSkills)); */ } skillInfo.m_LeftEnableMoveCount = skillInfo.m_EnableMoveCount; skillInfo.m_LeftEnableImpactsToMyself.AddRange(skillInfo.m_EnableImpactsToMyself); skillInfo.m_LeftEnableImpactsToOther.Clear(); if (logicInfo.SkillInst.IsSimulate) { obj.GetSkillStateInfo().SimulateEndTime = TimeUtility.GetServerMilliseconds() + logicInfo.SkillInst.MaxSkillLifeTime; } logicInfo.SkillInst.Start(obj); /* * DashFire.LogSystem.Warn("StartSkill {0} {1} EnableMoveCount {2} MaxMoveDistance {3}\n\tEnableImpactsToOther {4}\n\tEnableImpactsToMyself {5}\n\tSummonNpcSkills {6}", objId, skillId, skillInfo.m_LeftEnableMoveCount, skillInfo.m_MaxMoveDistanceSqr, * string.Join<int>(",", skillInfo.m_EnableImpactsToOther), * string.Join<int>(",", skillInfo.m_EnableImpactsToMyself), * string.Join<int>(",", logicInfo.SkillInst.SummonNpcSkills)); */ } } else { LogSystem.Error("{0} StartSkill can't find skill {1}", objId, skillId); } } } else { LogSystem.Debug("not find game obj by id " + objId); } }