private static void breakStone_Postfix(GameLocation __instance, ref bool __result, int indexOfStone, int x, int y, Farmer who, Random r) { SMonitor.Log($"Checking for custom ore in stone {indexOfStone}"); CustomOreNode node = customOreNodesList.Find(n => n.parentSheetIndex == indexOfStone); if (node == null) { return; } SMonitor.Log($"Got custom ore in stone {indexOfStone}"); OreLevelRange gotRange = null; foreach (OreLevelRange range in node.oreLevelRanges) { if (IsInRange(range, __instance, false)) { gotRange = range; break; } } if (gotRange == null) { SMonitor.Log($"No range for {indexOfStone}!", LogLevel.Warn); return; } int addedOres = who.professions.Contains(18) ? 1 : 0; SMonitor.Log($"custom node has {node.dropItems.Count} potential items."); foreach (DropItem item in node.dropItems) { if (Game1.random.NextDouble() < item.dropChance * gotRange.dropChanceMult / 100) { SMonitor.Log($"dropping item {item.itemIdOrName}"); if (!int.TryParse(item.itemIdOrName, out int itemId)) { foreach (KeyValuePair <int, string> kvp in Game1.objectInformation) { if (kvp.Value.StartsWith(item.itemIdOrName + "/")) { itemId = kvp.Key; break; } } } Game1.createMultipleObjectDebris(itemId, x, y, addedOres + (int)Math.Round(r.Next(item.minAmount, (Math.Max(item.minAmount + 1, item.maxAmount + 1)) + ((r.NextDouble() < who.LuckLevel / 100f) ? item.luckyAmount : 0) + ((r.NextDouble() < who.MiningLevel / 100f) ? item.minerAmount : 0)) * gotRange.dropMult), who.UniqueMultiplayerID, __instance); } } int experience = (int)Math.Round(node.exp * gotRange.expMult); who.gainExperience(3, experience); __result = experience > 0; }
private static void Object_Prefix(ref int parentSheetIndex, string Givenname) { if (Environment.StackTrace.Contains("chooseStoneType")) { return; } if (Givenname == "Stone" || parentSheetIndex == 294 || parentSheetIndex == 295) { float currentChance = 0; for (int i = 0; i < customOreNodesList.Count; i++) { CustomOreNode node = customOreNodesList[i]; OreLevelRange gotRange = null; foreach (OreLevelRange range in node.oreLevelRanges) { if (range.minLevel < 1) { gotRange = range; break; } } if (gotRange == null) { continue; } currentChance += node.spawnChance * gotRange.spawnChanceMult; if (Game1.random.NextDouble() < currentChance / 100f) { int index = node.parentSheetIndex; parentSheetIndex = index; break; } } } }
private static void breakStone_Postfix(GameLocation __instance, ref bool __result, int indexOfStone, int x, int y, Farmer who, Random r) { SMonitor.Log($"Checking for custom ore in stone {indexOfStone}"); int firstIndex = FirstIndex + (Config.SpriteSheetOffsetRows * SpringObjectsWidth / 16); if (indexOfStone - firstIndex < 0 || indexOfStone - firstIndex >= CustomOreNodes.Count) { return; } CustomOreNode node = CustomOreNodes[indexOfStone - firstIndex]; OreLevelRange gotRange = null; foreach (OreLevelRange range in node.oreLevelRanges) { if ((range.minLevel < 1 && !(__instance is MineShaft)) || (range.minLevel > 0 && __instance is MineShaft && ((__instance as MineShaft).mineLevel <= range.maxLevel))) { gotRange = range; break; } } if (gotRange == null) { return; } int addedOres = who.professions.Contains(18) ? 1 : 0; SMonitor.Log($"custom node has {node.dropItems.Count} potential items."); foreach (DropItem item in node.dropItems) { if (Game1.random.NextDouble() < item.dropChance * gotRange.dropChanceMult / 100) { SMonitor.Log($"dropping item {item.itemIdOrName}"); if (!int.TryParse(item.itemIdOrName, out int itemId)) { foreach (KeyValuePair <int, string> kvp in Game1.objectInformation) { if (kvp.Value.StartsWith(item.itemIdOrName + "/")) { itemId = kvp.Key; break; } } } Game1.createMultipleObjectDebris(itemId, x, y, addedOres + (int)Math.Round(r.Next(item.minAmount, (Math.Max(item.minAmount + 1, item.maxAmount + 1)) + ((r.NextDouble() < (double)((float)who.LuckLevel / 100f)) ? item.luckyAmount : 0) + ((r.NextDouble() < (double)((float)who.MiningLevel / 100f)) ? item.minerAmount : 0)) * gotRange.dropMult), who.uniqueMultiplayerID, __instance); } } int experience = (int)Math.Round(node.exp * gotRange.expMult); who.gainExperience(3, experience); __result = experience > 0; }
private static void chooseStoneType_Postfix(MineShaft __instance, ref Object __result, Vector2 tile) { if (__result == null) { return; } int difficulty = __instance.mineLevel > 120 ? Game1.netWorldState.Value.SkullCavesDifficulty : Game1.netWorldState.Value.MinesDifficulty; List <int> ores = new List <int>() { 765, 764, 290, 751 }; if (!ores.Contains(__result.ParentSheetIndex)) { float totalChance = 0; for (int i = 0; i < customOreNodesList.Count; i++) { CustomOreNode node = customOreNodesList[i]; foreach (OreLevelRange range in node.oreLevelRanges) { if ((range.minLevel < 1 || __instance.mineLevel >= range.minLevel) && (range.maxLevel < 1 || __instance.mineLevel <= range.maxLevel) && (range.minDifficulty <= difficulty) && (range.maxDifficulty < 0 || range.maxDifficulty >= difficulty)) { totalChance += node.spawnChance * range.spawnChanceMult; break; } } } double ourChance = Game1.random.NextDouble() * 100; if (ourChance < totalChance) { // SMonitor.Log($"Chance of custom ore: {ourChance}%"); float cumulativeChance = 0f; for (int i = 0; i < customOreNodesList.Count; i++) { CustomOreNode node = customOreNodesList[i]; OreLevelRange gotRange = null; foreach (OreLevelRange range in node.oreLevelRanges) { if (IsInRange(range, __instance, true)) { gotRange = range; break; } } if (gotRange == null) { continue; } cumulativeChance += node.spawnChance * gotRange.spawnChanceMult; if (ourChance < cumulativeChance) { SMonitor.Log($"Switching to custom ore \"{node.nodeDesc}\": {cumulativeChance}% / {ourChance}% (rolled)"); int index = node.parentSheetIndex; //SMonitor.Log($"Displaying stone at index {index}", LogLevel.Debug); __result = new Object(tile, index, "Stone", true, false, false, false) { MinutesUntilReady = node.durability }; return; } } } } }
private static bool IsInRange(OreLevelRange range, GameLocation location, bool mineOnly) { int difficulty = (location is MineShaft) ? ((location as MineShaft).mineLevel > 120 ? Game1.netWorldState.Value.SkullCavesDifficulty : Game1.netWorldState.Value.MinesDifficulty) : 0; return((range.minLevel < 1 && !(location is MineShaft) && !mineOnly) || (location is MineShaft && (range.minLevel <= (location as MineShaft).mineLevel && (range.maxLevel < 0 || (location as MineShaft).mineLevel <= range.maxLevel))) && (range.minDifficulty <= difficulty) && (range.maxDifficulty < 0 || range.maxDifficulty >= difficulty)); }
private static void chooseStoneType_Postfix(MineShaft __instance, ref Object __result, Vector2 tile) { if (__result == null || __result.parentSheetIndex == null) { return; } List <int> ores = new List <int>() { 765, 764, 290, 751 }; if (!ores.Contains(__result.ParentSheetIndex)) { float totalChance = 0; for (int i = 0; i < CustomOreNodes.Count; i++) { CustomOreNode node = CustomOreNodes[i]; foreach (OreLevelRange range in node.oreLevelRanges) { if ((range.minLevel < 1 || __instance.mineLevel >= range.minLevel) && (range.maxLevel < 1 || __instance.mineLevel <= range.maxLevel)) { totalChance += node.spawnChance * range.spawnChanceMult; break; } } } double ourChance = Game1.random.NextDouble() * 100; if (ourChance < totalChance) { // SMonitor.Log($"Chance of custom ore: {ourChance}%"); float cumulativeChance = 0f; for (int i = 0; i < CustomOreNodes.Count; i++) { CustomOreNode node = CustomOreNodes[i]; OreLevelRange gotRange = null; foreach (OreLevelRange range in node.oreLevelRanges) { if ((range.minLevel < 1 || __instance.mineLevel >= range.minLevel) && (range.maxLevel < 1 || __instance.mineLevel <= range.maxLevel)) { gotRange = range; break; } } if (gotRange == null) { continue; } cumulativeChance += node.spawnChance * gotRange.spawnChanceMult; if (ourChance < cumulativeChance) { SMonitor.Log($"Displaying custom ore \"{node.nodeDesc}\": {cumulativeChance}% / {ourChance}% (rolled)"); int index = (SpringObjectsHeight / 16 * SpringObjectsWidth / 16) + (Config.SpriteSheetOffsetRows * SpringObjectsWidth / 16) + i; //SMonitor.Log($"Displaying stone at index {index}", LogLevel.Debug); __result = new Object(tile, index, "Stone", true, false, false, false) { MinutesUntilReady = node.durability }; //SMonitor.Log(__result.DisplayName); return; } } } } }