Beispiel #1
0
    public Door FindDoor(bool allowLocked = true)
    {
        List <Door> list = Pool.GetList <Door>();

        Vis.Entities <Door>(base.transform.position, 1f, list, 2097152, QueryTriggerInteraction.Ignore);
        Door  door   = null;
        float single = Single.PositiveInfinity;

        foreach (Door door1 in list)
        {
            if (!door1.isServer)
            {
                continue;
            }
            if (!allowLocked)
            {
                BaseLock slot = door1.GetSlot(BaseEntity.Slot.Lock) as BaseLock;
                if (slot != null && slot.IsLocked())
                {
                    continue;
                }
            }
            float single1 = Vector3.Distance(door1.transform.position, base.transform.position);
            if (single1 >= single)
            {
                continue;
            }
            door   = door1;
            single = single1;
        }
        Pool.FreeList <Door>(ref list);
        return(door);
    }
Beispiel #2
0
    public Door FindDoor(bool allowLocked = true)
    {
        List <Door> list = (List <Door>)Pool.GetList <Door>();

        Vis.Entities <Door>(((Component)this).get_transform().get_position(), 1f, list, 2097152, (QueryTriggerInteraction)1);
        Door  door1 = (Door)null;
        float num1  = float.PositiveInfinity;

        foreach (Door door2 in list)
        {
            if (door2.isServer)
            {
                if (!allowLocked)
                {
                    BaseLock slot = door2.GetSlot(BaseEntity.Slot.Lock) as BaseLock;
                    if (Object.op_Inequality((Object)slot, (Object)null) && slot.IsLocked())
                    {
                        continue;
                    }
                }
                float num2 = Vector3.Distance(((Component)door2).get_transform().get_position(), ((Component)this).get_transform().get_position());
                if ((double)num2 < (double)num1)
                {
                    door1 = door2;
                    num1  = num2;
                }
            }
        }
        // ISSUE: cast to a reference type
        Pool.FreeList <Door>((List <M0>&) ref list);
        return(door1);
    }
Beispiel #3
0
    public Door FindDoor(bool allowLocked = true)
    {
        List <Door> obj = Pool.GetList <Door>();

        Vis.Entities(base.transform.position, 1f, obj, 2097152, QueryTriggerInteraction.Ignore);
        Door  result = null;
        float num    = float.PositiveInfinity;

        foreach (Door item in obj)
        {
            if (!item.isServer)
            {
                continue;
            }
            if (!allowLocked)
            {
                BaseLock baseLock = item.GetSlot(Slot.Lock) as BaseLock;
                if (baseLock != null && baseLock.IsLocked())
                {
                    continue;
                }
            }
            float num2 = Vector3.Distance(item.transform.position, base.transform.position);
            if (num2 < num)
            {
                result = item;
                num    = num2;
            }
        }
        Pool.FreeList(ref obj);
        return(result);
    }
Beispiel #4
0
        private object CanLock(BasePlayer player, BaseLock @lock)
        {
            if (player == null || @lock == null)
            {
                return(null);
            }
            if (@lock.IsLocked())
            {
                return(false);
            }
            if (playerPrefs.ContainsKey(player.UserIDString) && !playerPrefs[player.UserIDString])
            {
                return(null);
            }

            var prefab = @lock.parentEntity.Get(true).ShortPrefabName;

            if (prefab == null)
            {
                return(null);
            }

            var codeLock = @lock as CodeLock;

            foreach (var type in lockableTypes)
            {
                if (!prefab.Contains(type))
                {
                    continue;
                }
                if (!permission.UserHasPermission(player.UserIDString, $"masterkey.{type}"))
                {
                    return(null);
                }

                if (showMessages)
                {
                    player.ChatMessage(Lang("UnlockedWith", player.UserIDString, type));
                }
                if (logUsage)
                {
                    Log(Lang("LogLock", null, PlayerName(player), type, player.transform.position));
                }

                if (@lock != null)
                {
                    @lock.SetFlag(BaseEntity.Flags.Locked, true);
                }
                if (player != null && codeLock != null)
                {
                    EffectNetwork.Send(new Effect(codeLock.effectLocked.resourcePath, player.transform.position, Vector3.zero));
                }

                return(false);
            }

            return(null);
        }
