C#:
// #define TESTING
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Facepunch;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Random = UnityEngine.Random;
using Time = UnityEngine.Time;
#if TESTING
using System.Diagnostics;
#endif
#if CARBON
using Carbon.Base;
using Carbon.Modules;
#endif
namespace Oxide.Plugins {
[Info("Cases", "Mevent", "1.1.15")]
public class Cases : RustPlugin {
#region Fields
[PluginReference]
private Plugin ImageLibrary = null, PlaytimeTracker = null, UINotify = null, Notify = null;
private const string PERM_EDIT = "Cases.edit", Layer = "UI.Cases", ModalLayer = "UI.Cases.Modal";
private static Cases _instance;
#if CARBON
private ImageDatabaseModule imageDatabase;
#endif
private bool _enabledImageLibrary;
private const bool LangRu = true;
private const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
private readonly Dictionary<int, CaseEntry> _casesByIDs = new();
private readonly Dictionary<string, List<(int itemID, string shortName)>> _itemsCategories = new();
private readonly Dictionary<ulong, PlayerItemsData> _playersItems = new();
private class PlayerItemsData {
public int CaseId;
public List<ItemInfo> Items;
public PlayerItemsData(int caseId, List<ItemInfo> items) {
CaseId = caseId;
Items = items;
}
}
private readonly Dictionary<int, ItemInfo> _itemByIDs = new();
private readonly Dictionary<BasePlayer, float> TimePlayers = new();
#endregion
#region Config
private Configuration _config;
private class Configuration {
[JsonProperty(PropertyName = LangRu ? "Включить прокрутку предметов?" : "Enable item scrolling?")]
public bool Scrolling = true;
[JsonProperty(PropertyName = LangRu ? "Работать с Notify?" : "Work with Notify?")]
public bool UseNotify = true;
[JsonProperty(PropertyName = LangRu ? "Разрешение (например: cases.use)" : "Permission (ex: cases.use)")]
public string Permission = string.Empty;
[JsonProperty(PropertyName = LangRu ? "Количество предметов в рулетке" : "Amount of items in the roulette")]
public int AmountItems = 26;
[JsonProperty(PropertyName = LangRu ? "Команды" : "Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] Commands = {
"cases", "opencase"
}
;
[JsonProperty(PropertyName = LangRu ? "Экономика" : "Economy")]
public EconomyConf Economy = new() {
Type = EconomyType.Plugin, AddHook = "Deposit", BalanceHook = "Balance", RemoveHook = "Withdraw", Plug = "Economics", ShortName = "scrap", DisplayName = string.Empty, Skin = 0, Show = true
}
;
[JsonProperty(PropertyName = LangRu ? "Цвета редкости (шанс - цвет)" : "Rarity Colors (chance - color)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<float, IColor> Rarity = new() {
[70]
= new IColor("#AFAFAF", 75), [65] = new IColor("#6496E1", 75), [55] = new IColor("#4B69CD", 75), [50] = new IColor("#8847FF", 75), [45] = new IColor("#8847FF", 75), [40] = new IColor("#8847FF", 75), [35] = new IColor("#8847FF", 75), [30] = new IColor("#8847FF", 75), [25] = new IColor("#8847FF", 75), [20] = new IColor("#D32CE6", 75), [15] = new IColor("#D32CE6", 75), [10] = new IColor("#D32CE6", 75), [5] = new IColor("#EB4B4B", 75)
}
;
[JsonProperty(PropertyName = LangRu ? "Настройки трекера времени игры" : "Playtime Tracker Settings")]
public PlaytimeTrackerSettings PlaytimeTrackerConf = new() {
Enabled = true, Cases = new Dictionary<int, int> {
[3600]
= 1, [14400] = 2, [28800] = 3, [86400] = 4
}
}
;
[JsonProperty(PropertyName = LangRu ? "Настройки кейсов по времени" : "Cases for time settings")]
public TimeCasesSettings TimeCasesSettings = new() {
Enable = false, Cooldown = 14400, Cases = new List<int> {
1, 2, 3, 4, 5
}
}
;
[JsonProperty(PropertyName = LangRu ? "Бонусный кейс" : "Bonus Case")]
public BonusCaseEntry BonusCase = new() {
Enabled = true, ID = -1, Title = "Bonus Case", Image = "https://i.ibb.co/JCWHDmF/n4I3vI0.png", Permission = string.Empty, CooldownTime = 86400, Cost = 0, CustomCurrency = new CustomCurrency {
Enabled = false, CostFormat = "{0} scrap", Type = EconomyType.Item, Plug = string.Empty, AddHook = string.Empty, RemoveHook = string.Empty, BalanceHook = string.Empty, ShortName = "scrap", DisplayName = string.Empty, Skin = 0
}
, Items = new List<ItemInfo> {
new() {
Type = ItemType.Item, ID = 1, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "wood", Skin = 0, Amount = 3500, Chance = 70
}
, new() {
Type = ItemType.Item, ID = 2, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "stones", Skin = 0, Amount = 2500, Chance = 70
}
, new() {
Type = ItemType.Item, ID = 3, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "leather", Skin = 0, Amount = 1000, Chance = 55
}
, new() {
Type = ItemType.Item, ID = 4, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "cloth", Skin = 0, Amount = 1000, Chance = 55
}
, new() {
Type = ItemType.Item, ID = 5, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "lowgradefuel", Skin = 0, Amount = 500, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 6, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "metal.fragments", Skin = 0, Amount = 1500, Chance = 65
}
, new() {
Type = ItemType.Item, ID = 7, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "metal.refined", Skin = 0, Amount = 150, Chance = 65
}
, new() {
Type = ItemType.Item, ID = 8, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "sulfur", Skin = 0, Amount = 2500, Chance = 55
}
, new() {
Type = ItemType.Item, ID = 9, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "gunpowder", Skin = 0, Amount = 1500, Chance = 45
}
, new() {
Type = ItemType.Item, ID = 10, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "explosive.timed", Skin = 0, Amount = 1, Chance = 5
}
}
}
;
[JsonProperty(PropertyName = LangRu ? "Кейсы" : "Cases", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<CaseEntry> Cases = new() {
new CaseEntry {
ID = 1, Title = "ALTAIR", Image = "https://i.ibb.co/2cWDKYL/0p9qwot.png", Permission = string.Empty, Cost = 100, CustomCurrency = new CustomCurrency {
Enabled = false, CostFormat = "{0} scrap", Type = EconomyType.Item, Plug = string.Empty, AddHook = string.Empty, RemoveHook = string.Empty, BalanceHook = string.Empty, ShortName = "scrap", DisplayName = string.Empty, Skin = 0
}
, Items = new List<ItemInfo> {
new() {
Type = ItemType.Item, ID = 11, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "metalblade", Skin = 0, Amount = 40, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 12, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "sewingkit", Skin = 0, Amount = 30, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 14, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "roadsigns", Skin = 0, Amount = 15, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 15, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "metalpipe", Skin = 0, Amount = 20, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 16, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "gears", Skin = 0, Amount = 15, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 17, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "smgbody", Skin = 0, Amount = 5, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 18, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "smgbody", Skin = 0, Amount = 5, Chance = 20
}
, new() {
Type = ItemType.Item, ID = 19, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "metalspring", Skin = 0, Amount = 20, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 20, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "semibody", Skin = 0, Amount = 3, Chance = 15
}
, new() {
Type = ItemType.Item, ID = 21, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "techparts", Skin = 0, Amount = 10, Chance = 25
}
, new() {
Type = ItemType.Item, ID = 22, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "riflebody", Skin = 0, Amount = 10, Chance = 5
}
}
}
, new CaseEntry {
ID = 2, Title = "SCHEDAR", Image = "https://i.ibb.co/17QPX15/rADqKVZ.png", Permission = string.Empty, Cost = 150, CustomCurrency = new CustomCurrency {
Enabled = false, CostFormat = "{0} scrap", Type = EconomyType.Item, Plug = string.Empty, AddHook = string.Empty, RemoveHook = string.Empty, BalanceHook = string.Empty, ShortName = "scrap", DisplayName = string.Empty, Skin = 0
}
, Items = new List<ItemInfo> {
new() {
Type = ItemType.Item, ID = 43, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "scrap", Skin = 0, Amount = 500, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 44, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "gunpowder", Skin = 0, Amount = 3500, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 45, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.ak", Skin = 0, Amount = 1, Chance = 15
}
, new() {
Type = ItemType.Item, ID = 46, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.semiauto", Skin = 0, Amount = 1, Chance = 20
}
, new() {
Type = ItemType.Item, ID = 47, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "explosive.timed", Skin = 0, Amount = 5, Chance = 20
}
, new() {
Type = ItemType.Item, ID = 48, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "sulfur", Skin = 0, Amount = 5000, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 49, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "metal.refined", Skin = 0, Amount = 300, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 50, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "stones", Skin = 0, Amount = 8000, Chance = 60
}
, new() {
Type = ItemType.Item, ID = 51, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "wood", Skin = 0, Amount = 8000, Chance = 60
}
, new() {
Type = ItemType.Item, ID = 52, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "lmg.m249", Skin = 0, Amount = 1, Chance = 5
}
, new() {
Type = ItemType.Item, ID = 53, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "ammo.rocket.basic", Skin = 0, Amount = 4, Chance = 50
}
}
}
, new CaseEntry {
ID = 3, Title = "COR CAROLI", Image = "https://i.ibb.co/Y7NmQcC/ojg7Sn5.png", Permission = string.Empty, Cost = 200, CustomCurrency = new CustomCurrency {
Enabled = false, CostFormat = "{0} scrap", Type = EconomyType.Item, Plug = string.Empty, AddHook = string.Empty, RemoveHook = string.Empty, BalanceHook = string.Empty, ShortName = "scrap", DisplayName = string.Empty, Skin = 0
}
, Items = new List<ItemInfo> {
new() {
Type = ItemType.Item, ID = 23, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "pistol.semiauto", Skin = 0, Amount = 1, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 24, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "pistol.python", Skin = 0, Amount = 1, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 25, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "pistol.m92", Skin = 0, Amount = 1, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 26, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "smg.2", Skin = 0, Amount = 1, Chance = 40
}
, new() {
Type = ItemType.Item, ID = 27, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.m39", Skin = 0, Amount = 1, Chance = 20
}
, new() {
Type = ItemType.Item, ID = 28, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "smg.thompson", Skin = 0, Amount = 1, Chance = 40
}
, new() {
Type = ItemType.Item, ID = 29, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.semiauto", Skin = 0, Amount = 1, Chance = 20
}
, new() {
Type = ItemType.Item, ID = 30, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.lr300", Skin = 0, Amount = 1, Chance = 15
}
, new() {
Type = ItemType.Item, ID = 31, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.bolt", Skin = 0, Amount = 1, Chance = 15
}
, new() {
Type = ItemType.Item, ID = 54, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.ak", Skin = 0, Amount = 1, Chance = 15
}
}
}
, new CaseEntry {
ID = 4, Title = "PROCYON", Image = "https://i.ibb.co/gg72RjJ/1ZttHs8.png", Permission = string.Empty, Cost = 200, CustomCurrency = new CustomCurrency {
Enabled = false, CostFormat = "{0} scrap", Type = EconomyType.Item, Plug = string.Empty, AddHook = string.Empty, RemoveHook = string.Empty, BalanceHook = string.Empty, ShortName = "scrap", DisplayName = string.Empty, Skin = 0
}
, Items = new List<ItemInfo> {
new() {
Type = ItemType.Item, ID = 32, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "explosive.timed", Skin = 0, Amount = 5, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 33, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "ammo.rocket.basic", Skin = 0, Amount = 8, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 34, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "lmg.m249", Skin = 0, Amount = 1, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 35, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "gunpowder", Skin = 0, Amount = 8000, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 36, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "rifle.l96", Skin = 0, Amount = 1, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 37, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "supply.signal", Skin = 0, Amount = 6, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 38, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "explosive.satchel", Skin = 0, Amount = 6, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 39, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "ammo.rifle.explosive", Skin = 0, Amount = 250, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 40, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "grenade.f1", Skin = 0, Amount = 5, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 41, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "workbench3", Skin = 0, Amount = 1, Chance = 60
}
, new() {
Type = ItemType.Item, ID = 42, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "scrap", Skin = 0, Amount = 1000, Chance = 50
}
}
}
, new CaseEntry {
ID = 5, Title = "SADAMELIK", Image = "https://i.ibb.co/VNP4ntb/wIPGCGM.png", Permission = string.Empty, Cost = 500, CustomCurrency = new CustomCurrency {
Enabled = false, CostFormat = "{0} scrap", Type = EconomyType.Item, Plug = string.Empty, AddHook = string.Empty, RemoveHook = string.Empty, BalanceHook = string.Empty, ShortName = "scrap", DisplayName = string.Empty, Skin = 0
}
, Items = new List<ItemInfo> {
new() {
Type = ItemType.Item, ID = 55, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "wood", Skin = 0, Amount = 20000, Chance = 70
}
, new() {
Type = ItemType.Item, ID = 56, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "stones", Skin = 0, Amount = 15000, Chance = 70
}
, new() {
Type = ItemType.Item, ID = 57, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "leather", Skin = 0, Amount = 2400, Chance = 55
}
, new() {
Type = ItemType.Item, ID = 58, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "cloth", Skin = 0, Amount = 2300, Chance = 55
}
, new() {
Type = ItemType.Item, ID = 59, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "lowgradefuel", Skin = 0, Amount = 1500, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 60, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "roadsigns", Skin = 0, Amount = 35, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 61, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "metalpipe", Skin = 0, Amount = 40, Chance = 50
}
, new() {
Type = ItemType.Item, ID = 62, Image = string.Empty, Title = string.Empty, Command = string.Empty, Plugin = new PluginItem(), DisplayName = string.Empty, ShortName = "gears", Skin = 0, Amount = 30, Chance = 50
}
}
}
}
;
[JsonProperty(PropertyName = LangRu ? "Настройки очистки" : "Wipe Settings")]
public WipeSettings Wipe = new() {
Players = false, Cooldowns = true
}
;
[JsonProperty(PropertyName = LangRu ? "Настройки интерфейса" : "UI Settings")]
public InterfaceSettings UI = new() {
Colors = new InterfaceSettings.ColorsSettings {
Color1 = new IColor("#0E0E10", 100), Color2 = new IColor("#161617", 100), Color3 = new IColor("#FFFFFF", 100), Color4 = new IColor("#4B68FF", 100), Color5 = new IColor("#BFBFBF", 100), Color6 = new IColor("#4B68FF", 33), Color7 = new IColor("##324192", 100), Color8 = new IColor("#FFFFFF", 50), Color9 = new IColor("#161617", 99), Color10 = new IColor("#161617", 85), Color11 = new IColor("#FF4B4B", 100), Color12 = new IColor("#CD3838", 100), Color13 = new IColor("#50965F", 100)
}
}
;
[JsonProperty(PropertyName = LangRu ? "Настройки логов" : "Logs Settings")]
public LogSettings Logs = new() {
Console = false, File = false, Discord = new LogSettings.DiscordLogs {
Enabled = false, WebhookURL = "Insert webhook here (tutorial: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks)"
}
}
;
public VersionNumber Version;
}
private class LogSettings {
[JsonProperty(PropertyName = LangRu ? "Включить логирование в консоль?" : "Enable logging to the console?")]
public bool Console;
[JsonProperty(PropertyName = LangRu ? "Включить логирование в файл?" : "Enable logging to the file?")]
public bool File;
[JsonProperty(PropertyName = LangRu ? "Логирование в Discord" : "Discord Logging")]
public DiscordLogs Discord;
public void Log(string msg) {
if (string.IsNullOrWhiteSpace(msg)) return;
if (Console) LogToConsole(msg);
if (File) LogToFile(msg);
if (Discord?.Enabled == true) LogToDiscord(msg);
}
private void LogToConsole(string msg) {
_instance.Puts($"{msg}");
}
private void LogToFile(string msg) {
_instance.LogToFile("", $"[{DateTime.Now}] {msg}", _instance);
}
private void LogToDiscord(string msg) {
_instance.DiscordSendMessage(msg, Discord.WebhookURL);
}
public class DiscordLogs {
[JsonProperty(PropertyName = LangRu ? "Включено?" : "Enabled?")]
public bool Enabled;
[JsonProperty(PropertyName = "Webhook URL")]
public string WebhookURL = "";
}
}
private class InterfaceSettings {
[JsonProperty(PropertyName = LangRu ? "Цвета" : "Colors")]
public ColorsSettings Colors;
public class ColorsSettings {
[JsonProperty(PropertyName = LangRu ? "Цвет 1" : "Color 1")]
public IColor Color1;
[JsonProperty(PropertyName = LangRu ? "Цвет 2" : "Color 2")]
public IColor Color2;
[JsonProperty(PropertyName = LangRu ? "Цвет 3" : "Color 3")]
public IColor Color3;
[JsonProperty(PropertyName = LangRu ? "Цвет 4" : "Color 4")]
public IColor Color4;
[JsonProperty(PropertyName = LangRu ? "Цвет 5" : "Color 5")]
public IColor Color5;
[JsonProperty(PropertyName = LangRu ? "Цвет 6" : "Color 6")]
public IColor Color6;
[JsonProperty(PropertyName = LangRu ? "Цвет 7" : "Color 7")]
public IColor Color7;
[JsonProperty(PropertyName = LangRu ? "Цвет 8" : "Color 8")]
public IColor Color8;
[JsonProperty(PropertyName = LangRu ? "Цвет 9" : "Color 9")]
public IColor Color9;
[JsonProperty(PropertyName = LangRu ? "Цвет 10" : "Color 10")]
public IColor Color10;
[JsonProperty(PropertyName = LangRu ? "Цвет 11" : "Color 11")]
public IColor Color11;
[JsonProperty(PropertyName = LangRu ? "Цвет 12" : "Color 12")]
public IColor Color12;
[JsonProperty(PropertyName = LangRu ? "Цвет 13" : "Color 13")]
public IColor Color13;
}
}
private class WipeSettings {
[JsonProperty(PropertyName = LangRu ? "Очистить игроков?" : "Wipe Players?")]
public bool Players;
[JsonProperty(PropertyName = LangRu ? "Очистить таймауты?" : "Wipe Cooldowns?")]
public bool Cooldowns;
}
private class TimeCasesSettings {
[JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
public bool Enable;
[JsonProperty(PropertyName = LangRu ? "Таймаут (секунды)" : "Cooldown (seconds)")]
public float Cooldown;
[JsonProperty(PropertyName = LangRu ? "Кейсы (ID)" : "Cases (IDs)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<int> Cases = new();
}
private class PlaytimeTrackerSettings {
[JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = LangRu ? "Время игры (секунды) - ID кейса" : "Playtime (seconds) - CaseID", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<int, int> Cases = new();
}
private class IColor {
[JsonProperty(PropertyName = "HEX")]
public string HEX;
[JsonProperty(PropertyName = LangRu ? "Непрозрачность (0 - 100)" : "Opacity (0 - 100)")]
public float Alpha;
public string Get() {
if (string.IsNullOrEmpty(HEX)) HEX = "#FFFFFF";
var str = HEX.Trim('#');
if (str.Length != 6) throw new Exception(HEX);
var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
return $"{(double) r / 255} {(double) g / 255} {(double) b / 255} {Alpha / 100}";
}
public IColor(string hex, float alpha) {
HEX = hex;
Alpha = alpha;
}
}
private enum EconomyType {
Plugin, Item
}
private abstract class EconomyTemplate {
[JsonProperty(PropertyName = LangRu ? "Тип (Plugin/Item)" : "Type (Plugin/Item)")]
[JsonConverter(typeof(StringEnumConverter))]
public EconomyType Type;
[JsonProperty(PropertyName = LangRu ? "Название плагина" : "Plugin name")]
public string Plug;
[JsonProperty(PropertyName = LangRu ? "Функция пополнения баланса" : "Balance add hook")]
public string AddHook;
[JsonProperty(PropertyName = LangRu ? "Функция снятия баланса" : "Balance remove hook")]
public string RemoveHook;
[JsonProperty(PropertyName = LangRu ? "Функция показа баланса" : "Balance show hook")]
public string BalanceHook;
[JsonProperty(PropertyName = LangRu ? "Краткое имя предмета" : "ShortName")]
public string ShortName;
[JsonProperty(PropertyName = LangRu ? "Отображаемое имя (пусто - по умолчанию)" : "Display Name (empty - default)")]
public string DisplayName;
[JsonProperty(PropertyName = LangRu ? "Скин" : "Skin")]
public ulong Skin;
public double ShowBalance(BasePlayer player) {
switch (Type) {
case EconomyType.Plugin : {
var plugin = _instance?.plugins?.Find(Plug);
if (plugin == null) return 0;
return Math.Round(Convert.ToDouble(plugin.Call(BalanceHook, player.userID)));
}
case EconomyType.Item : {
return ItemCount(Enumerable.ToArray(Enumerable.Concat(player.inventory.containerMain?.itemList ?? Enumerable.Empty<Item>(), Enumerable.Concat(player.inventory.containerBelt?.itemList ?? Enumerable.Empty<Item>(), player.inventory.containerWear?.itemList ?? Enumerable.Empty<Item>()))), ShortName, Skin);
}
default : return 0;
}
}
public void AddBalance(BasePlayer player, double amount) {
switch (Type) {
case EconomyType.Plugin : {
var plugin = _instance?.plugins?.Find(Plug);
if (plugin == null) return;
switch (Plug) {
case "BankSystem" : case "ServerRewards" : plugin.Call(AddHook, player.userID, (int) amount);
break;
default : plugin.Call(AddHook, player.userID, amount);
break;
}
break;
}
case EconomyType.Item : {
var am = (int) amount;
var item = ToItem(am);
if (item == null) return;
player.GiveItem(item);
break;
}
}
}
public bool RemoveBalance(BasePlayer player, double amount) {
switch (Type) {
case EconomyType.Plugin : {
if (ShowBalance(player) < amount) return false;
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return false;
switch (Plug) {
case "BankSystem" : case "ServerRewards" : plugin.Call(RemoveHook, player.userID, (int) amount);
break;
default : plugin.Call(RemoveHook, player.userID, amount);
break;
}
return true;
}
case EconomyType.Item : {
var playerItems = Enumerable.Concat(player.inventory.containerMain?.itemList ?? Enumerable.Empty<Item>(), Enumerable.Concat(player.inventory.containerBelt?.itemList ?? Enumerable.Empty<Item>(), player.inventory.containerWear?.itemList ?? Enumerable.Empty<Item>()));
var am = (int) amount;
if (ItemCount(Enumerable.ToArray(playerItems), ShortName, Skin) < am) return false;
Take(Enumerable.ToArray(playerItems), ShortName, Skin, am);
return true;
}
default : return false;
}
}
private Item ToItem(int amount) {
var item = ItemManager.CreateByName(ShortName, amount, Skin);
if (item == null) {
Debug.LogError($"Error creating item with ShortName: '{ShortName}'");
return null;
}
if (!string.IsNullOrEmpty(DisplayName)) item.name = DisplayName;
return item;
}
}
private class EconomyConf : EconomyTemplate {
[JsonProperty(PropertyName = LangRu ? "Показывать баланс" : "Show Balance")]
public bool Show;
}
private class CustomCurrency : EconomyTemplate {
[JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = LangRu ? "Формат стоимости" : "Cost Format")]
public string CostFormat;
}
private abstract class CaseTemplate {
[JsonProperty(PropertyName = "ID")]
public int ID;
[JsonProperty(PropertyName = LangRu ? "Название" : "Title")]
public string Title;
[JsonProperty(PropertyName = LangRu ? "Изображение" : "Image")]
public string Image;
[JsonProperty(PropertyName = LangRu ? "Разрешение" : "Permission")]
public string Permission;
[JsonProperty(PropertyName = LangRu ? "Таймаут" : "Cooldown")]
public float CooldownTime;
[JsonProperty(PropertyName = LangRu ? "Предметы" : "Items", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ItemInfo> Items;
public bool HasCase(BasePlayer player) {
return _instance?.GetPlayerData(player)?.Cases?.ContainsKey(ID) == true;
}
public int CaseAmount(BasePlayer player) {
return _instance?.GetPlayerData(player)?.Cases[ID] ?? 0;
}
public void Log(BasePlayer player, ItemInfo itemInfo) {
_instance._config.Logs.Log(_instance?.Msg(player, LogOpenedCase).Replace("{username}", player.displayName).Replace("{steamid}", player.UserIDString).Replace("{casename}", Title).Replace("{item}", itemInfo.LogFormatted(player)));
}
public bool HasPermission(BasePlayer player) {
return string.IsNullOrEmpty(Permission) || _instance.permission.UserHasPermission(player.UserIDString, Permission);
}
}
private class BonusCaseEntry : CaseEntry {
[JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
public bool Enabled;
}
private class CaseEntry : CaseTemplate, ICloneable, IDisposable {
#region Fields
[JsonProperty(PropertyName = LangRu ? "Стоимость" : "Cost")]
public int Cost;
[JsonProperty(PropertyName = LangRu ? "Пользовательская валюта" : "Custom Currency")]
public CustomCurrency CustomCurrency;
#endregion
public object Clone() {
return MemberwiseClone();
}
public void Dispose() {
//null
}
}
private enum ItemType {
Item, Command, Plugin
}
private class ItemInfo {
#region Fields
[JsonProperty(PropertyName = LangRu ? "Тип" : "Type")]
[JsonConverter(typeof(StringEnumConverter))]
public ItemType Type;
[JsonProperty(PropertyName = "ID")]
public int ID;
[JsonProperty(PropertyName = LangRu ? "Изображение" : "Image")]
public string Image;
[JsonProperty(PropertyName = LangRu ? "Название" : "Title")]
public string Title;
[JsonProperty(PropertyName = LangRu ? "Команда (%steamid%)" : "Command (%steamid%)")]
public string Command;
[JsonProperty(PropertyName = LangRu ? "Плагин" : "Plugin")]
public PluginItem Plugin;
[JsonProperty(PropertyName = LangRu ? "Отображаемое имя (пусто - по умолчанию)" : "Display Name (empty - default)")]
public string DisplayName;
[JsonProperty(PropertyName = LangRu ? "Краткое имя" : "ShortName")]
public string ShortName;
[JsonProperty(PropertyName = LangRu ? "Скин" : "Skin")]
public ulong Skin;
[JsonProperty(PropertyName = LangRu ? "Количество" : "Amount")]
public int Amount;
[JsonProperty(PropertyName = LangRu ? "Шанс" : "Chance")]
public float Chance;
[JsonProperty(PropertyName = LangRu ? "Содержимое" : "Content")]
public ItemContent Content;
[JsonProperty(PropertyName = LangRu ? "Оружие" : "Weapon")]
public ItemWeapon Weapon;
#endregion
#region Utils
#region Definition
[JsonIgnore]
private ItemDefinition _definition;
[JsonIgnore]
public ItemDefinition ItemDefinition {
get {
if (_definition == null) _definition = ItemManager.FindItemDefinition(ShortName);
return _definition;
}
}
public void UpdateDefinition() {
_definition = ItemManager.FindItemDefinition(ShortName);
}
#endregion
public string GetName() {
if (!string.IsNullOrEmpty(Title)) return Title;
if (!string.IsNullOrEmpty(DisplayName)) return DisplayName;
var def = ItemManager.FindItemDefinition(ShortName);
if (!string.IsNullOrEmpty(ShortName) && def != null) return def.displayName.translated;
return string.Empty;
}
public void Get(BasePlayer player, int count = 1) {
switch (Type) {
case ItemType.Item : ToItem(player, count);
break;
case ItemType.Command : ToCommand(player, count);
break;
case ItemType.Plugin : Plugin.Get(player, count);
break;
}
}
private void ToItem(BasePlayer player, int count) {
if (ItemDefinition == null) {
Debug.LogError($"Error creating item with ShortName '{ShortName}'");
return;
}
GetStacks(ItemDefinition, Amount * count)?.ForEach(stack => {
var newItem = ItemManager.Create(ItemDefinition, stack, Skin);
if (newItem == null) {
_instance?.PrintError($"Error creating item with ShortName '{ShortName}'");
return;
}
if (!string.IsNullOrEmpty(DisplayName)) newItem.name = DisplayName;
if (Weapon != null && Weapon.Enabled) Weapon.Build(newItem);
if (Content != null && Content.Enabled) Content.Build(newItem);
player.GiveItem(newItem, BaseEntity.GiveItemReason.PickedUp);
}
);
}
private void ToCommand(BasePlayer player, int count) {
for (var i = 0; i < count; i++) {
var command = Command.Replace("\n", "|").Replace("%steamid%", player.UserIDString, StringComparison.OrdinalIgnoreCase).Replace("%username%", player.displayName, StringComparison.OrdinalIgnoreCase);
foreach (var check in command.Split('|')) _instance?.Server.Command(check);
}
}
private static List<int> GetStacks(ItemDefinition item, int amount) {
var list = Pool.GetList<int>();
var maxStack = item.stackable;
if (maxStack == 0) maxStack = 1;
while (amount > maxStack) {
amount -= maxStack;
list.Add(maxStack);
}
list.Add(amount);
return list;
}
public string LogFormatted(BasePlayer player) {
return _instance?.Msg(player, LogItem).Replace("{name}", GetName()).Replace("{amount}", Amount.ToString()).Replace("{shortname}", ShortName) ?? string.Empty;
}
#endregion
}
private class ItemContent {
#region Fields
[JsonProperty(PropertyName = LangRu ? "Включено" : "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = LangRu ? "Содержимое" : "Contents", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ContentInfo> Contents = new();
#endregion
#region Utils
public void Build(Item item) {
Contents?.ForEach(content => content?.Build(item));
}
#endregion
#region Classes
public class ContentInfo {
[JsonProperty(PropertyName = LangRu ? "Краткое имя" : "ShortName")]
public string ShortName;
[JsonProperty(PropertyName = LangRu ? "Состояние" : "Condition")]
public float Condition;
[JsonProperty(PropertyName = LangRu ? "Количество" : "Amount")]
public int Amount;
// ... [Code preview truncated due to length. Full source in attached file] ...