C#:
using Network;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Oxide.Core.Plugins;
using UnityEngine;
using Formatter = Oxide.Core.Libraries.Covalence.Formatter;
namespace Oxide.Plugins {
[Info("RatesController", "TopPlugin.ru", "3.0.8")]
[Description("All-in-one customizable rate system for the server")]
/*
* Author info:
* Forum: https://topplugin.ru/
* Vk: https://vk.com/rustnastroika
*/
class RatesController : RustPlugin {
#region Vars
private static PluginConfig _config;
private static RatesController _ratesController;
private PluginData _data;
private bool _isDay = true;
private Dictionary<ItemModCookable, float> _smeltRatesBackup = new Dictionary<ItemModCookable, float>();
private Dictionary<uint, string> _quarryOwners = new Dictionary<uint, string>();
private Dictionary<Item, CustomCookable> _customCookables = new Dictionary<Item, CustomCookable>();
private CoalConfig _defaultCoal;
private static class Constants {
public const string ExcavatorArmPrefab = "assets/content/structures/excavator/prefabs/excavator_yaw.prefab";
}
#endregion
#region Configuration
#region Rates
private sealed class RateType {
private readonly string _name;
private RateType(string name) {
_name = name;
}
public override string ToString() {
return _name;
}
public static implicit operator string(RateType type) => type._name;
public static readonly RateType Quarry = new RateType("Добываемые ресурсы в карьере");
public static readonly RateType Excavator = new RateType("Добываемые ресурсы в экскаваторе");
public static readonly RateType Gather = new RateType("Добываемые ресурсы");
public static readonly RateType Loot = new RateType("Получаемый лут");
public static readonly RateType Pickup = new RateType("Подбираемые ресурсы");
public static readonly RateType OvenSpeed = new RateType("Скорость печей");
public static readonly RateType[] Available = {
Quarry, Excavator, Gather, Loot, Pickup, OvenSpeed
}
;
}
private class Rates {
[JsonProperty("Днём")]
private Dictionary<string, float> _day = new Dictionary<string, float>();
[JsonProperty("Ночью")]
private Dictionary<string, float> _night = new Dictionary<string, float>();
public float GetRate(RateType type, bool day = true) {
var dict = day ? _day : _night;
float val;
return dict.TryGetValue(type, out val) ? val : 1f;
}
#region Default Сonfig
public static Rates Default => DefaultWith(1f);
public static Rates DefaultWith(float rate) => new Rates {
_day = RateType.Available.ToDictionary(x => (string) x, x => rate), _night = RateType.Available.ToDictionary(x => (string) x, x => rate)
}
;
#endregion
}
#endregion
#region Server Time Config
private class SavedDateConfig {
[JsonProperty("Устанавливать дату при запуске плагина")]
public bool Use;
[JsonProperty("День")]
private int _day;
[JsonProperty("Месяц")]
private int _month;
[JsonProperty("Год")]
private int _year;
[JsonProperty("Час")]
private int _hour;
[JsonProperty("Минута")]
private int _minute;
[JsonProperty("Секунда")]
private int _second;
[JsonIgnore]
public DateTime Date;
#region Default Config
public static SavedDateConfig DefaultConfig {
get {
var now = DateTime.Now;
return new SavedDateConfig {
Use = false, _day = now.Day, _month = now.Month, _year = now.Year, _hour = 12, _minute = 0, _second = 0
}
;
}
}
#endregion
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context) {
Date = new DateTime(_year, _month, _day, _hour, _minute, _second);
}
}
private class DayNightSwitchConfig {
[JsonProperty("Рассчитывать время по закату/восходу (false - по часам)")]
public bool UseSun;
[JsonProperty("Час начала дня (игровое время)")]
public int DayStartHour;
[JsonProperty("Час начала ночи (игровое время)")]
public int NightStartHour;
#region Default Config
public static DayNightSwitchConfig DefaultConfig => new DayNightSwitchConfig {
UseSun = true, DayStartHour = 6, NightStartHour = 18
}
;
#endregion
[JsonIgnore]
public float DayMultiplier;
[JsonIgnore]
public float NightMultiplier;
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context) {
DayMultiplier = 24.0f / (NightStartHour - DayStartHour);
NightMultiplier = 24.0f / (24.0f - (NightStartHour - DayStartHour));
}
}
private class TimeConfig {
[JsonProperty("Длина дня (в минутах)")]
public int DayLength;
[JsonProperty("Длина ночи (в минутах)")]
public int NightLength;
[JsonProperty("Настройки смены дня/ночи")]
public DayNightSwitchConfig DayNightSwitchConfig;
[JsonProperty("Восстанавливать состояние времени при запуске плагина")]
public bool RestoreState;
[JsonProperty("Устанавливаемая при запуске плагина дата")]
public SavedDateConfig SavedDateConfig;
#region Default Config
public static TimeConfig DefaultConfig => new TimeConfig {
DayLength = 30, NightLength = 30, DayNightSwitchConfig = DayNightSwitchConfig.DefaultConfig, RestoreState = true, SavedDateConfig = SavedDateConfig.DefaultConfig
}
;
#endregion
}
#endregion
#region General Options
// ... [Code preview truncated due to length. Full source in attached file] ...