Exemple #1
0
        private static bool DistanceChanged(TantrumEnvironmentalHazard __instance, ReferenceHub player)
        {
            try
            {
                if (player == null || __instance.DisableEffect || __instance._correctPosition == null)
                {
                    return(false);
                }

                var synapseplayer = player.GetPlayer();

                if (Vector3.Distance(player.transform.position, __instance._correctPosition.position) > __instance.DistanceToBeAffected)
                {
                    return(false);
                }

                var allow = true;

                if ((__instance.SCPImmune && synapseplayer.Team == (int)Team.SCP) || !SynapseExtensions.CanHarmScp(synapseplayer, false) || synapseplayer.GodMode)
                {
                    allow = false;
                }

                Synapse.Api.Events.EventHandler.Get.Player.InvokeTantrum(synapseplayer, __instance, ref allow);

                if (allow)
                {
                    Synapse.Api.Logger.Get.Debug("ALLOW TANTRUM");
                    synapseplayer.PlayerEffectsController.EnableEffect <CustomPlayerEffects.Stained>(2f, false);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Synapse.Api.Logger.Get.Error("Synapse-Event: PlayerWalkOnSinkholeEvent failed!!\n" + ex);
                return(true);
            }
        }
        public static bool Prefix(Generator079 __instance, GameObject person)
        {
            try
            {
                var player    = person.GetPlayer();
                var generator = __instance.GetGenerator();

                if (player.VanillaInventory == null || __instance._doorAnimationCooldown > 0f || __instance._deniedCooldown > 0f)
                {
                    return(false);
                }

                if (!generator.Locked)
                {
                    var allow = true;
                    if (!generator.Open)
                    {
                        Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, generator, GeneratorInteraction.OpenDoor, ref allow);
                    }
                    else
                    {
                        Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, generator, GeneratorInteraction.CloseDoor, ref allow);
                    }

                    if (!allow)
                    {
                        __instance.RpcDenied();
                        return(false);
                    }

                    generator.Open = !generator.Open;
                    return(false);
                }

                if (!SynapseExtensions.CanHarmScp(player))
                {
                    __instance.RpcDenied();
                    return(false);
                }

                //Unlock The Generator
                var flag = player.Bypass;

                var items = new List <Synapse.Api.Items.SynapseItem>();
                if (Server.Get.Configs.SynapseConfiguration.RemoteKeyCard)
                {
                    items.AddRange(player.Inventory.Items.Where(x => x.ItemCategory == ItemCategory.Keycard));
                }
                else if (player.ItemInHand != null && player.ItemInHand.ItemCategory == ItemCategory.Keycard)
                {
                    items.Add(player.ItemInHand);
                }


                foreach (var item in items)
                {
                    var keycardcanopen = false;
                    var permissions    = player.VanillaInventory.GetItemByID(item.ItemType).permissions;

                    foreach (var t in permissions)
                    {
                        if (t == "ARMORY_LVL_2")
                        {
                            keycardcanopen = true;
                        }
                    }

                    try
                    {
                        Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref keycardcanopen);
                    }
                    catch (Exception e)
                    {
                        Logger.Get.Error($"Synapse-Event: PlayerItemUseEvent(Keycard) failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
                    }

                    if (keycardcanopen)
                    {
                        flag = true;
                        break;
                    }
                }

                Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, generator, GeneratorInteraction.Unlocked, ref flag);

                if (flag)
                {
                    generator.Locked = false;
                    return(false);
                }
                __instance.RpcDenied();

                return(false);
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: DoorInteract failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
                return(true);
            }
        }
