feat : 맵관리 코드 추가 작업
This commit is contained in:
@@ -1,27 +1,45 @@
|
||||
using LiteNetLib;
|
||||
using MMOserver.Game.Channel.Maps;
|
||||
using MMOserver.Game.Channel.Maps.InstanceDungeun;
|
||||
using MMOserver.Game.Party;
|
||||
|
||||
namespace MMOserver.Game.Channel;
|
||||
|
||||
public class Channel
|
||||
{
|
||||
// 로비
|
||||
private Robby robby = new Robby();
|
||||
|
||||
// 파티
|
||||
private PartyManager partyManager = new PartyManager();
|
||||
// 채널 내 유저 NetPeer (hashKey → NetPeer) — BroadcastToChannel 교차 조회 제거용
|
||||
private readonly Dictionary<int, NetPeer> connectPeers = new();
|
||||
|
||||
// 채널 내 유저 상태 (hashKey → Player)
|
||||
private Dictionary<int, Player> connectUsers = new Dictionary<int, Player>();
|
||||
private readonly Dictionary<int, Player> connectUsers = new();
|
||||
|
||||
// 채널 내 유저 NetPeer (hashKey → NetPeer) — BroadcastToChannel 교차 조회 제거용
|
||||
private Dictionary<int, NetPeer> connectPeers = new Dictionary<int, NetPeer>();
|
||||
// 채널 맵 관리
|
||||
private readonly Dictionary<int, AMap> maps = new();
|
||||
|
||||
// 파티
|
||||
private readonly PartyManager partyManager = new();
|
||||
|
||||
public Channel(int channelId)
|
||||
{
|
||||
ChannelId = channelId;
|
||||
|
||||
// 일단 하드코딩으로 맵 생성
|
||||
{
|
||||
// 로비
|
||||
maps.Add(1, new Robby(1));
|
||||
|
||||
// 인던
|
||||
int defaultValue = 10;
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
maps.Add(i + defaultValue, new BossInstance(i + defaultValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ChannelId
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public int UserCount
|
||||
@@ -36,25 +54,48 @@ public class Channel
|
||||
private set;
|
||||
} = 100;
|
||||
|
||||
public Channel(int channelId)
|
||||
{
|
||||
ChannelId = channelId;
|
||||
}
|
||||
|
||||
public void AddUser(int userId, Player player, NetPeer peer)
|
||||
{
|
||||
connectUsers[userId] = player;
|
||||
connectPeers[userId] = peer;
|
||||
UserCount++;
|
||||
|
||||
// 처음 접속 시 1번 맵(로비)으로 입장
|
||||
ChangeMap(userId, player, 1);
|
||||
}
|
||||
|
||||
public void RemoveUser(int userId)
|
||||
{
|
||||
// 현재 맵에서도 제거
|
||||
if (connectUsers.TryGetValue(userId, out Player? player))
|
||||
{
|
||||
maps[player.CurrentMapId].RemoveUser(userId);
|
||||
}
|
||||
|
||||
connectUsers.Remove(userId);
|
||||
connectPeers.Remove(userId);
|
||||
UserCount--;
|
||||
}
|
||||
|
||||
// 맵 이동 (현재 맵 제거 → 새 맵 추가 → CurrentMapId 갱신)
|
||||
public bool ChangeMap(int userId, Player player, int mapId)
|
||||
{
|
||||
if (!maps.TryGetValue(mapId, out AMap? newMap))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 기존 맵에서 제거
|
||||
if (maps.TryGetValue(player.CurrentMapId, out AMap? oldMap))
|
||||
{
|
||||
oldMap.RemoveUser(userId);
|
||||
}
|
||||
|
||||
newMap.AddUser(userId, player);
|
||||
player.CurrentMapId = mapId;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 재연결(WiFi→LTE 등) 시 동일 유저의 peer 교체
|
||||
public void UpdatePeer(int userId, NetPeer peer)
|
||||
{
|
||||
@@ -96,10 +137,18 @@ public class Channel
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 로비 가져옴
|
||||
public Robby GetRobby()
|
||||
// 맵들 가져옴
|
||||
public Dictionary<int, AMap> GetMaps()
|
||||
{
|
||||
return robby;
|
||||
return maps;
|
||||
}
|
||||
|
||||
// 맵 가져옴
|
||||
public AMap? GetMap(int mapId)
|
||||
{
|
||||
AMap? map = null;
|
||||
maps.TryGetValue(mapId, out map);
|
||||
return map;
|
||||
}
|
||||
|
||||
// 파티매니저 가져옴
|
||||
|
||||
Reference in New Issue
Block a user