private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.HaveState(CharacterPropertyEnum.x3002_昏睡) || obj.HaveState(CharacterPropertyEnum.x3001_眩晕)) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float speed = (float)obj.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度); float distance = (speed * (float)(int)deltaTime) / 1000.0f; ScriptRuntime.Vector3 dir = msi.TargetDir; //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance); float x = 0, y = 0; if (msi.CalcDistancSquareToTarget() < distance * distance) { x = msi.TargetPosition.X; y = msi.TargetPosition.Z; ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y); msi.SetPosition2D(newPos); msi.IsMoving = false; } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
private static void AiPursue(EntityInfo npc, ScriptRuntime.Vector3 target) { MovementStateInfo msi = npc.GetMovementStateInfo(); msi.IsMoving = true; msi.TargetPosition = target; float dir = Geometry.GetYRadian(msi.GetPosition3D(), target); msi.SetFaceDir(dir); }
static public int GetPosition3D(IntPtr l) { try { GameFramework.MovementStateInfo self = (GameFramework.MovementStateInfo)checkSelf(l); var ret = self.GetPosition3D(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition)) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float speed = (float)obj.GetActualProperty().MoveSpeed; float distance = (speed * (float)(int)deltaTime) / 1000.0f; ScriptRuntime.Vector3 dir = msi.TargetDir; //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance); float x = 0, y = 0; if (msi.CalcDistancSquareToTarget() < distance * distance) { x = msi.TargetPosition.X; y = msi.TargetPosition.Z; ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y); msi.SetPosition2D(newPos); msi.IsMoving = false; User user = obj.CustomData as User; if (null != user) { Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
public static Msg_RC_NpcSkill BuildNpcSkillMessage(EntityInfo obj, int skillId) { MovementStateInfo msi = obj.GetMovementStateInfo(); ScriptRuntime.Vector3 pos = msi.GetPosition3D(); Msg_RC_NpcSkill msg = new Msg_RC_NpcSkill(); msg.npc_id = obj.GetId(); msg.skill_id = skillId; msg.stand_pos = ToPosition(pos.X, pos.Z); msg.face_direction = msi.GetFaceDir(); msg.target_id = obj.GetAiStateInfo().Target; return(msg); }
private void SyncMovement() { if (null != m_Entity && null != m_Actor) { float curTime = Time.time; MovementStateInfo msi = m_Entity.GetMovementStateInfo(); if (msi.IsMoving) { if (m_LastSyncTime + c_SyncInterval <= curTime) { m_LastSyncTime = curTime; if (m_Entity.IsServerEntity) { Transform t = m_Actor.transform; ScriptRuntime.Vector3 dir = msi.GetMoveDir3D(); Vector3 pos = t.position + new Vector3(dir.X, 0, dir.Z) * 8.0f * c_SyncInterval; } } if (GlobalVariables.Instance.IsDebug) { Utility.EventSystem.Publish("ui_actor_name", "ui", m_Entity.GetId(), string.Format("{0}({1}):c({2},{3})", m_Entity.GetName(), m_Entity.GetId(), msi.PositionX, msi.PositionZ)); } if (m_Entity.GetId() != PluginFramework.Instance.LeaderID) { if (Geometry.DistanceSquare(msi.GetPosition3D(), msi.TargetPosition) > 0.625f) { MoveTo(msi.TargetPosition.X, msi.TargetPosition.Y, msi.TargetPosition.Z); } else { msi.IsMoving = false; StopMove(); } } } else { if (GlobalVariables.Instance.IsDebug) { Utility.EventSystem.Publish("ui_actor_name", "ui", m_Entity.GetId(), string.Format("{0}({1}):c({2},{3})", m_Entity.GetName(), m_Entity.GetId(), msi.PositionX, msi.PositionZ)); } } } }
public bool CalcPosAndDir(int targetId, out ScriptRuntime.Vector3 pos, out float dir) { EntityViewModel view = GetEntityViewById(targetId); if (null != view) { MovementStateInfo msi = view.Entity.GetMovementStateInfo(); pos = msi.GetPosition3D(); dir = msi.GetFaceDir(); return(true); } else { pos = ScriptRuntime.Vector3.Zero; dir = 0; return(false); } }
public void Create(EntityInfo entity) { if (null != entity) { m_Entity = entity; MovementStateInfo msi = m_Entity.GetMovementStateInfo(); ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_Entity.GetId(), m_Entity.GetModel(), pos.X, pos.Y, pos.Z, dir, m_Entity.Scale, m_Entity.GetRadius(), entity.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度)); if (null != Actor) { m_Agent = Actor.GetComponent <NavMeshAgent>(); if (m_Agent == null) { m_Agent = Actor.AddComponent <NavMeshAgent>(); m_Agent.angularSpeed = c_AngularSpeed; m_Agent.acceleration = c_Acceleration; m_Agent.radius = entity.GetRadius(); m_Agent.speed = entity.ActualProperty.GetFloat(CharacterPropertyEnum.x2011_最终速度); m_Agent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; } m_Animator = Actor.GetComponentInChildren <Animator>(); EntityDrawGizmos gizmos = Actor.GetComponent <EntityDrawGizmos>(); if (null == gizmos) { gizmos = Actor.AddComponent <EntityDrawGizmos>(); gizmos.npcInfo = m_Entity; } else { gizmos.npcInfo = m_Entity; } SetMoveAgentEnable(true); try{ if (null != m_Agent) { m_Agent.ResetPath(); } } catch { m_Agent.enabled = true; } } } }
internal static void Execute(object msg, User user) { Msg_CR_UserMoveToPos move_msg = msg as Msg_CR_UserMoveToPos; if (move_msg == null) { return; } EntityInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.DEBUG, "charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name); return; } /// if (charactor.GetAIEnable()) { float tx, tz; ProtoHelper.DecodePosition2D(move_msg.target_pos, out tx, out tz); ScriptRuntime.Vector3 pos = new ScriptRuntime.Vector3(tx, 0, tz); MovementStateInfo msi = charactor.GetMovementStateInfo(); msi.IsMoving = true; msi.TargetPosition = pos; float dir = Geometry.GetYRadian(msi.GetPosition3D(), pos); msi.SetFaceDir(dir); msi.SetMoveDir(dir); Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(charactor); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
public void Tick() { try { if (this.CurrentState != RoomState.Active && this.CurrentState != RoomState.Finish) { return; } long curTime = TimeUtility.GetLocalMilliseconds(); if (m_LastLogTime + 60000 < curTime) { m_LastLogTime = curTime; LogSys.Log(LOG_TYPE.INFO, "Room.Tick {0}", RoomId); } if (this.CurrentState == RoomState.Active) { Scene scene = ActiveScene; if (null != scene) { scene.Tick(); OnTick(); } m_DisconnectedUsers.Clear(); m_RequestDeleteUsers.Clear(); foreach (User user in m_RoomUserMgr.RoomUsers) { if (user != null) { user.Tick(); if (user.IsTimeout()) { if (user.UserControlState == (int)UserControlState.User) { m_DisconnectedUsers.Add(user); } else if (user.UserControlState == (int)UserControlState.Remove) { m_RequestDeleteUsers.Add(user); } else if (user.UserControlState == (int)UserControlState.UserDropped) { if (user.LastNotifyUserDropTime + c_NotifyUserDropInterval < curTime) { Msg_RL_UserDrop uaqBuilder = new Msg_RL_UserDrop(); uaqBuilder.RoomId = m_RoomId; uaqBuilder.UserGuid = user.Guid; uaqBuilder.IsBattleEnd = false; m_Connector.SendMsgToLobby(uaqBuilder); user.LastNotifyUserDropTime = curTime; } //临时处理,踢掉断线的玩家 user.UserControlState = (int)UserControlState.Remove; } } } } foreach (User user in m_DisconnectedUsers) { m_RoomUserMgr.DropUser(user); } foreach (User user in m_RequestDeleteUsers) { m_RoomUserMgr.RemoveUser(user); } //todo:观察者掉线处理 for (int i = 0; i < m_RoomUserMgr.RoomObservers.Length; ++i) { Observer observer = m_RoomUserMgr.RoomObservers[i]; if (!observer.IsIdle) { observer.Tick(); } } if (!IsFieldRoom) { int userCount = GetActiveRoomUserCount(); if (userCount <= 0 && CanFinish) { if (GetMinimizeElapsedDroppedTime() > c_FinishTimeForNoUsers) { //若房间内玩家数目为0,结束战斗,关闭房间 Finish((int)CampIdEnum.Unkown); } } } //每个Tick结束,将空间属性同步给Peer,用于Peer转发消息 foreach (User user in m_RoomUserMgr.RoomUsers) { if (null != user && null != user.Info && null != user.Info.GetMovementStateInfo()) { GameFramework.RoomPeer peer = user.GetPeer(); if (null != peer) { MovementStateInfo info = user.Info.GetMovementStateInfo(); peer.Position = info.GetPosition3D(); peer.FaceDir = info.GetFaceDir(); } } } } else if (m_FinishTime + c_DeactiveWaitTime < curTime) { Deactive(); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }