C#:
using UnityEngine;
using System.Collections.Generic;
using System;
using Oxide.Core.Plugins;
using System.Collections;
using Newtonsoft.Json;
using System.Text;
using Facepunch;
using System.Linq;
namespace Oxide.Plugins {
[Info("IQRates", "WOLF#4002", "1.8.23")]
class IQRates : RustPlugin {
private void OnEntitySpawned(BaseHelicopter entity) {
NextTick(() => {
if (entity.OwnerID != 0 || entity.skinID != 0) return;
var EvenTimer = config.pluginSettings.OtherSetting.EventSetting.HelicopterSetting;
if ((EvenTimer.FullOff || EvenTimer.UseEventCustom)) entity.Kill();
}
);
}
bool IsWhiteList(string Shortname) {
var WhiteList = config.pluginSettings.RateSetting.WhiteList;
if (WhiteList.Contains(Shortname)) return true;
else return false;
}
private IEnumerator InitializeTransport() {
foreach (BaseNetworkable entity in BaseNetworkable.serverEntities.Where(e => e is BaseVehicle)) {
if (entity is MotorRowboat) OnEntitySpawned((MotorRowboat)entity);
if(entity is Snowmobile) OnEntitySpawned((Snowmobile)entity);
if(entity is HotAirBalloon) OnEntitySpawned((HotAirBalloon)entity);
if(entity is RHIB) OnEntitySpawned((RHIB)entity);
if(entity is BaseSubmarine) OnEntitySpawned((BaseSubmarine)entity);
if(entity is MiniCopter) OnEntitySpawned((MiniCopter)entity);
if(entity is ScrapTransportHelicopter) OnEntitySpawned((ScrapTransportHelicopter)entity);
yield return CoroutineEx.waitForSeconds(0.03f);
}
}
public List<UInt64> LootersListCrateID = new List<UInt64>();
private void OnEntitySpawned(SupplySignal entity) => UnSubProSub(10);
void StartupFreeze() {
if (!config.pluginSettings.OtherSetting.UseFreezeTime) return;
timeComponent.ProgressTime = false;
ConVar.Env.time = config.pluginSettings.OtherSetting.FreezeTime;
}
void OnFuelConsume(BaseOven oven, Item fuel, ItemModBurnable burnable) {
if (oven == null) return;
burnable.byproductChance = GetRareCoal(BasePlayer.FindByID(oven.OwnerID));
if (burnable.byproductChance == 0) burnable.byproductChance = -1;
}
void OnQuarryGather(MiningQuarry quarry, Item item) {
if (item == null || quarry == null) return;
item.amount = Converted(Types.Quarry, item.info.shortname, item.amount, null, GetQuarryPlayer(quarry.net.ID.Value).ToString());
}
public class ModiferTea {
public Modifier.ModifierType Type;
public Single Duration;
public Single Value;
}
private ModifierDefintion GetDefintionModifer(Modifier.ModifierType Type, Single Duration, Single Value) {
ModifierDefintion def = new ModifierDefintion {
source = Modifier.ModifierSource.Tea, type = Type, duration = Duration, value = Value <= 0 ? 1.0f : Value
}
;
return def;
}
public void SendChat(String Message, BasePlayer player, ConVar.Chat.ChatChannel channel = ConVar.Chat.ChatChannel.Global) {
if (IQChat) if (config.pluginSettings.ReferenceSettings.IQChatSetting.UIAlertUse) IQChat?.Call("API_ALERT_PLAYER_UI", player, Message);
else IQChat?.Call("API_ALERT_PLAYER", player, Message, config.pluginSettings.ReferenceSettings.IQChatSetting.CustomPrefix, config.pluginSettings.ReferenceSettings.IQChatSetting.CustomAvatar);
else player.SendConsoleCommand("chat.add", channel, 0, Message);
}
protected override void SaveConfig() => Config.WriteObject(config);
private static Configuration config = new Configuration();
public Int32 GetMultiplaceBurnableFuelSpeed(String ownerid) {
Int32 Multiplace = config.pluginSettings.RateSetting.SpeedFuelBurnable;
if (config.pluginSettings.RateSetting.UseSpeedBurnableList) {
var SpeedInList = config.pluginSettings.RateSetting.SpeedBurableList.OrderByDescending(z => z.SpeedFuelBurnable).FirstOrDefault(x => permission.UserHasPermission(ownerid, x.Permissions));
if (SpeedInList != null) Multiplace = SpeedInList.SpeedFuelBurnable;
}
return Multiplace;
}
void ReadData() => DataQuarryPlayer = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<UInt64, UInt64>>("IQSystem/IQRates/Quarrys");
public Dictionary<BasePlayer, Single> BonusRates = new Dictionary<BasePlayer, Single>();
private object OnOvenToggle(BaseOven oven, BasePlayer player) {
return OvenController.GetOrAdd(oven).Switch(player);
}
TOD_Time timeComponent = null;
public Dictionary<UInt64, UInt64> DataQuarryPlayer = new Dictionary<UInt64, UInt64>();
void StartEvent() {
var EventSettings = config.pluginSettings.OtherSetting.EventSetting;
StartCargoShip(EventSettings);
StartCargoPlane(EventSettings);
StartBreadley(EventSettings);
StartChinoock(EventSettings);
StartHelicopter(EventSettings);
}
protected override void LoadConfig() {
base.LoadConfig();
try {
config = Config.ReadObject<Configuration>();
if (config == null) LoadDefaultConfig();
if (config.pluginSettings.RateSetting.BlackListCategory == null) config.pluginSettings.RateSetting.BlackListCategory = new List<String>() {
"Weapon", "Ammunition", "Traps", "Attire", "Items", "Tools", "Component"
}
;
if (config.pluginSettings.RateSetting.WhiteList == null) {
config.pluginSettings.RateSetting.WhiteList = new List<String>() {
"wood", "sulfur.ore"
}
;
}
if (config.pluginSettings.RateSetting.RecyclersController.DefaultSpeedRecycler == 0f) config.pluginSettings.RateSetting.RecyclersController.DefaultSpeedRecycler = 5f;
if (config.pluginSettings.RateSetting.BlackListPrefabs == null || config.pluginSettings.RateSetting.BlackListPrefabs.Count == 0) config.pluginSettings.RateSetting.BlackListPrefabs = new List<String>() {
"crate_elite", "crate_normal"
}
;
if (config.pluginSettings.RateSetting.RecyclersController.PrivilageSpeedRecycler == null || config.pluginSettings.RateSetting.RecyclersController.PrivilageSpeedRecycler.Count == 0) {
config.pluginSettings.RateSetting.RecyclersController.PrivilageSpeedRecycler = new List<Configuration.PluginSettings.Rates.RecyclerController.PresetRecycler>() {
new Configuration.PluginSettings.Rates.RecyclerController.PresetRecycler() {
Permissions = "iqrates.recyclerhyperfast", SpeedRecyclers = 0
}
, new Configuration.PluginSettings.Rates.RecyclerController.PresetRecycler() {
Permissions = "iqrates.recyclerfast", SpeedRecyclers = 3
}
,
}
;
}
if (config.pluginSettings.RateSetting.DayRates.QuarryDetalis.ShortnameListQuarry.Count == 0) config.pluginSettings.RateSetting.DayRates.QuarryDetalis = new Configuration.PluginSettings.Rates.AllRates.QuarryRateDetalis() {
UseDetalisRateQuarry = false, ShortnameListQuarry = new Dictionary<String, Single>() {
["metal.ore"]
= 10, ["sulfur.ore"] = 5
}
}
;
if (config.pluginSettings.RateSetting.NightRates.QuarryDetalis.ShortnameListQuarry.Count == 0) config.pluginSettings.RateSetting.NightRates.QuarryDetalis = new Configuration.PluginSettings.Rates.AllRates.QuarryRateDetalis() {
UseDetalisRateQuarry = false, ShortnameListQuarry = new Dictionary<String, Single>() {
["metal.ore"]
= 10, ["sulfur.ore"] = 5
}
}
;
}
catch {
PrintWarning(LanguageEn ? "Error #334322343" + $"read configuration 'oxide/config/{Name}', create a new configuration!!" : "Ошибка #3332322343" + $"чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
void OnContainerDropItems(ItemContainer container) {
if (container == null) return;
var Container = container.entityOwner as LootContainer;
if (Container == null) return;
ulong NetID = Container.net.ID.Value;
if (LootersListCrateID.Contains(NetID)) return;
BasePlayer player = Container.lastAttacker as BasePlayer;
foreach (var item in container.itemList) item.amount = Converted(Types.Loot, item.info.shortname, item.amount, player);
}
private void UnSubProSub(int time = 1) {
Unsubscribe("OnEntitySpawned");
timer.Once(time, () => {
Subscribe("OnEntitySpawned");
}
);
}
private void OnRecyclerToggle(Recycler recycler, BasePlayer player) {
if (!recycler.IsOn()) {
NextTick(() => {
if (!recycler.IsOn()) return;
Single Speed = GetSpeedRecycler(player);
recycler.InvokeRepeating(recycler.RecycleThink, Speed, Speed);
}
);
}
}
private object OnExcavatorGather(ExcavatorArm arm, Item item) {
if (arm == null) return null;
if (item == null) return null;
item.amount = Converted(Types.Excavator, item.info.shortname, item.amount, ExcavatorPlayer);
return null;
}
private static StringBuilder sb = new StringBuilder();
bool IsPermission(string userID, string Permission) {
if (permission.UserHasPermission(userID, Permission)) return true;
else return false;
}
void OnExcavatorResourceSet(ExcavatorArm arm, string resourceName, BasePlayer player) {
if (arm == null || player == null) return;
ExcavatorPlayer = player;
}
void OnAirdrop(CargoPlane plane, Vector3 dropPosition) => plane.OwnerID = 999999999999;
void OnGrowableGathered(GrowableEntity plant, Item item, BasePlayer player) {
if (item == null || player == null) return;
item.amount = Converted(Types.Growable, item.info.shortname, item.amount, player);
}
void SpawnPlane() {
UnSubProSub();
var position = new Vector3(ConVar.Server.worldsize, 100, ConVar.Server.worldsize) - new Vector3(50f, 0f, 50f);
var entity = GameManager.server.CreateEntity(prefabPlane, position);
entity?.Spawn();
}
private void OnEntitySpawned(CargoShip entity) {
NextTick(() => {
if (entity.OwnerID != 0 || entity.skinID != 0) return;
var EvenTimer = config.pluginSettings.OtherSetting.EventSetting.CargoShipSetting;
if ((EvenTimer.FullOff || EvenTimer.UseEventCustom)) entity.Kill();
}
);
}
private const string prefabPlane = "assets/prefabs/npc/cargo plane/cargo_plane.prefab";
private void FuelSystemRating(EntityFuelSystem FuelSystem, Int32 Amount) {
if (FuelSystem == null) return;
NextTick(() => {
Item Fuel = FuelSystem.GetFuelItem();
if (Fuel == null) return;
if (Fuel.amount == 50 || Fuel.amount == 100) Fuel.amount = Amount;
}
);
}
void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player) {
foreach(ItemAmount item in collectible.itemList) item.amount = Converted(Types.PickUP, item.itemDef.shortname, (Int32)item.amount, player);
}
float GetRareCoal(BasePlayer player = null) {
Boolean IsTimes = IsTime();
var Rates = IsTimes ? config.pluginSettings.RateSetting.DayRates : config.pluginSettings.RateSetting.NightRates;
var PrivilegyRates = config.pluginSettings.RateSetting.PrivilegyRates;
if (player != null) {
foreach (var RatesSetting in PrivilegyRates) if (IsPermission(player.UserIDString, RatesSetting.Key)) Rates = IsTimes ? RatesSetting.Value.DayRates : RatesSetting.Value.NightRates;
}
float Rare = Rates.CoalRare;
float RareResult = (100 - Rare) / 100;
return RareResult;
}
void SpawnCH47() {
UnSubProSub();
var position = new Vector3(ConVar.Server.worldsize, 100, ConVar.Server.worldsize) - new Vector3(50f, 0f, 50f);
var entity = GameManager.server.CreateEntity(prefabCH47, position) as CH47HelicopterAIController;
entity?.TriggeredEventSpawn();
entity?.Spawn();
}
private void OnEntitySpawned(BradleyAPC entity) {
NextTick(() => {
if (entity.OwnerID != 0 || entity.skinID != 0) return;
var EvenTimer = config.pluginSettings.OtherSetting.EventSetting.BreadlaySetting;
if ((EvenTimer.FullOff || EvenTimer.UseEventCustom)) entity.Kill();
}
);
}
private void OnEntitySpawned(BaseSubmarine submarine) {
if (submarine == null) return;
FuelSystemRating(submarine.GetFuelSystem(), config.pluginSettings.OtherSetting.FuelSetting.AmountSubmarine);
submarine.maxFuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedSubmarine;
}
private Coroutine initializeTransport = null;
/// <summary>
/// Обновление 1.8.x
/// Изменения :
/// - Корректировка опреснителя воды
[PluginReference]
Plugin IQChat;
private BasePlayer ExcavatorPlayer = null;
private Single GetSpeedRecycler(BasePlayer player) {
Configuration.PluginSettings.Rates.RecyclerController Recycler = config.pluginSettings.RateSetting.RecyclersController;
foreach (Configuration.PluginSettings.Rates.RecyclerController.PresetRecycler presetRecycler in Recycler.PrivilageSpeedRecycler) {
if (permission.UserHasPermission(player.UserIDString, presetRecycler.Permissions)) return presetRecycler.SpeedRecyclers;
}
return Recycler.DefaultSpeedRecycler;
}
private void OnEntitySpawned(HotAirBalloon hotAirBalloon) {
if (hotAirBalloon == null) return;
hotAirBalloon.fuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedHotAirBalloon;
}
void API_BONUS_RATE_ADDPLAYER(BasePlayer player, Single Rate) {
if (player == null) return;
if (!BonusRates.ContainsKey(player)) BonusRates.Add(player, Rate);
else BonusRates[player] = Rate;
}
private void StartHelicopter(Configuration.PluginSettings.OtherSettings.EventSettings EventSettings) {
if (!EventSettings.HelicopterSetting.FullOff && EventSettings.HelicopterSetting.UseEventCustom) {
Int32 TimeSpawn = EventSettings.HelicopterSetting.RandomTimeSpawn.UseRandomTime ? GetRandomTime(EventSettings.HelicopterSetting.RandomTimeSpawn.MinEventSpawnTime, EventSettings.HelicopterSetting.RandomTimeSpawn.MaxEventSpawnTime) : EventSettings.HelicopterSetting.EventSpawnTime;
timer.Once(TimeSpawn, () => {
StartHelicopter(EventSettings);
SpawnHeli();
}
);
}
}
public Single GetMultiplaceBurnableSpeed(String ownerid) {
Single Multiplace = config.pluginSettings.RateSetting.SpeedBurnable;
if (config.pluginSettings.RateSetting.UseSpeedBurnableList) {
var SpeedInList = config.pluginSettings.RateSetting.SpeedBurableList.OrderByDescending(z => z.SpeedBurnable).FirstOrDefault(x => permission.UserHasPermission(ownerid, x.Permissions));
if (SpeedInList != null) Multiplace = SpeedInList.SpeedBurnable;
}
return Multiplace;
}
[ChatCommand("rates")]
private void GetInfoMyRates(BasePlayer player) {
if (player == null) return;
var PrivilegyRates = config.pluginSettings.RateSetting.PrivilegyRates;
Boolean IsTimes = IsTime();
var Rates = IsTimes ? config.pluginSettings.RateSetting.DayRates : config.pluginSettings.RateSetting.NightRates;
var CustomRate = IsTimes ? config.pluginSettings.RateSetting.CustomRatesPermissions.DayRates : config.pluginSettings.RateSetting.CustomRatesPermissions.NightRates;
var Rate = CustomRate.FirstOrDefault(x => IsPermission(player.UserIDString, x.Key));
foreach (var RatesSetting in PrivilegyRates) if (IsPermission(player.UserIDString, RatesSetting.Key)) Rates = IsTimes ? RatesSetting.Value.DayRates : RatesSetting.Value.NightRates;
SendChat(GetLang("MY_RATES_INFO", player.UserIDString, Rates.GatherRate, Rates.LootRate, Rates.PickUpRate, Rates.QuarryRate, Rates.ExcavatorRate, Rates.GrowableRate), player);
}
private Int32 GetRandomTime(Int32 Min, Int32 Max) => UnityEngine.Random.Range(Min, Max);
private void StartCargoPlane(Configuration.PluginSettings.OtherSettings.EventSettings EventSettings) {
if (!EventSettings.CargoPlaneSetting.FullOff && EventSettings.CargoPlaneSetting.UseEventCustom) {
Int32 TimeSpawn = EventSettings.CargoPlaneSetting.RandomTimeSpawn.UseRandomTime ? GetRandomTime(EventSettings.CargoPlaneSetting.RandomTimeSpawn.MinEventSpawnTime, EventSettings.CargoPlaneSetting.RandomTimeSpawn.MaxEventSpawnTime) : EventSettings.CargoPlaneSetting.EventSpawnTime;
timer.Once(TimeSpawn, () => {
StartCargoPlane(EventSettings);
SpawnPlane();
}
);
}
}
private const string prefabShip = "assets/content/vehicles/boats/cargoship/cargoshiptest.prefab";
private void OnEntitySpawned(CargoPlane entity) {
NextTick(() => {
if (entity.OwnerID != 0 || entity.skinID != 0) return;
var EvenTimer = config.pluginSettings.OtherSetting.EventSetting.CargoPlaneSetting;
if ((EvenTimer.FullOff || EvenTimer.UseEventCustom)) entity.Kill();
}
);
}
private void OnEntitySpawned(RHIB boat) {
if (boat == null) return;
boat.fuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedBoat;
}
private void OnEntitySpawned(MiniCopter copter) {
if (copter == null) return;
FuelSystemRating(copter.GetFuelSystem(), config.pluginSettings.OtherSetting.FuelSetting.AmountMinicopter);
copter.fuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedCopter;
}
int API_CONVERT(Types RateType, string Shortname, float Amount, BasePlayer player = null) => Converted(RateType, Shortname, Amount, player);
private class OvenController : FacepunchBehaviour {
private static readonly Dictionary<BaseOven, OvenController> Controllers = new Dictionary<BaseOven, OvenController>();
private BaseOven _oven;
private float _speed;
private string _ownerId;
private Int32 _ticks;
private Int32 _speedFuel;
private bool IsFurnace => (int)_oven.temperature >= 2;
private void Awake() {
_oven = (BaseOven)gameObject.ToBaseEntity();
_ownerId = _oven.OwnerID.ToString();
}
public object Switch(BasePlayer player) {
if (!IsFurnace || _oven.needsBuildingPrivilegeToUse && !player.CanBuild()) return null;
if (_oven.IsOn()) StopCooking();
else {
_ownerId = _oven.OwnerID != 0 ? _oven.OwnerID.ToString() : player.UserIDString;
StartCooking();
}
return false;
}
public void TryRestart() {
if (!_oven.IsOn()) return;
_oven.CancelInvoke(_oven.Cook);
StopCooking();
StartCooking();
}
private void Kill() {
if (_oven.IsOn()) {
StopCooking();
_oven.StartCooking();
}
Destroy(this);
}
public static OvenController GetOrAdd(BaseOven oven) {
OvenController controller;
if (Controllers.TryGetValue(oven, out controller)) return controller;
controller = oven.gameObject.AddComponent<OvenController>();
Controllers[oven] = controller;
return controller;
}
public static void TryRestartAll() {
foreach (var pair in Controllers) {
pair.Value.TryRestart();
}
}
public static void KillAll() {
foreach (var pair in Controllers) {
pair.Value.Kill();
}
Controllers.Clear();
}
public void OnDestroy() {
Destroy(this);
}
private void StartCooking() {
if(_oven.IndustrialMode != BaseOven.IndustrialSlotMode.ElectricFurnace) if (_oven.FindBurnable() == null) return;
Single Multiplace = _.GetMultiplaceBurnableSpeed(_ownerId);
_speed = (Single)(0.5f / Multiplace);
// 0.5 * M
Int32 MultiplaceFuel = _.GetMultiplaceBurnableFuelSpeed(_ownerId);
_speedFuel = MultiplaceFuel;
StopCooking();
_oven.inventory.temperature = _oven.cookingTemperature;
_oven.UpdateAttachmentTemperature();
InvokeRepeating(Cook, _speed, _speed);
_oven.SetFlag(BaseEntity.Flags.On, true);
}
private void StopCooking() {
CancelInvoke(Cook);
_oven.StopCooking();
_oven.SetFlag(BaseEntity.Flags.On, false);
_oven.SendNetworkUpdate();
if (_oven.inventory != null) {
foreach (Item item in _oven.inventory.itemList) {
if (item.HasFlag(global : : Item.Flag.Cooking)) item.SetFlag(global : : Item.Flag.Cooking, false);
item.MarkDirty();
}
}
}
public void Cook() {
if (!_oven.HasFlag(BaseEntity.Flags.On)) {
StopCooking();
return;
}
Item item = _oven.FindBurnable();
if (_oven.IndustrialMode != BaseOven.IndustrialSlotMode.ElectricFurnace) {
if (item == null) {
StopCooking();
return;
}
}
_oven.Cook();
SmeltItems();
if (_oven.IndustrialMode != BaseOven.IndustrialSlotMode.ElectricFurnace) {
var component = item.info.GetComponent<ItemModBurnable>();
item.fuel -= 0.5f * (_oven.cookingTemperature / 200f) * _speedFuel;
if (!item.HasFlag(global : : Item.Flag.OnFire)) {
item.SetFlag(global : : Item.Flag.OnFire, true);
item.MarkDirty();
}
if (item.fuel <= 0f) {
_oven.ConsumeFuel(item, component);
}
}
_ticks++;
}
private void SmeltItems() {
if (_ticks % 1 != 0) return;
for (var i = 0; i < _oven.inventory.itemList.Count; i++) {
var item = _oven.inventory.itemList[i];
if (item == null || !item.IsValid() || item.info == null) continue;
var cookable = item.info.GetComponent<ItemModCookable>();
if (cookable == null) continue;
if (_.IsBlackListBurnable(item.info.shortname)) continue;
Single temperature = item.temperature;
if ((temperature < cookable.lowTemp || temperature > cookable.highTemp)) {
if (!cookable.setCookingFlag || !item.HasFlag(global : : Item.Flag.Cooking)) continue;
item.SetFlag(global : : Item.Flag.Cooking, false);
item.MarkDirty();
continue;
}
if (!cookable.CanBeCookedByAtTemperature(temperature) && _.IsBlackListBurnable(item.info.shortname)) {
if (!cookable.setCookingFlag || !item.HasFlag(global : : Item.Flag.Cooking)) continue;
item.SetFlag(global : : Item.Flag.Cooking, false);
item.MarkDirty();
continue;
}
if (cookable.cookTime > 0 && _ticks * 1f / 1 % cookable.cookTime > 0) continue;
if (cookable.setCookingFlag && !item.HasFlag(global : : Item.Flag.Cooking)) {
item.SetFlag(global : : Item.Flag.Cooking, true);
item.MarkDirty();
}
var position = item.position;
if (item.amount > 1) {
item.amount--;
item.MarkDirty();
}
else {
item.Remove();
}
if (cookable.becomeOnCooked == null) continue;
var item2 = ItemManager.Create(cookable.becomeOnCooked, (int)(cookable.amountOfBecome * 1f));
if (item2 == null || item2.MoveToContainer(item.parent, position) || item2.MoveToContainer(item.parent)) continue;
item2.Drop(item.parent.dropPosition, item.parent.dropVelocity);
//if (!item.parent.entityOwner) continue;
StopCooking();
}
}
}
int API_CONVERT_GATHER(string Shortname, float Amount, BasePlayer player = null) => Converted(Types.Gather, Shortname, Amount, player);
int Converted(Types RateType, string Shortname, float Amount, BasePlayer player = null, String UserID = null) {
float ConvertedAmount = Amount;
ItemDefinition definition = ItemManager.FindItemDefinition(Shortname);
if(definition != null && !IsWhiteList(Shortname)) foreach (String BlackItemCategory in config.pluginSettings.RateSetting.BlackListCategory) {
ItemCategory Category;
if (!Enum.TryParse(BlackItemCategory, out Category)) continue;
if (Category == definition.category) {
//PrintToChat($"DEBUG : Категория {BlackItemCategory} заблокирована для множителя");
return Convert.ToInt32(ConvertedAmount);
}
}
if (config.pluginSettings.RateSetting.TypeList == TypeListUsed.BlackList) {
if (IsBlackList(Shortname)) return Convert.ToInt32(ConvertedAmount);
}
else {
if (!IsWhiteList(Shortname)) {
//PrintToChat($"DEBUG : Предмет {Shortname} заблокирована для #278137173 множителя");
return Convert.ToInt32(ConvertedAmount);
}
}
var PrivilegyRates = config.pluginSettings.RateSetting.PrivilegyRates;
Boolean IsTimes = IsTime();
Configuration.PluginSettings.Rates.AllRates Rates = IsTimes ? config.pluginSettings.RateSetting.DayRates : config.pluginSettings.RateSetting.NightRates;
UserID = player != null ? player.UserIDString : UserID;
if (UserID != null) {
var CustomRate = IsTimes ? config.pluginSettings.RateSetting.CustomRatesPermissions.DayRates : config.pluginSettings.RateSetting.CustomRatesPermissions.NightRates;
var Rate = CustomRate.FirstOrDefault(x => IsPermission(UserID, x.Key));
//dbg
if (Rate.Value != null) foreach (var RateValue in Rate.Value.Where(x => x.Shortname == Shortname)) {
ConvertedAmount = Amount * RateValue.Rate;
return (int)ConvertedAmount;
}
foreach (var RatesSetting in PrivilegyRates) if (IsPermission(UserID, RatesSetting.Key)) Rates = IsTimes ? RatesSetting.Value.DayRates : RatesSetting.Value.NightRates;
}
Single BonusRate = GetBonusRate(player);
switch (RateType) {
case Types.Gather : {
ConvertedAmount = Amount * (Rates.GatherRate + BonusRate);
break;
}
case Types.Loot : {
ConvertedAmount = Amount * (Rates.LootRate + BonusRate);
break;
}
case Types.PickUP : {
ConvertedAmount = Amount * (Rates.PickUpRate + BonusRate);
break;
}
case Types.Growable : {
ConvertedAmount = Amount * (Rates.GrowableRate + BonusRate);
break;
}
case Types.Quarry : {
Single QuarryRates = GetRateQuarryDetalis(Rates, Shortname);
ConvertedAmount = Amount * (QuarryRates + BonusRate);
break;
}
case Types.Excavator : {
ConvertedAmount = Amount * (Rates.ExcavatorRate + BonusRate);
break;
}
}
return Convert.ToInt32(ConvertedAmount);
}
void OnQuarryToggled(MiningQuarry quarry, BasePlayer player) {
AddQuarryPlayer(quarry.net.ID.Value, player.userID);
}
void OnDispenserBonus(ResourceDispenser disp, BasePlayer player, Item item) {
if (item == null || player == null) return;
int Rate = Converted(Types.Gather, item.info.shortname, item.amount, player);
item.amount = Rate;
}
void OnLootEntity(BasePlayer player, BaseEntity entity) {
if (entity == null) return;
if(config.pluginSettings.RateSetting.UseBlackListPrefabs) if (config.pluginSettings.RateSetting.BlackListPrefabs.Contains(entity.ShortPrefabName)) return;
LootContainer container = entity as LootContainer;
if (entity.net == null) return;
UInt64 NetID = entity.net.ID.Value;
if (LootersListCrateID.Contains(NetID)) return;
if (container == null) {
if (!(entity is NPCPlayerCorpse)) return;
NPCPlayerCorpse corpse = (NPCPlayerCorpse)entity;
foreach (ItemContainer corpseContainer in corpse.containers) {
foreach (Item item in corpseContainer.itemList) item.amount = Converted(Types.Loot, item.info.shortname, item.amount, player);
}
}
else {
foreach (Item item in container.inventory.itemList) item.amount = Converted(Types.Loot, item.info.shortname, item.amount, player);
}
LootersListCrateID.Add(NetID);
}
private new void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["MY_RATES_INFO"]
= "Your resource rating at the moment :" + "\n- Rating of extracted resources: <color=#FAF0F5>x{0}</color>" + "\n- Rating of found items: <color=#FAF0F5>х{1}</color>" + "\n- Rating of raised items: <color=#FAF0F5>х{2}</color>" + "\n- Career rankings: <color=#FAF0F5>x{3}</color>" + "\n- Excavator Rating: <color=#FAF0F5>x{4}</color>" + "\n- Rating of growable : <color=#FAF0F5>x{5}</color>", ["DAY_RATES_ALERT"] = "The day has come!" + "\nThe global rating on the server has been changed :" + "\n- Rating of extracted resources: <color=#FAF0F5>x{0}</color>" + "\n- Rating of found items: <color=#FAF0F5>х{1}</color>" + "\n- Rating of raised items: <color=#FAF0F5>х{2}</color>" + "\n- Career rankings: <color=#FAF0F5>x{3}</color>" + "\n- Excavator Rating: <color=#FAF0F5>x{4}</color>" + "\n- Rating of growable : <color=#FAF0F5>x{5}</color>", ["NIGHT_RATES_ALERT"] = "Night came!" + "\nThe global rating on the server has been changed :" + "\n- Rating of extracted resources: <color=#FAF0F5>x{0}</color>" + "\n- Rating of found items: <color=#FAF0F5>х{1}</color>" + "\n- Rating of raised items: <color=#FAF0F5>х{2}</color>" + "\n- Career rankings: <color=#FAF0F5>x{3}</color>" + "\n- Excavator Rating: <color=#FAF0F5>x{4}</color>" + "\n- Rating of growable : <color=#FAF0F5>x{5}</color>",
}
, this);
lang.RegisterMessages(new Dictionary<string, string> {
["MY_RATES_INFO"]
= "Ваш рейтинг ресурсов на данный момент :" + "\n- Рейтинг добываемых ресурсов: <color=#FAF0F5>x{0}</color>" + "\n- Рейтинг найденных предметов: <color=#FAF0F5>х{1}</color>" + "\n- Рейтинг поднимаемых предметов: <color=#FAF0F5>х{2}</color>" + "\n- Рейтинг карьеров: <color=#FAF0F5>x{3}</color>" + "\n- Рейтинг экскаватора: <color=#FAF0F5>x{4}</color>" + "\n- Рейтинг грядок : <color=#FAF0F5>x{5}</color>", ["DAY_RATES_ALERT"] = "Наступил день!" + "\nГлобальный рейтинг на сервере был изменен :" + "\n- Рейтинг добываемых ресурсов: <color=#FAF0F5>x{0}</color>" + "\n- Рейтинг найденных предметов: <color=#FAF0F5>х{1}</color>" + "\n- Рейтинг поднимаемых предметов: <color=#FAF0F5>х{2}</color>" + "\n- Рейтинг карьеров: <color=#FAF0F5>x{3}</color>" + "\n- Рейтинг экскаватора: <color=#FAF0F5>x{4}</color>" + "\n- Рейтинг грядок : <color=#FAF0F5>x{5}</color>", ["NIGHT_RATES_ALERT"] = "Наступила ночь!" + "\nГлобальный рейтинг на сервере был изменен :" + "\n- Рейтинг добываемых ресурсов: <color=#FAF0F5>x{0}</color>" + "\n- Рейтинг найденных предметов: <color=#FAF0F5>х{1}</color>" + "\n- Рейтинг поднимаемых предметов: <color=#FAF0F5>х{2}</color>" + "\n- Рейтинг карьеров: <color=#FAF0F5>x{3}</color>" + "\n- Рейтинг экскаватора: <color=#FAF0F5>x{4}</color>" + "\n- Рейтинг грядок : <color=#FAF0F5>x{5}</color>",
}
, this, "ru");
}
private const string prefabPatrol = "assets/prefabs/npc/patrol helicopter/patrolhelicopter.prefab";
void OnHour() {
if (TOD_Sky.Instance.Cycle.Hour > TOD_Sky.Instance.SunriseTime && TOD_Sky.Instance.Cycle.Hour < TOD_Sky.Instance.SunsetTime && TOD_Sky.Instance.Cycle.Hour >= config.pluginSettings.OtherSetting.DayStart && !activatedDay) {
OnSunrise();
return;
}
if ((TOD_Sky.Instance.Cycle.Hour > TOD_Sky.Instance.SunsetTime || TOD_Sky.Instance.Cycle.Hour < TOD_Sky.Instance.SunriseTime) && TOD_Sky.Instance.Cycle.Hour >= config.pluginSettings.OtherSetting.NightStart && activatedDay) {
OnSunset();
return;
}
}
bool IsBlackList(string Shortname) {
var BlackList = config.pluginSettings.RateSetting.BlackList;
if (BlackList.Contains(Shortname)) return true;
else return false;
}
private readonly Dictionary<String, ModiferTea> TeaModifers = new Dictionary<String, ModiferTea> {
["oretea.advanced"]
= new ModiferTea() {
Duration = 1800f, Value = 0.35f, Type = Modifier.ModifierType.Ore_Yield
}
, ["oretea"] = new ModiferTea() {
Duration = 1800f, Value = 0.2f, Type = Modifier.ModifierType.Ore_Yield
}
, ["oretea.pure"] = new ModiferTea() {
Duration = 1800f, Value = 0.5f, Type = Modifier.ModifierType.Ore_Yield
}
, ["woodtea.advanced"] = new ModiferTea() {
Duration = 1800f, Value = 1.0f, Type = Modifier.ModifierType.Wood_Yield
}
, ["woodtea"] = new ModiferTea() {
Duration = 1800f, Value = 0.5f, Type = Modifier.ModifierType.Wood_Yield
}
, ["woodtea.pure"] = new ModiferTea() {
Duration = 1800f, Value = 2.0f, Type = Modifier.ModifierType.Wood_Yield
}
, ["scraptea.advanced"] = new ModiferTea() {
Duration = 2700f, Value = 2.25f, Type = Modifier.ModifierType.Scrap_Yield
}
, ["scraptea"] = new ModiferTea() {
Duration = 1800f, Value = 1.0f, Type = Modifier.ModifierType.Scrap_Yield
}
, ["scraptea.pure"] = new ModiferTea() {
Duration = 3600f, Value = 3.5f, Type = Modifier.ModifierType.Scrap_Yield
}
,
}
;
void OnSunrise() {
timeComponent.DayLengthInMinutes = config.pluginSettings.OtherSetting.DayTime * (24.0f / (TOD_Sky.Instance.SunsetTime - TOD_Sky.Instance.SunriseTime));
activatedDay = true;
if (config.pluginSettings.OtherSetting.UseSkipTime) {
if (config.pluginSettings.OtherSetting.TypeSkipped == SkipType.Day) TOD_Sky.Instance.Cycle.Hour = config.pluginSettings.OtherSetting.NightStart;
else {
if (config.pluginSettings.OtherSetting.UseAlertDayNight) {
Configuration.PluginSettings.Rates.AllRates Rate = config.pluginSettings.RateSetting.DayRates;
foreach (BasePlayer player in BasePlayer.activePlayerList) SendChat(GetLang("DAY_RATES_ALERT", player.UserIDString, Rate.GatherRate, Rate.LootRate, Rate.PickUpRate, Rate.QuarryRate, Rate.ExcavatorRate, Rate.GrowableRate), player);
}
}
return;
}
if (config.pluginSettings.OtherSetting.UseAlertDayNight) {
Configuration.PluginSettings.Rates.AllRates Rate = config.pluginSettings.RateSetting.DayRates;
foreach (BasePlayer player in BasePlayer.activePlayerList) SendChat(GetLang("DAY_RATES_ALERT", player.UserIDString, Rate.GatherRate, Rate.LootRate, Rate.PickUpRate, Rate.QuarryRate, Rate.ExcavatorRate, Rate.GrowableRate), player);
}
}
void API_BONUS_RATE_ADDPLAYER(UInt64 userID, Single Rate) {
BasePlayer player = BasePlayer.FindByID(userID);
API_BONUS_RATE_ADDPLAYER(player, Rate);
}
private const string prefabCH47 = "assets/prefabs/npc/ch47/ch47scientists.entity.prefab";
public string GetLang(string LangKey, string userID = null, params object[] args) {
sb.Clear();
if (args != null) {
sb.AppendFormat(lang.GetMessage(LangKey, this, userID), args);
return sb.ToString();
}
return lang.GetMessage(LangKey, this, userID);
}
object OnContainerDropGrowable(ItemContainer container, Item item) {
if (container == null) return false;
var Container = container.entityOwner as LootContainer;
if (Container == null) return false;
ulong NetID = Container.net.ID.Value;
if (NetID == 14321199 && item.info.itemid == 1998363) return false;
return null;
}
public enum SkipType {
Day, Night
}
UInt64? GetQuarryPlayer(UInt64 NetID) {
if (!DataQuarryPlayer.ContainsKey(NetID)) return null;
if (DataQuarryPlayer[NetID] == 0) return null;
return DataQuarryPlayer[NetID];
}
Single GetRateQuarryDetalis(Configuration.PluginSettings.Rates.AllRates Rates, String Shortname) {
Single Rate = Rates.QuarryRate;
if (!Rates.QuarryDetalis.UseDetalisRateQuarry) return Rate;
return Rates.QuarryDetalis.ShortnameListQuarry.ContainsKey(Shortname) ? Rates.QuarryDetalis.ShortnameListQuarry[Shortname] : Rate;
}
bool IsTime() {
var Settings = config.pluginSettings.OtherSetting;
float TimeServer = TOD_Sky.Instance.Cycle.Hour;
return TimeServer < Settings.NightStart && Settings.DayStart <= TimeServer;
}
private void OnEntitySpawned(MotorRowboat boat) {
if (boat == null) return;
boat.fuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedBoat;
}
private void OnEntitySpawned(TrainCar trainCar) {
if (trainCar == null) return;
StorageContainer fuelContainer = trainCar.GetFuelSystem()?.GetFuelContainer();
if (fuelContainer == null) return;
TrainEngine trainEngine = fuelContainer.GetComponent<TrainEngine>();
if (trainEngine == null) return;
trainEngine.maxFuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedTrain;
}
private void OnEntitySpawned(Snowmobile snowmobiles) {
if (snowmobiles == null) return;
snowmobiles.maxFuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedSnowmobile;
}
public enum TypeListUsed {
WhiteList, BlackList
}
private object OnPlayerAddModifiers(BasePlayer player, Item item, ItemModConsumable consumable) {
if (!TeaModifers.ContainsKey(item.info.shortname)) return true;
List<ModifierDefintion> mods = Pool.GetList<ModifierDefintion>();
Dictionary<String, Configuration.PluginSettings.Rates.DayAnNightRate> PrivilegyRates = config.pluginSettings.RateSetting.PrivilegyRates;
Boolean IsTimes = IsTime();
Configuration.PluginSettings.Rates.AllRates Rates = IsTimes ? config.pluginSettings.RateSetting.DayRates : config.pluginSettings.RateSetting.NightRates;
Configuration.PluginSettings.Rates.AllRates DefaultRates = IsTimes ? config.pluginSettings.RateSetting.DayRates : config.pluginSettings.RateSetting.NightRates;
Single ModiferDifference = 1.0f;
Single DefaultRate = 1.0f;
Single PlayerRate = 1.0f;
foreach (var RatesSetting in PrivilegyRates) if (IsPermission(player.UserIDString, RatesSetting.Key)) Rates = IsTimes ? RatesSetting.Value.DayRates : RatesSetting.Value.NightRates;
Single BonusRate = GetBonusRate(player);
ModiferTea TeaLocal = TeaModifers[item.info.shortname];
switch (TeaLocal.Type) {
case Modifier.ModifierType.Ore_Yield : {
DefaultRate = DefaultRates.GatherRate;
PlayerRate = Rates.GatherRate + BonusRate;
ModiferDifference = (PlayerRate - DefaultRate) <= 0 ? 1 : (PlayerRate - DefaultRate);
mods.Add(GetDefintionModifer(TeaLocal.Type, TeaLocal.Duration, TeaLocal.Value / ModiferDifference));
break;
}
case Modifier.ModifierType.Wood_Yield : {
DefaultRate = DefaultRates.GatherRate;
PlayerRate = Rates.GatherRate + BonusRate;
ModiferDifference = (PlayerRate - DefaultRate) <= 0 ? 1 : (PlayerRate - DefaultRate);
mods.Add(GetDefintionModifer(TeaLocal.Type, TeaLocal.Duration, TeaLocal.Value / ModiferDifference));
break;
}
case Modifier.ModifierType.Scrap_Yield : {
DefaultRate = DefaultRates.LootRate;
PlayerRate = Rates.LootRate + BonusRate;
ModiferDifference = (PlayerRate - DefaultRate) <= 0 ? 1 : (PlayerRate - DefaultRate);
mods.Add(GetDefintionModifer(TeaLocal.Type, TeaLocal.Duration, TeaLocal.Value / ModiferDifference));
break;
}
}
player.modifiers.Add(mods);
Pool.FreeList(ref mods);
return true;
}
object OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
BasePlayer player = entity as BasePlayer;
if (item == null || player == null) return null;
Int32 Rate = Converted(Types.Gather, item.info.shortname, item.amount, player);
item.amount = Rate;
return null;
}
void AddQuarryPlayer(UInt64 NetID, UInt64 userID) {
if (DataQuarryPlayer.ContainsKey(NetID)) DataQuarryPlayer[NetID] = userID;
else DataQuarryPlayer.Add(NetID, userID);
WriteData();
}
private void OnEntitySpawned(ScrapTransportHelicopter helicopter) {
if (helicopter == null) return;
FuelSystemRating(helicopter.GetFuelSystem(), config.pluginSettings.OtherSetting.FuelSetting.AmountScrapTransport);
helicopter.fuelPerSec = config.pluginSettings.OtherSetting.FuelConsumedTransportSetting.ConsumedScrapTransport;
}
private void OnServerInitialized() {
_ = this;
SpacePort = TerrainMeta.Path.Monuments.FirstOrDefault(p => p.name.ToLower().Contains("launch_site"));
StartEvent();
foreach (var RateCustom in config.pluginSettings.RateSetting.PrivilegyRates) Register(RateCustom.Key);
foreach (Configuration.PluginSettings.Rates.RecyclerController.PresetRecycler presetRecycler in config.pluginSettings.RateSetting.RecyclersController.PrivilageSpeedRecycler) Register(presetRecycler.Permissions);
if (config.pluginSettings.RateSetting.UseSpeedBurnableList) foreach (var BurnableList in config.pluginSettings.RateSetting.SpeedBurableList) Register(BurnableList.Permissions);
List<String> PrivilegyCustomRatePermissions = config.pluginSettings.RateSetting.CustomRatesPermissions.NightRates.Keys.Union(config.pluginSettings.RateSetting.CustomRatesPermissions.DayRates.Keys).ToList();
foreach (var RateItemCustom in PrivilegyCustomRatePermissions) Register(RateItemCustom);
timer.Once(5, GetTimeComponent);
foreach (BaseOven oven in BaseNetworkable.serverE
// ... [Code preview truncated due to length. Full source in attached file] ...