Beispiel #5
0
    private void RPC_OpenDoor(BaseEntity.RPCMessage rpc)
    {
        if (!rpc.player.CanInteract())
        {
            return;
        }
        if (!this.canHandOpen)
        {
            return;
        }
        if (base.IsOpen())
        {
            return;
        }
        if (base.IsBusy())
        {
            return;
        }
        if (base.IsLocked())
        {
            return;
        }
        BaseLock slot = base.GetSlot(BaseEntity.Slot.Lock) as BaseLock;

        if (slot != null)
        {
            if (!slot.OnTryToOpen(rpc.player))
            {
                return;
            }
            if (slot.IsLocked() && UnityEngine.Time.realtimeSinceStartup - this.decayResetTimeLast > 60f)
            {
                BuildingBlock buildingBlock = base.FindLinkedEntity <BuildingBlock>();
                if (!buildingBlock)
                {
                    Decay.RadialDecayTouch(base.transform.position, 40f, 2097408);
                }
                else
                {
                    Decay.BuildingDecayTouch(buildingBlock);
                }
                this.decayResetTimeLast = UnityEngine.Time.realtimeSinceStartup;
            }
        }
        base.SetFlag(BaseEntity.Flags.Open, true, false, true);
        base.SendNetworkUpdateImmediate(false);
        if (this.isSecurityDoor && this.NavMeshLink != null)
        {
            this.SetNavMeshLinkEnabled(true);
        }
        Interface.CallHook("OnDoorOpened", this, rpc.player);
    }
Beispiel #6
0
        /*private void OnEntityEnter(TriggerBase trigger, BaseEntity entity)
         * {
         *  var player = entity as BasePlayer;
         *  if (player == null || !(trigger is BuildPrivilegeTrigger)) return;
         *
         *  if (playerPrefs.ContainsKey(player.UserIDString) && !playerPrefs[player.UserIDString]) return;
         *  if (!permission.UserHasPermission(player.UserIDString, permBuild)) return;
         *
         *  NextTick(() =>
         *  {
         *      player.SetPlayerFlag(BasePlayer.PlayerFlags.InBuildingPrivilege, true);
         *      player.SetPlayerFlag(BasePlayer.PlayerFlags.HasBuildingPrivilege, true);
         *  });
         *  if (logUsage) Log(Lang("MasterKeyUsed", null, player.displayName, player.UserIDString, player.transform.position));
         * }*/

        #endregion Build Anywhere

        #region Lock Access

        private object CanUseLockedEntity(BasePlayer player, BaseLock @lock)
        {
            if ([email protected]())
            {
                return(null);
            }
            if (playerPrefs.ContainsKey(player.UserIDString) && !playerPrefs[player.UserIDString])
            {
                return(null);
            }

            var prefab = @lock.parentEntity.Get(true).ShortPrefabName;

            if (prefab == null)
            {
                return(null);
            }

            foreach (var type in lockableTypes)
            {
                if (!prefab.Contains(type))
                {
                    continue;
                }
                if (!permission.UserHasPermission(player.UserIDString, $"masterkey.{type}"))
                {
                    return(null);
                }

                if (showMessages)
                {
                    player.ChatMessage(Lang("OpenWith", player.UserIDString, type));
                }
                if (logUsage)
                {
                    Log(Lang("LogOpen", null, PlayerName(player), type, player.transform.position));
                }

                return(true);
            }

            return(null);
        }
Beispiel #7
0
        // checks for a lock
        object CheckLock(BaseCombatEntity entity, HitInfo hitinfo)
        {
            // exclude deployed items in storage container lock check (since they can't have locks)
            if (entity.ShortPrefabName == "lantern.deployed" ||
                entity.ShortPrefabName == "ceilinglight.deployed" ||
                entity.ShortPrefabName == "furnace.large" ||
                entity.ShortPrefabName == "campfire" ||
                entity.ShortPrefabName == "furnace" ||
                entity.ShortPrefabName == "refinery_small_deployed" ||
                entity.ShortPrefabName == "waterbarrel" ||
                entity.ShortPrefabName == "jackolantern.angry" ||
                entity.ShortPrefabName == "jackolantern.happy" ||
                entity.ShortPrefabName == "repairbench_deployed" ||
                entity.ShortPrefabName == "researchtable_deployed" ||
                entity.ShortPrefabName.Contains("shutter"))
            {
                return(null);
            }

            // if unlocked damage allowed - check for lock
            BaseLock alock = entity.GetSlot(BaseEntity.Slot.Lock) as BaseLock;             // get lock

            if (alock == null)
            {
                return(null);                 // no lock, allow damage
            }
            if (alock.IsLocked())             // is locked, cancel damage except heli
            {
                // if heliDamageLocked option is false or heliDamage is false, all damage is cancelled
                if (!data.config[Option.heliDamageLocked] || !data.config[Option.heliDamage])
                {
                    return(false);
                }
                object heli = CheckHeliInitiator(hitinfo);
                if (heli != null)
                {
                    return((bool)heli);
                }
                return(false);
            }
            return(null);
        }
