internal static void Execute(object msg, User user) { Msg_CR_UserMoveToPos move_msg = msg as Msg_CR_UserMoveToPos; if (move_msg == null) { return; } UserInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.ERROR, "charactor {0} not exist", user.RoleId); return; } /// if (charactor.GetAIEnable()) { MovementStateInfo msi = charactor.GetMovementStateInfo(); msi.PositionX = move_msg.cur_pos_x; msi.PositionZ = move_msg.cur_pos_z; UserAiStateInfo asi = charactor.GetAiStateInfo(); Vector3 pos = new Vector3(move_msg.target_pos_x, 0, move_msg.target_pos_z); asi.TargetPos = pos; asi.IsTargetPosChanged = true; asi.ChangeToState((int)(AiStateId.Move)); } }
internal static void Execute(object msg, User user) { Msg_CRC_MoveMeetObstacle obstacle_msg = msg as Msg_CRC_MoveMeetObstacle; if (null == obstacle_msg) { return; } UserInfo userInfo = user.Info; if (userInfo != null) { MovementStateInfo msi = userInfo.GetMovementStateInfo(); userInfo.GetMovementStateInfo().IsMoveMeetObstacle = true; if (!msi.IsSkillMoving) { float x = obstacle_msg.cur_pos_x; float z = obstacle_msg.cur_pos_z; float velocity = (float)user.Info.GetActualProperty().MoveSpeed; if (!user.VerifyPosition(x, z, velocity, obstacle_msg.send_time, 4.0f)) { //todo:记录违规次数 } msi.SetPosition2D(x, z); user.SampleMoveData(obstacle_msg.cur_pos_x, obstacle_msg.cur_pos_z, velocity, msi.MoveDirCosAngle, msi.MoveDirSinAngle, obstacle_msg.send_time); } //LogSys.Log(LOG_TYPE.DEBUG, "MoveMeetObstacleHandler User:{0} isskillmoving:{1} ismovemeetobstacle:{2} time:{3} client time:{4}", user.RoleId, msi.IsSkillMoving, msi.IsMoveMeetObstacle, TimeUtility.GetServerMilliseconds(), obstacle_msg.send_time); } }
private void UpdateSpatial() { if (null != m_Npc) { if (ObjectInfo.IsGfxMoveControl) { if (ObjectInfo.DataChangedByGfx) { MovementStateInfo msi = m_Npc.GetMovementStateInfo(); msi.PositionX = ObjectInfo.X; msi.PositionY = ObjectInfo.Y; msi.PositionZ = ObjectInfo.Z; msi.SetFaceDir(ObjectInfo.FaceDir); ObjectInfo.DataChangedByGfx = false; } } else { if (ObjectInfo.DataChangedByGfx) { MovementStateInfo msi = m_Npc.GetMovementStateInfo(); msi.PositionX = ObjectInfo.X; msi.PositionY = ObjectInfo.Y; msi.PositionZ = ObjectInfo.Z; msi.SetFaceDir(ObjectInfo.FaceDir); ObjectInfo.DataChangedByGfx = false; } UpdateMovement(); } } }
public static void AdjustUserPosition(int id, float x, float y, float z, float time, float dir) { CharacterInfo info = WorldSystem.Instance.GetCharacterById(id); if (null != info) { MovementStateInfo msi = info.GetMovementStateInfo(); if (time < 1000) { Vector3 pos = msi.GetPosition3D(); float speed = info.GetActualProperty().MoveSpeed; float distance = (speed * time) / 1000; float len = pos.Length(); float nz = (float)(z + distance * Math.Cos(dir)); float nx = (float)(x + distance * Math.Sin(dir)); int ctrlId = ControllerIdCalculator.Calc(ControllerType.Position, id); PositionController ctrl = ControlSystem.Instance.PositionControllerPool.Alloc(); if (null != ctrl) { ctrl.Init(ctrlId, id, nx - pos.X, 0, nz - pos.Z, 1000); ControlSystem.Instance.AddController(ctrl); } LogSystem.Debug("PositionController start, dx:{0} dz:{1} time:{2}", nx - pos.X, nz - pos.Z, 500); } else { msi.SetPosition2D(x, z); LogSystem.Debug("PositionController just move to pos, x:{0} z:{1}", x, z); } } }
public void Create(NpcInfo npc) { Init(); if (null != npc) { m_Npc = npc; m_Npc.OnBeginAttack = ResetShootAnimation; MovementStateInfo msi = m_Npc.GetMovementStateInfo(); Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_Npc.GetId(), m_Npc.GetModel(), pos, dir, m_Npc.Scale); InitAnimationSets(); UpdateWeaponModel(m_Npc); } }
internal static void Execute(object msg, User user) { Msg_CRC_Skill use_skill = msg as Msg_CRC_Skill; if (use_skill == null) { return; } CharacterInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.ERROR, "UseSkillHandler, charactor {0} not exist", user.RoleId); return; } charactor = charactor.GetRealControlledObject(); MovementStateInfo msi = charactor.GetMovementStateInfo(); if (!msi.IsSkillMoving) { float x = use_skill.stand_pos.x; float z = use_skill.stand_pos.z; float velocity = (float)user.Info.GetActualProperty().MoveSpeed; if (!user.VerifyPosition(x, z, velocity, use_skill.send_time, 4.0f)) { //todo:记录违规次数 } msi.SetPosition2D(x, z); user.SampleMoveData(use_skill.stand_pos.x, use_skill.stand_pos.z, velocity, msi.MoveDirCosAngle, msi.MoveDirSinAngle, use_skill.send_time); } msi.SetFaceDir(use_skill.face_direction); Scene scene = user.OwnRoom.GetActiveScene(); if (null != scene) { scene.SkillSystem.StartSkill(user.RoleId, use_skill.skill_id); } //LogSys.Log(LOG_TYPE.DEBUG, "UseSkillHandler User:{0} skill:{1} isskillmoving:{2} ismovemeetobstacle:{3} time:{4} client time:{5}", user.RoleId, use_skill.skill_id, msi.IsSkillMoving, msi.IsMoveMeetObstacle, TimeUtility.GetServerMilliseconds(), use_skill.send_time); }
public void Create(UserInfo user) { Init(); if (null != user) { m_User = user; m_User.OnBeginAttack = ResetShootAnimation; MovementStateInfo msi = m_User.GetMovementStateInfo(); Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_User.GetId(), m_User.GetModel(), pos, dir, m_User.Scale); InitAnimationSets(); UpdateWeaponModel(m_User); if (user.GetId() == WorldSystem.Instance.PlayerSelfId) { GfxSystem.MarkPlayerSelf(Actor); } } }
protected void UpdateMovement() { CharacterInfo obj = GetOwner(); if (null != obj && !obj.IsDead() && null != ObjectInfo) { MovementStateInfo msi = obj.GetMovementStateInfo(); ObjectInfo.FaceDir = msi.GetFaceDir(); if (msi.IsMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); ObjectInfo.MoveCos = (float)msi.MoveDirCosAngle; ObjectInfo.MoveSin = (float)msi.MoveDirSinAngle; ObjectInfo.MoveSpeed = (float)obj.GetActualProperty().MoveSpeed *(float)obj.VelocityCoefficient; if (obj is UserInfo) { if (msi.TargetPosition.LengthSquared() < Geometry.c_FloatPrecision) { ObjectInfo.MoveTargetDistanceSqr = 100.0f; } else { ObjectInfo.MoveTargetDistanceSqr = msi.CalcDistancSquareToTarget(); } } else { ObjectInfo.MoveTargetDistanceSqr = msi.CalcDistancSquareToTarget(); } ObjectInfo.IsLogicMoving = true; } else { ObjectInfo.IsLogicMoving = false; } } else { ObjectInfo.IsLogicMoving = false; } }
internal static void Execute(object msg, User user) { Msg_CR_UserMoveToAttack attack_msg = msg as Msg_CR_UserMoveToAttack; if (attack_msg == null) { return; } UserInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.ERROR, "charactor {0} not exist", user.RoleId); return; } /// if (charactor.GetAIEnable()) { MovementStateInfo msi = charactor.GetMovementStateInfo(); msi.PositionX = attack_msg.cur_pos_x; msi.PositionZ = attack_msg.cur_pos_z; UserAiStateInfo aiInfo = charactor.GetAiStateInfo(); AiData_UserSelf_General data = charactor.GetAiStateInfo().AiDatas.GetData <AiData_UserSelf_General>(); if (null == data) { data = new AiData_UserSelf_General(); charactor.GetAiStateInfo().AiDatas.AddData(data); } charactor.GetMovementStateInfo().IsMoving = false; data.FoundPath.Clear(); aiInfo.Time = 0; aiInfo.Target = attack_msg.target_id; aiInfo.IsAttacked = false; aiInfo.AttackRange = attack_msg.attack_range; aiInfo.ChangeToState((int)AiStateId.Combat); } }
public 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; } // if move input is disable // MotionStatus is MoveStop, and MotionChanged is reflect the change accordingly // pm_.Update(EnableMoveInput); UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (null == playerself) { return; } Vector3 pos = playerself.GetMovementStateInfo().GetPosition3D(); Vector3 mouse_pos = new Vector3(GfxSystem.GetMouseX(), GfxSystem.GetMouseY(), GfxSystem.GetMouseZ());//GfxSystem.Instance.MainScene.GetMousePos(pos.Y); if (pm_.MotionStatus == PlayerMovement.Motion.Moving) { if (pm_.MotionChanged) { WorldSystem.Instance.InputMoveDir = pm_.MoveDir; playerself.GetMovementStateInfo().SetWantMoveDir(pm_.MoveDir); if (WorldSystem.Instance.IsPveScene()) { playerself.GetMovementStateInfo().SetMoveDir(pm_.MoveDir); playerself.GetMovementStateInfo().IsMoving = true; playerself.GetMovementStateInfo().TargetPosition = Vector3.Zero; } else { NetworkSystem.Instance.SyncPlayerMoveStart((float)pm_.MoveDir); } if (EnableRotateInput) { MovementStateInfo msi = playerself.GetMovementStateInfo(); msi.SetFaceDir(pm_.MoveDir); NetworkSystem.Instance.SyncFaceDirection((float)pm_.MoveDir); } } } else { if (pm_.MotionChanged) { WorldSystem.Instance.LastMoveDirAdjust = 0; if (WorldSystem.Instance.IsPveScene()) { playerself.GetMovementStateInfo().IsMoving = false; } else { NetworkSystem.Instance.SyncPlayerMoveStop(); } } } 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; } }
internal static void Execute(object msg, User user) { Msg_CRC_GfxControlMoveStop _msg = msg as Msg_CRC_GfxControlMoveStop; if (_msg == null) { return; } Scene scene = user.OwnRoom.GetActiveScene(); if (null != scene) { CharacterInfo info = scene.SceneContext.GetCharacterInfoById(_msg.obj_id); if (null != info && (_msg.obj_id == user.RoleId || info.OwnerId == user.RoleId)) { MovementStateInfo msi = info.GetMovementStateInfo(); Vector3 pos; if (_msg.obj_id == user.RoleId) { pos = user.LastClientPosition; } else { pos = msi.GetPosition3D(); } Vector3 newPos = new Vector3(_msg.target_pos.x, 0, _msg.target_pos.z); msi.IsSkillMoving = false; bool enableControl = false; if (_msg.is_skill) { SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(_msg.skill_or_impact_id); float distance = Geometry.Distance(pos, newPos); if (null != skillInfo && (skillInfo.m_LeftEnableMoveCount > 0 || distance <= 0.3)) { //校验 --skillInfo.m_LeftEnableMoveCount; if (distance <= skillInfo.m_MaxMoveDistance + 1) { enableControl = true; //LogSys.Log(LOG_TYPE.WARN, "Msg_CRC_GfxControlMoveStopHandler {0} ({1} <= {2}) LeftEnableMoveCount:{3} skill:{4} accept by server ({5}->{6})", _msg.obj_id, distSqr, skillInfo.m_MaxMoveDistanceSqr, skillInfo.m_LeftEnableMoveCount, _msg.skill_or_impact_id, pos.ToString(), newPos.ToString()); } else { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStopHandler {0} ({1} > {2}) LeftEnableMoveCount:{3} skill:{4} can't accept by server ({5}->{6})", _msg.obj_id, distance, skillInfo.m_MaxMoveDistance, skillInfo.m_LeftEnableMoveCount, _msg.skill_or_impact_id, pos.ToString(), newPos.ToString()); } } else { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStopHandler {0} (LeftEnableMoveCount:{1} skill:{2}) can't accept by server ({3}->{4})", _msg.obj_id, skillInfo != null ? skillInfo.m_LeftEnableMoveCount : -1, _msg.skill_or_impact_id, pos.ToString(), newPos.ToString()); } } else { ImpactInfo impactInfo = info.GetSkillStateInfo().GetImpactInfoForCheck(_msg.skill_or_impact_id); if (null != impactInfo && impactInfo.m_LeftEnableMoveCount > 0) { //校验 --impactInfo.m_LeftEnableMoveCount; float distance = Geometry.Distance(pos, newPos); if (distance <= impactInfo.m_MaxMoveDistance + 1) { enableControl = true; //LogSys.Log(LOG_TYPE.WARN, "Msg_CRC_GfxControlMoveStopHandler {0} ({1} <= {2}) LeftEnableMoveCount:{3} skill:{4} impact:{5} accept by server ({6}->{7})", _msg.obj_id, distSqr, impactInfo.m_MaxMoveDistanceSqr, impactInfo.m_LeftEnableMoveCount, impactInfo.m_SkillId, _msg.skill_or_impact_id, pos.ToString(), newPos.ToString()); } else { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStopHandler {0} ({1} > {2}) LeftEnableMoveCount:{3} skill:{4} impact:{5} can't accept by server ({6}->{7})", _msg.obj_id, distance, impactInfo.m_MaxMoveDistance, impactInfo.m_LeftEnableMoveCount, impactInfo.m_SkillId, _msg.skill_or_impact_id, pos.ToString(), newPos.ToString()); } } else { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStopHandler {0} (LeftEnableMoveCount:{1} skill:{2} impact:{3}) can't accept by server ({4}->{5})", _msg.obj_id, impactInfo != null ? impactInfo.m_LeftEnableMoveCount : -1, impactInfo != null ? impactInfo.m_SkillId : -1, _msg.skill_or_impact_id, pos.ToString(), newPos.ToString()); } } if (enableControl) { msi.SetFaceDir(_msg.face_dir); msi.SetPosition(newPos); } else { //todo:记录违规次数 } if (_msg.obj_id == user.RoleId) { float velocity = (float)user.Info.GetActualProperty().MoveSpeed; user.SampleMoveData(msi.PositionX, msi.PositionZ, velocity, msi.MoveDirCosAngle, msi.MoveDirSinAngle, _msg.send_time); } } else { if (null == info) { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStopHandler, charactor {0} not exist", _msg.obj_id); } else { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStopHandler, charactor {0} or owner {1} not user {2}", info.GetId(), info.OwnerId, user.RoleId); } } } }
internal static void Execute(object msg, User user) { Msg_CRC_GfxControlMoveStart _msg = msg as Msg_CRC_GfxControlMoveStart; if (_msg == null) { return; } Scene scene = user.OwnRoom.GetActiveScene(); if (null != scene) { CharacterInfo info = scene.SceneContext.GetCharacterInfoById(_msg.obj_id); if (null != info && (_msg.obj_id == user.RoleId || info.OwnerId == user.RoleId)) { bool enableControl = false; if (_msg.is_skill) { SkillInfo skillInfo = info.GetSkillStateInfo().GetSkillInfoById(_msg.skill_or_impact_id); if (null != skillInfo) { enableControl = true; } } else { /*ImpactInfo impactInfo = info.GetSkillStateInfo().GetImpactInfoForCheck(_msg.skill_or_impact_id); * if (null != impactInfo) {*/ enableControl = true; //} } if (enableControl) { MovementStateInfo msi = info.GetMovementStateInfo(); bool isSkillMoving = msi.IsSkillMoving; msi.IsSkillMoving = true; if (_msg.obj_id == user.RoleId) { if (!isSkillMoving) { float x = _msg.cur_pos.x; float z = _msg.cur_pos.z; float velocity = (float)user.Info.GetActualProperty().MoveSpeed; if (!user.VerifyPosition(x, z, velocity, _msg.send_time, 4.0f)) { //todo:记录违规次数 } msi.SetPosition2D(x, z); user.SampleMoveData(x, z, velocity, msi.MoveDirCosAngle, msi.MoveDirSinAngle, _msg.send_time); } } //LogSys.Log(LOG_TYPE.WARN, "Msg_CRC_GfxControlMoveStartHandler, charactor {0} skill_or_impact_id {1} isskill {2}", _msg.obj_id, _msg.skill_or_impact_id, _msg.is_skill); } else { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStartHandler, charactor {0} skill_or_impact_id {1} isskill {2}, skill or impact not found", _msg.obj_id, _msg.skill_or_impact_id, _msg.is_skill); } } else { if (null == info) { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStartHandler, charactor {0} not exist", _msg.obj_id); } else { LogSys.Log(LOG_TYPE.ERROR, "Msg_CRC_GfxControlMoveStartHandler, charactor {0} or owner {1} not user {2}", info.GetId(), info.OwnerId, user.RoleId); } } } }
internal void Tick() { try { if (this.CurrentState != RoomState.Active && this.CurrentState != RoomState.Finish) { return; } long curTime = TimeUtility.GetServerMilliseconds(); if (m_LastLogTime + 60000 < curTime) { m_LastLogTime = curTime; LogSys.Log(LOG_TYPE.INFO, "Room.Tick {0}", RoomID); } if (this.CurrentState == RoomState.Active) { Scene scene = GetActiveScene(); if (null != scene) { scene.Tick(); scene.SightTick(); } disconnected_users_.Clear(); request_delete_users_.Clear(); foreach (User user in room_users_) { if (user != null) { user.Tick(); if (user.IsTimeout()) { if (user.UserControlState == (int)UserControlState.User) { disconnected_users_.Add(user); } else if (user.UserControlState == (int)UserControlState.Remove) { request_delete_users_.Add(user); } } } } foreach (User user in disconnected_users_) { DropUser(user); } foreach (User user in request_delete_users_) { RemoveUser(user); } //todo:观察者掉线处理 for (int i = 0; i < room_observers_.Length; ++i) { Observer observer = room_observers_[i]; if (!observer.IsIdle) { observer.Tick(); } } int userCount = GetActiveRoomUserCount(); if (userCount <= 0) { if (GetMinimizeElapsedDroppedTime() > c_finish_time_for_no_users_) { //若房间内玩家数目为0,结束战斗,关闭房间 EndBattle((int)CampIdEnum.Unkown); } } //每个Tick结束,将空间属性同步给Peer,用于Peer转发消息 foreach (User user in room_users_) { if (null != user && null != user.Info && null != user.Info.GetMovementStateInfo()) { RoomServer.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); } }