C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Oxide.Game.Rust.Cui;
using System;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
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.Globalization;
using Facepunch;
using Newtonsoft.Json.Converters;
using System.Threading.Tasks;
using System.Timers;
using Facepunch.Extend;
namespace Oxide.Plugins {
[Info("ShopController", "Amino", "1.0.8")]
[Description("A sleek shop system for Rust")]
public class ShopController : RustPlugin {
[PluginReference]
private Plugin ServerRewards, Economics, ImageLibrary, WelcomeController, NoEscape;
#region Config
public static Configuration _config;
public UIElements _uiColors;
public class Configuration {
[JsonProperty("Commands")]
public List<string> Commands {
get;
set;
}
= new List<string>();
[JsonProperty(PropertyName = "Currency (RP, Economics, item.shortname)")]
public string Currency {
get;
set;
}
= "RP";
[JsonProperty(PropertyName = "Use Cart System")]
public bool UseCartSystem {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Allow Players to Save Carts")]
public bool AllowedToSaveCarts {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Commands section enabled")]
public bool UseCommandsSection {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Sell back enabled")]
public bool SellBackEnabled {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Clear redeemed items on wipe")]
public bool ClearDataOnWipe {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Block players from opening shop if raid blocked")]
public bool RaidblockBlock {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Block players from opening shop if combat blocked")]
public bool CombatblockBlock {
get;
set;
}
= true;
[JsonProperty(PropertyName = "Plugin images")]
public Images Images {
get;
set;
}
= new Images();
[JsonProperty(PropertyName = "UI Elements")]
public UIElements UIElements {
get;
set;
}
= new UIElements();
public Dictionary<string, List<ItemOption>> ItemList = new Dictionary<string, List<ItemOption>>();
public static Configuration DefaultConfig() {
return new Configuration {
Commands = new List<string> {
"shop", "s"
}
, Images = new Images {
CommandImagePlaceholder = "https://i.ibb.co/MNNw1W1/Buy-Command3.png", SellBackImage = "https://i.ibb.co/CWrwbQH/Money-Bag2.png"
}
}
;
}
}
public class Images {
[JsonProperty(PropertyName = "Command Image Placeholder")]
public string CommandImagePlaceholder {
get;
set;
}
[JsonProperty(PropertyName = "Sell Back Image")]
public string SellBackImage {
get;
set;
}
}
public class UIElements {
public string BlurBackgroundColor {
get;
set;
}
= "0 0 0.4";
public string MainPanelColor {
get;
set;
}
= ".17.17.17 1";
public string ThingBackgroundColor {
get;
set;
}
= "1 1 1.1";
public string PrimaryButtonColor {
get;
set;
}
= ".39.76 1.4";
public string PrimaryButtonTextColor {
get;
set;
}
= ".39.76 1.6";
public string SecondaryButtonColor {
get;
set;
}
= "0.46 0.46 0.46.4";
public string SecondaryButtonTextColor {
get;
set;
}
= "0.46 0.46 0.46.5";
public string ThirdButtonColor {
get;
set;
}
= "0.1 1 0.16.4";
public string ThirdButtonTextColor {
get;
set;
}
= "0.1 1 0.16.6";
public string FourthButtonColor {
get;
set;
}
= "1 0.17 0.17.4";
public string FourthButtonTextColor {
get;
set;
}
= "1 0.17 0.17.6";
public string CooldownLabelColor {
get;
set;
}
= "0.74 0.23 0.15 1";
public string CooldownLabelTextColor {
get;
set;
}
= "0.99 0.34 0.24 1";
}
protected override void LoadConfig() {
base.LoadConfig();
try {
_config = Config.ReadObject<Configuration>();
if (_config == null) LoadDefaultConfig();
_uiColors = _config.UIElements;
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 & Constructors
public Dictionary<string, List<ItemOption>> _itemList = new Dictionary<string, List<ItemOption>>();
public Dictionary<ulong, PlayerSettings> _playerSettings = new Dictionary<ulong, PlayerSettings>();
public List<CommandOption> _commandList = new List<CommandOption>();
public bool usingWC = false;
System.Random rnd = new System.Random();
public static DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0);
public static double LastWipe;
public class CommandOption {
public string CommandName {
get;
set;
}
public string CommandImage {
get;
set;
}
public int CommandPrice {
get;
set;
}
public string CommandExpiry {
get;
set;
}
= "Never";
public double CommandCooldown {
get;
set;
}
public List<string> Commands {
get;
set;
}
= new List<string>();
public bool CommandEnabled {
get;
set;
}
public int CommandSpecialId {
get;
set;
}
public CommandOption() {
}
public CommandOption Clone() {
return new CommandOption {
CommandName = this.CommandName, CommandImage = this.CommandImage, CommandPrice = this.CommandPrice, CommandExpiry = this.CommandExpiry, CommandCooldown = this.CommandCooldown, CommandEnabled = this.CommandEnabled, CommandSpecialId = this.CommandSpecialId, Commands = new List<string>(this.Commands),
}
;
}
}
public class ItemOption {
public int ItemId {
get;
set;
}
public string Shortname {
get;
set;
}
public string DisplayName {
get;
set;
}
public ulong SkinId {
get;
set;
}
= 0;
public bool InUse {
get;
set;
}
public int Amount {
get;
set;
}
public int Cost {
get;
set;
}
public double Cooldown {
get;
set;
}
public int SpecialId {
get;
set;
}
public ItemOption() {
}
public ItemOption(ItemOption other) {
this.ItemId = other.ItemId;
this.Shortname = other.Shortname;
this.DisplayName = other.DisplayName;
this.SkinId = other.SkinId;
this.InUse = other.InUse;
this.Amount = other.Amount;
this.Cost = other.Cost;
this.Cooldown = other.Cooldown;
this.SpecialId = other.SpecialId;
}
public ItemOption Clone() {
return new ItemOption {
ItemId = this.ItemId, Shortname = this.Shortname, DisplayName = this.DisplayName, SkinId = this.SkinId, InUse = this.InUse, Amount = this.Amount, Cost = this.Cost, Cooldown = this.Cooldown, SpecialId = this.SpecialId,
}
;
}
}
public class CartItem {
public string Text {
get;
set;
}
public int SpecialId {
get;
set;
}
public int ItemId {
get;
set;
}
public int Count {
get;
set;
}
public int Cost {
get;
set;
}
public CartItem() {
}
public CartItem(CartItem other) {
this.Text = other.Text;
this.SpecialId = other.SpecialId;
this.Count = other.Count;
this.Cost = other.Cost;
}
public CartItem Clone() {
return new CartItem {
Text = this.Text, SpecialId = this.SpecialId, Count = this.Count, Cost = this.Cost
}
;
}
}
public class ItemChange {
public Item Item {
get;
set;
}
public int Amount {
get;
set;
}
}
public class CanAddItem {
public bool canAdd {
get;
set;
}
public string Reason {
get;
set;
}
}
public class PlayerSettings {
public string Category {
get;
set;
}
public int CategoryPage = 0;
public int ItemPage = 0;
public string EditCategory = "Attire";
public int EditCategoryPage = 0;
public int EditItemPage = 0;
public string EditItemFilter {
get;
set;
}
public double LastWipe {
get;
set;
}
public int EditItem = 0;
public bool WC = false;
public string ItemFilter {
get;
set;
}
public ItemOption ItemOption = null;
public CommandOption CommandOption = null;
public int CommandsPage = 0;
public int CommandsEditPage = 0;
public int CommandsEditSelectPage = 0;
public int CurrentCartPage = 0;
public int CurrentSavedCartPage = 0;
public string CartView = null;
public string CurrentCart = null;
public List<CartItem> CurrentCartItems = new List<CartItem>();
public Dictionary<string, List<CartItem>> Carts = new Dictionary<string, List<CartItem>>();
public List<RedeemedItems> RedeemedItems = new List<RedeemedItems>();
public List<RedeemedItems> RedeemedCommands = new List<RedeemedItems>();
}
public class RedeemedItems {
public int SpecialId {
get;
set;
}
public double Cooldown {
get;
set;
}
}
public class MethodResponse {
public bool CanBuy {
get;
set;
}
public string Title {
get;
set;
}
public double Amount {
get;
set;
}
}
#endregion
#region Lang
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["Close"]
= "CLOSE", ["StoreName"] = "SHOP", ["NoPermission"] = "You do not have permisson to use this command", ["FreeButton"] = "FREE!", ["AddButton"] = "ADD", ["CartLabel"] = "CART", ["BuyCart"] = "PURCHASE CART", ["CartOptions"] = "CART OPTIONS", ["SaveCart"] = "SAVE CART", ["SavedCarts"] = "SAVED CARTS", ["ItemsButton"] = "ITEMS", ["CommandsButton"] = "COMMANDS", ["BuySavedCart"] = "BUY ${0}", ["Load"] = "LOAD", ["Override"] = "OVERRIDE", ["Delete"] = "DELETE", ["SuccessfulItemPurchase"] = "Successfully purchased <color=#4f8aff>{0}x</color> <color=#82acff>{1}</color> for <color=#4f8aff>${2}</color>!", ["NotEnoughRoom"] = "Not enough space in your inventory to purchase!", ["NotEnoughCurrency"] = "You do not have enough <color=#4f8aff>{0}</color> to purchase this!", ["CommandPrice"] = "COST", ["CommandExpiry"] = "EXPIRES", ["CommandPurchase"] = "PURCHASE", ["InsufficientFunds"] = "Insufficient funds!", ["CurrencyNotFound"] = "Could not find currency, please message admins.", ["SuccessfullyPurchasedCommand"] = "You have successfully purchased <color=#4f8aff>{0}</color> for <color=#4f8aff>${1}</color>!", ["SuccessSaveCart"] = "Successfully saved your cart!", ["SuccessDeletedCart"] = "Successfully deleted your cart!", ["SuccessOverrodeCart"] = "Successfully overrode your cart!", ["SuccessLoadedCart"] = "Successfully loaded your cart!", ["SellBackButton"] = "SELL", ["RPPlaceholder"] = "RP: {0}", ["EcomonicsPlaceholder"] = "${0}", ["ItemsPlaceholder"] = "${0}", ["SoldBackToShop"] = "Item successfully sold back to shop!", ["CombatRaidblocked"] = "You are currently combat / raidblocked and cannot access the shop!"
}
, this, "en");
}
private string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
#endregion
#region Hooks
private void Unload() {
if (!Interface.Oxide.IsShuttingDown) foreach (BasePlayer player in BasePlayer.activePlayerList) {
CuiHelper.DestroyUi(player, "SOCMainPanel");
SavePlayerSettings(player);
}
SaveCommandList();
_config = null;
}
void OnServerSave() {
foreach (BasePlayer player in BasePlayer.activePlayerList) {
SavePlayerSettings(player);
}
}
void OnServerInitialized(bool initial) {
var isUsingWC = Interface.Call("IsUsingPlugin", "ShopController");
if (isUsingWC != null && (isUsingWC is bool)) usingWC = (bool)isUsingWC;
else usingWC = false;
RegisterCommandsAndPermissions();
GenerateCommandList();
RegisterImages();
if ((Steamworks.SteamInventory.Definitions?.Length ?? 0) == 0) Steamworks.SteamInventory.OnDefinitionsUpdated += StartItemRequest;
else StartItemRequest();
LastWipe = SaveRestore.SaveCreatedTime.Subtract(Epoch).TotalSeconds;
}
void OnPlayerDisconnected(BasePlayer player, string reason) {
if (player == null || !player.userID.Get().IsSteamId()) return;
SavePlayerSettings(player);
_playerSettings.Remove(player.userID);
}
void OnWCRequestedUIPanel(BasePlayer player, string panelName, string neededPlugin) {
if (!neededPlugin.Equals("ShopController", StringComparison.OrdinalIgnoreCase)) return;
usingWC = true;
CMDOpenShop(player, null, null);
}
void OnPluginLoaded(Plugin plugin) {
if (plugin.Name == "WelcomeController") {
var isUsingWC = Interface.Call("IsUsingPlugin", "ShopController");
if (isUsingWC != null && (isUsingWC is bool)) usingWC = (bool)isUsingWC;
else usingWC = false;
}
}
void OnPluginUnloaded(Plugin plugin) {
if (plugin.Name == "WelcomeController") {
usingWC = false;
RegisterCommandsAndPermissions();
}
}
#endregion
#region Commands
[ConsoleCommand("soc_main")]
private void CMDSocMain(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (player == null) return;
var playerSettings = GetPlayerSettings(player);
switch (arg.Args[0]) {
case "close" : CuiHelper.DestroyUi(player, "SOCMainPanel");
break;
case "itempage" : playerSettings.ItemPage = int.Parse(arg.Args[1]);
UIGenerateShopItems(player, playerSettings);
break;
case "itemfilter" : string joinedString = String.Join(" ", arg.Args.Skip(1));
bool isOnlyLetters = joinedString.All(c => char.IsLetter(c) || c == ' ');
if (isOnlyLetters && joinedString != "SEARCH") playerSettings.ItemFilter = joinedString;
else playerSettings.ItemFilter = null;
playerSettings.CommandsPage = 0;
playerSettings.ItemPage = 0;
UIGenerateShopSearch(player, playerSettings);
UIGenerateShopItems(player, playerSettings);
UIGenerateShopCategories(player, playerSettings);
break;
case "buyitem" : var theItem = _itemList.SelectMany(x => x.Value).Where(x => x.SpecialId == int.Parse(arg.Args[1])).Select(x => new ItemOption(x)).FirstOrDefault();
PurchaseItem(player, playerSettings, theItem);
UIGenerateShopItems(player, playerSettings);
UIGenerateShopSearch(player, playerSettings);
break;
case "category" : playerSettings.Category = arg.Args[1];
UIGenerateShopItems(player, playerSettings);
UIGenerateShopCategories(player, playerSettings);
break;
case "categorypage" : playerSettings.CategoryPage = int.Parse(arg.Args[1]);
UIGenerateShopCategories(player, playerSettings);
break;
case "additem" : var specialId = int.Parse(arg.Args[1]);
var cost = int.Parse(arg.Args[2]);
var itemId = int.Parse(arg.Args[3]);
var inCart = playerSettings.CurrentCartItems.FirstOrDefault(x => x.SpecialId == specialId);
if (inCart != null) inCart.Count++;
else playerSettings.CurrentCartItems.Add(new CartItem {
Count = 1, SpecialId = specialId, Cost = cost, ItemId = itemId
}
);
UIGenerateCart(player, playerSettings);
break;
case "itempanel" : UIGenerateTopBar(player, playerSettings, false);
UIGenerateShopItems(player, playerSettings);
UIGenerateShopCategories(player, playerSettings);
break;
case "commandpanel" : UIGenerateShopCategories(player, playerSettings, true);
UIGenerateCommands(player, playerSettings);
break;
case "commandspage" : playerSettings.CommandsPage = int.Parse(arg.Args[1]);
UIGenerateShopCategories(player, playerSettings, true);
UIGenerateCommands(player, playerSettings);
break;
case "buycommand" : var theCommand = _commandList.FirstOrDefault(x => x.CommandSpecialId == int.Parse(arg.Args[1]));
BuyCommand(player, playerSettings, theCommand);
UIGenerateShopItems(player, playerSettings);
UIGenerateShopSearch(player, playerSettings);
break;
case "sellback" : theItem = _itemList.SelectMany(x => x.Value).FirstOrDefault(x => x.SpecialId == int.Parse(arg.Args[1]));
if (theItem == null) return;
var canSell = SellBack(player, theItem);
if (canSell.CanBuy) {
SendReply(player, Lang("SoldBackToShop"));
UICreatePopup(player, Lang("SoldBackToShop"), true);
}
else {
SendReply(player, canSell.Title);
UICreatePopup(player, canSell.Title, false);
}
UIGenerateShopSearch(player, playerSettings);
break;
}
}
[ConsoleCommand("soc_cart")]
private void CMDSocCart(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (player == null) return;
List<string> dontOpenFor = new List<string> {
"view"
}
;
var playerSettings = GetPlayerSettings(player);
switch (arg.Args[0]) {
case "removeitem" : var specialId = int.Parse(arg.Args[1]);
var theItem = playerSettings.CurrentCartItems.FirstOrDefault(x => x.SpecialId == specialId);
if (theItem != null) {
theItem.Count--;
if (theItem.Count <= 0) playerSettings.CurrentCartItems.Remove(theItem);
}
break;
case "deleteitem" : specialId = int.Parse(arg.Args[1]);
playerSettings.CurrentCartItems.RemoveAll(x => x.SpecialId == specialId);
break;
case "page" : playerSettings.CurrentCartPage = int.Parse(arg.Args[1]);
break;
case "save" : playerSettings.Carts.Add($"{rnd.Next(1, 9999999)}", playerSettings.CurrentCartItems.Select(x => new CartItem(x)).ToList());
UICreatePopup(player, Lang("SuccessSaveCart"), true);
break;
case "savedpage" : playerSettings.CurrentSavedCartPage = int.Parse(arg.Args[1]);
break;
case "view" : playerSettings.CartView = arg.Args[1];
break;
case "closeview" : playerSettings.CartView = null;
break;
case "buycart" : PurchaseCart(player, playerSettings);
UIGenerateShopItems(player, playerSettings);
UIGenerateShopSearch(player, playerSettings);
break;
case "load" : playerSettings.CurrentCartItems = playerSettings.Carts[playerSettings.CartView].Select(x => new CartItem(x)).ToList();
playerSettings.CurrentCart = playerSettings.CartView;
playerSettings.CartView = null;
UICreatePopup(player, Lang("SuccessLoadedCart"), true);
break;
case "override" : playerSettings.Carts[playerSettings.CartView] = playerSettings.CurrentCartItems.Select(x => new CartItem(x)).ToList();
playerSettings.CartView = null;
UICreatePopup(player, Lang("SuccessOverrodeCart"), true);
break;
case "delete" : playerSettings.Carts.Remove(playerSettings.CartView);
playerSettings.CurrentSavedCartPage = 0;
playerSettings.CartView = null;
UICreatePopup(player, Lang("SuccessDeletedCart"), true);
break;
}
UIGenerateCart(player, playerSettings, arg.Args[0] == "view");
}
[ConsoleCommand("soc_edit")]
private void CMDSocEdit(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (player == null) return;
var playerSettings = GetPlayerSettings(player);
switch (arg.Args[0]) {
case "close" : CMDOpenShop(player, null, null);
break;
case "open" : UIGenerateTopBar(player, playerSettings, true);
CuiHelper.DestroyUi(player, "SOCShopMiddlePanelOverlay");
CuiHelper.DestroyUi(player, "SOCShopBottomPanelOverlay");
playerSettings.ItemOption = _itemList["Attire"].First();
playerSettings.EditCategory = "Attire";
playerSettings.EditItem = playerSettings.ItemOption.ItemId;
UIGenerateEditPage(player, playerSettings);
break;
case "category" : playerSettings.EditCategory = arg.Args[1];
playerSettings.ItemOption = _itemList[playerSettings.EditCategory].First();
playerSettings.EditItemPage = 0;
playerSettings.EditItem = playerSettings.ItemOption.ItemId;
UIGenerateEditItems(player, playerSettings);
UIGenerateItemEdit(player, playerSettings);
UIGenerateEditCategories(player, playerSettings);
break;
case "categorypage" : playerSettings.EditCategoryPage = int.Parse(arg.Args[1]);
UIGenerateEditCategories(player, playerSettings);
break;
case "item" : var neededItems = _itemList.SelectMany(x => x.Value);
if (string.IsNullOrEmpty(playerSettings.EditItemFilter)) neededItems = _itemList[playerSettings.EditCategory];
playerSettings.ItemOption = neededItems.FirstOrDefault(x => x.ItemId == int.Parse(arg.Args[1]));
if (playerSettings.ItemOption == null) return;
playerSettings.EditItem = playerSettings.ItemOption.ItemId;
UIGenerateEditItems(player, playerSettings);
UIGenerateItemEdit(player, playerSettings);
break;
case "itempage" : playerSettings.EditItemPage = int.Parse(arg.Args[1]);
UIGenerateEditItems(player, playerSettings);
break;
case "itemfilter" : if (arg.Args.Length < 2) playerSettings.EditItemFilter = null;
else {
string joinedString = String.Join(" ", arg.Args.Skip(1));
bool isOnlyLetters = joinedString.All(c => char.IsLetter(c) || c == ' ');
if (isOnlyLetters) playerSettings.EditItemFilter = joinedString;
}
UIGenerateEditItems(player, playerSettings);
UIGenerateEditCategories(player, playerSettings);
break;
case "displayname" : playerSettings.ItemOption.DisplayName = arg.Args.Length > 1 ? string.Join(" ", arg.Args.Skip(1)) : playerSettings.ItemOption.DisplayName;
UIGenerateEditItems(player, playerSettings);
UIGenerateItemEdit(player, playerSettings);
break;
case "enabled" : if (playerSettings.ItemOption.InUse) playerSettings.ItemOption.InUse = false;
else playerSettings.ItemOption.InUse = true;
UIGenerateItemEdit(player, playerSettings);
bool en = playerSettings.ItemOption.InUse;
UICreatePopup(player, $"Successfully {(en ? "enabled" : "disabled")} item", en ? true : false);
break;
case "amount" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (int.TryParse(arg.Args[1], out int amount)) {
if (amount < 1) playerSettings.ItemOption.Amount = 1;
else playerSettings.ItemOption.Amount = amount;
}
}
UIGenerateItemEdit(player, playerSettings);
break;
case "cooldown" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (double.TryParse(arg.Args[1], out double amount)) {
if (amount < 1) playerSettings.ItemOption.Cooldown = 0;
else playerSettings.ItemOption.Cooldown = amount;
}
}
UIGenerateItemEdit(player, playerSettings);
break;
case "skinid" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (ulong.TryParse(arg.Args[1], out ulong skinid)) {
if (skinid < 1) playerSettings.ItemOption.SkinId = 0;
else playerSettings.ItemOption.SkinId = skinid;
}
}
UIGenerateItemEdit(player, playerSettings);
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) playerSettings.ItemOption.SkinId = 0;
else playerSettings.ItemOption.Cost = cost;
}
}
UIGenerateItemEdit(player, playerSettings);
break;
case "itempanel" : UIGenerateEditItems(player, playerSettings);
UIGenerateItemEdit(player, playerSettings);
UIGenerateEditCategories(player, playerSettings);
break;
case "commandpanel" : playerSettings.CommandOption = null;
UIGenerateEditCommands(player, playerSettings);
UIGenerateCommandEdit(player, playerSettings);
UIGenerateEditCategories(player, playerSettings, true);
break;
}
SaveConfig();
}
[ConsoleCommand("soc_editcommand")]
private void CMDSocEditCommand(ConsoleSystem.Arg arg) {
var player = arg.Player();
if (player == null) return;
var playerSettings = GetPlayerSettings(player);
switch (arg.Args[0]) {
case "close" : CMDOpenShop(player, null, null);
break;
case "selectcommand" : var foundCommand = _commandList.FirstOrDefault(x => x.CommandSpecialId == int.Parse(arg.Args[1])).Clone();
playerSettings.CommandOption = foundCommand;
if (!string.IsNullOrEmpty(playerSettings.CommandOption.CommandImage)) RegisterNewImage($"EditCommand{playerSettings.CommandOption.CommandName}", playerSettings.CommandOption.CommandImage);
UIGenerateCommandEdit(player, playerSettings);
UIGenerateEditCommands(player, playerSettings);
break;
case "altercommand" : var joinedString = string.Join(" ", arg.Args.Skip(2));
var index = int.Parse(arg.Args[1]);
if (string.IsNullOrEmpty(arg.Args[2])) playerSettings.CommandOption.Commands.RemoveAt(index);
else playerSettings.CommandOption.Commands[index] = joinedString;
UIGenerateCommandEdit(player, playerSettings);
break;
case "addcommand" : joinedString = string.Join(" ", arg.Args.Skip(1));
if (!string.IsNullOrEmpty(joinedString) && joinedString != "INSERT COMMAND") playerSettings.CommandOption.Commands.Add(joinedString);
UIGenerateCommandEdit(player, playerSettings);
break;
case "addnewcommand" : playerSettings.CommandOption = new CommandOption();
UIGenerateEditCommands(player, playerSettings);
UIGenerateCommandEdit(player, playerSettings);
break;
case "deletecommand" : playerSettings.CommandOption.Commands.RemoveAt(int.Parse(arg.Args[1]));
UIGenerateCommandEdit(player, playerSettings);
break;
case "deletesavedcommand" : _commandList.RemoveAll(x => x.CommandSpecialId == playerSettings.CommandOption.CommandSpecialId);
playerSettings.CommandOption = null;
UICreatePopup(player, "Successfully deleted command", false);
UIGenerateEditCommands(player, playerSettings);
UIGenerateCommandEdit(player, playerSettings);
break;
case "page" : playerSettings.CommandsEditPage = int.Parse(arg.Args[1]);
UIGenerateCommandEdit(player, playerSettings);
break;
case "commandpage" : playerSettings.CommandsEditSelectPage = int.Parse(arg.Args[1]);
UIGenerateEditCommands(player, playerSettings);
break;
case "displayname" : playerSettings.CommandOption.CommandName = String.Join(" ", arg.Args.Skip(1));
UIGenerateCommandEdit(player, playerSettings);
break;
case "savecommand" : if (playerSettings.CommandOption.CommandSpecialId == 0) {
var cmdClone = playerSettings.CommandOption.Clone();
cmdClone.CommandSpecialId = rnd.Next(1, 9999999);
playerSettings.CommandOption.CommandSpecialId = cmdClone.CommandSpecialId;
_commandList.Add(cmdClone);
}
else _commandList[_commandList.FindIndex(x => x.CommandSpecialId == playerSettings.CommandOption.CommandSpecialId)] = playerSettings.CommandOption.Clone();
RegisterNewImage($"Command{playerSettings.CommandOption.CommandName}", playerSettings.CommandOption.CommandImage);
timer.Once(.1f, () => {
UIGenerateCommandEdit(player, playerSettings);
}
);
UIGenerateEditCommands(player, playerSettings);
UICreatePopup(player, "Successfully saved command", true);
break;
case "image" : if (arg.Args.Length < 2) playerSettings.CommandOption.CommandImage = null;
else {
playerSettings.CommandOption.CommandImage = arg.Args[1];
RegisterNewImage($"EditCommand{playerSettings.CommandOption.CommandName}", arg.Args[1]);
timer.Once(.2f, () => {
UIGenerateCommandEdit(player, playerSettings);
}
);
}
break;
case "expiry" : playerSettings.CommandOption.CommandExpiry = String.Join(" ", arg.Args.Skip(1));
UIGenerateCommandEdit(player, playerSettings);
break;
case "price" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (int.TryParse(arg.Args[1], out int amount)) {
if (amount < 1) playerSettings.CommandOption.CommandPrice = 0;
else playerSettings.CommandOption.CommandPrice = amount;
}
}
UIGenerateCommandEdit(player, playerSettings);
break;
case "cooldown" : if (arg.Args.Length > 1 && !string.IsNullOrEmpty(arg.Args[1])) {
if (int.TryParse(arg.Args[1], out int amount)) {
if (amount < 1) playerSettings.CommandOption.CommandCooldown = 0;
else playerSettings.CommandOption.CommandCooldown = amount;
}
}
UIGenerateCommandEdit(player, playerSettings);
break;
}
}
#endregion
#region UI
private bool IsBlocked(BasePlayer player) {
if (NoEscape != null) {
if (_config.RaidblockBlock && NoEscape.Call<bool>("IsRaidBlocked", player.UserIDString)) return true;
if (_config.CombatblockBlock && NoEscape.Call<bool>("IsCombatBlocked", player.UserIDString)) return true;
}
return false;
}
private void CMDOpenShop(BasePlayer player, string command, string[] args) {
if (player == null) return;
if (!permission.UserHasPermission(player.UserIDString, "shopcontroller.use")) {
SendReply(player, Lang("NoPermission"));
return;
}
if (IsBlocked(player)) {
SendReply(player, Lang("CombatRaidblocked", player.UserIDString));
if (usingWC) CuiHelper.DestroyUi(player, "BackgrounPanel");
return;
}
var playerSettings = GetPlayerSettings(player);
if (string.IsNullOrEmpty(playerSettings.Category)) playerSettings.Category = _itemList.FirstOrDefault(x => x.Value.Any(y => y.InUse)).Key;
var container = new CuiElementContainer();
CreatePanel(ref container, "0 0", "1 1", usingWC ? "0 0 0 0" : _uiColors.BlurBackgroundColor, usingWC ? "WCSourcePanel" : "Overlay", "SOCMainPanel", true, true);
CreatePanel(ref container, usingWC ? "0 0" : ".15.1", usingWC ? "1 1" : ".85.9", "0 0 0 0", "SOCMainPanel", "SOCShopPanel");
UIOpenShop(player, ref container, playerSettings);
}
private void UIOpenShop(BasePlayer player, ref CuiElementContainer container, PlayerSettings playerSettings) {
CreatePanel(ref container, "0.9", "1 1", _uiColors.MainPanelColor, "SOCShopPanel", "SOCShopTopPanel");
CreatePanel(ref container, "0.11", "1.89", _uiColors.MainPanelColor, "SOCShopPanel", "SOCShopMiddlePanel");
CreatePanel(ref container, "0 0", "1.1", _uiColors.MainPanelColor, "SOCShopPanel", "SOCShopBottomPanel");
CreatePanel(ref container, "0 -.08", "1 -.01", _uiColors.MainPanelColor, "SOCShopPanel", "SOCShopSearchPanel");
CuiHelper.DestroyUi(player, "SOCMainPanel");
CuiHelper.AddUi(player, container);
UIGenerateTopBar(player, playerSettings, false);
UIGenerateShopItems(player, playerSettings);
UIGenerateShopCategories(player, playerSettings);
UIGenerateShopSearch(player, playerSettings);
}
void UIGenerateEditCommands(BasePlayer player, PlayerSettings playerSettings) {
var container = new CuiElementContainer();
var panel = CreatePanel(ref container, "0 0", "1 1", "0 0 0 0", "SOCShopEditItemsPanel", "SOCShopEditItemsPanelOverlay");
var maxPage = _commandList.Count / 10;
if (playerSettings.CommandsEditSelectPage > maxPage) playerSettings.CommandsEditSelectPage = 0;
if (playerSettings.CommandsEditSelectPage < 0) playerSettings.CommandsEditSelectPage = maxPage;
var pageItems = _commandList.Skip(9 * playerSettings.CommandsEditSelectPage).Take(9);
if (_commandList.Count != 0 && playerSettings.CommandOption == null) playerSettings.CommandOption = _commandList.First().Clone();
int i = 0;
foreach (var command in pageItems) {
var isButton = playerSettings.CommandOption != null && playerSettings.CommandOption.CommandSpecialId == command.CommandSpecialId;
CreateButton(ref container, $".019 {.9052 - (i *.0908)}", $".975 {.985 - (i *.0908)}", isButton ? _uiColors.PrimaryButtonColor : _uiColors.SecondaryButtonColor, isButton ? _uiColors.PrimaryButtonTextColor : _uiColors.SecondaryButtonTextColor, command.CommandName, 20, $"soc_editcommand selectcommand {command.CommandSpecialId}", panel);
i++;
}
if (_commandList.Count > 9) {
CreateButton(ref container, ".019.11", ".49.168", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "<", 20, $"soc_editcommand commandpage {playerSettings.CommandsEditSelectPage - 1}", panel);
CreateButton(ref container, ".51.11", ".975.168", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, ">", 20, $"soc_editcommand commandpage {playerSettings.CommandsEditSelectPage + 1}", panel);
}
else {
CreatePanel(ref container, ".019.11", ".49.17", _uiColors.SecondaryButtonColor, panel);
CreatePanel(ref container, ".51.11", ".975.17", _uiColors.SecondaryButtonColor, panel);
}
CreateButton(ref container, ".019.01", ".975.098", _uiColors.PrimaryButtonColor, _uiColors.PrimaryButtonTextColor, "CREATE NEW COMMAND", 20, "soc_editcommand addnewcommand", panel);
CuiHelper.DestroyUi(player, "SOCShopEditItemsPanelOverlay");
CuiHelper.AddUi(player, container);
}
void UIGenerateCommandEdit(BasePlayer player, PlayerSettings playerSettings) {
if (playerSettings.CommandOption == null) playerSettings.CommandOption = new CommandOption();
var commandOption = playerSettings.CommandOption;
var container = new CuiElementContainer();
var panel = CreatePanel(ref container, "0 0", "1 1", "0 0 0 0", "SOCShopItemEditPanel", "SOCShopItemEditPanelOverlay");
CreateLabel(ref container, ".008.93", ".989.985", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "COMMAND DISPLAY NAME", 15, TextAnchor.MiddleCenter, panel);
CreateInput(ref container, ".008.77", ".989.92", "soc_editcommand displayname", _uiColors.ThingBackgroundColor, "1 1 1 1", String.IsNullOrEmpty(commandOption.CommandName) ? " " : commandOption.CommandName, 30, TextAnchor.MiddleCenter, panel);
CreateLabel(ref container, ".504.705", ".7425.76", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "EXPIRY (STRING)", 15, TextAnchor.MiddleCenter, panel);
CreateInput(ref container, ".504.6", ".7425.695", "soc_editcommand expiry", _uiColors.ThingBackgroundColor, "1 1 1.1", String.IsNullOrEmpty(commandOption.CommandExpiry) ? " " : commandOption.CommandExpiry, 15, TextAnchor.MiddleCenter, panel);
CreateLabel(ref container, ".7505.705", ".989.76", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "PRICE", 15, TextAnchor.MiddleCenter, panel);
CreateInput(ref container, ".7505.6", ".989.695", "soc_editcommand price", _uiColors.ThingBackgroundColor, "1 1 1.1", $"{commandOption.CommandPrice}", 15, TextAnchor.MiddleCenter, panel);
CreateLabel(ref container, ".504.535", ".7425.59", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "IMAGE", 15, TextAnchor.MiddleCenter, panel);
CreateInput(ref container, ".504.43", ".7425.525", "soc_editcommand image", _uiColors.ThingBackgroundColor, "1 1 1.1", String.IsNullOrEmpty(commandOption.CommandImage) ? " " : commandOption.CommandImage, 15, TextAnchor.MiddleCenter, panel);
CreateLabel(ref container, ".7505.535", ".989.59", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "COOLDOWN (SEC)", 15, TextAnchor.MiddleCenter, panel);
CreateInput(ref container, ".7505.43", ".989.525", "soc_editcommand cooldown", _uiColors.ThingBackgroundColor, "1 1 1.1", $"{commandOption.CommandCooldown}", 15, TextAnchor.MiddleCenter, panel);
var imgPanel = CreatePanel(ref container, ".504.01", ".989.42", _uiColors.ThingBackgroundColor, panel);
CreateImagePanel(ref container, ".225.05", ".775.95", String.IsNullOrEmpty(playerSettings.CommandOption.CommandImage) ? GetImage("CommandPlaceholder") : GetImage($"EditCommand{playerSettings.CommandOption.CommandName}"), imgPanel);
CreateButton(ref container, ".008.01", ".237.098", _uiColors.ThirdButtonColor, _uiColors.ThirdButtonTextColor, "SAVE COMMAND", 18, "soc_editcommand savecommand", panel);
CreateButton(ref container, ".247.01", ".494.098", _uiColors.FourthButtonColor, _uiColors.FourthButtonTextColor, "DELETE COMMAND", 18, "soc_editcommand deletesavedcommand", panel);
CreateLabel(ref container, ".008.705", ".496.76", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "COMMANDS TO RUN | VARS: <color=#e27aff>{id}</color> <color=#a77aff>{name}</color> <color=#907aff>{x}</color> <color=#7aa0ff>{y}</color> <color=#7ac5ff>{z}</color>", 13, TextAnchor.MiddleCenter, panel);
var maxPage = playerSettings.CommandOption.Commands.Count / 5;
if (playerSettings.CommandsEditPage > maxPage) playerSettings.CommandsEditPage = 0;
if (playerSettings.CommandsEditPage < 0) playerSettings.CommandsEditPage = maxPage;
var pageItems = playerSettings.CommandOption.Commands.Skip(5 * playerSettings.CommandsEditPage).Take(5);
int i = 0;
foreach (var command in pageItems) {
var inputPnl = CreateInput(ref container, $".008 {.6 - (i *.105)}", $".496 {.695 - (i *.105)}", $"soc_editcommand altercommand {i}", _uiColors.ThingBackgroundColor, "1 1 1.1", command, 15, TextAnchor.MiddleCenter, panel);
CreateButton(ref container, ".01 0", ".12 1", "0 0 0 0", "1 1 1.15", "X", 20, $"soc_editcommand deletecommand {i}", inputPnl);
i++;
}
if (pageItems.Count() < 5) CreateInput(ref container, $".008 {.6 - (i *.105)}", $".496 {.695 - (i *.105)}", "soc_editcommand addcommand", _uiColors.ThingBackgroundColor, "1 1 1.1", "INSERT COMMAND", 15, TextAnchor.MiddleCenter, panel);
if (playerSettings.CommandOption.Commands.Count > 4) {
CreateButton(ref container, ".008.11", ".237.17", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, "<", 15, $"soc_editcommand page {playerSettings.CommandsEditPage - 1}", panel);
CreateButton(ref container, ".247.11", ".494.17", _uiColors.SecondaryButtonColor, _uiColors.SecondaryButtonTextColor, ">", 15, $"soc_editcommand page {playerSettings.CommandsEditPage + 1}", panel);
}
else {
CreatePanel(ref
// ... [Code preview truncated due to length. Full source in attached file] ...