C#:
using System;
using System.Collections;
using System.Collections.Generic;
using ConVar;
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using System.Linq;
using Oxide.Core;
using System.Text;
namespace Oxide.Plugins {
[Info("IQCases", "TopPlugin.ru", "0.0.10")]
[Description("Кейсы на ваш сервер")]
class IQCases : RustPlugin {
#region Reference
[PluginReference]
Plugin IQChat, IQEconomic, ImageLibrary, IQRankSystem;
#region IQChat
public void SendChat(string Message, BasePlayer player, Chat.ChatChannel channel = Chat.ChatChannel.Global) {
var Chat = config.ReferenceSettings.ChatSettings;
if (IQChat) if (Chat.UIAlertUse) IQChat?.Call("API_ALERT_PLAYER_UI", player, Message);
else IQChat?.Call("API_ALERT_PLAYER", player, Message, Chat.CustomPrefix, Chat.CustomAvatar);
else player.SendConsoleCommand("chat.add", channel, 0, Message);
}
#endregion
#region ImageLibrary
private String GetImage(String fileName, UInt64 skin = 0) {
var imageId = (String)plugins.Find("ImageLibrary").CallHook("GetImage", fileName, skin);
if (!string.IsNullOrEmpty(imageId)) return imageId;
return String.Empty;
}
public Boolean AddImage(String url, String shortname, UInt64 skin = 0) => (Boolean)ImageLibrary?.Call("AddImage", url, shortname, skin);
public void SendImage(BasePlayer player, String imageName, UInt64 imageId = 0) => ImageLibrary?.Call("SendImage", player, imageName, imageId);
public Boolean HasImage(String imageName) => (Boolean)ImageLibrary?.Call("HasImage", imageName);
public string ImageGetItems(string CaseKey, int ItemKey) {
var Case = config.CaseList[CaseKey];
var Item = Case.ItemSetting[ItemKey];
string ReturnImage = Item.CommandUse ? Item.Command : $"{Item.Shortname}_256px_case";
return ReturnImage;
}
public string ImageGetItemsInventory(ulong userID, ItemSettings itemSettings) {
string ReturnImage = itemSettings.CommandUse ? itemSettings.Command : $"{itemSettings.Shortname}_256px_case";
return ReturnImage;
}
private IEnumerator DownloadImages() {
PrintError("AddImages SkyPlugins.ru...");
var Image = config.CaseList;
foreach (var Img in Image) foreach (var ShortnameList in Img.Value.ItemSetting.Where(x => !x.CommandUse && !String.IsNullOrWhiteSpace(x.Shortname))) {
String URL = $"http://api.skyplugins.ru/api/getimage/{ShortnameList.Shortname}/256";
String KeyName = $"{ShortnameList.Shortname}_256px_case";
if (!HasImage(KeyName)) AddImage(URL, KeyName);
yield return new WaitForSeconds(0.04f);
}
yield return new WaitForSeconds(0.04f);
PrintError("AddImages SkyPlugins.ru - completed..");
}
void AddAllImage() {
var Image = config.CaseList;
foreach (var Img in Image) {
if (!HasImage(Img.Key)) AddImage(Img.Value.URLCase, Img.Key);
foreach (var Item in Img.Value.ItemSetting) if (!HasImage(Item.Command)) AddImage(Item.URLCommand, Item.Command);
}
if (!HasImage("LEFT_ARROW")) AddImage("https://i.imgur.com/s3FmUnW.png", "LEFT_ARROW");
if (!HasImage("RIGHT_ARROW")) AddImage("https://i.imgur.com/FMeWZWa.png", "RIGHT_ARROW");
}
void CachedImage(BasePlayer player) {
var Image = config.CaseList;
foreach (var Img in Image) {
SendImage(player, Img.Key);
foreach (var Item in Img.Value.ItemSetting) SendImage(player, Item.Command);
}
SendImage(player, "LEFT_ARROW");
SendImage(player, "RIGHT_ARROW");
}
#endregion
#region IQEconomic
int GetBalance(ulong userID) => (int)IQEconomic?.Call("API_GET_BALANCE", userID);
bool IsRemovedBalance(ulong userID, int Amount) => (bool)IQEconomic?.Call("API_IS_REMOVED_BALANCE", userID, Amount);
void SetBalance(ulong userID, int Balance) => IQEconomic?.Call("API_SET_BALANCE", userID, Balance);
void RemoveBalance(ulong userID, int Balance) => IQEconomic?.Call("API_REMOVE_BALANCE", userID, Balance);
#endregion
#region IQRankSystem
bool IsRank(ulong userID, string Key) {
if (!IQRankSystem) return false;
return (bool)IQRankSystem?.Call("API_GET_AVAILABILITY_RANK_USER", userID, Key);
}
string GetRankName(string Key) {
string Rank = string.Empty;
if (!IQRankSystem) return Rank;
return (string)IQRankSystem?.Call("API_GET_RANK_NAME", Key);
}
#endregion
#endregion
#region Varibles
public Dictionary<ulong, List<ItemSettings>> VariblesPrize = new Dictionary<ulong, List<ItemSettings>>();
#endregion
#region Classes
public class ItemSettings {
[JsonProperty("Команда - ture | Вещь - false")]
public bool CommandUse;
[JsonProperty("Команда")]
public string Command;
[JsonProperty("Иконка для команды")]
public string URLCommand;
[JsonProperty("Shortname предмета")]
public string Shortname;
[JsonProperty("Минимальное количество для предмета")]
public int MinAmount;
[JsonProperty("Максимальное количество для предмета")]
public int MaxAmount;
[JsonProperty("SkinID предмета")]
public ulong SkinID;
}
#endregion
#region Configuration
private static Configuration config = new Configuration();
private class Configuration {
[JsonProperty("Настройки плагина")]
public GeneralSettings GeneralSetting = new GeneralSettings();
[JsonProperty("Настройки кейсов [Каждый кейс настраивается индивидуально,вы можете использовать функционал как вашей душе угодно!]")]
public Dictionary<string, Cases> CaseList = new Dictionary<string, Cases>();
[JsonProperty("Настройки совместной работы с другими плагинами")]
public ReferenceSetting ReferenceSettings = new ReferenceSetting();
internal class GeneralSettings {
[JsonProperty("Включить автоматическую очистку инвентаря в WIPE")]
public bool InventoryClearWipe;
}
internal class Cases {
[JsonProperty("Права для открытия кейса(если давать доступ всем - оставляйте поле пустым)")]
public string PermissionOpenCase;
[JsonProperty("Название кейса")]
public string DisplayName;
[JsonProperty("Ссылка на иконку кейса")]
public string URLCase;
[JsonProperty("IQRankSystem : С каким рангом будет доступен данный кейс(Если не нужно,оставляйте строку пустой)")]
public string IQRankKey;
[JsonProperty("Цена на кейс(IQEconomic)")]
public int IQEconomicPrice;
[JsonProperty("IQEconomicUse : Разрешить покупку кейса")]
public bool IQEconomicUse;
[JsonProperty("IQEconomicUse : Разрешить продажу кейса")]
public bool IQEconomicUseSell;
[JsonProperty("Сколько монет дадут при продаже кейса(IQEconomic)")]
public int IQEconomicPriceSell;
[JsonProperty("Выдавать кейс за время")]
public bool GiveCaseFromPlaying;
[JsonProperty("Через сколько секунд выдавать кейс")]
public int PlayingNormalFromGive;
[JsonProperty("Включить выпадение кейсов из ящиков с шансом")]
public bool UseDropList;
[JsonProperty("Выпадение кейсов и шанс [ящик] = шанс")]
public Dictionary<string, int> CasesDropList = new Dictionary<string, int>();
[JsonProperty("Включить возможность выбрать награду(1 из 3) - true / Выключить возможность выбрать награду(будет один приз) - false")]
public bool VariblesPrize;
[JsonProperty("Предметы , которые будут выпадать из кейсов")]
public List<ItemSettings> ItemSetting = new List<ItemSettings>();
}
internal class ReferenceSetting {
[JsonProperty("IQChat : Настройки чата")]
public ChatSetting ChatSettings = new ChatSetting();
internal class ChatSetting {
[JsonProperty("IQChat : Кастомный префикс в чате")]
public string CustomPrefix;
[JsonProperty("IQChat : Кастомный аватар в чате(Если требуется)")]
public string CustomAvatar;
[JsonProperty("IQChat : Использовать UI уведомления")]
public bool UIAlertUse;
}
}
public static Configuration GetNewConfiguration() {
return new Configuration {
GeneralSetting = new GeneralSettings {
InventoryClearWipe = true,
}
, CaseList = new Dictionary<string, Cases> {
["freecase"]
= new Cases {
DisplayName = "Халява", PermissionOpenCase = "", IQRankKey = "", IQEconomicUseSell = false, IQEconomicPriceSell = 0, IQEconomicUse = true, IQEconomicPrice = 10, GiveCaseFromPlaying = true, PlayingNormalFromGive = 60, URLCase = "https://i.imgur.com/N93o4D2.png", UseDropList = true, CasesDropList = new Dictionary<string, int> {
["crate_normal"]
= 80, ["crate_basic"] = 10,
}
, VariblesPrize = true, ItemSetting = new List<ItemSettings> {
new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "wood", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "wood", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = true, Command = "say Test", MinAmount = 3, MaxAmount = 3, Shortname = "wood", SkinID = 0, URLCommand = "https://i.imgur.com/N93o4D2.png",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "wood", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "wood", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = true, Command = "say Test", MinAmount = 3, MaxAmount = 3, Shortname = "wood", SkinID = 0, URLCommand = "https://i.imgur.com/N93o4D2.png",
}
,
}
,
}
, ["resource"] = new Cases {
DisplayName = "Ресурсы", IQRankKey = "", PermissionOpenCase = "iqcases.resource", IQEconomicUseSell = true, IQEconomicPriceSell = 5, IQEconomicUse = true, IQEconomicPrice = 10, GiveCaseFromPlaying = false, PlayingNormalFromGive = 60, URLCase = "https://i.imgur.com/TLYnMTo.png", UseDropList = true, CasesDropList = new Dictionary<string, int> {
["crate_normal"]
= 80, ["crate_basic"] = 10,
}
, VariblesPrize = false, ItemSetting = new List<ItemSettings> {
new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "wood", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 99999, Shortname = "wood", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "wood", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
,
}
,
}
, ["raider"] = new Cases {
DisplayName = "Штурмовик", IQRankKey = "", PermissionOpenCase = "iqcases.raider", IQEconomicUseSell = true, IQEconomicPriceSell = 5, IQEconomicUse = false, IQEconomicPrice = 10, GiveCaseFromPlaying = false, PlayingNormalFromGive = 60, URLCase = "https://i.imgur.com/c0rRlwY.png", UseDropList = false, CasesDropList = new Dictionary<string, int> {
["crate_normal"]
= 80, ["crate_basic"] = 10,
}
, VariblesPrize = true, ItemSetting = new List<ItemSettings> {
new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 1, MaxAmount = 3, Shortname = "rifle.lr300", SkinID = 0, URLCommand = "",
}
,
}
,
}
, ["components"] = new Cases {
DisplayName = "Компоненты", IQRankKey = "", PermissionOpenCase = "iqcases.component", IQEconomicUseSell = true, IQEconomicPriceSell = 5, IQEconomicUse = true, IQEconomicPrice = 10, GiveCaseFromPlaying = false, PlayingNormalFromGive = 60, URLCase = "https://i.imgur.com/HULzBVP.png", UseDropList = false, CasesDropList = new Dictionary<string, int> {
["crate_normal"]
= 80, ["crate_basic"] = 10,
}
, VariblesPrize = true, ItemSetting = new List<ItemSettings> {
new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "scrap", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "scrap", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "scrap", SkinID = 0, URLCommand = "",
}
,
}
,
}
, ["raider"] = new Cases {
DisplayName = "Рейдер", IQRankKey = "", PermissionOpenCase = "iqcases.raider", IQEconomicUseSell = true, IQEconomicPriceSell = 5, IQEconomicUse = true, IQEconomicPrice = 10, GiveCaseFromPlaying = false, PlayingNormalFromGive = 60, URLCase = "https://i.imgur.com/uBTdXnC.png", UseDropList = false, CasesDropList = new Dictionary<string, int> {
["crate_normal"]
= 80, ["crate_basic"] = 10,
}
, VariblesPrize = true, ItemSetting = new List<ItemSettings> {
new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "explosive.timed", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "explosive.timed", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "explosive.timed", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "explosive.timed", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "explosive.timed", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "explosive.timed", SkinID = 0, URLCommand = "",
}
, new ItemSettings {
CommandUse = false, Command = "", MinAmount = 10, MaxAmount = 1000, Shortname = "explosive.timed", SkinID = 0, URLCommand = "",
}
,
}
,
}
,
}
, ReferenceSettings = new ReferenceSetting {
ChatSettings = new ReferenceSetting.ChatSetting {
CustomAvatar = "", CustomPrefix = "[CASES]\n", UIAlertUse = false,
}
,
}
}
;
}
}
protected override void LoadConfig() {
base.LoadConfig();
try {
config = Config.ReadObject<Configuration>();
if (config == null) LoadDefaultConfig();
}
catch {
PrintWarning("Ошибка #49" + $"чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию! #33");
LoadDefaultConfig();
}
NextTick(SaveConfig);
}
protected override void LoadDefaultConfig() => config = Configuration.GetNewConfiguration();
protected override void SaveConfig() => Config.WriteObject(config);
#endregion
#region Data
[JsonProperty("Дата времени игроколв")]
public Dictionary<ulong, Dictionary<string, int>> TrackerTimePlayer = new Dictionary<ulong, Dictionary<string, int>>();
[JsonProperty("Дата кейсов игроков")]
public Dictionary<ulong, Dictionary<string, int>> DataPlayer = new Dictionary<ulong, Dictionary<string, int>>();
[JsonProperty("Инвентарь игроков")]
public Dictionary<ulong, List<Inventory>> InventoryPlayer = new Dictionary<ulong, List<Inventory>>();
public class Inventory {
[JsonProperty("Информация")]
public ItemSettings ItemClass = new ItemSettings();
[JsonProperty("Количество")]
public int Amount;
}
void ReadData() {
DataPlayer = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, Dictionary<string, int>>>("IQCases/IQCasesUser");
InventoryPlayer = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, List<Inventory>>>("IQCases/IQInventoryUser");
TrackerTimePlayer = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, Dictionary<string, int>>>("IQCases/TrackerTimePlayer");
}
void WriteData() => timer.Every(60f, () => {
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("IQCases/IQCasesUser", DataPlayer);
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("IQCases/IQInventoryUser", InventoryPlayer);
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("IQCases/TrackerTimePlayer", TrackerTimePlayer);
}
);
void RegisteredDataUser(BasePlayer player) {
if (!DataPlayer.ContainsKey(player.userID)) DataPlayer.Add(player.userID, new Dictionary<string, int> {
}
);
if (!InventoryPlayer.ContainsKey(player.userID)) InventoryPlayer.Add(player.userID, new List<Inventory> {
}
);
if (!TrackerTimePlayer.ContainsKey(player.userID)) TrackerTimePlayer.Add(player.userID, new Dictionary<string, int> {
}
);
}
#endregion
#region Hooks
private void Init() {
ReadData();
foreach (var Case in config.CaseList.Where(Case => !String.IsNullOrWhiteSpace(Case.Value.PermissionOpenCase) && !permission.PermissionExists(Case.Value.PermissionOpenCase, this))) permission.RegisterPermission(Case.Value.PermissionOpenCase, this);
}
private void OnServerInitialized() {
AddAllImage();
foreach (var p in BasePlayer.activePlayerList) OnPlayerConnected(p);
ServerMgr.Instance.StartCoroutine(DownloadImages());
timer.Every(300f, () => {
foreach (var p in BasePlayer.activePlayerList) TrackerTime(p);
}
);
}
void OnPlayerConnected(BasePlayer player) {
RegisteredDataUser(player);
CachedImage(player);
}
void Unload() {
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("IQCases/IQCasesUser", DataPlayer);
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("IQCases/IQInventoryUser", InventoryPlayer);
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject("IQCases/TrackerTimePlayer", TrackerTimePlayer);
ServerMgr.Instance.StopCoroutine(DownloadImages());
}
void OnNewSave(string filename) {
if (config.GeneralSetting.InventoryClearWipe) if (InventoryPlayer != null) {
InventoryPlayer.Clear();
PrintWarning("Обнаружен WIPE инвентарь был успешно очищен!");
}
}
void OnLootEntity(BasePlayer player, BaseEntity entity) {
if (entity == null || player == null) return;
if (entity.GetComponent<StorageContainer>() == null) return;
if (entity.OwnerID >= 7656000000) return;
if (entity.OwnerID == 99909) return;
Metods_Search_Case(player, entity.ShortPrefabName);
entity.OwnerID = 99909;
}
#endregion
#region Command
[ChatCommand("case")]
void ChatCommandCase(BasePlayer player) {
Interface_Cases(player);
}
[ConsoleCommand("case")]
void SystemCommandCase(ConsoleSystem.Arg arg) {
BasePlayer player = arg.Player();
if (player == null) return;
switch (arg.Args[0].ToLower()) {
case "take" : {
var CaseKey = arg.Args[1];
Interface_Take_Element(player, CaseKey);
break;
}
case "whyitem" : {
var CaseKey = arg.Args[1];
Interface_Why_Case(player, CaseKey);
break;
}
case "open" : {
var CaseKey = arg.Args[1];
Metods_Open_Case(player, CaseKey);
break;
}
case "takeitem" : {
CuiHelper.DestroyUi(player, STOP_BLOCK_INFO);
var CaseKey = arg.Args[1];
int ItemIndex = Convert.ToInt32(arg.Args[2]);
int ItemAmount = Convert.ToInt32(arg.Args[3]);
var Item = config.CaseList[CaseKey].ItemSetting[ItemIndex];
Metods_Take_Prize(player, Item, ItemAmount);
break;
}
case "inventory" : {
switch (arg.Args[1].ToLower()) {
case "open" : {
Interface_My_Inventory(player);
break;
}
case "take" : {
int IndexSlot = Convert.ToInt32(arg.Args[2]);
var inventoryClass = InventoryPlayer[player.userID][IndexSlot];
Metods_Take_Inventory(player, inventoryClass);
break;
}
case "page.controller" : {
Int32 Page = (Int32)Convert.ToInt32(arg.Args[2]);
String PageAction = (String)arg.Args[3];
switch (PageAction) {
case "next" : {
Interface_My_Inventory_LoadeItems(player, Page + 1);
break;
}
case "back" : {
Interface_My_Inventory_LoadeItems(player, Page - 1);
break;
}
}
break;
}
}
break;
}
case "iqeconomic" : {
switch (arg.Args[1].ToLower()) {
case "buy" : {
var CaseKey = arg.Args[2];
Metods_IQEconomicBuyCase(player, CaseKey);
break;
}
case "sell" : {
var CaseKey = arg.Args[2];
Metods_IQEconomicSellCase(player, CaseKey);
break;
}
}
break;
}
}
}
[ConsoleCommand("iqcase")]
void AdminCommandCase(ConsoleSystem.Arg arg) {
if (!arg.IsAdmin) return;
switch (arg.Args[0].ToLower()) {
case "give" : {
ulong ID = ulong.Parse(arg.Args[1]);
BasePlayer player = BasePlayer.FindByID(ID);
string CaseKey = arg.Args[2];
int Amount = Convert.ToInt32(arg.Args[3]);
Metods_Case_Give(player.userID, CaseKey, Amount);
break;
}
}
}
#endregion
#region Metods
#region Case
void Metods_Open_Case(BasePlayer player, string CaseKey) {
if (!UserAmountCase(player, CaseKey)) return;
DataPlayer[player.userID][CaseKey]--;
ServerMgr.Instance.StartCoroutine(Interface_Animation(player, CaseKey));
Interface.Oxide.CallHook("OpenCase", player, config.CaseList[CaseKey].DisplayName);
}
void Metods_Search_Case(BasePlayer player, string CrateName) {
foreach (var Case in config.CaseList.Where(x => x.Value.UseDropList)) {
foreach (var Item in Case.Value.CasesDropList.Where(x => x.Key.Contains(CrateName))) {
if (!GetRandomDrop(Item.Value)) continue;
Metods_Case_Give(player.userID, Case.Key, 1);
break;
}
}
}
void Metods_Case_Give(ulong userID, string CaseKey, int Amount) {
if (!DataPlayer[userID].ContainsKey(CaseKey)) if (config.CaseList.ContainsKey(CaseKey)) {
DataPlayer[userID].Add(CaseKey, Amount);
Puts($"Игрок {userID} получил кейс - {CaseKey}");
}
else PrintError("#ERROR : Такого кейса не найдено,проверьте ключ! Если у вас все верно свяжитесь с разработчиком https://vk.com/mir_inc");
else {
DataPlayer[userID][CaseKey] += Amount;
Puts($"Игрок {userID} получил кейс - {CaseKey}");
SendChat(GetLang("CHAT_CASE_DROP_ACCESS", userID.ToString(), config.CaseList[CaseKey].DisplayName), BasePlayer.FindByID(userID));
}
}
#endregion
#region Inventory
void Metods_Take_Inventory(BasePlayer player, Inventory inventoryClass) {
if (!InventoryPlayer[player.userID].Contains(inventoryClass)) return;
var InventoryItem = inventoryClass.ItemClass;
if (InventoryItem.CommandUse) rust.RunServerCommand(InventoryItem.Command.Replace("%STEAMID%", player.UserIDString));
else {
Item item = ItemManager.CreateByName(InventoryItem.Shortname, inventoryClass.Amount, InventoryItem.SkinID);
player.GiveItem(item);
}
InventoryPlayer[player.userID].Remove(inventoryClass);
SendChat(lang.GetMessage("CHAT_INVENTORY_TAKE_ACCESS", this, player.UserIDString), player);
}
void Metods_Take_Prize(BasePlayer player, ItemSettings ItemSetting, int ItemAmount) {
if (!ItemSetting.CommandUse) {
var Inventory = InventoryPlayer[player.userID].FirstOrDefault(x => x.ItemClass.Shortname == ItemSetting.Shortname);
if (Inventory != null) {
ItemDefinition Item = ItemManager.FindItemDefinition(ItemSetting.Shortname);
if (Item != null) if (Item.category != ItemCategory.Weapon) {
Inventory.Amount += ItemAmount;
return;
}
}
}
InventoryPlayer[player.userID].Add(new Inventory {
ItemClass = ItemSetting, Amount = ItemAmount
}
);
}
#endregion
#region IQEconomic
void Metods_IQEconomicBuyCase(BasePlayer player, string CaseKey) {
var Case = config.CaseList[CaseKey];
var Data = DataPlayer[player.userID];
if (!IsRemovedBalance(player.userID, Case.IQEconomicPrice)) {
SendChat(GetLang("IQECONOMIC_CASE_NO_MONEY", player.UserIDString, Case.DisplayName), player);
return;
}
if (Data.ContainsKey(CaseKey)) Data[CaseKey]++;
else Data.Add(CaseKey, 1);
RemoveBalance(player.userID, Case.IQEconomicPrice);
SendChat(GetLang("IQECONOMIC_CASE_BUY_ACCESS", player.UserIDString, Case.DisplayName), player);
}
void Metods_IQEconomicSellCase(BasePlayer player, string CaseKey) {
var Case = config.CaseList[CaseKey];
var Data = DataPlayer[player.userID];
if(!UserAmountCase(player, CaseKey)) {
SendChat(GetLang("IQECONOMIC_CASE_NO_CASE_SELL", player.UserIDString), player);
return;
}
Data[CaseKey]--;
SetBalance(player.userID, Case.IQEconomicPriceSell);
SendChat(GetLang("IQECONOMIC_CASE_SELL_ACCESS", player.UserIDString, Case.DisplayName, Case.IQEconomicPriceSell), player);
}
#endregion
#region PlayingTime
public void TrackerTime(BasePlayer player) {
foreach (var Case in config.CaseList.Where(Case => String.IsNullOrWhiteSpace(Case.Value.PermissionOpenCase) || permission.UserHasPermission(player.UserIDString, Case.Value.PermissionOpenCase))) {
var User = TrackerTimePlayer[player.userID];
if (!Case.Value.GiveCaseFromPlaying) continue;
if (!User.ContainsKey(Case.Key)) User.Add(Case.Key, (int)(Case.Value.PlayingNormalFromGive + CurrentTime()));
else if (User[Case.Key] <= CurrentTime()) {
Metods_Case_Give(player.userID, Case.Key, 1);
User[Case.Key] = (int)(Case.Value.PlayingNormalFromGive + CurrentTime());
}
}
}
#endregion
#endregion
#region Interface
public static string UI_MAIN_UI = "MAIN_PLAYER_UI";
public static string UI_TAKE_ITEM = "MAIN_UI_TAKE_ITEM";
public static string UI_WHY_CASE = "MAIN_UI_WHY_CASE";
public static string UI_MY_INVENTORY = "MAIN_UI_INVENTORY_USER";
public static string UI_CASE_ANIMATION = "MAIN_UI_ANIMATION_USER";
public static string UI_CASE_SHOW_REWARD = "MAIN_UI_SHOW_REWARD";
public static string STOP_BLOCK_INFO = "STOP_BLOCK_INFOS";
#region Cases
void Interface_Cases(BasePlayer player) {
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, UI_MAIN_UI);
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Image = {
FadeIn = 0.15f, Color = HexToRustFormat("#282A21C6"), Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
}
}
, "Overlay", UI_MAIN_UI);
#region INFO_PANEL
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "0.2020833 1"
}
, Image = {
FadeIn = 0.15f, Color = HexToRustFormat("#772424F0"), Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
}
}
, UI_MAIN_UI, "INFO_PANEL");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.01546395 0.9351851", AnchorMax = "1 1"
}
, Text = {
Text = lang.GetMessage("UI_TITLE_INFO", this, player.UserIDString), Font = "robotocondensed-bold.ttf", Align = TextAnchor.MiddleLeft, FadeIn = 0.3f
}
}
, "INFO_PANEL", "TITLE_PANEL");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.01546395 0.8611111", AnchorMax = "1 0.9462963"
}
, Text = {
Text = lang.GetMessage("UI_TITLE_INFO_DESCRIPTION", this, player.UserIDString), Font = "robotocondensed-bold.ttf", Align = TextAnchor.UpperLeft, FadeIn = 0.3f
}
}
, "INFO_PANEL", "TITLE_PANEL_DESCRIPTION");
if (IQEconomic) {
int Balance = GetBalance(player.userID);
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.0876289 0.1546298", AnchorMax = "0.435567 0.2046296"
}
, Text = {
Text = lang.GetMessage("UI_TITLE_BALANCE", this, player.UserIDString), Font = "robotocondensed-bold.ttf", Align = TextAnchor.MiddleLeft, FadeIn = 0.3f
}
}
, "INFO_PANEL", "TITLE_PANEL_BALANCE_TITLE");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0.5283506 0.1333335", AnchorMax = "0.7860826 0.225926"
}
, Text = {
Text = $"{Balance}", FontSize = 30, Font = "robotocondensed-bold.ttf", Align = TextAnchor.MiddleRight, FadeIn = 0.3f
}
}
, "INFO_PANEL", "TITLE_PANEL_BALANCE");
}
container.Add(new CuiButton {
RectTransform = {
AnchorMin = $"0.06701034 0.07870371", AnchorMax = $"0.9252577 0.1287039"
}
, Button = {
Command = "case inventory open", Color = HexToRustFormat("#4D3737C8"), Sprite = "assets/content/ui/ui.background.tile.psd"
}
, Text = {
Text = lang.GetMessage("UI_BTN_INVENTORY", this, player.UserIDString), Color = HexToRustFormat("#E9D2C1FF"), Align = TextAnchor.MiddleCenter
}
}
, "INFO_PANEL");
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0.06701034 0.01388889", AnchorMax = "0.9252577 0.06388889"
}
, Button = {
Close = UI_MAIN_UI, Color = HexToRustFormat("#4D3737C8"), Sprite = "assets/content/ui/ui.background.tile.psd"
}
, Text = {
Text = lang.GetMessage("UI_CLOSE", this, player.UserIDString), Color = HexToRustFormat("#CAAD9EFF"), Align = TextAnchor.MiddleCenter
}
}
, "INFO_PANEL");
#endregion
#region CASES
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.2015625 0", AnchorMax = "1 1"
}
, Image = {
FadeIn = 0.15f, Color = HexToRustFormat("#282A21C6"), Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
}
}
, UI_MAIN_UI, "ELEMENT_PANEL");
var CaseList = config.CaseList;
int i = 0;
int ItemCount = 0;
float itemMinPosition = 219f;
float itemWidth = 0.413646f - 0.196f;
/// Ширина
float itemMargin = 0.439895f - 0.405f;
int itemCount = CaseList.Count;
float itemMinHeight = 0.65f;
float itemHeight = 0.32f;
/// Высота
int ItemTarget = 4;
if (itemCount > ItemTarget) {
itemMinPosition = 0.5f - ItemTarget / 2f * itemWidth - (ItemTarget - 1) / 2f * itemMargin;
itemCount -= ItemTarget;
}
else itemMinPosition = 0.5f - itemCount / 2f * itemWidth - (itemCount - 1) / 2f * itemMargin;
foreach (var Case in CaseList) {
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = $"{itemMinPosition} {itemMinHeight}", AnchorMax = $"{itemMinPosition + itemWidth} {itemMinHeight + itemHeight}"
}
, Image = {
FadeIn = 0.15f, Color = "0 0 0 0"
}
}
, "ELEMENT_PANEL", $"CASE_{i}");
container.Add(new CuiLabel {
RectTransform = {
AnchorMin = "0 0.8593974", AnchorMax = "1 1"
}
, Text = {
Text = $"{Case.Value.DisplayName.ToUpper()}", Color = HexToRustFormat("#AAA39CFF"), FontSize = 24, Font = "robotocondensed-bold.ttf", Align = TextAnchor.UpperLeft, FadeIn = 0.3f
}
}
, $"CASE_{i}");
container.Add(new CuiElement {
Parent = $"CASE_{i}", Components = {
new CuiRawImageComponent {
Png = GetImage(Case.Key)
}
, new CuiRectTransformComponent {
AnchorMin = "0 0", AnchorMax = $"1 1"
}
,
}
}
);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Command = $"case take {Case.Key}", Color = "0 0 0 0"
}
, Text = {
Text = "", Align = TextAnchor.MiddleCenter
}
}
, $"CASE_{i}");
ItemCount++;
i++;
itemMinPosition += (itemWidth + itemMargin);
if (ItemCount % ItemTarget == 0) {
itemMinHeight -= (itemHeight + (itemMargin * 2f));
if (itemCount > ItemTarget) {
itemMinPosition = 0.5f - ItemTarget / 2f * itemWidth - (ItemTarget - 1) / 2f * itemMargin;
itemCount -= ItemTarget;
}
else itemMinPosition = 0.5f - itemCount / 2f * itemWidth - (itemCount - 1) / 2f * itemMargin;
}
}
#endregion
CuiHelper.AddUi(player, container);
}
#endregion
#region TakeElement
void Interface_Take_Element(BasePlayer player, string CaseKey) {
CuiElementContainer container = new CuiElementContainer();
CuiHelper.DestroyUi(player, UI_TAKE_ITEM);
container.Add(new CuiPanel {
CursorEnabled = true, RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Image = {
FadeIn = 0.15f, Color = HexToRustFormat("#282721E6"), Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
}
}
, "ELEMENT_PANEL", UI_TAKE_ITEM);
int CaseAmountUser = GetAmountCase(player, CaseKey);
var Case = config.CaseList[CaseKey];
string HexIcon = UserAmountCase(player, CaseKey) ? "#FFFFFFFF" : "#FFFFFF9E";
string RankName = string.Empty;
if (IQRankSystem) if (!String.IsNullOrWhiteSpace(Case.IQRankKey)) if (!IsRank(player.userID, Case.IQRankKey)) RankName = $"{GetRankName(Case.IQRankKey)}";
string BtnCase = !String.IsNullOrWhiteSpace(Case.PermissionOpenCase) ? permission.UserHasPermission(player.UserIDString, Case.PermissionOpenCase) ? UserAmountCase(player, CaseKey) ? String.IsNullOrWhiteSpace(RankName) ? "UI_CASE_BTN_OPEN" : "UI_CASE_BTN_NO_RANK_OPEN" : "UI_CASE_BTN_NO_OPEN" : "UI_CASE_BTN_NO_PERM_OPEN_OPEN" : UserAmountCase(player, CaseKey) ? "UI_CASE_BTN_OPEN" : "UI_CASE_BTN_NO_OPEN";
string BtnCaseCMD = !String.IsNullOrWhiteSpace(Case.PermissionOpenCase) ? permission.UserHasPermission(player.UserIDString, Case.PermissionOpenCase) ? UserAmountCase(player, CaseKey) ? String.IsNullOrWhiteSpace(RankName) ? $"case open {CaseKey}" : "" : "" : "" : UserAmountCase(player, CaseKey) ? $"case open {CaseKey}" : "";
container.Add(new CuiPanel {
RectTransform = {
AnchorMin = "0.2002609 0.1833333", AnchorMax = "0.8330071 0.8592593"
}
, Image = {
FadeIn = 0.15f, Color = "0 0 0 0"
}
}
, UI_TAKE_ITEM);
container.Add(new CuiButton {
RectTransform = {
AnchorMin = "0 0", AnchorMax = "1 1"
}
, Button = {
Close = UI_TAKE_ITEM, Color = "0 0 0 0"
}
, Text = {
Text = ""
}
}
, UI_TAKE_ITEM);
container.Add(new CuiElement {
Parent
// ... [Code preview truncated due to length. Full source in attached file] ...