feat : 초기 존 진입 / 채널 나갈시 존에서도 나가게 구현

This commit is contained in:
qornwh1
2026-04-03 08:43:54 +09:00
parent 17ba88e841
commit 162d04d005
2 changed files with 27 additions and 8 deletions

View File

@@ -86,13 +86,16 @@ public class Channel : UserContainer
public override void RemoveUser(int userId)
{
base.RemoveUser(userId);
// 현재 맵에서도 제거
if (maps.TryGetValue(userId, out AMap? currentMap))
// 현재 맵에서 제거 (AMap.RemoveUser가 존까지 처리)
if (users.TryGetValue(userId, out Player? player))
{
currentMap.RemoveUser(userId);
if (maps.TryGetValue(player.CurrentMapId, out AMap? currentMap))
{
currentMap.RemoveUser(userId);
}
}
base.RemoveUser(userId);
connectPeers.Remove(userId);
}
@@ -110,12 +113,9 @@ public class Channel : UserContainer
oldMap.RemoveUser(userId);
}
// AMap.AddUser가 존 0 배치 + CurrentZoneId = 0 처리
newMap.AddUser(userId, player);
player.CurrentMapId = mapId;
player.CurrentZoneId = 0;
// 현재 맵에 0번 존에 추가
GetMap(mapId)?.GetZone(0)?.AddUser(player.PlayerId, player);
return true;
}

View File

@@ -63,6 +63,25 @@ public abstract class AMap : UserContainer
return (row >= 0 && row < Rows && col >= 0 && col < Cols) ? row * Cols + col : -1;
}
// 맵 입장 시 0번 존에 자동 배치
public override void AddUser(int userId, Player player)
{
base.AddUser(userId, player);
player.CurrentZoneId = 0;
GetZone(0)?.AddUser(userId, player);
}
// 맵 퇴장 시 현재 존에서 자동 제거
public override void RemoveUser(int userId)
{
if (users.TryGetValue(userId, out Player? player))
{
GetZone(player.CurrentZoneId)?.RemoveUser(userId);
}
base.RemoveUser(userId);
}
// 이동시 zone업데이트
public bool UpdatePlayerZone(int userId, Player player)
{