public void Remove(GameObject gameObject) { GameObjectType type = ObjectManager.GetObjectById(gameObject.Id); switch (type) { case GameObjectType.Player: Players.Remove((Player)gameObject); break; case GameObjectType.Monster: Monsters.Remove((Monster)gameObject); break; case GameObjectType.Projectile: Projectiles.Remove((Projectile)gameObject); break; } }
public void LeaveGame(int objectId) { GameObjectType type = ObjectManager.GetObjectById(objectId); Vector2Int cellPos; if (type == GameObjectType.Player) { Player player = null; if (_players.Remove(objectId, out player) == false) { return; } cellPos = player.CellPos; player.OnLeaveGame(); Map.ApplyLeave(player); player.Room = null; // 본인에게 정보 전송 { S_LeaveGame leavePacket = new S_LeaveGame(); player.Session.Send(leavePacket); } } else if (type == GameObjectType.Monster) { Monster monster = null; if (_monsters.Remove(objectId, out monster) == false) { return; } cellPos = monster.CellPos; Map.ApplyLeave(monster); monster.Room = null; } else if (type == GameObjectType.Projectile) { Projectile projectile = null; if (_projectiles.Remove(objectId, out projectile) == false) { return; } cellPos = projectile.CellPos; Map.ApplyLeave(projectile); projectile.Room = null; } else { return; } // 타인에게 정보 전송 { S_Despawn despawnPacket = new S_Despawn(); despawnPacket.ObjectIds.Add(objectId); Broadcast(cellPos, despawnPacket); } }
public void EnterGame(GameObject gameObject, bool randomPos) { if (gameObject == null) { return; } if (randomPos) { Vector2Int respawnPos; while (true) { respawnPos.x = _rand.Next(Map.MinX, Map.MaxX + 1); respawnPos.y = _rand.Next(Map.MinY, Map.MaxY + 1); if (Map.Find(respawnPos) == null) { gameObject.CellPos = respawnPos; break; } } } GameObjectType type = ObjectManager.GetObjectById(gameObject.Id); if (type == GameObjectType.Player) { Player player = gameObject as Player; _players.Add(gameObject.Id, player); player.Room = this; player.RefreshAdditionalStat(); if (player.Hp <= 0) { player.Hp = 1; } Map.ApplyMove(player, new Vector2Int(player.CellPos.x, player.CellPos.y)); GetZone(player.CellPos).Players.Add(player); // 본인에게 정보 전송 { S_EnterGame enterPacket = new S_EnterGame(); enterPacket.Player = player.Info; player.Session.Send(enterPacket); player.Vision.Update(); } } else if (type == GameObjectType.Monster) { Monster monster = gameObject as Monster; _monsters.Add(gameObject.Id, monster); monster.Room = this; Map.ApplyMove(monster, new Vector2Int(monster.CellPos.x, monster.CellPos.y)); GetZone(monster.CellPos).Monsters.Add(monster); monster.Update(); } else if (type == GameObjectType.Projectile) { Projectile projectile = gameObject as Projectile; _projectiles.Add(gameObject.Id, projectile); projectile.Room = this; GetZone(projectile.CellPos).Projectiles.Add(projectile); projectile.Update(); } // 타인에게 정보 전송 { S_Spawn spawnPacket = new S_Spawn(); spawnPacket.Objects.Add(gameObject.Info); Broadcast(gameObject.CellPos, spawnPacket); } }
public bool ApplyMove(GameObject gameObject, Vector2Int dest, bool checkObjects = true, bool collision = true) { if (gameObject.Room == null) { return(false); } if (gameObject.Room.Map != this) { return(false); } PositionInfo posInfo = gameObject.Info.PosInfo; if (CanGo(dest, checkObjects) == false) { return(false); } if (collision) { { int x = posInfo.PosX - MinX; int y = MaxY - posInfo.PosY; if (_objects[y, x] == gameObject) { _objects[y, x] = null; } } { int x = dest.x - MinX; int y = MaxY - dest.y; _objects[y, x] = gameObject; } } // Zone GameObjectType type = ObjectManager.GetObjectById(gameObject.Id); if (type == GameObjectType.Player) { Player player = (Player)gameObject; Zone now = gameObject.Room.GetZone(gameObject.CellPos); Zone after = gameObject.Room.GetZone(dest); if (now != after) { now.Players.Remove(player); after.Players.Add(player); } } else if (type == GameObjectType.Monster) { Monster monster = (Monster)gameObject; Zone now = gameObject.Room.GetZone(gameObject.CellPos); Zone after = gameObject.Room.GetZone(dest); if (now != after) { now.Monsters.Remove(monster); after.Monsters.Add(monster); } } else if (type == GameObjectType.Projectile) { Projectile projectile = (Projectile)gameObject; Zone now = gameObject.Room.GetZone(gameObject.CellPos); Zone after = gameObject.Room.GetZone(dest); if (now != after) { now.Projectiles.Remove(projectile); after.Projectiles.Add(projectile); } } // 실제 좌표 이동 posInfo.PosX = dest.x; posInfo.PosY = dest.y; return(true); }