Иконка ресурса

FREE Imperium : 1.10.0 1.10.0

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
 // Reference: System.Drawing
/*
 * Copyright (C) 2017-2018 chucklenugget
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.*
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.*/
namespace Oxide.Plugins {
    using System;
    using System.IO;
    using Oxide.Core;
    using Oxide.Core.Configuration;
    using UnityEngine;
    using System.Collections.Generic;
    using System.Linq;
    [Info("Imperium", "chucklenugget", "1.10.0")]
    public partial class Imperium : RustPlugin {
        static Imperium Instance;
        bool Ready;
        DynamicConfigFile AreasFile;
        DynamicConfigFile FactionsFile;
        DynamicConfigFile PinsFile;
        DynamicConfigFile WarsFile;
        GameObject GameObject;
        ImperiumOptions Options;
        Timer UpkeepCollectionTimer;
        AreaManager Areas;
        FactionManager Factions;
        HudManager Hud;
        PinManager Pins;
        UserManager Users;
        WarManager Wars;
        ZoneManager Zones;
        void Init() {
            AreasFile = GetDataFile("areas");
            FactionsFile = GetDataFile("factions");
            PinsFile = GetDataFile("pins");
            WarsFile = GetDataFile("wars");
        }
        void Loaded() {
            InitLang();
            Permission.RegisterAll(this);
            try {
                Options = Config.ReadObject<ImperiumOptions>();
            }
            catch (Exception ex) {
                PrintError($"Error while loading configuration: {ex.ToString()}");
            }
            Puts("Area claims are " + (Options.Claims.Enabled ? "enabled" : "disabled"));
            Puts("Taxation is " + (Options.Taxes.Enabled ? "enabled" : "disabled"));
            Puts("Badlands are " + (Options.Badlands.Enabled ? "enabled" : "disabled"));
            Puts("Map pins are " + (Options.Map.PinsEnabled ? "enabled" : "disabled"));
            Puts("War is " + (Options.War.Enabled ? "enabled" : "disabled"));
            Puts("Decay reduction is " + (Options.Decay.Enabled ? "enabled" : "disabled"));
            Puts("Claim upkeep is " + (Options.Upkeep.Enabled ? "enabled" : "disabled"));
            Puts("Zones are " + (Options.Zones.Enabled ? "enabled" : "disabled"));
            // If the map has already been initialized, we can set up now; otherwise,
            // we need to wait until the savefile has been loaded.if (TerrainMeta.Size.x > 0) Setup();
        }
        object OnSaveLoad(Dictionary<BaseEntity, ProtoBuf.Entity> entities) {
            Setup();
            return null;
        }
        void Setup() {
            Instance = this;
            GameObject = new GameObject();
            Areas = new AreaManager();
            Factions = new FactionManager();
            Hud = new HudManager();
            Pins = new PinManager();
            Users = new UserManager();
            Wars = new WarManager();
            Zones = new ZoneManager();
            Factions.Init(TryLoad<FactionInfo>(FactionsFile));
            Areas.Init(TryLoad<AreaInfo>(AreasFile));
            Pins.Init(TryLoad<PinInfo>(PinsFile));
            Users.Init();
            Wars.Init(TryLoad<WarInfo>(WarsFile));
            Zones.Init();
            Hud.Init();
            Hud.GenerateMapOverlayImage();
            if (Options.Upkeep.Enabled) UpkeepCollectionTimer = timer.Every(Options.Upkeep.CheckIntervalMinutes * 60, Upkeep.CollectForAllFactions);
            PrintToChat($"{Title} v{Version} initialized.");
            Ready = true;
        }
        void Unload() {
            Hud.Destroy();
            Zones.Destroy();
            Users.Destroy();
            Wars.Destroy();
            Pins.Destroy();
            Areas.Destroy();
            Factions.Destroy();
            if (UpkeepCollectionTimer != null && !UpkeepCollectionTimer.Destroyed) UpkeepCollectionTimer.Destroy();
            if (GameObject != null) UnityEngine.Object.Destroy(GameObject);
            Instance = null;
        }
        void OnServerSave() {
            AreasFile.WriteObject(Areas.Serialize());
            FactionsFile.WriteObject(Factions.Serialize());
            PinsFile.WriteObject(Pins.Serialize());
            WarsFile.WriteObject(Wars.Serialize());
        }
        DynamicConfigFile GetDataFile(string name) {
            return Interface.Oxide.DataFileSystem.GetFile(Name + Path.DirectorySeparatorChar + name);
        }
        IEnumerable<T> TryLoad<T>(DynamicConfigFile file) {
            List<T> items;
            try {
                items = file.ReadObject<List<T>>();
            }
            catch (Exception ex) {
                PrintWarning($"Error reading data from {file.Filename}: ${ex.ToString()}");
                items = new List<T>();
            }
            return items;
        }
        void Log(string message, params object[] args) {
            LogToFile("log", String.Format(message, args), this, true);
        }
        bool EnsureUserCanChangeFactionClaims(User user, Faction faction) {
            if (faction == null || !faction.HasLeader(user)) {
                user.SendChatMessage(Messages.NotLeaderOfFaction);
                return false;
            }
            if (faction.MemberCount < Options.Claims.MinFactionMembers) {
                user.SendChatMessage(Messages.FactionTooSmallToOwnLand, Options.Claims.MinFactionMembers);
                return false;
            }
            return true;
        }
        bool EnsureFactionCanClaimArea(User user, Faction faction, Area area) {
            if (area.Type == AreaType.Badlands) {
                user.SendChatMessage(Messages.AreaIsBadlands, area.Id);
                return false;
            }
            if (faction.MemberCount < Instance.Options.Claims.MinFactionMembers) {
                user.SendChatMessage(Messages.FactionTooSmallToOwnLand, Instance.Options.Claims.MinFactionMembers);
                return false;
            }
            Area[] claimedAreas = Areas.GetAllClaimedByFaction(faction);
            if (Instance.Options.Claims.RequireContiguousClaims && !area.IsClaimed && claimedAreas.Length > 0) {
                int contiguousClaims = Areas.GetNumberOfContiguousClaimedAreas(area, faction);
                if (contiguousClaims == 0) {
                    user.SendChatMessage(Messages.AreaNotContiguous, area.Id, faction.Id);
                    return false;
                }
            }
            int? maxClaims = Instance.Options.Claims.MaxClaims;
            if (maxClaims != null && claimedAreas.Length >= maxClaims) {
                user.SendChatMessage(Messages.FactionOwnsTooMuchLand, faction.Id, maxClaims);
                return false;
            }
            return true;
        }
        bool EnsureCupboardCanBeUsedForClaim(User user, BuildingPrivlidge cupboard) {
            if (cupboard == null) {
                user.SendChatMessage(Messages.SelectingCupboardFailedInvalidTarget);
                return false;
            }
            if (!cupboard.IsAuthed(user.Player)) {
                user.SendChatMessage(Messages.SelectingCupboardFailedNotAuthorized);
                return false;
            }
            return true;
        }
        bool EnsureUserAndFactionCanEngageInDiplomacy(User user, Faction faction) {
            if (faction == null) {
                user.SendChatMessage(Messages.NotMemberOfFaction);
                return false;
            }
            if (faction.MemberCount < Options.Claims.MinFactionMembers) {
                user.SendChatMessage(Messages.FactionTooSmallToOwnLand);
                return false;
            }
            if (Areas.GetAllClaimedByFaction(faction).Length == 0) {
                user.SendChatMessage(Messages.FactionDoesNotOwnLand);
                return false;
            }
            return true;
        }
        bool EnforceCommandCooldown(User user, string command, int cooldownSeconds) {
            int secondsRemaining = user.GetSecondsLeftOnCooldown(command);
            if (secondsRemaining > 0) {
                user.SendChatMessage(Messages.CommandIsOnCooldown, secondsRemaining);
                return false;
            }
            user.SetCooldownExpiration(command, DateTime.UtcNow.AddSeconds(cooldownSeconds));
            return true;
        }
        bool TryCollectFromStacks(ItemDefinition itemDef, IEnumerable<Item> stacks, int amount) {
            if (stacks.Sum(item => item.amount) < amount) return false;
            int amountRemaining = amount;
            var dirtyContainers = new HashSet<ItemContainer>();
            foreach (Item stack in stacks) {
                var amountToTake = Math.Min(stack.amount, amountRemaining);
                stack.amount -= amountToTake;
                amountRemaining -= amountToTake;
                dirtyContainers.Add(stack.GetRootContainer());
                if (stack.amount == 0) stack.RemoveFromContainer();
                if (amountRemaining == 0) break;
            }
            foreach (ItemContainer container in dirtyContainers) container.MarkDirty();
            return true;
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        [ChatCommand("cancel")]
        void OnCancelCommand(BasePlayer player, string command, string[] args) {
            User user = Users.Get(player);
            if (user.CurrentInteraction == null) {
                user.SendChatMessage(Messages.NoInteractionInProgress);
                return;
            }
            user.SendChatMessage(Messages.InteractionCanceled);
            user.CancelInteraction();
        }
    }
}
namespace Oxide.Plugins {
    using System.Text;
    public partial class Imperium {
        [ChatCommand("help")]
        void OnHelpCommand(BasePlayer player, string command, string[] args) {
            User user = Users.Get(player);
            if (user == null) return;
            var sb = new StringBuilder();
            sb.AppendLine($"<size=18>Welcome to {ConVar.Server.hostname}!</size>");
            sb.AppendLine($"Powered by {Name} v{Version} by <color=#ffd479>chucklenugget</color>");
            sb.AppendLine();
            sb.Append("The following commands are available.To learn more about each command, do <color=#ffd479>/command help</color>.");
            sb.AppendLine("For example, to learn more about how to claim land, do <color=#ffd479>/claim help</color>.");
            sb.AppendLine();
            sb.AppendLine("<color=#ffd479>/faction</color> Create or join a faction");
            sb.AppendLine("<color=#ffd479>/claim</color> Claim areas of land");
            if (Options.Taxes.Enabled) sb.AppendLine("<color=#ffd479>/tax</color> Manage taxation of your land");
            if (Options.Map.PinsEnabled) sb.AppendLine("<color=#ffd479>/pin</color> Add pins (points of interest) to the map");
            if (Options.War.Enabled) sb.AppendLine("<color=#ffd479>/war</color> See active wars, declare war, or offer peace");
            if (Options.Badlands.Enabled) {
                if (user.HasPermission(Permission.AdminBadlands)) sb.AppendLine("<color=#ffd479>/badlands</color> Find or change badlands areas");
                else sb.AppendLine("<color=#ffd479>/badlands</color> Find badlands (PVP) areas");
            }
            user.SendChatMessage(sb);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        [ChatCommand("pvp")]
        void OnPvpCommand(BasePlayer player, string command, string[] args) {
            User user = Users.Get(player);
            if (!Options.Pvp.EnablePvpCommand) {
                user.SendChatMessage(Messages.PvpModeDisabled);
                return;
            }
            if (!EnforceCommandCooldown(user, "pvp", Options.Pvp.CommandCooldownSeconds)) return;
            if (user.IsInPvpMode) {
                user.IsInPvpMode = false;
                user.SendChatMessage(Messages.ExitedPvpMode);
            }
            else {
                user.IsInPvpMode = true;
                user.SendChatMessage(Messages.EnteredPvpMode);
            }
            user.Hud.Refresh();
        }
    }
}
namespace Oxide.Plugins {
    using System.Linq;
    public partial class Imperium {
        [ChatCommand("badlands")]
        void OnBadlandsCommand(BasePlayer player, string command, string[] args) {
            User user = Users.Get(player);
            if (user == null) return;
            if (!Options.Badlands.Enabled) {
                user.SendChatMessage(Messages.BadlandsDisabled);
                return;
            }
            if (args.Length == 0) {
                var areas = Areas.GetAllByType(AreaType.Badlands).Select(a => a.Id);
                user.SendChatMessage(Messages.BadlandsList, Util.Format(areas), Options.Taxes.BadlandsGatherBonus);
                return;
            }
            if (!user.HasPermission(Permission.AdminBadlands)) {
                user.SendChatMessage(Messages.NoPermission);
                return;
            }
            var areaIds = args.Skip(1).Select(arg => Util.NormalizeAreaId(arg)).ToArray();
            switch (args[0].ToLower()) {
                case "add" : if (args.Length < 2) user.SendChatMessage(Messages.Usage, "/badlands add [XY XY XY...]");
                else OnAddBadlandsCommand(user, areaIds);
                break;
                case "remove" : if (args.Length < 2) user.SendChatMessage(Messages.Usage, "/badlands remove [XY XY XY...]");
                else OnRemoveBadlandsCommand(user, areaIds);
                break;
                case "set" : if (args.Length < 2) user.SendChatMessage(Messages.Usage, "/badlands set [XY XY XY...]");
                else OnSetBadlandsCommand(user, areaIds);
                break;
                case "clear" : if (args.Length != 1) user.SendChatMessage(Messages.Usage, "/badlands clear");
                else OnSetBadlandsCommand(user, new string[0]);
                break;
                default : OnBadlandsHelpCommand(user);
                break;
            }
        }
    }
}
namespace Oxide.Plugins {
    using System.Collections.Generic;
    using System.Linq;
    public partial class Imperium {
        void OnAddBadlandsCommand(User user, string[] args) {
            var areas = new List<Area>();
            foreach (string arg in args) {
                Area area = Areas.Get(Util.NormalizeAreaId(arg));
                if (area == null) {
                    user.SendChatMessage(Messages.UnknownArea, arg);
                    return;
                }
                if (area.Type != AreaType.Wilderness) {
                    user.SendChatMessage(Messages.AreaNotWilderness, area.Id);
                    return;
                }
                areas.Add(area);
            }
            Areas.AddBadlands(areas);
            user.SendChatMessage(Messages.BadlandsSet, Util.Format(Areas.GetAllByType(AreaType.Badlands)));
            Log($"{Util.Format(user)} added {Util.Format(areas)} to badlands");
        }
    }
}
namespace Oxide.Plugins {
    using System.Text;
    public partial class Imperium {
        void OnBadlandsHelpCommand(User user) {
            var sb = new StringBuilder();
            sb.AppendLine("Available commands:");
            sb.AppendLine("  <color=#ffd479>/badlands add XY [XY XY...]</color>: Add area(s) to the badlands");
            sb.AppendLine("  <color=#ffd479>/badlands remove XY [XY XY...]</color>: Remove area(s) from the badlands");
            sb.AppendLine("  <color=#ffd479>/badlands set XY [XY XY...]</color>: Set the badlands to a list of areas");
            sb.AppendLine("  <color=#ffd479>/badlands clear</color>: Remove all areas from the badlands");
            sb.AppendLine("  <color=#ffd479>/badlands help</color>: Prints this message");
            user.SendChatMessage(sb);
        }
    }
}
namespace Oxide.Plugins {
    using System.Collections.Generic;
    using System.Linq;
    public partial class Imperium {
        void OnRemoveBadlandsCommand(User user, string[] args) {
            var areas = new List<Area>();
            foreach (string arg in args) {
                Area area = Areas.Get(Util.NormalizeAreaId(arg));
                if (area == null) {
                    user.SendChatMessage(Messages.UnknownArea, arg);
                    return;
                }
                if (area.Type != AreaType.Badlands) {
                    user.SendChatMessage(Messages.AreaNotBadlands, area.Id);
                    return;
                }
                areas.Add(area);
            }
            Areas.Unclaim(areas);
            user.SendChatMessage(Messages.BadlandsSet, Util.Format(Areas.GetAllByType(AreaType.Badlands)));
            Log($"{Util.Format(user)} removed {Util.Format(areas)} from badlands");
        }
    }
}
namespace Oxide.Plugins {
    using System.Collections.Generic;
    using System.Linq;
    public partial class Imperium {
        void OnSetBadlandsCommand(User user, string[] args) {
            var areas = new List<Area>();
            foreach (string arg in args) {
                Area area = Areas.Get(Util.NormalizeAreaId(arg));
                if (area == null) {
                    user.SendChatMessage(Messages.UnknownArea, arg);
                    return;
                }
                if (area.Type != AreaType.Wilderness) {
                    user.SendChatMessage(Messages.AreaNotWilderness, area.Id);
                    return;
                }
                areas.Add(area);
            }
            Areas.Unclaim(Areas.GetAllByType(AreaType.Badlands));
            Areas.AddBadlands(areas);
            user.SendChatMessage(Messages.BadlandsSet, Util.Format(Areas.GetAllByType(AreaType.Badlands)));
            Log($"{Util.Format(user)} set badlands to {Util.Format(areas)}");
        }
    }
}
namespace Oxide.Plugins {
    using System.Linq;
    public partial class Imperium {
        [ChatCommand("claim")]
        void OnClaimCommand(BasePlayer player, string command, string[] args) {
            User user = Users.Get(player);
            if (user == null) return;
            if (!Options.Claims.Enabled) {
                user.SendChatMessage(Messages.AreaClaimsDisabled);
                return;
            }
            if (args.Length == 0) {
                OnClaimAddCommand(user);
                return;
            }
            var restArguments = args.Skip(1).ToArray();
            switch (args[0].ToLower()) {
                case "add" : OnClaimAddCommand(user);
                break;
                case "remove" : OnClaimRemoveCommand(user);
                break;
                case "hq" : OnClaimHeadquartersCommand(user);
                break;
                case "rename" : OnClaimRenameCommand(user, restArguments);
                break;
                case "give" : OnClaimGiveCommand(user, restArguments);
                break;
                case "cost" : OnClaimCostCommand(user, restArguments);
                break;
                case "upkeep" : OnClaimUpkeepCommand(user);
                break;
                case "show" : OnClaimShowCommand(user, restArguments);
                break;
                case "list" : OnClaimListCommand(user, restArguments);
                break;
                case "assign" : OnClaimAssignCommand(user, restArguments);
                break;
                case "delete" : OnClaimDeleteCommand(user, restArguments);
                break;
                default : OnClaimHelpCommand(user);
                break;
            }
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnClaimAddCommand(User user) {
            Faction faction = Factions.GetByMember(user);
            if (!EnsureUserCanChangeFactionClaims(user, faction)) return;
            user.SendChatMessage(Messages.SelectClaimCupboardToAdd);
            user.BeginInteraction(new AddingClaimInteraction(faction));
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnClaimAssignCommand(User user, string[] args) {
            if (!user.HasPermission(Permission.AdminClaims)) {
                user.SendChatMessage(Messages.NoPermission);
                return;
            }
            if (args.Length == 0) {
                user.SendChatMessage(Messages.Usage, "/claim assign FACTION");
                return;
            }
            string factionId = Util.NormalizeFactionId(args[0]);
            Faction faction = Factions.Get(factionId);
            if (faction == null) {
                user.SendChatMessage(Messages.FactionDoesNotExist, factionId);
                return;
            }
            user.SendChatMessage(Messages.SelectClaimCupboardToAssign);
            user.BeginInteraction(new AssigningClaimInteraction(faction));
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnClaimCostCommand(User user, string[] args) {
            Faction faction = Factions.GetByMember(user);
            if (faction == null) {
                user.SendChatMessage(Messages.NotMemberOfFaction);
                return;
            }
            if (faction.MemberCount < Options.Claims.MinFactionMembers) {
                user.SendChatMessage(Messages.FactionTooSmallToOwnLand, Options.Claims.MinFactionMembers);
                return;
            }
            if (args.Length > 1) {
                user.SendChatMessage(Messages.Usage, "/claim cost [XY]");
                return;
            }
            Area area;
            if (args.Length == 0) area = user.CurrentArea;
            else area = Areas.Get(Util.NormalizeAreaId(args[0]));
            if (area == null) {
                user.SendChatMessage(Messages.Usage, "/claim cost [XY]");
                return;
            }
            if (area.Type == AreaType.Badlands) {
                user.SendChatMessage(Messages.AreaIsBadlands, area.Id);
                return;
            }
            else if (area.Type != AreaType.Wilderness) {
                user.SendChatMessage(Messages.CannotClaimAreaAlreadyClaimed, area.Id, area.FactionId);
                return;
            }
            int cost = area.GetClaimCost(faction);
            user.SendChatMessage(Messages.ClaimCost, area.Id, faction.Id, cost);
        }
    }
}
namespace Oxide.Plugins {
    using System.Collections.Generic;
    public partial class Imperium {
        void OnClaimDeleteCommand(User user, string[] args) {
            if (args.Length == 0) {
                user.SendChatMessage(Messages.Usage, "/claim delete XY [XY XY...]");
                return;
            }
            if (!user.HasPermission(Permission.AdminClaims)) {
                user.SendChatMessage(Messages.NoPermission);
                return;
            }
            var areas = new List<Area>();
            foreach (string arg in args) {
                Area area = Areas.Get(Util.NormalizeAreaId(arg));
                if (area.Type == AreaType.Badlands) {
                    user.SendChatMessage(Messages.AreaIsBadlands, area.Id);
                    return;
                }
                if (area.Type == AreaType.Wilderness) {
                    user.SendChatMessage(Messages.AreaIsWilderness, area.Id);
                    return;
                }
                areas.Add(area);
            }
            foreach (Area area in areas) {
                PrintToChat(Messages.AreaClaimDeletedAnnouncement, area.FactionId, area.Id);
                Log($"{Util.Format(user)} deleted {area.FactionId}'s claim on {area.Id}");
            }
            Areas.Unclaim(areas);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnClaimGiveCommand(User user, string[] args) {
            if (args.Length == 0) {
                user.SendChatMessage(Messages.Usage, "/claim give FACTION");
                return;
            }
            Faction sourceFaction = Factions.GetByMember(user);
            if (!EnsureUserCanChangeFactionClaims(user, sourceFaction)) return;
            string factionId = Util.NormalizeFactionId(args[0]);
            Faction targetFaction = Factions.Get(factionId);
            if (targetFaction == null) {
                user.SendChatMessage(Messages.FactionDoesNotExist, factionId);
                return;
            }
            user.SendChatMessage(Messages.SelectClaimCupboardToTransfer);
            user.BeginInteraction(new TransferringClaimInteraction(sourceFaction, targetFaction));
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnClaimHeadquartersCommand(User user) {
            Faction faction = Factions.GetByMember(user);
            if (!EnsureUserCanChangeFactionClaims(user, faction)) return;
            user.SendChatMessage(Messages.SelectClaimCupboardForHeadquarters);
            user.BeginInteraction(new SelectingHeadquartersInteraction(faction));
        }
    }
}
namespace Oxide.Plugins {
    using System.Text;
    public partial class Imperium {
        void OnClaimHelpCommand(User user) {
            var sb = new StringBuilder();
            sb.AppendLine("Available commands:");
            sb.AppendLine("  <color=#ffd479>/claim</color>: Add a claim for your faction");
            sb.AppendLine("  <color=#ffd479>/claim hq</color>: Select your faction's headquarters");
            sb.AppendLine("  <color=#ffd479>/claim remove</color>: Remove a claim for your faction (no undo!)");
            sb.AppendLine("  <color=#ffd479>/claim give FACTION</color>: Give a claimed area to another faction (no undo!)");
            sb.AppendLine("  <color=#ffd479>/claim rename XY \"NAME\"</color>: Rename an area claimed by your faction");
            sb.AppendLine("  <color=#ffd479>/claim show XY</color>: Show who owns an area");
            sb.AppendLine("  <color=#ffd479>/claim list FACTION</color>: List all areas claimed for a faction");
            sb.AppendLine("  <color=#ffd479>/claim cost [XY]</color>: Show the cost for your faction to claim an area");
            if (!Options.Upkeep.Enabled) sb.AppendLine("  <color=#ffd479>/claim upkeep</color>: Show information about upkeep costs for your faction");
            sb.AppendLine("  <color=#ffd479>/claim help</color>: Prints this message");
            if (user.HasPermission(Permission.AdminClaims)) {
                sb.AppendLine("Admin commands:");
                sb.AppendLine("  <color=#ffd479>/claim assign FACTION</color>: Use the hammer to assign a claim to another faction");
                sb.AppendLine("  <color=#ffd479>/claim delete XY [XY XY XY...]</color>: Remove the claim on the specified areas (no undo!)");
            }
            user.SendChatMessage(sb);
        }
    }
}
namespace Oxide.Plugins {
    using System;
    using System.Linq;
    using System.Text;
    public partial class Imperium {
        void OnClaimListCommand(User user, string[] args) {
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/claim list FACTION");
                return;
            }
            string factionId = Util.NormalizeFactionId(args[0]);
            Faction faction = Factions.Get(factionId);
            if (faction == null) {
                user.SendChatMessage(Messages.FactionDoesNotExist, factionId);
                return;
            }
            Area[] areas = Areas.GetAllClaimedByFaction(faction);
            Area headquarters = areas.FirstOrDefault(a => a.Type == AreaType.Headquarters);
            var sb = new StringBuilder();
            if (areas.Length == 0) {
                sb.AppendFormat(String.Format("<color=#ffd479>[{0}]</color> has no land holdings.", factionId));
            }
            else {
                float percentageOfMap = (areas.Length / (float)Areas.Count) * 100;
                sb.AppendLine(String.Format("<color=#ffd479>[{0}] owns {1} tiles ({2:F2}% of the known world)</color>", faction.Id, areas.Length, percentageOfMap));
                sb.AppendLine(String.Format("Headquarters: {0}", (headquarters == null) ? "Unknown" : headquarters.Id));
                sb.AppendLine(String.Format("Areas claimed: {0}", Util.Format(areas)));
            }
            user.SendChatMessage(sb);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnClaimRemoveCommand(User user) {
            Faction faction = Factions.GetByMember(user);
            if (!EnsureUserCanChangeFactionClaims(user, faction)) return;
            user.SendChatMessage(Messages.SelectClaimCupboardToRemove);
            user.BeginInteraction(new RemovingClaimInteraction(faction));
        }
    }
}
namespace Oxide.Plugins {
    using System;
    public partial class Imperium {
        void OnClaimRenameCommand(User user, string[] args) {
            Faction faction = Factions.GetByMember(user);
            if (!EnsureUserCanChangeFactionClaims(user, faction)) return;
            if (args.Length != 2) {
                user.SendChatMessage(Messages.Usage, "/claim rename XY \"NAME\"");
                return;
            }
            var areaId = Util.NormalizeAreaId(args[0]);
            var name = Util.NormalizeAreaName(args[1]);
            if (name == null || name.Length < Options.Claims.MinAreaNameLength || name.Length > Options.Claims.MaxAreaNameLength) {
                user.SendChatMessage(Messages.InvalidAreaName, Options.Claims.MinAreaNameLength, Options.Claims.MaxAreaNameLength);
                return;
            }
            Area area = Areas.Get(areaId);
            if (area == null) {
                user.SendChatMessage(Messages.UnknownArea, areaId);
                return;
            }
            if (area.FactionId != faction.Id) {
                user.SendChatMessage(Messages.AreaNotOwnedByYourFaction, area.Id);
                return;
            }
            user.SendChatMessage(Messages.AreaRenamed, area.Id, name);
            Log($"{Util.Format(user)} renamed {area.Id} to {name}");
            area.Name = name;
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnClaimShowCommand(User user, string[] args) {
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/claim show XY");
                return;
            }
            Area area = Areas.Get(Util.NormalizeAreaId(args[0]));
            switch (area.Type) {
                case AreaType.Badlands : user.SendChatMessage(Messages.AreaIsBadlands, area.Id);
                return;
                case AreaType.Claimed : user.SendChatMessage(Messages.AreaIsClaimed, area.Id, area.FactionId);
                return;
                case AreaType.Headquarters : user.SendChatMessage(Messages.AreaIsHeadquarters, area.Id, area.FactionId);
                return;
                default : user.SendChatMessage(Messages.AreaIsWilderness, area.Id);
                return;
            }
        }
    }
}
namespace Oxide.Plugins {
    using System;
    public partial class Imperium {
        void OnClaimUpkeepCommand(User user) {
            if (!Options.Upkeep.Enabled) {
                user.SendChatMessage(Messages.UpkeepDisabled);
                return;
            }
            Faction faction = Factions.GetByMember(user);
            if (faction == null) {
                user.SendChatMessage(Messages.NotMemberOfFaction);
                return;
            }
            if (faction.MemberCount < Options.Claims.MinFactionMembers) {
                user.SendChatMessage(Messages.FactionTooSmallToOwnLand, Options.Claims.MinFactionMembers);
                return;
            }
            Area[] areas = Areas.GetAllClaimedByFaction(faction);
            if (areas.Length == 0) {
                user.SendChatMessage(Messages.NoAreasClaimed);
                return;
            }
            int upkeep = faction.GetUpkeepPerPeriod();
            var nextPaymentHours = (int)faction.NextUpkeepPaymentTime.Subtract(DateTime.UtcNow).TotalHours;
            if (nextPaymentHours > 0) user.SendChatMessage(Messages.UpkeepCost, upkeep, areas.Length, faction.Id, nextPaymentHours);
            else user.SendChatMessage(Messages.UpkeepCostOverdue, upkeep, areas.Length, faction.Id, nextPaymentHours);
        }
    }
}
namespace Oxide.Plugins {
    using System.Linq;
    public partial class Imperium {
        [ChatCommand("faction")]
        void OnFactionCommand(BasePlayer player, string command, string[] args) {
            User user = Users.Get(player);
            if (user == null) return;
            if (args.Length == 0) {
                OnFactionShowCommand(user);
                return;
            }
            var restArguments = args.Skip(1).ToArray();
            switch (args[0].ToLower()) {
                case "create" : OnFactionCreateCommand(user, restArguments);
                break;
                case "join" : OnFactionJoinCommand(user, restArguments);
                break;
                case "leave" : OnFactionLeaveCommand(user, restArguments);
                break;
                case "invite" : OnFactionInviteCommand(user, restArguments);
                break;
                case "kick" : OnFactionKickCommand(user, restArguments);
                break;
                case "promote" : OnFactionPromoteCommand(user, restArguments);
                break;
                case "demote" : OnFactionDemoteCommand(user, restArguments);
                break;
                case "disband" : OnFactionDisbandCommand(user, restArguments);
                break;
                case "help" : default : OnFactionHelpCommand(user);
                break;
            }
        }
        [ChatCommand("clan")]
        void OnClanCommand(BasePlayer player, string command, string[] args) {
            OnFactionCommand(player, command, args);
        }
    }
}
namespace Oxide.Plugins {
    using System;
    public partial class Imperium {
        [ChatCommand("f")]
        void OnFactionChatCommand(BasePlayer player, string command, string[] args) {
            User user = Users.Get(player);
            if (user == null) return;
            string message = String.Join(" ", args).Trim();
            if (message.Length == 0) {
                user.SendChatMessage(Messages.Usage, "/f MESSAGE...");
                return;
            }
            Faction faction = Factions.GetByMember(user);
            if (faction == null) {
                user.SendChatMessage(Messages.NotMemberOfFaction);
                return;
            }
            faction.SendChatMessage("<color=#a1ff46>(FACTION)</color> {0}: {1}", user.UserName, message);
            Puts("[FACTION] {0} - {1}: {2}", faction.Id, user.UserName, message);
        }
        [ChatCommand("c")]
        void OnClanChatCommand(BasePlayer player, string command, string[] args) {
            OnFactionChatCommand(player, command, args);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionCreateCommand(User user, string[] args) {
            if (!user.HasPermission(Permission.ManageFactions)) {
                user.SendChatMessage(Messages.NoPermission);
                return;
            }
            if (user.Faction != null) {
                user.SendChatMessage(Messages.AlreadyMemberOfFaction);
                return;
            }
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/faction create NAME");
                return;
            }
            string id = Util.RemoveSpecialCharacters(args[0].Replace(" ", ""));
            if (id.Length < Options.Factions.MinFactionNameLength || id.Length > Options.Factions.MaxFactionNameLength) {
                user.SendChatMessage(Messages.InvalidFactionName, Options.Factions.MinFactionNameLength, Options.Factions.MaxFactionNameLength);
                return;
            }
            if (Factions.Exists(id)) {
                user.SendChatMessage(Messages.FactionAlreadyExists, id);
                return;
            }
            PrintToChat(Messages.FactionCreatedAnnouncement, id);
            Log($"{Util.Format(user)} created faction {id}");
            Faction faction = Factions.Create(id, user);
            user.SetFaction(faction);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionDemoteCommand(User user, string[] args) {
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/faction demote \"PLAYER\"");
                return;
            }
            Faction faction = Factions.GetByMember(user);
            if (faction == null || !faction.HasLeader(user)) {
                user.SendChatMessage(Messages.NotLeaderOfFaction);
                return;
            }
            User member = Users.Find(args[0]);
            if (member == null) {
                user.SendChatMessage(Messages.InvalidUser, args[0]);
                return;
            }
            if (!faction.HasMember(member)) {
                user.SendChatMessage(Messages.UserIsNotMemberOfFaction, member.UserName, faction.Id);
                return;
            }
            if (faction.HasOwner(member)) {
                user.SendChatMessage(Messages.CannotPromoteOrDemoteOwnerOfFaction, member.UserName, faction.Id);
                return;
            }
            if (!faction.HasManager(member)) {
                user.SendChatMessage(Messages.UserIsNotManagerOfFaction, member.UserName, faction.Id);
                return;
            }
            user.SendChatMessage(Messages.ManagerRemoved, member.UserName, faction.Id);
            Log($"{Util.Format(user)} demoted {Util.Format(member)} in faction {faction.Id}");
            faction.Demote(member);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionDisbandCommand(User user, string[] args) {
            if (args.Length != 1 || args[0].ToLowerInvariant() != "forever") {
                user.SendChatMessage(Messages.Usage, "/faction disband forever");
                return;
            }
            Faction faction = user.Faction;
            if (faction == null || !faction.HasLeader(user)) {
                user.SendChatMessage(Messages.NotLeaderOfFaction);
                return;
            }
            PrintToChat(Messages.FactionDisbandedAnnouncement, faction.Id);
            Log($"{Util.Format(user)} disbanded faction {faction.Id}");
            Factions.Disband(faction);
        }
    }
}
namespace Oxide.Plugins {
    using System.Text;
    public partial class Imperium {
        void OnFactionHelpCommand(User user) {
            var sb = new StringBuilder();
            sb.AppendLine("Available commands:");
            sb.AppendLine("  <color=#ffd479>/faction</color>: Show information about your faction");
            sb.AppendLine("  <color=#ffd479>/f MESSAGE...</color>: Send a message to all online members of your faction");
            if (user.HasPermission(Permission.ManageFactions)) sb.AppendLine("  <color=#ffd479>/faction create</color>: Create a new faction");
            sb.AppendLine("  <color=#ffd479>/faction join FACTION</color>: Join a faction if you have been invited");
            sb.AppendLine("  <color=#ffd479>/faction leave</color>: Leave your current faction");
            sb.AppendLine("  <color=#ffd479>/faction invite \"PLAYER\"</color>: Invite another player to join your faction");
            sb.AppendLine("  <color=#ffd479>/faction kick \"PLAYER\"</color>: Kick a player out of your faction");
            sb.AppendLine("  <color=#ffd479>/faction promote \"PLAYER\"</color>: Promote a faction member to manager");
            sb.AppendLine("  <color=#ffd479>/faction demote \"PLAYER\"</color>: Remove a faction member as manager");
            sb.AppendLine("  <color=#ffd479>/faction disband forever</color>: Disband your faction immediately (no undo!)");
            sb.AppendLine("  <color=#ffd479>/faction help</color>: Prints this message");
            user.SendChatMessage(sb);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionInviteCommand(User user, string[] args) {
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/faction invite \"PLAYER\"");
                return;
            }
            Faction faction = Factions.GetByMember(user);
            if (faction == null || !faction.HasLeader(user)) {
                user.SendChatMessage(Messages.NotLeaderOfFaction);
                return;
            }
            User member = Users.Find(args[0]);
            if (member == null) {
                user.SendChatMessage(Messages.InvalidUser, args[0]);
                return;
            }
            if (faction.HasMember(member)) {
                user.SendChatMessage(Messages.UserIsAlreadyMemberOfFaction, member.UserName, faction.Id);
                return;
            }
            int? maxMembers = Options.Factions.MaxMembers;
            if (maxMembers != null && faction.MemberCount >= maxMembers) {
                user.SendChatMessage(Messages.FactionHasTooManyMembers, faction.Id, faction.MemberCount);
                return;
            }
            member.SendChatMessage(Messages.InviteReceived, user.UserName, faction.Id);
            user.SendChatMessage(Messages.InviteAdded, member.UserName, faction.Id);
            Log($"{Util.Format(user)} invited {Util.Format(member)} to faction {faction.Id}");
            faction.AddInvite(member);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionJoinCommand(User user, string[] args) {
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/faction join FACTION");
                return;
            }
            if (user.Faction != null) {
                user.SendChatMessage(Messages.AlreadyMemberOfFaction);
                return;
            }
            Faction faction = Factions.Get(args[0]);
            if (faction == null) {
                user.SendChatMessage(Messages.FactionDoesNotExist, args[0]);
                return;
            }
            if (!faction.HasInvite(user)) {
                user.SendChatMessage(Messages.CannotJoinFactionNotInvited, faction.Id);
                return;
            }
            user.SendChatMessage(Messages.YouJoinedFaction, faction.Id);
            PrintToChat(Messages.FactionMemberJoinedAnnouncement, user.UserName, faction.Id);
            Log($"{Util.Format(user)} joined faction {faction.Id}");
            faction.AddMember(user);
            user.SetFaction(faction);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionKickCommand(User user, string[] args) {
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/faction kick \"PLAYER\"");
                return;
            }
            Faction faction = user.Faction;
            if (faction == null || !faction.HasLeader(user)) {
                user.SendChatMessage(Messages.NotLeaderOfFaction);
                return;
            }
            User member = Users.Find(args[0]);
            if (member == null) {
                user.SendChatMessage(Messages.InvalidUser, args[0]);
                return;
            }
            if (!faction.HasMember(member)) {
                user.SendChatMessage(Messages.UserIsNotMemberOfFaction, member.UserName, faction.Id);
                return;
            }
            if (faction.HasLeader(member)) {
                user.SendChatMessage(Messages.CannotKickLeaderOfFaction, member.UserName, faction.Id);
                return;
            }
            user.SendChatMessage(Messages.MemberRemoved, member.UserName, faction.Id);
            PrintToChat(Messages.FactionMemberLeftAnnouncement, member.UserName, faction.Id);
            Log($"{Util.Format(user)} kicked {Util.Format(member)} from faction {faction.Id}");
            faction.RemoveMember(member);
            member.SetFaction(null);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionLeaveCommand(User user, string[] args) {
            if (args.Length != 0) {
                user.SendChatMessage(Messages.Usage, "/faction leave");
                return;
            }
            Faction faction = user.Faction;
            if (faction == null) {
                user.SendChatMessage(Messages.NotMemberOfFaction);
                return;
            }
            if (faction.MemberCount == 1) {
                PrintToChat(Messages.FactionDisbandedAnnouncement, faction.Id);
                Log($"{Util.Format(user)} disbanded faction {faction.Id} by leaving as its only member");
                Factions.Disband(faction);
                return;
            }
            user.SendChatMessage(Messages.YouLeftFaction, faction.Id);
            PrintToChat(Messages.FactionMemberLeftAnnouncement, user.UserName, faction.Id);
            Log($"{Util.Format(user)} left faction {faction.Id}");
            faction.RemoveMember(user);
            user.SetFaction(null);
        }
    }
}
namespace Oxide.Plugins {
    public partial class Imperium {
        void OnFactionPromoteCommand(User user, string[] args) {
            if (args.Length != 1) {
                user.SendChatMessage(Messages.Usage, "/faction promote \"PLAYER\"");
                return;
            }
            Faction faction = Factions.GetByMember(user);
            if (faction == null || !faction.HasLeader(user)) {
                user.SendChatMessage(Messages.NotLeaderOfFaction);
                return;
            }
            User member = Users.Find(args[0]);
            if (member == null) {
                user.SendChatMessage(Messages.InvalidUser, args[0]);
                ret
// ... [Code preview truncated due to length. Full source in attached file] ...

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху