//广播自己位置 public void BroadcastSelfPostion(ObjCharacter _this) { if (!_this.mActive) { return; } if (null == _this.Zone) { return; } var msg = new SyncPostionMsg(); msg.ObjId = _this.ObjId; msg.Pos = new PositionData { Pos = new Vector2Int32 { x = Utility.MultiplyPrecision(_this.GetPosition().X), y = Utility.MultiplyPrecision(_this.GetPosition().Y) }, Dir = new Vector2Int32 { x = Utility.MultiplyPrecision(_this.GetDirection().X), y = Utility.MultiplyPrecision(_this.GetDirection().Y) } }; SceneServer.Instance.ServerControl.SyncStopMove(_this.EnumAllVisiblePlayerIdExclude(), msg); }
public void SyncStopMove(SyncPostionMsg msg) { if (msg == null) { Logger.Log2Bugly(" SyncPostionMsg msg =null"); return; } var character = ObjManager.Instance.FindCharacterById(msg.ObjId); if (null == character) { Logger.Warn("StopMove: obj[{0}]=null", msg.ObjId); return; } if (msg == null) { Logger.Log2Bugly(" SyncPostionMsg msg =null"); return; } if (msg.Pos == null || msg.Pos.Pos == null) { Logger.Log2Bugly(" msg.Pos || msg.Pos.Pos=null"); return; } var des = GameLogic.GetTerrainPosition(GameUtils.DividePrecision(msg.Pos.Pos.x), GameUtils.DividePrecision(msg.Pos.Pos.y)); var dir = new Vector3(GameUtils.DividePrecision(msg.Pos.Dir.x), 0, GameUtils.DividePrecision(msg.Pos.Dir.y)); var diff = (des.xz() - character.Position.xz()).magnitude; if (character.GetObjType() == OBJ.TYPE.MYPLAYER) { if (diff > 5) { character.StopMove(); character.Position = des; character.TargetDirection = dir; } } else { if (GameSetting.Instance == null) { Logger.Log2Bugly(" GameSetting.Instance =null"); return; } var errorDis = character.GetObjType() == OBJ.TYPE.OTHERPLAYER ? GameSetting.Instance.OtherPlayerStopPosErrorDistance : GameSetting.Instance.NPCStopPosErrorDistance; if (character.GetObjType() == OBJ.TYPE.NPC && diff < 0.8f) { character.StopMove(); character.TargetDirection = dir; } else if (diff < errorDis) { character.MoveTo(des); } else { character.StopMove(); character.Position = des; character.TargetDirection = dir; Logger.Warn("Foce StopMove:" + des.x + " " + des.z); } if (character.GetObjType() == OBJ.TYPE.NPC) { (character as ObjNPC).DelayedMove = null; } } //Logger.Info("SyncStopMove Obj[{0}] pos[{1},{2}]", msg.ObjId, des.x, des.z); }