Exemple #3
0
        private static bool OnInteract(Scp079Generator __instance, ReferenceHub ply, byte colliderId)
        {
            try
            {
                var gen    = __instance.GetGenerator();
                var player = ply.GetPlayer();

                if (__instance._cooldownStopwatch.IsRunning && __instance._cooldownStopwatch.Elapsed.TotalSeconds < __instance._targetCooldown)
                {
                    return(false);
                }

                if (colliderId != 0 && !gen.Open)
                {
                    return(false);
                }

                __instance._cooldownStopwatch.Stop();

                switch (colliderId)
                {
                case 0:
                    if (!gen.Locked)
                    {
                        var allow = true;
                        Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, gen,
                                                                                    gen.Open ? GeneratorInteraction.CloseDoor : GeneratorInteraction.OpenDoor, ref allow);

                        if (!allow)
                        {
                            return(false);
                        }

                        gen.Open = !gen.Open;
                        __instance._targetCooldown = __instance._doorToggleCooldownTime;
                    }
                    else
                    {
                        if (!SynapseExtensions.CanHarmScp(player))
                        {
                            __instance.RpcDenied();
                            return(false);
                        }

                        var items = new List <SynapseItem>();
                        if (player.ItemInHand.ID != -1)
                        {
                            items.Add(player.ItemInHand);
                        }

                        if (Server.Get.Configs.synapseConfiguration.RemoteKeyCard)
                        {
                            items.AddRange(player.Inventory.Items.Where(x => x != player.ItemInHand));
                        }

                        var canOpen = false;

                        foreach (var item in items.Where(x => x.ItemCategory == ItemCategory.Keycard))
                        {
                            if ((item.ItemBase as KeycardItem).Permissions.HasFlagFast(__instance._requiredPermission))
                            {
                                canOpen = true;
                                Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref canOpen);
                                break;
                            }
                        }

                        Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, gen, GeneratorInteraction.Unlocked, ref canOpen);

                        if (canOpen)
                        {
                            gen.Locked = false;
                        }
                        else
                        {
                            __instance.RpcDenied();
                        }

                        __instance._targetCooldown = __instance._unlockCooldownTime;
                    }
                    break;

                case 1:
                    if ((__instance.Activating || SynapseExtensions.CanHarmScp(player)) && !__instance.Engaged)
                    {
                        var allow = true;
                        Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, gen,
                                                                                    gen.Active ? GeneratorInteraction.Disabled : GeneratorInteraction.Activated, ref allow);

                        if (!allow)
                        {
                            return(false);
                        }

                        __instance.Activating = !__instance.Activating;

                        if (__instance.Activating)
                        {
                            __instance._leverStopwatch.Restart();
                        }

                        __instance._targetCooldown = __instance._doorToggleCooldownTime;
                    }
                    break;

                case 2:
                    if (__instance.Activating && !__instance.Engaged)
                    {
                        var allow = true;
                        Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, gen,
                                                                                    GeneratorInteraction.Disabled, ref allow);

                        if (!allow)
                        {
                            return(false);
                        }

                        gen.Active = false;
                        __instance._targetCooldown = __instance._unlockCooldownTime;
                    }
                    break;


                default:
                    __instance._targetCooldown = 1;
                    break;
                }

                __instance._cooldownStopwatch.Restart();

                return(false);
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: PlayerGeneratorInteract event failed!!\n{e}");
                return(true);
            }
        }
        private static bool Prefix(Generator079 __instance, GameObject person, PlayerInteract.Generator079Operations command)
        {
            try
            {
                var player    = person.GetPlayer();
                var generator = __instance.GetGenerator();

                switch (command)
                {
                case PlayerInteract.Generator079Operations.Tablet:

                    if (generator.IsTabletConnected || !generator.Open || __instance._localTime <= 0f || Generator079.mainGenerator.forcedOvercharge || !SynapseExtensions.CanHarmScp(player))
                    {
                        return(false);
                    }

                    Inventory component = person.GetComponent <Inventory>();

                    using (SyncList <Inventory.SyncItemInfo> .SyncListEnumerator enumerator = component.items.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Inventory.SyncItemInfo syncItemInfo = enumerator.Current;
                            if (syncItemInfo.id == ItemType.WeaponManagerTablet)
                            {
                                bool allow2 = true;
                                var  item   = syncItemInfo.GetSynapseItem();
                                Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, generator, GeneratorInteraction.TabletInjected, ref allow2);
                                Server.Get.Events.Player.InvokePlayerItemUseEvent(player, item, Api.Events.SynapseEventArguments.ItemInteractState.Finalizing, ref allow2);
                                if (!allow2)
                                {
                                    break;
                                }

                                generator.ConnectedTablet = item;
                                break;
                            }
                        }
                    }
                    return(false);

                case PlayerInteract.Generator079Operations.Cancel:
                    if (!generator.IsTabletConnected)
                    {
                        return(false);
                    }

                    bool allow = true;
                    Server.Get.Events.Player.InvokePlayerGeneratorInteractEvent(player, generator, GeneratorInteraction.TabledEjected, ref allow);
                    return(allow);
                }
                return(true);
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: PlayerGenerator failed!!\n{e}\nStackTrace:\n{e.StackTrace}");
                return(true);
            }
        }
