C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Libraries;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using WebSocketSharp;
namespace Oxide.Plugins {
[Info("GameStoresRUST", "HOUGAN # GAMESTORES", "0.2.8")]
public class GameStoresRUST : RustPlugin {
#region References
[PluginReference]
private Plugin ImageLibrary;
#endregion
#region Classes
private static class Delays {
[JsonProperty("Игроки с активными запросами к АПИ")]
public static List<ulong> ItemList = new List<ulong>();
[JsonProperty("Количество запросов за последнюю секунду")]
public static int RequestPerSecond = 0;
[JsonProperty("Ограничение запросов в секунду")]
public static int RequestPerSecondLimit = 20;
public static bool CanRequest(BasePlayer player) {
if (RequestPerSecond > RequestPerSecondLimit) {
return false;
}
if (ItemList.Contains(player.userID)) {
player.ChatMessage($"Пожалуйста, дождитесь <<окончания>> предыдущего действия!");
return false;
}
return true;
}
public static void FinishRequest(BasePlayer player) {
if (ItemList.Contains(player.userID)) ItemList.Remove(player.userID);
}
public static IEnumerator MakeRequest(BasePlayer player) {
RequestPerSecond++;
if (ItemList.Contains(player.userID)) yield return null;
ItemList.Add(player.userID);
yield return new WaitForSeconds(3f);
if (ItemList.Contains(player.userID)) ItemList.Remove(player.userID);
}
}
private class Stats {
}
private class Configuration {
public class API {
[JsonProperty("ИД магазина в сервисе")]
public string ShopID = "UNDEFINED";
[JsonProperty("ИД сервера в сервисе")]
public string ServerID = "UNDEFINED";
[JsonProperty("Секретный ключ (не распространяйте его)")]
public string SecretKey = "UNDEFINED";
}
public class Interface {
[JsonProperty("Включить изображение корзины")]
public bool BucketEnable = true;
[JsonProperty("Ссылка на изображение корзины (BUCKET - стандартное изображение)")]
public string BucketURL = "BUCKET";
[JsonProperty("Количество предметов на строке")]
public int ItemOnString = 7;
[JsonProperty("Количество строк в интерфейсе")]
public int StringAmount = 3;
[JsonProperty("Сторона одного предмета")]
public int ItemSide = 150;
[JsonProperty("Отступ между предметами")]
public int ItemMargin = 5;
}
public class TOP {
[JsonProperty("Отправлять данные топа игроков")]
public bool UseTop = true;
}
[JsonProperty("Настройки API плагина")]
public API APISettings = new API();
[JsonProperty("Настройки интерфейса плагина")]
public Interface InterfaceSettings = new Interface();
[JsonProperty("Настройки статистики сервера")]
public TOP TOPSettings = new TOP();
}
private class WItem {
public string ID;
public string Name;
public int ItemID;
public int Amount;
public string ShortName;
public string Command;
public string ImageUrl;
public bool Blocked;
public double Block_Date = 0;
public bool IsBlueprint;
public bool IsCommand;
public bool IsItem;
public WItem(Dictionary<string, object> data, bool show = true) {
try {
if (data.ContainsKey("id")) ID = data["id"].ToString();
if (data.ContainsKey("name")) Name = data["name"].ToString();
if (data.ContainsKey("item_id")) ItemID = System.Convert.ToInt32(data["item_id"]);
if (data.ContainsKey("amount")) Amount = System.Convert.ToInt32(data["amount"]);
if (data.ContainsKey("command")) Command = data["command"].ToString();
if (data.ContainsKey("img")) ImageUrl = data["img"].ToString();
if (data.ContainsKey("blocked")) Blocked = bool.Parse(data["blocked"].ToString());
if (data.ContainsKey("block_date") && data["block_date"] is int) {
double.TryParse(data["block_date"].ToString(), out Block_Date);
}
if (data.ContainsKey("type")) {
IsBlueprint = data["type"].ToString() == "bp";
IsCommand = data["type"].ToString() == "command";
IsItem = data["type"].ToString() == "item";
}
if (ItemID != 0) {
var itemInfo = ItemManager.FindItemDefinition(ItemID);
if (itemInfo != null) ShortName = itemInfo.shortname;
else if (IDToShortName.ContainsKey(ItemID)) {
itemInfo = ItemManager.FindItemDefinition(IDToShortName[ItemID]);
if (itemInfo == null) return;
ShortName = itemInfo.shortname;
}
}
var imageLibrary = instance.plugins.Find("ImageLibrary");
if (imageLibrary != null) {
if (ItemID == 0) {
if ((bool) imageLibrary.Call("HasImage", $"IconGS.{ID}")) {
string probablyId = (string) imageLibrary.Call("GetImage", $"IconGS.{ID}");
if (!probablyId.IsNullOrEmpty() && probablyId != instance.NoImageID && probablyId != instance.LoadingImageID) ImageUrl = probablyId;
return;
}
if (!ImageUrl.IsNullOrEmpty()) {
imageLibrary.Call("AddImage", ImageUrl.Replace("https", "http"), $"IconGS.{ID}");
}
}
else {
string probablyId = (string) imageLibrary.Call("GetImage", ShortName);
if (!probablyId.IsNullOrEmpty() && probablyId != instance.NoImageID && probablyId != instance.LoadingImageID) ImageUrl = probablyId;
}
}
}
catch (NullReferenceException e) {
Interface.Oxide.LogError(JsonConvert.SerializeObject(data));
}
}
}
#endregion
#region Variables
private static bool Initialized = false;
private static GameStoresRUST instance;
private static Configuration Settings = new Configuration();
private string ShopURL = "UNDEFINED";
private int StartBalance = 0;
public string NoImageID = "";
public string LoadingImageID = "";
private Coroutine LoadingCoroutine;
private string BaseRequest => $"https://gamestores.ru/api/?shop_id={Settings.APISettings.ShopID}&secret={Settings.APISettings.SecretKey}{(!Settings.APISettings.ServerID.IsNullOrEmpty() && Settings.APISettings.ServerID != "0" && Settings.APISettings.ServerID != "1" && Settings.APISettings.ServerID != "UNDEFINED" ? $"&server= {
Settings.APISettings.ServerID
}
" : "")}";
#endregion
#region Interface
private void OnServerInitialized() {
if (ImageLibrary) {
NoImageID = (string) ImageLibrary.Call("GetImage", "NONE");
LoadingImageID = (string) ImageLibrary.Call("GetImage", "LOADING");
}
if (Settings.InterfaceSettings.BucketURL.Contains("http") && plugins.Find("ImageLibrary") != null) {
ImageLibrary.Call("AddImage", Settings.InterfaceSettings.BucketURL, "GameStoresRUSTBucket");
LoadingCoroutine = ServerMgr.Instance.StartCoroutine(WaitForLoad());
}
else {
BasePlayer.activePlayerList.ForEach(OnPlayerInit);
}
instance = this;
if (!Settings.TOPSettings.UseTop) Unsubscribe(nameof(OnEntityDeath));
if (!Settings.TOPSettings.UseTop) Unsubscribe(nameof(OnPlayerDisconnected));
if (Settings.APISettings.ShopID == "UNDEFINED" || Settings.APISettings.SecretKey == "UNDEFINED") {
PrintError($"Verify that plugin is installed correct! Some of API settings are 'UNDEFINED'");
return;
}
FetchShopUrl();
timer.Every(1, () => Delays.RequestPerSecond = 0);
}
private IEnumerator WaitForLoad() {
while (!(bool) ImageLibrary.Call("HasImage", "GameStoresRUSTBucket")) {
PrintError($"Image of bucket is loading!");
yield return new WaitForSeconds(1);
}
PrintWarning("Image of bucket loaded correct!");
BasePlayer.activePlayerList.ForEach(OnPlayerInit);
yield return 0;
}
protected override void LoadConfig() {
base.LoadConfig();
try {
Settings = Config.ReadObject<Configuration>();
if (Settings?.APISettings == null) LoadDefaultConfig();
}
catch {
PrintWarning($"Error reading config, creating one new config!");
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
protected override void LoadDefaultConfig() {
Settings = new Configuration();
}
protected override void SaveConfig() => Config.WriteObject(Settings);
private void Unload() {
if (Initialized) StatHandler.SendStats();
if (LoadingCoroutine != null) ServerMgr.Instance.StopCoroutine(LoadingCoroutine);
BasePlayer.activePlayerList.ForEach(p => CuiHelper.DestroyUi(p, IconLayer));
BasePlayer.activePlayerList.ForEach(p => CuiHelper.DestroyUi(p, StoreLayer));
}
#endregion
#region Hooks
private void OnPlayerDisconnected(BasePlayer player, string reason) {
StatHandler.AddStat(new StatHandler.TimeStat(player));
}
private void OnPlayerInit(BasePlayer player) {
if (player.IsReceivingSnapshot) {
NextTick(() => OnPlayerInit(player));
return;
}
if (Settings.InterfaceSettings.BucketEnable) InitializeIcon(player);
}
#endregion
#region Stats
private static class StatHandler {
internal class Stat {
[JsonProperty("dataType")]
public string DataType;
}
internal class KillStat : Stat {
[JsonProperty("player_id")]
public string PlayerUserId;
[JsonProperty("victim_id")]
public string VictimUserID;
[JsonProperty("type")]
public string Type;
[JsonProperty("time")]
public string Time;
}
internal class TimeStat : Stat {
[JsonProperty("player_id")]
public string PlayerID;
[JsonProperty("username")]
public string PlayerName;
[JsonProperty("played")]
public string Played;
[JsonProperty("time")]
public string Time;
public TimeStat(BasePlayer player) {
PlayerID = player.UserIDString;
PlayerName = player.displayName;
DataType = "leave";
Played = player.secondsConnected.ToString();
Time = CurrentTime().ToString();
}
}
private static List<Stat> Stats = new List<Stat>();
public static void AddStat(Stat stat) {
Stats.Add(stat);
if (Stats.Count > 10) {
SendStats();
Stats.Clear();
}
}
public static void SendStats() {
if (Stats.Count == 0) return;
var obj = JsonConvert.SerializeObject(Stats);
Request($"&method=topData&data={obj}", (i, s) => {
}
);
Interface.Oxide.LogInfo($"GameStores sent stats successful!");
}
}
[ConsoleCommand("sendtop")]
private void CmdSendTop(ConsoleSystem.Arg args) {
if (args.Player() != null && !args.Player().IsAdmin) return;
StatHandler.SendStats();
}
private void OnEntityDeath(BaseCombatEntity entity, HitInfo info) {
if (entity == null || info == null || info.Initiator == null) return;
if (Settings.TOPSettings.UseTop) {
BaseEntity initiator = info.Initiator;
if (entity as BasePlayer == null && initiator as BasePlayer == null) return;
StatHandler.KillStat stat = new StatHandler.KillStat();
if (initiator as BasePlayer != null) stat.PlayerUserId = initiator.ToPlayer().UserIDString;
else if (initiator.PrefabName.Contains("agents")) stat.PlayerUserId = "1";
if (entity as BasePlayer != null) {
stat.VictimUserID = entity.ToPlayer().UserIDString;
stat.Type = entity.ToPlayer().IsSleeping() ? "sleeper" : "kill";
}
else if (entity.PrefabName.Contains("agents")) {
stat.VictimUserID = "1";
stat.Type = "kill";
}
stat.DataType = "death";
stat.Time = CurrentTime().ToString();
StatHandler.AddStat(stat);
}
}
#endregion
#region Commands
[ChatCommand("store")]
private void CmdChatStore(BasePlayer player, string command, string[] args) {
if (!Initialized) {
player.ChatMessage($"Подождите, магазин загружается....");
return;
}
if (args.Length == 1 && args[0].ToLower() == "hide") {
CuiHelper.DestroyUi(player, IconLayer);
}
else {
if (!Delays.CanRequest(player)) return;
InitializeStore(player, 0, true);
}
}
[ConsoleCommand("UI_GameStoresRUST")]
private void CmdConsoleCommand(ConsoleSystem.Arg args) {
BasePlayer player = args.Player();
if (player == null) return;
if (!args.HasArgs(1)) {
player.SendConsoleCommand("chat.say /store");
return;
}
switch (args.Args[0].ToLower()) {
case "page" : {
int page = 0;
if (!args.HasArgs(2) || !int.TryParse(args.Args[1], out page)) return;
InitializeStore(player, page, false);
break;
}
case "help" : {
string helpLayer = StoreLayer + ".Help";
CuiHelper.DestroyUi(player, helpLayer);
CuiElementContainer container = new CuiElementContainer();
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
FadeIn = 1f, Color = "0 0 0 0.9", Material = "assets/content/ui/uibackgroundblur.mat", Close = helpLayer, Command = "closemenu"
}
, Text = {
Text = ""
}
}
, StoreLayer, helpLayer);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0.6", AnchorMax = "1 0.78", OffsetMax = "0 0"
}
, Text = {
FadeIn = 1f, Text = "ИНСТРУКЦИЯ ПОЛЬЗОВАТЕЛЯ", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 34
}
}
, helpLayer);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0.3", AnchorMax = "1 0.72", OffsetMax = "0 0"
}
, Text = {
FadeIn = 1f, Text = $"Здесь вы можете забрать товары приобретенные у нас в магазине!\n" + $"Пополнить счёт можно различными способами: электронные кошельки, карты и т.д.\n" + $"Авторизация в магазине происходит при помощи вашего аккаунта STEAM", Font = "robotocondensed-regular.ttf", FontSize = 22, Align = TextAnchor.MiddleCenter
}
}
, helpLayer);
string addText = StartBalance > 0 ? $"<size=18>При первой авторизации вы получите в подарок <b>{StartBalance} рублей</b>!</size>" : "";
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0.1", AnchorMax = "1 0.48", OffsetMax = "0 0"
}
, Text = {
FadeIn = 1f, Text = $"{ShopURL.ToUpper()}\n" + $"{addText}", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 32
}
}
, helpLayer);
CuiHelper.AddUi(player, container);
break;
}
case "take" : {
if (!args.HasArgs(3)) return;
int index = 0, id = 0;
if (!int.TryParse(args.Args[1], out index) || !int.TryParse(args.Args[2], out id)) return;
if (args.HasArgs(5) && args.Args[3].ToLower() == "blocked") {
double left = 0;
if (!double.TryParse(args.Args[4], out left)) return;
TimeSpan span = TimeSpan.FromSeconds(left);
string text = "";
if (span.Days >= 1) text += $"{span.Days} дн.";
if (span.Hours >= 1) text += $"{span.Hours} ч.";
if (span.Minutes >= 1) text += $"{span.Minutes} мин.";
if (span.Seconds >= 1) text += $"{span.Seconds} сек.";
ShowNotify(player, "Вы не можете забрать этот предмет из корзины!\n" + $"До его разблокировки осталось: {text}");
return;
}
ShowNotify(player, "Подождите, ваш запрос обрабатывается!");
CuiElementContainer container = new CuiElementContainer();
if (!Delays.CanRequest(player)) {
ShowNotify(player, "Подождите, ваш предыдущий запрос ещё обрабатывается!");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "1 1 1 0.2", Close = StoreLayer + ".BlockPanel." + index + ".Open", Command = $"UI_GameStoresRUST take {index} {id}"
}
, Text = {
Text = ""
}
}
, StoreLayer + ".BlockPanel." + index , StoreLayer + ".BlockPanel." + index + ".Open");
CuiHelper.AddUi(player, container);
return;
}
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
FadeIn = 1f, Color = "1 1 1 0.2", Close = StoreLayer + ".BlockPanel." + index + ".Open", Command = $"UI_GameStoresRUST take {index} {id}", Material = ""
}
, Text = {
Text = ""
}
}
, StoreLayer + ".BlockPanel." + index , StoreLayer + ".BlockPanel." + index + ".Open");
CuiHelper.AddUi(player, container);
LogPlayerAction(player, $"---------------------------------");
LogPlayerAction(player, $"Запрос на получение предмета: {id}");
Request($"&item=true&steam_id={player.UserIDString}&id={id}", (i, s) => {
switch (i) {
case 0 : LogPlayerAction(player, $"API не ответило на запрос: {id}");
PrintError("Api does not responded to a request");
if (player != null) {
player.ChatMessage($"Непредвиденная ошибка со стороны сервера, просим прощения!");
CuiHelper.DestroyUi(player, StoreLayer);
}
break;
case 200 : Dictionary<string, object> response = JsonConvert.DeserializeObject<Dictionary<string, object>>(s, new KeyValuesConverter());
if (!response.ContainsKey("data")) {
LogPlayerAction(player, $"Ошибка получения товара, отсутствует Data [{id}]");
container.Clear();
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel." + index + ".Open");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
FadeIn = 1f, Color = "1 0.5 0.5 0.2", Close = StoreLayer + ".BlockPanel." + index + ".Open", Command = $"UI_GameStoresRUST take {index} {id}", Material = ""
}
, Text = {
Text = ""
}
}
, StoreLayer + ".BlockPanel." + index , StoreLayer + ".BlockPanel." + index + ".Open");
ShowNotify(player, "Произошла непредвиденная ошибка, попробуйте позже!\n" + "Ваш предмет в безопасности, не переживайте!");
CuiHelper.AddUi(player, container);
return;
}
LogPlayerAction(player, $"Товар отмечен полученным [{id}]");
Request($"&gived=true&id={id}", (code, newResponse) => {
if (code != 200 || JsonConvert.DeserializeObject<JObject>(newResponse)["result"].ToString() != "success") {
container.Clear();
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel." + index + ".Open");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
FadeIn = 1f, Color = "1 0.5 0.5 0.2", Close = StoreLayer + ".BlockPanel." + index + ".Open", Command = $"UI_GameStoresRUST take {index} {id}", Material = ""
}
, Text = {
Text = ""
}
}
, StoreLayer + ".BlockPanel." + index , StoreLayer + ".BlockPanel." + index + ".Open");
ShowNotify(player, "Произошла непредвиденная ошибка, попробуйте позже!\n" + "Ваш предмет в безопасности, не переживайте!");
CuiHelper.AddUi(player, container);
return;
}
ProcessTake(player, response["data"] as Dictionary<string, object>);
}
, player);
container.Clear();
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel." + index + ".Open");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
FadeIn = 1f, Color = "0.5 1 0.5 0.2", Material = ""
}
, Text = {
Text = ""
}
}
, StoreLayer + ".BlockPanel." + index , StoreLayer + ".BlockPanel." + index + ".Open");
CuiHelper.AddUi(player, container);
break;
case 404 : LogPlayerAction(player, $"Сайт не ответило на запрос: {id}");
player.ChatMessage($"Непредвиденная ошибка со стороны сервера, просим прощения!");
CuiHelper.DestroyUi(player, StoreLayer);
Debug.LogError("Response code: 404, please check your configurations");
break;
}
}
, player);
break;
}
}
}
#endregion
#region Interface
private static string StoreLayer = "UI_GameStoresRUST_Store";
private void InitializeStore(BasePlayer player, int page, bool first = true) {
CuiElementContainer container = new CuiElementContainer();
if (first) {
CuiHelper.DestroyUi(player, StoreLayer);
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Image = {
Color = "0 0 0 0.9", Material = "assets/content/ui/uibackgroundblur.mat"
}
,
}
, "Overlay", StoreLayer);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.8 0.9", AnchorMax = "0.935 1", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Close = StoreLayer, Command = "closemenu"
}
, Text = {
Text = "ВЫХОД", Align = TextAnchor.MiddleRight, Font = "robotocondensed-regular.ttf", FontSize = 28
}
}
, StoreLayer);
}
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel");
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0.9", OffsetMax = "0 0"
}
, Image = {
Color = "0 0 0 0"
}
}
, StoreLayer, StoreLayer + ".BlockPanel");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1.1", OffsetMax = "0 0"
}
, Text = {
Text = "Подождите, мы обрабатываем ваш запрос...", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 34
}
}
, StoreLayer + ".BlockPanel", StoreLayer + ".BlockPanel.Text");
CuiHelper.AddUi(player, container);
Request($"&method=basket&steam_id={player.UserIDString}", (code, response) => {
switch (code) {
case 0 : {
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel.Text");
CuiElementContainer secondContainer = new CuiElementContainer();
secondContainer.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = "Непредвиденная ошибка, попробуйте позже!", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 38
}
}
, StoreLayer + ".BlockPanel", StoreLayer + ".BlockPanel.Text");
CuiHelper.AddUi(player, secondContainer);
break;
}
case 200 : {
var firstInfo = JsonConvert.DeserializeObject<Dictionary<string, object>>(response, new KeyValuesConverter());
if (firstInfo.ContainsKey("result")) {
if (firstInfo["result"].ToString() == "fail") {
if (firstInfo["code"].ToString() == "104") {
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel.Text");
CuiElementContainer secondContainer = new CuiElementContainer();
secondContainer.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0.1", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = "Ваша корзина пуста", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 34
}
}
, StoreLayer + ".BlockPanel", StoreLayer + ".BlockPanel.Text");
CuiHelper.AddUi(player, secondContainer);
}
if (firstInfo["code"].ToString() == "105") {
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel.Text");
CuiElementContainer secondContainer = new CuiElementContainer();
secondContainer.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0.1", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Text = {
Text = "Вы не авторизованы в магазине!\n" + "Ссылку на авторизацию вы можете найти в разделе 'помощь'", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 34
}
}
, StoreLayer + ".BlockPanel", StoreLayer + ".BlockPanel.Text");
CuiHelper.AddUi(player, secondContainer);
}
}
else {
CuiElementContainer secondContainer = new CuiElementContainer();
if (!(firstInfo["data"] is List<object>)) {
PrintError("Unkown error #1");
CuiHelper.DestroyUi(player, StoreLayer);
return;
}
List<object> data = firstInfo["data"] as List<object>;
List<WItem> wItems = new List<WItem>();
foreach (var check in data.Skip(page * 21).Take(21)) {
wItems.Add(new WItem(check as Dictionary<string, object>));
}
secondContainer.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 0.14", OffsetMax = "0 0"
}
, Text = {
Text = (page + 1).ToString(), Align = TextAnchor.MiddleCenter, FontSize = 34
}
}
, StoreLayer + ".BlockPanel");
secondContainer.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.4 0.14", AnchorMax = "0.4 0.14", OffsetMin = "-40 -125", OffsetMax = "125 40"
}
, Button = {
Color = "0 0 0 0", Material = "", Command = page > 0 ? $"UI_GameStoresRUST page {page - 1}" : ""
}
, Text = {
Text = "<", Color = page > 0 ? "1 1 1 1" : "1 1 1 0.2", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 80
}
}
, StoreLayer + ".BlockPanel");
secondContainer.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.6 0.14", AnchorMax = "0.6 0.14", OffsetMin = "-125 -125", OffsetMax = "40 40"
}
, Button = {
Color = "0 0 0 0", Material = "", Command = (page + 1) * 21 < data.Count ? $"UI_GameStoresRUST page {page + 1}" : ""
}
, Text = {
Text = ">", Color = (page + 1) * 21 < data.Count ? "1 1 1 1" : "1 1 1 0.2", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 80
}
}
, StoreLayer + ".BlockPanel");
double xSwitch = 0;
double ySwitch = 0;
for (int i = 0; i < Settings.InterfaceSettings.ItemOnString * Settings.InterfaceSettings.StringAmount; i++) {
UI_RecountPosition(ref xSwitch, ref ySwitch, i, Settings.InterfaceSettings.ItemOnString * Settings.InterfaceSettings.StringAmount);
secondContainer.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.495 0.55", AnchorMax = "0.495 0.55", OffsetMin = $"{xSwitch} {ySwitch - Settings.InterfaceSettings.ItemSide}", OffsetMax = $"{xSwitch + Settings.InterfaceSettings.ItemSide} {ySwitch}"
}
, Button = {
Color = "1 1 1 0.03", Command = $""
}
, Text = {
Text = ""
}
}
, StoreLayer + ".BlockPanel", StoreLayer + $".BlockPanel.{i}");
}
/*if (player.IsAdmin)
{
LogToFile("Test", "123 - " + JsonConvert.SerializeObject(wItems), this);
} */
foreach (var check in wItems.Select((i, t) => new {
A = i, B = t
}
)) {
if (check.A.IsBlueprint) {
if (plugins.Find("ImageLibrary") != null) {
secondContainer.Add(new CuiElement {
Parent = StoreLayer + ".BlockPanel." + check.B, Components = {
new CuiRawImageComponent {
Png = (string) plugins.Find("ImageLibrary").Call("GetImage", "blueprintbase")
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5"
}
,
}
}
);
}
else {
secondContainer.Add(new CuiElement {
Parent = StoreLayer + ".BlockPanel." + check.B, Components = {
new CuiRawImageComponent {
Url = "https://gamestores.ru/img/games/rust/blueprintbase.png"
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5"
}
,
}
}
);
}
}
if (!check.A.ImageUrl.Contains("http")) {
secondContainer.Add(new CuiElement {
Parent = StoreLayer + ".BlockPanel." + check.B, Components = {
new CuiRawImageComponent {
Png = check.A.ImageUrl
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5"
}
,
}
}
);
}
else {
secondContainer.Add(new CuiElement {
Parent = StoreLayer + ".BlockPanel." + check.B, Components = {
new CuiRawImageComponent {
Url = check.A.ImageUrl
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "5 5", OffsetMax = "-5 -5"
}
,
}
}
);
}
if (check.A.Amount > 1) {
secondContainer.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMin = "0 5", OffsetMax = "-5 0"
}
, Text = {
Text = "x" + check.A.Amount, Align = TextAnchor.LowerRight, Font = "robotocondensed-regular.ttf", FontSize = 24
}
}
, StoreLayer + ".BlockPanel." + check.B);
}
if (check.A.Blocked) {
double left = check.A.Block_Date - CurrentTime();
secondContainer.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "1 0.5 0.5 0.2", Command = $"UI_GameStoresRUST take {check.B} {check.A.ID} blocked {left}"
}
, Text = {
Text = "", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 38
}
}
, StoreLayer + ".BlockPanel." + check.B , StoreLayer + ".BlockPanel." + check.B + ".Open");
}
else {
secondContainer.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Close = StoreLayer + ".BlockPanel." + check.B + ".Open", Command = $"UI_GameStoresRUST take {check.B} {check.A.ID}"
}
, Text = {
Text = ""
}
}
, StoreLayer + ".BlockPanel." + check.B , StoreLayer + ".BlockPanel." + check.B + ".Open");
}
}
CuiHelper.AddUi(player, secondContainer);
CuiHelper.DestroyUi(player, StoreLayer + ".BlockPanel.Text");
}
}
break;
}
}
}
, player);
}
private string IconLayer = "UI_GameStoresRUST_Bucket";
private void InitializeIcon(BasePlayer player) {
CuiHelper.DestroyUi(player, IconLayer);
CuiElementContainer container = new CuiElementContainer();
if (Settings.InterfaceSettings.BucketURL.Contains("http")) {
if (ImageLibrary) {
container.Add(new CuiElement {
Parent = "Overlay", Name = IconLayer, Components = {
new CuiRawImageComponent {
Png = (string) ImageLibrary.Call("GetImage", "GameStoresRUSTBucket")
}
, new CuiRectTransformComponent {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "8 -40", OffsetMax = "43 -6"
}
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 0"
}
, Button = {
Color = "0 0 0 0", Command = "chat.say /store"
}
, Text = {
Text = ""
}
}
, IconLayer);
}
else {
container.Add(new CuiElement {
Parent = "Overlay", Name = IconLayer, Components = {
new CuiRawImageComponent {
Url = Settings.InterfaceSettings.BucketURL
}
, new CuiRectTransformComponent {
AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "8 -40", OffsetMax = "43 -6"
}
}
// ... [Code preview truncated due to length. Full source in attached file] ...