Beispiel #8
0
        // Door.RPC_CloseDoor()/RPC_OpenDoor()
        public static void On_DoorUse(Door door, BaseEntity.RPCMessage rpc, bool open)
        {
            if ((open && door.IsOpen()) || (!open && !door.IsOpen()))
            {
                return;
            }

            DoorUseEvent due = new DoorUseEvent(new Entity(door), Server.GetPlayer(rpc.player), open);

            OnNext("On_DoorUse", due);

            if (!due.Allow)
            {
                if (due.DenyReason != "")
                {
                    rpc.player.SendConsoleCommand("chat.add", 0, String.Format("{0}: {1}", Server.server_message_name.ColorText("fa5"), due.DenyReason));
                }
                return;
            }

            bool doaction = true;

            BaseLock baseLock = door.GetSlot(BaseEntity.Slot.Lock) as BaseLock;

            if (!due.IgnoreLock && baseLock != null)
            {
                doaction = open ? baseLock.OnTryToOpen(rpc.player) : baseLock.OnTryToClose(rpc.player);

                if (doaction && open && (baseLock.IsLocked() && Time.realtimeSinceStartup - (float)door.GetFieldValue("decayResetTimeLast") > 60))
                {
                    Decay.RadialDecayTouch(door.transform.position, 40, 270532608);
                    door.SetFieldValue("decayResetTimeLast", Time.realtimeSinceStartup);
                }
            }

            if (doaction)
            {
                door.SetFlag(BaseEntity.Flags.Open, open);
                door.SendNetworkUpdateImmediate(false);
                door.CallMethod("UpdateDoorAnimationParameters", false);
            }
        }
Beispiel #9
0
        object CanUseDoor(BasePlayer player, BaseLock door)
        {
            var prefab = door.parentEntity.Get(true).ShortPrefabName;

            if (!door.IsLocked())
            {
                return(true);
            }
            if (playerPrefs.ContainsKey(player.UserIDString) && !playerPrefs[player.UserIDString])
            {
                return(null);
            }

            foreach (var type in types)
            {
                if (!type.Contains(prefab))
                {
                    continue;
                }

                if (!IsAllowed(player.UserIDString, "masterkey.all") && !IsAllowed(player.UserIDString, $"masterkey.{type}"))
                {
                    return(null);
                }
                if (showMessages)
                {
                    player.ChatMessage(Lang("UnlockedWith", player.UserIDString, type));
                }
                if (logUsage)
                {
                    LogToFile(Lang("MasterKeyUsed", null, player.displayName, player.UserIDString, player.transform.position));
                }
                return(true);
            }

            return(null);
        }
Beispiel #10
0
    private void RPC_OpenDoor(BaseEntity.RPCMessage rpc)
    {
        if (!rpc.player.CanInteract() || !this.canHandOpen || (this.IsOpen() || this.IsBusy()) || this.IsLocked())
        {
            return;
        }
        BaseLock slot = this.GetSlot(BaseEntity.Slot.Lock) as BaseLock;

        if (Object.op_Inequality((Object)slot, (Object)null))
        {
            if (!slot.OnTryToOpen(rpc.player))
            {
                return;
            }
            if (slot.IsLocked() && (double)Time.get_realtimeSinceStartup() - (double)this.decayResetTimeLast > 60.0)
            {
                BuildingBlock linkedEntity = this.FindLinkedEntity <BuildingBlock>();
                if (Object.op_Implicit((Object)linkedEntity))
                {
                    Decay.BuildingDecayTouch(linkedEntity);
                }
                else
                {
                    Decay.RadialDecayTouch(((Component)this).get_transform().get_position(), 40f, 2097408);
                }
                this.decayResetTimeLast = Time.get_realtimeSinceStartup();
            }
        }
        this.SetFlag(BaseEntity.Flags.Open, true, false, true);
        this.SendNetworkUpdateImmediate(false);
        if (this.isSecurityDoor && Object.op_Inequality((Object)this.NavMeshLink, (Object)null))
        {
            this.SetNavMeshLinkEnabled(true);
        }
        Interface.CallHook("OnDoorOpened", (object)this, (object)rpc.player);
    }
