Esempio n. 1
0
        private void OnExplodingGrenade(ExplodingGrenadeEventArgs ev)
        {
            if (Check(ev.Grenade))
            {
                Log.Debug($"{ev.Thrower.Nickname} threw an implosion grenade!", CustomItems.Instance.Config.IsDebugEnabled);
                Dictionary <Player, float> copiedList = new Dictionary <Player, float>();
                foreach (KeyValuePair <Player, float> kvp in ev.TargetToDamages)
                {
                    if (kvp.Value > 0)
                    {
                        copiedList.Add(kvp.Key, kvp.Value);
                    }
                }

                ev.TargetToDamages.Clear();
                Log.Debug("IG: List cleared.", CustomItems.Instance.Config.IsDebugEnabled);
                effectedPlayers = NorthwoodLib.Pools.ListPool <Player> .Shared.Rent();

                foreach (Player player in copiedList.Keys)
                {
                    ev.TargetToDamages.Add(player, copiedList[player] * DamageModifier);
                    if (BlacklistedRoles.Contains(player.Role))
                    {
                        continue;
                    }

                    Log.Debug($"{player.Nickname} starting suction", CustomItems.Instance.Config.IsDebugEnabled);

                    try
                    {
                        if (layerMask == 0)
                        {
                            layerMask = ev.Grenade.GetComponent <FragGrenade>().hurtLayerMask;
                        }

                        foreach (Transform grenadePoint in player.ReferenceHub.playerStats.grenadePoints)
                        {
                            bool line = Physics.Linecast(ev.Grenade.transform.position, grenadePoint.position, layerMask);
                            Log.Debug($"{player.Nickname} - {line}", CustomItems.Instance.Config.IsDebugEnabled);
                            if (!line)
                            {
                                effectedPlayers.Add(player);
                                Coroutines.Add(Timing.RunCoroutine(DoSuction(player, ev.Grenade.transform.position + (Vector3.up * 1.5f))));
                                break;
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error($"{nameof(OnExplodingGrenade)} error: {exception}");
                    }
                }
            }
        }
        /// <inheritdoc/>
        protected override void OnExploding(ExplodingGrenadeEventArgs ev)
        {
            ev.IsAllowed = false;
            Log.Debug($"{ev.Thrower.Nickname} threw an implosion grenade!", CustomItems.Instance.Config.IsDebugEnabled);
            List <Player> copiedList = new List <Player>();

            foreach (Player player in ev.TargetsToAffect)
            {
                copiedList.Add(player);
            }

            ev.TargetsToAffect.Clear();
            Log.Debug("IG: List cleared.", CustomItems.Instance.Config.IsDebugEnabled);
            effectedPlayers = NorthwoodLib.Pools.ListPool <Player> .Shared.Rent();

            foreach (Player player in copiedList)
            {
                if (BlacklistedRoles.Contains(player.Role))
                {
                    continue;
                }

                Log.Debug($"{player.Nickname} starting suction", CustomItems.Instance.Config.IsDebugEnabled);

                try
                {
                    if (layerMask == 0)
                    {
                        if (ev.Grenade is ExplosionGrenade explosionGrenade)
                        {
                            layerMask = explosionGrenade._detectionMask;
                        }
                    }

                    bool line = Physics.Linecast(ev.Grenade.transform.position, player.Position, layerMask);
                    Log.Debug($"{player.Nickname} - {line}", CustomItems.Instance.Config.IsDebugEnabled);
                    if (line)
                    {
                        effectedPlayers.Add(player);
                        Coroutines.Add(Timing.RunCoroutine(DoSuction(player, ev.Grenade.transform.position + (Vector3.up * 1.5f))));
                    }
                }
                catch (Exception exception)
                {
                    Log.Error($"{nameof(OnExploding)} error: {exception}");
                }
            }
        }