public static void MonsterDrop_Postfix(GameLocation __instance, Monster monster, int x, int y, Farmer who) { try { if (who == Game1.player) { // Make the monster drop an augmentor if you're lucky double Chance = MachineAugmentorsMod.UserConfig.MonsterLootSettings.GetAugmentorDropChance(__instance, monster, out double BaseChance, out double LocationMultiplier, out double ExpMultiplier, out double HPMultiplier); bool Success = Augmentor.Randomizer.NextDouble() <= Chance; string LogMessage; if (Success) { int SpawnDirection = Augmentor.Randomizer.Next(4); int NumTypes = Enum.GetValues(typeof(AugmentorType)).Length; AugmentorType Type = (AugmentorType)Augmentor.Randomizer.Next(NumTypes); int Quantity = Augmentor.RollDice(0.1) ? 2 : 1; Game1.createItemDebris(Augmentor.CreateInstance(Type, Quantity), Game1.player.getStandingPosition(), SpawnDirection, null, -1); LogMessage = string.Format("Succeeded drop chance: Location = {0}, monster.ExperienceGained = {1}, monster.MaxHealth = {2}\n" + "BaseChance = {3} ({4}%), LocationMultiplier = {5} (+{6}%), ExpMultiplier = {7}, HPMultiplier = {8} (+{9}%), TotalChance = {10} ({11}%)", __instance.Name, monster.ExperienceGained, monster.MaxHealth, BaseChance, (BaseChance * 100.0).ToString("0.##"), LocationMultiplier, ((LocationMultiplier - 1.0) * 100.0).ToString("0.##"), ExpMultiplier.ToString("#.####"), HPMultiplier, ((HPMultiplier - 1.0) * 100.0).ToString("0.##"), Chance, (Chance * 100.0).ToString("0.###")); } else { LogMessage = string.Format("Failed drop chance: Location = {0}, monster.ExperienceGained = {1}, monster.MaxHealth = {2}\n" + "BaseChance = {3} ({4}%), LocationMultiplier = {5} (+{6}%), ExpMultiplier = {7}, HPMultiplier = {8} (+{9}%), TotalChance = {10} ({11}%)", __instance.Name, monster.ExperienceGained, monster.MaxHealth, BaseChance, (BaseChance * 100.0).ToString("0.##"), LocationMultiplier, ((LocationMultiplier - 1.0) * 100.0).ToString("0.##"), ExpMultiplier.ToString("#.####"), HPMultiplier, ((HPMultiplier - 1.0) * 100.0).ToString("0.##"), Chance, (Chance * 100.0).ToString("0.###")); } #if DEBUG MachineAugmentorsMod.ModInstance.Monitor.Log(LogMessage, LogLevel.Debug); #else MachineAugmentorsMod.ModInstance.Monitor.Log(LogMessage, LogLevel.Trace); #endif } } catch (Exception ex) { MachineAugmentorsMod.ModInstance.Monitor.Log(string.Format("Unhandled Error in {0}:\n{1}", nameof(MonsterDrop_Postfix), ex), LogLevel.Error); } }
private void RegisterConsoleCommands() { List <string> ValidTypes = Enum.GetValues(typeof(AugmentorType)).Cast <AugmentorType>().Select(x => x.ToString()).ToList(); //Possible TODO: Add translation support for this command string CommandName = "player_addaugmentor"; string CommandHelp = string.Format("Adds augmentors of the given AugmentorType into your inventory.\n" + "Arguments: <AugmentorType> <Quantity>\n" + "Example: {0} EfficiencyAugmentor 6\n\n" + "Valid values for <AugmentorType>: {1}", CommandName, string.Join(", ", ValidTypes), string.Join(", ", ValidTypes)); Helper.ConsoleCommands.Add(CommandName, CommandHelp, (string Name, string[] Args) => { if (Game1.player.isInventoryFull()) { Monitor.Log("Unable to execute command: Inventory is full!", LogLevel.Alert); } else if (Args.Length < 2) { Monitor.Log("Unable to execute command: Required arguments missing!", LogLevel.Alert); } else { string TypeName = Args[0]; if (!Enum.TryParse(TypeName, out AugmentorType AugmentorType)) { Monitor.Log(string.Format("Unable to execute command: <AugmentorType> \"{0}\" is not valid. Expected valid values: {1}", TypeName, string.Join(", ", ValidTypes)), LogLevel.Alert); } else { if (!int.TryParse(Args[1], out int Quantity)) { Monitor.Log(string.Format("Unable to execute command: could not parse an integer from \"{0}\".", Args[1]), LogLevel.Alert); } else { Augmentor SpawnedItem = Augmentor.CreateInstance(AugmentorType, Quantity); Game1.player.addItemToInventory(SpawnedItem); } } } }); }
private void RegisterConsoleCommands() { List <string> ValidTypes = Enum.GetValues(typeof(AugmentorType)).Cast <AugmentorType>().Select(x => x.ToString()).ToList(); //Possible TODO: Add translation support for this command string CommandName = "player_addaugmentor"; string CommandHelp = string.Format("Adds augmentors of the given AugmentorType into your inventory.\n" + "Arguments: <AugmentorType> <Quantity>\n" + "Example: {0} EfficiencyAugmentor 6\n\n" + "Valid values for <AugmentorType>: {1}", CommandName, string.Join(", ", ValidTypes), string.Join(", ", ValidTypes)); Helper.ConsoleCommands.Add(CommandName, CommandHelp, (string Name, string[] Args) => { if (Game1.player.isInventoryFull()) { Monitor.Log("Unable to execute command: Inventory is full!", LogLevel.Alert); } else if (Args.Length < 2) { Monitor.Log("Unable to execute command: Required arguments missing!", LogLevel.Alert); } else { string TypeName = Args[0]; if (!Enum.TryParse(TypeName, out AugmentorType AugmentorType)) { Monitor.Log(string.Format("Unable to execute command: <AugmentorType> \"{0}\" is not valid. Expected valid values: {1}", TypeName, string.Join(", ", ValidTypes)), LogLevel.Alert); } else { if (!int.TryParse(Args[1], out int Quantity)) { Monitor.Log(string.Format("Unable to execute command: could not parse an integer from \"{0}\".", Args[1]), LogLevel.Alert); } else { Augmentor SpawnedItem = Augmentor.CreateInstance(AugmentorType, Quantity); Game1.player.addItemToInventory(SpawnedItem); } } } }); //Possible TODO: Add translation support for this command CommandName = "machine_augmentors_reload_config"; CommandHelp = "Reloads configuration settings from this mod's config.json file. Normally this file's settings are only loaded once when the game is started." + " Use this command if you've made changes to the config during this game session."; Helper.ConsoleCommands.Add(CommandName, CommandHelp, (string Name, string[] Args) => { try { LoadUserConfig(); Monitor.Log("config.json settings were successfully reloaded.", LogLevel.Alert); } catch (Exception ex) { Monitor.Log(string.Format("Machine Augmentors: Unhandled error while executing command: {0}", ex.Message), LogLevel.Error); } }); }
private void Display_MenuChanged(object sender, StardewModdingAPI.Events.MenuChangedEventArgs e) { // Add Augmentors items to the shop's stock if (e.NewMenu is ShopMenu NewShop && IsTravellingMerchantShop(NewShop)) { if (TodaysStock == null) { TodaysStock = new Dictionary <ISalable, int[]>(); // Pick the Augmentor types that will be sold today int NumTypes = Augmentor.WeightedRound(UserConfig.ShopSettings.NumAugmentorTypesInShop); List <AugmentorConfig> ChosenTypes = new List <AugmentorConfig>(); List <AugmentorConfig> RemainingTypes = new List <AugmentorConfig>(UserConfig.AugmentorConfigs); while (ChosenTypes.Count < NumTypes && RemainingTypes.Any()) { int TotalWeight = RemainingTypes.Sum(x => x.ShopAppearanceWeight); int ChosenWeight = Augmentor.Randomizer.Next(TotalWeight); // EX: If the remaining types had weights = { 3, 6, 2 }, picks random number from 0 to 10 inclusive. // Then the first is selected if ChosenWeight is 0-2 (3/11 chance), second is selected if 3-8 (6/11 chance), third is selected if 9-10 (2/11 chance) int CurrentSum = 0; for (int i = 0; i < RemainingTypes.Count; i++) { AugmentorConfig CurrentConfig = RemainingTypes[i]; CurrentSum += CurrentConfig.ShopAppearanceWeight; if (ChosenWeight < CurrentSum) { ChosenTypes.Add(CurrentConfig); RemainingTypes.RemoveAt(i); break; } } } // Add each type to today's stock foreach (AugmentorConfig Config in ChosenTypes) { // Compute price double BasePrice = Config.BasePrice * UserConfig.GlobalPriceMultiplier; double Price = BasePrice; if (UserConfig.ShopSettings.PriceDeviationRolls > 0) { double MinMultiplier = 1.0 - UserConfig.ShopSettings.PriceDeviation; double MaxMultiplier = 1.0 + UserConfig.ShopSettings.PriceDeviation; double Multiplier = Enumerable.Range(0, UserConfig.ShopSettings.PriceDeviationRolls).Select(x => Augmentor.GetRandomNumber(MinMultiplier, MaxMultiplier)).Average(); Price = Math.Round(BasePrice * Multiplier, MidpointRounding.AwayFromZero); } // Compute quantity double BaseQuantityInStock = UserConfig.ShopSettings.BaseQuantityInStock; double YearMultiplier = 1.0 + (UserConfig.ShopSettings.YearShopStockMultiplierBonus * (Game1.Date.Year - 1)); double DesiredValue = BaseQuantityInStock * Config.ShopStockMultiplier * YearMultiplier; int QuantityInStock = Math.Max(1, Augmentor.WeightedRound(DesiredValue)); Augmentor SellableInstance = Augmentor.CreateInstance(Config.AugmentorType, 1); TodaysStock.Add(SellableInstance, new int[] { (int)Price, QuantityInStock }); } } // Add today's stock to the shop if (TodaysStock.Any()) { Dictionary <ISalable, int[]> Stock = NewShop.itemPriceAndStock; foreach (KeyValuePair <ISalable, int[]> Item in TodaysStock) { if (Item.Value[1] > 0 && !Stock.ContainsKey(Item.Key)) { Stock.Add(Item.Key, Item.Value); } } NewShop.setItemPriceAndStock(Stock); } } }