C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Oxide.Game.Rust.Cui;
using System;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using System.IO;
using Newtonsoft.Json;
using Oxide.Core.Configuration;
using System.Collections;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using System.Threading.Tasks;
using System.Timers;
using Facepunch.Extend;
using Facepunch;
using System.Reflection;
namespace Oxide.Plugins {
[Info("KitController", "Amino", "2.2.1")]
[Description("A new, modern kit system for Rust")]
public class KitController : RustPlugin {
[PluginReference]
Plugin WelcomeController, ImageLibrary, NoEscape, ServerRewards, Economics;
#region Config
public class Configuration {
[JsonProperty("Kit Commands")]
public List<string> KitCommands {
get;
set;
}
= new List<string>();
[JsonProperty(PropertyName = "Default Currency (RP, Economics, item.shortname)")]
public string DefaultCurrency {
get;
set;
}
= "RP";
[JsonProperty(PropertyName = "Clear data on server wipe")]
public bool WipePlayerKitsOnServerWipe {
get;
set;
}
= true;
[JsonProperty(PropertyName = "(No Escape) Can't redeem kits on combat blocked")]
public bool UseNoKitsOnCombatBlock {
get;
set;
}
= false;
[JsonProperty(PropertyName = "(No Escape) Can't redeem kits on raid blocked")]
public bool UseNoKitsOnRaidBlock {
get;
set;
}
= false;
[JsonProperty(PropertyName = "Kits Title (Panel image will take priority)")]
public string KitsTitle {
get;
set;
}
= "KITS";
[JsonProperty(PropertyName = "Plugin images")]
public Images Images {
get;
set;
}
= new Images();
[JsonProperty(PropertyName = "Kits Layout (0, 1)")]
public int KitsLayout {
get;
set;
}
= 0;
[JsonProperty(PropertyName = "UI Colors (0, 1)")]
public int KitsColors {
get;
set;
}
= 0;
[JsonProperty(PropertyName = "UI 0")]
public UIElements UIZero {
get;
set;
}
[JsonProperty(PropertyName = "UI 1")]
public UIElements UIOne {
get;
set;
}
public static Configuration DefaultConfig() {
return new Configuration {
DefaultCurrency = "RP", KitCommands = new List<string> {
"kits", "kit"
}
, Images = new Images {
PanelImage = "https://i.ibb.co/wK0ZYJ3/Kits-Banner.png", EditImage = "https://i.ibb.co/92yTGNd/edit-Button.png", KitPlaceholderImage = "https://i.ibb.co/J58sN3b/Kit-Placeholder.png"
}
, UIZero = new UIElements(), UIOne = new UIElements {
MiddlePanelColor = ".17.17.17 1", TopPanelColor = ".17.17.17 1", BottomPanelColor = ".17.17.17 1", CategoryButtonColor = "1 1 1.08", CategoryPageButtonColor = "1 1 1.08", KitDisplayPanelColor = "1 1 1.08", KitImageBackgroundColor = "1 1 1.08", HeaderCooldownColor = "1 1 1.08", HeaderMaxUsesColor = "1 1 1.08", HeaderKitNameColor = "1 1 1.08", KitsLayoutOneBlankBoxColor = "1 1 1.08", KitsItemPageButtonColor = "1 1 1.08", KitsItemsColor = "1 1 1.08", MockInventoryItemColor = "1 1 1.08", EditPageMainColor = ".17.17.17 1", EditPageSecondaryColor = "1 1 1.08", ViewPageMainColor = ".17.17.17 1", ViewPageSecondaryColor = "1 1 1.08", KitsPageButtonColor = "1 1 1.08"
}
}
;
}
}
public class Images {
[JsonProperty(PropertyName = "Panel Image")]
public string PanelImage {
get;
set;
}
[JsonProperty(PropertyName = "Edit Image")]
public string EditImage {
get;
set;
}
[JsonProperty(PropertyName = "Kit placeholder image")]
public string KitPlaceholderImage {
get;
set;
}
}
public class UIElements {
public string BlurBackgroundColor {
get;
set;
}
= "0 0 0.4";
public string TopPanelColor {
get;
set;
}
= "0 0 0.5";
public string MiddlePanelColor {
get;
set;
}
= "0 0 0.5";
public string BottomPanelColor {
get;
set;
}
= "0 0 0.5";
public string CloseText {
get;
set;
}
= "X";
public string CloseTextColor {
get;
set;
}
= "1 1 1 1";
public string KitsPageButtonColor {
get;
set;
}
= "0 0 0.5";
public string CategoryPageButtonColor {
get;
set;
}
= "0 0 0.5";
public string CategoryButtonColor {
get;
set;
}
= "0 0 0.5";
public string ActiveCategoryButtonColor {
get;
set;
}
= ".20.60.92.5";
public string KitDisplayPanelColor {
get;
set;
}
= "0 0 0.5";
public string KitImageBackgroundColor {
get;
set;
}
= "0 0 0.5";
public string CanClaimButtonColor {
get;
set;
}
= ".39.89.4.8";
public string CantClaimButtonColor {
get;
set;
}
= "1.31.31.8";
public string CanClaimTextColor {
get;
set;
}
= "0.44 1 0.23 1";
public string CantClaimTextColor {
get;
set;
}
= "1.31.31 1";
public string ViewButtonColor {
get;
set;
}
= ".39.64 1.7";
public string ViewTextColor {
get;
set;
}
= ".61.81 1 1";
public string NoPermsViewButtonColor {
get;
set;
}
= "0.31 0.68 1 1";
public string NoPermsViewTextColor {
get;
set;
}
= "1 1 1 1";
public string CantClaimCooldownColor {
get;
set;
}
= "1.31.31 1";
public string CanClaimCooldownColor {
get;
set;
}
= "1 1 1 1";
public string CantClaimMaxUsesColor {
get;
set;
}
= "1.31.31 1";
public string CanClaimMaxUsesColor {
get;
set;
}
= "1 1 1 1";
public string HeaderCooldownColor {
get;
set;
}
= "0 0 0.4";
public string HeaderCooldownTextColor {
get;
set;
}
= "1 1 1 1";
public string HeaderMaxUsesColor {
get;
set;
}
= "0 0 0.4";
public string HeaderMaxUsesTextColor {
get;
set;
}
= "1 1 1 1";
public string HeaderKitNameColor {
get;
set;
}
= "0 0 0.4";
public string HeaderKitNameTextColor {
get;
set;
}
= "1 1 1 1";
public string NoPermissionOverlayColor {
get;
set;
}
= "0 0 0.5";
public string KitsLayoutOneBlankBoxColor {
get;
set;
}
= "0 0 0.4";
public string KitsItemPageButtonColor {
get;
set;
}
= "0 0 0.4";
public string KitsItemsColor {
get;
set;
}
= "0 0 0.4";
public string MockInventoryItemColor {
get;
set;
}
= "0 0 0.5";
public string EditPageMainColor {
get;
set;
}
= "0 0 0.5";
public string EditPageSecondaryColor {
get;
set;
}
= "0 0 0.5";
public string ViewPageMainColor {
get;
set;
}
= "0 0 0.5";
public string ViewPageSecondaryColor {
get;
set;
}
= "0 0 0.5";
}
private static Configuration _config;
private static UIElements _uiColors;
protected override void LoadConfig() {
base.LoadConfig();
try {
_config = Config.ReadObject<Configuration>();
if (_config == null) LoadDefaultConfig();
if (_config.KitsColors == 0) _uiColors = _config.UIZero;
else _uiColors = _config.UIOne;
SaveConfig();
}
catch (Exception e) {
Debug.LogException(e);
PrintWarning("Creating new config file");
LoadDefaultConfig();
}
}
protected override void LoadDefaultConfig() => _config = Configuration.DefaultConfig();
protected override void SaveConfig() => Config.WriteObject(_config);
#endregion
#region Data
public List<aKit> _kitData = new List<aKit>();
public Dictionary<ulong, bKit> _kitEdits = new Dictionary<ulong, bKit>();
public Dictionary<ulong, PlayerOptions> _playerOptions = new Dictionary<ulong, PlayerOptions>();
public List<PlayerUsedKits> _userData = new List<PlayerUsedKits>();
public bool RespawnSubed = false;
public static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0);
public static double CurrentTime => DateTime.UtcNow.Subtract(Epoch).TotalSeconds;
public static double LastWipe;
public bool usingWC = false;
public class CanRedeem {
public bool Can {
get;
set;
}
public string Time {
get;
set;
}
}
public class ClaimKitResponse {
public bool CanRedeem {
get;
set;
}
public string Reason {
get;
set;
}
}
public class CanPurchase {
public bool CanBuy {
get;
set;
}
public string Reason {
get;
set;
}
}
public class ItemChange {
public Item Item {
get;
set;
}
public int Amount {
get;
set;
}
}
public class aKit {
public string KitName {
get;
set;
}
public string Permission {
get;
set;
}
public string Description {
get;
set;
}
public string Category {
get;
set;
}
public int Cost {
get;
set;
}
public string Currency {
get;
set;
}
= "rp";
public int MaxUses {
get;
set;
}
= 0;
public double Cooldown {
get;
set;
}
= 0;
public string KitImage {
get;
set;
}
public string NoPermissionText {
get;
set;
}
= "You need to be VIP to use this kit!";
public bool IsAutoKit {
get;
set;
}
public int AutoKitPriority {
get;
set;
}
public double WipeCooldown {
get;
set;
}
public bool Hidden {
get;
set;
}
public List<kitContents> Items {
get;
set;
}
= new List<kitContents>();
}
public class createItem {
public string Category {
get;
set;
}
public Item Item {
get;
set;
}
}
public class bKit : aKit {
public string ParentName {
get;
set;
}
public bKit() {
}
public bKit(aKit source) {
KitName = source.KitName;
Permission = source.Permission;
Description = source.Description;
Category = source.Category;
MaxUses = source.MaxUses;
Cost = source.Cost;
Cooldown = source.Cooldown;
Currency = source.Currency;
KitImage = source.KitImage;
Hidden = source.Hidden;
NoPermissionText = source.NoPermissionText;
IsAutoKit = source.IsAutoKit;
AutoKitPriority = source.AutoKitPriority;
WipeCooldown = source.WipeCooldown;
Items = source.Items;
}
}
public class kitContents {
public string Shortname {
get;
set;
}
public int ItemId {
get;
set;
}
public ulong Skin {
get;
set;
}
public int Amount {
get;
set;
}
public int Ammo {
get;
set;
}
public string AmmoType {
get;
set;
}
public int Position {
get;
set;
}
public string Container {
get;
set;
}
public bool IsBlueprint {
get;
set;
}
public List<int> Contents {
get;
set;
}
}
public class PlayerOptions {
public string ActiveCategory {
get;
set;
}
public int KitPage {
get;
set;
}
public int CategoryPage {
get;
set;
}
public bool UsingWelcomeController {
get;
set;
}
}
public class PlayerUsedKits {
public ulong SteamId {
get;
set;
}
public List<UsedKits> UsedKits {
get;
set;
}
}
public class UsedKits {
public string KitName {
get;
set;
}
public int TotalUses {
get;
set;
}
= 0;
public double NextUseTime {
get;
set;
}
= 0;
}
public class MockItem {
public int ItemId {
get;
set;
}
public ulong SkinId {
get;
set;
}
public int ItemAmount {
get;
set;
}
public int ItemPosition {
get;
set;
}
}
#endregion
#region RustKits Data
public class OldKit {
public string Name {
get;
set;
}
= string.Empty;
public string Description {
get;
set;
}
= string.Empty;
public string RequiredPermission {
get;
set;
}
= string.Empty;
public int MaximumUses {
get;
set;
}
public int RequiredAuth {
get;
set;
}
public int Cooldown {
get;
set;
}
public int Cost {
get;
set;
}
public bool IsHidden {
get;
set;
}
public string CopyPasteFile {
get;
set;
}
= string.Empty;
public string KitImage {
get;
set;
}
= string.Empty;
public OldItemData[] MainItems {
get;
set;
}
= new OldItemData[0];
public OldItemData[] WearItems {
get;
set;
}
= new OldItemData[0];
public OldItemData[] BeltItems {
get;
set;
}
= new OldItemData[0];
}
public class OldItemData {
public string Shortname {
get;
set;
}
public ulong Skin {
get;
set;
}
public int Amount {
get;
set;
}
public float Condition {
get;
set;
}
public float MaxCondition {
get;
set;
}
public int Ammo {
get;
set;
}
public string Ammotype {
get;
set;
}
public int Position {
get;
set;
}
public int Frequency {
get;
set;
}
public string BlueprintShortname {
get;
set;
}
public OldItemData[] Contents {
get;
set;
}
internal OldItemData() {
}
internal OldItemData(Item item) {
Shortname = item.info.shortname;
Amount = item.amount;
Ammotype = (item.GetHeldEntity() as BaseProjectile)?.primaryMagazine.ammoType.shortname ?? null;
Ammo = item.GetHeldEntity() is BaseProjectile ? (item.GetHeldEntity() as BaseProjectile).primaryMagazine.contents : item.GetHeldEntity() is FlameThrower ? (item.GetHeldEntity() as FlameThrower).ammo : 0;
Position = item.position;
Skin = item.skin;
Condition = item.condition;
MaxCondition = item.maxCondition;
Frequency = ItemModAssociatedEntity<PagerEntity>.GetAssociatedEntity(item)?.GetFrequency() ?? -1;
if (item.instanceData != null && item.instanceData.blueprintTarget != 0) BlueprintShortname = ItemManager.FindItemDefinition(item.instanceData.blueprintTarget).shortname;
Contents = item.contents?.itemList.Select(item1 => new OldItemData(item1)).ToArray();
}
}
#endregion
#region Lang
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["ChatTitle"]
= "<color=#91b9fa>[ KIT CONTROLLER ]:</color>", ["ButtonView"] = "VIEW", ["KitViewTitle"] = "KIT VIEW", ["ButtonRedeemLimitReached"] = "REDEEM LIMIT REACHED", ["ButtonClaim"] = "CLAIM", ["ButtonOnCooldown"] = "ON COOLDOWN", ["TextNoCooldown"] = "No cooldown", ["IsBlocked"] = "You are currently <color=#91b9fa>combat</color> and or <color=#91b9fa>raid</color> blocked!", ["ButtonNoPermission"] = "NO PERMISSION", ["HeaderMaxUses"] = "MAX USES", ["HeaderKitName"] = "KIT NAME", ["HeaderCooldown"] = "COOLDOWN", ["HeaderImage"] = "IMAGE", ["HeaderDescription"] = "DESCRIPTION", ["AdminHeaderMaxUses"] = "MAX USES", ["AdminHeaderKitName"] = "KIT NAME", ["AdminHeaderCooldown"] = "COOLDOWN (SEC)", ["AdminHeaderCreateKit"] = "CREATE KIT", ["AdminHeaderImage"] = "IMAGE", ["AdminHeaderDescription"] = "DESCRIPTION", ["ErrNameExists"] = "A KIT WITH THIS NAME ALREADY EXISTS", ["ChatOnCooldown"] = "Kit <color=#91b9fa>{0}</color> is on cooldown for <color=#91b9fa>{1}</color>", ["ChatMaxRedeem"] = "You've reached the max redeem limit for <color=#91b9fa>{0}</color>", ["ChatKitRedeemed"] = "You've redeemed <color=#91b9fa>{0}</color> kit!", ["ChatNoPermission"] = "You don't have permission to redeem <color=#91b9fa>{0}</color> kit", ["ChatNotFound"] = "Kit <color=#91b9fa>{0}</color> not found", ["ChatNoKitItems"] = "No kit items found for <color=#91b9fa>{0}</color>", ["ChatWipeCooldown"] = "<color=#91b9fa>{0}</color> is on wipe cooldown for <color=#91b9fa>{1}</color>", ["ChatTooManyItems"] = "Too many items in <color=#91b9fa>inventory</color>", ["ChatNoPlayerFound"] = "Could not find <color=#91b9fa>{0}</color> on the server", ["ChatIsAutoKit"] = "Cannot redeem <color=#91b9fa>{0}</color> because it's an autokit", ["ChatKitGivenPlr"] = "Gave <color=#91b9fa>{0}</color> kit to <color=#91b9fa>{1}</color>", ["RPPlaceholder"] = "{0} RP", ["EconomicsPlaceholder"] = "${0}", ["ItemPlaceholder"] = "${0}", ["RPNotEnough"] = "You do not have enough RP to purchase <color=#91b9fa>{0}</color> kit!", ["EconomicsNotEnough"] = "You do not have enough money to purchase <color=#91b9fa>{0}</color> kit!", ["ItemNotEnough"] = "You do not have enough scrap to purchase <color=#91b9fa>{0}</color> kit!", ["CurrencyNotFound"] = "Currency not found! Please contact admin!",
}
, this, "en");
}
private string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
#endregion
#region Hooks
public static Dictionary<string, string> ConvertToDictionary(UIElements uiElements) {
var dictionary = new Dictionary<string, string>();
foreach (PropertyInfo property in typeof(UIElements).GetProperties()) {
string key = property.Name;
string value = property.GetValue(uiElements)?.ToString();
dictionary[key] = value;
}
return dictionary;
}
void OnWCRequestColors(string pluginName) {
if (!pluginName.Equals("KitController", StringComparison.OrdinalIgnoreCase)) return;
Interface.CallHook("WCSendColors", ConvertToDictionary(_uiColors), pluginName);
}
void OnWCSentThemeColors(List<string> pluginNames, Dictionary<string, string> themeColors) {
if (!pluginNames.Contains("KitController")) return;
_uiColors.TopPanelColor = themeColors["BackgroundColor"];
_uiColors.MiddlePanelColor = themeColors["BackgroundColor"];
_uiColors.BottomPanelColor = themeColors["BackgroundColor"];
_uiColors.KitsPageButtonColor = themeColors["SecondaryColor"];
_uiColors.CategoryPageButtonColor = themeColors["SecondaryColor"];
_uiColors.ActiveCategoryButtonColor = themeColors["PrimaryButtonColor"];
_uiColors.KitDisplayPanelColor = themeColors["SecondaryColor"];
_uiColors.KitDisplayPanelColor = themeColors["SecondaryColor"];
_uiColors.CanClaimButtonColor = themeColors["ThirdButtonColor"];
_uiColors.CantClaimButtonColor = themeColors["SecondaryButtonColor"];
_uiColors.CanClaimTextColor = "1 1 1 1";
_uiColors.CantClaimTextColor = "1 1 1 1";
_uiColors.ViewButtonColor = themeColors["PrimaryButtonColor"];
_uiColors.ViewTextColor = "1 1 1 1";
_uiColors.NoPermsViewButtonColor = themeColors["PrimaryButtonColor"];
_uiColors.NoPermsViewTextColor = "1 1 1 1";
_uiColors.CantClaimButtonColor = themeColors["SecondaryButtonColor"];
_uiColors.CantClaimMaxUsesColor = themeColors["SecondaryButtonColor"];
_uiColors.HeaderCooldownColor = themeColors["SecondaryColor"];
_uiColors.HeaderMaxUsesColor = themeColors["SecondaryColor"];
_uiColors.HeaderKitNameColor = themeColors["SecondaryColor"];
_uiColors.NoPermissionOverlayColor = themeColors["SecondaryColor"];
_uiColors.KitsLayoutOneBlankBoxColor = themeColors["SecondaryColor"];
_uiColors.KitsItemPageButtonColor = themeColors["SecondaryColor"];
_uiColors.KitsItemsColor = themeColors["SecondaryColor"];
_uiColors.MockInventoryItemColor = themeColors["SecondaryColor"];
_uiColors.EditPageMainColor = themeColors["SecondaryColor"];
_uiColors.EditPageSecondaryColor = themeColors["SecondaryColor"];
_uiColors.ViewPageMainColor = themeColors["SecondaryColor"];
_uiColors.ViewPageSecondaryColor = themeColors["SecondaryColor"];
SaveConfig();
}
void OnServerInitialized(bool initial) {
RegisterImages();
LastWipe = SaveRestore.SaveCreatedTime.Subtract(Epoch).TotalSeconds;
var isUsingWC = Interface.Call("IsUsingPlugin", "KitController");
if (isUsingWC != null && (isUsingWC is bool)) usingWC = (bool)isUsingWC;
else usingWC = false;
RegisterCommandsAndPermissions();
}
void Loaded() {
LoadKitData();
LoadUserData();
UnsubscribeHooks();
}
void OnWCRequestedUIPanel(BasePlayer player, string panelName, string neededPlugin) {
if (!neededPlugin.Equals("kitcontroller", StringComparison.OrdinalIgnoreCase)) return;
usingWC = true;
KitCommand(player, null, null);
}
void OnPluginLoaded(Plugin plugin) {
if (plugin.Name == "WelcomeController") {
var isUsingWC = Interface.Call("IsUsingPlugin", "KitController");
if (isUsingWC != null && (isUsingWC is bool)) usingWC = (bool)isUsingWC;
else usingWC = false;
}
}
void OnPluginUnloaded(Plugin plugin) {
if (plugin.Name == "WelcomeController") {
usingWC = false;
RegisterCommandsAndPermissions(true);
}
}
void OnServerSave() {
SaveKitList();
SaveUserList();
}
private void Unload() {
if (!Interface.Oxide.IsShuttingDown) {
SaveKitList();
SaveUserList();
foreach (BasePlayer player in BasePlayer.activePlayerList) {
CuiHelper.DestroyUi(player, "KCMainPanel");
CuiHelper.DestroyUi(player, "KCMainEditPanel");
CuiHelper.DestroyUi(player, "KCMainViewPanel");
}
}
_config = null;
}
void OnNewSave(string filename) {
if (_config.WipePlayerKitsOnServerWipe) _userData.Clear();
}
object OnPlayerRespawned(BasePlayer player, BasePlayer.SpawnPoint spawnPoint) {
GiveAutoKit(player);
return null;
}
#endregion
#region Commands
[ChatCommand("convertkits")]
private void ConvertData(BasePlayer player, string command, string[] args) {
if (!permission.UserHasPermission(player.UserIDString, "kitcontroller.admin")) {
SendReply(player, "You do not have kitcontroller.admin permission!");
return;
}
ConvertRustKitsData(player);
}
private void AddItemData(ref List<kitContents> kitContents, OldItemData[] oldItemData, string container) {
foreach (var item in oldItemData) {
var isBlueprint = !string.IsNullOrEmpty(item.BlueprintShortname);
var theItem = ItemManager.FindItemDefinition(isBlueprint ? item.BlueprintShortname : item.Shortname);
if (theItem == null) continue;
var contents = new List<int>();
if (item.Contents != null) {
foreach (var content in item.Contents) {
var theContent = ItemManager.FindItemDefinition(content.Shortname);
if (theContent == null) continue;
contents.Add(theContent.itemid);
}
}
kitContents.Add(new kitContents() {
ItemId = theItem.itemid, Shortname = theItem.shortname, Skin = item.Skin, Amount = item.Amount, Ammo = item.Ammo, AmmoType = item.Ammotype, IsBlueprint = isBlueprint, Position = item.Position, Container = container, Contents = contents
}
);
}
}
private void ConvertRustKitsData(BasePlayer player = null) {
try {
DynamicConfigFile kits = Interface.Oxide.DataFileSystem.GetFile("Kits/kits_data");
kits.Settings.NullValueHandling = NullValueHandling.Ignore;
Dictionary<string, Dictionary<string, OldKit>> rustKitsStoredData = kits.ReadObject<Dictionary<string, Dictionary<string, OldKit>>>();
if (rustKitsStoredData == null || rustKitsStoredData.Count == 0) {
if (player != null) SendReply(player, "Could not locate 'Kits' data file!");
return;
}
if (player != null) SendReply(player, $"Converting {rustKitsStoredData["_kits"].Count} kits to Kit Controller!");
foreach (var kit in rustKitsStoredData["_kits"].Values) {
if (_kitData.Any(x => x.KitName.Equals(kit.Name, StringComparison.OrdinalIgnoreCase))) {
SendReply(player, $"Cannot add {kit.Name} because it's already in current kit list!");
continue;
}
List<kitContents> kitContents = new List<kitContents>();
if (kit.WearItems != null) AddItemData(ref kitContents, kit.WearItems, "attire");
if (kit.MainItems != null) AddItemData(ref kitContents, kit.MainItems, "main");
if (kit.BeltItems != null) AddItemData(ref kitContents, kit.BeltItems, "belt");
aKit newKit = new aKit() {
KitName = kit.Name, Permission = kit.RequiredPermission.Contains('.') ? "kitcontroller" + kit.RequiredPermission.Substring(5) : $"kitcontroller.{kit.RequiredPermission}", Description = kit.Description, Cost = kit.Cost, MaxUses = kit.MaximumUses, Cooldown = kit.Cooldown, KitImage = kit.KitImage, Hidden = kit.IsHidden, Items = kitContents
}
;
RegisterNewImage($"Kit{kit.Name}", kit.KitImage);
SendReply(player, $"Successfully converted {kit.Name}!");
_kitData.Add(newKit);
}
}
catch {
if (player != null) SendReply(player, "Could not locate 'Kits' data file!");
}
}
[ConsoleCommand("kc_main")]
private void ConsoleKit(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (arg == null || player == null) return;
switch (arg.Args[0]) {
case "close" : CuiHelper.DestroyUi(player, "KCMainPanel");
break;
case "edit" : _kitEdits[player.userID] = new bKit();
if (arg.Args.Length > 1) {
var kitName = String.Join(" ", arg.Args.Skip(1));
_kitEdits[player.userID] = _kitData.Where(x => x.KitName == kitName).Select(x => new bKit(x)).FirstOrDefault();
_kitEdits[player.userID].ParentName = kitName;
}
UICreateEditPage(player);
CuiHelper.DestroyUi(player, "KCMainPanel");
break;
case "editclose" : CuiHelper.DestroyUi(player, "KCMainEditPanel");
_kitEdits.Remove(player.userID);
OpenKitUI(player);
break;
case "category" : var playerInfo = GetOrLoadPlayerOptions(player);
playerInfo.ActiveCategory = string.Join(" ", arg.Args.Skip(1));
playerInfo.KitPage = 0;
OpenKitUI(player);
break;
case "kitspage" : playerInfo = GetOrLoadPlayerOptions(player);
playerInfo.KitPage = int.Parse(arg.Args[1]);
OpenKitUI(player);
break;
case "categorypage" : playerInfo = GetOrLoadPlayerOptions(player);
playerInfo.CategoryPage = int.Parse(arg.Args[1]);
OpenKitUI(player);
break;
}
}
[ConsoleCommand("kc_edit")]
private void ConsoleEditKits(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (arg == null || player == null) return;
var editKit = _kitEdits[player.userID];
switch (arg.Args[0]) {
case "deletekit" : _kitData.RemoveAll(x => x.KitName.Equals(editKit.ParentName, StringComparison.OrdinalIgnoreCase));
CuiHelper.DestroyUi(player, "KCMainEditPanel");
_kitEdits.Remove(player.userID);
OpenKitUI(player);
break;
case "selectitem" : HandleItemEdit(player, int.Parse(arg.Args[1]), arg.Args[2]);
break;
case "shortname" : ChangeItem(player, int.Parse(arg.Args[1]), arg.Args[2], arg.Args.Length > 3 ? arg.Args[3] : " ", 0);
break;
case "skin" : ChangeItem(player, int.Parse(arg.Args[1]), arg.Args[2], arg.Args.Length > 3 ? arg.Args[3] : " ", 1);
break;
case "amount" : ChangeItem(player, int.Parse(arg.Args[1]), arg.Args[2], arg.Args.Length > 3 ? arg.Args[3] : " ", 2);
break;
case "cost" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (int.TryParse(arg.Args[1], out int cost)) {
if (cost < 1) cost = 0;
else editKit.Cost = cost;
}
}
else editKit.Cost = 0;
break;
case "currency" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) editKit.Currency = String.Join(" ", arg.Args.Skip(1));
else editKit.Currency = _config.DefaultCurrency;
break;
case "savekit" : if (!string.IsNullOrEmpty(editKit.ParentName)) SaveKit(player, true, editKit);
else SaveKit(player, false, editKit);
break;
case "image" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
editKit.KitImage = arg.Args[1];
RegisterNewImage($"KitEdit{editKit.KitName}", arg.Args[1]);
}
else editKit.KitImage = null;
break;
case "name" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) editKit.KitName = String.Join(" ", arg.Args.Skip(1));
break;
case "category" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) editKit.Category = String.Join(" ", arg.Args.Skip(1));
else editKit.Category = null;
break;
case "kitinventory" : SaveItems(player);
break;
case "autokit" : if (editKit.IsAutoKit) editKit.IsAutoKit = false;
else editKit.IsAutoKit = true;
break;
case "closeitem" : CuiHelper.DestroyUi(player, "KCMainItemEdit");
break;
case "deleteitem" : editKit.Items.RemoveAll(x => x.Position == int.Parse(arg.Args[1]) && x.Container == arg.Args[2]);
var playerInfo = GetOrLoadPlayerOptions(player);
playerInfo.ActiveCategory = null;
CuiHelper.DestroyUi(player, "KCMainItemEdit");
break;
case "hidden" : if (editKit.Hidden) editKit.Hidden = false;
else editKit.Hidden = true;
break;
case "categoryselect" : var catString = string.Join(" ", arg.Args.Skip(1));
switch (catString) {
case "CLOSE" : CuiHelper.DestroyUi(player, "KCCategoryDropdown");
break;
case "ALL" : editKit.Category = null;
break;
default : editKit.Category = catString;
break;
}
break;
case "categoryui" : UICategoryDropdownFunctionality(player);
break;
case "description" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) editKit.Description = String.Join(" ", arg.Args.Skip(1));
else editKit.Description = null;
break;
case "nopermtext" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) editKit.NoPermissionText = String.Join(" ", arg.Args.Skip(1));
else editKit.NoPermissionText = null;
break;
case "permission" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
var permission = arg.Args[1];
if (!permission.Contains("kitcontroller.")) permission = "kitcontroller." + permission;
editKit.Permission = permission;
}
else editKit.Permission = null;
break;
case "autokitpriority" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (int.TryParse(arg.Args[1], out int priority)) {
if (priority < 1) priority = 0;
else editKit.AutoKitPriority = priority;
}
}
else editKit.AutoKitPriority = 0;
break;
case "cooldown" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (double.TryParse(arg.Args[1], out double cooldown)) {
if (cooldown < 0) cooldown = 0;
else editKit.Cooldown = cooldown;
}
}
else editKit.Cooldown = 0;
break;
case "maxuses" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (int.TryParse(arg.Args[1], out int maxuses)) {
if (maxuses < 0) maxuses = 0;
else editKit.MaxUses = maxuses;
}
}
else editKit.MaxUses = 0;
break;
case "wipecooldown" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (double.TryParse(arg.Args[1], out double wipecooldown)) {
if (wipecooldown < 0) wipecooldown = 0;
else editKit.WipeCooldown = wipecooldown;
}
}
else editKit.WipeCooldown = 0;
break;
}
if (arg.Args[0] != "savekit" && arg.Args[0] != "selectitem" && arg.Args[0] != "categoryui" && arg.Args[0] != "deletekit") {
if (arg.Args[0] == "image") timer.Once(.3f, () => {
if (_kitEdits.ContainsKey(player.userID)) UICreateEditOverlayPage(player);
}
);
else UICreateEditOverlayPage(player);
}
}
[ConsoleCommand("kc_kit")]
private void ConsoleKitKits(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (arg == null || player == null) return;
var playerOptions = GetOrLoadPlayerOptions(player);
switch (arg.Args[0]) {
case "itemspage" : UICreateKits(player, playerOptions, int.Parse(arg.Args[1]), string.Join(" ", arg.Args.Skip(2)));
break;
case "claim" : var clamKit = ClaimKit(player, string.Join(" ", arg.Args.Skip(1)));
SendReply(player, Lang("ChatTitle") + " " + clamKit.Reason);
CuiHelper.DestroyUi(player, "KCMainPanel");
CuiHelper.DestroyUi(player, "KCMainViewPanel");
if (usingWC) {
CuiHelper.DestroyUi(player, "BackgroundPanel");
CuiHelper.DestroyUi(player, "BackgrounPanel");
}
break;
case "view" : UICreateViewPage(player, string.Join(" ", arg.Args.Skip(1)));
CuiHelper.DestroyUi(player, "KCMainPanel");
break;
case "viewclose" : CuiHelper.DestroyUi(player, "KCMainViewPanel");
OpenKitUI(player);
break;
}
}
[ChatCommand("kitadmin")]
private void CMDAdminCommands(BasePlayer player, string command, string[] args) {
if (player == null) return;
HandleAdminCommands(player, args.Length == 0 ? null : args, true);
}
#endregion
#region Methods
string GetCurrencyType(aKit kit) {
var kitCurrency = kit.Currency.ToLower();
switch (kitCurrency) {
case "rp" : return Lang("RPPlaceholder", null, $"{kit.Cost}");
case "economics" : return Lang("EconomicsPlaceholder", null, $"{kit.Cost}");
default : return Lang("ItemPlaceholder", null, $"{kit.Cost}");
}
}
CanPurchase CanBuy(BasePlayer player, aKit kit) {
var kitCurrency = kit.Currency.ToLower();
switch (kitCurrency) {
case "rp" : var points = ServerRewards?.Call("CheckPoints", (ulong)player.userID);
if (kit.Cost > (points == null ? 0 : double.Parse($"{points}"))) return new CanPurchase {
CanBuy = false, Reason = Lang("RPNotEnough", null, kit.KitName)
}
;
else return new CanPurchase {
CanBuy = true
}
;
case "economics" : var eco = Economics?.Call("Balance", (ulong)player.userID);
if (kit.Cost > (eco == null ? 0 : double.Parse($"{eco}"))) return new CanPurchase {
CanBuy = false, Reason = Lang("EconomicsNotEnough", null, kit.KitName)
}
;
else return new CanPurchase {
CanBuy = true
}
;
default : var theItem = ItemManager.CreateByName(kit.Currency);
if (theItem == null) return new CanPurchase {
CanBuy = false, Reason = Lang("CurrencyNotFound")
}
;
List<Item> itemList = Facepunch.Pool.Get<List<Item>>();
player.inventory.GetAllItems(itemList);
var inventoryItemCount = itemList.Where(x => x.info.shortname.Equals(theItem.info.shortname)).Sum(x => x.amount);
itemList.Clear();
Facepunch.Pool.FreeUnsafe(ref itemList);
if (kit.Cost > inventoryItemCount) return new CanPurchase {
CanBuy = false, Reason = Lang("ItemNotEnough", null, kit.KitName)
}
;
else return new CanPurchase {
CanBuy = true
}
;
}
}
void BuyKit(BasePlayer player, aKit kit) {
var kitCurrency = kit.Currency.ToLower();
switch (kitCurrency) {
case "rp" : ServerRewards?.Call("TakePoints", (ulong)player.userID, kit.Cost);
break;
case "economics" : Economics?.Call("Withdraw", (ulong)player.userID, (double)kit.Cost);
break;
default : List<ItemChange> needsEditedList = new List<ItemChange>();
List<ItemChange> needsRemovedList = new List<ItemChange>();
int amountLeft = kit.Cost;
List<Item> itemList = Facepunch.Pool.Get<List<Item>>();
player.inventory.GetAllItems(itemList);
foreach (var item in itemList.Where(x => x.info.shortname.Equals(kit.Currency, StringComparison.OrdinalIgnoreCase))) {
if (amountLeft >= item.amount) {
needsRemovedList.Add(new ItemChange {
Amount = item.amount, Item = item
}
);
amountLeft -= item.amount;
}
else if (amountLeft < item.amount) {
n
// ... [Code preview truncated due to length. Full source in attached file] ...