public void HandleMove(Player player, C_Move movePacket) { if (player == null) { return; } // TODO : 검증 PositionInfo movePosInfo = movePacket.PosInfo; ObjectInfo info = player.Info; // 다른 좌표로 이동할 경우, 갈 수 있는지 체크 if (movePosInfo.PosX != info.PosInfo.PosX || movePosInfo.PosY != info.PosInfo.PosY) { if (Map.CanGo(new Vector2Int(movePosInfo.PosX, movePosInfo.PosY)) == false) { return; } } info.PosInfo.State = movePosInfo.State; info.PosInfo.MoveDir = movePosInfo.MoveDir; Map.ApplyMove(player, new Vector2Int(movePosInfo.PosX, movePosInfo.PosY)); // 다른 플레이어한테도 알려준다 S_Move resMovePacket = new S_Move(); resMovePacket.ObjectId = player.Info.ObjectId; resMovePacket.PosInfo = movePacket.PosInfo; Broadcast(player.CellPos, resMovePacket); }
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); } }