public Game(IModHelper helper, ModConfig modConfig) { this.ModHelper = helper; this.modConfig = modConfig; Spawns.LoadSpawnLocations(helper); Chests.LoadChestsSpawns(helper); Storm.LoadStormData(helper); //Ban people from hiding in the elevator building. ModEntry.Events.Display.MenuChanged += (o, e) => { if (IsGameInProgress && e.NewMenu != null && e.NewMenu.GetType().Name == "ElevatorMenu") { e.NewMenu.exitThisMenu(false); } }; ModEntry.Events.GameLoop.UpdateTicked += (o, e) => { if (IsGameInProgress && Game1.IsServer && e.IsMultipleOf(8)) { Storm.QuarterSecUpdate(alivePlayers); } }; }
public void ServerStartGame() { if (IsGameInProgress) { Console.WriteLine("A game is already in progress!"); return; } IsGameInProgress = true; Console.WriteLine("Server start game"); NetworkUtility.SendChatMessageToAllPlayers("Game starting!"); //Wipe objects foreach (GameLocation location in Game1.locations) { location.Objects.Clear(); location.debris.Clear(); } Game1.MasterPlayer.Money = 0; //Spawn chests new Chests().SpawnAndFillChests(); #region Store tree locations or replant Random random = new Random(); if (trees.Count == 0) //Store info { foreach (GameLocation gameLocation in Game1.locations) { foreach (var pair in gameLocation.terrainFeatures.Pairs) { TerrainFeature feature = pair.Value; if (feature is Tree tree && tree.growthStage.Value >= 5) { Vector2 vector = pair.Key; trees.Add(new TileLocation(gameLocation.Name, (int)vector.X, (int)vector.Y)); } } } } else //Replant { //Delete all trees foreach (GameLocation gameLocation in Game1.locations) { List <Vector2> toRemove = new List <Vector2>(); foreach (Vector2 vector in gameLocation.terrainFeatures.Keys) { TerrainFeature feature = gameLocation.terrainFeatures[vector]; if (feature is Tree tree && tree.growthStage.Value >= 5) { toRemove.Add(vector); } } foreach (Vector2 vector in toRemove) { gameLocation.terrainFeatures.Remove(vector); } } //Replant foreach (TileLocation treeLocation in trees) { treeLocation.GetGameLocation().terrainFeatures.Remove(treeLocation.CreateVector2()); treeLocation.GetGameLocation().terrainFeatures.Add(treeLocation.CreateVector2(), new Tree(random.Next(1, 4), 100)); } } #endregion //Remove resource clumps (e.g. boulders) other than stumps and hollow logs var rc = Game1.getFarm().resourceClumps; foreach (var a in rc.Where(a => a.parentSheetIndex.Value != 600 || a.parentSheetIndex.Value != 602).ToList()) { rc.Remove(a); } //Remove small stones and weeds var farmObjects = Game1.getFarm().objects; var keys = farmObjects.Keys.ToList(); for (int i = 0; i < keys.Count(); i++) { var key0 = keys[i]; if (farmObjects[key0].name == "Stone" || farmObjects[key0].name == "Weeds") { farmObjects.Remove(key0); } } //Setup alive players alivePlayers.Clear(); foreach (Farmer player in Game1.getOnlineFarmers()) { if (player != null && !(player == Game1.player && !modConfig.ShouldHostParticipate)) { Console.WriteLine($"Adding {player.Name} to the game"); alivePlayers.Add(player.UniqueMultiplayerID); } } //Storm index int stormIndex = Storm.GetRandomStormIndex(); //Spawn players in & Tell the clients to start game var chosenSpawns = new Spawns().ScatterPlayers(Game1.getOnlineFarmers()); foreach (Farmer player in chosenSpawns.Keys) { if (player == Game1.player) { ClientStartGame(alivePlayers.Count, modConfig.ShouldHostParticipate, stormIndex); if (modConfig.ShouldHostParticipate) { NetworkUtility.WarpFarmer(player, chosenSpawns[player]); } else { player.warpFarmer(new TileLocation("Forest", 100, 20).CreateWarp()); } } else { NetworkUtility.BroadcastGameStartToClient(player, alivePlayers.Count, modConfig.ShouldHostParticipate, stormIndex); NetworkUtility.WarpFarmer(player, chosenSpawns[player]); } } //Remove horses/NPCs foreach (GameLocation loc in Game1.locations) { foreach (NPC horse in loc.characters.Where(x => ModEntry.Config.KillAllNPCs || x is StardewValley.Characters.Horse).ToList()) { loc.characters.Remove(horse); } } //Freeze time Game1.timeOfDay = 1400; FreezeTime.TimeFrozen = true; }