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.GetObjectTypeById(gameObject.Id); if (type == GameObjectType.Player) { Player player = gameObject as Player; _players.Add(gameObject.Id, player); player.Room = this; player.RefreshAdditionalStat(); 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; _monster.Add(gameObject.Id, monster); monster.Room = this; GetZone(monster.CellPos).Monsters.Add(monster); Map.ApplyMove(monster, new Vector2Int(monster.CellPos.x, monster.CellPos.y)); 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 void EnterGame(GameObject gameObject, bool randomPos = true) { if (gameObject == null) { return; } GameObjectType type = ObjectManager.GetObjectTypeById(gameObject.Id); if (randomPos) { Random _rand = new Random(); 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; } } } // 오브젝트 타입이 Player일때 if (type == GameObjectType.Player) { // 플레이어 룸 스폰 Player player = gameObject as Player; // 플레이어가 룸안에 들어옴 _players.Add(gameObject.Id, player); player.Room = this; player.RefreshAdditionalStat(); Map.ApplyMove(player, new Vector2Int(player.CellPos.x, player.CellPos.y)); GetZone(player.CellPos).Players.Add(player); // 클라이언트에게 Room 에서 처리하고 있는 맵을 로드하라! { S_ChangeMap changeMapPacket = new S_ChangeMap(); changeMapPacket.MapId = this.Map.MapID; player.Session.Send(changeMapPacket); } // 본인한테 Room 에 있던 player정보 전송 { S_EnterGame enterPacket = new S_EnterGame(); enterPacket.Player = player.Info; player.Session.Send(enterPacket); player.Vision.Update(); } } // 오브젝트 타입이 Monster else if (type == GameObjectType.Monster) { // 몬스터 룸 스폰 Monster monster = gameObject as Monster; _monsters.Add(gameObject.Id, monster); monster.Room = this; GetZone(monster.CellPos).Monsters.Add(monster); Map.ApplyMove(monster, new Vector2Int(monster.CellPos.x, monster.CellPos.y)); // 업데이트 한번실행 monster.Update(); } // 오브젝트 타입이 Projectile 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); } }