C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
/********************************************************
*
* Credits to Nogrod and Reneb for the original plugin.* TODO Fix a few commands here and there.*
*******************************************************/
namespace Oxide.Plugins {
[Info("GUI Shop", "Default", "1.5.7")]
[Description("GUI shop based on Economics, with NPC support")]
public class GUIShop : RustPlugin {
private const string ShopOverlayName = "ShopOverlay";
private const string ShopContentName = "ShopContent";
private const string ShopDescOverlay = "ShopDescOverlay";
public const string BlockAllow = "guishop.allow";
private readonly int[] steps = {
1, 10, 100, 1000
}
;
int playersMask;
//////////////////////////////////////////////////////////////////////////////////////
// References ////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
[PluginReference]
Plugin Economics, Kits, ImageCache;
private void OnServerInitialized() {
permission.RegisterPermission(BlockAllow, this);
displaynameToShortname.Clear();
foreach (var itemdef in ItemManager.itemList) {
var displayName = itemdef.displayName.english.ToLower();
if (!displaynameToShortname.ContainsKey(displayName)) displaynameToShortname.Add(displayName, itemdef.shortname);
if (string.IsNullOrEmpty(IconUrl)) continue;
ImageCache?.CallHook("Add", string.Format(IconUrl, itemdef.shortname));
}
var shopCategories = DefaultShopCategories();
CheckCfg("Shop - Shop Categories", ref shopCategories);
foreach (var shopCategory in shopCategories) {
var itemdata = shopCategory.Value as Dictionary<string, object>;
if (itemdata == null) continue;
try {
var data = new ItemData();
object obj;
if (itemdata.TryGetValue("item", out obj)) {
var itemname = ((string)obj).ToLower();
if (displaynameToShortname.ContainsKey(itemname)) itemname = displaynameToShortname[itemname];
var definition = ItemManager.FindItemDefinition(itemname);
if (definition == null) {
Puts("ShopCategory: {0} Unknown item: {1}", shopCategory.Key, itemname);
continue;
}
data.Shortname = definition.shortname;
}
if (itemdata.TryGetValue("cmd", out obj)) data.Cmd = ((List<object>)obj).ConvertAll(c => (string)c);
double value;
if (itemdata.TryGetValue("cooldown", out obj) && double.TryParse((string)obj, out value)) data.Cooldown = value;
if (itemdata.TryGetValue("buy", out obj) && double.TryParse((string)obj, out value)) data.Buy = value;
if (itemdata.TryGetValue("sell", out obj) && double.TryParse((string)obj, out value)) data.Sell = value;
if (itemdata.TryGetValue("fixed", out obj)) data.Fixed = Convert.ToBoolean(obj);
if (itemdata.TryGetValue("img", out obj)) data.Img = (string)obj;
ShopCategories[shopCategory.Key] = data;
}
catch (Exception e) {
Puts("Failed to load ShopCategory: {0} Error: {1}", shopCategory.Key, e.Message);
}
}
if (configChanged) SaveConfig();
foreach (var itemData in ShopCategories.Values) {
if (string.IsNullOrEmpty(itemData.Img)) continue;
ImageCache?.CallHook("Add", itemData.Img);
}
if (!Economics) PrintWarning("Economics plugin not found." + Name + " will not function!");
}
//////////////////////////////////////////////////////////////////////////////////////
// Configs Manager ///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
private void LoadDefaultConfig() {
}
private void CheckCfg<T>(string Key, ref T var) {
if (Config[Key] is T) var = (T)Config[Key];
else {
Config[Key] = var;
configChanged = true;
}
}
class ItemData {
public string Shortname {
get;
set;
}
public double Cooldown {
get;
set;
}
public double Buy {
get;
set;
}
= -1;
public double Sell {
get;
set;
}
= -1;
public bool Fixed {
get;
set;
}
public List<string> Cmd {
get;
set;
}
public string Img {
get;
set;
}
}
private Dictionary<string, ItemData> ShopCategories = new Dictionary<string, ItemData>();
private Dictionary<string, object> Shops = DefaultShops();
private bool Balance;
private string IconUrl = string.Empty;
string MessageShowNoEconomics = "Couldn't get informations out of Economics.Is it installed?";
string MessageBought = "You've successfully bought {0}x {1}";
string MessageSold = "You've successfully sold {0}x {1}";
string MessageErrorCooldown = "This item has a cooldown of {0} seconds.";
string MessageErrorCooldownAmount = "This item has a cooldown and amount is limited to 1.";
string MessageErrorInventoryFull = "Your inventory is full.";
string MessageErrorInventorySlots = "Your inventory needs {0} free slots.";
string MessageErrorNoShop = "This shop doesn't seem to exist.";
string MessageErrorNoActionShop = "You are not allowed to {0} in this shop";
string MessageErrorNoNPC = "The NPC owning this shop was not found around you";
string MessageErrorNoActionItem = "You are not allowed to {0} this item here";
string MessageErrorItemItem = "WARNING: The admin didn't set this item properly! (item)";
string MessageErrorItemNoValid = "WARNING: It seems like it's not a valid item";
string MessageErrorRedeemKit = "WARNING: There was an error while giving you this kit";
string MessageErrorBuyCmd = "Can't buy multiple";
string MessageErrorBuyPrice = "WARNING: No buy price was given by the admin, you can't buy this item";
string MessageErrorSellPrice = "WARNING: No sell price was given by the admin, you can't sell this item";
string MessageErrorNotEnoughMoney = "You need {0} coins to buy {1} of {2}";
string MessageErrorNotEnoughSell = "You don't have enough of this item.";
string MessageErrorNotNothing = "You cannot buy nothing of this item.";
string MessageErrorItemNoExist = "WARNING: The item you are trying to buy doesn't seem to exist";
string MessageErrorNPCRange = "You may not use the chat shop.You might need to find the NPC Shops.";
string MessageErrorBuildingBlocked = "You cannot shop while in building blocked area.";
private void Init() {
CheckCfg("Shop - Shop Icon Url", ref IconUrl);
CheckCfg("Shop - Shop List", ref Shops);
CheckCfg("Shop - Balance", ref Balance);
CheckCfg("Message - Error - No Econonomics", ref MessageShowNoEconomics);
CheckCfg("Message - Bought", ref MessageBought);
CheckCfg("Message - Sold", ref MessageSold);
CheckCfg("Message - Error - Cooldown", ref MessageErrorCooldown);
CheckCfg("Message - Error - Cooldown Amount", ref MessageErrorCooldownAmount);
CheckCfg("Message - Error - Invetory Full", ref MessageErrorInventoryFull);
CheckCfg("Message - Error - Invetory Slots", ref MessageErrorInventorySlots);
CheckCfg("Message - Error - No Shop", ref MessageErrorNoShop);
CheckCfg("Message - Error - No Action In Shop", ref MessageErrorNoActionShop);
CheckCfg("Message - Error - No NPC", ref MessageErrorNoNPC);
CheckCfg("Message - Error - No Action Item", ref MessageErrorNoActionItem);
CheckCfg("Message - Error - Item Not Set Properly", ref MessageErrorItemItem);
CheckCfg("Message - Error - Item Not Valid", ref MessageErrorItemNoValid);
CheckCfg("Message - Error - Redeem Kit", ref MessageErrorRedeemKit);
CheckCfg("Message - Error - Command Multiple", ref MessageErrorBuyCmd);
CheckCfg("Message - Error - No Buy Price", ref MessageErrorBuyPrice);
CheckCfg("Message - Error - No Sell Price", ref MessageErrorSellPrice);
CheckCfg("Message - Error - Not Enough Money", ref MessageErrorNotEnoughMoney);
CheckCfg("Message - Error - Not Enough Items", ref MessageErrorNotEnoughSell);
CheckCfg("Message - Error - Not Nothing", ref MessageErrorNotNothing);
CheckCfg("Message - Error - Item Doesnt Exist", ref MessageErrorItemNoExist);
CheckCfg("Message - Error - No Chat Shop", ref MessageErrorNPCRange);
CheckCfg("Message - Error - Building Blocked", ref MessageErrorBuildingBlocked);
if (configChanged) SaveConfig();
LoadData();
}
private void LoadData() {
cooldowns = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, Dictionary<string, double>>>(nameof(GUIShop) + "Cooldowns");
buyed = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, ulong>>(nameof(GUIShop) + "Buyed");
selled = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, ulong>>(nameof(GUIShop) + "Selled");
}
private void SaveData() {
if (cooldowns != null) Interface.Oxide.DataFileSystem.WriteObject(nameof(GUIShop) + "Cooldowns", cooldowns);
if (buyed != null) Interface.Oxide.DataFileSystem.WriteObject(nameof(GUIShop) + "Buyed", buyed);
if (selled != null) Interface.Oxide.DataFileSystem.WriteObject(nameof(GUIShop) + "Selled", selled);
}
private void Unload() {
SaveData();
}
private void OnServerSave() {
SaveData();
}
private void OnServerShutdown() {
SaveData();
}
private static int CurrentTime() {
return Facepunch.Math.Epoch.Current;
}
//////////////////////////////////////////////////////////////////////////////////////
// Default Shops for Tutorial purpoise ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
private static Dictionary<string, object> DefaultShops() {
var shops = new Dictionary<string, object> {
{
"commands", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this commands shop"
}
, {
"name", "Commands"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"weapons", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this weapons shop"
}
, {
"name", "Weapons"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"construction", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this construction shop"
}
, {
"name", "Construction"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"resources", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this resources shop"
}
, {
"name", "Resource"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"attire", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this attire shop"
}
, {
"name", "Clothing"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"tools", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this tools shop"
}
, {
"name", "Tools"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"medical", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this medical shop"
}
, {
"name", "Meds"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"food", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this food shop"
}
, {
"name", "Food"
}
, {
"buy", new List<object> {
"BlueBerries"
}
}
, {
"sell", new List<object> {
"Apple"
}
}
}
}
, {
"ammunition", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this ammunition shop"
}
, {
"name", "Ammunition"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"traps", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this traps shop"
}
, {
"name", "Trap"
}
, {
"buy", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"items", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this items market"
}
, {
"name", "Item"
}
, {
"buy", new List<object> {
"Apple", "BlueBerries", "Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Apple", "BlueBerries", "Assault Rifle", "Bolt Action Rifle"
}
}
}
}
, {
"components", new Dictionary<string, object> {
{
"description", "You currently have {0} coins to spend in this components shop"
}
, {
"name", "Item"
}
, {
"buy", new List<object> {
"Apple", "BlueBerries", "Assault Rifle", "Bolt Action Rifle"
}
}
, {
"sell", new List<object> {
"Apple", "BlueBerries", "Assault Rifle", "Bolt Action Rifle"
}
}
}
}
}
;
return shops;
}
private static Dictionary<string, object> DefaultShopCategories() {
var dsc = new Dictionary<string, object> {
{
"Assault Rifle", new Dictionary<string, object> {
{
"item", "assault rifle"
}
, {
"buy", "10"
}
, {
"sell", "8"
}
}
}
, {
"Bolt Action Rifle", new Dictionary<string, object> {
{
"item", "bolt action rifle"
}
, {
"buy", "10"
}
, {
"sell", "8"
}
}
}
, {
"Apple", new Dictionary<string, object> {
{
"item", "apple"
}
, {
"buy", "1"
}
, {
"sell", "1"
}
}
}
, {
"BlueBerries", new Dictionary<string, object> {
{
"item", "blueberries"
}
, {
"buy", "1"
}
, {
"sell", "1"
}
}
}
}
;
return dsc;
}
//////////////////////////////////////////////////////////////////////////////////////
// Item Management ///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
readonly Dictionary<string, string> displaynameToShortname = new Dictionary<string, string>();
//////////////////////////////////////////////////////////////////////////////////////
// Oxide Hooks ///////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
private void Loaded() {
playersMask = LayerMask.GetMask("Player (Server)");
}
private void OnUseNPC(BasePlayer npc, BasePlayer player) {
if (!Shops.ContainsKey(npc.UserIDString)) return;
ShowShop(player, npc.UserIDString, 0);
}
//////////////////////////////////////////////////////////////////////////////////////
// GUI ///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
private static CuiElementContainer CreateShopOverlay(string shopname) {
return new CuiElementContainer {
{
new CuiPanel {
Image = {
Color = "0.1 0.1 0.1 0.8"
}
, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, CursorEnabled = true
}
, new CuiElement().Parent, ShopOverlayName
}
, {
new CuiLabel {
Text = {
Text = shopname, FontSize = 30, Align = TextAnchor.MiddleCenter
}
, RectTransform = {
AnchorMin = "0.3 0.8", AnchorMax = "0.7 0.9"
}
}
, ShopOverlayName
}
, {
new CuiLabel {
Text = {
Text = "Item", FontSize = 20, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = "0.2 0.6", AnchorMax = "0.4 0.65"
}
}
, ShopOverlayName
}
, {
new CuiLabel {
Text = {
Text = "Buy", FontSize = 20, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = "0.55 0.6", AnchorMax = "0.7 0.65"
}
}
, ShopOverlayName
}
, {
new CuiLabel {
Text = {
Text = "Sell", FontSize = 20, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = "0.75 0.6", AnchorMax = "0.9 0.65"
}
}
, ShopOverlayName
}
, {
new CuiButton {
Button = {
Close = ShopOverlayName, Color = "0.5 0.5 0.5 0.2"
}
, RectTransform = {
AnchorMin = "0.5 0.15", AnchorMax = "0.7 0.2"
}
, Text = {
Text = "Close", FontSize = 20, Align = TextAnchor.MiddleCenter
}
}
, ShopOverlayName
}
}
;
}
private readonly CuiLabel shopDescription = new CuiLabel {
Text = {
Text = "{shopdescription}", FontSize = 15, Align = TextAnchor.MiddleCenter
}
, RectTransform = {
AnchorMin = "0.2 0.7", AnchorMax = "0.8 0.79"
}
}
;
private CuiElementContainer CreateShopItemEntry(string price, float ymax, float ymin, string shop, string item, string color, bool sell, bool cooldown) {
var container = new CuiElementContainer {
{
new CuiLabel {
Text = {
Text = price, FontSize = 15, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = $"{(sell ? 0.725 : 0.45)} {ymin}", AnchorMax = $"{(sell ? 0.755 : 0.5)} {ymax}"
}
}
, ShopContentName
}
}
;
for (var i = 0; i < steps.Length; i++) {
container.Add(new CuiButton {
Button = {
Command = $"shop.{(sell ? "sell" : "buy")} {shop} {item} {steps[i]}", Color = color
}
, RectTransform = {
AnchorMin = $"{(sell ? 0.775 : 0.5) + i * 0.03 + 0.001} {ymin}", AnchorMax = $"{(sell ? 0.805 : 0.53) + i * 0.03 - 0.001} {ymax}"
}
, Text = {
Text = steps[i].ToString(), FontSize = 15, Align = TextAnchor.MiddleCenter
}
}
, ShopContentName);
//if (cooldown) break;
}
if (!cooldown) {
container.Add(new CuiButton {
Button = {
Command = $"shop.{(sell ? "sell" : "buy")} {shop} {item} all", Color = color
}
, RectTransform = {
AnchorMin = $"{(sell ? 0.775 : 0.5) + steps.Length * 0.03 + 0.001} {ymin}", AnchorMax = $"{(sell ? 0.805 : 0.53) + steps.Length * 0.03 - 0.001} {ymax}"
}
, Text = {
Text = "All", FontSize = 15, Align = TextAnchor.MiddleCenter
}
}
, ShopContentName);
}
return container;
}
private CuiElementContainer CreateShopItemIcon(string name, float ymax, float ymin, ItemData data) {
string url = null;
if (!string.IsNullOrEmpty(data.Img)) url = data.Img;
else if (!string.IsNullOrEmpty(data.Shortname)) url = string.Format(IconUrl, data.Shortname);
var label = new CuiLabel {
Text = {
Text = name, FontSize = 15, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = $"0.1 {ymin}", AnchorMax = $"0.3 {ymax}"
}
}
;
if (string.IsNullOrEmpty(url)) return new CuiElementContainer {
{
label, ShopContentName
}
}
;
var rawImage = new CuiRawImageComponent();
if (url.StartsWith("http") || url.StartsWith("file")) {
var id = (string)ImageCache?.CallHook("Get", url);
if (!string.IsNullOrEmpty(id)) rawImage.Png = id;
else rawImage.Url = url;
rawImage.Sprite = "assets/content/textures/generic/fulltransparent.tga";
}
else rawImage.Sprite = url;
var container = new CuiElementContainer {
{
label, ShopContentName
}
, new CuiElement {
Parent = ShopContentName, Components = {
rawImage, new CuiRectTransformComponent {
AnchorMin = $"0.05 {ymin}", AnchorMax = $"0.08 {ymax}"
}
}
}
}
;
return container;
}
/* private static CuiElementContainer CreateShopChangePage(string currentshop, int shoppageminus, int shoppageplus)
{
return new CuiElementContainer
{
{
new CuiButton
{
Button = {Command = $"shop.show {currentshop} {shoppageminus}", Color = "0.5 0.5 0.5 0.2"},
RectTransform = {AnchorMin = "0.2 0.15", AnchorMax = "0.3 0.2"},
Text = {Text = "<<", FontSize = 20, Align = TextAnchor.MiddleCenter}
},
ShopOverlayName,
"ButtonBack"
},
{
new CuiButton
{
Button = {Command = $"shop.show {currentshop} {shoppageplus}", Color = "0.5 0.5 0.5 0.2"},
RectTransform = {AnchorMin = "0.35 0.15", AnchorMax = "0.45 0.2"},
Text = {Text = ">>", FontSize = 20, Align = TextAnchor.MiddleCenter}
},
ShopOverlayName,
"ButtonForward"
}
};
} */
//TODO MMMEEERRGGGGEEEE
private static CuiElementContainer CreateShopChangePage(string currentshop, int shoppageminus, int shoppageplus) {
return new CuiElementContainer {
{
new CuiButton {
Button = {
Command = $"shop.show {currentshop} {shoppageminus}", Color = "0.5 0.5 0.5 0.2"
}
, RectTransform = {
AnchorMin = "0.2 0.12", AnchorMax = "0.3 0.17"
}
, Text = {
Text = "<<", FontSize = 20, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf"
}
}
, ShopOverlayName, "ButtonBack"
}
, {
new CuiButton {
Button = {
Command = $"shop.show {currentshop} {shoppageplus}", Color = "0.5 0.5 0.5 0.2"
}
, RectTransform = {
AnchorMin = "0.35 0.12", AnchorMax = "0.45 0.17"
}
, Text = {
Text = ">>", FontSize = 20, Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf"
}
}
, ShopOverlayName, "ButtonForward"
}
, {
new CuiButton {
Button = {
Command = $"shop.show components {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.90 0.78", AnchorMax = "0.97 0.83"
}
, Text = {
Text = $"Components", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Components"
}
, {
new CuiButton {
Button = {
Command = $"shop.show traps {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.82 0.78", AnchorMax = "0.89 0.83"
}
, Text = {
Text = $"Traps", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Traps"
}
, {
new CuiButton {
Button = {
Command = $"shop.show ammunition {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.74 0.78", AnchorMax = "0.81 0.83"
}
, Text = {
Text = $"Ammunition", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Ammunition"
}
, {
new CuiButton {
Button = {
Command = $"shop.show food {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.66 0.78", AnchorMax = "0.73 0.83"
}
, Text = {
Text = $"Food", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Food"
}
, {
new CuiButton {
Button = {
Command = $"shop.show medical {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.58 0.78", AnchorMax = "0.65 0.83"
}
, Text = {
Text = $"Medical", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Medical"
}
, {
new CuiButton {
Button = {
Command = $"shop.show tools {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.50 0.78", AnchorMax = "0.57 0.83"
}
, Text = {
Text = $"Tools", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Tools"
}
, {
new CuiButton {
Button = {
Command = $"shop.show attire {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.42 0.78", AnchorMax = "0.49 0.83"
}
, Text = {
Text = $"Attire", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Attire"
}
, {
new CuiButton {
Button = {
Command = $"shop.show resources {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.34 0.78", AnchorMax = "0.41 0.83"
}
, Text = {
Text = $"Resources", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Resources"
}
, {
new CuiButton {
Button = {
Command = $"shop.show items {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.26 0.78", AnchorMax = "0.33 0.83"
}
, Text = {
Text = $"Items", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Items"
}
, {
new CuiButton {
Button = {
Command = $"shop.show construction {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.18 0.78", AnchorMax = "0.25 0.83"
}
, Text = {
Text = $"Construction", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Construction"
}
, {
new CuiButton {
Button = {
Command = $"shop.show weapons {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.10 0.78", AnchorMax = "0.17 0.83"
}
, Text = {
Text = $"Weapons", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Weapons"
}
, {
new CuiButton {
Button = {
Command = $"shop.show commands {shoppageminus}", Color = "0.5 0.5 0.5 0.5"
}
, RectTransform = {
AnchorMin = "0.02 0.78", AnchorMax = "0.09 0.83"
}
, Text = {
Text = $"Commands", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 14
}
}
, ShopOverlayName, "Commands"
}
}
;
}
readonly Hash<ulong, int> shopPage = new Hash<ulong, int>();
private Dictionary<ulong, Dictionary<string, double>> cooldowns;
private Dictionary<string, ulong> buyed;
private Dictionary<string, ulong> selled;
private bool configChanged;
private void ShowShop(BasePlayer player, string shopid, int from = 0, bool fullPaint = true, bool refreshMoney = false) {
shopPage[player.userID] = from;
object shopObj;
if (!Shops.TryGetValue(shopid, out shopObj)) {
SendReply(player, MessageErrorNoShop);
return;
}
if (Economics == null) {
SendReply(player, MessageShowNoEconomics);
return;
}
var playerCoins = (double)Economics.CallHook("Balance", player.UserIDString);
var shop = (Dictionary<string, object>)shopObj;
shopDescription.Text.Text = string.Format((string)shop["description"], playerCoins);
if (refreshMoney) {
CuiHelper.DestroyUi(player, ShopDescOverlay);
CuiHelper.AddUi(player, new CuiElementContainer {
{
shopDescription, ShopOverlayName, ShopDescOverlay
}
}
);
return;
}
DestroyUi(player, fullPaint);
CuiElementContainer container;
if (fullPaint) {
container = CreateShopOverlay((string)shop["name"]);
container.Add(shopDescription, ShopOverlayName, ShopDescOverlay);
}
else container = new CuiElementContainer();
container.Add(new CuiPanel {
Image = {
Color = "0 0 0 0"
}
, RectTransform = {
AnchorMin = "0 0.2", AnchorMax = "1 0.6"
}
}
, ShopOverlayName, ShopContentName);
if (from < 0) {
CuiHelper.AddUi(player, container);
return;
}
var itemslist = new Dictionary<string, Dictionary<string, bool>>();
object type;
if (shop.TryGetValue("sell", out type)) {
foreach (string itemname in (List<object>)type) {
Dictionary<string, bool> itemEntry;
if (!itemslist.TryGetValue(itemname, out itemEntry)) itemslist[itemname] = itemEntry = new Dictionary<string, bool>();
itemEntry["sell"] = true;
}
}
if (shop.TryGetValue("buy", out type)) {
foreach (string itemname in (List<object>)type) {
Dictionary<string, bool> itemEntry;
if (!itemslist.TryGetValue(itemname, out itemEntry)) itemslist[itemname] = itemEntry = new Dictionary<string, bool>();
itemEntry["buy"] = true;
}
}
var current = 0;
foreach (var pair in itemslist) {
ItemData data;
if (!ShopCategories.TryGetValue(pair.Key, out data)) continue;
if (current >= from && current < from + 7) {
var pos = 0.85f - 0.125f * (current - from);
var cooldown = data.Cooldown > 0;
var name = pair.Key;
if (cooldown) name += $" ({FormatTime((long)data.Cooldown)})";
container.AddRange(CreateShopItemIcon(name, pos + 0.125f, pos, data));
var buyed = false;
if (cooldown) {
Dictionary<string, double> itemCooldowns;
double itemCooldown;
if (cooldowns.TryGetValue(player.userID, out itemCooldowns) && itemCooldowns.TryGetValue(pair.Key, out itemCooldown) && itemCooldown > CurrentTime()) {
buyed = true;
container.Add(new CuiLabel {
Text = {
Text = GetBuyPrice(data).ToString(), FontSize = 15, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = $"0.45 {pos}", AnchorMax = $"0.5 {pos + 0.125f}"
}
}
, ShopContentName);
container.Add(new CuiLabel {
Text = {
Text = FormatTime((long)(itemCooldown - CurrentTime())), FontSize = 15, Align = TextAnchor.MiddleLeft
}
, RectTransform = {
AnchorMin = $"0.5 {pos}", AnchorMax = $"0.6 {pos + 0.125f}"
}
}
// ... [Code preview truncated due to length. Full source in attached file] ...