Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Event StartingRecallEventArgs's IsAllowed issue. #2226

Closed
wants to merge 18 commits into from
Closed

Fixed Event StartingRecallEventArgs's IsAllowed issue. #2226

wants to merge 18 commits into from

Conversation

XKaguya
Copy link
Contributor

@XKaguya XKaguya commented Nov 11, 2023

StartingRecallEventArgs's IsAllowed won't stop the event. Patch at RagdollAbilityBase could solve this.

NaoUnderscore and others added 12 commits September 10, 2023 16:22
* Added ChaosTargetCount

* a

* Updated

* Fix build errors

---------

Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
Co-authored-by: Nao <60253860+NaoUnderscore@users.noreply.github.com>
Grammar fixes. This includes fixing multiple it's to its, removal of unnecessary commas, and removal of redundancies.
Now the IsAllowed will work as what it should be.
@XKaguya
Copy link
Contributor Author

XKaguya commented Nov 11, 2023

The part of

                // base.CurRagdoll
                new(OpCodes.Ldarg_1),
                new(OpCodes.Callvirt, PropertyGetter(typeof(RagdollAbilityBase<Scp049Role>), nameof(RagdollAbilityBase<Scp049Role>.CurRagdoll))),

currently will lead into crash , dont merge before if i can fix this bug.Another option is to give up acquiring Target players, although I know this is not realistic, lol

@louis1706
Copy link
Member

louis1706 commented Nov 11, 2023

this will also be call for Scp0492 'RagdollAbilityBase'

@XKaguya
Copy link
Contributor Author

XKaguya commented Nov 11, 2023

this will also be call for Scp0492 'RagdollAbilityBase'

yes , that is what the arg used for.Actually it will be call by Scp3114, but to doing limits on the Player , then it can be avoided.

@XKaguya
Copy link
Contributor Author

XKaguya commented Nov 11, 2023

The problem about previous patch's IsAllowed is not vailed is because NW using non-zero as error code.Meanwhile Transpiler can't modify the return value.
So the patch must use Prefix instead of Transpiler .
Things are all done now.This event can get Target, Player, Ragdoll and IsAllowed.

By using

using System;
using Exiled.API.Features;
using PlayerRoles;
using System.Linq;
using Exiled.Events.EventArgs.Scp049;
using LimitZombie.Events.EventArgs.Scp049;
using static PlayerRoles.PlayableScps.Scp049.Zombies.ZombieAudioPlayer;

namespace LimitZombie
{
    public class ResurrectHandler
    {
        public static void ShowMessageOnConsole(int playerCount, int zombieCount, bool IsAllowed, bool IsMaxed)
        {
            int Limit;
            
            if (IsMaxed)
            {
                CalcLimit(playerCount, out Limit);
                Log.Info($"SCP-049-2 count is {zombieCount}.Max {Limit} Event blocked.");
                Log.Info("Executed branch 2.");
                Log.Info($"Current Flag: {IsAllowed}");
            }
            else
            {
                CalcLimit(playerCount, out Limit);
                Log.Info($"SCP-049-2 count is {zombieCount}.Max {Limit} Event is not blocked.");
                Log.Info("Executed branch 1.");
                Log.Info($"Current Flag: {IsAllowed}");
            }
        }

        public static void CalcLimit(int count, out int limit)
        {
            limit = (int)Math.Round(count * 2.0 / 3.0);
        }
        
        public static void OnResurrect(StartingRecallEventArgsMod ev)
        {
            Log.Info($"ev type: {ev.GetType().FullName}");

            Log.Info($"ev.IsAllowed: {ev?.IsAllowed}");
            Log.Info($"ev.Player: {ev?.Player}");
            Log.Info($"ev.Ragdoll: {ev?.Ragdoll}");

            Player player = ev.Player;
            Player target = ev.Ragdoll.Owner ?? null;

            Log.Info($"Executed Player: {player}");
            Log.Info($"Target Player: {target}");

            Log.Info($"Entering OnResurrect. Initial IsAllowed: {ev.IsAllowed}");

            if (player.Role.Type == RoleTypeId.Scp049)
            {
                bool Test = true;
                if (Test)
                {
                    int scp0492Count = Player.List.Count(player => player.Role == RoleTypeId.Scp0492);
                    int playerList = Player.List.Count;
                    int scpList = Player.List.Count(player => player.Role.Type == RoleTypeId.Scp049 || player.Role.Type == RoleTypeId.Scp096 || player.Role.Type == RoleTypeId.Scp106 || player.Role.Type == RoleTypeId.Scp3114 || player.Role.Type == RoleTypeId.Scp173 || player.Role.Type == RoleTypeId.Scp939 || player.Role.Type == RoleTypeId.Scp096);
                    int playerCount = playerList - scpList;
                    int Limit;

                    CalcLimit(playerCount, out Limit);
                    string msg = $"本局非SCP人数:{playerCount},本局最多可同时存在{Limit}个小僵尸。目前小僵尸数量:{scp0492Count}";

                    Log.Info($"Entering Method OnResurrect");
                    if (scp0492Count == Limit)
                    {
                        Log.Info("Event is now Blocked.");
                        player.Broadcast(5, msg, Broadcast.BroadcastFlags.Normal, true);
                        ShowMessageOnConsole(playerCount, scp0492Count, ev.IsAllowed, true);
                        ev.IsAllowed = false;
                    }
                    else
                    {
                        Log.Info("Event is not Blocked.");
                        player.Broadcast(5, msg, Broadcast.BroadcastFlags.Normal, true);
                        ShowMessageOnConsole(playerCount, scp0492Count, ev.IsAllowed, false);
                        ev.IsAllowed = true;
                    }
                }
                else
                {
                    int scp0492Count = Player.List.Count(player => player.Role == RoleTypeId.Scp0492);
                    int playerList = Player.List.Count;
                    int scpList = Player.List.Count(player => player.Role.Type == RoleTypeId.Scp049 || player.Role.Type == RoleTypeId.Scp096 || player.Role.Type == RoleTypeId.Scp106 || player.Role.Type == RoleTypeId.Scp3114 || player.Role.Type == RoleTypeId.Scp173 || player.Role.Type == RoleTypeId.Scp939 || player.Role.Type == RoleTypeId.Scp096);
                    int playerCount = playerList - scpList;
                    int Limit;

                    CalcLimit(playerCount, out Limit);
                    string msg = $"本局非SCP人数:{playerCount},本局最多可同时存在{Limit}个小僵尸。目前小僵尸数量:{scp0492Count}";

                    player.Broadcast(5, msg, Broadcast.BroadcastFlags.Normal, true);
                    ShowMessageOnConsole(playerCount, scp0492Count, ev.IsAllowed, false);
                    ev.IsAllowed = true;
                }
            }
            Log.Info($"Exiting OnResurrect. Final IsAllowed: {ev.IsAllowed}");
        }
    }
}

