C#:
using Facepunch;
using Oxide.Core;
using System.Text;
using Oxide.Core.Plugins;
using System;
using System.Collections.Generic;
using Oxide.Plugins.XDShopExtensionMethods;
using UnityEngine;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using System.Collections;
/// <summary>
/// - исправления после обновления
/// - исправления NRE
/// - теперь скидка не будет отображаться если вы не используете их
/// </summary>
namespace Oxide.Plugins {
[Info("XDShop", "Sempai#3239", "1.3.5")]
[Description("Large easily customizable store")]
internal class XDShop : RustPlugin {
private void CONFIRMATIONSUI(BasePlayer player, int itemID, int indexCategory, int amount, ThemeType themetype) {
Configuration.InterfaceSettings.ThemeCustomization theme = themetype == ThemeType.Dark ? _config.interfaceSettings.DarkTheme : _config.interfaceSettings.LightTheme;
Configuration.CategoryShop.Product product = GetCategories(player)[indexCategory].product.Find(x => x.ID == itemID);
float discount = GetUserDiscount(player);
int playerLim = GetLimit(player, product, true);
string limit = playerLim == -1 ? GetLang("XDSHOP_UI_PATTERN", player.UserIDString) : playerLim + "/" + product.GetLimitLotWipe(player, true);
CuiElementContainer container = new CuiElementContainer {
new CuiElement {
Name = ConfirmationsPanel, Parent = PanelProduct, Components = {
new CuiRawImageComponent {
Color = theme.colorMainBG, Png =GetImage($"{Name}_" +"13")
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-230.488 -109.615", OffsetMax = "261.007 77.799"
}
}
}
, new CuiElement {
Name = "IMAGE_PRODUCT_BACKGROUND", Parent = ConfirmationsPanel, Components = {
new CuiRawImageComponent {
Color = theme.colortext6, Png =GetImage($"{Name}_" +"15")
}
, new CuiRectTransformComponent {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "46.52 -114.22", OffsetMax = "122.52 -42.22"
}
}
}
}
;
if (!string.IsNullOrWhiteSpace(product.Url) || product.Type == ItemType.Kit || product.Type == ItemType.Command) {
container.Add(new CuiElement {
Name = "PRODUCT_IMAGE", Parent = "IMAGE_PRODUCT_BACKGROUND", Components = {
new CuiRawImageComponent {
Color = "1 1 1 1", Png = GetImage(string.IsNullOrWhiteSpace(product.Url) ? "NONE" : product.Url)
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-30 -30", OffsetMax = "30 30"
}
}
}
);
}
else if (product.Type == ItemType.CustomItem) {
container.Add(new CuiElement {
Name = "PRODUCT_IMAGE", Parent = "IMAGE_PRODUCT_BACKGROUND", Components = {
new CuiRawImageComponent {
Color = "1 1 1 1", Png = GetImage(product.ShortName + 60, product.SkinID)
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-30 -30", OffsetMax = "30 30"
}
}
}
);
}
else if (product.Type == ItemType.Item) {
container.Add(new CuiElement {
Name = "PRODUCT_IMAGE", Parent = "IMAGE_PRODUCT_BACKGROUND", Components = {
new CuiImageComponent {
Color = "1 1 1 1", ItemId = ItemManager.FindItemDefinition(product.ShortName).itemid
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-30 -30", OffsetMax = "30 30"
}
}
}
);
}
else {
container.Add(new CuiElement {
Name = "PRODUCT_IMAGE", Parent = "IMAGE_PRODUCT_BACKGROUND", Components = {
new CuiImageComponent {
Color = "1 1 1 1", ItemId = ItemManager.FindItemDefinition("blueprintbase").itemid
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-30 -30", OffsetMax = "30 30"
}
}
}
);
container.Add(new CuiElement {
Name = "PRODUCT_IMAGE", Parent = "IMAGE_PRODUCT_BACKGROUND", Components = {
new CuiImageComponent {
Color = "1 1 1 1", ItemId = ItemManager.FindItemDefinition(product.ShortName).itemid
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-30 -30", OffsetMax = "30 30"
}
}
}
);
}
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-118.134 -68.265", OffsetMax = "8.346 -39.543"
}
, Text = {
Text = product.GetProductName(player.UserIDString), Font = "robotocondensed-bold.ttf", FontSize = 11, Align = TextAnchor.LowerLeft, Color = theme.colortext7
}
,
}
, ConfirmationsPanel);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-118.134 -137.191", OffsetMax = "8.346 -70.689"
}
, Text = {
Text = GetLang("XDSHOP_UI_PRODUCT_INFO", player.UserIDString, GetDiscountedPrice(product.Price * amount, discount) + _config.economicsCustomization.PrefixBalance, product.Amount * amount, limit), Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleLeft, Color = theme.Colortext5
}
,
}
, ConfirmationsPanel);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = "-228.122 -8.202", OffsetMax = "-44.678 54.164"
}
, Text = {
Text = product.GetProductDescription(), Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.UpperLeft, Color = theme.Colortext5
}
,
}
, ConfirmationsPanel);
container.Add(new CuiElement {
Name = "PRODUCT_BUY_BTN", Parent = ConfirmationsPanel, Components = {
new CuiRawImageComponent {
Color = theme.colortext8, Png =GetImage($"{Name}_" +"14")
}
, new CuiRectTransformComponent {
AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = "-162.4 42.9", OffsetMax = "-109.4 63.9"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Command = $"UI_HandlerShop PRODUCT_BUY {itemID} {indexCategory} {amount} {themetype}", Color = "0 0 0 0"
}
, Text = {
Text = GetLang("XDSHOP_UI_BTN_BUY", player.UserIDString).ToUpper(), Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleCenter
}
}
, "PRODUCT_BUY_BTN");
container.Add(new CuiElement {
Name = "PRODUCT_CLOSE_BTN", Parent = ConfirmationsPanel, Components = {
new CuiRawImageComponent {
Color = theme.closeBtnColor2, Png = GetImage($"{Name}_" +"14")
}
, new CuiRectTransformComponent {
AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = "-100 42.9", OffsetMax = "-47 63.9"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Close = "CONFIRMATIONS_PANEL", Color = "0 0 0 0"
}
, Text = {
Text = GetLang("XDSHOP_UI_PRODUCT_INFO_EXIT", player.UserIDString), Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleCenter
}
}
, "PRODUCT_CLOSE_BTN");
CuiHelper.DestroyUi(player, ConfirmationsPanel);
CuiHelper.AddUi(player, container);
}
[ConsoleCommand("xdshop.refill")]
private void CmdShopItemsRefill(ConsoleSystem.Arg arg) {
if (arg.Connection != null && arg.Connection.authLevel <= 0) return;
SendReply(arg, GetLang("XDSHOP_SERVICE_CMD_REFILL"));
ulong userId = arg.Connection == null || arg.IsRcon ? 0U : arg.Connection.userid;
if (_pdpw.Contains(userId)) return;
_pdpw.Add(userId);
timer.In(15, () => {
if (_pdpw.Contains(userId)) _pdpw.Remove(userId);
}
);
}
private const string MainLayer = "MAIN_SHOP_LAYER";
private class CooldownData {
public DateTime Buy = new DateTime(1970, 1, 1, 0, 0, 0);
public DateTime Sell = new DateTime(1970, 1, 1, 0, 0, 0);
}
private void AddLimit(BasePlayer player, Configuration.CategoryShop.Product item, int lots, bool purchase) {
PlayerLimits.GetOrAddPlayer(player.userID).AddItem(item, lots, purchase);
}
private void Purchasing(BasePlayer player, int itemId, int category, int amount, ThemeType themetype) {
Configuration.CategoryShop.Product product = GetCategories(player)[category].product.Find(x => x.ID == itemId);
if (product != null) {
if (IsDuel(player)) {
NotificationUI(player, NotificationType.Error, GetLang("XDSHOP_UI_NOTIFICATION_IS_DUEL", player.UserIDString));
return;
}
if (_config.mainSettings.RaidBlock && IsRaid(player)) {
NotificationUI(player, NotificationType.Error, GetLang("XDSHOP_UI_NOTIFICATION_IS_RAID", player.UserIDString));
return;
}
if (product.Type == ItemType.Blueprint || product.Type == ItemType.CustomItem || product.Type == ItemType.Item) {
List<int> stack = GetStacks(product.Definition, product.Amount * amount);
int slots = player.inventory.containerBelt.capacity - player.inventory.containerBelt.itemList.Count + (player.inventory.containerMain.capacity - player.inventory.containerMain.itemList.Count);
if (slots < stack.Count) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_NOT_ENOUGH_SPACE", player.UserIDString));
return;
}
}
float price = GetDiscountedPrice(product.Price * amount, GetUserDiscount(player));
if (GetBalance(player) < price) {
NotificationUI(player, NotificationType.Error, GetLang("XDSHOP_UI_NOTIFICATION_INSUFFICIENT_FUNDS", player.UserIDString));
return;
}
if (product.BuyCooldown > 0) {
int cooldown = GetCooldownTime(player.userID, product, true);
if (cooldown > 0) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_BUY_RECHARGE", player.UserIDString, product.GetProductName(player.UserIDString), TimeHelper.FormatTime(TimeSpan.FromSeconds(cooldown), 5, lang.GetLanguage(player.UserIDString))));
return;
}
SetCooldown(player, product, true);
}
int limit = GetLimit(player, product, true);
if (limit != -1) {
if (limit == 0) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_BUY_LIMIT", player.UserIDString, product.GetProductName(player.UserIDString)));
return;
}
else if (amount > limit) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_BUY_LIMIT_1", player.UserIDString, product.GetProductName(player.UserIDString), limit));
return;
}
AddLimit(player, product, amount, true);
}
switch (_config.economicsCustomization.TypeEconomic) {
case EconomicsType.Economics : if ((bool)Economics?.Call("Withdraw", player.userID, (double)price)) {
GiveProduct(player, product, amount);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_PURCHASE", player.UserIDString, product.GetProductName(player.UserIDString)));
}
break;
case EconomicsType.ServerRewards : if (ServerRewards?.Call<object>("TakePoints", player.userID, (int)price) != null) {
GiveProduct(player, product, amount);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_PURCHASE", player.UserIDString, product.GetProductName(player.UserIDString)));
}
break;
case EconomicsType.IQEconomic : IQEconomic?.Call("API_REMOVE_BALANCE", player.userID, (int)price);
GiveProduct(player, product, amount);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_PURCHASE", player.UserIDString, product.GetProductName(player.UserIDString)));
break;
case EconomicsType.Item : TakeItem(player.inventory.AllItems(), _config.economicsCustomization.EconomicShortname, (int)price, _config.economicsCustomization.EconomicSkinId);
GiveProduct(player, product, amount);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_PURCHASE", player.UserIDString, product.GetProductName(player.UserIDString)));
break;
}
}
}
private const string ProductAmountChangeBg = "PRODUCT_AMOUNT_CHANGE_BG";
private enum EconomicsType {
Economics, ServerRewards, IQEconomic, Item
}
private void NotificationUI(BasePlayer player, NotificationType type, string msg) {
string color = type == NotificationType.Error ? "1.00 0.30 0.31 1.00" : type == NotificationType.Warning ? "0.98 0.68 0.08 1.00" : "0.32 0.77 0.10 1.00";
ThemeType themeType = _playerThemeSelect[player.userID];
Configuration.InterfaceSettings.ThemeCustomization theme = themeType == ThemeType.Dark ? _config.interfaceSettings.DarkTheme : _config.interfaceSettings.LightTheme;
CuiElementContainer container = new CuiElementContainer {
new CuiElement {
FadeOut = 0.30f, Name = NotificationMain, Parent = "Overlay", Components = {
new CuiRawImageComponent {
Color = theme.colorMainBG, Png =GetImage($"{Name}_" +"16"), FadeIn = 0.30f
}
, new CuiRectTransformComponent {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "112 -78", OffsetMax = "383 -10"
}
}
}
, new CuiElement {
FadeOut = 0.30f, Name = "NOTIFICATION_POLOSA", Parent = NotificationMain, Components = {
new CuiRawImageComponent {
Color = color, Png = GetImage($"{Name}_" +"17") , FadeIn = 0.30f
}
, new CuiRectTransformComponent {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-95.99 -1.97", OffsetMax = "75.01 2.03"
}
}
}
, new CuiElement {
FadeOut = 0.30f, Name = "NOTIFICATION_IMG", Parent = NotificationMain, Components = {
new CuiRawImageComponent {
Color = color, Png = GetImage($"{Name}_" +"10") , FadeIn = 0.30f
}
, new CuiRectTransformComponent {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "13.5 -32.47", OffsetMax = "73.5 28.53"
}
}
}
, {
new CuiLabel {
FadeOut = 0.30f, RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-58 -32.47", OffsetMax = "119.546 28.53"
}
, Text = {
Text = msg, Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleLeft, Color = theme.Colortext10, FadeIn = 0.30f
}
,
}
, NotificationMain, "NOTIFICATION_TEXT"
}
}
;
CuiHelper.DestroyUi(player, "NOTIFICATION_POLOSA");
CuiHelper.DestroyUi(player, "NOTIFICATION_IMG");
CuiHelper.DestroyUi(player, "NOTIFICATION_TEXT");
CuiHelper.DestroyUi(player, NotificationMain);
CuiHelper.AddUi(player, container);
DeleteNotification(player);
}
private void GiveProduct(BasePlayer player, Configuration.CategoryShop.Product product, int amount) {
switch (product.Type) {
case ItemType.Item : GetStacks(product.Definition, product.Amount * amount)?.ForEach(stack => {
Item newItem = ItemManager.CreateByPartialName(product.ShortName, stack);
player.GiveItem(newItem, BaseEntity.GiveItemReason.PickedUp);
}
);
break;
case ItemType.Blueprint : GetStacks(product.Definition, product.Amount * amount)?.ForEach(stack => {
Item itemBp = ItemManager.CreateByItemID(-996920608, stack);
if (itemBp.instanceData == null) itemBp.instanceData = new ProtoBuf.Item.InstanceData();
itemBp.instanceData.ShouldPool = false;
itemBp.instanceData.blueprintAmount = 1;
itemBp.instanceData.blueprintTarget = product.Definition.itemid;
itemBp.MarkDirty();
player.GiveItem(itemBp, BaseEntity.GiveItemReason.PickedUp);
}
);
break;
case ItemType.CustomItem : GetStacks(product.Definition, product.Amount * amount)?.ForEach(stack => {
Item customItem = ItemManager.CreateByPartialName(product.ShortName, stack, product.SkinID);
customItem.name = product.Name;
player.GiveItem(customItem, BaseEntity.GiveItemReason.PickedUp);
}
);
break;
case ItemType.Command : foreach (string cammand in product.Commands) Server.Command(cammand.Replace("%STEAMID%", player.UserIDString));
break;
case ItemType.Kit : if (Kits) Kits.Call("GiveKit", player, product.KitName);
else if (IQKits) IQKits.Call("API_KIT_GIVE", player, product.KitName);
break;
}
}
[ConsoleCommand("xdshop.no")]
private void CmdShopItemsRefillNo(ConsoleSystem.Arg arg) {
if (arg.Connection != null && arg.Connection.authLevel <= 0) return;
ulong userId = arg.Connection == null || arg.IsRcon ? 0U : arg.Connection.userid;
if (!_pdpw.Contains(userId)) return;
SendReply(arg, GetLang("XDSHOP_SERVICE_CMD_REFILL_NO"));
_pdpw.Remove(userId);
}
private float GetDiscountedPrice(float price, float discount) {
float dicsount = (price * discount / 100);
return (float)Math.Round(price - dicsount, 2);
}
private void UPDATEAMOUNTUI(BasePlayer player, int index, int cat, int amount, ThemeType themetype) {
Configuration.InterfaceSettings.ThemeCustomization theme = themetype == ThemeType.Dark ? _config.interfaceSettings.DarkTheme : _config.interfaceSettings.LightTheme;
Configuration.CategoryShop.Product item = GetCategories(player)[cat].product.Find(x => x.ID == index);
if (amount <= 0 || (item.GetLimitLot(player, true) != 0 && amount > item.GetLimitLot(player, true)) || amount >= 100) return;
float discount = GetUserDiscount(player);
bool isSale = item.PriceSales != 0 && item.Price == 0;
CuiElementContainer container = new CuiElementContainer {
{
new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-10.064 -8", OffsetMax = "9.372 8"
}
, Text = {
Text = amount.ToString(), Font = "robotocondensed-regular.ttf", FontSize = 9, Align = TextAnchor.MiddleCenter, Color = themetype == ThemeType.Dark ? "1 1 1 1" : "0 0 0 1"
}
,
}
, ProductAmountChangeBg + $"_{index}", $"PRODUCT_LOT_COUNT_{index}"
}
, {
new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-53.25 68.035", OffsetMax = "38.45 83.165"
}
, Text = {
Text = "x" + (isSale ? item.AmountSales * amount : item.Amount * amount), Font = "robotocondensed-regular.ttf", FontSize = 10, Align = TextAnchor.MiddleLeft, Color = theme.colortext2
}
,
}
, $"PRODUCT_BACKGROUND_{index}", $"PRODUCT_AMOUNT_{index}"
}
, {
new CuiButton {
RectTransform = {
AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-63 0", OffsetMax = "63 15"
}
, Button = {
Command = isSale ? $"UI_HandlerShop PRODUCT_SALE_CONFIRMATION {item.ID} {cat} {amount} {themetype}" : $"UI_HandlerShop PRODUCT_BUY_CONFIRMATION {index} {cat} {amount} {themetype}", Color = isSale ? theme.colortext9 : theme.colortext8
}
, Text = {
Text = isSale ? GetLang("XDSHOP_UI_BTN_SALLE", player.UserIDString) : GetLang("XDSHOP_UI_BTN_BUY", player.UserIDString), FontSize = 12, Align = TextAnchor.MiddleCenter
}
}
, $"PRODUCT_BACKGROUND_{index}", isSale ? $"PRODUCT_SELL_BTN_{index}" : $"PRODUCT_BUY_BTN_{index}"
}
, {
new CuiButton {
RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "0 -8", OffsetMax = "14.936 8"
}
, Button = {
Command = $"UI_HandlerShop AMOUNT_CHANGE_MINUS {index} {cat} {amount} {themetype} 0", Color = "0 0 0 0"
}
, Text = {
Text = ""
}
}
, ProductAmountChangeBg + $"_{index}", $"PRODUCT_AMOUNT_MINUS_{index}"
}
, {
new CuiButton {
RectTransform = {
AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = "-15.628 -8", OffsetMax = "0 8"
}
, Button = {
Command = $"UI_HandlerShop AMOUNT_CHANGE_PLUS {index} {cat} {amount} {themetype} 0", Color = "0 0 0 0"
}
, Text = {
Text = ""
}
}
, ProductAmountChangeBg + $"_{index}", $"PRODUCT_AMOUNT_PLUS_{index}"
}
, {
new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-41.852 -55.831", OffsetMax = "5.011 -34.169"
}
, Text = {
Text = $"{(isSale ? item.PriceSales * amount : GetDiscountedPrice((item.Price * amount), discount))}{_config.economicsCustomization.PrefixBalance}", Font = "robotocondensed-bold.ttf", FontSize = 13, Align = TextAnchor.MiddleLeft, Color = "0.24 0.48 0.71 1.00"
}
,
}
, $"PRODUCT_BACKGROUND_{index}", $"PRODUCT_PRICE_{index}"
}
}
;
CuiHelper.DestroyUi(player, $"PRODUCT_AMOUNT_{index}");
CuiHelper.DestroyUi(player, $"PRODUCT_LOT_COUNT_{index}");
CuiHelper.DestroyUi(player, $"PRODUCT_PRICE_{index}");
CuiHelper.DestroyUi(player, $"PRODUCT_AMOUNT_PLUS_{index}");
CuiHelper.DestroyUi(player, $"PRODUCT_AMOUNT_PLUS_{index}");
CuiHelper.DestroyUi(player, $"PRODUCT_AMOUNT_MINUS_{index}");
CuiHelper.DestroyUi(player, isSale ?$"PRODUCT_SELL_BTN_{index}" : $"PRODUCT_BUY_BTN_{index}");
CuiHelper.AddUi(player, container);
}
private void OnPlayerDisconnected(BasePlayer player, string reason) {
if (_uiPlayerUseNow.Contains(player.userID)) _uiPlayerUseNow.Remove(player.userID);
if (_config.humanNpcs.UseHumanNpcs) if (_humanNpcPlayerOpen.ContainsKey(player.userID)) _humanNpcPlayerOpen.Remove(player.userID);
}
private void UPDATE_UI_SELLING(BasePlayer player, int itemId, int indexCategory, int amount, ThemeType themetype) {
CuiElementContainer container = new CuiElementContainer();
Configuration.CategoryShop.Product product = GetCategories(player)[indexCategory].product.Find(x => x.ID == itemId);
if (amount <= 0 || (product.GetLimitLot(player, false) != 0 && amount > product.GetLimitLot(player, false)) || amount >= 100) return;
int playerLim = GetLimit(player, product, false);
string limit = playerLim == -1 ? GetLang("XDSHOP_UI_PATTERN", player.UserIDString) : playerLim + "/" + product.GetLimitLotWipe(player, false);
Configuration.InterfaceSettings.ThemeCustomization theme = themetype == ThemeType.Dark ? _config.interfaceSettings.DarkTheme : _config.interfaceSettings.LightTheme;
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Command = $"UI_HandlerShop PRODUCT_SALE {itemId} {indexCategory} {amount} {themetype}", Color = "0 0 0 0"
}
, Text = {
Text = GetLang("XDSHOP_UI_BTN_SALLE", player.UserIDString).ToUpper(), Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleCenter
}
}
, "PRODUCT_BUY_BTN", "PRODUCT_BUY_GO");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-10.064 -8", OffsetMax = "9.372 8"
}
, Text = {
Text = amount.ToString(), Font = "robotocondensed-regular.ttf", FontSize = 9, Align = TextAnchor.MiddleCenter, Color = themetype == ThemeType.Dark ? "1 1 1 1" : "0 0 0 1"
}
,
}
, ProductAmountChangeBg, $"PRODUCT_LOT_COUNT");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "0 -8", OffsetMax = "14.936 8"
}
, Button = {
Command = $"UI_HandlerShop AMOUNT_CHANGE_MINUS {itemId} {indexCategory} {amount} {themetype} 1", Color = "0 0 0 0"
}
, Text = {
Text = ""
}
}
, ProductAmountChangeBg, $"PRODUCT_AMOUNT_MINUS");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "1 0.5", AnchorMax = "1 0.5", OffsetMin = "-15.628 -8", OffsetMax = "0 8"
}
, Button = {
Command = $"UI_HandlerShop AMOUNT_CHANGE_PLUS {itemId} {indexCategory} {amount} {themetype} 1", Color = "0 0 0 0"
}
, Text = {
Text = ""
}
}
, ProductAmountChangeBg, $"PRODUCT_AMOUNT_PLUS");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-118.134 -137.191", OffsetMax = "8.346 -70.689"
}
, Text = {
Text = GetLang("XDSHOP_UI_PRODUCT_SELL_INFO", player.UserIDString, GetDiscountedPrice(product.PriceSales * amount, GetUserDiscount(player)) + _config.economicsCustomization.PrefixBalance, product.AmountSales * amount, limit), Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleLeft, Color = theme.Colortext5
}
,
}
, ConfirmationsPanelSelling, "PRODUCT_SELLING_DESC");
CuiHelper.DestroyUi(player, "PRODUCT_BUY_GO");
CuiHelper.DestroyUi(player, "PRODUCT_AMOUNT_MINUS");
CuiHelper.DestroyUi(player, "PRODUCT_AMOUNT_PLUS");
CuiHelper.DestroyUi(player, "PRODUCT_LOT_COUNT");
CuiHelper.DestroyUi(player, "PRODUCT_SELLING_DESC");
CuiHelper.AddUi(player, container);
}
private void OnNewSave(string filename) {
_playerDataLimits.Players.Clear();
_playerDataCooldowns.Clear();
}
private const string CategoryLayer = "CATEGORY_LAYER";
private void Selling(BasePlayer player, int itemId, int category, int amount, ThemeType themetype) {
Configuration.CategoryShop.Product product = GetCategories(player)[category].product.Find(x => x.ID == itemId);
if (product == null) return;
if (IsDuel(player)) {
NotificationUI(player, NotificationType.Error, GetLang("XDSHOP_UI_NOTIFICATION_SELL_IS_DUEL", player.UserIDString));
return;
}
if (_config.mainSettings.RaidBlock && IsRaid(player)) {
NotificationUI(player, NotificationType.Error, GetLang("XDSHOP_UI_NOTIFICATION_IS_RAID", player.UserIDString));
return;
}
Item[] playerItems = player.inventory.AllItems();
int needAmount = product.AmountSales * amount;
bool blueprint = product.Type == ItemType.Blueprint;
if (blueprint || product.Type == ItemType.CustomItem || product.Type == ItemType.Item) {
if (GetItemAmount(playerItems, product.ShortName, product.SkinID, blueprint) < needAmount) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_NOT_ENOUGH_ITEM", player.UserIDString));
return;
}
}
float price = product.PriceSales * amount;
if (product.SellCooldown > 0) {
int cooldown = GetCooldownTime(player.userID, product, false);
if (cooldown > 0) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_SELL_RECHARGE", player.UserIDString, product.GetProductName(player.UserIDString), TimeHelper.FormatTime(TimeSpan.FromSeconds(cooldown), 5, lang.GetLanguage(player.UserIDString))));
return;
}
SetCooldown(player, product, false);
}
int limit = GetLimit(player, product, false);
if (limit != -1) {
if (limit == 0) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_SELL_LIMIT", player.UserIDString, product.GetProductName(player.UserIDString)));
return;
}
else if (amount > limit) {
NotificationUI(player, NotificationType.Warning, GetLang("XDSHOP_UI_NOTIFICATION_SELL_LIMIT_1", player.UserIDString, product.GetProductName(player.UserIDString), limit));
return;
}
AddLimit(player, product, amount, false);
}
switch (_config.economicsCustomization.TypeEconomic) {
case EconomicsType.Economics : if ((bool)Economics?.Call("Deposit", player.userID, (double)price)) {
TakeItem(playerItems, product.ShortName, needAmount, product.SkinID, blueprint);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_SALE", player.UserIDString, product.GetProductName(player.UserIDString)));
}
break;
case EconomicsType.ServerRewards : if (ServerRewards?.Call<object>("AddPoints", player.userID, (int)price) != null) {
TakeItem(playerItems, product.ShortName, needAmount, product.SkinID, blueprint);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_SALE", player.UserIDString, product.GetProductName(player.UserIDString)));
}
break;
case EconomicsType.IQEconomic : IQEconomic?.Call("API_SET_BALANCE", player.userID, (int)price);
TakeItem(playerItems, product.ShortName, needAmount, product.SkinID, blueprint);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_SALE", player.UserIDString, product.GetProductName(player.UserIDString)));
break;
case EconomicsType.Item : Item item = ItemManager.CreateByName(_config.economicsCustomization.EconomicShortname, (int)price, _config.economicsCustomization.EconomicSkinId);
player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp);
TakeItem(playerItems, product.ShortName, needAmount, product.SkinID, blueprint);
UpdateBalance(player, themetype);
NotificationUI(player, NotificationType.Success, GetLang("XDSHOP_UI_NOTIFICATION_SUCCESSFUL_SALE", player.UserIDString, product.GetProductName(player.UserIDString)));
break;
}
}
private static Dictionary<string, string> _imageList = new Dictionary<string, string> {
["0"]
= "https://i.imgur.com/2KCXXmf.png", ["1"] = "https://i.imgur.com/J5WoK4d.png", ["2"] = "https://i.imgur.com/ZR7bbZm.png", ["3"] = "https://i.imgur.com/lariGpB.png", ["4"] = "https://i.imgur.com/jjEsmL5.png", ["5"] = "https://i.imgur.com/jo3WN9H.png", ["6"] = "https://i.imgur.com/odqNSDS.png", ["7"] = "https://i.imgur.com/xOWHmh0.png", ["8"] = "https://i.imgur.com/gcdpOnw.png", ["9"] = "https://i.imgur.com/NkekyV4.png", ["10"] = "https://i.imgur.com/z88veYB.png", ["11"] = "https://i.imgur.com/yENDy73.png", ["12"] = "https://i.imgur.com/khOBy3x.png", ["13"] = "https://i.imgur.com/e0y4aM5.png", ["14"] = "https://i.imgur.com/d5YRaLB.png", ["15"] = "https://i.imgur.com/eV9QUa0.png", ["16"] = "https://i.imgur.com/e0FCvGc.png", ["17"] = "https://i.imgur.com/Tbv05TC.png", ["18"] = "https://i.imgur.com/qIkeHGq.png",
}
;
public static StringBuilder StringBuilderInstance;
private void OnLeaveNPC(BasePlayer npc, BasePlayer player) {
if (!_config.humanNpcs.NPCs.ContainsKey(npc.UserIDString)) return;
if (!_humanNpcPlayerOpen.ContainsKey(player.userID)) return;
_humanNpcPlayerOpen.Remove(player.userID);
if (_uiPlayerUseNow.Contains(player.userID)) _uiPlayerUseNow.Remove(player.userID);
CuiHelper.DestroyUi(player, "NOTIFICATION_POLOSA");
CuiHelper.DestroyUi(player, "NOTIFICATION_IMG");
CuiHelper.DestroyUi(player, "NOTIFICATION_TEXT");
CuiHelper.DestroyUi(player, NotificationMain);
CuiHelper.DestroyUi(player, MainLayer);
}
private string GetImage(string fileName, ulong skin = 0) {
string imageId = (string)plugins.Find("ImageLibrary").CallHook("GetImage", fileName, skin);
if (!string.IsNullOrEmpty(imageId)) return imageId;
return string.Empty;
}
private const string ConfirmationsPanelSelling = "CONFIRMATIONS_PANEL_SELLING";
private readonly List<ulong> _pdpw = new List<ulong>();
private Dictionary<ulong, ThemeType> _playerThemeSelect = new Dictionary<ulong, ThemeType>();
private void ValidateConfig() {
foreach (Configuration.CategoryShop category in _config.product) {
foreach (Configuration.CategoryShop.Product product in category.product) {
foreach (KeyValuePair<string, int> buyLimits in product.BuyLimits) if (!permission.PermissionExists(buyLimits.Key)) permission.RegisterPermission(buyLimits.Key, this);
foreach (KeyValuePair<string, int> sellLimits in product.SellLimits) if (!permission.PermissionExists(sellLimits.Key)) permission.RegisterPermission(sellLimits.Key, this);
foreach (KeyValuePair<string, int> buyLimitsWipe in product.BuyLimitsWipe) if (!permission.PermissionExists(buyLimitsWipe.Key)) permission.RegisterPermission(buyLimitsWipe.Key, this);
foreach (KeyValuePair<string, int> sellLimitsWipe in product.SellLimitsWipe) if (!permission.PermissionExists(sellLimitsWipe.Key)) permission.RegisterPermission(sellLimitsWipe.Key, this);
}
if (!permission.PermissionExists(category.PermissionCategory)) permission.RegisterPermission(category.PermissionCategory, this);
}
}
private void CheckingProducts() {
foreach (Configuration.CategoryShop category in _config.product) {
foreach (Configuration.CategoryShop.Product product in category.product) {
if (product.ID == 0) product.ID = Core.Random.Range(int.MinValue, int.MaxValue);
if (product.Type == ItemType.Item || product.Type == ItemType.Blueprint || product.Type == ItemType.CustomItem) {
product.Definition = ItemManager.FindItemDefinition(product.ShortName);
if (product.Definition == null) {
product.ItemsError = true;
PrintError(GetLang("XDSHOP_SERVICE_CONFIG_1", args : product.ID));
continue;
}
}
if (product.Price <= 0 && product.PriceSales <= 0) {
product.ItemsError = true;
PrintError(GetLang("XDSHOP_SERVICE_CONFIG_2", args : product.ID));
}
}
}
}
private void UIMAIN(BasePlayer player, ThemeType themetype) {
Configuration.InterfaceSettings.ThemeCustomization theme = themetype == ThemeType.Dark ? _config.interfaceSettings.DarkTheme : _config.interfaceSettings.LightTheme;
float discount = GetUserDiscount(player);
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiElement {
Name = PanelProduct, Parent = MainLayer, Components = {
new CuiRawImageComponent {
Color = theme.colorMainBG, Png =GetImage($"{Name}_" +"0")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1"
}
}
}
);
container.Add(new CuiButton {
Button = {
Color = "0 0 0 0", Command = "UI_HandlerShop CLOSE_ALL_UI"
}
, Text = {
Text = "x", Font = "robotocondensed-bold.ttf", FontSize = 13, Align = TextAnchor.MiddleCenter, Color = theme.CloseBtnColor
}
, RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-27.467 -24.554", OffsetMax = "-6.946 -5.983"
}
}
, PanelProduct, "CLOSE_MENU_BTN");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "115.291 -40.197", OffsetMax = "248.709 -21.203"
}
, Text = {
Text = GetLang("XDSHOP_UI_TITLE", player.UserIDString), Font = "robotocondensed-regular.ttf", FontSize = 11, Align = TextAnchor.MiddleLeft, Color = theme.colorTextTitle
}
}
, PanelProduct, "LABEL_TITLE");
container.Add(new CuiElement {
Name = "IMAGE_TITLE", Parent = PanelProduct, Components = {
new CuiImageComponent {
Color = theme.colorImgTitle, Png =GetImage($"{Name}_" +"7")
}
, new CuiRectTransformComponent {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "90.223 -40.197", OffsetMax = "107.083 -23.441"
}
}
}
);
if (_config.discountStores.DiscountPerm.Count != 0) {
container.Add(new CuiPanel {
CursorEnabled = false, Image = {
Color = "1 1 1 0"
}
, RectTransform = {
AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-113.69 -46.75", OffsetMax = "-61.91 -18.068"
}
}
, PanelProduct, "DISCOUNT_INFO");
container.Add(new CuiElement {
Name = "DISCOUNT_IMAGE", Parent = "DISCOUNT_INFO", Components = {
new CuiRawImageComponent {
Color = theme.colorImgDiscount, Png =GetImage($"{Name}_" +"5")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0.5", AnchorMax = "0 0.5", OffsetMin = "3 -7.5", OffsetMax = "18 10.5"
}
}
}
);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-1.576 -7.5", OffsetMax = "25.89 7.051"
}
, Text = {
Text = $"{discount}%", Font = "robotocondensed-bold.ttf", FontSize = 11, Align = TextAnchor.MiddleLeft, Color = theme.colorTextDiscount
}
}
, "DISCOUNT_INFO", "DISCOUNT");
}
CuiHelper.DestroyUi(player, PanelProduct);
CuiHelper.AddUi(player, container);
UIPRODUCT(player, themetype);
UICATEGORY(player, themetype);
UpdateBalance(player, themetype);
if (_config.interfaceSettings.UseChangeTheme) ThemeSwitch(player, themetype);
}
private void CONFIRMATIONSSALEUI(BasePlayer player, int itemId, int indexCategory, int amount, ThemeType themetype) {
Configuration.InterfaceSettings.ThemeCustomization theme = themetype == ThemeType.Dark ? _config.interfaceSettings.DarkTheme : _config.interfaceSettings.LightTheme;
Configuration.CategoryShop.Product product = GetCategories(player)[indexCategory].product.Find(x => x.ID == itemId);
int playerLim = GetLimit(player, product, false);
string limit = playerLim == -1 ? GetLang("XDSHOP_UI_PATTERN", player.UserIDString) : playerLim + "/" + product.GetLimitLotWipe(player, false);
bool isSale = product.PriceSales != 0 && product.Price == 0;
CuiElementContainer container = new CuiElementContainer {
new CuiElement {
Name = ConfirmationsPanelSelling, Parent = PanelProduct, Components = {
new CuiRawImageComponent {
Color = theme.colorMainBG, Png =GetImage($"{Name}_" +"13")
}
, new CuiRectTransformComponent {
AnchorMi
// ... [Code preview truncated due to length. Full source in attached file] ...