public void SendMessage(IActorMessage message) { // EthanDebug //if(message is M2C_MapUnitCreate m2C_MapUnitCreate) //{ // for(int i = 0; i < ReceviceMambers.Count; i++) // { // m2C_MapUnitCreate.MapUnitInfo.DebugId = IdGenerater.GenerateId(); // var rev = ReceviceMambers[i]; // BsonDocument doc = new BsonDocument // { // { "Block.room.Id" , Block?.room?.Id }, // { "Block.roomId" , Block?.roomId }, // { "Block.blockId" , Block?.blockId }, // { "rev.Id" , rev?.Id }, // { "rev.MapAppId" , IdGenerater.GetAppId(rev == null ? 0 : rev.Id) }, // { "rev.Uid" , rev?.Uid }, // { "rev.RoomId" , rev?.RoomId }, // { "rev.Room.Id" , rev?.Room?.Id }, // { "rev.Block.room.Id" , rev?.Block?.room?.Id }, // { "rev.Block.roomId" , rev?.Block?.roomId }, // { "rev.Block.blockId" , rev?.Block?.blockId }, // { "sendToList", ReceviceMambers.Select(e => $"MapUnitId:{e.Id}, Uid:{e.Uid}, BlockId:{e.Block?.blockId}").ToJson() } // }; // Log.Trace($"DebugId[{m2C_MapUnitCreate.MapUnitInfo.DebugId}]> {doc.ToJson()}"); // } //} MapMessageHelper.BroadcastTarget(message, ReceviceMambers); }
public void ModifyPosition(MapUnit mapUnit, double position) { position %= _roadDistance_m; bool IsInside = mapUnit.Block != null && mapUnit.Block.IsInside(position); if (!IsInside) { BlockChannel oldBlockChannel = null; BlockChannel newBlockChannel = null; //離開舊的Block if (mapUnit.Block != null) { oldBlockChannel = mapUnit.SendChannel; mapUnit.Block.Leave(mapUnit, false); } //加入新的Block for (int i = 0; i < _blocks.Count; i++) { if (_blocks[i].IsInside(position)) { _blocks[i].Enter(mapUnit, position, false); break; } } newBlockChannel = mapUnit.SendChannel; //清空舊的資料 _m2C_MapUnitCreateAndDestroy.CreateMapUnitInfos.Clear(); _m2C_MapUnitCreateAndDestroy.DestroyMapUnitIds.Clear(); //取得觀看的BlockChannel資訊 for (int i = 0; i < newBlockChannel.PositionMambers.Count; i++) { var rev = newBlockChannel.PositionMambers[i]; var info = rev.Info; //info.DebugId = IdGenerater.GenerateId(); //var list = mapUnit.GetLookAtSources(); //BsonDocument doc = new BsonDocument //{ // { "rev.Id" , rev?.Id }, // { "rev.MapAppId" , IdGenerater.GetAppId(rev == null ? 0 : rev.Id) }, // { "rev.Uid" , rev?.Uid }, // { "rev.RoomId" , rev?.RoomId }, // { "rev.Room.Id" , rev?.Room?.Id }, // { "rev.Block.room.Id" , rev?.Block?.room?.Id }, // { "rev.Block.roomId" , rev?.Block?.roomId }, // { "rev.Block.blockId" , rev?.Block?.blockId }, // { "sendToList", list.Select(e => $"MapUnitId:{e.Id}, Uid:{e.Uid}, BlockId:{e.Block?.blockId}").ToJson() } //}; //Log.Trace($"DebugId[{info.DebugId}]> {doc.ToJson()}"); _m2C_MapUnitCreateAndDestroy.CreateMapUnitInfos.Add(info); } //移除取消觀看的BlockChannel資訊 for (int i = 0; i < oldBlockChannel?.PositionMambers?.Count; i++) { if (_m2C_MapUnitCreateAndDestroy.CreateMapUnitInfos.Contains(oldBlockChannel.PositionMambers[i].Info)) { continue; } _m2C_MapUnitCreateAndDestroy.DestroyMapUnitIds.Add(oldBlockChannel.PositionMambers[i].Id); } MapMessageHelper.BroadcastTarget(_m2C_MapUnitCreateAndDestroy, mapUnit.GetLookAtSources()); } //更新MapUnit _m2C_MapUnitUpdate.MapUnitId = mapUnit.Id; _m2C_MapUnitUpdate.DistanceTravelledTarget = mapUnit.Info.DistanceTravelled; _m2C_MapUnitUpdate.SpeedMS = mapUnit.Info.SpeedMS; _m2C_MapUnitUpdate.DistanceTravelledUpdateUTCTick = System.DateTime.UtcNow.Ticks; SendMessage(mapUnit, _m2C_MapUnitUpdate); }
public void LookMapUnitBlockChannel(MapUnit target) { if (target == null) { Log.Error($"觀看對象不存在, SelfUid:{Uid}"); return; } if (target.SendChannel == null) { return; } if (target == LookAtTarget) { return; } if (RoomId == 0 || RoomId != target.RoomId) { return; } BlockChannel oldBlockChannel = null; BlockChannel newBlockChannel = null; _m2C_MapUnitCreateAndDestroy.CreateMapUnitInfos.Clear(); _m2C_MapUnitCreateAndDestroy.DestroyMapUnitIds.Clear(); //取消觀看舊的BlockChannel if (LookAtTarget != null && LookAtTarget.SendChannel != null) { LookAtTarget.SendChannel.Unlook(this); if (LookAtTarget.LookAtSources.Contains(this)) { LookAtTarget.LookAtSources.Remove(this); } oldBlockChannel = LookAtTarget.SendChannel; } //觀看新的BlockChannel target.SendChannel.Look(this); LookAtTarget = target; if (!LookAtTarget.LookAtSources.Contains(this)) { LookAtTarget.LookAtSources.Add(this); } newBlockChannel = target.SendChannel; //清空舊的資料 _m2C_MapUnitCreateAndDestroy.CreateMapUnitInfos.Clear(); _m2C_MapUnitCreateAndDestroy.DestroyMapUnitIds.Clear(); //取得觀看的BlockChannel資訊 for (int i = 0; i < newBlockChannel.PositionMambers.Count; i++) { var rev = newBlockChannel.PositionMambers[i]; var info = rev.Info; //info.DebugId = IdGenerater.GenerateId(); //BsonDocument doc = new BsonDocument //{ // { "Block.room.Id" , Block?.room?.Id }, // { "Block.roomId" , Block?.roomId }, // { "Block.blockId" , Block?.blockId }, // { "rev.Id" , rev?.Id }, // { "rev.MapAppId" , IdGenerater.GetAppId(rev == null ? 0 : rev.Id) }, // { "rev.Uid" , rev?.Uid }, // { "rev.RoomId" , rev?.RoomId }, // { "rev.Room.Id" , rev?.Room?.Id }, // { "rev.Block.room.Id" , rev?.Block?.room?.Id }, // { "rev.Block.roomId" , rev?.Block?.roomId }, // { "rev.Block.blockId" , rev?.Block?.blockId }, // { "sendToList", $"MapUnitId:{this.Id}, Uid:{this.Uid}, BlockId:{this.Block?.blockId}" } //}; //Log.Trace($"DebugId[{info.DebugId}]> {doc.ToJson()}"); _m2C_MapUnitCreateAndDestroy.CreateMapUnitInfos.Add(info); } // 移除取消觀看的BlockChannel資訊 for (int i = 0; i < oldBlockChannel?.PositionMambers?.Count; i++) { if (_m2C_MapUnitCreateAndDestroy.CreateMapUnitInfos.Contains(oldBlockChannel.PositionMambers[i].Info)) { continue; } _m2C_MapUnitCreateAndDestroy.DestroyMapUnitIds.Add(oldBlockChannel.PositionMambers[i].Id); } MapMessageHelper.BroadcastTarget(_m2C_MapUnitCreateAndDestroy, this); }