C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using Facepunch;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Configuration;
using Oxide.Game.Rust.Cui;
using Rust;
using UnityEngine;
using Newtonsoft.Json;
namespace Oxide.Plugins {
[Info("TiersMode", "ninco90", "1.2.4")]
[Description("Tiers game mode.")]
public class TiersMode : RustPlugin {
[PluginReference]
Plugin ImageLibrary, DiscordMessages;
#region Fields
private DynamicConfigFile _pluginData;
private TiersData _Data;
private bool _PluginReady = false;
private float minNextTier = 100.0f;
private float timerInterval = 10.0f;
private DateTime wipeTime;
private Timer cuiTimer;
private static CuiElementContainer containerTime;
private float refreshTime = 10.0f;
private bool counterEnabled = true;
private bool screenCounterIcon = true;
private bool screenCounterButton = true;
private int tierCurrent = 0;
private int tiercountAll = 0;
private string tierName = null;
private string tierColor = null;
private string tierIcon = null;
private bool enabledMaxCUP = false;
private bool enabledAlertDestrTC = false;
private bool alertDestrName = true;
private bool alertDestrPos = true;
private int limitCupboard = 0;
private bool useWorkbench = true;
private bool allPlaceWorkbench = true;
private bool cargoEvent = true;
private bool oilEvent = true;
private bool ch47Event = true;
private bool heliEvent = true;
private bool supplyEvent = true;
private bool bradleyEvent = true;
private bool sellersHeli = true;
private bool sellersBoat = true;
private bool sellersHorse = true;
private bool sellersDrones = true;
private bool enabledMLRS = false;
private bool enabledWORKCART = true;
private bool enabledTRAIN = true;
private bool sellersVending = true;
private bool blockCraft = true;
private bool blockDeployables = false;
private int maxUpgrade = 0;
private float craftingDuration = 1.0f;
private float researchDuration = 10.0f;
private float recyclerDuration = 5.0f;
private bool gatherEnabled = false;
private float multResource = 0.0f;
private float multResourceBonus = 0.0f;
private float multPickup = 0.0f;
private float multGrowable = 0.0f;
private float multSurvey = 0.0f;
private float multQuarry = 0.0f;
private float multExcavator = 0.0f;
private List<string> listWorkbench = new List<string>();
private List<string> listCards = new List<string>();
private List<string> listVehicles = new List<string>();
private List<string> blackItems = new List<string>();
private Dictionary<string, string> blackItemsBuilding = new Dictionary<string, string>();
private List<string> listCommand = new List<string>();
private const string commandOpenInfo = "tier.open";
private const string commandInfoClose = "open.close";
private const string commandSelect = "tier.select";
private const string commandEditClose = "edit.close";
private const string commandClearList = "edit.clear_list";
private const string commandClearItem = "edit.clear_iteam";
private const string commandCopy = "edit.copy";
private const string commandTierEditPage = "edit.page";
private const string commandTierInfoPage = "info.page";
private const string commandItemInfo = "info.item";
private const string commandItemInfoClose = "info.item.close";
private const string permissionAdmin = "tiersmode.admin";
private const string permByPassUseWorkcart = "tiersmode.bypass.use_workcart";
private const string permByPassUseLocomotive = "tiersmode.bypass.use_locomotive";
private const string permByPassUseMLRS = "tiersmode.bypass.use_mlrs";
private const string permByPassLimitCupboard = "tiersmode.bypass.limit_cupboard";
private const string permByPassBlockItems = "tiersmode.bypass.block_items";
private const string permByPassBlockPlaceNoBuilding = "tiersmode.bypass.block_place_no_building";
private const string permByPassPlaceAllWorkbench = "tiersmode.bypass.block_place_all_workbench";
private const string permByPassBlockResearch = "tiersmode.bypass.block_research";
private const string permByPassBlockHelis = "tiersmode.bypass.block_vending_helis";
private const string permByPassBlockBoat = "tiersmode.bypass.block_vending_boat";
private const string permByPassBlockHorses = "tiersmode.bypass.block_vending_horses";
private const string permByPassInstantResearch = "tiersmode.instant_research";
private const string permByPassInstantRecycler = "tiersmode.instant_recycler";
private const string permByPassAlertsBlock = "tiersmode.alerts.block";
private const string permByPassUpgrade = "tiersmode.bypass.upgrade";
public string prefabMarketplace = "assets/prefabs/misc/marketplace/marketplace.prefab";
//GUI
private Dictionary<int, Dictionary<string, List<SectionInfo>>> itemType = new Dictionary<int, Dictionary<string, List<SectionInfo>>>();
private class SectionInfo {
public string img {
get;
set;
}
public string title {
get;
set;
}
public string text {
get;
set;
}
}
private const string elemq0 = "gui.modal";
private const string elemq1 = "gui.count";
private const string elemq2 = "gui.count_time";
private const string elemq3 = "gui.edit";
private const string elemq4 = "gui.edit_item";
private const string elemq5 = "gui.open";
private const string elemq6 = "gui.open_item";
private const string elemq7 = "gui.modal_changue";
private const string elemq8 = "gui.modal_events";
private const string elemq9 = "gui.open_info_item";
private const string elemq10 = "gui.open_info_subitem";
#endregion
#region Hooks
private void Init() {
_pluginData = Interface.Oxide.DataFileSystem.GetFile(nameof(TiersMode));
cmd.AddConsoleCommand(commandSelect, this, nameof(cmdSelectTier));
cmd.AddConsoleCommand(commandEditClose, this, nameof(cmdCloseEdit));
cmd.AddConsoleCommand(commandClearList, this, nameof(cmdClearList));
cmd.AddConsoleCommand(commandClearItem, this, nameof(cmdClearItem));
cmd.AddConsoleCommand(commandCopy, this, nameof(cmdCopy));
cmd.AddConsoleCommand(commandTierEditPage, this, nameof(cmdTierEditPage));
cmd.AddConsoleCommand(commandOpenInfo, this, nameof(cmdOpenInfo));
cmd.AddConsoleCommand(commandInfoClose, this, nameof(cmdCloseInfo));
cmd.AddConsoleCommand(commandTierInfoPage, this, nameof(cmdTierInfoPage));
cmd.AddConsoleCommand(commandItemInfo, this, nameof(cmdItemInfo));
cmd.AddConsoleCommand(commandItemInfoClose, this, nameof(cmdCloseItemInfo));
cmd.AddConsoleCommand("tier.edit", this, nameof(cmdEditTier));
permission.RegisterPermission(permissionAdmin, this);
permission.RegisterPermission(permByPassAlertsBlock, this);
permission.RegisterPermission(permByPassBlockBoat, this);
permission.RegisterPermission(permByPassBlockHelis, this);
permission.RegisterPermission(permByPassBlockHorses, this);
permission.RegisterPermission(permByPassBlockItems, this);
permission.RegisterPermission(permByPassBlockPlaceNoBuilding, this);
permission.RegisterPermission(permByPassBlockResearch, this);
permission.RegisterPermission(permByPassInstantRecycler, this);
permission.RegisterPermission(permByPassInstantResearch, this);
permission.RegisterPermission(permByPassLimitCupboard, this);
permission.RegisterPermission(permByPassPlaceAllWorkbench, this);
permission.RegisterPermission(permByPassUseLocomotive, this);
permission.RegisterPermission(permByPassUseMLRS, this);
permission.RegisterPermission(permByPassUseWorkcart, this);
permission.RegisterPermission(permByPassUpgrade, this);
LoadData();
}
private void OnServerInitialized() {
if (ImageLibrary == null) {
PrintWarning("The ImageLibrary plugin is not installed, I can't work without it.Load ImageLibrary and then load me again.");
Interface.Oxide.RootPluginManager.RemovePlugin(this);
return;
}
LoadImages();
SaveDefaultDurationCraft();
wipeTime = SaveRestore.SaveCreatedTime;
if (_Data.activeTier == 999) {
tierCurrent = 0;
NotifyInit();
}
else {
tierCurrent = _Data.activeTier;
}
SelectTier(_Data.activeTier, tierCurrent);
InfoData();
PluginReady();
}
private void OnServerSave() {
SaveData();
}
private void OnNewSave() {
ClearData();
}
private void Unload() {
SaveData();
foreach (var player in BasePlayer.activePlayerList) {
CuiHelper.DestroyUi(player, elemq0);
CuiHelper.DestroyUi(player, elemq1);
CuiHelper.DestroyUi(player, elemq5);
CuiHelper.DestroyUi(player, elemq7);
CuiHelper.DestroyUi(player, elemq8);
CuiHelper.DestroyUi(player, elemq9);
}
}
private void OnPlayerConnected(BasePlayer player) {
if (config.GUI.screenCounter && counterEnabled) {
Countdown(player);
if(containerTime != null) CuiHelper.AddUi(player, containerTime);
}
if (config.MSG.chatEnabled && config.MSG.chatWelcomeEnabled) PrintToChat(player, Languaje("WelcomeChat", null, player.displayName, tierName));
if (config.GUI.WINDOWS.showWindowsEnter) OpenPanel(player, tierCurrent, 0);
}
private bool? CanBuild(Planner planner, Construction prefab, Construction.Target target) {
BasePlayer player = planner.GetOwnerPlayer();
if (player == null) return null;
if (prefab.deployable == null) return null;
var fullname = prefab.deployable.fullName;
if (fullname.Contains("cupboard.tool") && enabledMaxCUP) {
if(HasPermission(player.UserIDString, permByPassLimitCupboard)) return null;
var cupCount = 0;
_Data.armariosCount.TryGetValue(player.userID, out cupCount);
if (cupCount > (limitCupboard-1)) {
Notify(player, "red", "cupboard.tool", Languaje("BuildBlock", player.UserIDString), Languaje("MaxLimitCup", player.UserIDString, cupCount + "/" + limitCupboard), "Hud");
return false;
}
else {
_Data.armariosCount[player.userID] = cupCount + 1;
return null;
}
}
if (fullname.Contains("workbench") && !allPlaceWorkbench) {
if(HasPermission(player.UserIDString, permByPassPlaceAllWorkbench)) return null;
if (listWorkbench.Contains(fullname)) {
return null;
}
else {
var workbench = "workbench3";
var level = "3";
if (fullname.Contains("1")) {
workbench = "workbench1";
level = "1";
}
else if (fullname.Contains("2")) {
workbench = "workbench2";
level = "2";
}
Notify(player, "red", workbench, Languaje("BuildBlock", player.UserIDString), Languaje("NoPlaceWorkbench", player.UserIDString, level), "Hud");
return false;
}
}
if (blackItemsBuilding.ContainsValue(fullname) && blockDeployables && !HasPermission(player.UserIDString, permByPassBlockPlaceNoBuilding)) {
var myKey = blackItemsBuilding.FirstOrDefault(x => x.Value == fullname).Key;
BuildingPrivlidge priv = player.GetBuildingPrivilege();
if (priv == null) {
Notify(player, "red", myKey, Languaje("BuildBlock", player.UserIDString), Languaje("NoBuilding", player.UserIDString), "Hud");
return false;
}
if (priv.IsAuthed(player)) return null;
Notify(player, "red", myKey, Languaje("BuildBlock", player.UserIDString), Languaje("NoBuilding", player.UserIDString), "Hud");
return false;
}
return null;
}
private void OnEntitySpawned(BaseEntity entity) {
//Puts("NAME " + entity.ShortPrefabName);
if(_PluginReady) {
if (entity.ShortPrefabName.Contains("codelockedhackablecrate_oilrig")) {
if (!oilEvent) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
else {
NotifyEvents("blue", "hackable", Languaje("ServerEvents", null), Languaje("Event_HackableCrate", null));
}
}
if (entity.ShortPrefabName.Contains("ch47scientists")) {
if (!ch47Event) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
else {
NotifyEvents("blue", "ch47", Languaje("ServerEvents", null), Languaje("Event_CH47", null));
}
}
if (entity.ShortPrefabName.Contains("patrolhelicopter")) {
if (!heliEvent) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
else {
NotifyEvents("blue", "patrol", Languaje("ServerEvents", null), Languaje("Event_PatrolHelicopter", null));
}
}
if (entity.ShortPrefabName.Contains("cargo_plane")) {
if (!supplyEvent) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
else {
NotifyEvents("blue", "airdrop", Languaje("ServerEvents", null), Languaje("Event_Airdrop", null));
}
}
if (entity.ShortPrefabName.Contains("cargoshiptest")) {
if (!supplyEvent) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
else {
NotifyEvents("blue", "cargoship", Languaje("ServerEvents", null), Languaje("Event_Cargoship", null));
}
}
if (entity.ShortPrefabName.Contains("bradleyapc")) {
if (!supplyEvent) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
else {
NotifyEvents("blue", "bradley", Languaje("ServerEvents", null), Languaje("Event_Bradley", null));
}
}
if (entity.ShortPrefabName.Contains("keycard") && entity.ShortPrefabName.Contains("_pickup.entity")) {
if (!listCards.Contains(entity.ShortPrefabName)) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
}
if (entity.ShortPrefabName.Contains("module_car_spawned")) {
if (!listVehicles.Contains(entity.ShortPrefabName)) {
NextTick(() => {
if (entity != null) entity.Kill();
}
);
}
}
if (entity.ShortPrefabName.Contains("workbench") && !allPlaceWorkbench) {
//Puts(entity.ShortPrefabName);
bool destroy = true;
if (entity.ShortPrefabName == "workbench1.deployed") {
if (listWorkbench.Contains("assets/prefabs/deployable/tier 1 workbench/workbench1.deployed.prefab")) destroy = false;
}
else if (entity.ShortPrefabName == "workbench2.deployed") {
if (listWorkbench.Contains("assets/prefabs/deployable/tier 2 workbench/workbench2.deployed.prefab")) destroy = false;
}
else if (entity.ShortPrefabName == "workbench3.deployed") {
if (listWorkbench.Contains("assets/prefabs/deployable/tier 3 workbench/workbench3.deployed.prefab")) destroy = false;
}
NextTick(() => {
if (entity != null && destroy) entity.Kill();
}
);
}
}
}
private void OnEntityKill(BaseNetworkable entity) {
if (entity != null) {
if (entity.ShortPrefabName.Contains("cupboard.tool")) {
BaseEntity cup = (BaseEntity)(entity as BaseEntity);
if (!cup) return;
var cupCount = 0;
_Data.armariosCount.TryGetValue(cup.OwnerID, out cupCount);
if (cupCount != 0) _Data.armariosCount[cup.OwnerID] = cupCount - 1;
}
}
}
private void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) {
if (entity != null) {
if (entity.ShortPrefabName.Contains("cupboard.tool") && enabledAlertDestrTC) {
if (hitInfo == null || hitInfo.Initiator == null) return;
BasePlayer playerDestroyer = hitInfo?.Initiator as BasePlayer;
if (entity.OwnerID == playerDestroyer.userID) return;
RelationshipManager.PlayerTeam team = RelationshipManager.ServerInstance.FindTeam(playerDestroyer.currentTeam);
if (team != null) {
foreach (ulong memberID in team.members) {
if(memberID == entity.OwnerID) return;
}
}
var message = Languaje("CupboardDestInfo", null);
if (alertDestrName) {
message = Languaje("CupboardDestInfoPlayer", null, playerDestroyer.displayName);
}
if (alertDestrPos) {
message = Languaje("CupboardDestInfoPos", null, GridPos(entity.transform.position));
}
if (alertDestrName && alertDestrPos) {
message = Languaje("CupboardDestInfoPosPlayer", null, GridPos(entity.transform.position), playerDestroyer.displayName);
}
SendAlert(Languaje("CupboardDestroyed", null), message, "#BF2E11", "cupboard.tool", true);
}
}
}
private bool? CanUnlockTechTreeNode(BasePlayer player, TechTreeData.NodeInstance node, TechTreeData techTree) {
if (useWorkbench || HasPermission(player.UserIDString, permByPassBlockResearch)) {
return null;
}
else {
Notify(player, "red", "researchpaper", Languaje("ResearchBlock", player.UserIDString), Languaje("NoResearchWorkbench", player.UserIDString));
return false;
}
}
private bool? CanUnlockTechTreeNodePath(BasePlayer player, TechTreeData.NodeInstance node, TechTreeData techTree) {
if (useWorkbench || HasPermission(player.UserIDString, permByPassBlockResearch)) {
return null;
}
else {
return false;
}
}
private bool? CanUseVending(BasePlayer player, VendingMachine machine) {
if (!sellersVending) {
if(machine.GetComponent<NPCVendingMachine>()) {
if(machine.shopName == "Stables Shopkeeper" && sellersBoat) return true;
if(machine.shopName == "Boat Vendor" && sellersHorse) return true;
Notify(player, "red", "vending.machine", Languaje("BlockVending", player.UserIDString), Languaje("VendingBlock", player.UserIDString));
}
}
return true;
}
private bool? OnNpcConversationStart(VehicleVendor vendor, BasePlayer player, ConversationData conversationData) {
if (conversationData.shortname == "airwolf_heli_vendor" && !sellersHeli && !HasPermission(player.UserIDString, permByPassBlockHelis)) {
Notify(player, "red", "scrapheli", Languaje("BlockVendor", player.UserIDString), Languaje("VendorDesHeli", player.UserIDString));
return false;
}
return null;
}
private object OnNpcConversationRespond(NPCTalking npcTalking, BasePlayer player, ConversationData conversationData, ConversationData.ResponseNode responseNode) {
//Puts(responseNode.responseText + " - " + conversationData.shortname);
if (conversationData.shortname == "airwolf_heli_vendor" && !sellersHeli && responseNode.responseText == "I'd like to buy a helicopter" && !HasPermission(player.UserIDString, permByPassBlockHelis)) {
npcTalking.ForceEndConversation(player);
Notify(player, "red", "scrapheli", Languaje("BlockVendor", player.UserIDString), Languaje("VendorDesHeli", player.UserIDString));
return false;
}
if (conversationData.shortname == "boatvendor" && !sellersBoat && responseNode.responseText == "I'm looking to buy a boat" && !HasPermission(player.UserIDString, permByPassBlockBoat)) {
npcTalking.ForceEndConversation(player);
Notify(player, "red", "rowboat", Languaje("BlockVendor", player.UserIDString), Languaje("VendorDesBoat", player.UserIDString));
return false;
}
if (conversationData.shortname == "stablesvendor" && !sellersHorse && responseNode.responseText == "I'd like to buy a horse" && !HasPermission(player.UserIDString, permByPassBlockHorses)) {
npcTalking.ForceEndConversation(player);
Notify(player, "red", "horse", Languaje("BlockVendor", player.UserIDString), Languaje("VendorDesHorse", player.UserIDString));
return false;
}
return null;
}
private bool CanChangeGrade(BasePlayer player, BuildingBlock block, BuildingGrade.Enum grade) {
if(HasPermission(player.UserIDString, permByPassUpgrade)) return true;
if (grade == BuildingGrade.Enum.Wood && maxUpgrade > 0) {
return true;
}
if (grade == BuildingGrade.Enum.Stone && maxUpgrade > 1) {
return true;
}
if (grade == BuildingGrade.Enum.Metal && maxUpgrade > 2) {
return true;
}
if (grade == BuildingGrade.Enum.TopTier && maxUpgrade > 3) {
return true;
}
Notify(player, "blue", "hammer", Languaje("BlockUpgrade", player.UserIDString), Languaje("UpgradeDes", player.UserIDString, Languaje(grade.ToString(), player.UserIDString)), "Hud");
return false;
}
private object CanMountEntity(BasePlayer player, BaseMountable entity) {
if (entity && !enabledMLRS && entity.GetComponent<MLRS>() && !HasPermission(player.UserIDString, permByPassUseMLRS)) {
Notify(player, "red", "mlrs", Languaje("BlockVehicle", player.UserIDString), Languaje("MlrsDes", player.UserIDString), "Hud");
return false;
}
if (entity && !enabledWORKCART && entity.ShortPrefabName == "workcartdriver" && !HasPermission(player.UserIDString, permByPassUseWorkcart)) {
Notify(player, "red", "workcart", Languaje("BlockVehicle", player.UserIDString), Languaje("TrainDes", player.UserIDString), "Hud");
return false;
}
if (entity && !enabledTRAIN && entity.ShortPrefabName == "locomotivedriver" && !HasPermission(player.UserIDString, permByPassUseLocomotive)) {
Notify(player, "red", "locomotive", Languaje("BlockVehicle", player.UserIDString), Languaje("TrainDes", player.UserIDString), "Hud");
return false;
}
return null;
}
private void OnItemResearch(ResearchTable table, Item targetItem, BasePlayer player) {
if (HasPermission(player.UserIDString, permByPassInstantResearch)) {
table.researchDuration = 0.0f;
}
else {
if (researchDuration != 10.0f) table.researchDuration = researchDuration;
}
}
private void OnRecyclerToggle(Recycler recycler, BasePlayer player) {
if (recycler.IsOn()) return;
recycler.CancelInvoke(nameof(recycler.RecycleThink));
if (HasPermission(player.UserIDString, permByPassInstantRecycler)) {
timer.Once(0.1f, () => recycler.InvokeRepeating(recycler.RecycleThink, 0.0f, 0.0f));
}
else {
timer.Once(0.1f, () => recycler.InvokeRepeating(recycler.RecycleThink, recyclerDuration - 0.1f, recyclerDuration));
}
}
#region GatherSystem
private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) {
GatherMultiplier(item, multResource);
}
private void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) {
GatherMultiplier(item, multResourceBonus);
}
private void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player) {
foreach(ItemAmount item in collectible.itemList) {
item.amount = (int)(item.amount * multPickup);
}
}
private void OnGrowableGathered(GrowableEntity plant, Item item, BasePlayer player) {
GatherMultiplier(item, multGrowable);
}
private void OnSurveyGather(SurveyCharge surveyCharge, Item item) {
GatherMultiplier(item, multSurvey);
}
private void OnQuarryGather(MiningQuarry quarry, Item item) {
GatherMultiplier(item, multQuarry);
}
private void OnExcavatorGather(ExcavatorArm excavator, Item item) {
GatherMultiplier(item, multExcavator);
}
#endregion
#region BlockItems
private object CanEquipItem(PlayerInventory inventory, Item item, int target) {
return CanWearItem(inventory, item, target);
}
private object OnWeaponReload(BaseProjectile projectile, BasePlayer player) {
return OnMagazineReload(projectile, -1, player);
}
private object CanWearItem(PlayerInventory inventory, Item item, int target) {
if (HasPermission(inventory.GetComponent<BasePlayer>().UserIDString, permByPassBlockItems)) return null;
var result = CanUseItem(inventory.GetComponent<BasePlayer>(), item.info.shortname);
return result ? (object) null : false;
}
private object OnMagazineReload(BaseProjectile projectile, int desiredAmount, BasePlayer player) {
if (HasPermission(player.UserIDString, permByPassBlockItems)) return null;
if (projectile.primaryMagazine.definition.ammoTypes == AmmoTypes.RIFLE_556MM) {
NextTick(()=> {
CheckGun(player, projectile);
}
);
}
var result = CanUseItem(player, projectile.primaryMagazine.ammoType.shortname);
return result ? (object) null : true;
}
private object OnItemAction(Item item, string action, BasePlayer player) {
if(action == null) return null;
if(action == "consume") {
var result = CanUseItem(player, item.info.shortname);
return result ? (object) null : false;
}
return null;
}
ItemContainer.CanAcceptResult? CanAcceptItem(ItemContainer container, Item item, int targetPos) {
if (container == null || container.playerOwner == null) return null;
BasePlayer player = container.playerOwner;
bool hasLargeBackpackEquipped = player.inventory.containerWear.itemList.Any(wearable => wearable.info.shortname == "largebackpack");
if (hasLargeBackpackEquipped && container.entityOwner != null && container.entityOwner.ShortPrefabName == "largebackpack") return ItemContainer.CanAcceptResult.CannotAccept;
Item parentItem = container.parent;
if (parentItem != null) {
BasePlayer parentPlayer = parentItem.GetOwnerPlayer() ?? item.GetOwnerPlayer();
if (parentPlayer == null) return null;
var result = CanUseItem(parentPlayer, item.info.shortname);
return result ? (ItemContainer.CanAcceptResult?)null : ItemContainer.CanAcceptResult.CannotAccept;
}
return null;
}
private object CanCraft(PlayerBlueprints blueprints, ItemDefinition definition, int skinId) {
if(!blockCraft) return null;
BasePlayer player = blueprints.GetComponentInParent<BasePlayer>();
if (HasPermission(player.UserIDString, permByPassBlockItems)) return null;
var result = CanUseItem(player, definition.shortname);
return result ? (object) null : false;
}
#endregion
#endregion
#region Comandos
private void cmdSelectTier(ConsoleSystem.Arg arg) {
if (arg.IsAdmin == false) {
SendReply(arg, "You don't have access to that command!");
return;
}
var args = arg.Args;
if (args == null || args?.Length == 0) {
SendReply(arg, "Usage: tier.select 0-3");
return;
}
int newtier = Int16.Parse(args[0]);
SelectTier(tierCurrent, newtier);
}
private void cmdOpenInfo(ConsoleSystem.Arg arg) {
OpenPanel(arg.Player(), tierCurrent);
}
[ChatCommand("tier")]
void cmdChatTier(BasePlayer player, string command, string[] args) {
if (args.Length == 0) {
if(config.GUI.WINDOWS.showWindowsCommand) OpenPanel(player, tierCurrent, 0);
}
else {
if (HasPermission(player.UserIDString, permissionAdmin)) {
switch (args[0]) {
case "edit" : if (args?.Length != 2) {
EditTier(player, tierCurrent);
return;
}
int tiercount = Int16.Parse(args[1])-1;
if (tiercountAll > tiercount) {
EditTier(player, tiercount);
return;
}
else {
SendReply(player, "The specified Tier does not exist make sure to enter a number from 1 to " + tiercountAll);
}
return;
}
}
else {
PrintToChat(player, Languaje("NotAllowed", player.UserIDString));
}
}
}
[ChatCommand("tieralert")]
void cmdChatTierAlert(BasePlayer player, string command, string[] args) {
if (HasPermission(player.UserIDString, permissionAdmin)) {
if (args.Length == 0) {
PrintToChat(player, Languaje("Unspecified", player.UserIDString));
}
else {
string message = string.Join(" ", args.Skip(0).ToArray());
SendAlert(Languaje("TierAlertTitle", null), message, null, null, true);
}
}
else {
PrintToChat(player, Languaje("NotAllowed", player.UserIDString));
}
}
private void cmdEditTier(ConsoleSystem.Arg arg) {
if (arg.IsAdmin == false) {
SendReply(arg, "You don't have access to that command!");
return;
}
NotifyChangue(0, 1);
var args = arg.Args;
if (args == null || args?.Length == 0) {
SendReply(arg, "Usage: tier.edit 0-3");
return;
}
int newtier = Int16.Parse(args[0]);
//SelectTier(tierCurrent, newtier);
}
#endregion
#region Functions
private void SelectTier(int old_tier, int new_tier) {
Puts("Applying Tier ("+new_tier+"): " + config.TIERS[new_tier].name + " - Previous Tier ("+old_tier+")");
screenCounterIcon = config.GUI.COUNTER.screenCounterIcon;
screenCounterButton = config.GUI.COUNTER.screenCounterButton;
tierName = config.TIERS[new_tier].name;
tierIcon = config.TIERS[new_tier].icon;
tierColor = config.TIERS[new_tier].color;
enabledMaxCUP = config.TIERS[new_tier].cupboards.limitCupboard;
limitCupboard = config.TIERS[new_tier].cupboards.maxCupboards;
enabledAlertDestrTC = config.TIERS[new_tier].cupboards.enabledAlert;
alertDestrName = config.TIERS[new_tier].cupboards.ALERT.name;
alertDestrPos = config.TIERS[new_tier].cupboards.ALERT.pos;
maxUpgrade = config.TIERS[new_tier].cupboards.maxGrade;
useWorkbench = config.TIERS[new_tier].workbench.researchWorkbench;
allPlaceWorkbench = config.TIERS[new_tier].workbench.placeAllWorkbench;
listWorkbench = config.TIERS[new_tier].workbench.onlyWorkbench;
listCards = config.TIERS[new_tier].spawns.spawnCards;
listVehicles = config.TIERS[new_tier].spawns.spawnVehicles;
enabledMLRS = config.TIERS[new_tier].spawns.spawnMLRS;
enabledWORKCART = config.TIERS[new_tier].spawns.spawnWORKCART;
enabledTRAIN = config.TIERS[new_tier].spawns.spawnTRAIN;
cargoEvent = config.TIERS[new_tier].events.cargoship;
oilEvent = config.TIERS[new_tier].events.oilrig;
ch47Event = config.TIERS[new_tier].events.chinook;
heliEvent = config.TIERS[new_tier].events.helicopter;
supplyEvent = config.TIERS[new_tier].events.supplysignal;
bradleyEvent = config.TIERS[new_tier].events.bradley;
sellersHeli = config.TIERS[new_tier].sellers.helicopter;
sellersBoat = config.TIERS[new_tier].sellers.boat;
sellersHorse = config.TIERS[new_tier].sellers.horse;
sellersDrones = config.TIERS[new_tier].sellers.drones;
sellersVending = config.TIERS[new_tier].sellers.vending;
craftingDuration = config.TIERS[new_tier].speed.craftingSpeed;
researchDuration = config.TIERS[new_tier].speed.researchSpeed;
recyclerDuration = config.TIERS[new_tier].speed.recyclerSpeed;
gatherEnabled = config.TIERS[new_tier].speed.gatherSpeed;
multResource = config.TIERS[new_tier].speed.gatherConfig.Resource;
multResourceBonus = config.TIERS[new_tier].speed.gatherConfig.ResourceBonus;
multPickup = config.TIERS[new_tier].speed.gatherConfig.Pickup;
multGrowable = config.TIERS[new_tier].speed.gatherConfig.Growable;
multSurvey = config.TIERS[new_tier].speed.gatherConfig.Survey;
multQuarry = config.TIERS[new_tier].speed.gatherConfig.Quarry;
multExcavator = config.TIERS[new_tier].speed.gatherConfig.Excavator;
blockCraft = config.TIERS[new_tier].lists.itemsBlockCraft;
blockDeployables = config.TIERS[new_tier].lists.itemsBlockDeployables;
listCommand = config.TIERS[new_tier].lists.commands;
minNextTier = 0;
int count = 0;
foreach (var tier in config.TIERS) {
if(new_tier >= count) {
minNextTier += config.TIERS[count].durationMinutes;
}
count++;
}
if (listVehicles.Count == 0) {
Puts("Vehicles disabled in this Tier, disabling car population (Better performance).");
Server.Command("modularcar.population 0");
}
else {
Puts("There is some kind of car set to Spawn, resetting population.");
Server.Command("modularcar.population 3");
}
if(config.SERVERTITLE.titleEnabled) {
ConVar.Server.hostname = string.Format(config.SERVERTITLE.titleText, tierName);
}
tierCurrent = new_tier;
tiercountAll = config.TIERS.Count();
_Data.activeTier = new_tier;
UpdateEvents();
UpdateVending();
CheckExistMarketplace();
CheckExistVehicles();
ItemsBlock();
SetDurationCraft();
UpdateHooks();
ExecuteCommands();
SaveData();
ControlTime();
ClearEntities();
}
private void InfoData() {
int count = 0;
foreach (var tier in config.TIERS) {
itemType.Add(count, new Dictionary<string, List<SectionInfo>> {
{
"Building", new List<SectionInfo> {
new SectionInfo {
img = "cupboard.tool", title = "CupboardsMax", text = tier.cupboards.limitCupboard ? "Max: " + tier.cupboards.maxCupboards : "Unlimited"
}
, new SectionInfo {
img = "hammer", title = "MaxUpgrade", text = Grade(tier.cupboards.maxGrade)
}
}
}
, {
"Workbench", new List<SectionInfo> {
new SectionInfo {
img = "blueprintbase", title = "ResearchWorkbench", text = tier.workbench.researchWorkbench ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = Workbench(tier.workbench), title = "MaxWorkbenchLevel", text = Workbench(tier.workbench)
}
}
}
, {
"Events", new List<SectionInfo> {
new SectionInfo {
img = "cargoship", title = "Cargoship", text = tier.events.cargoship ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "hackable", title = "OilRig", text = tier.events.oilrig ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "ch47", title = "Chinook", text = tier.events.chinook ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "patrol", title = "PatrolHelicopter", text = tier.events.helicopter ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "airdrop", title = "Airdrop", text = tier.events.supplysignal ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "bradley", title = "BradleyAPC", text = tier.events.bradley ? "Enabled" : "Disabled"
}
}
}
, {
"Vending", new List<SectionInfo> {
new SectionInfo {
img = "scrapheli", title = "HelicopterSale", text = tier.sellers.helicopter ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "rowboat", title = "BoatSales", text = tier.sellers.boat ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "horse", title = "HorseSales", text = tier.sellers.horse ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "drone2", title = "UseofDrones", text = tier.sellers.drones ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "vending.machine", title = "UseofVending", text = tier.sellers.vending ? "Enabled" : "Disabled"
}
}
}
, {
"Spawn", new List<SectionInfo> {
new SectionInfo {
img = KeyCard(tier.spawns.spawnCards), title = "SpawnCards", text = KeyCard(tier.spawns.spawnCards)
}
, new SectionInfo {
img = Vehicles(tier.spawns.spawnVehicles, true), title = "SpawnVehicles", text = Vehicles(tier.spawns.spawnVehicles)
}
, new SectionInfo {
img = "mlrs", title = "UseVehicleMLRS", text = tier.spawns.spawnMLRS ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "workcart", title = "UseVehicleWORKCART", text = tier.spawns.spawnWORKCART ? "Enabled" : "Disabled"
}
, new SectionInfo {
img = "locomotive", title = "UseVehicleTRAIN", text = tier.spawns.spawnTRAIN ? "Enabled" : "Disabled"
}
}
}
, {
"Speed", new List<SectionInfo> {
new SectionInfo {
img = "building.planner", title = "CraftingRate", text = tier.speed.craftingSpeed + " (1.0 = Vanilla | 0.0 = Instant)."
}
, new SectionInfo {
img = "research.table", title = "ResearchSeconds", text = tier.speed.researchSpeed + " seconds."
}
, new SectionInfo {
img = "gears", title = "RecyclerSeconds", text = tier.speed.recyclerSpeed + " seconds."
}
}
.Concat(tier.speed.gatherSpeed ? new[] {
new SectionInfo {
img = "pickaxe", title = "GatherSystem", text = "x" + tier.speed.gatherConfig.ResourceBonus
}
}
: Enumerable.Empty<SectionInfo>() ).ToList()
}
}
);
count++;
}
}
private string Grade(int grade, bool name = false) {
switch (grade) {
case 1 : return name ? "wood" : "Wood";
case 2 : return name ? "stones" : "Stone";
case 3 : return name ? "metal.fragments" : "Metal";
case 4 : return name ? "metal.refined" : "TopTier";
default : return name ? "metal.refined" : "TopTier";
}
}
private string Workbench(WorkbenchConfig tier) {
if(tier.placeAllWorkbench) return "workbench3";
if(tier.onlyWorkbench.Contains("assets/prefabs/deployable/tier 3 workbench/workbench3.deployed.prefab")) return "workbench3";
if(tier.onlyWorkbench.Contains("assets/prefabs/deployable/tier 2 workbench/workbench2.deployed.prefab")) return "workbench2";
return "workbench1";
}
private string KeyCard(List<string> list) {
if(list.Contains("keycard_red_pickup.entity")) return "keycard_red";
if(list.Contains("keycard_blue_pickup.entity")) return "keycard_blue";
return "keycard_green";
}
private string Vehicles(List<string> list, bool name = false) {
if(list.Contains("4module_car_spawned.entity")) return name ? "vehicle.chassis.4mod" : "4module_car_spawned";
if(list.Contains("3module_car_spawned.entity")) return name ? "vehicle.chassis.3mod" : "3module_car_spawned";
if(list.Contains("2module_car_spawned.entity")) return name ? "vehicle.chassis.2mod" : "2module_car_spawned";
return "nocars";
}
private void ControlTime() {
if (config.GUI.screenCounter) {
foreach (var player in BasePlayer.activePlayerList) {
if (player == null) return;
Countdown(player);
}
}
TierTimer();
SpeedTimer();
}
private void SpeedTimer() {
cuiTimer = timer
// ... [Code preview truncated due to length. Full source in attached file] ...