Exemple #5
0
        private static bool TriggerEnter(PocketDimensionTeleport __instance, Collider other)
        {
            try
            {
                var component = other.GetComponent <NetworkIdentity>();
                if (component == null)
                {
                    return(false);
                }

                var type   = __instance._type;
                var player = component.GetPlayer();
                var pos    = Vector3.zero;
                if (player == null)
                {
                    return(false);
                }

                var forceEscape = !SynapseExtensions.CanHarmScp(player, false);
                if (player.Hub.scp106PlayerScript.GrabbedPosition == Vector3.zero)
                {
                    player.Hub.scp106PlayerScript.GrabbedPosition = new Vector3(0f, -1997f, 0f);
                }

                var identifier = MapGeneration.RoomIdUtils.RoomAtPosition(player.Hub.scp106PlayerScript.GrabbedPosition);
                if (identifier.Zone == FacilityZone.Surface)
                {
                    foreach (var player2 in Server.Get.Players)
                    {
                        if (player2.RoleType == RoleType.Scp106)
                        {
                            Vector3 objPos = (player2 == null)
                                ? Vector3.zero
                                : player2.PlayerMovementSync.RealModelPosition;
                            SafeTeleportPosition componentInChildren = identifier.GetComponentInChildren <SafeTeleportPosition>();
                            float num  = Vector3.Distance(objPos, componentInChildren.SafePositions[0].position);
                            float num2 = Vector3.Distance(objPos, componentInChildren.SafePositions[1].position);
                            pos = (num2 < num) ? componentInChildren.SafePositions[0].position : componentInChildren.SafePositions[1].position;
                            break;
                        }
                    }
                }
                else
                {
                    var hashSet = MapGeneration.RoomIdUtils.FindRooms(MapGeneration.RoomName.Unnamed, identifier.Zone, MapGeneration.RoomShape.Undefined);

                    /*hashSet.RemoveWhere((MapGeneration.RoomIdentifier room) =>
                     * room.Name == MapGeneration.RoomName.Hcz106 || room.Name == MapGeneration.RoomName.EzGateA ||
                     * room.Name == MapGeneration.RoomName.EzGateB || room.Name == MapGeneration.RoomName.EzEvacShelter ||
                     * (room.Zone == MapGeneration.FacilityZone.LightContainment && room.Shape == MapGeneration.RoomShape.Curve) ||
                     * room.Zone == MapGeneration.FacilityZone.None || room.Name == MapGeneration.RoomName.Pocket ||
                     * room.Name == MapGeneration.RoomName.HczTesla);*/

                    try
                    {
                        while (hashSet.Count > 0)
                        {
                            MapGeneration.RoomIdentifier roomIdentifier2 = hashSet.ElementAt(UnityEngine.Random.Range(0, hashSet.Count));
                            var safepos      = roomIdentifier2.transform.position;
                            var safeTeleport = roomIdentifier2.GetComponentInChildren <SafeTeleportPosition>();
                            if (safeTeleport != null && safeTeleport.SafePositions?.Length != 0)
                            {
                                safepos = safeTeleport.SafePositions[UnityEngine.Random.Range(0, safeTeleport.SafePositions.Length)].position;
                            }

                            if (PlayerMovementSync.FindSafePosition(safepos, out pos, false, true))
                            {
                                break;
                            }
                            hashSet.Remove(roomIdentifier2);
                        }
                    }
                    catch (Exception ex)
                    {
                        //I don't know how but for some Reason this fails sometimes and the method is called a second time
                        //Logger.Get.Debug(ex);
                        return(false);
                    }
                }
                EventHandler.Get.Scp.Scp106.InvokePocketDimensionLeaveEvent(player, ref pos, ref type, out var allow);

                if (!allow)
                {
                    return(false);
                }

                if (!forceEscape && (type == PocketDimensionTeleport.PDTeleportType.Killer || Synapse.Api.Nuke.Get.Detonated))
                {
                    player.PlayerStats.DealDamage(new UniversalDamageHandler(-1f, DeathTranslations.PocketDecay));
                    return(false);
                }
                else
                {
                    player.Position = pos;
                    player.PlayerEffectsController.EnableEffect <CustomPlayerEffects.Disabled>(10f, true);
                    player.PlayerEffectsController.GetEffect <CustomPlayerEffects.Corroding>().Intensity = 0;
                    Achievements.AchievementHandlerBase.ServerAchieve(component.connectionToClient, AchievementName.LarryFriend);
                }
                MapGeneration.ImageGenerator.pocketDimensionGenerator.GenerateRandom();

                return(false);
            }
            catch (Exception e)
            {
                Logger.Get.Error($"Synapse-Event: PocketDimLeave failed!!\n{e}");
                return(true);
            }
        }