public override void EnterState(GameLevel gameLevel) { gameLevel.DoForAllPlayers(player => { player.RemoveAllEffects(); player.SetGameMode(GameMode.Adventure); }); GameLevelInfo gameLevelInfo = gameLevel.GameLevelInfo; //Spawn Lobby NPC if (gameLevelInfo.LobbyNPCLocation == null) { gameLevelInfo.LobbyNPCLocation = new PlayerLocation(260.5, 15, 251.5); File.WriteAllText(GameController.GetGameLevelInfoLocation(gameLevel.GameType, gameLevel.LevelName), JsonConvert.SerializeObject(gameLevel.GameLevelInfo, Formatting.Indented)); SkyUtil.log($"LobbyNPCLocation Updated with default value for {gameLevel.LevelName}"); } _spawnedEntities = PlayerNPC.SpawnLobbyNPC(gameLevel, gameLevelInfo.GameType, gameLevel.GameLevelInfo.LobbyNPCLocation); gameLevel.AddPendingTask(() => { //Spawn Lobby Map/Image if (gameLevelInfo.LobbyMapLocation.Y < 0) //Default == -1 { gameLevelInfo.LobbyMapLocation = new BlockCoordinates(252, 15, 249); File.WriteAllText(GameController.GetGameLevelInfoLocation(gameLevel.GameType, gameLevel.LevelName), JsonConvert.SerializeObject(gameLevel.GameLevelInfo, Formatting.Indented)); } _spawnedEntities.AddRange(MapUtil.SpawnMapImage(@"C:\Users\Administrator\Desktop\dl\map-images\TestImage.png", 7, 4, gameLevel, gameLevelInfo.LobbyMapLocation)); }); }
public HubLevel(SkyCoreAPI plugin, string gameId, string levelPath, GameLevelInfo gameLevelInfo, bool modifiable = false) : base(plugin, "hub", gameId, levelPath, gameLevelInfo, modifiable) { AddPendingTask(() => { PlayerLocation portalInfoLocation = new PlayerLocation(256.5, 79.5, 276.5); const string hologramContent = " §d§lSkytonia§r §f§lNetwork§r" + "\n" + " §7Enter the portal and§r" + "\n" + "§7enjoy your adventure!§r" + "\n" + " §ewww.skytonia.com§r"; new Hologram(hologramContent, this, portalInfoLocation).SpawnEntity(); RunnableTask.RunTaskLater(() => { try { PlayerNPC.SpawnAllHubNPCs(this); //SpawnHubMaps(); } catch (Exception e) { BugSnagUtil.ReportBug(e, this); } }, 250); }); }
// public static void RegisterGameIntent(string gameName, bool spawnNPC = false) { bool npcOnly = false; //Some games may not be completed. Use an NPC as a placeholder if (spawnNPC) { string neatName = gameName; PlayerLocation npcLocation = new PlayerLocation(0.5D, 30D, 16.5D, 180F, 180F, 0F); switch (gameName) { case "murder": { neatName = "§c§lMurder Mystery"; npcLocation = new PlayerLocation(260.5, 77, 271.5, 180F, 180F, 0F); break; } case "build-battle": { neatName = "§e§lBuild Battle"; npcLocation = new PlayerLocation(252.5, 77, 271.5, 180F, 180F, 0F); break; } case "block-hunt": { neatName = PlayerNPC.ComingSoonName; npcLocation = new PlayerLocation(263.5, 77, 269.5, 180F, 180F, 0F); npcOnly = true; break; } case "bed-wars": { neatName = PlayerNPC.ComingSoonName; npcLocation = new PlayerLocation(249.5, 77, 269.5, 180F, 180F, 0F); npcOnly = true; break; } } if (!gameName.Equals("hub")) { try { PlayerNPC.SpawnHubNPC(null, neatName, npcLocation, $"GID:{gameName}"); } catch (Exception e) { Console.WriteLine(e); } } } { if (!GameRegistrations.ContainsKey(gameName)) { //Initialize GamePool GamePool gamePool = GetGamePool(gameName); if (npcOnly) { gamePool.Active = false; return; } } else { return; //Already listening, Don't start again. } } ISubscriber subscriber = RedisPool.GetSubscriber(); /* * Channel <game>_info * Format: * {ip-address}:{port}:{current-players}:{available-servers} */ subscriber.SubscribeAsync($"{GetDevelopmentPrefix()}{gameName}_info", (channel, message) => { try { string[] messageSplit = ((string)message).Split(':'); string hostAddress = messageSplit[0]; if (!ushort.TryParse(messageSplit[1], out ushort hostPort)) { SkyUtil.log($"Invalid format of port in message {message}"); return; } InstanceInfo instanceInfo; if (!GameRegistrations.TryGetValue(gameName, out var gamePool)) { string gameHostAddress = (hostAddress + ":" + hostPort).Equals(SkyCoreAPI.Instance.CurrentIp) ? "local" : hostAddress; instanceInfo = new InstanceInfo { HostAddress = gameHostAddress, HostPort = hostPort }; SkyUtil.log($"Game {gameName} missing from GameRegistrations! Re-Registering..."); RegisterGame(gameName, instanceInfo); } else { instanceInfo = (hostAddress + ":" + hostPort).Equals(SkyCoreAPI.Instance.CurrentIp) ? gamePool.GetLocalInstance() : gamePool.GetInstance(hostAddress + ":" + hostPort); } int.TryParse(messageSplit[2], out var instancePlayers); instanceInfo.CurrentPlayers = instancePlayers; instanceInfo.AvailableGames = PopulateGameList(messageSplit[3].Split('|'), new List <GameInfo>()); instanceInfo.Update(); //SkyUtil.log($"Updated {availableGames.Count} available games on {gameName} ({hostAddress + ":" + hostPort})"); } catch (Exception e) { BugSnagUtil.ReportBug(e); } }); }