Beispiel #11
0
        object CanUseDoor(BasePlayer player, BaseLock door)
        {
            var parent = door.parentEntity.Get(true);
            var prefab = parent.LookupPrefabName();

            if (!door.IsLocked())
            {
                return(true);
            }

            if (prefab.Contains("box.wooden") || prefab.Contains("woodbox_deployed"))
            {
                if (!HasPermission(player, "masterkey.all") && !HasPermission(player, "masterkey.boxes"))
                {
                    return(null);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, UnlockedWith.Replace("{object}", "box"));
                }
                if (LogUsage)
                {
                    LogToFile(player, MasterKeyUsed);
                }
                return(true);
            }

            if (prefab.Contains("door.hinged"))
            {
                if (!HasPermission(player, "masterkey.all") && !HasPermission(player, "masterkey.doors"))
                {
                    return(null);
                }
                if (parent.IsOpen())
                {
                    return(true);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, UnlockedWith.Replace("{object}", "door"));
                }
                if (LogUsage)
                {
                    LogToFile(player, MasterKeyUsed);
                }
                return(true);
            }

            if (prefab.Contains("furnace"))
            {
                if (!HasPermission(player, "masterkey.all") && !HasPermission(player, "masterkey.furnaces"))
                {
                    return(null);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, UnlockedWith.Replace("{object}", "furnace"));
                }
                if (LogUsage)
                {
                    LogToFile(player, MasterKeyUsed);
                }
                return(true);
            }

            if (prefab.Contains("gates.external"))
            {
                if (!HasPermission(player, "masterkey.all") && !HasPermission(player, "masterkey.gates"))
                {
                    return(null);
                }
                if (parent.IsOpen())
                {
                    return(true);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, UnlockedWith.Replace("{object}", "gate"));
                }
                if (LogUsage)
                {
                    LogToFile(player, MasterKeyUsed);
                }
                return(true);
            }

            if (prefab.Contains("stash_deployed"))
            {
                if (!HasPermission(player, "masterkey.all") && !HasPermission(player, "masterkey.stashes"))
                {
                    return(null);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, UnlockedWith.Replace("{object}", "stash"));
                }
                if (LogUsage)
                {
                    LogToFile(player, MasterKeyUsed);
                }
                return(true);
            }

            return(null);
        }
Beispiel #12
0
        object CanUseDoor(BasePlayer player, BaseLock door)
        {
            var parent = door.parentEntity.Get(true);
            var prefab = parent.LookupPrefabName();

            if (!door.IsLocked())
            {
                return(true);
            }
            if (playerPrefs.ContainsKey(player.userID) && !playerPrefs[player.userID])
            {
                return(null);
            }

            if (prefab.Contains("box"))
            {
                if (!HasPermission(player.UserIDString, "masterkey.all") && !HasPermission(player.UserIDString, "masterkey.boxes"))
                {
                    return(null);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, string.Format(GetMessage("UnlockedWith"), "box"));
                }
                if (LogUsage)
                {
                    LogToFile(player, GetMessage("MasterKeyUsed"));
                }
                return(true);
            }

            if (prefab.Contains("cell"))
            {
                if (!HasPermission(player.UserIDString, "masterkey.all") && !HasPermission(player.UserIDString, "masterkey.cells"))
                {
                    return(null);
                }
                if (parent.IsOpen())
                {
                    return(true);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, string.Format(GetMessage("UnlockedWith"), "cell"));
                }
                if (LogUsage)
                {
                    LogToFile(player, GetMessage("MasterKeyUsed"));
                }
                return(true);
            }

            if (prefab.Contains("door"))
            {
                if (!HasPermission(player.UserIDString, "masterkey.all") && !HasPermission(player.UserIDString, "masterkey.doors"))
                {
                    return(null);
                }
                if (parent.IsOpen())
                {
                    return(true);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, string.Format(GetMessage("UnlockedWith"), "door"));
                }
                if (LogUsage)
                {
                    LogToFile(player, GetMessage("MasterKeyUsed"));
                }
                return(true);
            }

            if (prefab.Contains("fence.gate") || prefab.Contains("gates.external"))
            {
                if (!HasPermission(player.UserIDString, "masterkey.all") && !HasPermission(player.UserIDString, "masterkey.gates"))
                {
                    return(null);
                }
                if (parent.IsOpen())
                {
                    return(true);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, string.Format(GetMessage("UnlockedWith"), "gate"));
                }
                if (LogUsage)
                {
                    LogToFile(player, GetMessage("MasterKeyUsed"));
                }
                return(true);
            }

            if (prefab.Contains("shopfront"))
            {
                if (!HasPermission(player.UserIDString, "masterkey.all") && !HasPermission(player.UserIDString, "masterkey.shops"))
                {
                    return(null);
                }
                if (parent.IsOpen())
                {
                    return(true);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, string.Format(GetMessage("UnlockedWith"), "shop"));
                }
                if (LogUsage)
                {
                    LogToFile(player, GetMessage("MasterKeyUsed"));
                }
                return(true);
            }

            if (prefab.Contains("floor"))
            {
                if (!HasPermission(player.UserIDString, "masterkey.all") && !HasPermission(player.UserIDString, "masterkey.floor"))
                {
                    return(null);
                }
                if (parent.IsOpen())
                {
                    return(true);
                }
                if (ShowMessages)
                {
                    PrintToChat(player, string.Format(GetMessage("UnlockedWith"), "floor"));
                }
                if (LogUsage)
                {
                    LogToFile(player, GetMessage("MasterKeyUsed"));
                }
                return(true);
            }

            return(null);
        }