using System; using System.Linq; using System.Reflection; using System.Collections.Generic; using UnityEngine; using Oxide.Core.Plugins; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Facepunch; namespace Oxide.Plugins { [Info("Power Tools Plus", "Krungh Crow", "1.0.2")] [Description("PowerTools configuration")] class PowerToolsPlus : RustPlugin { #region Variables const string Default_Perm = "powertoolsplus.default"; const string Vip_Perm = "powertoolsplus.vip"; const string Plus_Perm = "powertoolsplus.plus"; const string ChainDura_Perm = "powertoolsplus.chainsaw"; const string JackDura_Perm = "powertoolsplus.jackhammer"; #endregion #region Configuration void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } permission.RegisterPermission(Default_Perm, this); permission.RegisterPermission(Vip_Perm, this); permission.RegisterPermission(Plus_Perm, this); permission.RegisterPermission(ChainDura_Perm, this); permission.RegisterPermission(JackDura_Perm, this); } private ConfigData configData; class ConfigData { [JsonProperty(PropertyName = "Durability Settings")] public Durabilitys Durability = new Durabilitys(); [JsonProperty(PropertyName = "Chainsaw Settings Default")] public SettingsChain cfgchain = new SettingsChain(); [JsonProperty(PropertyName = "Chainsaw Settings Vip")] public SettingsChainV cfgchainV = new SettingsChainV(); [JsonProperty(PropertyName = "Chainsaw Settings Plus")] public SettingsChainP cfgchainP = new SettingsChainP(); } class Durabilitys { [JsonProperty(PropertyName = "Chainsaw : No Durability loss (Global)")] public bool Chainsawdura = false; [JsonProperty(PropertyName = "Jackhammer : No Durability loss (Global)")] public bool Jackdura = false; } class SettingsChain { [JsonProperty(PropertyName = "Chainsaw start chance")] public float chance = 0.33f; [JsonProperty(PropertyName = "Chainsaw Fuel Capacity")] public int capacity = 100; [JsonProperty(PropertyName = "Chainsaw Fuel consumption")] public float fuelsec = 1.0f; } class SettingsChainV { [JsonProperty(PropertyName = "Chainsaw start chance")] public float chanceV = 0.75f; [JsonProperty(PropertyName = "Chainsaw Fuel Capacity")] public int capacityV = 250; [JsonProperty(PropertyName = "Chainsaw Fuel consumption")] public float fuelsecV = 0.5f; } class SettingsChainP { [JsonProperty(PropertyName = "Chainsaw start chance")] public float chanceP = 1.0f; [JsonProperty(PropertyName = "Chainsaw Fuel Capacity")] public int capacityP = 500; [JsonProperty(PropertyName = "Chainsaw Fuel consumption")] public float fuelsecP = 0.33f; } 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(); SaveConf(); } void SaveConf() => Config.WriteObject(configData, true); #endregion #region Methods private void OnActiveItemChanged(BasePlayer player, Item oldItem, Item newItem) { if (player == null || newItem == null || !player.userID.IsSteamId()) return; if (newItem.info.shortname == "chainsaw") { var chainsaw = newItem.GetHeldEntity() as Chainsaw; if (chainsaw == null) return; if (permission.UserHasPermission(player.UserIDString, Plus_Perm)) { chainsaw.engineStartChance = configData.cfgchainP.chanceP;//1.0 is always chainsaw.maxAmmo = configData.cfgchainP.capacityP;//max fuel containersize chainsaw.fuelPerSec = configData.cfgchainP.fuelsecP;//fuel per sec/tick return; } if (permission.UserHasPermission(player.UserIDString, Vip_Perm)) { chainsaw.engineStartChance = configData.cfgchainV.chanceV; chainsaw.maxAmmo = configData.cfgchainV.capacityV; chainsaw.fuelPerSec = configData.cfgchainV.fuelsecV; return; } if (permission.UserHasPermission(player.UserIDString, Default_Perm)) { chainsaw.engineStartChance = configData.cfgchain.chance; chainsaw.maxAmmo = configData.cfgchain.capacity; chainsaw.fuelPerSec = configData.cfgchain.fuelsec; return; } } } void OnLoseCondition(Item item, ref float amount) { if (item != null) { BasePlayer player; if (item.GetOwnerPlayer() == null) { if (item?.info == null) return; player = item?.GetRootContainer()?.GetOwnerPlayer(); if (player == null) return; } else player = item.GetOwnerPlayer(); if (player != null) { var def = ItemManager.FindItemDefinition(item.info.itemid); if (configData.Durability.Chainsawdura) { if (item.info.shortname == "chainsaw") if (item.hasCondition) item.RepairCondition(amount); } if (configData.Durability.Jackdura) { if (item.info.shortname == "jackhammer") if (item.hasCondition) item.RepairCondition(amount); } if (permission.UserHasPermission(player.UserIDString, ChainDura_Perm)) { if (item.info.shortname == "chainsaw") if (item.hasCondition) item.RepairCondition(amount); } if (permission.UserHasPermission(player.UserIDString, JackDura_Perm)) { if (item.info.shortname == "jackhammer") if (item.hasCondition) item.RepairCondition(amount); } } } return; } #endregion } }