C#:
using System;
using Oxide.Core.Plugins;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("AdvancedRates", "Drop Dead", "1.0.12")]
public class AdvancedRates : RustPlugin
{
#region Var [Определения]
[PluginReference] private Plugin RadHouse;
public List<uint> LootedBoxes = new List<uint>();
#endregion
#region Data [Работа с датой]
private void SaveData()
{
Interface.Oxide.DataFileSystem.WriteObject($"{Title}/LootedBoxes", LootedBoxes);
}
private void LoadData()
{
if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{Title}/LootedBoxes"))
LootedBoxes = Interface.Oxide.DataFileSystem.ReadObject<List<uint>>($"{Title}/LootedBoxes");
}
private void WipeData()
{
LootedBoxes.Clear();
}
#endregion
#region Config [Конфигурация плагина]
private PluginConfig cfg;
public class PluginConfig
{
[JsonProperty("Настройки рейтов фарма")]
public GatherSettings gather = new GatherSettings();
[JsonProperty("Настройки рейтов на бонус-добычу")]
public BonusSettings bonus = new BonusSettings();
[JsonProperty("Настройки рейтов подбора")]
public CollectibleSettings collectible = new CollectibleSettings();
[JsonProperty("Настройки рейтов компонтентов (ящики)")]
public ComponentsSettings components = new ComponentsSettings();
[JsonProperty("Настройки рейтов компонтентов (бочки)")]
public BarrelsSettings barrels = new BarrelsSettings();
[JsonProperty("Настройки рейтов компонтентов в карьерах")]
public QuarrySettings quarry = new QuarrySettings();
public class GatherSettings
{
[JsonProperty("Включить рейты на добычу (камни, деревья)?")]
public bool enablegatherrate = true;
[JsonProperty("Рейты на добычу")]
public float gatherrate = 2f;
[JsonProperty("Список запрещенных предметов (рейты не будут распространятся на них)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> blacklist = new List<string>()
{
{ "hq.metal.ore" },
{ "example" }
};
[JsonProperty("Пермишны для увеличения рейтов на добычу", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> perms = new Dictionary<string, float>
{
["advancedrates.gather.vip"] = 3f,
["advancedrates.gather.prem"] = 4f
};
}
public class BonusSettings
{
[JsonProperty("Включить рейты на бонус-добычу (бонус дается в конце фарма)?")]
public bool enablebonusrate = true;
[JsonProperty("Рейты на бонус-добычу")]
public float bonusrate = 2f;
[JsonProperty("Список запрещенных предметов (рейты не будут распространятся на них)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> blacklist = new List<string>()
{
{ "example" },
{ "example" }
};
[JsonProperty("Пермишны для увеличения рейтов на бонус-добычу", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> perms = new Dictionary<string, float>
{
["advancedrates.bonus.vip"] = 3f,
["advancedrates.bonus.prem"] = 4f
};
}
public class CollectibleSettings
{
[JsonProperty("Включить рейты на подбор (collectible ресурсы)?")]
public bool enablepickuprate = true;
[JsonProperty("Рейты на подбор")]
public float pickuprate = 2f;
[JsonProperty("Список запрещенных предметов (рейты не будут распространятся на них)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> blacklist = new List<string>()
{
{ "clone.black.berry" },
{ "seed.black.berry" },
{ "clone.blue.berry" },
{ "seed.blue.berry" },
{ "clone.corn" },
{ "seed.corn" },
{ "clone.green.berry" },
{ "seed.green.berry" },
{ "clone.hemp" },
{ "seed.hemp" },
{ "clone.potato" },
{ "seed.potato" },
{ "clone.pumpkin" },
{ "seed.pumpkin" },
{ "clone.red.berry" },
{ "seed.red.berry" },
{ "clone.white.berry" },
{ "seed.white.berry" },
{ "clone.yellow.berry" },
{ "seed.yellow.berry" }
};
[JsonProperty("Пермишны для увеличения рейтов на подбор", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> perms = new Dictionary<string, float>
{
["advancedrates.collectible.vip"] = 3f,
["advancedrates.collectible.prem"] = 4f
};
}
public class ComponentsSettings
{
[JsonProperty("Включить рейты на компоненты?")]
public bool enablecomponentsrate = true;
[JsonProperty("Рейты на компоненты отдельно для каждого ящика", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> rate = new Dictionary<string, float>
{
["bradley_crate"] = 1f,
["heli_crate"] = 1f,
["crate_basic"] = 2f,
["crate_elite"] = 2f,
["crate_mine"] = 1f,
["crate_normal"] = 2f,
["crate_normal_2"] = 2f,
["crate_normal_2_food"] = 1f,
["crate_normal_2_medical"] = 2f,
["crate_tools"] = 1f,
["crate_underwater_advanced"] = 2f,
["crate_underwater_basic"] = 1f,
["codelockedhackablecrate"] = 3f,
["codelockedhackablecrate_oilrig"] = 2f,
["loot-barrel-1"] = 2f,
["loot-barrel-2"] = 2f,
["loot_barrel_1"] = 2f,
["loot_barrel_2"] = 2f,
["oil_barrel"] = 2f
};
[JsonProperty("Список запрещенных предметов (рейты не будут распространятся на них в любом ящике)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> blacklist = new List<string>()
{
{ "hazmatsuit" },
{ "wall.external.high.stone" },
{ "gates.external.high.wood" },
{ "wall.external.high" },
{ "gates.external.high.stone" },
{ "diving.mask" },
{ "diving.tank" },
{ "diving.wetsuit" },
{ "diving.fins" },
{ "electric.solarpanel.large" },
{ "electric.timer" },
{ "electric.battery.rechargable.small" },
{ "electric.pressurepad" }
};
[JsonProperty("Пермишны для увеличения рейтов на компоненты", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> perms = new Dictionary<string, float>
{
["advancedrates.components.vip"] = 3f,
["advancedrates.components.prem"] = 4f
};
}
public class BarrelsSettings
{
[JsonProperty("Включить рейты на компоненты с бочкек?")]
public bool enablebarrelsrate = true;
[JsonProperty("Рейты на компоненты отдельно для каждой бочки", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> rate = new Dictionary<string, float>
{
["loot-barrel-1"] = 2f,
["loot-barrel-2"] = 2f,
["loot_barrel_1"] = 2f,
["loot_barrel_2"] = 2f,
["oil_barrel"] = 2f
};
[JsonProperty("Список запрещенных предметов (рейты не будут распространятся на них в любой бочке)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> blacklist = new List<string>()
{
{ "tarp" },
{ "example" }
};
}
public class QuarrySettings
{
[JsonProperty("Включить рейты на карьеры?")]
public bool enablequarryrate = true;
[JsonProperty("Рейты на карьер без привелегии")]
public float quarryrate = 2f;
[JsonProperty("Список запрещенных предметов (рейты не будут распространятся на них в любом карьере)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> blacklist = new List<string>()
{
{ "hq.metal.ore" },
{ "example" }
};
[JsonProperty("Пермишны для увеличения рейтов карьеров", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> perms = new Dictionary<string, float>
{
["advancedrates.quarry.vip"] = 3f,
["advancedrates.quarry.prem"] = 4f
};
}
}
private void Init()
{
cfg = Config.ReadObject<PluginConfig>();
Config.WriteObject(cfg);
}
protected override void LoadDefaultConfig()
{
Config.WriteObject(new PluginConfig(), true);
}
#endregion
#region API
uint GetRadHouseBoxID()
{
var result = RadHouse?.Call("RadHouseGetContainerID");
if (result == "") return 0;
return uint.Parse(result.ToString());
}
#endregion
#region Methods [Методы]
float GetPlayerRate(string playerid, string type, string crate)
{
float gatherrate = cfg.gather.gatherrate;
float bonusrate = cfg.bonus.bonusrate;
float collectiblerate = cfg.collectible.pickuprate;
float cratesrate = 1f;
float barrelsrate = 1f;
float quarryrate = 1f;
if (type == "gather")
{
foreach (var num in cfg.gather.perms)
{
if (permission.UserHasPermission(playerid, num.Key))
{
if (num.Value > gatherrate) gatherrate = num.Value;
}
}
return gatherrate;
}
if (type == "bonus")
{
foreach (var num in cfg.bonus.perms)
{
if (permission.UserHasPermission(playerid, num.Key))
{
if (num.Value > bonusrate) bonusrate = num.Value;
}
}
return bonusrate;
}
if (type == "collectible")
{
foreach (var num in cfg.collectible.perms)
{
if (permission.UserHasPermission(playerid, num.Key))
{
if (num.Value > collectiblerate) collectiblerate = num.Value;
}
}
return collectiblerate;
}
if (type == "components")
{
cratesrate = cfg.components.rate[crate];
foreach (var num in cfg.components.perms)
{
if (permission.UserHasPermission(playerid, num.Key))
{
if (num.Value > cratesrate) cratesrate = num.Value;
}
}
return cratesrate;
}
if (type == "quarry")
{
quarryrate = cfg.quarry.quarryrate;
foreach (var num in cfg.quarry.perms)
{
if (permission.UserHasPermission(playerid, num.Key))
{
if (num.Value > quarryrate) quarryrate = num.Value;
}
}
return quarryrate;
}
return 1f;
}
#endregion
#region Hooks [Хуки]
void OnNewSave()
{
WipeData();
}
void OnServerSave()
{
SaveData();
}
void Unload()
{
SaveData();
}
void OnServerInitialized()
{
LoadData();
foreach (var perm in cfg.gather.perms) permission.RegisterPermission(perm.Key, this);
foreach (var perm in cfg.bonus.perms) permission.RegisterPermission(perm.Key, this);
foreach (var perm in cfg.collectible.perms) permission.RegisterPermission(perm.Key, this);
foreach (var perm in cfg.components.perms) permission.RegisterPermission(perm.Key, this);
foreach (var perm in cfg.quarry.perms) permission.RegisterPermission(perm.Key, this);
}
void OnQuarryGather(MiningQuarry quarry, Item item)
{
if (quarry == null || item == null || !cfg.quarry.enablequarryrate) return;
if (quarry.OwnerID == 0) return;
if (cfg.collectible.blacklist.Contains(item.info.shortname)) return;
item.amount = (int)(Convert.ToDouble(item.amount) * GetPlayerRate(quarry.OwnerID.ToString(), "quarry", ""));
}
void OnCollectiblePickup(Item item, BasePlayer player, CollectibleEntity entity)
{
if (item == null || player == null || entity == null || !cfg.collectible.enablepickuprate) return;
if (cfg.collectible.blacklist.Contains(item.info.shortname)) return;
item.amount = (int)(Convert.ToDouble(item.amount) * GetPlayerRate(player.UserIDString, "collectible", ""));
}
void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item)
{
if (item == null || player == null || dispenser == null || !cfg.bonus.enablebonusrate) return;
if (cfg.bonus.blacklist.Contains(item.info.shortname)) return;
item.amount = (int)(Convert.ToDouble(item.amount) * GetPlayerRate(player.UserIDString, "bonus", ""));
}
void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
{
if (dispenser == null || entity == null || item == null || !cfg.gather.enablegatherrate) return;
if (!entity.ToPlayer()) return;
var player = entity.ToPlayer();
if (player == null) return;
if (cfg.gather.blacklist.Contains(item.info.shortname)) return;
item.amount = (int)(Convert.ToDouble(item.amount) * GetPlayerRate(player.UserIDString, "gather", ""));
}
private void OnLootEntity(BasePlayer player, BaseEntity entity)
{
if (player == null || entity == null || entity.net == null || !cfg.components.enablecomponentsrate) return;
if (entity is LootableCorpse) return;
var container = entity as LootContainer;
if (container == null) return;
if (LootedBoxes.Contains(container.net.ID)) return;
if (!cfg.components.rate.ContainsKey(container.ShortPrefabName)) return;
if (GetRadHouseBoxID() != 0 && container.net.ID == GetRadHouseBoxID()) return;
if (container.inventory == null) return;
if (container.inventory.itemList?.Count == 0) return;
foreach (var item in container.inventory.itemList)
{
if (item == null) continue;
if (cfg.components.blacklist.Contains(item.info.shortname) || item.info.stackable == 1) continue;
item.amount = (int)(Convert.ToDouble(item.amount) * GetPlayerRate(player.UserIDString, "components", container.ShortPrefabName));
}
if (!LootedBoxes.Contains(container.net.ID)) LootedBoxes.Add(container.net.ID);
}
private void OnLootSpawn(BaseNetworkable entity)
{
if (!cfg.barrels.enablebarrelsrate || entity == null) return;
if (!entity.ShortPrefabName.Contains("barrel")) return;
var lootContainer = entity as LootContainer;
if (lootContainer != null)
{
foreach (var barrel in cfg.barrels.rate)
{
if (entity.ShortPrefabName.Contains(barrel.Key))
{
NextTick(() =>
{
foreach (var items in lootContainer.inventory.itemList)
{
if (cfg.barrels.blacklist.Contains(items.info.shortname) || items.info.stackable == 1) continue;
items.amount = (int)(Convert.ToDouble(items.amount) * barrel.Value);
}
});
}
}
}
}
#endregion
}
}