public void HandleMoonAfterWake() { Beach b = Game1.getLocationFromName("Beach") as Beach; int itemsChanged = 0; if (Dice.NextDoublePositive() < .20) { return; } //new moon processing if (CurrentPhase() == MoonPhase.NewMoon && ModConfig.HazardousMoonEvents && !(b is null)) { List <KeyValuePair <Vector2, StardewValley.Object> > entries = (from o in b.objects.Pairs where beachItems.Contains(o.Value.ParentSheetIndex) select o).ToList(); foreach (KeyValuePair <Vector2, StardewValley.Object> rem in entries) { double diceRoll = ModConfig.BeachRemovalChance; if (IsSuperMoon) { diceRoll *= 2; } if (Dice.NextDouble() < diceRoll) { itemsChanged++; b.objects.Remove(rem.Key); } } if (itemsChanged > 0) { Game1.addHUDMessage(new HUDMessage(Translations.Get("moon-text.hud_message_new"))); } } //full moon processing if (CurrentPhase() == MoonPhase.FullMoon) { Rectangle rectangle = new Rectangle(65, 11, 25, 12); for (int index = 0; index < 8; ++index) { //get the item ID to spawn var parentSheetIndex = moonBeachItems.GetRandomItem(Dice); if (Dice.NextDouble() <= .0001) { parentSheetIndex = 392; //rare chance for a Nautlius Shell. } double emeraldChance = .2001; if (IsSuperMoon) { emeraldChance += .10; } else if (Dice.NextDouble() > .0001 && Dice.NextDouble() <= emeraldChance) { parentSheetIndex = 60; } if (Dice.NextDouble() < ModConfig.BeachSpawnChance) { Vector2 v = new Vector2(Game1.random.Next(rectangle.X, rectangle.Right), Game1.random.Next(rectangle.Y, rectangle.Bottom)); itemsChanged++; if (b.isTileLocationTotallyClearAndPlaceable(v)) { b.dropObject(new StardewValley.Object(parentSheetIndex, 1, false, -1, 0), v * Game1.tileSize, Game1.viewport, true, null); } } } if (IsSuperMoon) { for (int j = 0; j < 20; ++j) { double driftWoodChance = .25; int parentSheetIndex = 388; if (Dice.NextDouble() < driftWoodChance) { Vector2 v = new Vector2(Game1.random.Next(rectangle.X, rectangle.Right), Game1.random.Next(rectangle.Y, rectangle.Bottom)); itemsChanged++; if (b.isTileLocationTotallyClearAndPlaceable(v)) { b.dropObject(new StardewValley.Object(parentSheetIndex, 1, false, -1, 0), v * Game1.tileSize, Game1.viewport, true, null); } } } } if (itemsChanged > 0) { Game1.addHUDMessage(new HUDMessage(Translations.Get("moon-text.hud_message_full"))); } } }
public void HandleMoonAfterWake(ITranslationHelper Helper) { if (Game1.getLocationFromName("Beach") is null) { throw new Exception("... Please reinstall your game"); } Beach b = Game1.getLocationFromName("Beach") as Beach; int itemsChanged = 0; if (Dice.NextDoublePositive() < .20) { return; } //new moon processing if (CurrentPhase == MoonPhase.NewMoon) { List <KeyValuePair <Vector2, StardewValley.Object> > entries = (from o in b.objects where beachItems.Contains(o.Value.parentSheetIndex) select o).ToList(); foreach (KeyValuePair <Vector2, StardewValley.Object> rem in entries) { if (Dice.NextDouble() < BeachRemovalChance) { itemsChanged++; b.objects.Remove(rem.Key); } } if (itemsChanged > 0) { Game1.addHUDMessage(new HUDMessage(Helper.Get("moon-text.hud_message_new"))); } } //full moon processing if (CurrentPhase == MoonPhase.FullMoon) { int parentSheetIndex = 0; Rectangle rectangle = new Rectangle(65, 11, 25, 12); for (int index = 0; index < 5; ++index) { //get the item ID to spawn parentSheetIndex = moonBeachItems.GetRandomItem(Dice); if (Dice.NextDouble() <= .0001) { parentSheetIndex = 392; //rare chance for a Nautlius Shell. } else if (Dice.NextDouble() > .0001 && Dice.NextDouble() <= .45) { parentSheetIndex = 589; } else if (Dice.NextDouble() > .45 && Dice.NextDouble() <= .62) { parentSheetIndex = 60; } if (Dice.NextDouble() < BeachSpawnChance) { Vector2 v = new Vector2((float)Game1.random.Next(rectangle.X, rectangle.Right), (float)Game1.random.Next(rectangle.Y, rectangle.Bottom)); itemsChanged++; if (b.isTileLocationTotallyClearAndPlaceable(v)) { b.dropObject(new StardewValley.Object(parentSheetIndex, 1, false, -1, 0), v * (float)Game1.tileSize, Game1.viewport, true, null); } } } if (itemsChanged > 0) { Game1.addHUDMessage(new HUDMessage(Helper.Get("moon-text.hud_message_full"))); } } }