using System.Collections.Generic; using Newtonsoft.Json; using UnityEngine; using System.Linq; using System; using Oxide.Core; using Oxide.Core.Plugins; using Oxide.Game.Rust.Cui; using ProtoBuf; using static ConsoleSystem; using static BuildingManager; namespace Oxide.Plugins { [Info("Building Health Manager", "Miho", "1.0.3")] [Description("Managing the Health of Construction")] public class BuildingHealthManager : RustPlugin { [PluginReference] Plugin ImageLibrary, RaidableBases; #region Filed private ConfigData config; private List saved = new List(); private const string permdefault = "buildinghealthmanager.default"; private const string permVIP = "buildinghealthmanager.vip"; private const string permVVIP = "buildinghealthmanager.vvip"; private const string permAdmin = "buildinghealthmanager.admin"; #endregion #region Dictionary private Dictionary hpdata = new Dictionary(); private Dictionary doorHealthSetting = new Dictionary { { "door.hinged.wood", 200 }, { "door.hinged.metal", 250 }, { "door.hinged.toptier", 1000 }, { "door.double.hinged.wood", 200 }, { "door.double.hinged.metal", 250 }, { "door.double.hinged.toptier", 1000 }, { "wall.frame.garagedoor", 600 }, { "door.hinged.industrial.d", 250 }, { "gates.external.high.wood", 500 }, { "gates.external.high.stone", 500 }, { "shutter.wood.a", 200 }, { "floor.ladder.hatch", 250 }, { "wall.frame.cell.gate", 300 }, { "floor.triangle.ladder.hatch", 250 }, { "wall.frame.fence.gate", 75 }, { "wall.frame.shopfront", 500 } }; private Dictionary externalWallHealthSetting = new Dictionary() { { "wall.external.high.wood", 500 }, { "wall.external.high.stone", 500 }, { "wall.external.high.ice", 500 }, { "icewall", 200 } }; private Dictionary barricadeHealthSetting = new Dictionary() { { "barricade.woodwire", 400 }, { "barricade.concrete", 500 }, { "barricade.metal", 600 }, { "barricade.sandbags", 200 }, { "barricade.stone", 100 }, { "barricade.wood", 250 }, { "barricade.cover.wood", 120 } }; private Dictionary windowHealthSetting = new Dictionary() { { "shutter.metal.embrasure.b", 500 }, { "wall.window.bars.metal", 500 }, { "shutter.metal.embrasure.a", 500 }, { "wall.window.bars.toptier", 500 }, { "wall.window.glass.reinforced", 350 }, { "wall.window.bars.wood", 250 } }; private Dictionary frameHealthSetting = new Dictionary() { { "wall.frame.fence", 100 }, { "floor.grill", 250 }, { "floor.triangle.grill", 250 }, { "wall.frame.shopfront.metal", 750 }, { "wall.frame.netting", 100 }, { "wall.frame.cell", 300 }, { "watchtower.wood", 200 }, { "ladder.wooden.wall", 100 } }; private Dictionary InputBoxValues = new Dictionary(); private Dictionary> categoryImages = new Dictionary> { { "Building", new List { "foundation", "foundation.triangle", "wall", "wall.frame", "wall.window", "wall.doorway", "floor", "floor.frame", "floor.triangle", "floor.triangle.frame", "roof", "roof.triangle", "wall.half", "wall.low", "ramp", "block.stair.ushape", "block.stair.lshape", "foundation.steps", "block.stair.spiral.triangle", "block.stair.spiral" } }, { "Door", new List { "door.hinged.wood", "door.hinged.metal", "door.hinged.toptier", "door.double.hinged.wood", "door.double.hinged.metal", "door.double.hinged.toptier", "wall.frame.garagedoor", "door.hinged.industrial.d", "gates.external.high.wood", "gates.external.high.stone", "shutter.wood.a", "floor.ladder.hatch", "wall.frame.cell.gate", "floor.triangle.ladder.hatch", "wall.frame.fence.gate", "wall.frame.shopfront" } }, { "External", new List { "wall.external.high.wood", "wall.external.high.stone", "wall.external.high.ice", "icewall" } }, { "Barricade", new List { "barricade.woodwire", "barricade.concrete", "barricade.metal", "barricade.sandbags", "barricade.stone", "barricade.wood", "barricade.cover.wood" } }, { "Window", new List { "shutter.metal.embrasure.b", "wall.window.bars.metal", "shutter.metal.embrasure.a", "wall.window.bars.toptier", "wall.window.glass.reinforced", "wall.window.bars.wood" } }, { "Frame", new List { "wall.frame.fence", "floor.grill", "floor.triangle.grill", "wall.frame.shopfront.metal", "wall.frame.netting", "wall.frame.cell", "watchtower.wood", "ladder.wooden.wall" } } }; private Dictionary playerPageMap = new Dictionary(); private Dictionary buildingblockImageUrls = new Dictionary { { "foundation", "https://rustlabs.com/img/screenshots/foundation0.png" }, { "foundation.triangle", "https://rustlabs.com/img/screenshots/tr-foundation0.png" }, { "wall", "https://rustlabs.com/img/screenshots/wall0.png" }, { "wall.frame", "https://rustlabs.com/img/screenshots/wall-frame0.png" }, { "wall.window", "https://rustlabs.com/img/screenshots/window0.png" }, { "wall.doorway", "https://rustlabs.com/img/screenshots/doorway0.png" }, { "floor", "https://rustlabs.com/img/screenshots/floor0.png" }, { "floor.frame", "https://rustlabs.com/img/screenshots/floor-frame0.png" }, { "floor.triangle", "https://rustlabs.com/img/screenshots/tr-floor0.png" }, { "floor.triangle.frame", "https://rustlabs.com/img/screenshots/triangle-frame1.png" }, { "roof", "https://rustlabs.com/img/screenshots/roof0.png" }, { "roof.triangle", "https://rustlabs.com/img/screenshots/tr-roof0.png" }, { "wall.half", "https://rustlabs.com/img/screenshots/half-wall0.png" }, { "wall.low", "https://rustlabs.com/img/screenshots/low-wall0.png" }, { "ramp", "https://rustlabs.com/img/screenshots/ramp1.png" }, { "block.stair.ushape", "https://rustlabs.com/img/screenshots/u-stair0.png" }, { "block.stair.lshape", "https://rustlabs.com/img/screenshots/l-stair0.png" }, { "foundation.steps", "https://rustlabs.com/img/screenshots/stairs0.png" }, { "block.stair.spiral.triangle", "https://rustlabs.com/img/screenshots/triangle-spiral1.png" }, { "block.stair.spiral", "https://rustlabs.com/img/screenshots/block-spiral1.png" } }; private Dictionary specialImageUrls = new Dictionary { { "door.hinged.industrial.d", "https://rustlabs.com/img/skins/324/10189.png" }, { "wall.external.high.wood", "https://rustlabs.com/img/items180/wall.external.high.png" }, { "icewall", "https://rustlabs.com/img/items180/wall.ice.wall.png" }, { "barricade.cover.wood", "https://rustlabs.com/img/items180/barricade.wood.cover.png" } }; #endregion #region Configuration public class ConfigData { [JsonProperty(PropertyName = "Building Block Health")] public Dictionary BuildingBlockHealth; [JsonProperty(PropertyName = "Door Health")] public PermissionSetting> DoorHealth; [JsonProperty(PropertyName = "External Wall Health")] public PermissionSetting> ExternalWallHealth; [JsonProperty(PropertyName = "Barricade Health")] public PermissionSetting> BarricadeHealth; [JsonProperty(PropertyName = "Window Health")] public PermissionSetting> WindowHealth; [JsonProperty(PropertyName = "Frame Health")] public PermissionSetting> FrameHealth; [JsonProperty(PropertyName = "Version")] public string Version; } public class PermissionSetting { [JsonProperty(PropertyName = "Default settings")] public T DefaultSettings; [JsonProperty(PropertyName = "VIP settings")] public T VIPSettings; [JsonProperty(PropertyName = "VVIP settings")] public T VVIPSettings; [JsonProperty(PropertyName = "Raidable Bases settings")] public T RaidableBasesSettings; } private ConfigData GetDefaultConfig() { PrintWarning("Creating a new configuration file"); var buildingBlockHealthSetting = new Dictionary() { { "foundation", 100 }, { "foundation.triangle", 100 }, { "wall", 100 }, { "wall.frame", 100 }, { "wall.window", 100 }, { "wall.doorway", 100 }, { "floor", 100 }, { "floor.frame", 100 }, { "floor.triangle", 100 }, { "floor.triangle.frame", 100 }, { "roof", 100 }, { "roof.triangle", 100 }, { "wall.half", 100 }, { "wall.low", 100 }, { "ramp", 100 }, { "block.stair.ushape", 100 }, { "block.stair.lshape", 100 }, { "foundation.steps", 100 }, { "block.stair.spiral.triangle", 100 }, { "block.stair.spiral", 100 } }; var doorHealthSetting = new Dictionary() { { "door.hinged.wood", 200 }, { "door.hinged.metal", 250 }, { "door.hinged.toptier", 1000 }, { "door.double.hinged.wood", 200 }, { "door.double.hinged.metal", 250 }, { "door.double.hinged.toptier", 1000 }, { "wall.frame.garagedoor", 600 }, { "door.hinged.industrial.d", 250 }, { "gates.external.high.wood", 500 }, { "gates.external.high.stone", 500 }, { "shutter.wood.a", 200 }, { "floor.ladder.hatch", 250 }, { "wall.frame.cell.gate", 300 }, { "floor.triangle.ladder.hatch", 250 }, { "wall.frame.fence.gate", 75 }, { "wall.frame.shopfront", 500 } }; var externalWallHealthSetting = new Dictionary() { { "wall.external.high.wood", 500 }, { "wall.external.high.stone", 500 }, { "wall.external.high.ice", 500 }, { "icewall", 200 } }; var barricadeHealthSetting = new Dictionary() { { "barricade.woodwire", 400 }, { "barricade.concrete", 500 }, { "barricade.metal", 600 }, { "barricade.sandbags", 200 }, { "barricade.stone", 100 }, { "barricade.wood", 250 }, { "barricade.cover.wood", 120 } }; var windowHealthSetting = new Dictionary() { { "shutter.metal.embrasure.b", 500 }, { "wall.window.bars.metal", 500 }, { "shutter.metal.embrasure.a", 500 }, { "wall.window.bars.toptier", 500 }, { "wall.window.glass.reinforced", 350 }, { "wall.window.bars.wood", 250 } }; var frameHealthSetting = new Dictionary() { { "wall.frame.fence", 100 }, { "floor.grill", 250 }, { "floor.triangle.grill", 250 }, { "wall.frame.shopfront.metal", 750 }, { "wall.frame.netting", 100 }, { "wall.frame.cell", 300 }, { "watchtower.wood", 200 }, { "ladder.wooden.wall", 100 } }; var permissionSettingForDoor = new PermissionSetting>() { DefaultSettings = doorHealthSetting, VIPSettings = doorHealthSetting, VVIPSettings = doorHealthSetting, RaidableBasesSettings = doorHealthSetting }; var permissionSettingForExternalWall = new PermissionSetting>() { DefaultSettings = externalWallHealthSetting, VIPSettings = externalWallHealthSetting, VVIPSettings = externalWallHealthSetting, RaidableBasesSettings = externalWallHealthSetting }; var permissionSettingForBarricade = new PermissionSetting>() { DefaultSettings = barricadeHealthSetting, VIPSettings = barricadeHealthSetting, VVIPSettings = barricadeHealthSetting, RaidableBasesSettings = barricadeHealthSetting }; var permissionSettingForWindow = new PermissionSetting>() { DefaultSettings = windowHealthSetting, VIPSettings = windowHealthSetting, VVIPSettings = windowHealthSetting, RaidableBasesSettings = windowHealthSetting }; var permissionSettingForFrame = new PermissionSetting>() { DefaultSettings = frameHealthSetting, VIPSettings = frameHealthSetting, VVIPSettings = frameHealthSetting, RaidableBasesSettings = frameHealthSetting }; return new ConfigData { BuildingBlockHealth = buildingBlockHealthSetting, DoorHealth = permissionSettingForDoor, ExternalWallHealth = permissionSettingForExternalWall, BarricadeHealth = permissionSettingForBarricade, WindowHealth = permissionSettingForWindow, FrameHealth = permissionSettingForFrame, Version = "1.0.3" }; } protected override void LoadConfig() { base.LoadConfig(); try { config = Config.ReadObject(); if (config == null) { PrintWarning("Error : Failed to load configuration"); return; } if (config.Version != "1.0.3") { PrintWarning("Configuration file is outdated, Updating config values..."); var defaultConfig = GetDefaultConfig(); config = MergeConfig(config, defaultConfig); } } catch { PrintWarning("Error : Failed to load configuration"); return; } SaveConfig(); } private ConfigData MergeConfig(ConfigData currentConfig, ConfigData defaultConfig) { if (currentConfig == null) { return defaultConfig; } currentConfig.BuildingBlockHealth = MergeDictionary(currentConfig.BuildingBlockHealth, defaultConfig.BuildingBlockHealth); currentConfig.DoorHealth = MergePermissionSettings(currentConfig.DoorHealth, defaultConfig.DoorHealth); currentConfig.ExternalWallHealth = MergePermissionSettings(currentConfig.ExternalWallHealth, defaultConfig.ExternalWallHealth); currentConfig.BarricadeHealth = MergePermissionSettings(currentConfig.BarricadeHealth, defaultConfig.BarricadeHealth); currentConfig.WindowHealth = MergePermissionSettings(currentConfig.WindowHealth, defaultConfig.WindowHealth); currentConfig.FrameHealth = MergePermissionSettings(currentConfig.FrameHealth, defaultConfig.FrameHealth); currentConfig.Version = defaultConfig.Version; return currentConfig; } private Dictionary MergeDictionary(Dictionary current, Dictionary defaultDict) { var merged = new Dictionary(defaultDict); if (current != null) { foreach (var key in current.Keys) { merged[key] = current[key]; } } return merged; } private PermissionSetting> MergePermissionSettings(PermissionSetting> current, PermissionSetting> defaultSetting) { if (current == null) { return defaultSetting; } current.DefaultSettings = MergeDictionary(current.DefaultSettings, defaultSetting.DefaultSettings); current.VIPSettings = MergeDictionary(current.VIPSettings, defaultSetting.VIPSettings); current.VVIPSettings = MergeDictionary(current.VVIPSettings, defaultSetting.VVIPSettings); current.RaidableBasesSettings = MergeDictionary(current.RaidableBasesSettings, defaultSetting.RaidableBasesSettings); return current; } private Dictionary MergeDictionary(Dictionary current, Dictionary defaultDict) { var merged = new Dictionary(defaultDict); if (current != null) { foreach (var key in current.Keys) { merged[key] = current[key]; } } return merged; } protected override void LoadDefaultConfig() { config = GetDefaultConfig(); } protected override void SaveConfig() { Config.WriteObject(config); } #endregion #region Hooks private void Init() { permission.RegisterPermission(permdefault, this); permission.RegisterPermission(permVIP, this); permission.RegisterPermission(permVVIP, this); permission.RegisterPermission(permAdmin, this); } private void OnServerInitialized() { Change(); Imageload(); } private void Unload() { Change(false); foreach (var player in BasePlayer.activePlayerList) { CuiHelper.DestroyUi(player, "bhm_panel"); } } private void OnEntityBuilt(Planner plan, GameObject go) { var entity = go?.ToBaseEntity(); BuildingBlock buildingblock = entity as BuildingBlock; if (buildingblock != null && buildingblock.IsValid()) { string save = entity.ShortPrefabName; if (saved.Contains(save)) { return; } float percent = 0f; if (!config.BuildingBlockHealth.TryGetValue(save, out percent) || percent <= 0) return; var hp = buildingblock.health / buildingblock.MaxHealth(); buildingblock.blockDefinition.healthMultiplier = percent / 100f; buildingblock.health = hp * buildingblock.MaxHealth(); saved.Add(save); } } private void OnEntitySpawned(BaseNetworkable entity) { if (entity != null) Spawnhp(entity); } #endregion #region Methods private void Spawnhp(BaseNetworkable entity) { string cleanPrefabName = GetCleanPrefabName(entity.PrefabName); if (string.IsNullOrEmpty(cleanPrefabName)) { return; } Type entityType = entity.GetType(); switch (entityType) { case Type when entityType == typeof(Door): HandleDoor(entity as Door, cleanPrefabName); break; case Type when entityType == typeof(SimpleBuildingBlock): HandleBuildingBlock(entity as SimpleBuildingBlock, cleanPrefabName); break; case Type when entityType == typeof(Barricade): HandleBarricade(entity as Barricade, cleanPrefabName); break; case Type when entityType == typeof(IceFence): HandleIceFence(entity as IceFence, cleanPrefabName); break; case Type when entityType == typeof(StabilityEntity): HandleStabilityEntity(entity as StabilityEntity, cleanPrefabName); break; case Type when entityType == typeof(DecayEntity): HandleDecayEntity(entity as DecayEntity, cleanPrefabName); break; case Type when entityType == typeof(ShopFront): HandleShopFront(entity as ShopFront, cleanPrefabName); break; case Type when entityType == typeof(BaseLadder): HandleBaseLadder(entity as BaseLadder, cleanPrefabName); break; default: break; } } private void HandleDoor(Door door, string prefabName) { if (door == null) return; if (config.DoorHealth.DefaultSettings.ContainsKey(prefabName)) { if (door.OwnerID != 0) SetDoorHealth(door, prefabName); else if (isRaidableVaild(door)) SetDoorHealth(door, prefabName, true); } } private void HandleBuildingBlock(SimpleBuildingBlock block, string prefabName) { if (block == null) return; string blockType = GetSimpleBlockType(block, prefabName); if (blockType != null) { if (block.OwnerID != 0) HandleSimpleBlockBasedOnType(blockType, block, false, prefabName); else if (isRaidableVaild(block)) HandleSimpleBlockBasedOnType(blockType, block, true, prefabName); } } private void HandleBarricade(Barricade barricade, string prefabName) { if (barricade == null) return; if (config.BarricadeHealth.DefaultSettings.ContainsKey(prefabName)) { if (barricade.OwnerID != 0) SetBarricadeHealth(barricade, prefabName); else if (isRaidableVaild(barricade)) SetBarricadeHealth(barricade, prefabName, true); } } private void HandleIceFence(IceFence fence, string prefabName) { if (fence == null) return; if (config.ExternalWallHealth.DefaultSettings.ContainsKey(prefabName)) { if (fence.OwnerID != 0) SetExternalWallHealth(fence, prefabName); else if (isRaidableVaild(fence)) SetExternalWallHealth(fence, prefabName, true); } } private void HandleStabilityEntity(StabilityEntity entity, string prefabName) { if (entity == null) return; if (config.WindowHealth.DefaultSettings.ContainsKey(prefabName)) { if (entity.OwnerID != 0) SetStabilityEntityHealth(entity, prefabName); else if (isRaidableVaild(entity)) SetStabilityEntityHealth(entity, prefabName, true); } } private void HandleDecayEntity(DecayEntity entity, string prefabName) { if (entity == null) return; if (config.FrameHealth.DefaultSettings.ContainsKey(prefabName)) { if (entity.OwnerID != 0) SetDecayEntityHealth(entity, prefabName); else if (isRaidableVaild(entity)) SetDecayEntityHealth(entity, prefabName, true); } } private void HandleShopFront(ShopFront shopFront, string prefabName) { if (shopFront == null) return; if (config.FrameHealth.DefaultSettings.ContainsKey(prefabName)) { if (shopFront.OwnerID != 0) SetShopFrontHealth(shopFront, prefabName); else if (isRaidableVaild(shopFront)) SetShopFrontHealth(shopFront, prefabName, true); } } private void HandleBaseLadder(BaseLadder ladder, string prefabName) { if (ladder == null) return; if (config.FrameHealth.DefaultSettings.ContainsKey(prefabName)) { if (ladder.OwnerID != 0) SetBaseLadderHealth(ladder, prefabName); else if (isRaidableVaild(ladder)) SetBaseLadderHealth(ladder, prefabName, true); } } private void Change(bool load = true) { hpdata.Clear(); saved.Clear(); foreach (var entity in BaseNetworkable.serverEntities.OfType().Where(entity => isVaild(entity))) { GetHPData(entity); } foreach (var entity in BaseNetworkable.serverEntities) { if (entity == null) continue; if (entity is BuildingBlock && isVaild((BuildingBlock)entity)) { ProcessBuildingBlock((BuildingBlock)entity, load); } else if (entity is Door && isVaild((Door)entity)) { ProcessDoor((Door)entity, load); } else if (entity is SimpleBuildingBlock && isVaild((SimpleBuildingBlock)entity)) { ProcessSimpleBuildingBlock((SimpleBuildingBlock)entity, load); } else if (entity is Barricade && isVaild((Barricade)entity)) { ProcessBarricade((Barricade)entity, load); } else if (entity is IceFence && isVaild((IceFence)entity)) { ProcessIceFence((IceFence)entity, load); } else if (entity is StabilityEntity && isVaild((StabilityEntity)entity)) { ProcessStabilityEntity((StabilityEntity)entity, load); } else if (entity is DecayEntity && isVaild((DecayEntity)entity)) { ProcessDecayEntity((DecayEntity)entity, load); } else if (entity is ShopFront && isVaild((ShopFront)entity)) { ProcessShopFront((ShopFront)entity, load); } else if (entity is BaseLadder && isVaild((BaseLadder)entity)) { ProcessBaseLadder((BaseLadder)entity, load); } } } private void ProcessBuildingBlock(BuildingBlock buildingblock, bool load = true) { string save = buildingblock.ShortPrefabName; if (!saved.Contains(save)) { float percent = 0; if (!config.BuildingBlockHealth.TryGetValue(save, out percent) || percent <= 0) return; float multiplier = load ? percent / 100f : 1f; buildingblock.blockDefinition.healthMultiplier = multiplier; saved.Add(save); } ulong id = buildingblock.net.ID.Value; if (!hpdata.ContainsKey(id)) return; buildingblock.health = hpdata[id] * buildingblock.MaxHealth(); } private void GetHPData(BuildingBlock buildingblock) { ulong id = buildingblock.net.ID.Value; float hp = buildingblock.health / buildingblock.MaxHealth(); hpdata[id] = hp; } private void ProcessDoor(Door door, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(door.PrefabName); if (config.DoorHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { if (door.OwnerID != 0) SetDoorHealth(door, cleanPrefabName); else if (isRaidableVaild(door)) SetDoorHealth(door, cleanPrefabName, true); } } else { string cleanPrefabName = GetCleanPrefabName(door.PrefabName); if (config.DoorHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { ResetDoorHealth(door, cleanPrefabName); } } } private void ProcessSimpleBuildingBlock(SimpleBuildingBlock simpleBlock, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(simpleBlock.PrefabName); string blockType = GetSimpleBlockType(simpleBlock, cleanPrefabName); if (blockType != null) { if (simpleBlock.OwnerID != 0) HandleSimpleBlockBasedOnType(blockType, simpleBlock, false, cleanPrefabName); else if (isRaidableVaild(simpleBlock)) HandleSimpleBlockBasedOnType(blockType, simpleBlock, true, cleanPrefabName); } } else { string cleanPrefabName = GetCleanPrefabName(simpleBlock.PrefabName); ResetSimpleBuildingBlockHealth(simpleBlock, cleanPrefabName); } } private void ProcessBarricade(Barricade barricade, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(barricade.PrefabName); if (config.BarricadeHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { if (barricade.OwnerID != 0) SetBarricadeHealth(barricade, cleanPrefabName); else if (isRaidableVaild(barricade)) SetBarricadeHealth(barricade, cleanPrefabName, true); } } else { string cleanPrefabName = GetCleanPrefabName(barricade.PrefabName); if (config.BarricadeHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { ResetBarricadeHealth(barricade, cleanPrefabName); } } } private void ProcessIceFence(IceFence icefence, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(icefence.PrefabName); if (config.ExternalWallHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { if (icefence.OwnerID != 0) SetExternalWallHealth(icefence, cleanPrefabName); else if (isRaidableVaild(icefence)) SetExternalWallHealth(icefence, cleanPrefabName, true); } } else { string cleanPrefabName = GetCleanPrefabName(icefence.PrefabName); if (config.ExternalWallHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { ResetIceFenceHealth(icefence, cleanPrefabName); } } } private void ProcessStabilityEntity(StabilityEntity stabilityentity, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(stabilityentity.PrefabName); if (config.WindowHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { if (stabilityentity.OwnerID != 0) SetStabilityEntityHealth(stabilityentity, cleanPrefabName); else if (isRaidableVaild(stabilityentity)) SetStabilityEntityHealth(stabilityentity, cleanPrefabName, true); } } else { string cleanPrefabName = GetCleanPrefabName(stabilityentity.PrefabName); if (config.WindowHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { ResetStabilityEntityHealth(stabilityentity, cleanPrefabName); } } } private void ProcessDecayEntity(DecayEntity decayentity, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(decayentity.PrefabName); if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { if (decayentity.OwnerID != 0) SetDecayEntityHealth(decayentity, cleanPrefabName); else if (isRaidableVaild(decayentity)) SetDecayEntityHealth(decayentity, cleanPrefabName, true); } } else { string cleanPrefabName = GetCleanPrefabName(decayentity.PrefabName); if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { ResetDecayEntityHealth(decayentity, cleanPrefabName); } } } private void ProcessShopFront(ShopFront shopfront, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(shopfront.PrefabName); if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { if (shopfront.OwnerID != 0) SetShopFrontHealth(shopfront, cleanPrefabName); else if (isRaidableVaild(shopfront)) SetShopFrontHealth(shopfront, cleanPrefabName, true); } } else { string cleanPrefabName = GetCleanPrefabName(shopfront.PrefabName); if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { ResetShopFrontHealth(shopfront, cleanPrefabName); } } } private void ProcessBaseLadder(BaseLadder baseladder, bool load = true) { if (load) { string cleanPrefabName = GetCleanPrefabName(baseladder.PrefabName); if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { if (baseladder.OwnerID != 0) SetBaseLadderHealth(baseladder, cleanPrefabName); else if (isRaidableVaild(baseladder)) SetBaseLadderHealth(baseladder, cleanPrefabName, true); } } else { string cleanPrefabName = GetCleanPrefabName(baseladder.PrefabName); if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { ResetBaseLadderHealth(baseladder, cleanPrefabName); } } } private string GetCleanPrefabName(string prefabName) { int lastSlash = prefabName.LastIndexOf('/'); int dotPrefab = prefabName.IndexOf(".prefab"); string cleanPrefabName = prefabName.Substring(lastSlash + 1, dotPrefab - lastSlash - 1); return cleanPrefabName; } private void HandleSimpleBlockBasedOnType(string blockType, SimpleBuildingBlock block, bool isValid, string cleanPrefabName) { switch (blockType) { case "ExternalWall": if (isValid) { SetExternalWallHealth(block, cleanPrefabName, true); } else { SetExternalWallHealth(block, cleanPrefabName); } break; case "Window": if (isValid) { SetWindowHealth(block, cleanPrefabName, true); } else { SetWindowHealth(block, cleanPrefabName); } break; case "Frame": if (isValid) { SetFrameHealth(block, cleanPrefabName, true); } else { SetFrameHealth(block, cleanPrefabName); } break; } } private string GetSimpleBlockType(SimpleBuildingBlock block, string cleanPrefabName) { if (config.ExternalWallHealth.DefaultSettings.ContainsKey(cleanPrefabName)) return "ExternalWall"; if (config.WindowHealth.DefaultSettings.ContainsKey(cleanPrefabName)) return "Window"; if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) return "Frame"; return null; } private bool isVaild(BaseEntity entity) { if (entity.OwnerID != 0) return true; return RaidableBases != null && Convert.ToBoolean(RaidableBases?.Call("EventTerritory", entity.transform.position)); } private bool isRaidableVaild(BaseEntity entity) { return RaidableBases != null && Convert.ToBoolean(RaidableBases?.Call("EventTerritory", entity.transform.position)); } private void ResetDoorHealth(Door door, string cleanPrefabName) { float sv = door.health / door._maxHealth; float resetHealth = doorHealthSetting[cleanPrefabName]; door._maxHealth = resetHealth; door.health = sv * resetHealth; door.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } private void ResetSimpleBuildingBlockHealth(SimpleBuildingBlock simpleblock, string cleanPrefabName) { float sv = simpleblock.health / simpleblock._maxHealth; string typename = GetSimpleBlockType(simpleblock, cleanPrefabName); switch (typename) { case "ExternalWall": if (config.ExternalWallHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { float resetexwallHealth = externalWallHealthSetting[cleanPrefabName]; simpleblock._maxHealth = resetexwallHealth; simpleblock.health = sv * resetexwallHealth; simpleblock.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } break; case "Window": if (config.WindowHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { float resetwindowHealth = windowHealthSetting[cleanPrefabName]; simpleblock._maxHealth = resetwindowHealth; simpleblock.health = sv * resetwindowHealth; simpleblock.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } break; case "Frame": if (config.FrameHealth.DefaultSettings.ContainsKey(cleanPrefabName)) { float resetframeHealth = frameHealthSetting[cleanPrefabName]; simpleblock._maxHealth = resetframeHealth; simpleblock.health = sv * resetframeHealth; simpleblock.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } break; } } private void ResetBarricadeHealth(Barricade barricade, string cleanPrefabName) { float sv = barricade.health / barricade._maxHealth; float resetHealth = barricadeHealthSetting[cleanPrefabName]; barricade._maxHealth = resetHealth; barricade.health = sv * resetHealth; barricade.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } private void ResetIceFenceHealth(IceFence icefence, string cleanPrefabName) { float sv = icefence.health / icefence._maxHealth; float resetHealth = externalWallHealthSetting[cleanPrefabName]; icefence._maxHealth = resetHealth; icefence.health = sv * resetHealth; icefence.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } private void ResetStabilityEntityHealth(StabilityEntity stabilityentity, string cleanPrefabName) { float sv = stabilityentity.health / stabilityentity._maxHealth; float resetHealth = windowHealthSetting[cleanPrefabName]; stabilityentity._maxHealth = resetHealth; stabilityentity.health = sv * resetHealth; stabilityentity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } private void ResetDecayEntityHealth(DecayEntity decayentity, string cleanPrefabName) { float sv = decayentity.health / decayentity._maxHealth; float resetHealth = frameHealthSetting[cleanPrefabName]; decayentity._maxHealth = resetHealth; decayentity.health = sv * resetHealth; decayentity.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } private void ResetShopFrontHealth(ShopFront shopfront, string cleanPrefabName) { float sv = shopfront.health / shopfront._maxHealth; float resetHealth = frameHealthSetting[cleanPrefabName]; shopfront._maxHealth = resetHealth; shopfront.health = sv * resetHealth; shopfront.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } private void ResetBaseLadderHealth(BaseLadder baseladder, string cleanPrefabName) { float sv = baseladder.health / baseladder._maxHealth; float resetHealth = frameHealthSetting[cleanPrefabName]; baseladder._maxHealth = resetHealth; baseladder.health = sv * resetHealth; baseladder.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } private void SetDoorHealth(Door door, string cleanPrefabName, bool check = false) { float sv = door.health / door._maxHealth; if (check) { if (config.DoorHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; door._maxHealth = config.DoorHealth.RaidableBasesSettings[cleanPrefabName]; door.health = sv * door._maxHealth; door.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(door.OwnerID.ToString(), permVVIP)) { if (config.DoorHealth.VVIPSettings[cleanPrefabName] <= 0) return; door._maxHealth = config.DoorHealth.VVIPSettings[cleanPrefabName]; door.health = sv * door._maxHealth; door.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(door.OwnerID.ToString(), permVIP)) { if (config.DoorHealth.VIPSettings[cleanPrefabName] <= 0) return; door._maxHealth = config.DoorHealth.VIPSettings[cleanPrefabName]; door.health = sv * door._maxHealth; door.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(door.OwnerID.ToString(), permdefault)) { if (config.DoorHealth.DefaultSettings[cleanPrefabName] <= 0) return; door._maxHealth = config.DoorHealth.DefaultSettings[cleanPrefabName]; door.health = sv * door._maxHealth; door.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetExternalWallHealth(SimpleBuildingBlock externalwall, string cleanPrefabName, bool check = false) { float sv = externalwall.health / externalwall._maxHealth; if (check) { if (config.ExternalWallHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; externalwall._maxHealth = config.ExternalWallHealth.RaidableBasesSettings[cleanPrefabName]; externalwall.health = sv * externalwall._maxHealth; externalwall.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(externalwall.OwnerID.ToString(), permVVIP)) { if (config.ExternalWallHealth.VVIPSettings[cleanPrefabName] <= 0) return; externalwall._maxHealth = config.ExternalWallHealth.VVIPSettings[cleanPrefabName]; externalwall.health = sv * externalwall._maxHealth; externalwall.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(externalwall.OwnerID.ToString(), permVIP)) { if (config.ExternalWallHealth.VIPSettings[cleanPrefabName] <= 0) return; externalwall._maxHealth = config.ExternalWallHealth.VIPSettings[cleanPrefabName]; externalwall.health = sv * externalwall._maxHealth; externalwall.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(externalwall.OwnerID.ToString(), permdefault)) { if (config.ExternalWallHealth.DefaultSettings[cleanPrefabName] <= 0) return; externalwall._maxHealth = config.ExternalWallHealth.DefaultSettings[cleanPrefabName]; externalwall.health = sv * externalwall._maxHealth; externalwall.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetWindowHealth(SimpleBuildingBlock window, string cleanPrefabName, bool check = false) { float sv = window.health / window._maxHealth; if (check) { if (config.WindowHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.RaidableBasesSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(window.OwnerID.ToString(), permVVIP)) { if (config.WindowHealth.VVIPSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.VVIPSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(window.OwnerID.ToString(), permVIP)) { if (config.WindowHealth.VIPSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.VIPSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(window.OwnerID.ToString(), permdefault)) { if (config.WindowHealth.DefaultSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.DefaultSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetStabilityEntityHealth(StabilityEntity window, string cleanPrefabName, bool check = false) { float sv = window.health / window._maxHealth; if (check) { if (config.WindowHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.RaidableBasesSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(window.OwnerID.ToString(), permVVIP)) { if (config.WindowHealth.VVIPSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.VVIPSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(window.OwnerID.ToString(), permVIP)) { if (config.WindowHealth.VIPSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.VIPSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(window.OwnerID.ToString(), permdefault)) { if (config.WindowHealth.DefaultSettings[cleanPrefabName] <= 0) return; window._maxHealth = config.WindowHealth.DefaultSettings[cleanPrefabName]; window.health = sv * window._maxHealth; window.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetFrameHealth(SimpleBuildingBlock frame, string cleanPrefabName, bool check = false) { float sv = frame.health / frame._maxHealth; if (check) { if (config.FrameHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.RaidableBasesSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(frame.OwnerID.ToString(), permVVIP)) { if (config.FrameHealth.VVIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VVIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permVIP)) { if (config.FrameHealth.VIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permdefault)) { if (config.FrameHealth.DefaultSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.DefaultSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetDecayEntityHealth(DecayEntity frame, string cleanPrefabName, bool check = false) { float sv = frame.health / frame._maxHealth; if (check) { if (config.FrameHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.RaidableBasesSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(frame.OwnerID.ToString(), permVVIP)) { if (config.FrameHealth.VVIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VVIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permVIP)) { if (config.FrameHealth.VIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permdefault)) { if (config.FrameHealth.DefaultSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.DefaultSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetShopFrontHealth(ShopFront frame, string cleanPrefabName, bool check = false) { float sv = frame.health / frame._maxHealth; if (check) { if (config.FrameHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.RaidableBasesSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(frame.OwnerID.ToString(), permVVIP)) { if (config.FrameHealth.VVIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VVIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permVIP)) { if (config.FrameHealth.VIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permdefault)) { if (config.FrameHealth.DefaultSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.DefaultSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetBaseLadderHealth(BaseLadder frame, string cleanPrefabName, bool check = false) { float sv = frame.health / frame._maxHealth; if (check) { if (config.FrameHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.RaidableBasesSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(frame.OwnerID.ToString(), permVVIP)) { if (config.FrameHealth.VVIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VVIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permVIP)) { if (config.FrameHealth.VIPSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.VIPSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(frame.OwnerID.ToString(), permdefault)) { if (config.FrameHealth.DefaultSettings[cleanPrefabName] <= 0) return; frame._maxHealth = config.FrameHealth.DefaultSettings[cleanPrefabName]; frame.health = sv * frame._maxHealth; frame.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } private void SetBarricadeHealth(Barricade barricade, string cleanPrefabName, bool check = false) { float sv = barricade.health / barricade._maxHealth; if (check) { if (config.BarricadeHealth.RaidableBasesSettings[cleanPrefabName] <= 0) return; barricade._maxHealth = config.BarricadeHealth.RaidableBasesSettings[cleanPrefabName]; barricade.health = sv * barricade._maxHealth; barricade.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); return; } if (permission.UserHasPermission(barricade.OwnerID.ToString(), permVVIP)) { if (config.BarricadeHealth.VVIPSettings[cleanPrefabName] <= 0) return; barricade._maxHealth = config.BarricadeHealth.VVIPSettings[cleanPrefabName]; barricade.health = sv * barricade._maxHealth; barricade.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(barricade.OwnerID.ToString(), permVIP)) { if (config.BarricadeHealth.VIPSettings[cleanPrefabName] <= 0) return; barricade._maxHealth = config.BarricadeHealth.VIPSettings[cleanPrefabName]; barricade.health = sv * barricade._maxHealth; barricade.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } else if (permission.UserHasPermission(barricade.OwnerID.ToString(), permdefault)) { if (config.BarricadeHealth.DefaultSettings[cleanPrefabName] <= 0) return; barricade._maxHealth = config.BarricadeHealth.DefaultSettings[cleanPrefabName]; barricade.health = sv * barricade._maxHealth; barricade.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } #endregion #region CUI private void LoadImagesForCategory(BasePlayer player, string category, int page) { var container = new CuiElementContainer(); List imageNames; if (!categoryImages.TryGetValue(category, out imageNames)) return; int columns = 4; int rows = 2; int startIndex = page * (columns * rows); int endIndex = Math.Min(startIndex + (columns * rows), imageNames.Count); for (int i = 0; i < columns * rows && startIndex + i < imageNames.Count; i++) { var imageName = imageNames[startIndex + i]; var imageId = ImageLibrary.Call("GetImage", imageName); int row = i / columns; int column = i % columns; string anchorMin = $"{0.25 + (column * 0.19)} {0.59 - (row * 0.4)}"; string anchorMax = $"{0.37 + (column * 0.19)} {0.84 - (row * 0.4)}"; container.Add(new CuiElement { Parent = "bhm_panel", Components = { new CuiRawImageComponent { Png = imageId, Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = anchorMin, AnchorMax = anchorMax } } }); container.Add(new CuiButton { Button = { Command = $"bh.button {category} {page} {i}", Color = "0.8 1 0.6 0.5" }, RectTransform = { AnchorMin = $"{0.345 + column * 0.19} {0.49 - row * 0.4}", AnchorMax = $"{0.385 + column * 0.19} {0.55 - row * 0.4}" }, Text = { Text = "Save", FontSize = 13, Align = TextAnchor.MiddleCenter } }, "bhm_panel"); string[] labelTexts; if (category == "Building") { labelTexts = new[] { "", "Set", "" }; } else { labelTexts = new[] { "Default", "VIP", "VVIP", "RaidableBase" }; } for (int j = 0; j < labelTexts.Length; j++) { if (string.IsNullOrEmpty(labelTexts[j])) continue; string labelAnchorMin = $"{0.235 + column * 0.19} {0.54 - (j * 0.03) - row * 0.4}"; string labelAnchorMax = $"{0.285 + column * 0.19} {0.57 - (j * 0.03) - row * 0.4}"; var label = new CuiElement { Parent = "bhm_panel", Components = { new CuiTextComponent { Text = labelTexts[j], FontSize = 10, Align = TextAnchor.MiddleCenter }, new CuiRectTransformComponent { AnchorMin = labelAnchorMin, AnchorMax = labelAnchorMax }, new CuiOutlineComponent { Distance = "1 -1", Color = "0.1 0.1 0.1 1" }, } }; container.Add(label); string current = $"{page}{i}{j}"; string needvaule = Currentvalue(category, current); string currentvalue = GetConfigValue(category, current, needvaule); string input = $"inputField input_{category}_{page}_{i}_{j}"; string inputAnchorMin = $"{0.295 + column * 0.19} {0.53 - (j * 0.03) - row * 0.4}"; string inputAnchorMax = $"{0.335 + column * 0.19} {0.58 - (j * 0.03) - row * 0.4}"; InputBox(ref container, $"input_{category}_{page}_{i}_{j}", "bhm_panel", "1 1 1 1", 9, inputAnchorMin, inputAnchorMax, currentvalue, $"{input}"); } } if (endIndex < imageNames.Count) { container.Add(new CuiButton { Button = { Command = $"bh.showdetails {category} {page + 1}", Color = "0.8 1 0.6 0.5" }, RectTransform = { AnchorMin = "0.97 0.4", AnchorMax = "0.99 0.5" }, Text = { Text = ">", FontSize = 20, Align = TextAnchor.MiddleCenter } }, "bhm_panel"); } if (page > 0) { container.Add(new CuiButton { Button = { Command = $"bh.showdetails {category} {page - 1}", Color = "0.8 1 0.6 0.5" }, RectTransform = { AnchorMin = "0.21 0.4", AnchorMax = "0.23 0.5" }, Text = { Text = "<", FontSize = 20, Align = TextAnchor.MiddleCenter } }, "bhm_panel"); } CuiHelper.AddUi(player, container); } public static void InputBox(ref CuiElementContainer _container, string _name, string _parent, string _color, int _size, string _anchorMin, string _anchorMax, string _defaultText, string _command,string _font = "permanentmarker.ttf", TextAnchor _align = TextAnchor.MiddleCenter, int _charsLimit = 50) { _container.Add(new CuiElement { Parent = _parent, Name = _name, Components = { new CuiInputFieldComponent { Text = _defaultText, CharsLimit = _charsLimit, Color = _color, IsPassword = false, Command = _command, Font = _font, FontSize = _size, Align = _align, NeedsKeyboard = true }, new CuiRectTransformComponent { AnchorMin = _anchorMin, AnchorMax = _anchorMax } }, }); } #endregion #region CUI Methods private void Imageload() { if (ImageLibrary == null) { PrintWarning("Missing plugin dependency: ImageLibrary"); return; } foreach (var category in categoryImages) { foreach (var imageName in category.Value) { if ((bool)ImageLibrary.Call("HasImage", imageName)) continue; string imageUrl; if (category.Key == "Building") { imageUrl = buildingblockImageUrls[imageName]; } else if (specialImageUrls.ContainsKey(imageName)) { imageUrl = specialImageUrls[imageName]; } else { imageUrl = $"https://rustlabs.com/img/items180/{imageName}.png"; } ImageLibrary.Call("AddImage", imageUrl, imageName); } } } private string Currentvalue(string currenttype, string index) { List currentList; if (categoryImages.TryGetValue(currenttype, out currentList)) { string subIndex = index.Substring(0, 2); int indexNumber = int.Parse(subIndex); int currentListIndex = (indexNumber / 10) * 8 + (indexNumber % 10); return currentList[currentListIndex]; } return null; } private string GetConfigValue(string currenttype, string inputvalue, string value) { float checkvalue; string subIndex = inputvalue.Substring(2, 1); switch (currenttype) { case "Building": return config.BuildingBlockHealth.TryGetValue(value, out checkvalue) ? checkvalue.ToString() : null; case "Door": return TryGetValueForSubIndex(subIndex, config.DoorHealth, value); case "External": return TryGetValueForSubIndex(subIndex, config.ExternalWallHealth, value); case "Barricade": return TryGetValueForSubIndex(subIndex, config.BarricadeHealth, value); case "Window": return TryGetValueForSubIndex(subIndex, config.WindowHealth, value); case "Frame": return TryGetValueForSubIndex(subIndex, config.FrameHealth, value); default: return null; } } private string TryGetValueForSubIndex(string subIndex, PermissionSetting> configType, string value) { int checkvalue; switch (subIndex) { case "0": if (configType.DefaultSettings.TryGetValue(value, out checkvalue)) return checkvalue.ToString(); break; case "1": if (configType.VIPSettings.TryGetValue(value, out checkvalue)) return checkvalue.ToString(); break; case "2": if (configType.VVIPSettings.TryGetValue(value, out checkvalue)) return checkvalue.ToString(); break; case "3": if (configType.RaidableBasesSettings.TryGetValue(value, out checkvalue)) return checkvalue.ToString(); break; } return null; } void SetValueForSubIndex(string category, int subIndex, int value, string prefabname, BasePlayer player) { string permset = ""; switch (category) { case "Door": switch (subIndex) { case 0: if (config.DoorHealth.DefaultSettings.ContainsKey(prefabname)) { config.DoorHealth.DefaultSettings[prefabname] = value; permset = "DefaultSetting"; } break; case 1: if (config.DoorHealth.VIPSettings.ContainsKey(prefabname)) { config.DoorHealth.VIPSettings[prefabname] = value; permset = "VIPSetting"; } break; case 2: if (config.DoorHealth.VVIPSettings.ContainsKey(prefabname)) { config.DoorHealth.VVIPSettings[prefabname] = value; permset = "VVIPSetting"; } break; case 3: if (config.DoorHealth.RaidableBasesSettings.ContainsKey(prefabname)) { config.DoorHealth.RaidableBasesSettings[prefabname] = value; permset = "RaidableBasesSetting"; } break; } break; case "External": switch (subIndex) { case 0: if (config.ExternalWallHealth.DefaultSettings.ContainsKey(prefabname)) { config.ExternalWallHealth.DefaultSettings[prefabname] = value; permset = "DefaultSetting"; } break; case 1: if (config.ExternalWallHealth.VIPSettings.ContainsKey(prefabname)) { config.ExternalWallHealth.VIPSettings[prefabname] = value; permset = "VIPSetting"; } break; case 2: if (config.ExternalWallHealth.VVIPSettings.ContainsKey(prefabname)) { config.ExternalWallHealth.VVIPSettings[prefabname] = value; permset = "VVIPSetting"; } break; case 3: if (config.ExternalWallHealth.RaidableBasesSettings.ContainsKey(prefabname)) { config.ExternalWallHealth.RaidableBasesSettings[prefabname] = value; permset = "RaidableBasesSetting"; } break; } break; case "Barricade": switch (subIndex) { case 0: if (config.BarricadeHealth.DefaultSettings.ContainsKey(prefabname)) { config.BarricadeHealth.DefaultSettings[prefabname] = value; permset = "DefaultSetting"; } break; case 1: if (config.BarricadeHealth.VIPSettings.ContainsKey(prefabname)) { config.BarricadeHealth.VIPSettings[prefabname] = value; permset = "VIPSetting"; } break; case 2: if (config.BarricadeHealth.VVIPSettings.ContainsKey(prefabname)) { config.BarricadeHealth.VVIPSettings[prefabname] = value; permset = "VVIPSetting"; } break; case 3: if (config.BarricadeHealth.RaidableBasesSettings.ContainsKey(prefabname)) { config.BarricadeHealth.RaidableBasesSettings[prefabname] = value; permset = "RaidableBasesSetting"; } break; } break; case "Window": switch (subIndex) { case 0: if (config.WindowHealth.DefaultSettings.ContainsKey(prefabname)) { config.WindowHealth.DefaultSettings[prefabname] = value; permset = "DefaultSetting"; } break; case 1: if (config.WindowHealth.VIPSettings.ContainsKey(prefabname)) { config.WindowHealth.VIPSettings[prefabname] = value; permset = "VIPSetting"; } break; case 2: if (config.WindowHealth.VVIPSettings.ContainsKey(prefabname)) { config.WindowHealth.VVIPSettings[prefabname] = value; permset = "VVIPSetting"; } break; case 3: if (config.WindowHealth.RaidableBasesSettings.ContainsKey(prefabname)) { config.WindowHealth.RaidableBasesSettings[prefabname] = value; permset = "RaidableBasesSetting"; } break; } break; case "Frame": switch (subIndex) { case 0: if (config.FrameHealth.DefaultSettings.ContainsKey(prefabname)) { config.FrameHealth.DefaultSettings[prefabname] = value; permset = "DefaultSetting"; } break; case 1: if (config.FrameHealth.VIPSettings.ContainsKey(prefabname)) { config.FrameHealth.VIPSettings[prefabname] = value; permset = "VIPSetting"; } break; case 2: if (config.FrameHealth.VVIPSettings.ContainsKey(prefabname)) { config.FrameHealth.VVIPSettings[prefabname] = value; permset = "VVIPSetting"; } break; case 3: if (config.FrameHealth.RaidableBasesSettings.ContainsKey(prefabname)) { config.FrameHealth.RaidableBasesSettings[prefabname] = value; permset = "RaidableBasesSetting"; } break; } break; } SaveConfig(); if (permset != "") { player.ChatMessage(string.Format(lang.GetMessage("OtherSave", this, player.UserIDString), prefabname, permset, value)); } } #endregion #region CUI Commands [ChatCommand("bhm")] private void OpenBuildingHealthManager(BasePlayer player) { if (!permission.UserHasPermission(player.UserIDString, permAdmin)) { player.SendConsoleCommand("gametip.showtoast_translated", 4, "", string.Format(lang.GetMessage("NoPerm", this, player.UserIDString))); return; } var container = new CuiElementContainer(); var panel = container.Add(new CuiPanel { Image = { Color = "0.1 0.1 0.1 1.0" }, RectTransform = { AnchorMin = "0.2 0.2", AnchorMax = "0.8 0.8" }, CursorEnabled = true }, "Overlay", "bhm_panel"); container.Add(new CuiLabel { Text = { Text = "*Save, then reload plugin", Align = TextAnchor.MiddleCenter, FontSize = 14 }, RectTransform = { AnchorMin = "0 0.89", AnchorMax = "0.21 0.99" } }, panel); container.Add(new CuiLabel { Text = { Text = "Building Health Manager", Align = TextAnchor.MiddleCenter, FontSize = 24 }, RectTransform = { AnchorMin = "0 0.89", AnchorMax = "1 0.99" } }, panel); container.Add(new CuiPanel { Image = { Color = "0.8 0.8 0.8 1" }, RectTransform = { AnchorMin = "0 0.87", AnchorMax = "1 0.88" } }, panel); container.Add(new CuiButton { Button = { Command = $"bhc", Color = "0.75 0.2 0.2 1" }, RectTransform = { AnchorMin = "0.92 0.91", AnchorMax = "0.98 0.97" }, Text = { Text = "X", FontSize = 22, Align = TextAnchor.MiddleCenter } }, panel); string[] categories = new[] { "Building Block", "Door", "External Wall", "Barricade", "Window", "Frame" }; for (int i = 0; i < categories.Length; i++) { container.Add(new CuiButton { Button = { Command = $"bh.showdetails {categories[i]}", Color = "0.2 0.2 0.2 0.7" }, RectTransform = { AnchorMin = $"0.01 {0.72 - i * 0.13}", AnchorMax = $"0.2 {0.82 - i * 0.13}" }, Text = { Text = categories[i], FontSize = 20, Align = TextAnchor.MiddleCenter } }, panel); } CuiHelper.AddUi(player, container); } [ConsoleCommand("inputField")] void ProcessInputField(ConsoleSystem.Arg args) { if (args == null) return; var player = args.Player(); if (player == null) return; if (!permission.UserHasPermission(player.UserIDString, permAdmin)) { player.SendConsoleCommand("gametip.showtoast_translated", 4, "", string.Format(lang.GetMessage("NoPerm", this, player.UserIDString))); return; } var inputId = args.GetString(0); var inputValue = args.GetString(1); InputBoxValues[inputId] = inputValue; } [ConsoleCommand("bh.button")] void ProcessButton(ConsoleSystem.Arg args) { if (args == null) return; var player = args.Player(); if (player == null) return; if (!permission.UserHasPermission(player.UserIDString, permAdmin)) { player.SendConsoleCommand("gametip.showtoast_translated", 4, "", string.Format(lang.GetMessage("NoPerm", this, player.UserIDString))); return; } var category = args.GetString(0); var page = args.GetString(1); var i = args.GetString(2); string value; int intValue; float floatValue; string current = $"{page}{i}"; string needvaule = Currentvalue(category, current); switch (category) { case "Building": if (InputBoxValues.TryGetValue($"input_{category}_{page}_{i}_1", out value) && float.TryParse(value, out floatValue)) { if (config.BuildingBlockHealth.ContainsKey(needvaule)) { config.BuildingBlockHealth[needvaule] = floatValue; player.ChatMessage(string.Format(lang.GetMessage("BuildingBlockSave", this, player.UserIDString), needvaule, floatValue)); SaveConfig(); } } break; case "Door": case "External": case "Barricade": case "Window": case "Frame": for (int j = 0; j < 4; j++) { if (InputBoxValues.TryGetValue($"input_{category}_{page}_{i}_{j}", out value) && int.TryParse(value, out intValue)) { SetValueForSubIndex(category, j, intValue, needvaule, player); } } break; } } [ConsoleCommand("bh.showdetails")] private void ShowCategoryDetails(ConsoleSystem.Arg arg) { var player = arg?.Player(); var args = arg.Args; if (args.Length == 0) return; if (player == null) return; if (!permission.UserHasPermission(player.UserIDString, permAdmin)) { player.SendConsoleCommand("gametip.showtoast_translated", 4, "", string.Format(lang.GetMessage("NoPerm", this, player.UserIDString))); return; } string category = args[0]; int page = 0; if (args.Length > 1 && int.TryParse(args[1], out page)) { playerPageMap[player] = page; } else if (playerPageMap.ContainsKey(player)) { if (page == 0) { playerPageMap[player] = 0; } else { page = playerPageMap[player]; } } else { playerPageMap[player] = page; } CuiHelper.DestroyUi(player, "bhm_panel"); OpenBuildingHealthManager(player); LoadImagesForCategory(player, category, page); } [ConsoleCommand("bhc")] private void CloseBuildingHealthManager(ConsoleSystem.Arg arg) { var player = arg?.Player(); if (arg.Player() == null) return; CuiHelper.DestroyUi(player, "bhm_panel"); } #endregion #region Localization protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { {"NoPerm", "You don't have permission to use that command"}, {"BuildingBlockSave", "The Setting for {0}'s Health have been saved as {1}"}, {"OtherSave", "The {1} for {0}'s Health have been saved as {2}"} }, this); } #endregion } }