private static void Postfix(TeslaGateController __instance)
 {
     SynapseController.Server.Map.Teslas.Clear();
     foreach (var tesla in __instance.TeslaGates)
     {
         SynapseController.Server.Map.Teslas.Add(new Tesla(tesla));
     }
 }
Example #2
0
        private static bool Prefix(TeslaGateController __instance)
        {
            foreach (KeyValuePair<GameObject, ReferenceHub> allHub in ReferenceHub.GetAllHubs())
            {
                if (allHub.Value.characterClassManager.CurClass == RoleType.Spectator)
                    continue;
                foreach (TeslaGate teslaGate in __instance.TeslaGates)
                {
                    if (!teslaGate.PlayerInRange(allHub.Value) || teslaGate.InProgress)
                        continue;

                    var ev = new TriggeringTeslaEventArgs(API.Features.Player.Get(allHub.Key), teslaGate.PlayerInHurtRange(allHub.Key));
                    Player.OnTriggeringTesla(ev);

                    if (ev.IsTriggerable)
                        teslaGate.ServerSideCode();
                }
            }

            return false;
        }
Example #3
0
        private static bool Prefix(TeslaGateController __instance)
        {
            try
            {
                foreach (KeyValuePair <GameObject, ReferenceHub> allHub in ReferenceHub.GetAllHubs())
                {
                    if (allHub.Value.characterClassManager.CurClass == RoleType.Spectator)
                    {
                        continue;
                    }
                    foreach (TeslaGate teslaGate in __instance.TeslaGates)
                    {
                        if (!teslaGate.PlayerInRange(allHub.Value) || teslaGate.InProgress)
                        {
                            continue;
                        }

                        var ev = new TriggeringTeslaEventArgs(API.Features.Player.Get(allHub.Key), teslaGate.PlayerInHurtRange(allHub.Key));
                        Player.OnTriggeringTesla(ev);

                        if (ev.IsTriggerable)
                        {
                            teslaGate.ServerSideCode();
                        }
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                Exiled.API.Features.Log.Error($"Exiled.Events.Patches.Events.Player.TriggeringTesla: {e}\n{e.StackTrace}");

                return(true);
            }
        }
Example #4
0
        private static bool Prefix(TeslaGateController __instance)
        {
            try
            {
                if (!Round.IsStarted)
                {
                    return(false);
                }

                if (TeslaGate.TeslasValue.Count == 0)
                {
                    return(true);
                }
                foreach (BaseTeslaGate baseTeslaGate in __instance.TeslaGates)
                {
                    if (!baseTeslaGate.isActiveAndEnabled || baseTeslaGate.InProgress)
                    {
                        continue;
                    }

                    if (baseTeslaGate.NetworkInactiveTime > 0f)
                    {
                        baseTeslaGate.NetworkInactiveTime = Mathf.Max(0f, baseTeslaGate.InactiveTime - Time.fixedDeltaTime);
                        continue;
                    }

                    TeslaGate teslaGate     = TeslaGate.Get(baseTeslaGate);
                    bool      inIdleRange   = false;
                    bool      isTriggerable = false;

                    foreach (Player player in Player.List)
                    {
                        try
                        {
                            if (player is null || !teslaGate.CanBeIdle(player))
                            {
                                continue;
                            }

                            TriggeringTeslaEventArgs ev = new(player, teslaGate);
                            Handlers.Player.OnTriggeringTesla(ev);

                            if (ev.IsTriggerable && !isTriggerable)
                            {
                                isTriggerable = ev.IsTriggerable;
                            }

                            if (ev.IsInIdleRange && !inIdleRange)
                            {
                                inIdleRange = ev.IsInIdleRange;
                            }
                        }
#pragma warning disable CS0168
                        catch (Exception e)
#pragma warning restore CS0168
                        {
#if DEBUG
                            Log.Error($"{nameof(TriggeringTesla)}.Prefix: {e}");
#endif
                        }
                    }

                    if (isTriggerable)
                    {
                        teslaGate.Trigger();
                    }

                    if (inIdleRange != teslaGate.IsIdling)
                    {
                        teslaGate.IsIdling = inIdleRange;
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                Log.Error($"Exiled.Events.Patches.Events.Player.TriggeringTesla: {e}\n{e.StackTrace}");
                return(true);
            }
        }
Example #5
0
        private static bool Prefix(TeslaGateController __instance)
        {
            try
            {
                foreach (TeslaGate teslaGate in __instance.TeslaGates)
                {
                    if (!teslaGate.isActiveAndEnabled || teslaGate.InProgress)
                    {
                        continue;
                    }

                    if (teslaGate.NetworkInactiveTime > 0f)
                    {
                        teslaGate.NetworkInactiveTime = Mathf.Max(0f, teslaGate.InactiveTime - Time.fixedDeltaTime);
                        continue;
                    }

                    bool inIdleRange   = false;
                    bool isTriggerable = false;
                    foreach (KeyValuePair <GameObject, ReferenceHub> allHub in ReferenceHub.GetAllHubs())
                    {
                        if (allHub.Value.isDedicatedServer || allHub.Value.characterClassManager.CurClass == RoleType.Spectator)
                        {
                            continue;
                        }

                        if (teslaGate.PlayerInIdleRange(allHub.Value))
                        {
                            TriggeringTeslaEventArgs ev = new TriggeringTeslaEventArgs(API.Features.Player.Get(allHub.Key), teslaGate, teslaGate.PlayerInHurtRange(allHub.Key), teslaGate.PlayerInRange(allHub.Value));
                            Player.OnTriggeringTesla(ev);

                            if (ev.IsTriggerable && !isTriggerable)
                            {
                                isTriggerable = ev.IsTriggerable;
                            }

                            if (!inIdleRange)
                            {
                                inIdleRange = ev.IsInIdleRange;
                            }
                        }
                    }

                    if (isTriggerable)
                    {
                        teslaGate.ServerSideCode();
                    }

                    if (inIdleRange != teslaGate.isIdling)
                    {
                        teslaGate.ServerSideIdle(inIdleRange);
                    }
                }

                return(false);
            }
            catch (Exception e)
            {
                API.Features.Log.Error($"Exiled.Events.Patches.Events.Player.TriggeringTesla: {e}\n{e.StackTrace}");

                return(true);
            }
        }