public void Leave(MapUnit mapUnit, bool isLeaveRoom) { if (!IsOnSameRoom(mapUnit)) { return; } mapUnit.SendChannel = null; var obj = OtherHelper.Search(PositionMambers, e => e.Uid == mapUnit.Uid); if (obj != null) { PositionMambers.Remove(mapUnit); } if (isLeaveRoom) { //如果MapUnit是離開Room,要告知MapUnitDestroy m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; SendMessage(m2C_MapUnitDestroy); } else { //如果MapUnit是離開Block,不就要告知觀看者MapUnitDestroy for (int i = 0; i < mapUnit.LookAtSources.Count; i++) { Unlook(mapUnit.LookAtSources[i]); } m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; SendMessage(m2C_MapUnitDestroy); } }
public void Leave(MapUnit mapUnit) { if (mapUnit != null && mapUnit.Block != null) { mapUnit.Block.Leave(mapUnit, true); } }
public void Add(MapUnit unit) { if (this.uidUnits.TryAdd(unit.Uid, unit)) { this.idUnits.Add(unit.Id, unit); } }
public void UnlookMapUnitBlockChannel() { if (LookAtTarget != null && LookAtTarget.SendChannel != null) { LookAtTarget.SendChannel.Unlook(this); } LookAtTarget = null; }
public void Unlook(MapUnit mapUnit) { var obj = OtherHelper.Search(ReceviceMambers, e => e.Uid == mapUnit.Uid); if (obj != null) { ReceviceMambers.Remove(mapUnit); } }
public void DestroyNPC() { if (_mapUnit != null) { Game.Scene.GetComponent <MapUnitComponent>().Remove(_mapUnit.Id); _mapUnit = null; _restAfterTime_ms = TimeHelper.NowAfterTimeSeconds(_data.RestTime); } }
public void CheckDistanceTravelledEnd() { if (MapUnit?.Info?.DistanceTravelled > DistanceTravelledEnd) { RefreshDistanceTravelledEnd(); MapUnit.TrySetStartTime(true); MapUnit.Info.DistanceTravelled = 0; } }
public void SendMessage(MapUnit sender, IActorMessage message) { if (sender == null) { Log.Error("SendMessage 失敗, sender為空"); return; } if (sender.SendChannel != null) { sender.SendChannel.SendMessage(message); } }
public bool AddMember(MapUnit mapUnit) { if (!MemberDataUidDict.ContainsKey(mapUnit.Uid)) { int newMemberIndex = -1; if (Data.IsReservation) { //預約有屬於每個玩家的固定位置 for (int i = 0; i < ReservationMembers.Count; i++) { if (ReservationMembers[i].Uid == mapUnit.Uid) { newMemberIndex = i; break; } } } else { for (int i = 0; i < MEMBER_MAX; i++) { if (MemberDatas[i] == null) { newMemberIndex = i; break; } } } if (newMemberIndex == -1) { Log.Error($"AddMember Failed, 超出最大人數!, Uid:{mapUnit.Uid}, RoomId:{RoomEntity.Id}"); return(false); } TeamMemberData memberData = new TeamMemberData() { MemberIndex = newMemberIndex, Uid = mapUnit.Uid, Name = mapUnit.Info.Name, Location = mapUnit.Info.Location, CharSetting = mapUnit.Info.CharSetting, }; MemberDataUidDict.Add(mapUnit.Uid, memberData); MemberDatas[newMemberIndex] = memberData; return(true); } return(false); }
public void Leave(MapUnit mapUnit, bool isLeaveRoom) { if (mapUnit == null) { Log.Error($"Block.Leave() Failed, mapUnit == null"); return; } mapUnit.Block = null; if (mapUnit.SendChannel?.Block == this) { mapUnit.SendChannel.Leave(mapUnit, isLeaveRoom); } }
public void Look(MapUnit mapUnit) { if (!IsOnSameRoom(mapUnit)) { return; } var obj = OtherHelper.Search(ReceviceMambers, e => e.Uid == mapUnit.Uid); if (obj == null) { ReceviceMambers.Add(mapUnit); } }
public void Enter(MapUnit mapUnit, double position, bool isPreEnter) { if (mapUnit == null) { Log.Error($"Block.Enter() Failed, mapUnit == null"); return; } //進入該Block if (!isPreEnter) { mapUnit.Block = this; } //判斷是否已有本Block的SendChannel if (mapUnit.SendChannel?.Block == this) { return; } //找尋還有空位的BlockChannel BlockChannel freeChannel = null; for (int i = 0; i < _blockChannels.Count; i++) { if (!_blockChannels[i].IsFullMember()) { freeChannel = _blockChannels[i]; break; } } //新開一個BlockChannel if (freeChannel == null) { freeChannel = new BlockChannel(this); freeChannel.Start(); _blockChannels.Add(freeChannel); } //進入 freeChannel.Enter(mapUnit, position); }
private static bool CheckMapUnitSenderVailed(MapUnit mapUnit, out long gateSessionActorId) { gateSessionActorId = 0; if (mapUnit == null) { return(false); } if (mapUnit.MapUnitType == MapUnitType.Npc) { return(false); } var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var player = playerSync.Get <Player>(mapUnit.Uid); if (player == null || !player.isOnline) { return(false); } var mapUnitGateComponent = mapUnit.GetComponent <MapUnitGateComponent>(); if (mapUnitGateComponent == null) { return(false); } if (mapUnitGateComponent.IsDisconnect) { return(false); } gateSessionActorId = mapUnitGateComponent.GateSessionActorId; if (gateSessionActorId == 0) { return(false); } return(true); }
public void Enter(MapUnit mapUnit, double position) { if (!IsOnSameRoom(mapUnit)) { return; } mapUnit.SendChannel = this; var obj = OtherHelper.Search(PositionMambers, e => e.Uid == mapUnit.Uid); if (obj == null) { PositionMambers.Add(mapUnit); } m2C_MapUnitCreate.MapUnitInfo = mapUnit.Info; SendMessage(m2C_MapUnitCreate); var lookAtSources = mapUnit.GetLookAtSources(); for (int i = 0; i < lookAtSources.Count; i++) { Look(lookAtSources[i]); } }
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 Release() { _roomNPCComponent = null; _data = null; _mapUnit = null; }
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); }
/// <summary> /// 判斷是否在同一個房間內? /// </summary> /// <param name="mapUnit"></param> /// <returns></returns> private bool IsOnSameRoom(MapUnit mapUnit) { return(Block.roomId != 0 && Block.roomId == mapUnit.RoomId); }
public void Enter(MapUnit mapUnit, double position) { ModifyPosition(mapUnit, 0); }