Example #1
0
	    protected GameController(SkyCoreAPI plugin, string gameName, string neatName, List<string> levelNames)
        {
            Plugin = plugin;
            
            GameName = neatName;
            RawName = gameName;
            
            foreach(var levelName in levelNames)
            {
                string fullLevelPath = $@"C:\Users\Administrator\Desktop\worlds\{gameName}\{levelName}";
	            if (!Directory.Exists(fullLevelPath))
	            {
					SkyUtil.log($"Unable to find world at ({fullLevelPath})");
				}
	            else
	            {
					LevelNames.Add(fullLevelPath);

		            SkyUtil.log($"Added world at ({fullLevelPath})");

					//Pre-load GameLevelInfo
		            GetGameLevelInfo(levelName);

					//Pre-cache the WorldProvider
		            AnvilProviderFactory.GetLevelProvider(plugin.Server.LevelManager, fullLevelPath);
	            }
            }

			if (LevelNames.Count == 0)
			{
				SkyUtil.log($"No Levels configured for {gameName}");
				return;
			}

			RedisGameIdKey = $"next_game_id_{GameName}";

	        ExternalGameHandler.RegisterInternalGame(RawName);

			GameTickThread = new Thread(() =>
	        {
		        Thread.CurrentThread.IsBackground = true;

		        GameTick = new HighPrecisionTimer(50, _CoreGameTick, true);
	        });
	        GameTickThread.Start();
		}
Example #2
0
	    public virtual GameLevel InstantQueuePlayer(SkyPlayer player, bool join = true)
	    {
		    if (player == null)
		    {
			    if (_isFirstLevelRetrieve)
			    {
				    _isFirstLevelRetrieve = false;

				    //Get Next. Should be used for join.
					return GameLevels.Values.GetEnumerator().Current; 
				}
			    
			    SkyUtil.log("Attempted to pass null SkyPlayer to InstantQueuePlayer. Bad Join?");
			    return null;
		    }
		    
			//SkyUtil.log($"Trying to add {player.Username} player to {GameLevels.Count} games");
		    lock (GameLevels)
		    {
			    foreach (GameLevel gameLevel in GetMostViableGames())
			    {
				    if (!gameLevel.CurrentState.CanAddPlayer(gameLevel))
				    {
					    continue;
				    }

				    if (join)
				    {
						//SkyUtil.log($"Adding {player.Username} to game {gameLevel.GameId}-({gameLevel.LevelId}-{gameLevel.LevelName})");
						gameLevel.AddPlayer(player);
					}

				    return gameLevel;
			    }

				//Player shouldn't be here if no games are accessible
			    ExternalGameHandler.AddPlayer(player, "hub");
			}

		    return null;
	    }
Example #3
0
        public static void ShowGameList(SkyPlayer player)
        {
            try
            {
                if (player == null || !player.IsConnected || player.KnownPosition == null)
                {
                    SkyUtil.log("Attempted to show GameList to a null player");
                    return;
                }

                var simpleForm = new SimpleForm
                {
                    Title   = "§lSkytonia Network",
                    Content = "",
                    Buttons = new List <Button>
                    {
                        new Button
                        {
                            Text  = $"§3§lNetwork Lobby\n{GetFormattedPlayerCount("hub")}",
                            Image = new Image
                            {
                                Type = "url",
                                Url  = "https://static.skytonia.com/dl/hubiconmenu.png"
                            },
                            ExecuteAction = delegate { ExternalGameHandler.AddPlayer(player, "hub"); }
                        },
                        new Button
                        {
                            Text  = $"§c§lMurder Mystery\n{GetFormattedPlayerCount("murder")}",
                            Image = new Image
                            {
                                Type = "url",
                                Url  = "https://static.skytonia.com/dl/murdericonmenu.png"
                            },
                            ExecuteAction = delegate { ExternalGameHandler.AddPlayer(player, "murder"); }
                        },
                        new Button
                        {
                            Text  = $"§6§l Build Battle\n{GetFormattedPlayerCount("build-battle")}",
                            Image = new Image
                            {
                                Type = "url",
                                Url  = "https://static.skytonia.com/dl/buildbattleiconmenu.png"
                            },
                            ExecuteAction = delegate { ExternalGameHandler.AddPlayer(player, "build-battle"); }
                        },
                        new Button
                        {
                            Text  = $"§d§lComing Soon...",
                            Image = new Image
                            {
                                Type = "url",
                                Url  = "https://static.skytonia.com/dl/comingsooniconmenu.png"
                            },
                            ExecuteAction = delegate {  }                             //Empty
                        }
                    }
                };

                player.SendForm(simpleForm);
            }
            catch (Exception e)
            {
                BugSnagUtil.ReportBug(e);
            }
        }