C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
// #define TESTING
#if TESTING
using System.Diagnostics;
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using ConVar;
using Facepunch;
using Facepunch.Math;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Oxide.Plugins.ClansExtensionMethods;
using UnityEngine;
using Debug = UnityEngine.Debug;
using Enumerable = System.Linq.Enumerable;
using Pool = Facepunch.Pool;
using Random = UnityEngine.Random;
namespace Oxide.Plugins {
[Info("Clans", "Mevent", "1.1.29")]
public class Clans : RustPlugin {
#region Fields
[PluginReference]
private Plugin ImageLibrary = null, ArenaTournament = null, BetterChat = null, ZoneManager = null, PlayTimeRewards = null, PlayerDatabase = null;
private static Clans _instance;
private const string Layer = "UI.Clans", ModalLayer = "UI.Clans.Modal", PermAdmin = "clans.admin", COLORED_LABEL = "<color={0}>{1}</color>";
private Coroutine _actionAvatars, _actionConvert, _initTopHandle, _topHandle;
private bool _enabledSkins, _enabledImageLibrary;
private Regex _tagFilter, _hexFilter = new Regex("^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$");
private readonly List<ItemDefinition> _defaultItems = new List<ItemDefinition>();
private readonly Dictionary<ulong, ulong> _looters = new Dictionary<ulong, ulong>();
private Dictionary<string, ClanData> _playerToClan = new Dictionary<string, ClanData>();
private int _lastPlayerTop;
private readonly HashSet<ulong> _openedUI = new HashSet<ulong>();
#region Pages
private const int ABOUT_CLAN = 0, MEMBERS_LIST = 1, CLANS_TOP = 2, PLAYERS_TOP = 3, GATHER_RATES = 4, SKINS_PAGE = 6, PLAYERS_LIST = 5, ALIANCES_LIST = 7;
#endregion
#endregion
#region Config
private static Configuration _config;
private class Configuration {
[JsonProperty(PropertyName = "Avatar Settings")]
public AvatarSettings Avatar = new AvatarSettings {
DefaultAvatar = "https://i.ibb.co/q97QG6c/image.png", CanOwner = true, CanModerator = false, CanMember = false, PermissionToChange = string.Empty
}
;
[JsonProperty(PropertyName = "Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> ClanCommands = new List<string> {
"clan", "clans"
}
;
[JsonProperty(PropertyName = "Clan Info Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] ClanInfoCommands = {
"cinfo"
}
;
[JsonProperty(PropertyName = "Maximum clan description characters")]
public int DescriptionMax = 256;
[JsonProperty(PropertyName = "Clan tag in player name")]
public bool TagInName = true;
[JsonProperty(PropertyName = "Automatic team creation")]
public bool AutoTeamCreation = true;
[JsonProperty(PropertyName = "Allow players to leave their clan by using Rust's leave team button")]
public bool ClanTeamLeave = true;
[JsonProperty(PropertyName = "Allow players to kick members from their clan using Rust's kick member button")]
public bool ClanTeamKick = true;
[JsonProperty(PropertyName = "Allow players to invite other players to their clan via Rust's team invite system")]
public bool ClanTeamInvite = true;
[JsonProperty(PropertyName = "Allow players to promote other clan members via Rust's team promote button")]
public bool ClanTeamPromote = true;
[JsonProperty(PropertyName = "Allow players to accept a clan invite using the Rust invite accept button")]
public bool ClanTeamAcceptInvite = true;
[JsonProperty(PropertyName = "Show clan creation interface when creating a team?")]
public bool ClanCreateTeam = false;
[JsonProperty(PropertyName = "Force to create a clan when creating a team?")]
public bool ForceClanCreateTeam = false;
[JsonProperty(PropertyName = "Top refresh rate")]
public float TopRefreshRate = 60f;
[JsonProperty(PropertyName = "Default value for the resource standarts")]
public int DefaultValStandarts = 100000;
[JsonProperty(PropertyName = "Chat Settings")]
public ChatSettings ChatSettings = new ChatSettings {
Enabled = true, TagFormat = "<color=#{color}>[{tag}]</color>", EnabledClanChat = true, ClanChatCommands = new[] {
"c", "cchat"
}
, EnabledAllianceChat = true, AllianceChatCommands = new[] {
"a", "achat"
}
, WorkingWithBetterChat = true, WorkingWithInGameChat = false
}
;
[JsonProperty(PropertyName = "Permission Settings")]
public PermissionSettings PermissionSettings = new PermissionSettings {
UsePermClanCreating = false, ClanCreating = "clans.cancreate", UsePermClanJoining = false, ClanJoining = "clans.canjoin", UsePermClanLeave = false, ClanLeave = "clans.canleave", UsePermClanDisband = false, ClanDisband = "clans.candisband", UsePermClanKick = false, ClanKick = "clans.cankick", UsePermClanSkins = false, ClanSkins = "clans.canskins", ClanInfoAuthLevel = 0
}
;
[JsonProperty(PropertyName = "Alliance Settings")]
public AllianceSettings AllianceSettings = new AllianceSettings {
Enabled = true, UseFF = true, DefaultFF = false, GeneralFriendlyFire = false, ModersGeneralFF = false, PlayersGeneralFF = false, AllyAddPlayersTeams = false
}
;
[JsonProperty(PropertyName = "Purge Settings")]
public PurgeSettings PurgeSettings = new PurgeSettings {
Enabled = true, OlderThanDays = 14, ListPurgedClans = true, WipeClansOnNewSave = false, WipePlayersOnNewSave = false, WipeInvitesOnNewSave = false
}
;
[JsonProperty(PropertyName = "Limit Settings")]
public LimitSettings LimitSettings = new LimitSettings {
MemberLimit = 8, ModeratorLimit = 2, AlliancesLimit = 2
}
;
[JsonProperty(PropertyName = "Resources", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> Resources = new List<string> {
"stones", "sulfur.ore", "metal.ore", "hq.metal.ore", "wood"
}
;
[JsonProperty(PropertyName = "Score Table (shortname - score)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, float> ScoreTable = new Dictionary<string, float> {
["kills"]
= 1, ["deaths"] = -1, ["stone-ore"] = 0.1f, ["supply_drop"] = 3f, ["crate_normal"] = 0.3f, ["crate_elite"] = 0.5f, ["bradley_crate"] = 5f, ["heli_crate"] = 5f, ["bradley"] = 10f, ["helicopter"] = 15f, ["barrel"] = 0.1f, ["scientistnpc"] = 0.5f, ["heavyscientist"] = 2f, ["sulfur.ore"] = 0.5f, ["metal.ore"] = 0.5f, ["hq.metal.ore"] = 0.5f, ["stones"] = 0.5f, ["cupboard.tool.deployed"] = 1f
}
;
[JsonProperty(PropertyName = "Available items for resource standarts", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> AvailableStandartItems = new List<string> {
"gears", "metalblade", "metalpipe", "propanetank", "roadsigns", "rope", "sewingkit", "sheetmetal", "metalspring", "tarp", "techparts", "riflebody", "semibody", "smgbody", "fat.animal", "cctv.camera", "charcoal", "cloth", "crude.oil", "diesel_barrel", "gunpowder", "hq.metal.ore", "leather", "lowgradefuel", "metal.fragments", "metal.ore", "scrap", "stones", "sulfur.ore", "sulfur", "targeting.computer", "wood"
}
;
[JsonProperty(PropertyName = "Pages", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<PageSettings> Pages = new List<PageSettings> {
new PageSettings {
ID = ABOUT_CLAN, Key = "aboutclan", Enabled = true, Permission = string.Empty
}
, new PageSettings {
ID = MEMBERS_LIST, Key = "memberslist", Enabled = true, Permission = string.Empty
}
, new PageSettings {
ID = CLANS_TOP, Key = "clanstop", Enabled = true, Permission = string.Empty
}
, new PageSettings {
ID = PLAYERS_TOP, Key = "playerstop", Enabled = true, Permission = string.Empty
}
, new PageSettings {
ID = GATHER_RATES, Key = "resources", Enabled = true, Permission = string.Empty
}
, new PageSettings {
ID = SKINS_PAGE, Key = "skins", Enabled = true, Permission = string.Empty
}
, new PageSettings {
ID = PLAYERS_LIST, Key = "playerslist", Enabled = true, Permission = string.Empty
}
, new PageSettings {
ID = ALIANCES_LIST, Key = "alianceslist", Enabled = true, Permission = string.Empty
}
}
;
[JsonProperty(PropertyName = "Interface")]
public InterfaceSettings UI = new InterfaceSettings {
Color1 = new IColor("#0E0E10", 100), Color2 = new IColor("#4B68FF", 100), Color3 = new IColor("#161617", 100), Color4 = new IColor("#324192", 100), Color5 = new IColor("#303030", 100), Color6 = new IColor("#FF4B4B", 100), Color7 = new IColor("#4B68FF", 33), Color8 = new IColor("#0E0E10", 99), ValueAbbreviation = true, ShowCloseOnClanCreation = true, TopClansColumns = new List<ColumnSettings> {
new ColumnSettings {
Width = 75, Key = "top", LangKey = TopTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "#{0}"
}
, new ColumnSettings {
Width = 165, Key = "name", LangKey = NameTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 70, Key = "leader", LangKey = LeaderTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 90, Key = "members", LangKey = MembersTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 80, Key = "score", LangKey = ScoreTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
}
, TopPlayersColumns = new List<ColumnSettings> {
new ColumnSettings {
Width = 75, Key = "top", LangKey = TopTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "#{0}"
}
, new ColumnSettings {
Width = 185, Key = "name", LangKey = NameTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 70, Key = "kills", LangKey = KillsTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 70, Key = "resources", LangKey = ResourcesTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 80, Key = "score", LangKey = ScoreTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 12, FontSize = 12, TextFormat = "{0}"
}
}
, ProfileButtons = new List<BtnConf> {
new BtnConf {
Enabled = false, CloseMenu = true, AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "270 -55", OffsetMax = "360 -30", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 10, TextColor = new IColor("#FFFFFF", 100), Color = new IColor("#324192", 100), Title = "TP", Command = "tpr {target}"
}
, new BtnConf {
Enabled = false, CloseMenu = true, AnchorMin = "0 1", AnchorMax = "0 1", OffsetMin = "370 -55", OffsetMax = "460 -30", Align = TextAnchor.MiddleCenter, Font = "robotocondensed-regular.ttf", FontSize = 10, TextColor = new IColor("#FFFFFF", 100), Color = new IColor("#324192", 100), Title = "TRADE", Command = "trade {target}"
}
}
, ClanMemberProfileFields = new List<ColumnSettings> {
new ColumnSettings {
Width = 140, Key = "gather", LangKey = GatherTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "{0}%"
}
, new ColumnSettings {
Width = 140, Key = "lastlogin", LangKey = LastLoginTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 10, TextFormat = "{0}"
}
}
, TopPlayerProfileFields = new List<ColumnSettings> {
new ColumnSettings {
Width = 300, Key = "clanname", LangKey = ClanNameTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 140, Key = "rating", LangKey = RatingTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 140, Key = "score", LangKey = ScoreTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 140, Key = "kills", LangKey = KillsTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 140, Key = "deaths", LangKey = DeathsTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "{0}"
}
, new ColumnSettings {
Width = 140, Key = "kd", LangKey = KDTitle, TextAlign = TextAnchor.MiddleCenter, TitleFontSize = 10, FontSize = 12, TextFormat = "{0}"
}
}
, ShowBtnChangeAvatar = true, ShowBtnLeave = true
}
;
[JsonProperty(PropertyName = "Skins Settings")]
public SkinsSettings Skins = new SkinsSettings {
ItemSkins = new Dictionary<string, List<ulong>> {
["metal.facemask"]
= new List<ulong>(), ["hoodie"] = new List<ulong>(), ["metal.plate.torso"] = new List<ulong>(), ["pants"] = new List<ulong>(), ["roadsign.kilt"] = new List<ulong>(), ["shoes.boots"] = new List<ulong>(), ["rifle.ak"] = new List<ulong>(), ["rifle.bolt"] = new List<ulong>()
}
, UseSkinBox = false, UsePlayerSkins = false, UseLSkins = false, CanCustomSkin = true, Permission = string.Empty, DisableSkins = false, DefaultValueDisableSkins = true
}
;
[JsonProperty(PropertyName = "Statistics Settings")]
public StatisticsSettings Statistics = new StatisticsSettings {
Kills = true, Gather = true, Loot = true, Entities = true, Craft = true
}
;
[JsonProperty(PropertyName = "Colos Settings")]
public ColorsSettings Colors = new ColorsSettings {
Member = "#fcf5cb", Moderator = "#74c6ff", Owner = "#a1ff46"
}
;
[JsonProperty(PropertyName = "PlayerDatabase")]
public PlayerDatabaseConf PlayerDatabase = new PlayerDatabaseConf(false, "Clans");
[JsonProperty(PropertyName = "ZoneManager Settings")]
public ZoneManagerSettings ZMSettings = new ZoneManagerSettings {
Enabled = false, FFAllowlist = new List<string> {
"92457", "4587478545"
}
}
;
[JsonProperty(PropertyName = "Clan Tag Settings")]
public TagSettings Tags = new TagSettings {
TagMin = 2, TagMax = 6, BlockedWords = new List<string> {
"admin", "mod", "owner"
}
, CheckingCharacters = true, AllowedCharacters = "!²³", TagColor = new TagSettings.TagColorSettings {
Enabled = true, DefaultColor = "AAFF55", Owners = true, Moderators = false, Players = false
}
}
;
[JsonProperty(PropertyName = "Commands Settings")]
public CommandsSettings Commands = new CommandsSettings {
ClansFF = new[] {
"cff"
}
, AllyFF = new[] {
"aff"
}
}
;
[JsonProperty(PropertyName = "Saving Settings")]
public SavingSettings Saving = new SavingSettings {
SavePlayersOnServerSave = false, SaveClansOnServerSave = true
}
;
[JsonProperty(PropertyName = "Friendly Fire Settings")]
public FriendlyFireSettings FriendlyFire = new FriendlyFireSettings {
UseFriendlyFire = true, UseTurretsFF = false, GeneralFriendlyFire = false, ModersGeneralFF = false, PlayersGeneralFF = false, FriendlyFire = false, IgnoreOnArenaTournament = false
}
;
[JsonProperty(PropertyName = "Paid Functionality Settings")]
public PaidFunctionalitySettings PaidFunctionality = new PaidFunctionalitySettings {
Economy = new PaidFunctionalitySettings.EconomySettings {
Type = PaidFunctionalitySettings.EconomySettings.EconomyType.Plugin, AddHook = "Deposit", BalanceHook = "Balance", RemoveHook = "Withdraw", Plug = "Economics", ShortName = "scrap", DisplayName = string.Empty, Skin = 0
}
, ChargeFeeToCreateClan = false, CostCreatingClan = 100, ChargeFeeToJoinClan = false, CostJoiningClan = 100, ChargeFeeToKickClanMember = false, CostKickingClanMember = 100, ChargeFeeToLeaveClan = false, CostLeavingClan = 100, ChargeFeeToDisbandClan = false, CostDisbandingClan = 100, ChargeFeeToSetClanSkin = false, CostSettingClanSkin = 100, ChargeFeeToSetClanAvatar = false, CostSettingClanAvatar = 100, ChargeFeeForSendInviteToClan = false, CostForSendInviteToClan = 100
}
;
[JsonProperty(PropertyName = "Pages Settings")]
public PagesSettings PagesConfig = new PagesSettings {
Default = new PagesSettings.DefaultPages {
Enabled = true, ClanPageNotFound = ABOUT_CLAN, ClanPageWhenExists = PLAYERS_TOP
}
, StayOnPageWithSelectedSkin = true
}
;
public VersionNumber Version;
#region Classes
public class PagesSettings {
[JsonProperty(PropertyName = "Default Pages")]
public DefaultPages Default;
[JsonProperty(PropertyName = "Stay on page of item for which skin is selected")]
public bool StayOnPageWithSelectedSkin;
public class DefaultPages {
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "Default page when a clan not found")]
public int ClanPageNotFound;
[JsonProperty(PropertyName = "Default page when a clan exists")]
public int ClanPageWhenExists;
}
}
#endregion Classes
}
private class PaidFunctionalitySettings {
[JsonProperty(PropertyName = "Economy")]
public EconomySettings Economy;
[JsonProperty(PropertyName = "Charge a fee to create a clan?")]
public bool ChargeFeeToCreateClan;
[JsonProperty(PropertyName = "Cost of creating a clan")]
public int CostCreatingClan;
[JsonProperty(PropertyName = "Charge a fee to join a clan?")]
public bool ChargeFeeToJoinClan;
[JsonProperty(PropertyName = "Cost of joining a clan")]
public int CostJoiningClan;
[JsonProperty(PropertyName = "Charge a fee to kick a clan member?")]
public bool ChargeFeeToKickClanMember;
[JsonProperty(PropertyName = "Cost of kicking a clan member")]
public int CostKickingClanMember;
[JsonProperty(PropertyName = "Charge a fee to leave a clan?")]
public bool ChargeFeeToLeaveClan;
[JsonProperty(PropertyName = "Cost of leaving a clan")]
public int CostLeavingClan;
[JsonProperty(PropertyName = "Charge a fee to disband a clan?")]
public bool ChargeFeeToDisbandClan;
[JsonProperty(PropertyName = "Cost of disbanding a clan")]
public int CostDisbandingClan;
[JsonProperty(PropertyName = "Charge a fee to set a clan skin?")]
public bool ChargeFeeToSetClanSkin;
[JsonProperty(PropertyName = "Cost of setting a clan skin")]
public int CostSettingClanSkin;
[JsonProperty(PropertyName = "Charge a fee to set a clan avatar?")]
public bool ChargeFeeToSetClanAvatar;
[JsonProperty(PropertyName = "Cost of setting a clan avatar")]
public int CostSettingClanAvatar;
[JsonProperty(PropertyName = "Charge a fee for sending an invitation to a clan?")]
public bool ChargeFeeForSendInviteToClan;
[JsonProperty(PropertyName = "Cost of sending an invitation to a clan")]
public int CostForSendInviteToClan;
public class EconomySettings {
[JsonProperty(PropertyName = "Type (Plugin/Item)")]
[JsonConverter(typeof(StringEnumConverter))]
public EconomyType Type;
[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;
[JsonProperty(PropertyName = "ShortName")]
public string ShortName;
[JsonProperty(PropertyName = "Display Name (empty - default)")]
public string DisplayName;
[JsonProperty(PropertyName = "Skin")]
public ulong Skin;
public enum EconomyType {
Plugin, Item
}
public double ShowBalance(BasePlayer player) {
switch (Type) {
case EconomyType.Plugin : {
var plugin = _instance?.plugins?.Find(Plug);
if (plugin == null) return 0;
return Math.Round(Convert.ToDouble(plugin.Call(BalanceHook, player.userID)));
}
case EconomyType.Item : {
return ItemCount(player.inventory.AllItems(), ShortName, Skin);
}
default : return 0;
}
}
public void AddBalance(BasePlayer player, double amount) {
switch (Type) {
case EconomyType.Plugin : {
var plugin = _instance?.plugins?.Find(Plug);
if (plugin == null) return;
switch (Plug) {
case "BankSystem" : case "ServerRewards" : plugin.Call(AddHook, player.userID, (int) amount);
break;
default : plugin.Call(AddHook, player.userID, amount);
break;
}
break;
}
case EconomyType.Item : {
var am = (int) amount;
var item = ToItem(am);
if (item == null) return;
player.GiveItem(item);
break;
}
}
}
public bool RemoveBalance(BasePlayer player, double amount) {
switch (Type) {
case EconomyType.Plugin : {
if (ShowBalance(player) < amount) return false;
var plugin = _instance?.plugins.Find(Plug);
if (plugin == null) return false;
switch (Plug) {
case "BankSystem" : case "ServerRewards" : plugin.Call(RemoveHook, player.userID, (int) amount);
break;
default : plugin.Call(RemoveHook, player.userID, amount);
break;
}
return true;
}
case EconomyType.Item : {
var playerItems = player.inventory.AllItems();
var am = (int) amount;
if (ItemCount(playerItems, ShortName, Skin) < am) return false;
Take(playerItems, ShortName, Skin, am);
return true;
}
default : return false;
}
}
private Item ToItem(int amount) {
var item = ItemManager.CreateByName(ShortName, amount, Skin);
if (item == null) {
Debug.LogError($"Error creating item with ShortName: '{ShortName}'");
return null;
}
if (!string.IsNullOrEmpty(DisplayName)) item.name = DisplayName;
return item;
}
#region Utils
private int ItemCount(Item[] items, string shortname, ulong skin) {
return items.Where(item => item.info.shortname == shortname && !item.isBroken && (skin == 0 || item.skin == skin)).Sum(item => item.amount);
}
private void Take(IEnumerable<Item> itemList, string shortname, ulong skinId, int iAmount) {
var num1 = 0;
if (iAmount == 0) return;
var list = Pool.GetList<Item>();
foreach (var item in itemList) {
if (item.info.shortname != shortname || (skinId != 0 && item.skin != skinId) || item.isBroken) continue;
var num2 = iAmount - num1;
if (num2 <= 0) continue;
if (item.amount > num2) {
item.MarkDirty();
item.amount -= num2;
//num1 += num2;
break;
}
if (item.amount <= num2) {
num1 += item.amount;
list.Add(item);
}
if (num1 == iAmount) break;
}
foreach (var obj in list) obj.RemoveFromContainer();
Pool.FreeList(ref list);
}
#endregion
}
}
private class FriendlyFireSettings {
[JsonProperty(PropertyName = "Use Friendly Fire?")]
public bool UseFriendlyFire;
[JsonProperty(PropertyName = "Use Friendly Fire for Turrets?")]
public bool UseTurretsFF;
[JsonProperty(PropertyName = "General friendly fire (only the leader of the clan can enable/disable it)")]
public bool GeneralFriendlyFire;
[JsonProperty(PropertyName = "Can moderators toggle general friendly fire?")]
public bool ModersGeneralFF;
[JsonProperty(PropertyName = "Can players toggle general friendly fire?")]
public bool PlayersGeneralFF;
[JsonProperty(PropertyName = "Friendly Fire Default Value")]
public bool FriendlyFire;
[JsonProperty(PropertyName = "Ignore when using ArenaTournament?")]
public bool IgnoreOnArenaTournament;
}
private class SavingSettings {
[JsonProperty(PropertyName = "Enable saving player data during server saves?")]
public bool SavePlayersOnServerSave;
[JsonProperty(PropertyName = "Enable saving clan data during server save?")]
public bool SaveClansOnServerSave;
}
private class AvatarSettings {
[JsonProperty(PropertyName = "Default Avatar")]
public string DefaultAvatar;
[JsonProperty(PropertyName = "Can the clan owner change the avatar?")]
public bool CanOwner;
[JsonProperty(PropertyName = "Can the clan moderator change the avatar?")]
public bool CanModerator;
[JsonProperty(PropertyName = "Can the clan member change the avatar?")]
public bool CanMember;
[JsonProperty(PropertyName = "Permission to change clan avatar")]
public string PermissionToChange;
}
private class CommandsSettings {
[JsonProperty(PropertyName = "Clans FF", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] ClansFF;
[JsonProperty(PropertyName = "Aliance FF", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] AllyFF;
}
private class TagSettings {
[JsonProperty(PropertyName = "Blocked Words", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> BlockedWords;
[JsonProperty(PropertyName = "Minimum clan tag characters")]
public int TagMin;
[JsonProperty(PropertyName = "Maximum clan tag characters")]
public int TagMax;
[JsonProperty(PropertyName = "Enable character checking in tags?")]
public bool CheckingCharacters;
[JsonProperty(PropertyName = "Special characters allowed in tags")]
public string AllowedCharacters;
[JsonProperty(PropertyName = "Tag Color Settings")]
public TagColorSettings TagColor;
public class TagColorSettings {
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "DefaultColor")]
public string DefaultColor;
[JsonProperty(PropertyName = "Can the owner change the color?")]
public bool Owners;
[JsonProperty(PropertyName = "Can the moderators change the color?")]
public bool Moderators;
[JsonProperty(PropertyName = "Can the players change the color?")]
public bool Players;
}
}
private class ZoneManagerSettings {
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "Zones with allowed Friendly Fire", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> FFAllowlist;
}
private class ColorsSettings {
[JsonProperty(PropertyName = "Clan owner color (hex)")]
public string Owner;
[JsonProperty(PropertyName = "Clan moderator color (hex)")]
public string Moderator;
[JsonProperty(PropertyName = "Clan member color (hex)")]
public string Member;
}
private class PlayerDatabaseConf {
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "Table")]
public string Field;
public PlayerDatabaseConf(bool enabled, string field) {
Enabled = enabled;
Field = field;
}
}
private class StatisticsSettings {
[JsonProperty(PropertyName = "Kills")]
public bool Kills;
[JsonProperty(PropertyName = "Gather")]
public bool Gather;
[JsonProperty(PropertyName = "Loot")]
public bool Loot;
[JsonProperty(PropertyName = "Entities")]
public bool Entities;
[JsonProperty(PropertyName = "Craft")]
public bool Craft;
}
private class SkinsSettings {
[JsonProperty(PropertyName = "Item Skins", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, List<ulong>> ItemSkins;
[JsonProperty(PropertyName = "Use skins from SkinBox?")]
public bool UseSkinBox;
[JsonProperty(PropertyName = "Use skins from PlayerSkins?")]
public bool UsePlayerSkins;
[JsonProperty(PropertyName = "Use skins from LSkins?")]
public bool UseLSkins;
[JsonProperty(PropertyName = "Can players install custom skins?")]
public bool CanCustomSkin;
[JsonProperty(PropertyName = "Permission to install custom skin")]
public string Permission;
[JsonProperty(PropertyName = "Option to disable clan skins?")]
public bool DisableSkins;
[JsonProperty(PropertyName = "Default value to disable skins")]
public bool DefaultValueDisableSkins;
}
private class InterfaceSettings {
[JsonProperty(PropertyName = "Color One")]
public IColor Color1;
[JsonProperty(PropertyName = "Color Two")]
public IColor Color2;
[JsonProperty(PropertyName = "Color Three")]
public IColor Color3;
[JsonProperty(PropertyName = "Color Four")]
public IColor Color4;
[JsonProperty(PropertyName = "Color Five")]
public IColor Color5;
[JsonProperty(PropertyName = "Color Six")]
public IColor Color6;
[JsonProperty(PropertyName = "Color Seven")]
public IColor Color7;
[JsonProperty(PropertyName = "Color Eight")]
public IColor Color8;
[JsonProperty(PropertyName = "Use value abbreviation?")]
public bool ValueAbbreviation;
[JsonProperty(PropertyName = "Show the close button on the clan creation screen?")]
public bool ShowCloseOnClanCreation = true;
[JsonProperty(PropertyName = "Top Clans Columns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ColumnSettings> TopClansColumns;
[JsonProperty(PropertyName = "Top Players Columns", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ColumnSettings> TopPlayersColumns;
[JsonProperty(PropertyName = "Profile Buttons", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<BtnConf> ProfileButtons;
[JsonProperty(PropertyName = "Clan Member Profile Fields", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ColumnSettings> ClanMemberProfileFields;
[JsonProperty(PropertyName = "Top Player Profile Fields", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<ColumnSettings> TopPlayerProfileFields;
[JsonProperty(PropertyName = "Show the \"Change avatar\" button?")]
public bool ShowBtnChangeAvatar;
[JsonProperty(PropertyName = "Show the \"Leave\" button?")]
public bool ShowBtnLeave;
}
private abstract class InterfacePosition {
public string AnchorMin;
public string AnchorMax;
public string OffsetMin;
public string OffsetMax;
}
private class BtnConf : InterfacePosition {
[JsonProperty(PropertyName = "Enabled")]
public bool Enabled;
[JsonProperty(PropertyName = "Close Menu?")]
public bool CloseMenu;
[JsonProperty(PropertyName = "Command")]
public string Command;
[JsonProperty(PropertyName = "Color")]
public IColor Color;
[JsonProperty(PropertyName = "Title")]
public string Title;
[JsonProperty(PropertyName = "Font Size")]
public int FontSize;
[JsonProperty(PropertyName = "Font")]
public string Font;
[JsonProperty(PropertyName = "Align")]
[JsonConverter(typeof(StringEnumConverter))]
public TextAnchor Align;
[JsonProperty(PropertyName = "Text Color")]
public IColor TextColor;
private string GetCommand(ulong target) {
if (string.IsNullOrEmpty(Command)) return string.Empty;
return Command.Replace("{target}", target.ToString()).Replace("{targetName}", $"\"{BasePlayer.FindAwakeOrSleeping(target.ToString())?.Connection.username}\"");
}
public void Get(ref CuiElementContainer container, ulong target, string parent, string close) {
if (!Enabled) return;
container.Add(new CuiButton {
RectTransform = {
AnchorMin = AnchorMin ?? "0 0", AnchorMax = AnchorMax ?? "1 1", OffsetMin = OffsetMin ?? "0 0", OffsetMax = OffsetMax ?? "0 0"
}
, Text = {
Text = $"{Title}", Align = Align, Font = Font, FontSize = FontSize, Color = TextColor?.Get() ?? "1 1 1 1"
}
, Button = {
Command = $"clans.sendcmd {GetCommand(target)}", Color = Color?.Get() ?? "1 1 1 1", Close = CloseMenu ? close : string.Empty
}
}
, parent);
}
}
private class ColumnSettings {
[JsonProperty(PropertyName = "Width")]
public float Width;
[JsonProperty(PropertyName = "Lang Key")]
public string LangKey;
[JsonProperty(PropertyName = "Key")]
public string Key;
[JsonProperty(PropertyName = "Text Format")]
public string TextFormat;
[JsonProperty(PropertyName = "Text Align")]
[JsonConverter(typeof(StringEnumConverter))]
public TextAnchor TextAlign;
[JsonProperty(PropertyName = "Title Font Size")]
public int TitleFontSize;
[JsonProperty(PropertyName = "Font Size")]
public int FontSize;
public string GetFormat(int top, string values) {
switch (Key) {
case "top" : return string.Format(TextFormat, top);
default : return string.Format(TextFormat, values);
}
}
}
private class IColor {
[JsonProperty(PropertyName = "HEX")]
public string Hex;
[JsonProperty(PropertyName = "Opacity (0 - 100)")]
public float Alpha;
public string Get() {
if (string.IsNullOrEmpty(Hex)) Hex = "#FFFFFF";
var str = Hex.Trim('#');
if (str.Length != 6) throw new Exception(Hex);
var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
return $"{(double) r / 255} {(double) g / 255} {(double) b / 255} {Alpha / 100}";
}
public IColor(string hex, float alpha) {
Hex = hex;
Alpha = alpha;
}
}
private class PageSettings {
[JsonProperty(PropertyName = "ID (DON'T CHANGE)")]
public int ID;
[JsonProperty(PropertyName = "Key (DON'T CHANGE)")]
public string Key;
[JsonProperty(PropertyName = "Enabled?")]
public bool Enabled;
[JsonProperty(PropertyName = "Permission")]
public string Permission;
}
private class LimitSettings {
[JsonProperty(PropertyName = "Member Limit")]
public int MemberLimit;
[JsonProperty(PropertyName = "Moderator Limit")]
public int ModeratorLimit;
[JsonProperty(PropertyName = "Alliances Limit")]
public int AlliancesLimit;
}
private class PurgeSettings {
[JsonProperty(PropertyName = "Enable clan purging")]
public bool Enabled;
[JsonProperty(PropertyName = "Purge clans that havent been online for x amount of day")]
public int OlderThanDays;
[JsonProperty(PropertyName = "List purged clans in console when purging")]
public bool ListPurgedClans;
[JsonProperty(PropertyName = "Wipe clans on new map save")]
public bool WipeClansOnNewSave;
[JsonProperty(PropertyName = "Wipe players on new map save")]
public bool WipePlayersOnNewSave;
[JsonProperty(PropertyName = "Wipe invites on new map save")]
public bool WipeInvitesOnNewSave;
}
private class ChatSettings {
[JsonProperty(PropertyName = "Enable clan tags in chat?")]
public bool Enabled;
[JsonProperty(PropertyName = "Tag format")]
public string TagFormat;
[JsonProperty(PropertyName = "Enable clan chat?")]
public bool EnabledClanChat;
[JsonProperty(PropertyName = "Clan chat commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] ClanChatCommands;
[JsonProperty(PropertyName = "Enable alliance chat?")]
public bool EnabledAllianceChat;
[JsonProperty(PropertyName = "Alliance chat commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] AllianceChatCommands;
[JsonProperty(PropertyName = "Working with BatterChat?")]
public bool WorkingWithBetterChat;
[JsonProperty(PropertyName = "Working with in-game chat?")]
public bool WorkingWithInGameChat;
}
private class PermissionSettings {
[JsonProperty(PropertyName = "Use permission to create a clan")]
public bool UsePermClanCreating;
[JsonProperty(PropertyName = "Permission to create a clan")]
public string ClanCreating;
[JsonProperty(PropertyName = "Use permission to join a clan")]
public bool UsePermClanJoining;
[JsonProperty(PropertyName = "Permission to join a clan")]
public string ClanJoining;
[JsonProperty(PropertyName = "Use permission to kick a clan member")]
public bool UsePermClanKick;
[JsonProperty(PropertyName = "Clan kick permission")]
public string ClanKick;
[JsonProperty(PropertyName = "Use permission to leave a clan")]
public bool UsePermClanLeave;
[JsonProperty(PropertyName = "Clan leave permission")]
public string ClanLeave;
[JsonProperty(PropertyName = "Use permission to disband a clan")]
public bool UsePermClanDisband;
[JsonProperty(PropertyName = "Clan disband permission")]
public string ClanDisband;
[JsonProperty(PropertyName = "Use permission to clan skins")]
public bool UsePermClanSkins;
[JsonProperty(PropertyName = "Use clan skins permission")]
public string ClanSkins;
[JsonProperty(PropertyName = "Minimum auth level required to view clan info (0 = player, 1 = moderator, 2 = owner)")]
public int ClanInfoAuthLevel;
}
private class AllianceSettings {
[JsonProperty(PropertyName = "Enable clan alliances")]
public bool Enabled;
[JsonProperty(PropertyName = "Enable friendly fire (allied clans)")]
public bool UseFF;
[JsonProperty(PropertyName = "Default friendly fire value")]
public bool DefaultFF;
[JsonProperty(PropertyName = "General friendly fire (only the leader of the clan can enable/disable it)")]
public bool GeneralFriendlyFire;
[JsonProperty(PropertyName = "Can moderators toggle general friendly fire?")]
public bool ModersGeneralFF;
[JsonProperty(PropertyName = "Can players toggle general friendly fire?")]
public bool PlayersGeneralFF;
[JsonProperty(PropertyName = "Add players from the clan alliance to in-game teams?")]
public bool AllyAddPlayersTeams;
}
protected override void LoadConfig() {
base.LoadConfig();
try {
_config = Config.ReadObject<Configuration>();
if (_config == null) throw new Exception();
if (_config.Version < Version) UpdateConfigValues();
SaveConfig(
// ... [Code preview truncated due to length. Full source in attached file] ...