C#:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using WebSocketSharp;
using Random = UnityEngine.Random;
namespace Oxide.Plugins {
[Info("Battlepass", "Mevent", "1.21.0")]
public class Battlepass : RustPlugin {
#region Fields
[PluginReference]
private Plugin ImageLibrary;
private const string Layer = "UI.Battlepass";
private const string ModalLayer = "UI.Battlepass.Modal";
private const string OrangeColor = "0.74 0.36 0.13 1";
private const string ProgressBarColor = "0.74 0.36 0.13 0.4";
private static Battlepass _instance;
private bool needUpdate;
private readonly Dictionary<BasePlayer, List<ItemCase>> openedCaseItems = new Dictionary<BasePlayer, List<ItemCase>>();
private readonly List<GeneralMission> _generalMissions = new List<GeneralMission>();
private List<int> _privateMissions = new List<int>();
private readonly List<BasePlayer> _missionPlayers = new List<BasePlayer>();
private readonly List<uint> LootedItems = new List<uint>();
private DateTime nextTime;
private class GeneralMission {
public int ID;
public MissionConfig Mission;
}
private enum ItemType {
Item, Command, Plugin
}
private enum MissionType {
Gather, Kill, Craft, Look, Build, Upgrade
}
#endregion
#region Config
private static Configuration _config;
private class Configuration {
[JsonProperty(PropertyName = "Команда | Command")]
public string Command = "pass";
[JsonProperty(PropertyName = "Право | Permission")]
public string Permission = "battlepass.use";
[JsonProperty(PropertyName = "Фон | Background")]
public string Background = "https://i.imgur.com/Duv8iVm.jpg";
[JsonProperty(PropertyName = "Логотип | Logo")]
public string Logo = "https://i.imgur.com/mhRO2AN.png";
[JsonProperty(PropertyName = "Сбрасывать квест после его завершения? | Reset the quest after completing it?")]
public bool ResetQuestAfterComplete;
[JsonProperty(PropertyName = "Валюта 1 | Currency 1")]
public FirstCurrencyClass FirstCurrency = new FirstCurrencyClass {
Image = "https://i.imgur.com/swNAv0k.png", useDefaultCur = true, AddHook = "Deposit", BalanceHook = "Balance", RemoveHook = "Withdraw", Plug = "Economics", Rates = new Dictionary<string, float> {
["battlepass.vip"]
= 2f, ["battlepass.premium"] = 3f
}
}
;
[JsonProperty(PropertyName = "Использовать 2 валюту? | Use 2nd currency?")]
public bool useSecondCur = true;
[JsonProperty(PropertyName = "Валюта 2 | Currency 2")]
public SecondCurrencyClass SecondCurrency = new SecondCurrencyClass {
Image = "https://i.imgur.com/d3vGeRL.png", useDefaultCur = true, AddHook = "Deposit", BalanceHook = "Balance", RemoveHook = "Withdraw", Plug = "Economics"
}
;
[JsonProperty(PropertyName = "Изображение сезона | Season image")]
public string Battlepass = "https://i.imgur.com/f2GN8m7.png";
[JsonProperty(PropertyName = "Изображение кейсов | Case Image")]
public string CaseImg = "https://i.imgur.com/2lMM2bS.png";
[JsonProperty(PropertyName = "Изображение инвентаря | Inventory Image")]
public string InventoryImg = "https://i.imgur.com/vvJe7KO.png";
[JsonProperty(PropertyName = "Изображение топ награды | Image Top Awards")]
public string AdvanceAwardImg = "https://i.imgur.com/gRFdu5D.png";
[JsonProperty(PropertyName = "Фон для кейсов | Background for cases")]
public string CaseBG = "https://i.imgur.com/tlMMjqc.png";
[JsonProperty(PropertyName = "Кейсы | Cases", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<CaseClass> Cases = new List<CaseClass> {
new CaseClass {
DisplayName = "Кейс 'Сокровища пиратов'", Image = "https://i.imgur.com/tsPPUhg.png", Permission = "battlepass.vip", FCost = 3000, PCost = 1500, Items = new List<ItemCase> {
new ItemCase {
Title = "Дерево (2000 шт.)", Chance = 80, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "wood", Skin = 0, Amount = 2000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Камень (3000 шт.)", Chance = 70, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "stones", Skin = 0, Amount = 3000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Штурмовая винтовка", Chance = 50, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 0, Amount = 1, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Сера (10000 шт.)", Chance = 25, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "sulfur", Skin = 0, Amount = 10000, Command = string.Empty, PluginAward = new PluginAward()
}
}
}
, new CaseClass {
DisplayName = "Легендарный кейс", Image = "https://i.imgur.com/3mtbqji.png", Permission = "battlepass.use", FCost = 2000, PCost = 1000, Items = new List<ItemCase> {
new ItemCase {
Title = "Дерево (2000 шт.)", Chance = 80, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "wood", Skin = 0, Amount = 2000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Камень (3000 шт.)", Chance = 70, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "stones", Skin = 0, Amount = 3000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Штурмовая винтовка", Chance = 50, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 0, Amount = 1, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Сера (10000 шт.)", Chance = 25, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "sulfur", Skin = 0, Amount = 10000, Command = string.Empty, PluginAward = new PluginAward()
}
}
}
, new CaseClass {
DisplayName = "Кейс мастера", Image = "https://i.imgur.com/NvHk5Sw.png", Permission = "battlepass.use", FCost = 1500, PCost = 750, Items = new List<ItemCase> {
new ItemCase {
Title = "Дерево (2000 шт.)", Chance = 80, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "wood", Skin = 0, Amount = 2000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Камень (3000 шт.)", Chance = 70, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "stones", Skin = 0, Amount = 3000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Штурмовая винтовка", Chance = 50, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 0, Amount = 1, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Сера (10000 шт.)", Chance = 25, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "sulfur", Skin = 0, Amount = 10000, Command = string.Empty, PluginAward = new PluginAward()
}
}
}
, new CaseClass {
DisplayName = "Кейс профессионала", Image = "https://i.imgur.com/kZyZqy9.png", Permission = "battlepass.use", FCost = 1000, PCost = 500, Items = new List<ItemCase> {
new ItemCase {
Title = "Дерево (2000 шт.)", Chance = 80, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "wood", Skin = 0, Amount = 2000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Камень (3000 шт.)", Chance = 70, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "stones", Skin = 0, Amount = 3000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Штурмовая винтовка", Chance = 50, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 0, Amount = 1, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Сера (10000 шт.)", Chance = 25, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "sulfur", Skin = 0, Amount = 10000, Command = string.Empty, PluginAward = new PluginAward()
}
}
}
, new CaseClass {
DisplayName = "Кейс любителя", Image = "https://i.imgur.com/5bur68a.png", Permission = "battlepass.use", FCost = 500, PCost = 250, Items = new List<ItemCase> {
new ItemCase {
Title = "Дерево (2000 шт.)", Chance = 80, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "wood", Skin = 0, Amount = 2000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Камень (3000 шт.)", Chance = 70, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "stones", Skin = 0, Amount = 3000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Штурмовая винтовка", Chance = 50, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 0, Amount = 1, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Сера (10000 шт.)", Chance = 25, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "sulfur", Skin = 0, Amount = 10000, Command = string.Empty, PluginAward = new PluginAward()
}
}
}
, new CaseClass {
DisplayName = "Кейс новичка", Image = "https://i.imgur.com/9KIoJ2G.png", Permission = "", FCost = 150, PCost = 75, Items = new List<ItemCase> {
new ItemCase {
Title = "Дерево (2000 шт.)", Chance = 80, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "wood", Skin = 0, Amount = 2000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Камень (3000 шт.)", Chance = 70, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "stones", Skin = 0, Amount = 3000, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Штурмовая винтовка", Chance = 50, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 0, Amount = 1, Command = string.Empty, PluginAward = new PluginAward()
}
, new ItemCase {
Title = "Сера (10000 шт.)", Chance = 25, Type = ItemType.Item, Image = string.Empty, DisplayName = string.Empty, Shortname = "sulfur", Skin = 0, Amount = 10000, Command = string.Empty, PluginAward = new PluginAward()
}
}
}
}
;
[JsonProperty(PropertyName = "Количество общих миссий в день | Total missions per day")]
public int MissionsCount = 7;
[JsonProperty(PropertyName = "Раз во сколько часов обновлять миссии? | How many hours are missions updated?")]
public int MissionHours = 24;
[JsonProperty(PropertyName = "Настройка общих миссий | Settings shared missions", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<int, MissionConfig> Missions = new Dictionary<int, MissionConfig> {
[1]
= new MissionConfig {
Description = "Добыть 5000 камней", Type = MissionType.Gather, Shortname = "stones", Skin = 0, Grade = 0, Amount = 5000, MainAward = 50, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
, [2] = new MissionConfig {
Description = "Убить 3 игроков", Type = MissionType.Kill, Shortname = "player", Skin = 0, Grade = 0, Amount = 3, MainAward = 90, UseAdvanceAward = false, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
, [3] = new MissionConfig {
Description = "Скрафтить 15 ракет", Type = MissionType.Craft, Shortname = "ammo.rocket.basic", Skin = 0, Grade = 0, Amount = 15, MainAward = 75, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
, [4] = new MissionConfig {
Description = "Залутать 10 металлических пружин", Type = MissionType.Look, Shortname = "metalspring", Skin = 0, Grade = 0, Amount = 10, MainAward = 50, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
, [5] = new MissionConfig {
Description = "Построить 25 высоких внешних каменных стен для защиты Вашего дома", Type = MissionType.Build, Shortname = "wall.external.high.stone", Skin = 0, Grade = 0, Amount = 25, MainAward = 100, UseAdvanceAward = false, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
, [6] = new MissionConfig {
Description = "Улучшить 10 фундаментов в металл", Type = MissionType.Upgrade, Shortname = "foundation.prefab", Skin = 0, Grade = 3, Amount = 10, MainAward = 60, UseAdvanceAward = false, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
, [7] = new MissionConfig {
Description = "Добыть 10000 дерева", Type = MissionType.Gather, Shortname = "wood", Skin = 0, Grade = 0, Amount = 10000, MainAward = 50, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
, [8] = new MissionConfig {
Description = "Скрафтите 3 бронированные двери для дома", Type = MissionType.Craft, Shortname = "door.hinged.toptier", Skin = 0, Grade = 0, Amount = 3, MainAward = 85, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "rifle.ak", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = false, SecondAward = 0
}
}
;
[JsonProperty(PropertyName = "Настройка вызова дня | Settings challenge of the day", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<int, MissionConfig> PrivateMissions = new Dictionary<int, MissionConfig> {
[1]
= new MissionConfig {
Description = "Добыть 5000 камней", Type = MissionType.Gather, Shortname = "stones", Skin = 0, Grade = 0, Amount = 5000, MainAward = 50, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = true, SecondAward = 25
}
, [2] = new MissionConfig {
Description = "Убить 3 игроков", Type = MissionType.Kill, Shortname = "player", Skin = 0, Grade = 0, Amount = 3, MainAward = 90, UseAdvanceAward = false, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = true, SecondAward = 25
}
, [3] = new MissionConfig {
Description = "Скрафтить 15 ракет", Type = MissionType.Craft, Shortname = "ammo.rocket.basic", Skin = 0, Grade = 0, Amount = 15, MainAward = 75, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = true, SecondAward = 25
}
, [4] = new MissionConfig {
Description = "Залутать 10 металлических пружин", Type = MissionType.Look, Shortname = "metalspring", Skin = 0, Grade = 0, Amount = 10, MainAward = 50, UseAdvanceAward = true, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = true, SecondAward = 25
}
, [5] = new MissionConfig {
Description = "Построить 25 высоких внешних каменных стен для защиты Вашего дома", Type = MissionType.Build, Shortname = "wall.external.high.stone", Skin = 0, Grade = 0, Amount = 25, MainAward = 100, UseAdvanceAward = false, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = true, SecondAward = 25
}
, [6] = new MissionConfig {
Description = "Улучшить 10 фундаментов в металл", Type = MissionType.Upgrade, Shortname = "foundation.prefab", Skin = 0, Grade = 3, Amount = 10, MainAward = 60, UseAdvanceAward = false, AdvanceAward = new AdvanceAward {
Image = "https://i.imgur.com/IkEWGT8.png", Amount = 1, DisplayName = string.Empty, Shortname = "", Skin = 1230963555, Title = "Talon AK-47"
}
, UseSecondAward = true, SecondAward = 25
}
}
;
[JsonProperty(PropertyName = "Включить логирование в консоль? | Enable logging to the console?")]
public bool LogToConsole = true;
[JsonProperty(PropertyName = "Включить логирование в файл? | Enable logging to the file?")]
public bool LogToFile = true;
}
private class CurrencyClass {
[JsonProperty(PropertyName = "Картинка | Image")]
public string Image;
[JsonProperty(PropertyName = "Использовать встроенную систему? | Use embedded system?")]
public bool useDefaultCur;
[JsonProperty(PropertyName = "Название плагина | Plugin name")]
public string Plug;
[JsonProperty(PropertyName = "Функция пополнения баланса | Balance add hook")]
public string AddHook;
[JsonProperty(PropertyName = "Функция снятия баланса | Balance remove hook")]
public string RemoveHook;
[JsonProperty(PropertyName = "Функция показа баланса | Balance show hook")]
public string BalanceHook;
}
private class FirstCurrencyClass : CurrencyClass {
[JsonProperty(PropertyName = "Rates for permissions", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> Rates;
public double ShowBalance(BasePlayer player) {
if (useDefaultCur) return _instance.GetFirstCurrency(player.userID);
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return 0;
return Math.Round(Convert.ToDouble(plugin.Call(BalanceHook, player.UserIDString)));
}
public void AddBalance(BasePlayer player, int amount) {
if (useDefaultCur) {
_instance.AddFirstCurrency(player, amount);
return;
}
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return;
switch (Plug) {
case "Economics" : plugin.Call(AddHook, player.UserIDString, (double) amount);
break;
default : plugin.Call(AddHook, player.UserIDString, amount);
break;
}
}
public bool RemoveBalance(BasePlayer player, int amount) {
if (ShowBalance(player) < amount) return false;
if (useDefaultCur) return _instance.RemoveFirstCurrency(player, amount);
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return false;
switch (Plug) {
case "Economics" : plugin.Call(RemoveHook, player.UserIDString, (double) amount);
break;
default : plugin.Call(RemoveHook, player.UserIDString, amount);
break;
}
return true;
}
}
private class SecondCurrencyClass : CurrencyClass {
[JsonProperty(PropertyName = "Право | Permission")]
public string Permission;
public double ShowBalance(BasePlayer player) {
if (useDefaultCur) return _instance.GetSecondCurrency(player.userID);
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return 0;
return Math.Round(Convert.ToDouble(plugin.Call(BalanceHook, player.UserIDString)));
}
public void AddBalance(BasePlayer player, int amount) {
if (useDefaultCur) {
_instance.AddSecondCurrency(player, amount);
return;
}
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return;
switch (Plug) {
case "Economics" : plugin.Call(AddHook, player.UserIDString, (double) amount);
break;
default : plugin.Call(AddHook, player.UserIDString, amount);
break;
}
}
public bool RemoveBalance(BasePlayer player, int amount) {
if (ShowBalance(player) < amount) return false;
if (useDefaultCur) return _instance.RemoveSecondCurrency(player, amount);
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return false;
switch (Plug) {
case "Economics" : plugin.Call(RemoveHook, player.UserIDString, (double) amount);
break;
default : plugin.Call(RemoveHook, player.UserIDString, amount);
break;
}
return true;
}
}
private class MissionConfig {
[JsonProperty(PropertyName = "Описание миссии | Mission description")]
public string Description;
[JsonProperty(PropertyName = "Тип миссии | Mission type")]
[JsonConverter(typeof(StringEnumConverter))]
public MissionType Type;
[JsonProperty(PropertyName = "Шортнейм/префаб | Shortname/prefab")]
public string Shortname;
[JsonProperty(PropertyName = "Скин (0 - любой предмет) | Skin (0 - any item)")]
public ulong Skin;
[JsonProperty(PropertyName = "Уровень апгрейда (для миссий 'Улучшить') | Upgrade Level (for 'Улучшить' missions)")]
public int Grade;
[JsonProperty(PropertyName = "Количество | Amount")]
public int Amount;
[JsonProperty(PropertyName = "Количество основной награды | Amounr of main reward")]
public int MainAward;
[JsonProperty(PropertyName = "Давать доп.награду? | Give extra reward?")]
public bool UseAdvanceAward;
[JsonProperty(PropertyName = "Настройка доп.награды | Settings extra reward")]
public AdvanceAward AdvanceAward;
[JsonProperty(PropertyName = "(Вызов) Давать вторую валюту | (Challenge) Give second currency?")]
public bool UseSecondAward;
[JsonProperty(PropertyName = "(Вызов) Количество основной валюты | (Challenge) Amount of second currency")]
public int SecondAward;
private void GiveMainAward(BasePlayer player) {
_config.FirstCurrency.AddBalance(player, MainAward);
}
public void GiveAwards(BasePlayer player) {
GiveMainAward(player);
if (UseAdvanceAward) AdvanceAward?.GiveItem(player);
}
public void GivePrivateAwards(BasePlayer player) {
GiveMainAward(player);
if (UseSecondAward) _config.SecondCurrency.AddBalance(player, SecondAward);
}
}
private class AdvanceAward {
[JsonProperty(PropertyName = "Картинка (если пусто - берётся иконка по shortname) | Image (if empty - the icon is taken by shortname)")]
public string Image;
[JsonProperty(PropertyName = "Отображаемое имя (если пусто - стандартное) | Display Name (if empty - standard)")]
public string DisplayName;
[JsonProperty(PropertyName = "Отображаемое имя (для интерфейса) | Display Name (for interface)")]
public string Title;
[JsonProperty(PropertyName = "Shortname")]
public string Shortname;
[JsonProperty(PropertyName = "Скин | Skin")]
public ulong Skin;
[JsonProperty(PropertyName = "Количество (для предмета) | Amount (for item)")]
public int Amount;
public void GiveItem(BasePlayer player) {
var item = ItemManager.CreateByName(Shortname, Amount, Skin);
if (item == null) {
_instance?.PrintError($"Error creating item with shortname '{Shortname}'");
return;
}
if (!string.IsNullOrEmpty(DisplayName)) item.name = DisplayName;
player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp);
}
}
private class CaseClass {
[JsonProperty(PropertyName = "Отображаемое имя кейса | Case Display Name")]
public string DisplayName;
[JsonProperty(PropertyName = "Картинка | Image")]
public string Image;
[JsonProperty(PropertyName = "Право | Permission")]
public string Permission;
[JsonProperty(PropertyName = "Стоимость в валюте 1 | Cost in currency 1")]
public int FCost;
[JsonProperty(PropertyName = "Стоимость в валюте 2 | Cost in currency 2")]
public int PCost;
[JsonProperty(PropertyName = "Предметы | Items", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ItemCase> Items = new List<ItemCase>();
}
private class ItemCase {
[JsonProperty(PropertyName = "Отображаемое имя (для вывода в интерфейсе) | Display Name (for display in the interface)")]
public string Title;
[JsonProperty(PropertyName = "Шанс | Chance")]
public float Chance;
[JsonProperty(PropertyName = "Тип предмета | Item type")]
[JsonConverter(typeof(StringEnumConverter))]
public ItemType Type;
[JsonProperty(PropertyName = "Картинка (если пусто - берётся икнока по shortname) | Image (if empty - the icon is taken by shortname) ")]
public string Image;
[JsonProperty(PropertyName = "Отображаемое имя (для предмета) (если пусто - стандартное) | Display name (for the item) (if empty - standard)")]
public string DisplayName;
[JsonProperty(PropertyName = "Shortname")]
public string Shortname;
[JsonProperty(PropertyName = "Скин | Skin")]
public ulong Skin;
[JsonProperty(PropertyName = "Количество (для предмета) | Amount (for item)")]
public int Amount;
[JsonProperty(PropertyName = "Команда | Command")]
public string Command;
[JsonProperty(PropertyName = "Плагин | Plugin")]
public PluginAward PluginAward;
private void ToItem(BasePlayer player) {
var newItem = ItemManager.CreateByName(Shortname, Amount, Skin);
if (newItem == null) {
_instance?.PrintError($"Error creating item with shortname '{Shortname}'");
return;
}
if (!string.IsNullOrEmpty(DisplayName)) newItem.name = DisplayName;
player.GiveItem(newItem, BaseEntity.GiveItemReason.PickedUp);
}
private void ToCommand(BasePlayer player) {
var command = Command.Replace("\n", "|").Replace("%steamid%", player.UserIDString, StringComparison.OrdinalIgnoreCase).Replace("%username%", player.displayName, StringComparison.OrdinalIgnoreCase);
foreach (var check in command.Split('|')) _instance?.Server.Command(check);
}
public void GetItem(BasePlayer player) {
if (player == null) return;
switch (Type) {
case ItemType.Command : {
ToCommand(player);
break;
}
case ItemType.Plugin : {
PluginAward?.ToPluginAward(player);
break;
}
case ItemType.Item : {
ToItem(player);
break;
}
}
}
}
private class PluginAward {
[JsonProperty("Название функции для вызова | Hook to call")]
public string hook = "Withdraw";
[JsonProperty("Название плагина | Plugin name")]
public string plugin = "Economics";
[JsonProperty("Количество | Amount")]
public int amount;
[JsonProperty("(GameStores) ИД магазина в сервисе")]
public string ShopID = "UNDEFINED";
[JsonProperty("(GameStores) ИД сервера в сервисе")]
public string ServerID = "UNDEFINED";
[JsonProperty("(GameStores) Секретный ключ")]
public string SecretKey = "UNDEFINED";
public void ToPluginAward(BasePlayer player) {
var plug = _instance?.plugins.Find(plugin);
if (plug == null) {
_instance?.PrintError($"Economy plugin '{plugin}' not found !!! ");
return;
}
switch (plugin) {
case "RustStore" : {
plug.CallHook(hook, player.userID, amount, new Action<string>(result => {
if (result == "SUCCESS") {
_instance?.Log("givemoney", "givemoney", player.displayName, player.UserIDString, amount, plug);
return;
}
Interface.Oxide.LogDebug($"Баланс игрока {player.userID} не был изменен, ошибка: {result}");
}
));
break;
}
case "GameStoresRUST" : {
_instance?.webrequest.Enqueue($"https://gamestores.ru/api/?shop_id={ShopID}&secret={SecretKey}&server={ServerID}&action=moneys&type=plus&steam_id={player.UserIDString}&amount={amount}", "", (code, response) => {
switch (code) {
case 0 : {
_instance?.PrintError("Api does not responded to a request");
break;
}
case 200 : {
_instance?.Log("givemoney", "givemoney", player.displayName, player.UserIDString, amount, plug);
break;
}
case 404 : {
_instance?.PrintError("Please check your configuration! [404]");
break;
}
}
}
, _instance);
break;
}
case "Economics" : {
plug.Call(hook, player.userID, (double) amount);
break;
}
default : {
plug.Call(hook, player.userID, amount);
break;
}
}
}
}
protected override void LoadConfig() {
base.LoadConfig();
try {
_config = Config.ReadObject<Configuration>();
if (_config == null) throw new Exception();
SaveConfig();
}
catch {
PrintError("Your configuration file contains an error.Using default configuration values.");
LoadDefaultConfig();
}
}
protected override void SaveConfig() {
Config.WriteObject(_config);
}
protected override void LoadDefaultConfig() {
_config = new Configuration();
}
#endregion
#region Data
private static PluginData _data;
private void SaveData() {
Interface.Oxide.DataFileSystem.WriteObject(Name, _data);
}
private void LoadData() {
try {
_data = Interface.Oxide.DataFileSystem.ReadObject<PluginData>(Name);
}
catch (Exception e) {
PrintError(e.ToString());
}
if (_data == null) _data = new PluginData();
}
private class PluginData {
[JsonProperty(PropertyName = "Date of last mission update")]
public DateTime MissionsDate = new DateTime(1970, 1, 1, 0, 0, 0);
[JsonProperty(PropertyName = "Missions", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<int> Missions = new List<int>();
[JsonProperty(PropertyName = "Players Data", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<ulong, PlayerData> PlayerDatas = new Dictionary<ulong, PlayerData>();
}
private class PlayerData {
[JsonProperty(PropertyName = "MissionDate")]
public DateTime MissionDate;
[JsonProperty(PropertyName = "Mission ID")]
public int MissionId;
[JsonProperty(PropertyName = "Mission Progress")]
public int MissionProgress;
[JsonProperty(PropertyName = "Currency 1")]
public int FirstCurrency;
[JsonProperty(PropertyName = "Currency 2")]
public int SecondCurrency;
[JsonProperty(PropertyName = "General Mission Progress", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<int, int> Missions = new Dictionary<int, int>();
[JsonProperty(PropertyName = "Items", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<int, ItemCase> Items = new Dictionary<int, ItemCase>();
}
#endregion
#region Hooks
private void Init() {
_instance = this;
LoadData();
}
private void OnServerInitialized() {
if (!ImageLibrary) {
PrintWarning("IMAGE LIBRARY IS NOT INSTALLED.");
}
else {
ImageLibrary.Call("AddImage", _config.Background, _config.Background);
ImageLibrary.Call("AddImage", _config.Logo, _config.Logo);
ImageLibrary.Call("AddImage", _config.FirstCurrency.Image, _config.FirstCurrency.Image);
ImageLibrary.Call("AddImage", _config.Battlepass, _config.Battlepass);
ImageLibrary.Call("AddImage", _config.CaseImg, _config.CaseImg);
ImageLibrary.Call("AddImage", _config.InventoryImg, _config.InventoryImg);
ImageLibrary.Call("AddImage", _config.CaseBG, _config.CaseBG);
ImageLibrary.Call("AddImage", _config.AdvanceAwardImg, _config.AdvanceAwardImg);
if (_config.useSecondCur) ImageLibrary.Call("AddImage", _config.SecondCurrency.Image, _config.SecondCurrency.Image);
_config.Cases.ForEach(check => {
if (!string.IsNullOrEmpty(check.Image)) ImageLibrary.Call("AddImage", check.Image, check.Image);
if (!check.Permission.IsNullOrEmpty() && !permission.PermissionExists(check.Permission)) permission.RegisterPermission(check.Permission, this);
check.Items.ForEach(item => {
if (!string.IsNullOrEmpty(item.Image)) ImageLibrary.Call("AddImage", item.Image, item.Image);
}
);
}
);
foreach (var missions in _config.Missions.Values) {
if (missions.UseAdvanceAward || string.IsNullOrEmpty(missions.AdvanceAward.Image)) continue;
ImageLibrary.Call("AddImage", missions.AdvanceAward.Image, missions.AdvanceAward.Image);
}
foreach (var missions in _config.PrivateMissions.Values) {
if (missions.UseAdvanceAward || string.IsNullOrEmpty(missions.AdvanceAward.Image)) continue;
ImageLibrary.Call("AddImage", missions.AdvanceAward.Image, missions.AdvanceAward.Image);
}
}
foreach (var check in _config.FirstCurrency.Rates) if (!permission.PermissionExists(check.Key)) permission.RegisterPermission(check.Key, this);
if (_config.useSecondCur && !_config.SecondCurrency.Permission.IsNullOrEmpty() && !permission.PermissionExists(_config.SecondCurrency.Permission)) permission.RegisterPermission(_config.SecondCurrency.Permission, this);
if (!_config.Permission.IsNullOrEmpty() && !permission.PermissionExists(_config.Permission)) permission.RegisterPermission(_config.Permission, this);
cmd.AddChatCommand(_config.Command, this, nameof(CmdChatOpenBattlepass));
AddCovalenceCommand(new[] {
"addfirstcurrency", "addsecondcurrency"
}
, nameof(CmdAddBalance));
UpdateMissions();
Ch
// ... [Code preview truncated due to length. Full source in attached file] ...