The event written by myself.I can get such info:

[2023-11-12 01:26:07.933 +08:00] [INFO] [LimitZombie] ev type: LimitZombie.Events.EventArgs.Scp049.StartingRecallEventArgsMod
[2023-11-12 01:26:07.945 +08:00] [INFO] [LimitZombie] ev.IsAllowed: True
[2023-11-12 01:26:07.956 +08:00] [INFO] [LimitZombie] ev.Player: 2 (辉夜) [76561198372680760@steam] *Scp SCPs Scp049 True*
[2023-11-12 01:26:07.968 +08:00] [INFO] [LimitZombie] ev.Ragdoll: 4 (Dummy) [Dummy@localhost] *None Dead Spectator True* (Ragdoll_1(Clone)) [Killed directly by SCP-049 (辉夜).] *ClassD* |12/11/2023 01:26:07| =False=
[2023-11-12 01:26:07.979 +08:00] [INFO] [LimitZombie] Executed Player: 2 (辉夜) [76561198372680760@steam] *Scp SCPs Scp049 True*
[2023-11-12 01:26:07.992 +08:00] [INFO] [LimitZombie] Target Player: 4 (Dummy) [Dummy@localhost] *None Dead Spectator True*
[2023-11-12 01:26:08.005 +08:00] [INFO] [LimitZombie] Entering OnResurrect. Initial IsAllowed: True
[2023-11-12 01:26:08.016 +08:00] [INFO] [LimitZombie] Entering Method OnResurrect
[2023-11-12 01:26:08.027 +08:00] [INFO] [LimitZombie] Event is now Blocked.
[2023-11-12 01:26:08.039 +08:00] [INFO] [LimitZombie] SCP-049-2 count is 1.Max 1 Event blocked.
[2023-11-12 01:26:08.051 +08:00] [INFO] [LimitZombie] Executed branch 2.
[2023-11-12 01:26:08.063 +08:00] [INFO] [LimitZombie] Current Flag: True
[2023-11-12 01:26:08.074 +08:00] [INFO] [LimitZombie] Exiting OnResurrect. Final IsAllowed: False

@louis1706
Copy link
Member

IsAllowed

Transpiler can modify return value ???

@XKaguya
Copy link
Contributor Author

XKaguya commented Nov 11, 2023

IsAllowed

Transpiler can modify return value ???

uh , letme try that lol , forget its just stack

@XKaguya
Copy link
Contributor Author

XKaguya commented Nov 11, 2023

IsAllowed

Transpiler can modify return value ???

Alright. now i've rewritten as Transpiler.And tested.

@Misaka-ZeroTwo
Copy link
Member

Please target dev branch.

/// <param name="isAllowed">
/// <inheritdoc cref="IsAllowed" />
/// </param>
public StartingRecallEventArgsMod(Player player, Ragdoll ragdoll, bool isAllowed = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public StartingRecallEventArgsMod(Player player, Ragdoll ragdoll, bool isAllowed = true)
public StartingRecallEventArgs(Player player, Ragdoll ragdoll, bool isAllowed = true)

@XKaguya
Copy link
Contributor Author

XKaguya commented Nov 12, 2023

Please target dev branch.

OK I'll do it after i get up

@XKaguya XKaguya changed the base branch from master to dev November 12, 2023 04:56
@Misaka-ZeroTwo
Copy link
Member

You will need to create a separate PR to prevent conflicts.

@XKaguya XKaguya closed this by deleting the head repository Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants