public DeepWoodsExit(DeepWoods myDeepWoods, ExitDirection exitDir, Location location) { this.InitNetFields(); this.myDeepWoodsName.Value = myDeepWoods.Name; this.exitDir.Value = (int)exitDir; this.location.Value = new Point(location.X, location.Y); }
public static void Update(DeepWoods deepWoods, GameTime time) { if (deepWoods.baubles != null) { for (int index = 0; index < deepWoods.baubles.Count; ++index) { Vector2 vector2 = new Vector2(); ref Vector2 local = ref vector2; double num1 = deepWoods.baubles[index].X - Math.Max(0.4f, Math.Min(1f, index * 0.01f)); double num2 = index * 0.00999999977648258; double num3 = 2.0 * Math.PI; TimeSpan timeSpan = time.TotalGameTime; double milliseconds = timeSpan.Milliseconds; double num4 = Math.Sin(num3 * milliseconds / 8000.0); double num5 = num2 * num4; double num6 = num1 - num5; local.X = (float)num6; vector2.Y = deepWoods.baubles[index].Y + Math.Max(0.5f, Math.Min(1.2f, index * 0.02f)); if (vector2.Y > deepWoods.map.DisplayHeight || vector2.X < 0) { vector2.X = (float)Game1.random.Next(0, deepWoods.map.DisplayWidth); vector2.Y = -64f; } deepWoods.baubles[index] = vector2; } }
public static void RemoveDeepWoodsFromGameLocations(DeepWoods deepWoods) { // Player might be in this level, teleport them out if (Game1.player.currentLocation == deepWoods) { Game1.warpFarmer(Game1.getLocationRequest("Woods", false), WOODS_WARP_LOCATION.X, WOODS_WARP_LOCATION.Y, 0); // Take away all health and energy to avoid cheaters using Save Anywhere to escape getting lost if (deepWoods.level.Value > 1 && deepWoods.IsLost) { Game1.player.health = 1; Game1.player.Stamina = 0; } Game1.player.currentLocation = Game1.getLocationFromName("Woods"); Game1.player.Position = new Vector2(WOODS_WARP_LOCATION.X * 64, WOODS_WARP_LOCATION.Y * 64); } Game1.locations.Remove(deepWoods); Game1.removeLocationFromLocationLookup(deepWoods); if (Game1.IsMasterGame) { foreach (Farmer who in Game1.otherFarmers.Values) { if (who != Game1.player) { ModEntry.SendMessage(deepWoods.Name, MessageId.RemoveLocation, who.UniqueMultiplayerID); } } } }
public static void Remove() { if (!Game1.IsMasterGame) { return; } if (Game1.getLocationFromName("DeepWoods") is DeepWoods rootDeepWoods) { DeepWoodsManager.rootDeepWoodsBackup = rootDeepWoods; } List <DeepWoods> toBeRemoved = new List <DeepWoods>(); foreach (var location in Game1.locations) { if (location is DeepWoods deepWoods) { toBeRemoved.Add(deepWoods); } } foreach (var deepWoods in toBeRemoved) { DeepWoodsManager.RemoveDeepWoodsFromGameLocations(deepWoods); } }
private void SpawnFoodItems(DeepWoods deepWoods, Tool t, int x, int y) { for (int i = 0, n = Game1.random.Next(1, 4); i < n; i++) { SpawnFoodItem(deepWoods, t, x, y); } }
public void ValidateAndIfNecessaryCreateExitChildren() { if (!Game1.IsMasterGame) { return; } if (this.playerCount.Value <= 0) { return; } if (this.level.Value > 1 && this.Parent == null && !this.HasExit(CastEnterDirToExitDir(this.EnterDir))) { // this.abandonedByParentTime = Game1.timeOfDay; this.exits.Add(new DeepWoodsExit(this, CastEnterDirToExitDir(this.EnterDir), this.EnterLocation)); } foreach (var exit in this.exits) { DeepWoods exitDeepWoods = Game1.getLocationFromName(exit.TargetLocationName) as DeepWoods; if (exitDeepWoods == null) { exitDeepWoods = new DeepWoods(this, this.level.Value + 1, ExitDirToEnterDir(exit.ExitDir)); DeepWoodsManager.AddDeepWoodsToGameLocations(exitDeepWoods); } exit.TargetLocationName = exitDeepWoods.Name; exit.TargetLocation = exitDeepWoods.EnterLocation; } }
public static void RemoveDeepWoodsFromGameLocations(DeepWoods deepWoods) { // Player might be in this level, teleport them out if (Game1.player.currentLocation == deepWoods) { Game1.warpFarmer(Game1.getLocationRequest("Woods", false), WOODS_WARP_LOCATION.X, WOODS_WARP_LOCATION.Y, 0); // Take away all health and energy to avoid cheaters using Save Anywhere to escape getting lost if (deepWoods.level > 1 && deepWoods.IsLost) { Game1.player.health = 1; Game1.player.Stamina = 0; } Game1.player.currentLocation = Game1.getLocationFromName("Woods"); Game1.player.Position = new Vector2(WOODS_WARP_LOCATION.X * 64, WOODS_WARP_LOCATION.Y * 64); } Game1.locations.Remove(deepWoods); if (Game1.IsMasterGame) { foreach (Farmer who in Game1.otherFarmers.Values) { if (who != Game1.player) { who.queueMessage(Settings.Network.DeepWoodsMessageId, Game1.MasterPlayer, new object[] { NETWORK_MESSAGE_DEEPWOODS_ADDREMOVE, (byte)0, deepWoods.Name }); } } } }
private int GetRandomFoodType(DeepWoods deepWoods) { if (random == null) { random = new DeepWoodsRandom(deepWoods, (deepWoods?.Seed ?? Game1.random.Next()) ^ Game1.currentGameTime.TotalGameTime.Milliseconds ^ (int)this.tile.X ^ (int)this.tile.Y); } return(random.GetRandomValue(Settings.Objects.GingerBreadHouse.FootItems)); }
public DeepWoodsRandom(DeepWoods deepWoods, int seed) { this.deepWoods = deepWoods; this.seed = seed; this.random = new Random(this.seed); this.masterRandom = new Random(this.seed ^ Game1.random.Next()); // this.masterModeCounter = 0; }
public DeepWoods(DeepWoods parent, int level, EnterDirection enterDir) : this() { base.isOutdoors.Value = true; base.ignoreDebrisWeather.Value = true; base.ignoreOutdoorLighting.Value = true; this.hasReceivedNetworkData.Value = true; this.uniqueMultiplayerID.Value = Game1.MasterPlayer.UniqueMultiplayerID; this.seed = DeepWoodsRandom.CalculateSeed(level, enterDir, parent?.Seed); if (level == 1) { base.name.Value = "DeepWoods"; } else { base.name.Value = "DeepWoods_" + this.seed; } this.parentName.Value = parent?.Name; this.ParentExitLocation = parent?.GetExit(EnterDirToExitDir(enterDir))?.Location ?? new Location(); this.level.Value = level; DeepWoodsState.LowestLevelReached = Math.Max(DeepWoodsState.LowestLevelReached, this.level.Value - 1); this.EnterDir = enterDir; this.spawnTime.Value = Game1.timeOfDay; this.spawnedFromObelisk.Value = parent?.spawnedFromObelisk?.Value ?? false; ModEntry.GetAPI().CallOnCreate(this); CreateSpace(); DetermineExits(); updateMap(); ModEntry.GetAPI().CallBeforeFill(this); if ((this.isLichtung.Value && this.lichtungHasLake.Value) || !ModEntry.GetAPI().CallOverrideFill(this)) { DeepWoodsStuffCreator.AddStuff(this, new DeepWoodsRandom(this, this.seed ^ Game1.currentGameTime.TotalGameTime.Milliseconds ^ Game1.random.Next())); } ModEntry.GetAPI().CallAfterFill(this); ModEntry.GetAPI().CallBeforeMonsterGeneration(this); if (!ModEntry.GetAPI().CallOverrideMonsterGeneration(this)) { DeepWoodsMonsters.AddMonsters(this, new DeepWoodsRandom(this, this.seed ^ Game1.currentGameTime.TotalGameTime.Milliseconds ^ Game1.random.Next())); } ModEntry.GetAPI().CallAfterMonsterGeneration(this); if (parent == null && level > 1 && !this.HasExit(CastEnterDirToExitDir(this.EnterDir))) { this.exits.Add(new DeepWoodsExit(this, CastEnterDirToExitDir(this.EnterDir), this.EnterLocation)); } if (parent != null) { ModEntry.Log($"Child spawned, time: {Game1.timeOfDay}, name: {this.Name}, level: {this.level}, parent: {this.parentName}, enterDir: {this.EnterDir}, enterLocation: {this.EnterLocation.X}, {this.EnterLocation.Y}", LogLevel.Trace); } }
// Called whenever a player warps, both from and to may be null public static void PlayerWarped(Farmer who, GameLocation rawFrom, GameLocation rawTo) { DeepWoods from = rawFrom as DeepWoods; DeepWoods to = rawTo as DeepWoods; if (from != null && to != null && from.Name == to.Name) { return; } ModEntry.Log("PlayerWarped from: " + rawFrom?.Name + ", to: " + rawTo?.Name, LogLevel.Trace); from?.RemovePlayer(who); to?.AddPlayer(who); if (from != null && to == null) { // We left the deepwoods, fix lighting DeepWoodsManager.FixLighting(); // Stop music Game1.changeMusicTrack("none"); Game1.updateMusic(); // Workaround for bug where players are warped to [0,0] for some reason if (rawTo is Woods && who == Game1.player) { who.Position = new Vector2(WOODS_WARP_LOCATION.X * 64, WOODS_WARP_LOCATION.Y * 64); } } if (who == Game1.player && from != null && to != null && from.Parent == null && to.Parent == from && !lostMessageDisplayedToday && !to.spawnedFromObelisk.Value && ExitDirToEnterDir(CastEnterDirToExitDir(from.EnterDir)) == to.EnterDir) { Game1.addHUDMessage(new HUDMessage(I18N.LostMessage) { noIcon = true }); lostMessageDisplayedToday = true; } if (who == Game1.player && to != null && to.level.Value >= Settings.Level.MinLevelForWoodsObelisk && !Game1.player.hasOrWillReceiveMail(WOODS_OBELISK_WIZARD_MAIL_ID) && (Game1.player.mailReceived.Contains("hasPickedUpMagicInk") || Game1.player.hasMagicInk)) { Game1.addMailForTomorrow(WOODS_OBELISK_WIZARD_MAIL_ID); } }
private void SpawnFoodItem(DeepWoods deepWoods, Tool t, int x, int y) { if (Game1.IsMultiplayer) { Game1.createMultipleObjectDebris(GetRandomFoodType(deepWoods), x, y, 1, t.getLastFarmerToUse().UniqueMultiplayerID); } else { Game1.createMultipleObjectDebris(GetRandomFoodType(deepWoods), x, y, 1); } }
public static void AddExitLocation(DeepWoods deepWoods, Location tile, DeepWoodsExit exit) { if (!Game1.IsMasterGame) { return; } if (deepWoods == null) { return; } deepWoods.AddExitLocation(tile, exit); }
public static void RemoveExitLocation(DeepWoods deepWoods, Location tile) { if (!Game1.IsMasterGame) { return; } if (deepWoods == null) { return; } deepWoods.RemoveExitLocation(tile); }
public static void Restore() { if (!Game1.IsMasterGame) { return; } if (DeepWoodsManager.rootDeepWoodsBackup != null) { DeepWoodsManager.AddDeepWoodsToGameLocations(DeepWoodsManager.rootDeepWoodsBackup); } DeepWoodsManager.rootDeepWoodsBackup = null; CheckValid(); }
// This is called by every client at the start of a new day public static void LocalDayUpdate(int dayOfMonth) { DeepWoodsManager.currentDeepWoods = null; DeepWoodsManager.currentWarpRequestName = null; DeepWoodsManager.currentWarpRequestLocation = null; lostMessageDisplayedToday = false; if (Game1.IsMasterGame) { nextRandomizeTime = 0; Remove(); Restore(); } }
private static int GetLeafType(DeepWoods deepWoods) { if (deepWoods.isLichtung.Value) { return(WeatherDebris.pinkPetals); } else if (Game1.currentSeason == "fall") { return(WeatherDebris.fallLeaves); } else { return(WeatherDebris.greenLeaves); } }
public static void Initialize(DeepWoods deepWoods) { Clear(deepWoods); if (!Game1.isRaining) { int mapWidth = deepWoods.mapWidth.Value; int mapHeight = deepWoods.mapHeight.Value; int numBaubles = (mapWidth * mapHeight) / MINIMUM_TILES_FOR_BAUBLE; for (int index = 0; index < numBaubles; ++index) { deepWoods.baubles.Add(new Vector2(Game1.random.Next(0, mapWidth * 64), Game1.random.Next(0, mapHeight * 64))); } if (Game1.currentSeason != "winter" && !deepWoods.isLichtung.Value) { int numWeatherDebris = (mapWidth * mapHeight) / MINIMUM_TILES_FOR_LEAVES; for (int index = 0; index < numWeatherDebris; ++index) { Vector2 v = new Vector2(Game1.random.Next(0, mapWidth * 64), Game1.random.Next(0, mapHeight * 64)); deepWoods.weatherDebris.Add(new WeatherDebris(v, GetLeaveType(deepWoods), Game1.random.Next(15) / 500f, Game1.random.Next(-10, 0) / 50f, Game1.random.Next(10) / 50f)); } /* * int maxValue = 192; * for (int index = 0; index < numWeatherDebris; ++index) * { * Viewport viewport = Game1.graphics.GraphicsDevice.Viewport; * * float x = (index * maxValue % viewport.Width + Game1.random.Next(maxValue)); * * float y = (index * maxValue / viewport.Width * maxValue + Game1.random.Next(maxValue)); * * WeatherDebris weatherDebris = new WeatherDebris(new Vector2(x, y), 1, Game1.random.Next(15) / 500f, Game1.random.Next(-10, 0) / 50f, Game1.random.Next(10) / 50f); * deepWoods.weatherDebris.Add(weatherDebris); * } */ } } }
public static void AddDeepWoodsToGameLocations(DeepWoods deepWoods) { if (deepWoods == null) { return; } Game1.locations.Add(deepWoods); if (Game1.IsMasterGame) { foreach (Farmer who in Game1.otherFarmers.Values) { if (who != Game1.player) { who.queueMessage(Settings.Network.DeepWoodsMessageId, Game1.MasterPlayer, new object[] { NETWORK_MESSAGE_DEEPWOODS_ADDREMOVE, (byte)1, deepWoods.Name }); } } } }
public static void AddDeepWoodsToGameLocations(DeepWoods deepWoods) { if (deepWoods == null) { return; } Game1.locations.Add(deepWoods); if (Game1.IsMasterGame) { foreach (Farmer who in Game1.otherFarmers.Values) { if (who != Game1.player) { ModEntry.SendMessage(deepWoods.Name, MessageId.AddLocation, who.UniqueMultiplayerID); } } } }
public static void WarpFarmerIntoDeepWoods(DeepWoods deepWoods) { if (deepWoods == null) { return; } Game1.player.FacingDirection = DeepWoodsEnterExit.EnterDirToFacingDirection(deepWoods.EnterDir); if (deepWoods.EnterDir == EnterDirection.FROM_TOP) { Game1.warpFarmer(deepWoods.Name, deepWoods.enterLocation.X, deepWoods.enterLocation.Y + 1, false); } else if (deepWoods.EnterDir == EnterDirection.FROM_RIGHT) { Game1.warpFarmer(deepWoods.Name, deepWoods.enterLocation.X + 1, deepWoods.enterLocation.Y, false); } else { Game1.warpFarmer(deepWoods.Name, deepWoods.enterLocation.X, deepWoods.enterLocation.Y, false); } }
public static DeepWoods AddDeepWoodsFromObelisk(int level) { if (!Game1.IsMasterGame) { throw new ApplicationException("Illegal call to DeepWoodsManager.AddDeepWoodsFromObelisk in client."); } // First check if a level already exists and use that. foreach (GameLocation gameLocation in Game1.locations) { if (gameLocation is DeepWoods && (gameLocation as DeepWoods).level.Value == level) { return(gameLocation as DeepWoods); } } // Otherwise create a new level. DeepWoods deepWoods = new DeepWoods(level); DeepWoodsManager.AddDeepWoodsToGameLocations(deepWoods); return(deepWoods); }
public static void Initialize(DeepWoods deepWoods) { Clear(deepWoods); if (!Game1.isRaining) { int mapWidth = deepWoods.mapWidth.Value; int mapHeight = deepWoods.mapHeight.Value; if (DeepWoodsSettings.Settings.Performance.BaubleDensity > 0) { int numBaubles = (mapWidth * mapHeight) / MINIMUM_TILES_FOR_BAUBLE; if (DeepWoodsSettings.Settings.Performance.BaubleDensity < 100) { numBaubles = (int)(numBaubles * DeepWoodsSettings.Settings.Performance.BaubleDensity / 100); } for (int index = 0; index < numBaubles; ++index) { deepWoods.baubles.Add(new Vector2(Game1.random.Next(0, mapWidth * 64), Game1.random.Next(0, mapHeight * 64))); } } if (Game1.currentSeason != "winter" && !deepWoods.isLichtung.Value && DeepWoodsSettings.Settings.Performance.LeafDensity > 0) { int numWeatherDebris = (mapWidth * mapHeight) / MINIMUM_TILES_FOR_LEAVES; if (DeepWoodsSettings.Settings.Performance.LeafDensity < 100) { numWeatherDebris = (int)(numWeatherDebris * DeepWoodsSettings.Settings.Performance.LeafDensity / 100); } for (int index = 0; index < numWeatherDebris; ++index) { Vector2 v = new Vector2(Game1.random.Next(0, mapWidth * 64), Game1.random.Next(0, mapHeight * 64)); deepWoods.weatherDebris.Add(new WeatherDebris(v, GetLeafType(deepWoods), Game1.random.Next(15) / 500f, Game1.random.Next(-10, 0) / 50f, Game1.random.Next(10) / 50f)); } } } }
public static void AddMonsters(DeepWoods deepWoods, DeepWoodsRandom random) { new DeepWoodsMonsters(deepWoods, random).AddMonsters(); }
private DeepWoodsMonsters(DeepWoods deepWoods, DeepWoodsRandom random) { this.deepWoods = deepWoods; this.random = random; }
public static void Clear(DeepWoods deepWoods) { deepWoods.baubles = new List <Vector2>(); deepWoods.weatherDebris = new List <WeatherDebris>(); }
private int GetDamage(DeepWoods deepWoods) { int level = deepWoods?.level.Value ?? 1; return((1 + level / 10) * Settings.Objects.Bush.ThornyBushDamagePerLevel); }
private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e) { if (e.FromModID != this.ModManifest.UniqueID) { return; } ModEntry.Log($"[{(Context.IsMainPlayer ? "host" : "farmhand")}] Received {e.Type} from {e.FromPlayerID}.", LogLevel.Trace); switch (e.Type) { // farmhand requested metadata case MessageId.RequestMetadata: if (Context.IsMainPlayer) { // client requests settings and state, send it: InitResponseMessage response = new InitResponseMessage { Settings = DeepWoodsSettings.Settings, State = DeepWoodsSettings.DeepWoodsState, LevelNames = Game1.locations.OfType <DeepWoods>().Select(p => p.Name).ToArray() }; ModEntry.SendMessage(response, MessageId.Metadata, e.FromPlayerID); } break; // host sent metadata case MessageId.Metadata: if (!Context.IsMainPlayer) { InitResponseMessage response = e.ReadAs <InitResponseMessage>(); DeepWoodsSettings.Settings = response.Settings; DeepWoodsSettings.DeepWoodsState = response.State; ModEntry.DeepWoodsInitServerAnswerReceived(response.LevelNames); } break; // farmhand requested that we load and activate a DeepWoods level case MessageId.RequestWarp: if (Context.IsMainPlayer) { // load level int level = e.ReadAs <int>(); DeepWoods deepWoods = DeepWoodsManager.AddDeepWoodsFromObelisk(level); // send response WarpMessage response = new WarpMessage { Level = deepWoods.Level, Name = deepWoods.Name, EnterLocation = new Vector2(deepWoods.enterLocation.Value.X, deepWoods.enterLocation.Value.Y) }; ModEntry.SendMessage(response, MessageId.Warp, e.FromPlayerID); } break; // host loaded area for warp case MessageId.Warp: if (!Context.IsMainPlayer) { WarpMessage data = e.ReadAs <WarpMessage>(); DeepWoodsManager.AddBlankDeepWoodsToGameLocations(data.Name); DeepWoodsManager.WarpFarmerIntoDeepWoodsFromServerObelisk(data.Name, data.EnterLocation); } break; // host sent 'lowest level reached' update case MessageId.SetLowestLevelReached: if (!Context.IsMainPlayer) { DeepWoodsState.LowestLevelReached = e.ReadAs <int>(); } break; // host sent 'received stardrop from unicorn' update case MessageId.SetUnicornStardropReceived: if (Context.IsMainPlayer) { DeepWoodsState.PlayersWhoGotStardropFromUnicorn.Add(e.FromPlayerID); } break; // host added/removed location case MessageId.AddLocation: if (!Context.IsMainPlayer) { string name = e.ReadAs <string>(); DeepWoodsManager.AddBlankDeepWoodsToGameLocations(name); } break; case MessageId.RemoveLocation: if (!Context.IsMainPlayer) { string name = e.ReadAs <string>(); DeepWoodsManager.RemoveDeepWoodsFromGameLocations(name); } break; default: ModEntry.Log(" ignored unknown type.", LogLevel.Trace); break; } }
public static void AddStuff(DeepWoods deepWoods, DeepWoodsRandom random) { DeepWoodsSpaceManager spaceManager = new DeepWoodsSpaceManager(deepWoods.mapWidth.Value, deepWoods.mapHeight.Value); new DeepWoodsStuffCreator(deepWoods, random, spaceManager).ClearAndAddStuff(); }
private DeepWoodsStuffCreator(DeepWoods deepWoods, DeepWoodsRandom random, DeepWoodsSpaceManager spaceManager) { this.deepWoods = deepWoods; this.random = random; this.spaceManager = spaceManager; }