using Newtonsoft.Json; using Oxide.Core.Plugins; using System; using System.Collections.Generic; using UnityEngine; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Libraries; using Oxide.Core; using Oxide.Core.Configuration; using Oxide.Game.Rust.Cui; using Network; namespace Oxide.Plugins { [Info("Monument Lock", "Rustonauts", "1.9.5")] [Description("Locks down monuments for players and teams who arrive first, and may broadcast it via chat.")] class MonumentLock : RustPlugin { [PluginReference] private Plugin PuzzlePoints, MonumentFinder, ImageLibrary; ThePermissions Perms; #region Fields private List> _monumentsFinder; private Dictionary timers = new Dictionary(); public List LockedMarkers = new List(); private Configuration _config; private StoredData storedData; //private MUI mui = new MUI(); private string api_hook = ""; //placing timer text on map private Vector3 _monumentPos; private Timer _timer; private float _timeLeft = 600; private const string _RED_KEYCARD = "keycard_red"; #endregion #region Init private void Init() { Perms = new ThePermissions(this); LoadData(); // Initialize the pool with 10 objects ObjectPool.Initialize(8); //LoadImages(); // foreach (var player in BasePlayer.activePlayerList) // { // TopRightCornerCui(player); // MenuButtonCui(player); // } // foreach(BasePlayer _player in BasePlayer.activePlayerList) { // mui.Init(_player, Perms); // timer.Every(60f, () => mui.Refresh(_player)); // } } private void OnPlayerConnected(BasePlayer player) { if (player == null) return; //mui.Init(player, Perms); } #endregion #region Oxide Hooks // void OnEntitySpawned(BaseNetworkable entity) // { // Puts("OnEntitySpawned works!"); // } void OnDestroyUI(BasePlayer player, string json) { //Puts($".. destroy ui: {json}"); } object CanUseUI(BasePlayer player, string json) { //Puts($"..add UI: {json}"); return null; } object OnPlayerDeath(BasePlayer player, HitInfo info) { //if not configed to unlock, abort if(!_config.unlock_on_death) return null; //sessions foreach(MSession _session in new List(storedData.m_sessions)) { //if on a team if(player.currentTeam != 0) { //if player has an actively locked monument if(player.currentTeam.ToString() == _session.GetTeamId()) { //iterate through active players foreach(BasePlayer activePlayer in new List(BasePlayer.activePlayerList)) { if(activePlayer.UserIDString != player.UserIDString && activePlayer.currentTeam.ToString() == _session.GetTeamId()) { //if no other teammate is in the monument, then unlock var dictClosestMonument = MonumentFinder?.Call("API_GetClosestMonument", activePlayer.ServerPosition) as Dictionary; if(_session.SessionMonument.shortName == dictClosestMonument["ShortName"].ToString()) return null; } } UnlockMonument(player, _session); return null; } } //solo if(_session.player_id == player.UserIDString) UnlockMonument(player, _session); } return null; } private object OnPPSwipe(BasePlayer player, string cardType, CardReader cardReader, string monumentName, string gridPosition) { api_hook = "card_swipe"; //guards if(!Perms.CanUse(player)) return null; if(!MonumentEnabled( player )) return null; //can't swipe card if(!LockCheck(player, "swipe")) return false; // PrintToChat($"{GetLang("CardSwipedAt", player.UserIDString, player.displayName, cardType, GetDisplayName(monumentName), gridPosition)}"); BroadcastToChat("CardSwipedAt", player.displayName, cardType, GetDisplayName(monumentName), gridPosition); return null; } object OnItemPickup(Item item, BasePlayer player) { api_hook = "item_pickup"; //guards if(!MonumentEnabled( player )) return null; if(!Perms.CanUse(player)) return null; if(!LockCheck(player, item.info.category.ToString())) return false; return null; } object CanMoveItem(Item item, PlayerInventory playerLoot=null, uint targetContainer=0, int targetSlot=0, int amount=0) { api_hook = "move_item"; // //guards BasePlayer player = playerLoot.loot.GetComponent(); if(!MonumentEnabled( player )) return null; if(!Perms.CanUse(player)) return null; if(!LockCheck(player, item.info.category.ToString())) return false; return null; } void OnLootEntity(BasePlayer player, BaseEntity entity=null) { api_hook = "loot_entity"; if(MonumentEnabled( player ) && Perms.CanUse(player) ) LockCheck(player, entity.ShortPrefabName); } object CanLootEntity(BasePlayer _player, DroppedItemContainer container) { api_hook = "loot_entity"; if(!Perms.CanUse(_player)) return null; if(!MonumentEnabled( _player )) return null; if(!LockCheck(_player, container.ShortPrefabName)) return false; return null; } object CanHackCrate(BasePlayer player, HackableLockedCrate crate=null) { api_hook = "hack_crate"; //guards if(!MonumentEnabled( player )) return null; if(!Perms.CanUse(player)) return null; if(!LockCheck(player, "locked_crate")) return false; return null; } object OnPlayerAttack(BasePlayer attacker, HitInfo info=null) { api_hook = "player_attack"; if(!Perms.CanUse(attacker)) return null; if(!MonumentEnabled( attacker )) return null; if(!LockCheck(attacker, "attack")) return false; return null; } #endregion #region MonumentLock Hooks API private void OnImportFailed() { Puts("-- Failed to import monuments.."); } private void NoPermissions(BasePlayer player, string perm) { player.ChatMessage(GetLang("NoPerms", player.UserIDString)); } private object OnTeamHasActiveSession(BasePlayer player) { player.ChatMessage(GetLang("TeamAlreadyLocked", player.UserIDString)); return true; } private object OnMonumentLocked(BasePlayer player, string displayName, string gridPosition) { Puts($"{GetLang("MonumentLocked", null, player.displayName, displayName, gridPosition)}"); BroadcastToChat("MonumentLocked", player.displayName, displayName, gridPosition); RemoveMapMarkers(); LoadMapMarkers(); // foreach (var player1 in BasePlayer.activePlayerList) // { // NotificationCui(player1, $"{displayName} has been locked by {player.displayName}"); // } return null; } private object OnMonumentUnlocked(BasePlayer player, string displayName, string gridPosition) { BroadcastToChat("MonumentUnlocked", displayName, gridPosition); RemoveMapMarkers(); LoadMapMarkers(); // foreach (var player1 in BasePlayer.activePlayerList) // { // NotificationCui(player1, $"{displayName} is unlocked!"); // } return null; } private object OnAccessDenied(BasePlayer player, string seconds, BasePlayer lockedPlayer) { SendReply(player, GetLang("MonumentIsLocked", player.UserIDString, lockedPlayer.displayName, seconds)); return null; } private object OnAccessGranted(BasePlayer player, string shortName, string gridPosition) { // UpdateLockTimer(shortName); return null; } #endregion API_MonumentLock_Hooks #region Chat [ChatCommand("mu")] private void mu(BasePlayer player, string command, string[] args) { UnlockMonument(player); } [ChatCommand("mlock")] private void mlock(BasePlayer player, string command, string[] args) { //guards if(!Perms.CanUse(player) && !Perms.CanCommands(player)) return; //user typed /mlock if (args.Length < 1) { //launch ui //if(Perms.CanUiView(player)) mui.Toggle(player); } //user typed /mlock else if(args.Length == 1) { if(args[0] == "list") { MonumentsListReply(player); } else if(args[0] == "clear") { if(!Perms.IsAdmin(player)) return; storedData.m_sessions.Clear(); RemoveMapMarkers(true); } else if(args[0] == "unlock") { //player type /mlock unlock in chat to unlock a monument UnlockMonument(player); } //user typed /mlock else { if(MonumentEnabled(player, args[0] )) { if(!LockCheck( player, "chat", args[0])) { SendReply(player, GetLang("MonumentAlreadyLocked")); } } else { SendReply(player, GetLang("MonumentNotValid")); MonumentsListReply(player); } } } //admin locking monument for a player /mlock else if(args.Length == 2) { //guard if(!Perms.IsAdmin(player)) return; //2nd argument is player_name string locked_playerName = args[1]; BasePlayer locked_player = BasePlayer.FindAwakeOrSleeping(locked_playerName); if(MonumentEnabled(player, args[0] )) { if(!LockCheck( locked_player, "chat", args[0])) { //SendReply(player, GetLang("MonumentAlreadyLocked")); } } else { SendReply(player, GetLang("MonumentNotValid")); MonumentsListReply(player); } } } #endregion #region Console [ConsoleCommand("mlock.mem")] private void mem(ConsoleSystem.Arg arg) { PrintMemoryUsage(); } [ConsoleCommand("mu")] private void mU(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); if(player == null) return; UnlockMonument(player); //mui.Toggle(player, arg.Args[0]); } [ConsoleCommand("mlock")] private void mLock(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); if(!LockCheck(player, "chat", arg.Args[0])) { SendReply(player, GetLang("MonumentAlreadyLocked")); } //mui.Toggle(player, arg.Args[0]); } [ConsoleCommand("mui.toggle")] private void mToggle(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); if(player == null) return; //mui.Toggle(player); } [ConsoleCommand("mui.refresh")] private void MuiRefresh(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); // mui.Show(player, ref storedData, ref _config); } [ConsoleCommand("mui.config")] private void MuiConfig(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); // mui.ShowConfig(player, ref storedData, ref _config); } [ConsoleCommand("mui.config.hardtimer")] private void MuiConfigHardtimer(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); if(player == null) return; _config.hard_timer = ! _config.hard_timer; SaveConfig(); player.SendConsoleCommand("mui.config"); player.SendConsoleCommand("mui.config"); } [ConsoleCommand("mui.config.maxtimer")] private void MuiConfigMaxtimer(ConsoleSystem.Arg arg) { BasePlayer player = arg.Player(); if(player == null) return; _config.enable_max_timer = ! _config.enable_max_timer; SaveConfig(); player.SendConsoleCommand("mui.config"); player.SendConsoleCommand("mui.config"); } [ConsoleCommand("mui.closeall")] void CloseAllMUI(ConsoleSystem.Arg args) { // MUI.CloseAll(); } [ConsoleCommand("mui.sync")] private void SyncMonuments(ConsoleSystem.Arg arg) { ImportMonuments(); BasePlayer _player = arg.Player(); if(_player == null) return; // mui.SyncMonuments(_player); } [ConsoleCommand("mlock.import")] void ImportMonuments(ConsoleSystem.Arg args) { ImportMonuments(); Puts($"{GetLang("MonumentsImported", null)}"); } [ConsoleCommand("mlock.default")] void DefaultMonuments(ConsoleSystem.Arg args) { _config.Monuments.Clear(); SaveConfig(); DefaultMonuments(); Puts($"{GetLang("MonumentsDefaulted", null)}"); } [ConsoleCommand("mlock.fresh")] void FreshMonuments(ConsoleSystem.Arg args) { _config.Monuments.Clear(); DefaultMonuments(); ImportMonuments(); Puts($"{GetLang("MonumentsImported", null)}"); } [ConsoleCommand("mlock.remove")] void ClearMonuments(ConsoleSystem.Arg args) { _config.Monuments.Clear(); SaveConfig(); Puts($"{GetLang("MonumentsRemoved", null)}"); } #endregion Commands #region Pooling private void PrintMemoryUsage() { // Force garbage collection for accurate measurement GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); // Get total memory in bytes long memoryUsageByes = GC.GetTotalMemory(false); double memoryUsageMB = memoryUsageByes / (1024.0 * 1024.0); Puts($"memory usage: {memoryUsageMB:F2} MB"); } public static class ObjectPool where T : class, new() { private static readonly Stack _pool = new Stack(); // Pre-populate the pool with a specified number of objects public static void Initialize(int initialSize) { for (int i = 0; i < initialSize; i++) { _pool.Push(new T()); } } public static T Get() { return _pool.Count > 0 ? _pool.Pop() : new T(); } public static void Free(ref T obj) { if (obj == null) return; _pool.Push(obj); obj = null; } } public interface IPooled{ void ResetToPool(); } #endregion #region Core private MSession GetSession(BasePlayer player) { foreach(MSession _session in storedData.m_sessions) { //is player the monument owner if(_session.GetPlayerId() == player.UserIDString) { return _session; } //no? else { //is the player on the team of the monument owner? if( (player.currentTeam > 0) && (_session.GetTeamId() == player.currentTeam.ToString()) ) { return _session; } } } return null; } private string FindMonumentShortName(BasePlayer _player, string _shortNameFromCommand) { if(_shortNameFromCommand != null) return _shortNameFromCommand; //check monuments var dictMonument = IsInMonument(_player); if(dictMonument != null) return dictMonument["ShortName"].ToString(); //check if we're in cargo foreach(var entity in BaseNetworkable.serverEntities) { if(entity is CargoShip) { var cargo = (entity as CargoShip); if(Vector3.Distance(cargo.transform.position, _player.transform.position) < 100) return "cargo_ship"; } } return null; } private bool IsSessionActive(BasePlayer _player, MSession _session) { if(!_session.IsActive()) { UnlockMonument(_player, _session); SaveData(); return false; } SaveData(); return true; } private bool LockCheck(BasePlayer player, string loot="", string _shortNameFromCommand=null) { var _shortName = FindMonumentShortName(player, _shortNameFromCommand); var is_locked = false; if(_shortNameFromCommand == null && _shortName == null) return true; //player isn't in monument foreach(MSession _session in storedData.m_sessions) { if(_session.SessionMonument.shortName == _shortName) { if(IsSessionActive(player, _session)) { is_locked = true; SaveData(); //active session found if(!_session.IsLockedToMyTeam(player)) { //if cancel_cards global is turned off, stop here and grant access to swiping if(loot == "swipe" && !_config.cancel_cards && !_session.IsCancelCards()) return true; //if lock_attack global is turned off, stop here and grant access to attacking if(loot == "attack" && !_config.lock_attack && !_session.IsLockAttack()) return true; //if lock_crate_hacking global is turned off, stop here and grant access to crate hacking if(loot == "locked_crate" && !_config.lock_crate_hacking && !_session.IsLockedCrate()) return true; //if food crate if(loot == "trash-pile-1" || loot == "food") return true; //if lock_looting monument is turned off, stop here and grant access to looting if(!_config.lock_looting && !_session.IsLockLooting()) return true; return false; } //it is locked to my team Interface.Call("OnAccessGranted", player, _shortName, GetGridPosition(player.ServerPosition)); return true; } return LockMonument(_shortName, player, GetGridPosition(player.ServerPosition)); } } //monument not in an active sessions, lock monument and create session return LockMonument(_shortName, player, GetGridPosition(player.ServerPosition));; } private Dictionary IsInMonument(BasePlayer player) { var dictClosestMonument = MonumentFinder?.Call("API_GetClosestMonument", player.ServerPosition) as Dictionary; if(dictClosestMonument != null) { var IsInBounds = ((Func)dictClosestMonument["IsInBounds"]).Invoke(player.ServerPosition); if(IsInBounds && MonumentInConfig(dictClosestMonument["ShortName"].ToString())) return dictClosestMonument; } //clean up all locked monuments for this player, if no active session. but if there is, cannot unlock MyTeamHasActiveSession(player); return null; } private bool MonumentInConfig(string _shortName) { foreach(Monument _monument in _config.Monuments) { if(_monument.shortName == _shortName) return true; } return false; } private void UnlockMonument(BasePlayer player, MSession _expired_session=null) { bool unlocked = false; MSession unlockedSession = _expired_session ?? GetSession(player); //find my team session // if(unlockedSession == null) unlockedSession = GetSession(player); if (unlockedSession != null) { unlocked = true; // Cancel the timer if it exists unlockedSession.UnlockTimer?.Destroy(); unlockedSession.UnlockTimer = null; } //if the config hard timer is true and monument.hard_timer is true, and is active then don't unlock if(_config.hard_timer && unlockedSession.SessionMonument.hard_timer && unlockedSession.IsActive()) unlocked = false; //if the player or team has a locked monument if(unlocked) { storedData.m_sessions.Remove(unlockedSession); SaveData(); Interface.Call("OnMonumentUnlocked", player, unlockedSession.SessionMonument.displayName, GetGridPosition(player.ServerPosition)); ObjectPool.Free(ref unlockedSession); } return; } private bool LockMonument(string shortName, BasePlayer player, string gridPosition) { if(MyTeamHasActiveSession(player)) { if (Interface.Call("OnTeamHasActiveSession", player) != null) { return false; } } //does the current player action allow for locking a monument if(!CanActionLock()) return false; //get monuments from config foreach(Monument _monument in _config.Monuments) { //find the monument in _config by short name if(_monument.shortName == shortName) { if (Interface.Call("CanMonumentLock", player, _monument.displayName, gridPosition) != null) { return false; } // MSession _mSession = Facepunch.Pool.Pool.Get().Initialize(player.UserIDString, _monument); MSession _mSession = ObjectPool.Get().Initialize(player.UserIDString, _monument); storedData.m_sessions.Add(_mSession); SaveData(); if (_config.hard_timer || _monument.hard_timer) { _mSession.UnlockTimer = timer.Once(_monument.lock_timer, () => { LockCheck(player); }); } if (Interface.Call("OnMonumentLocked", player, _monument.displayName, gridPosition) != null) { return false; } return true; } } return false; } #endregion Core #region External Plugins API private List> GetMonuments(string filter = null) { if(UseMonumentFinder()) return MonumentFinder.Call("API_FindMonuments", filter) as List>; return null; } #endregion #region Configuration private void DisableMonuments() { //make config monuments disabled foreach(Monument _monument in _config.Monuments) { if(_monument.shortName != "cargo_ship") { _monument.enabled = false; _monument.is_online = false; } } SaveConfig(); } private void ImportMonuments() { //enabled should never be adjusted, it's how the plugin knows if the monument is on the map //is_online is a dynamic state, and admins/other plugins can adjust it _monumentsFinder = GetMonuments(); if(_monumentsFinder == null) Interface.Call("OnImportFailed"); if(_monumentsFinder == null) return; DisableMonuments(); //iteration through the monuments from Monument Finder foreach( Dictionary _monument in _monumentsFinder) { bool import_monument = true; //ignore monuments from the exceptions list (in config file) foreach( string _exception in _config.Exceptions) { if(_exception == _monument["ShortName"].ToString()) { import_monument = false; } } //updating existing monuments foreach(Monument _configMonument in _config.Monuments) { if(_configMonument.shortName == _monument["ShortName"].ToString() && _configMonument.shortName != "cargo_ship") { _configMonument.enabled = true; _configMonument.is_online = true; _configMonument.gridPos = GetGridPosition((Vector3)_monument["Position"]); _configMonument.prefabName = _monument["PrefabName"].ToString(); //do something around the icon import_monument = false; } } //importing new monuments if(import_monument) { _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, is_online = true, prefabName = _monument["PrefabName"].ToString(), shortName = _monument["ShortName"].ToString(), displayName = _monument["ShortName"].ToString(), gridPos = GetGridPosition((Vector3)_monument["Position"]), lock_attack = true, lock_crate_hacking = true, lock_timer = 600, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" //do something to import })); } } SaveConfig(); } private void DefaultMonuments() { _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "", shortName = "cargo_ship", displayName = "Cargo Ship", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 1500, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/harbor/harbor_1.prefab", shortName = "harbor_1", displayName = "Large Harbor", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/ND4c70v.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/harbor/harbor_2.prefab", shortName = "harbor_2", displayName = "Small Harbor", gridPos = "", lock_looting = true, lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/ND4c70v.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/arctic_bases/arctic_research_base_a.prefab", shortName = "arctic_research_base_a", displayName = "Arctic Research Base", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/large/military_tunnel_1.prefab", shortName = "military_tunnel_1", displayName = "Military Tunnel", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/6RwXvC2.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/large/powerplant_1.prefab", shortName = "powerplant_1", displayName = "Power Plant", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/ZxqiBc6.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/small/sphere_tank.prefab", shortName = "sphere_tank", displayName = "Dome", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon = "https://i.imgur.com/mPRgBF2.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "oilrig_1", shortName = "oilrig_1", displayName = "Large Oil", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/AAhZO7k.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "radtown_1", shortName = "radtown_1", displayName = "Radtown", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/AAhZO7k.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "oilrig_2", shortName = "oilrig_2", displayName = "Small Oil", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/AAhZO7k.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/large/launch_site_1.prefab", shortName = "launch_site_1", displayName = "Launch", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/gjdynsc.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/military_bases/desert_military_base_a.prefab", shortName = "desert_military_base_a", displayName = "Milly Base", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/medium/radtown_small_3.prefab", shortName = "radtown_small_3", displayName = "Sewer Branch", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon = "https://i.imgur.com/PbKZQdZ.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/large/water_treatment_plant_1.prefab", shortName = "water_treatment_plant_1", displayName = "Water Treatment Plant", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="https://i.imgur.com/5L2Gdag.png" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/small/satellite_dish.prefab", shortName = "satellite_dish", displayName = "Satellite Dish", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon = "https://i.imgur.com/XwSpCJY.png" })); // _config.Monuments.Add (new Monument(new MonumentSettings // { // enabled = true, // prefabName = "assets/bundled/prefabs/autospawn/monument/underwater_lab/underwater_lab_a.prefab", // shortName = "underwater_lab_a", // displayName = "Underwater Lab A", // gridPos = "", // lock_attack = true, // lock_crate_hacking = true, // lock_timer = 600, // hard_timer = false, // lock_looting = true, // cancel_cards = true, // enable_broadcasting = true, // icon = "" // })); // _config.Monuments.Add (new Monument(new MonumentSettings // { // enabled = true, // prefabName = "assets/bundled/prefabs/autospawn/monument/underwater_lab/underwater_lab_b.prefab", // shortName = "underwater_lab_b", // displayName = "Underwater Lab B", // gridPos = "", // lock_attack = true, // lock_crate_hacking = true, // lock_timer = 600, // hard_timer = false, // lock_looting = true, // cancel_cards = true, // enable_broadcasting = true, // icon = "" // })); // _config.Monuments.Add (new Monument(new MonumentSettings // { // enabled = true, // prefabName = "assets/bundled/prefabs/autospawn/monument/underwater_lab/underwater_lab_c.prefab", // shortName = "underwater_lab_c", // displayName = "Underwater Lab C", // gridPos = "", // lock_attack = true, // lock_crate_hacking = true, // lock_timer = 600, // hard_timer = false, // lock_looting = true, // cancel_cards = true, // enable_broadcasting = true, // icon = "" // })); // _config.Monuments.Add (new Monument(new MonumentSettings // { // enabled = true, // prefabName = "assets/bundled/prefabs/autospawn/monument/underwater_lab/underwater_lab_d.prefab", // shortName = "underwater_lab_d", // displayName = "Underwater Lab D", // gridPos = "", // lock_attack = true, // lock_crate_hacking = true, // lock_timer = 600, // hard_timer = false, // lock_looting = true, // cancel_cards = true, // enable_broadcasting = true, // icon="" // })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/harbor/ferry_terminal_1.prefab", shortName = "ferry_terminal_1", displayName = "Ferry Terminal", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/medium/nuclear_missile_silo.prefab", shortName = "nuclear_missile_silo", displayName = "Nuclear Silo", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/large/excavator_1.prefab", shortName = "excavator_1", displayName = "Excavator", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/large/airfield_1.prefab", shortName = "airfield_1", displayName = "Airfield", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); _config.Monuments.Add (new Monument(new MonumentSettings { enabled = true, prefabName = "assets/bundled/prefabs/autospawn/monument/medium/junkyard_1.prefab", shortName = "junkyard_1", displayName = "Junkyard", gridPos = "", lock_attack = true, lock_crate_hacking = true, lock_timer = 600, hard_timer = false, lock_looting = true, cancel_cards = true, enable_broadcasting = true, icon="" })); SaveConfig(); } protected override void LoadConfig() { base.LoadConfig(); try { _config = Config.ReadObject(); if (_config == null) throw new Exception(); Puts("Config loaded"); } catch { Puts("config error, create defaults"); LoadDefaultConfig(); } //if(!IsConfigCompatible()) LoadDefaultConfig(); } protected override void LoadDefaultConfig() { _config = new Configuration(); DefaultMonuments(); SaveConfig(); } protected override void SaveConfig() { Config.WriteObject(_config, true); } protected bool IsConfigCompatible() { string gridPos; foreach(Monument _monument in _config.Monuments) { try{ gridPos = _monument.gridPos; } catch{ return false; } if(gridPos == null) return false; } return true; } public struct MonumentSettings { [JsonProperty(PropertyName = "Enabled: Is Monument enabled?")] public bool enabled; [JsonProperty(PropertyName = "is_online: Is Monument online and able to be locked?")] public bool is_online; [JsonProperty(PropertyName = "Lock Looting: When a player enters this monument while locked, do we lock their looting abilities?")] public bool lock_looting; [JsonProperty(PropertyName = "Lock Attack: When a player enters a locked monument, do we lock their attacking abilities?")] public bool lock_attack; [JsonProperty(PropertyName = "Cancel Cards: When a player enters this monument while locked, do we lock their card swiping abilities?")] public bool cancel_cards; [JsonProperty(PropertyName = "Lock Crate: When a player enters this monument while locked, do we lock their hacking on locked crates?")] public bool lock_crate_hacking; [JsonProperty(PropertyName = "Broadcasting: Do we want this plugin to broadcast to the server when this monument is locked?")] public bool enable_broadcasting; [JsonProperty(PropertyName = "Monument Display Name")] public string displayName; [JsonProperty(PropertyName = "Monument Prefab Name")] public string prefabName; [JsonProperty(PropertyName = "Monument Short Name")] public string shortName; [JsonProperty(PropertyName = "Monument Grid Position")] public string gridPos; [JsonProperty(PropertyName = "Lock timer (600 = 10 min)?")] public int lock_timer; [JsonProperty(PropertyName = "Only timer expiration will unlock a monument ")] public bool hard_timer; [JsonProperty(PropertyName = "Monument Icon")] public string icon; } public class Monument { [JsonProperty(PropertyName = "enabled: Is Monument enabled and to be used in this map?")] public bool enabled; [JsonProperty(PropertyName = "is_online: Is Monument online and able to be locked?")] public bool is_online { get; set; } = true; [JsonProperty(PropertyName = "Lock Looting: When a player enters this monument while locked, do we lock their looting abilities?")] public bool lock_looting; [JsonProperty(PropertyName = "Lock Attack: When a player enters a locked monument, do we lock their attacking abilities?")] public bool lock_attack { get; set; } = true; [JsonProperty(PropertyName = "Cancel Cards: When a player enters this monument while locked, do we lock their card swiping abilities?")] public bool cancel_cards; [JsonProperty(PropertyName = "Lock Crate: When a player enters this monument while locked, do we lock their hacking on locked crates?")] public bool lock_crate_hacking; [JsonProperty(PropertyName = "Broadcasting: Do we want this plugin to broadcast to the server when this monument is locked?")] public bool enable_broadcasting; [JsonProperty(PropertyName = "Monument Display Name")] public string displayName; [JsonProperty(PropertyName = "Monument Prefab Name")] public string prefabName; [JsonProperty(PropertyName = "Monument Short Name")] public string shortName; [JsonProperty(PropertyName = "Monument Grid Position")] public string gridPos; [JsonProperty(PropertyName = "Monument Icon")] public string icon; [JsonProperty(PropertyName = "Lock timer (600 = 10 min)?")] public int lock_timer { get; set; } = 600; [JsonProperty(PropertyName = "Only timer expiration will unlock a monument ")] public bool hard_timer { get; set; } = false; public Monument() { } public Monument(MonumentSettings settings) { enabled = settings.enabled; is_online = settings.is_online; lock_looting = settings.lock_looting; lock_attack = settings.lock_attack; cancel_cards = settings.cancel_cards; lock_crate_hacking = settings.lock_crate_hacking; enable_broadcasting = settings.enable_broadcasting; displayName = settings.displayName; prefabName = settings.prefabName; shortName = settings.shortName; lock_timer = settings.lock_timer; icon = settings.icon; } } private class Configuration { // public List EnabledMonuments() // { // private List _enabled = new List{}; // foreach(Monument _monument in Monuments) { // if(_monument.enabled) _enabled.Add(_monument); // } // return _enabled; // } [JsonProperty(PropertyName = "Lock timer (600 = 10 min)?")] public int lock_timer { get; set; } = 600; [JsonProperty(PropertyName = "Hard timer: Only timer expiration will unlock a monument ")] public bool hard_timer { get; set; } = false; [JsonProperty(PropertyName = "Enable max timer (regardless of how active player is)?")] public bool enable_max_timer { get; set; } = false; [JsonProperty(PropertyName = "Max timer (1200 = 20 min)?")] public int max_timer { get; set; } = 1200; [JsonProperty(PropertyName = "When a player enters a locked monument, do we lock their looting abilities?")] public bool lock_looting { get; set; } = true; [JsonProperty(PropertyName = "When a player enters a locked monument, do we lock their card swiping abilities?")] public bool cancel_cards { get; set; } = true; [JsonProperty(PropertyName = "When a player enters a locked monument, do we lock their locked crate hacking abilities?")] public bool lock_crate_hacking { get; set; } = true; [JsonProperty(PropertyName = "When a player enters a locked monument, do we lock their attacking abilities?")] public bool lock_attack { get; set; } = true; [JsonProperty(PropertyName = "When a player dies, do we unlock the monument?")] public bool unlock_on_death { get; set; } = true; [JsonProperty(PropertyName = "Can player lock monument from looting?")] public bool onLootEntity { get; set; } = true; [JsonProperty(PropertyName = "Can player lock monument from moving inventory items?")] public bool canMoveItem { get; set; } = true; [JsonProperty(PropertyName = "Can player lock monument from Puzzle Points card swipe?")] public bool onPPSwipe { get; set; } = true; [JsonProperty(PropertyName = "Can player lock monument from picking up an item?")] public bool onItemPickup { get; set; } = true; [JsonProperty(PropertyName = "Can player lock monument from attacking?")] public bool onPlayerAttack { get; set; } = true; [JsonProperty(PropertyName = "Do we want this plugin to broadcast to the server when a monument is locked?")] public bool enable_broadcasting { get; set; } = true; [JsonProperty(PropertyName = "Monuments", ObjectCreationHandling = ObjectCreationHandling.Replace)] public List Monuments = new List{}; [JsonProperty(PropertyName = "Monument Exceptions", ObjectCreationHandling = ObjectCreationHandling.Replace)] public List Exceptions = new List { "bandit_town", "cave_large_hard", "cave_large_medium", "cave_large_sewers_hard", "cave_medium_easy", "cave_medium_hard", "cave_medium_medium", "cave_small_easy", "cave_small_hard", "cave_small_medium", "compound", "entrance_bunker_a", "entrance_bunker_b", "entrance_bunker_c", "entrance_bunker_d", "fishing_village_a", "fishing_village_b", "fishing_village_c", "ice_lake_1", "ice_lake_2", "ice_lake_3", "ice_lake_4", "mining_quarry_a", "mining_quarry_b", "mining_quarry_c", "stables_a", "stables_b", "swamp_a", "swamp_b", "swamp_c", "water_well_a", "water_well_b", "water_well_c", "water_well_d", "water_well_e", "power_sub_big_1", "power_sub_big_2", "power_sub_small_1", "power_sub_small_2", "underwater_lab_a", "underwater_lab_b", "underwater_lab_c", "underwater_lab_d", "lighthouse", "warehouse" }; } #endregion Configuration #region DataFile private void LoadData() { try { Puts("loading datafile..{0}", Name.ToString()); storedData = Interface.Oxide.DataFileSystem.ReadObject(Name); Puts("Datafile loaded"); } catch { storedData = null; } if (storedData == null) { Puts("-- no datafile, creating new.."); ClearData(); } } private void SaveData() { //Puts("-- saving data.."); Interface.Oxide.DataFileSystem.WriteObject(Name, storedData); //Puts("-- data saved!"); } private void ClearData() { storedData = new StoredData(); SaveData(); } #endregion DataFile #region Helpers private bool UseMonumentFinder() { if(MonumentFinder != null && MonumentFinder.IsLoaded) return true; return false; } private void BroadcastToChat(string langkey, params object[] args) { for (int i=0; i < BasePlayer.activePlayerList.Count; i++) { BasePlayer player = BasePlayer.activePlayerList[i]; player.ChatMessage(GetLang(langkey, player.UserIDString, args)); } } private bool MyTeamHasActiveSession(BasePlayer player) { MSession session = GetSession(player); if(session != null && IsSessionActive(player, session)) return true; return false; } private bool CanActionLock() { if(api_hook == "card_swipe" && !_config.onPPSwipe) return false; if(api_hook == "item_pickup" && !_config.onItemPickup) return false; if(api_hook == "move_item" && !_config.canMoveItem) return false; if(api_hook == "loot_entity" && !_config.onLootEntity) return false; if(api_hook == "player_attack" && !_config.onPlayerAttack) return false; return true; } private void LoadMapMarkers() { RemoveMapMarkers(); _monumentsFinder = GetMonuments(); foreach(MSession _session in storedData.m_sessions) { foreach(Dictionary _monumentFind in _monumentsFinder) { if(_monumentFind["ShortName"].ToString() != "cargo_ship") { if(_monumentFind["ShortName"].ToString() == _session.SessionMonument.shortName.ToString()) { _monumentPos = (Vector3)_monumentFind["Position"]; } } } if(_session.SessionMonument.shortName.ToString() != "cargo_ship") { //put a marker on it. MapMarkerGenericRadius mapMarker = GameManager.server.CreateEntity("assets/prefabs/tools/map/genericradiusmarker.prefab", _monumentPos) as MapMarkerGenericRadius; mapMarker.alpha = 0.35f; mapMarker.color1 = Color.red; mapMarker.color2 = Color.red; //mapMarker.name = timeLeftStr; mapMarker.radius = 1.1f; LockedMarkers.Add(mapMarker); mapMarker.Spawn(); mapMarker.SendUpdate(); } } } private void RemoveMapMarkers(bool all=false) { foreach (MapMarkerGenericRadius marker in LockedMarkers) { if (marker != null) { marker.Kill(); marker.SendUpdate(); } } LockedMarkers.Clear(); } private void MonumentsListReply(BasePlayer player) { //display a list of valid monuments string output = ""; foreach(Monument _configMonument in _config.Monuments) { output += "" + _configMonument.displayName + " | " + _configMonument.shortName + "\n"; } SendReply(player, output); } private bool MonumentEnabled(BasePlayer player, string _shortNameFromCommand = null) { var _shortName = FindMonumentShortName(player, _shortNameFromCommand); if(_shortName == null) return false; foreach(Monument _monument in _config.Monuments) { if(_monument.shortName == _shortName) { return _monument.enabled; } } return false; } private string GetDisplayName(string shortName) { foreach(Monument _monument in _config.Monuments) { if(_monument.shortName == shortName) { return _monument.displayName; } } return ""; } private bool UsePP() { //if(!configData.useEconomics) return false; if(PuzzlePoints == null) return false; if(!PuzzlePoints.IsLoaded) return false; return true; } //copied from DiscordLogger private string GetGridPosition(Vector3 position) => MapHelper.PositionToString(position); //copied from Give private string GetLang(string langKey, string playerId = null, params object[] args) { return string.Format(lang.GetMessage(langKey, this, playerId), args); } #endregion Helpers #region Localization protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["MonumentLocked"] = "{0} locked {1} at ({2})", ["MonumentUnlocked"] = "{0} at ({1}) is now unlocked.", ["MonumentIsLocked"] = "This monument is already locked by {0} {1} seconds ago", ["CardSwipedAt"] = "{0} swiped a {1} card at {2} ({3})!", ["CardSwipedCancel"] = "You don't have card reader access right now.", ["ZeroArgs"] = "Syntax: mlock (eg. mlock import)", ["MonumentsImported"] = "Monuments imported.", ["MonumentsRemoved"] = "Monuments removed.", ["MonumentsDefaulted"] = "Monuments reset to default.", ["MonumentAlreadyLocked"] = "This monument is locked to another player.", ["MonumentNotValid"] = "This is not a valid monument name..", ["NoPerms"] = "You don't have permissions to use this command", ["TeamAlreadyLocked"] = "You or your team already has a locked monument.", }, this); } #endregion Localization #region Permissions class ThePermissions { MonumentLock mlock; public const string _USE = "monumentlock.use"; public const string _COMMANDS = "monumentlock.commands"; public const string _ADMIN = "monumentlock.admin"; public const string _UI_VIEW = "monumentlock.ui.view"; public const string _UI_USE = "monumentlock.ui.use"; List permissions; public ThePermissions(MonumentLock _mlock) { permissions = new List() { _USE, _ADMIN, _COMMANDS, _UI_VIEW, _UI_USE }; mlock = _mlock; RegisterPermissions(); } public bool CanUse(BasePlayer _player) { return HasPermission(_player, _USE); } public bool CanUiUse(BasePlayer _player) { return HasPermission(_player, _UI_USE); } public bool CanUiView(BasePlayer _player) { return HasPermission(_player, _UI_VIEW); } public bool CanCommands(BasePlayer _player) { return HasPermission(_player, _COMMANDS); } public bool IsAdmin(BasePlayer _player) { return HasPermission(_player, _ADMIN); } private bool HasPermission(BasePlayer player, string perm) { if(mlock.permission.UserHasPermission(player.UserIDString, perm)) return true; Interface.Call("NoPermissions", player, perm); return false; } private void RegisterPermissions() { foreach (string _permission in permissions) { mlock.permission.RegisterPermission(_permission, mlock); } } } #endregion #region Classes private class StoredData { public List m_sessions { get; set; } = new List(); ///locking benefits ///locking restrictions ///set time ///variable time ///behaviour public StoredData() { } public StoredData(List _sessions) { m_sessions = _sessions; } public bool IsSessionActive(MSession session) { foreach(MSession _session in m_sessions) { if(_session.SessionMonument.shortName == session.SessionMonument.shortName) { if(_session.IsActive()) return true; } } return false; } public MSession FindByShortName(string _shortname) { foreach(MSession _session in m_sessions) { if(_session.SessionMonument.shortName == _shortname) { return _session; } } return null; } } private class MSession { // private string[] lock_trigger_types = { "ACTIVITY", "COMMAND" }; // private string[] unlock_trigger_types = { "ACTIVITY", "COMMAND", "TIME" }; // private string lock_trigger; // private string unlock_trigger; [JsonIgnore] public Timer UnlockTimer { get; set; } [JsonProperty("Player Id")] public string player_id; [JsonProperty("Locked by admin?")] private bool locked_by_admin {get; set;} = false; [JsonProperty("Team ID")] private string team_id; [JsonProperty("Monument")] public Monument SessionMonument = new Monument(); [JsonProperty("Session started_at")] private string started_at; [JsonProperty("Session updated_at")] private string updated_at; [JsonProperty("Session ended_at")] private string ended_at; [JsonProperty("Session duration(sec)")] private double duration; [JsonProperty("Session lock timer(sec)")] private int lock_timer; public MSession() {} public MSession Initialize(string _player_id, Monument _monument, bool is_admin=false) { player_id = _player_id; team_id = GetPlayer(_player_id).currentTeam.ToString(); SessionMonument = _monument; locked_by_admin = is_admin; started_at = DateTime.Now.ToString(); updated_at = DateTime.Now.ToString(); //lock_trigger = trigger_type; duration = 0; lock_timer = _monument.lock_timer; return this; } public bool IsLockLooting() {return SessionMonument.lock_looting;} public bool IsCancelCards() {return SessionMonument.cancel_cards;} public bool IsLockAttack() {return SessionMonument.lock_attack;} public bool IsLockedCrate() {return SessionMonument.lock_crate_hacking;} public string GetPlayerId() {return player_id;} public string GetTeamId() {return team_id;} public BasePlayer GetPlayer(string _player_id){return BasePlayer.FindAwakeOrSleeping(_player_id);} public void UpdateDuration() { DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Parse(started_at); TimeSpan lock_time = dt1-dt2; updated_at = dt1.ToString(); duration = Math.Truncate(lock_time.TotalSeconds); return; } public double GetRemaining() { UpdateDuration(); return lock_timer - duration; } public bool IsActive() { UpdateDuration(); if(duration < SessionMonument.lock_timer) return true; return false; } public bool IsLockedToMyTeam(BasePlayer player) { //am i on a team if(player.currentTeam > 0) return player.currentTeam.ToString() == GetTeamId(); return player.UserIDString == GetPlayerId(); } public void Reset() { player_id = null; locked_by_admin = false; team_id = null; SessionMonument = new Monument(); started_at = null; updated_at = null; duration = 0; lock_timer = 0; } } #endregion // #region MUI // private class MUI // { // private CuiElementContainer btnContainer = new CuiElementContainer(); // private CuiElementContainer container = new CuiElementContainer(); // private CuiElementContainer configContainer = new CuiElementContainer(); // private CuiPanel panel; // private CuiPanel btnPanel; // private CuiPanel configPanel; // private BasePlayer player; // private ThePermissions perms; // //MUI // private const double _MAIN_PANEL_HEIGHT = 0.595; // private const double _MAIN_PANEL_WIDTH = 0.33; // private const double _MAIN_PANEL_BASE_X = 0.65; // private const double _MAIN_PANEL_BASE_Y = 0.305; // private const double _MAIN_PANEL_MAX_X = _MAIN_PANEL_BASE_X + _MAIN_PANEL_WIDTH; // private const double _MAIN_PANEL_MAX_Y = _MAIN_PANEL_BASE_Y + _MAIN_PANEL_HEIGHT; // private const double _CONFIG_PANEL_HEIGHT = 0.360; // private const double _CONFIG_PANEL_WIDTH = 0.300; // private const double _CONFIG_PANEL_BASE_X = .5 - (_CONFIG_PANEL_WIDTH / 2); // private const double _CONFIG_PANEL_BASE_Y = .5 - (_CONFIG_PANEL_HEIGHT / 2); // private const double _CONFIG_PANEL_MAX_X = _CONFIG_PANEL_BASE_X + _CONFIG_PANEL_WIDTH; // private const double _CONFIG_PANEL_MAX_Y = _CONFIG_PANEL_BASE_Y + _CONFIG_PANEL_HEIGHT; // private string currentMonumentShortName=null; // private bool showButton = true; // private bool muiToggle = false; // private bool configToggle = false; // private string layer = _LAYER_OVERLAY; // private const string _MAIN_PANEL = "mui-panel"; // private const string _CONFIG_PANEL = "config-panel"; // private const string _BUTTON_PANEL = "btn-panel"; // private const string _MONUMENTS_PANEL = "monuments-panel"; // private const string _LAYER_OVERLAY = "Overlay"; // private const string _LAYER_OVERALL = "Overall"; // private const string _LAYER_HUD = "Hud"; // private const string _LAYER_UNDER = "Under"; // private const string _LAYER_HUD_MENU = "Hud.Menu"; // public MUI() // { // layer = _LAYER_OVERLAY; // var color = "0 0 0 .5"; //grey transparent // //var color = "1 0 1 0.65"; //fucia // } // public void Init(BasePlayer _player, ThePermissions _perms) // { // perms = _perms; // player = _player; // UI.Close(player, _BUTTON_PANEL); // UI.Close(player, _MAIN_PANEL); // UI.Close(player, _CONFIG_PANEL); // if(perms.CanUiView(_player)) { // btnContainer = new CuiElementContainer(); // ButtonPanel(); // UI.Create(player, btnContainer); // } // } // // private void UpdateMonuments(CuiTextComponent txtRemainingTime, MSession mSession, BasePlayer player, CuiElementContainer container, string elTimerName) // // { // // txtRemainingTime.Text = mSession.GetRemaining().ToString(); // // //Puts($"-- isactive: {storedData.IsSessionActive(mSession)}"); // // if(!storedData.IsSessionActive(mSession)){ // // //Puts("--Session Inactive"); // // foreach (var kvp in timers) { // // if(kvp.Key == elTimerName) { // // //timers.Remove(elTimerName); // // Timer t = kvp.Value; // // t.Destroy(); // // } // // } // // UnlockMonument(player); // // //Puts("-- completed destroying timer"); // // //CuiHelper.DestroyUi(player, elTimerName); // // player.SendConsoleCommand("ToggleMonumentLockWindow"); // // } // // else // // { // // //Puts("--time in active session"); // // if(isInMonumentLockMenu[player.userID]) { // // //CuiHelper.DestroyUi(player, elTimerName); // // //CuiHelper.AddUi(player, container); // // } // // } // // return; // // } // public void ShowConfig(BasePlayer _player, ref StoredData _data, ref Configuration _config) // { // player = _player; // Close(_player, _CONFIG_PANEL); // configToggle = ! configToggle; // if(perms.IsAdmin(_player) && configToggle) { // configContainer = new CuiElementContainer(); // ConfigPanel(_player, ref _config); // UI.Create(_player, configContainer); // } // } // public void Show(BasePlayer _player, ref StoredData _data, ref Configuration _config) // { // player = _player; // // if(currentMonumentShortName != null) Close(_player, currentMonumentShortName); // // if(currentMonumentShortName == null) Close(_player); // Close(_player); // if(muiToggle && perms.CanUiView(_player)) { // container = new CuiElementContainer(); // MainPanel(_player); // MonumentsPanel(_data, _config); // UI.Create(_player, container); // } // } // public void Refresh(BasePlayer _player) // { // _player.SendConsoleCommand("mui.refresh"); // } // public void Toggle(BasePlayer _player, string monumentName=null) // { // player = _player; // muiToggle = ! muiToggle; // currentMonumentShortName = monumentName; // _player.SendConsoleCommand("mui.refresh"); // return; // } // public void SyncMonuments(BasePlayer _player) // { // _player.SendConsoleCommand("mui.toggle"); // _player.SendConsoleCommand("mui.toggle"); // // _player.SendConsoleCommand("mui.config"); // } // private void MonumentsPanel(StoredData _data, Configuration _config) // { // var aMin = "0 0"; // var aMax = "1 1"; // // var color = ".2 0.2 0.2 .6"; //grey transparent // var color = "0 0 0 0"; //full transparent // var textColor = "1 1 1 1"; // MSession m_session = null; // UI.Element(ref container, _MONUMENTS_PANEL, _MAIN_PANEL, aMin, aMax, null, null, color); // //config panel button // UI.Button(ref container, _MONUMENTS_PANEL, "mui.config", "config", 7, ".8 0 .4 .7", textColor, "0.01 0.88", "0.08 0.93"); // int monumentCount = 0; // foreach(Monument _monument in _config.Monuments) { // if(_monument.enabled) { // m_session = _data.FindByShortName(_monument.shortName); // MonumentPanel(_monument, monumentCount, m_session); // monumentCount += 1; // } // } // return; // } // private void MonumentPanel(Monument _monument, int _monumentCount, MSession m_session) // { // var baseY = 0.88; // var baseX = 0.1; // var height = 0.05; // var width = 0.35; // var max_rows = 22; // var baseX_row2 = baseX + width + 0.02; // int row_count = _monumentCount; // if(_monumentCount >= max_rows) { // baseX = baseX_row2; // row_count = _monumentCount - max_rows; // } // var minY = baseY - (row_count * height); // var maxY = minY + height; // var maxX = baseX + width; // var aMin = baseX.ToString() + " " + minY.ToString(); // var aMax = maxX.ToString() + " " + maxY.ToString(); // // var color = "3 3 3 .65"; //fucia // // var color = ".3 0.3 0.3 .7"; // var bgGrey = ".1 0.1 0.1 .75"; // var bgBlue = "0 0 1 .4"; // var bgRed = "1 0 0 .6"; // var green = "0.0 1 0.0 0.4"; //green // var red = "0 0 1 .8"; //red // var grey = ".7 .7 .7 1"; // string time = m_session==null ? null : m_session.GetRemaining().ToString(); // string command = "mlock " + _monument.shortName; // // var img = GetImage(_monument.icon); // // var img = imageLibrary?.Call("GetImage", "_monument.icon"); // var img = ""; // UI.Element(ref container, _monument.shortName, _MONUMENTS_PANEL, aMin, aMax, null, null, m_session==null?bgGrey:bgRed); // //UI.Image(ref container, _monument.shortName, "icn_"+_monument.shortName, null, "0 0", "0.08 0.08", null, null, img, null); // if(m_session != null && m_session.IsLockedToMyTeam(player)) command = "mu " + _monument.shortName; // // UI.Label(ref container, "l_"+_monument.shortName, _monument.shortName, "", 7, "0.9 0.9 0.9 0.8", "0.1 0.1", "0.4 0.9", null, null, TextAnchor.MiddleLeft, null, VerticalWrapMode.Truncate); // UI.Element(ref container, "l_"+_monument.shortName, _monument.shortName, ".02 .02", ".7 .98", null, null, "0 0 0 0"); // UI.Button(ref container, "l_"+_monument.shortName, command, _monument.displayName, 6, "0 0 0 0", "1 1 1 1", "0 0", "1 1", TextAnchor.MiddleLeft); // if(_monument.gridPos!=null) // UI.Label(ref container, "l_pos_"+_monument.shortName, _monument.shortName, _monument.gridPos, 8, green, "0.86 0.01", "0.99 0.99", null, null, TextAnchor.MiddleLeft, null, VerticalWrapMode.Truncate); // //only show a button if a monument is unlocked // if(m_session!=null) { // UI.Label(ref container, "l_red"+_monument.shortName, _monument.shortName, time+" secs", 6, grey, "0.47 0.1", "0.7 0.9", null, null, TextAnchor.MiddleRight, null, VerticalWrapMode.Truncate); // } // // else { // // UI.Element(ref container, "l_"+_monument.shortName, _monument.shortName, "0.1 0.1", "0.9 0.9", null, null, "0 0 0 0"); // // } // } // private void CloseButton(ref CuiElementContainer _container, string _panelName, string _command = "mui.configclose", string color=".8 0 .4 1", string textColor="1 1 1 1", int _fontSize=16, string aMin=".94 .94", string aMax=".98 .98") // { // string _close_btn_panel = "close-button-panel"; // //UI.Panel(ref _container, color, aMin, aMax, true, _LAYER_OVERALL, _close_btn_panel); // UI.Element(ref _container, _close_btn_panel, _CONFIG_PANEL, aMin, aMax, null, null, color); // UI.Button(ref _container, _close_btn_panel, _command, "X", _fontSize, color, textColor, "0 0", "1 1"); // } // private void ButtonPanel(string color="0 0 0 0", string aMin="0.025 0.65", string aMax="0.1 0.69", bool cursorEnabled=false, string panelName=_BUTTON_PANEL) // { // UI.Panel(ref btnContainer, color, aMin, aMax, cursorEnabled, _LAYER_OVERLAY, panelName); // UI.Button(ref btnContainer, panelName, "mui.toggle", "Monuments", 14, ".1 .2 .9 .7", "1 1 1 1", "0 0", "1 1"); // } // private void ConfigPanel(BasePlayer _player, ref Configuration _config, string color=".2 .2 .2 .6") // { // string _layer = _LAYER_HUD_MENU; // var _aMin = _CONFIG_PANEL_BASE_X.ToString() + " " + _CONFIG_PANEL_BASE_Y.ToString(); // var _aMax = _CONFIG_PANEL_MAX_X.ToString() + " " + _CONFIG_PANEL_MAX_Y.ToString(); // double padding_x = .02; // double padding_y = .03; // double btnHeight = 0.07; // double btnWidth = 0.23; // string bgFalse = ".2 .2 .2 .4"; // string bgTrue = "0 .7 .0 .8"; // string txFalse = ".6 .6 .6 .4"; // string txTrue = ".9 .9 .9 .9"; // string btnSyncMonumentsColor = "0.2 .2 .8 .8"; // //config button panel bg color // string bgButtonPanel = "0 0 0 0"; // //config button colours // string bgHardTimer = bgFalse; // if(_config.hard_timer) bgHardTimer = bgTrue; // string txHardTimer = txFalse; // if(_config.hard_timer) txHardTimer = txTrue; // string bgMaxTimer = bgFalse; // if(_config.enable_max_timer) bgMaxTimer = bgTrue; // string txtMaxTimer = txFalse; // if(_config.enable_max_timer) txtMaxTimer = txTrue; // //main config panel // UI.Panel(ref configContainer, color, _aMin, _aMax, true, _layer, _CONFIG_PANEL); // //sync monuments // UI.Element(ref configContainer, "btn-sync", _CONFIG_PANEL, ".02 .9", ".25 .97", null, null, btnSyncMonumentsColor); // UI.Button(ref configContainer, "btn-sync", "mui.sync", "Sync Monuments", 8, "0 0 0 0", "1 1 1 1", ".01 .01", ".99 .99"); // //timers // // string aMin_timers = padding_x.ToString() + " " + () // UI.Element(ref configContainer, "timers-panel", _CONFIG_PANEL, "0.02 .7", ".98 .88", null, null, "0 0 0 .3"); // //hardtimer // UI.Element(ref configContainer, "btn-hard-timer", "timers-panel", ".01 .5", ".98 .95", null, null, bgButtonPanel); // UI.Button(ref configContainer, "btn-hard-timer", "mui.config.hardtimer", "Hard Timer", 8, bgHardTimer, "1 1 1 1", ".01 .2", ".2 .8"); // UI.Label(ref configContainer, "l_hardtimer", "btn-hard-timer", "Only the timer expiration will unlock a monument", 8, txHardTimer, ".22 .2", ".99 .8", null, null, TextAnchor.MiddleLeft); // //maxtimer // UI.Element(ref configContainer, "btn-max-timer", "timers-panel", ".01 .01", ".98 .45", null, null, bgButtonPanel); // UI.Button(ref configContainer, "btn-max-timer", "mui.config.maxtimer", "Max Timer", 8, bgMaxTimer, "1 1 1 1", ".01 .2", ".2 .8"); // UI.Label(ref configContainer, "l_maxtimer", "btn-max-timer", "Player activity will not reset timer, max timer is in effect.", 8, txtMaxTimer, ".22 .2", ".99 .8", null, null, TextAnchor.MiddleLeft); // } // private void MainPanel(BasePlayer _player=null, string color="0 0 0 0", string aMin="0.65 0.305", string aMax="0.98 0.9", bool cursorEnabled=true, string panelName=_MAIN_PANEL) // { // string _layer = _LAYER_UNDER; // if(player!=null && perms.CanUiUse(_player)) _layer = _LAYER_HUD_MENU; // var _aMin = ""; // var _aMax = _MAIN_PANEL_MAX_X.ToString() + " " + _MAIN_PANEL_MAX_Y.ToString(); // UI.Panel(ref container, color, aMin, _aMax, cursorEnabled, _layer, panelName); // } // public void Close(BasePlayer _player, string _panel=_MAIN_PANEL) // { // UI.Close(_player, _panel); // } // public static void CloseAll() // { // UI.CloseAll(_MAIN_PANEL); // //UI.CloseAll(_BUTTON_PANEL); // UI.CloseAll(_CONFIG_PANEL); // } // } // #endregion // #region UI // private class UI // { // public static float Size = 1; // private const string _ROBOT_CONDENSED_REG = "robotocondensed-regular.ttf"; // public static void Element(ref CuiElementContainer container, string name, string parent, string aMin="0 0", string aMax="1 1", string oMin="-45 -80", string oMax= "-10 -45", string color="0 0 0 1") // { // container.Add(new CuiElement // { // Name = name, // Parent = parent, // Components = // { // new CuiRectTransformComponent // { // AnchorMin = aMin, // AnchorMax = aMax, // OffsetMin = oMin, // OffsetMax = oMax // }, // new CuiImageComponent // { // Color = color // }, // } // }); // } // public static void Panel(ref CuiElementContainer container, string color="0 0 0 0", string aMin="0 0", string aMax="1 1", bool cursorEnabled=false, string layer="Overlay", string panelName="panel") // { // container.Add(new CuiPanel { // Image = { // Color = color // }, // RectTransform = { // AnchorMin = aMin, // AnchorMax = aMax // }, // CursorEnabled = cursorEnabled // }, layer, panelName); // } // public static void Input(ref CuiElementContainer container, string parent, string name, string color="0 0 0 1", string text="", int fontSize=10, TextAnchor align = TextAnchor.MiddleLeft, string aMin="0 0", string aMax="1 1", string oMin=null, string oMax=null) // { // } // public static void Icon(ref CuiElementContainer container, string parent, string name = null, string destroy = null, string aMin = "0 0", string aMax = "1 1", string oMin = "0 0", string oMax = "0 0", int itemID = 0, ulong skinID = 0) => // container.Add(new CuiElement // { // Parent = parent, // Name = name, // Components = // { // new CuiRectTransformComponent { AnchorMin = aMin, AnchorMax = aMax, OffsetMin = oMin == null ? "0 0" : int.Parse(oMin.Split(' ')[0]) * Size + " " + int.Parse(oMin.Split(' ')[1]) * Size, OffsetMax = oMax == null ? "0 0" : int.Parse(oMax.Split(' ')[0]) * Size + " " + int.Parse(oMax.Split(' ')[1]) * Size }, // new CuiImageComponent { ItemId = itemID, SkinId = skinID }, // }, // }); // public static void Image(ref CuiElementContainer container, string parent, string name = null, string destroy = null, string aMin = "0 0", string aMax = "1 1", string oMin = "0 0", string oMax = "0 0", string image = "", string color = "1 1 1 1") => // container.Add(new CuiElement // { // Parent = parent, // Name = name, // DestroyUi = destroy == null ? null : destroy, // Components = // { // new CuiRectTransformComponent { AnchorMin = aMin, AnchorMax = aMax, OffsetMin = oMin == null ? "0 0" : int.Parse(oMin.Split(' ')[0]) * Size + " " + int.Parse(oMin.Split(' ')[1]) * Size, OffsetMax = oMax == null ? "0 0" : int.Parse(oMax.Split(' ')[0]) * Size + " " + int.Parse(oMax.Split(' ')[1]) * Size }, // new CuiRawImageComponent { Png = !image.StartsWith("http") && !image.StartsWith("www") ? image : null, Url = image.StartsWith("http") || image.StartsWith("www") ? image : null, Color = color, Sprite = "assets/content/textures/generic/fulltransparent.tga" }, // }, // }); // public static void Label(ref CuiElementContainer container, string name, string parent, string text, int fontSize=16, string textColor="0 0 0 1", string aMin="0 0", string aMax="1 1", string oMin="0 0", string oMax="1 1", TextAnchor align = TextAnchor.MiddleCenter, string font = _ROBOT_CONDENSED_REG, VerticalWrapMode wrapMode = VerticalWrapMode.Truncate) // { // container.Add(new CuiElement // { // Parent = parent, // Name = name, // Components = // { // new CuiRectTransformComponent // { // AnchorMin = aMin, // AnchorMax = aMax, // OffsetMin = oMin, // OffsetMax = oMax // }, // new CuiTextComponent // { // Text = text, // FontSize = (int) fontSize, // Color = textColor, // Align = align, // Font = font, // VerticalOverflow = wrapMode // } // }, // }); // } // public static void Button(ref CuiElementContainer container, string panelName, string command=null, string text="", int fontSize=15, string color="0 0 0 0", string textColor="1 1 1 1", string aMin="0.25 0", string aMax="0.75, 0.65", TextAnchor align = TextAnchor.MiddleCenter) // { // container.Add(new CuiButton { // Button = { // Command = command, // Color = color // }, // RectTransform = { // AnchorMin = aMin, // AnchorMax = aMax // }, // Text = { // Text = text, // FontSize = fontSize, // Align = align, // } // }, panelName); // } // public static void Create(BasePlayer player, CuiElementContainer container) // { // CuiHelper.AddUi(player, container); // } // public static void Close(BasePlayer player, string panelName) // { // CuiHelper.DestroyUi(player, panelName); // } // public static void CloseAll(string _panelName) // { // foreach (var player in BasePlayer.activePlayerList) // Close(player, _panelName); // } // } // #endregion // #region Image // // [PluginReference] private Plugin ImageLibrary; // private void AddImage(string url) => ImageLibrary.Call("AddImage", url, url); // private string GetImage(string url) // { // var img = ImageLibrary?.Call("GetImage", url); // return img ?? url; // } // private void LoadImages() // { // if (!ImageLibrary) // { // PrintError("ImageLibrary not found. You can download the plugin here - https://umod.org/plugins/image-library."); // return; // } // //var configMainSetup = _config.MainSetup; // foreach(Monument _monument in _config.Monuments) { // AddImage(_monument.icon); // Puts($"img: {GetImage(_monument.icon)}"); // } // } // #endregion // #region MUIx // /// // /// The UI Region contains the OnPlayerConnected() hook and the Unload(), if you want to move it that fine, but remember to // /// copy the code in it. // /// // /// NotificationCui() send a notification to all players // /// MenuButtonCui() Creates the menu button // /// TopRightCornerCui() is just for anchoring and mustn't be used or destroyed // /// ToggleMonumentLockWindow() (ConsoleCommand) Is the command that is executed when you press the menubutton // /// If you want to show the menu to just someone specific just call MenuButtonCui(), ToggleMonumentLockWindow() will be executed from there // /// In the OnMonumentLocked() function, you can configure the text that should be displayed in the notification // /// // private string _cuiCache = ""; // private readonly string CuiParent = "MonumentLockCui"; // private readonly string _cuiMenuButton = "MenuButton"; // private readonly string _cuiCheckPanel = "CheckPanel"; // private readonly string _cuiOpenMenu = "OpenMenu"; // private readonly string _cuiTopRightCorner = "TopRightCorner"; // private readonly string _cuiNotification = "Notification"; // private readonly string _cuiAdminCui = "AdminCui"; // private Dictionary activeNotification = new Dictionary(); // private static Dictionary isInMonumentLockMenu = new Dictionary(); // // void OnPlayerConnected(BasePlayer player) // // { // // // Puts("OnPlayerConnected works!"); // // TopRightCornerCui(player); // // MenuButtonCui(player); // // } // void Unload() // { // foreach(var player in BasePlayer.activePlayerList) // { // CuiHelper.DestroyUi(player, "Corner"); // } // } // private void UpdateUi(BasePlayer player, string uiToDestroy) // { // //Debug.Log(_cuiCache); // CuiHelper.DestroyUi(player, uiToDestroy); // CuiHelper.AddUi(player, _cuiCache); // } // private void UpdateUi(BasePlayer player, List uiToDestroy) // { // foreach (var cuielement in uiToDestroy) // { // CuiHelper.DestroyUi(player, cuielement); // } // CuiHelper.AddUi(player, _cuiCache); // } // private void TopRightCornerCui(BasePlayer player) // { // CuiElementContainer UiContainer = new CuiElementContainer(); // UiContainer.Add(new CuiElement // { // Name = _cuiTopRightCorner, // Parent = "Overlay", // Components = // { // new CuiRectTransformComponent // { // AnchorMin = "1 0.9", // AnchorMax = "1 0.9" // } // } // }); // _cuiCache = UiContainer.ToString(); // UpdateUi(player,""); // } // private void NotificationCui(BasePlayer player, string message) // { // if (player == null) // { // return; // } // if (!activeNotification.ContainsKey(player.userID)) // { // activeNotification[player.userID] = false; // } // if (activeNotification[player.userID]) // { // return; // } // activeNotification[player.userID] = true; // CuiElementContainer UiContainer = new CuiElementContainer(); // UiContainer.Add(new CuiElement // { // Name = _cuiNotification, // Parent = _cuiTopRightCorner, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = "-400 -43", // OffsetMax = "-9 -15" // }, // new CuiImageComponent // { // Color = "0.2 0.2 0.2 0.8", // FadeIn = 3f, // } // } // }); // UiContainer.Add(new CuiElement // { // Name = "NotificationWhiteBar", // Parent = _cuiNotification, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = "0 -2", // OffsetMax = "0 -29" // }, // new CuiImageComponent // { // Color = "1 1 1 1", // FadeIn = 3f, // }, // } // }); // UiContainer.Add(new CuiElement // { // Name = "NotificationText", // Parent = _cuiNotification, // Components = // { // new CuiTextComponent // { // Text = message, // FadeIn = 3f, // Align = TextAnchor.MiddleLeft, // FontSize = 18 // } // } // }); // _cuiCache = UiContainer.ToString(); // UpdateUi(player,""); // timer.In(5f, () => // { // _cuiCache = ""; // UpdateUi(player,"Notification"); // activeNotification[player.userID] = false; // }); // } // private void MenuButtonCui(BasePlayer player) // { // if (player == null) // { // return; // } // CuiElementContainer Uic = new CuiElementContainer(); // Uic.Add(new CuiElement // { // Name = CuiParent, // Parent = _cuiTopRightCorner, // Components = // { // new CuiRectTransformComponent // { // AnchorMin = "1 1", // AnchorMax = "1 1" // } // } // }); // Uic.Add(new CuiElement // { // Name = _cuiCheckPanel, // Parent = CuiParent, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = "-45 -80", // OffsetMax = "-10 -45" // }, // new CuiImageComponent // { // Color = "0.34 0.34 0.34 0.8" // }, // } // }); // Uic.Add(new CuiButton // { // Button = // { // Command = "notoggle", // Sprite = "assets/icons/menu_dots.png", // Color = "1 1 1 1" // }, // RectTransform = // { // OffsetMin = "-45 -80", // OffsetMax = "-10 -45" // }, // }, CuiParent,_cuiMenuButton); // Uic.Add(new CuiElement // { // Name = "WhiteBarTop", // Parent = _cuiCheckPanel, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = "0 0", // OffsetMax = "0 -34" // }, // new CuiImageComponent // { // Color = "1 1 1 1" // }, // } // }); // Uic.Add(new CuiElement // { // Name = "WhiteBarTop2", // Parent = _cuiCheckPanel, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = "0 34", // OffsetMax = "0 0" // }, // new CuiImageComponent // { // Color = "1 1 1 1" // }, // } // }); // _cuiCache = Uic.ToString(); // //UpdateUi(player, CuiParent); // } // public int MonLock; // public int MonLockAdd; // [ConsoleCommand("notoggle")] // private void notoggle(ConsoleSystem.Arg arg) // { // } // [ConsoleCommand("ToggleMonumentLockWindow")] // private void ToggleMonumentLockWindow(ConsoleSystem.Arg arg) // { // var player = arg.Player(); // if (player == null) // { // return; // } // if (!isInMonumentLockMenu.ContainsKey(player.userID)) // { // isInMonumentLockMenu[player.userID] = false; // } // MonLock = storedData.m_sessions.Count; // if (isInMonumentLockMenu[player.userID]) // { // MenuButtonCui(player); // isInMonumentLockMenu[player.userID] = false; // return; // } // if (MonLock == 0) // { // //player.ChatMessage("There are no locked monuments currently."); // return; // } // isInMonumentLockMenu[player.userID] = true; // MonLockAdd = -30 * MonLock; // CuiElementContainer UiContainer = new CuiElementContainer(); // UiContainer.Add(new CuiElement // { // Name = _cuiAdminCui, // Parent = CuiParent, // Components = // { // new CuiRectTransformComponent // { // AnchorMin = "1 1", // AnchorMax = "1 1" // } // } // }); // UiContainer.Add(new CuiElement // { // Name = _cuiOpenMenu, // Parent = _cuiCheckPanel, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = $"-180 {MonLockAdd}", // OffsetMax = "-0 -36" // }, // new CuiImageComponent // { // Color = "0.34 0.34 0.34 0.8" // }, // } // }); // var i = 0; // string elTimerName; // Debug.Log(storedData.m_sessions.Count); // foreach(var session in storedData.m_sessions) // { // if(session.IsActive()) { // var cuiMonument = new CuiElement // { // Name = session.SessionMonument.shortName, // Parent = _cuiOpenMenu // }; // UiContainer.Add(cuiMonument); // UiContainer.Add(new CuiElement // { // Name = "l_" + session.SessionMonument.shortName, // Parent = session.SessionMonument.shortName, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = $"7 {30 * i}", // OffsetMax = $"-7 -{(30 *(MonLock - i - 1))}" // }, // new CuiTextComponent // { // Color = "1 1 1 1", // FontSize = 17, // Text = $"{session.SessionMonument.displayName}", // Align = TextAnchor.MiddleLeft, // Font = "RobotoCondensed-Bold.ttf" // }, // } // }); // elTimerName = "Timer"+i; // CuiTextComponent txtTimeRemaining = new CuiTextComponent // { // Color = "1 1 1 1", // FontSize = 17, // Text = $"{session.GetRemaining()}", // Align = TextAnchor.MiddleRight, // Font = "RobotoCondensed-Regular.ttf" // }; // var elTimeRemaining = new CuiElement // { // Name = elTimerName, // Parent = session.SessionMonument.shortName, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = $"7 {30 * i}", // OffsetMax = $"-7 -{(30 *(MonLock - i - 1))}" // }, // txtTimeRemaining // } // }; // UiContainer.Add(elTimeRemaining); // //Timer newTimer = timer.Every(1f, () => UpdateRemainingTime(txtTimeRemaining, session, player, UiContainer, session.SessionMonument.shortName)); // //timers.Add(session.SessionMonument.shortName, newTimer); // i++; // } // } // UiContainer.Add(new CuiElement // { // Name = "WhiteBar", // Parent = _cuiOpenMenu, // Components = // { // new CuiRectTransformComponent // { // OffsetMin = "-0 -3", // OffsetMax = $"0 {MonLockAdd}" // }, // new CuiImageComponent // { // Color = "1 1 1 1" // }, // } // }); // _cuiCache = UiContainer.ToString(); // Debug.Log(UiContainer.ToString()); // _cuiCache = UiContainer.ToString(); // //UpdateUi(player, "WhiteBarTop"); // } // private void UpdateRemainingTime(CuiTextComponent txtRemainingTime, MSession mSession, BasePlayer player, CuiElementContainer container, string elTimerName) // { // txtRemainingTime.Text = mSession.GetRemaining().ToString(); // //Puts($"-- isactive: {storedData.IsSessionActive(mSession)}"); // if(!storedData.IsSessionActive(mSession)){ // //Puts("--Session Inactive"); // foreach (var kvp in timers) { // if(kvp.Key == elTimerName) { // //timers.Remove(elTimerName); // Timer t = kvp.Value; // t.Destroy(); // } // } // UnlockMonument(player); // //Puts("-- completed destroying timer"); // //CuiHelper.DestroyUi(player, elTimerName); // player.SendConsoleCommand("ToggleMonumentLockWindow"); // } // else // { // //Puts("--time in active session"); // if(isInMonumentLockMenu[player.userID]) { // //CuiHelper.DestroyUi(player, elTimerName); // //CuiHelper.AddUi(player, container); // } // } // return; // } // [ConsoleCommand("printsession")] // void gamingtime(ConsoleSystem.Arg args) // { // var player = args.Player(); // player.ConsoleMessage(storedData.m_sessions[0].SessionMonument.lock_timer.ToString()); // } // #endregion } }