using System; using System.Linq; using System.Reflection; using System.Collections.Generic; using UnityEngine; using Oxide.Core; using Oxide.Core.Plugins; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Facepunch; using Rust; #region Changelogs and Todo /********************************************************************** * * 1.0.0 : - Initial release * 1.0.1 : - Cleanup * - Added 1 fishbone after eating minnows * 1.0.2 - Converted gutting to switchcase * - When inventory is full when gutting drops the items on the floor * **********************************************************************/ #endregion namespace Oxide.Plugins { [Info("FishR", "Krungh Crow", "1.0.2")] [Description("Core item handling when gutting fish")] class FishR : RustPlugin { #region Variables ulong chaticon = 0; string prefix; bool Debug = false; ulong SkinBoneFi; #endregion #region Configuration void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } Debug = configData.PlugCFG.Debug; prefix = "[FishR] "; chaticon = 0; #region Fish Bone Skin Id assign SkinBoneFi = 2583801321; #endregion if (Debug) Puts($"[Debug] Debug is activated if unintentional disable this in the config !"); } private ConfigData configData; class ConfigData { [JsonProperty(PropertyName = "Main config")] public SettingsPlugin PlugCFG = new SettingsPlugin(); [JsonProperty(PropertyName = "Anchovy")] public OutputAnchovy Anchovy = new OutputAnchovy(); [JsonProperty(PropertyName = "Cat fish")] public OutputCatfish Catfish = new OutputCatfish(); [JsonProperty(PropertyName = "Herring")] public OutputHerring Herring = new OutputHerring(); [JsonProperty(PropertyName = "Orange Roughy")] public OutputOrange Orange = new OutputOrange(); [JsonProperty(PropertyName = "Salmon")] public OutputSalmon Salmon = new OutputSalmon(); [JsonProperty(PropertyName = "Sardine")] public OutputSardine Sardine = new OutputSardine(); [JsonProperty(PropertyName = "Small Shark")] public OutputSmallShark Shark = new OutputSmallShark(); [JsonProperty(PropertyName = "Small Trout")] public OutputTrout Trout = new OutputTrout(); [JsonProperty(PropertyName = "Yellow Perch")] public OutputYellow Yellow = new OutputYellow(); } class SettingsPlugin { [JsonProperty(PropertyName = "Debug")] public bool Debug = false; } class OutputAnchovy { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 2; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 1; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 1; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = false; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputCatfish { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 18; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 18; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 18; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = true; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputHerring { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 1; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 2; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 1; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = false; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputOrange { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 18; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 18; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 18; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = true; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputSalmon { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 16; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 18; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 16; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = true; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputSmallShark { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 20; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 20; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 20; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = true; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputSardine { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 1; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 1; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 5; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = false; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputTrout { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 5; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 4; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 8; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = false; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } class OutputYellow { [JsonProperty(PropertyName = "Fish Bones")] public int FBones = 6; [JsonProperty(PropertyName = "Raw Fish")] public int Fmeat = 4; [JsonProperty(PropertyName = "Animal Fat")] public int FFat = 9; [JsonProperty(PropertyName = "Add bonus item")] public bool UseBonus = false; [JsonProperty(PropertyName = "Bonus item (x1)")] public List Bonus = new List(); } private bool LoadConfigVariables() { try { configData = Config.ReadObject(); } catch { return false; } SaveConf(); return true; } protected override void LoadDefaultConfig() { Puts("Fresh install detected Creating a new config file."); configData = new ConfigData(); configData.Catfish.Bonus = new List { {"scrap"}, {"keycard_blue"}, {"cloth"}, {"ammo.pistol"}, {"flare"} }; configData.Orange.Bonus = new List { {"scrap"}, {"keycard_blue"}, {"cloth"}, {"ammo.pistol"}, {"flare"} }; configData.Salmon.Bonus = new List { {"scrap"}, {"keycard_blue"}, {"cloth"}, {"ammo.pistol"}, {"flare"} }; configData.Shark.Bonus = new List { {"scrap"}, {"keycard_blue"}, {"cloth"}, {"ammo.pistol"}, {"flare"} }; SaveConf(); } void SaveConf() => Config.WriteObject(configData, true); #endregion #region LanguageAPI protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["GutUnsuccesful"] = "Gutting was unsuccesfull ! gut the fish in your inventory instead.", ["Info"] = "\nAvailable Commands :\n/fishr info : Shows info on version/author and commands", ["InvalidInput"] = "Please enter a valid command!", ["Version"] = "Version : V", }, this); } #endregion #region Commands [ChatCommand("fishr")] private void CMDFishr(BasePlayer player, string command, string[] args) { if (args.Length == 0) { Player.Message(player, prefix + string.Format(msg("InvalidInput", player.UserIDString)), chaticon); } else { if (args[0].ToLower() == "info") { Player.Message(player, prefix + string.Format(msg("Version", player.UserIDString)) + this.Version.ToString() + " By : " + this.Author.ToString() + msg("Info") , chaticon); return; } else { Player.Message(player, prefix + string.Format(msg("InvalidInput", player.UserIDString)), chaticon); } } } #endregion #region Hooks private object OnItemUse(Item item) { BasePlayer ownerPlayer = item.GetOwnerPlayer(); if (item.info.shortname.Contains("minnows") && item != null) { Item bones = ItemManager.CreateByName("bone.fragments", 1); bones.name = "Fish Bones"; bones.skin = SkinBoneFi; bones.MarkDirty(); ownerPlayer.inventory.GiveItem(bones, null); return false; } return null; } private object OnItemAction(Item item, string action, BasePlayer player) { BasePlayer ownerPlayer = item.GetOwnerPlayer(); if (action == "Gut") { try { string itemName = item.info.shortname.ToLower(); Item bonus = null; // Initialize bonus variable Item bones = ItemManager.CreateByName("bone.fragments" , 1); Item fat = ItemManager.CreateByName("fat.animal" , 1); Item meat = ItemManager.CreateByName("fish.raw" , 1); switch (itemName) { case "fish.anchovy": item.UseItem(); if (configData.Anchovy.Bonus.Count != 0 && configData.Anchovy.UseBonus == true) { string BonusItem = configData.Anchovy.Bonus[new System.Random().Next(configData.Anchovy.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Anchovy.FBones; fat.amount = configData.Anchovy.FFat; meat.amount = configData.Anchovy.Fmeat; break; case "fish.catfish": item.UseItem(); if (configData.Catfish.Bonus.Count != 0 && configData.Catfish.UseBonus == true) { string BonusItem = configData.Catfish.Bonus[new System.Random().Next(configData.Catfish.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Catfish.FBones; fat.amount = configData.Catfish.FFat; meat.amount = configData.Catfish.Fmeat; break; case "fish.herring": item.UseItem(); if (configData.Herring.Bonus.Count != 0 && configData.Herring.UseBonus == true) { string BonusItem = configData.Herring.Bonus[new System.Random().Next(configData.Herring.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Herring.FBones; fat.amount = configData.Herring.FFat; meat.amount = configData.Herring.Fmeat; break; case "fish.orangeroughy": item.UseItem(); if (configData.Orange.Bonus.Count != 0 && configData.Orange.UseBonus == true) { string BonusItem = configData.Orange.Bonus[new System.Random().Next(configData.Orange.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Orange.FBones; fat.amount = configData.Orange.FFat; meat.amount = configData.Orange.Fmeat; break; case "fish.salmon": item.UseItem(); if (configData.Salmon.Bonus.Count != 0 && configData.Salmon.UseBonus == true) { string BonusItem = configData.Salmon.Bonus[new System.Random().Next(configData.Salmon.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Salmon.FBones; fat.amount = configData.Salmon.FFat; meat.amount = configData.Salmon.Fmeat; break; case "fish.sardine": item.UseItem(); if (configData.Sardine.Bonus.Count != 0 && configData.Sardine.UseBonus == true) { string BonusItem = configData.Sardine.Bonus[new System.Random().Next(configData.Sardine.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Sardine.FBones; fat.amount = configData.Sardine.FFat; meat.amount = configData.Sardine.Fmeat; break; case "fish.smallshark": item.UseItem(); if (configData.Shark.Bonus.Count != 0 && configData.Shark.UseBonus == true) { string BonusItem = configData.Shark.Bonus[new System.Random().Next(configData.Shark.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Shark.FBones; fat.amount = configData.Shark.FFat; meat.amount = configData.Shark.Fmeat; break; case "fish.troutsmall": item.UseItem(); if (configData.Yellow.Bonus.Count != 0 && configData.Yellow.UseBonus == true) { string BonusItem = configData.Yellow.Bonus[new System.Random().Next(configData.Yellow.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Yellow.FBones; fat.amount = configData.Yellow.FFat; meat.amount = configData.Yellow.Fmeat; break; case "fish.yellowperch": item.UseItem(); if (configData.Yellow.Bonus.Count != 0 && configData.Yellow.UseBonus == true) { string BonusItem = configData.Yellow.Bonus[new System.Random().Next(configData.Yellow.Bonus.Count())]; bonus = ItemManager.CreateByName($"{BonusItem}" , 1); //if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); } bones.amount = configData.Yellow.FBones; fat.amount = configData.Yellow.FFat; meat.amount = configData.Yellow.Fmeat; break; default: // Handle the default case if the fish type is not recognized break; } bones.name = "Fish Bones"; bones.skin = SkinBoneFi; bones.MarkDirty(); if (player.inventory.containerMain.IsFull()) { bones.DropAndTossUpwards(player.transform.position); fat.DropAndTossUpwards(player.transform.position); meat.DropAndTossUpwards(player.transform.position); if (bonus != null) bonus.DropAndTossUpwards(player.transform.position); } else { if (bonus != null) ownerPlayer.inventory.GiveItem(bonus , null); ownerPlayer.inventory.GiveItem(bones , null); ownerPlayer.inventory.GiveItem(fat , null); ownerPlayer.inventory.GiveItem(meat , null); } if (Debug) Puts($"[Debug] {ownerPlayer.displayName} Gutted a {item.info.shortname} and got :\n {bones.amount}x [{bones.name}]\n {fat.amount}x [animal fat]\n {meat.amount}x [raw fish]"); return true; } catch { Player.Message(player , prefix + string.Format(msg("GutUnsuccesful" , player.UserIDString)) , chaticon); return false; } } return null; } #endregion #region Message helper private string msg(string key, string id = null) => lang.GetMessage(key, this, id); #endregion } }