C#:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Facepunch;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Oxide.Plugins
{
[Info("Battlepass", "Mevent", "1.33.0")]
public class Battlepass : RustPlugin
{
#region Fields
[PluginReference] private Plugin ImageLibrary, PlayerDatabase;
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 Timer _updateMissions;
private Timer _refreshCooldown;
private readonly List<Coroutine> _coroutines = new List<Coroutine>();
private readonly Dictionary<BasePlayer, List<ItemCase>> _openedCaseItems =
new Dictionary<BasePlayer, List<ItemCase>>();
private List<GeneralMission> _generalMissions = new List<GeneralMission>();
private List<int> _privateMissions = new List<int>();
private readonly List<BasePlayer> _missionPlayers = new List<BasePlayer>();
private DateTime _nextTime;
private class GeneralMission
{
public readonly int ID;
public readonly MissionConfig Mission;
public GeneralMission(int id, MissionConfig mission)
{
ID = id;
Mission = 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 readonly string Command = "pass";
[JsonProperty(PropertyName = "Commands for Missions page")]
public readonly string[] MissionsCommands = {"passmissions", "pmissions"};
[JsonProperty(PropertyName = "Commands for Cases page")]
public readonly string[] CasesCommands = {"passcase"};
[JsonProperty(PropertyName = "Commands for Inventory page")]
public readonly string[] InventoryCommands = {"passinv"};
[JsonProperty(PropertyName = "Permission")]
public readonly string Permission = "battlepass.use";
[JsonProperty(PropertyName = "Background")]
public readonly string Background = "https://i.imgur.com/Duv8iVm.jpg";
[JsonProperty(PropertyName = "Logo")] public readonly string Logo = "https://i.imgur.com/mhRO2AN.png";
[JsonProperty(PropertyName = "Reset the quest after completing it?")]
public bool ResetQuestAfterComplete;
[JsonProperty(PropertyName = "Currency 1")]
public readonly 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 = "Use 2nd currency?")]
public readonly bool useSecondCur = true;
[JsonProperty(PropertyName = "Currency 2")]
public readonly SecondCurrencyClass SecondCurrency = new SecondCurrencyClass
{
Permission = "battlepass.vip",
Image = "https://i.imgur.com/d3vGeRL.png",
useDefaultCur = true,
AddHook = "Deposit",
BalanceHook = "Balance",
RemoveHook = "Withdraw",
Plug = "Economics"
};
[JsonProperty(PropertyName = "Season image")]
public readonly string Battlepass = "https://i.imgur.com/f2GN8m7.png";
[JsonProperty(PropertyName = "Case Image")]
public readonly string CaseImg = "https://i.imgur.com/2lMM2bS.png";
[JsonProperty(PropertyName = "Inventory Image")]
public readonly string InventoryImg = "https://i.imgur.com/vvJe7KO.png";
[JsonProperty(PropertyName = "Image Top Awards")]
public readonly string AdvanceAwardImg = "https://i.imgur.com/gRFdu5D.png";
[JsonProperty(PropertyName = "Background for cases")]
public readonly string CaseBG = "https://i.imgur.com/tlMMjqc.png";
[JsonProperty(PropertyName = "Cases", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public readonly List<CaseClass> Cases = new List<CaseClass>
{
new CaseClass
{
DisplayName = "Case 'Pirate Treasure'",
Permission = "battlepass.vip",
Image = "https://i.imgur.com/tsPPUhg.png",
FCost = 3000,
PCost = 1500,
Items = new List<ItemCase>
{
new ItemCase
{
Title = "Wood (2000 pcs.)",
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 = "Stones (3000 pcs.)",
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 = "Assault rifle",
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 = "Sulfur (10000 pcs.)",
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 = "Legendary case",
Permission = "battlepass.use",
Image = "https://i.imgur.com/3mtbqji.png",
FCost = 2000,
PCost = 1000,
Items = new List<ItemCase>
{
new ItemCase
{
Title = "Wood (2000 pcs.)",
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 = "Stones (3000 pcs.)",
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 = "Assault rifle",
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 = "Sulfur (10000 pcs.)",
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 = "Master Case",
Permission = "battlepass.use",
Image = "https://i.imgur.com/NvHk5Sw.png",
FCost = 1500,
PCost = 750,
Items = new List<ItemCase>
{
new ItemCase
{
Title = "Wood (2000 pcs.)",
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 = "Stones (3000 pcs.)",
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 = "Assault rifle",
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 = "Sulfur (10000 pcs.)",
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 = "Professional case",
Permission = "battlepass.use",
Image = "https://i.imgur.com/kZyZqy9.png",
FCost = 1000,
PCost = 500,
Items = new List<ItemCase>
{
new ItemCase
{
Title = "Wood (2000 pcs.)",
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 = "Stones (3000 pcs.)",
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 = "Assault rifle",
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 = "Sulfur (10000 pcs.)",
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 = "Amateur case",
Permission = "battlepass.use",
Image = "https://i.imgur.com/5bur68a.png",
FCost = 500,
PCost = 250,
Items = new List<ItemCase>
{
new ItemCase
{
Title = "Wood (2000 pcs.)",
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 = "Stones (3000 pcs.)",
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 = "Assault rifle",
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 = "Sulfur (10000 pcs.)",
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 = "Newbie case",
Permission = "",
Image = "https://i.imgur.com/9KIoJ2G.png",
FCost = 150,
PCost = 75,
Items = new List<ItemCase>
{
new ItemCase
{
Title = "Wood (2000 pcs.)",
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 = "Stones (3000 pcs.)",
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 = "Assault rifle",
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 = "Sulfur (10000 pcs.)",
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 readonly int MissionsCount = 7;
[JsonProperty(PropertyName =
"How many hours are missions updated?")]
public readonly int MissionHours = 24;
[JsonProperty(PropertyName = "Settings shared missions",
ObjectCreationHandling = ObjectCreationHandling.Replace)]
public readonly Dictionary<int, MissionConfig> Missions = new Dictionary<int, MissionConfig>
{
[1] = new MissionConfig
{
Description = "Collect 5000 stones",
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 = "Kill 3 players",
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 = "Craft 15 rockets",
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 = "Loot 10 metal springs",
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 = "Build 25 high exterior stone walls to protect your home",
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 = "Upgrade 10 Foundations to Metal",
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 = "Collect 10000 wood",
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 = "Craft 3 Armored Doors",
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 readonly Dictionary<int, MissionConfig> PrivateMissions = new Dictionary<int, MissionConfig>
{
[1] = new MissionConfig
{
Description = "Collect 5000 stones",
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 = "Kill 3 players",
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 = "Craft 15 rockets",
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 = "Loot 10 metal springs",
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 = "Build 25 high exterior stone walls to protect your home",
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 = "Upgrade 10 Foundations to Metal",
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 readonly bool LogToConsole = true;
[JsonProperty(PropertyName = "Enable logging to the file?")]
public readonly bool LogToFile = true;
[JsonProperty(PropertyName = "PlayerDatabase")]
public readonly PlayerDatabaseConf PlayerDatabase = new PlayerDatabaseConf(false, "Battlepass");
}
private class PlayerDatabaseConf
{
[JsonProperty(PropertyName = "Enabled")]
public readonly bool Enabled;
[JsonProperty(PropertyName = "Table")] public readonly string Field;
public PlayerDatabaseConf(bool enabled, string field)
{
Enabled = enabled;
Field = field;
}
}
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 (empty - all)")]
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 = "Skin (0 - any item)")]
public ulong Skin;
[JsonProperty(PropertyName =
"Upgrade Level (for 'Upgrade' missions)")]
public int Grade;
[JsonProperty(PropertyName = "Amount")]
public int Amount;
[JsonProperty(PropertyName = "Amount of main reward")]
public int MainAward;
[JsonProperty(PropertyName = "Give extra reward?")]
public bool UseAdvanceAward;
[JsonProperty(PropertyName = "Settings extra reward")]
public AdvanceAward AdvanceAward;
[JsonProperty(PropertyName = "Give second currency?")]
public bool UseSecondAward;
[JsonProperty(PropertyName = "Amount of second currency")]
public int SecondAward;
private void GiveMainAward(BasePlayer player)
{
_config.FirstCurrency.AddBalance(player, (int) (MainAward * GetPlayerRates(player.UserIDString)));
}
public void GiveAwards(BasePlayer player)
{
GiveMainAward(player);
if (UseAdvanceAward) AdvanceAward?.GiveItem(player);
if (UseSecondAward) _config.SecondCurrency.AddBalance(player, SecondAward);
}
public JObject ToJObject()
{
return new JObject
{
["description"] = Description,
["type"] = (int) Type,
["shortname"] = Shortname,
["skin"] = Skin,
["grade"] = Grade,
["amount"] = Amount,
["mainaward"] = MainAward,
["use_advanceaward"] = UseAdvanceAward,
["advanceaward_image"] = AdvanceAward?.Image,
["advanceaward_displayname"] = AdvanceAward?.DisplayName,
["advanceaward_title"] = AdvanceAward?.Title,
["advanceaward_shortname"] = AdvanceAward?.Shortname,
["advanceaward_skin"] = AdvanceAward?.Skin,
["advanceaward_amount"] = AdvanceAward?.Amount,
["use_second_award"] = UseSecondAward,
["second_award"] = SecondAward
};
}
}
private class AdvanceAward
{
[JsonProperty(PropertyName =
"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 = "Cost in currency 1")]
public int FCost;
[JsonProperty(PropertyName = "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 = "ID")] public int ID;
[JsonProperty(PropertyName = "Chance")]
public float Chance;
[JsonProperty(PropertyName = "Item type")] [JsonConverter(typeof(StringEnumConverter))]
public ItemType Type;
[JsonProperty(PropertyName =
"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;
// ... [Code preview truncated due to length. Full source in attached file] ...