eDonnes124 / Town-Of-Us-R

An Among Us mod containing a bunch of roles
GNU General Public License v3.0
345 stars 140 forks source link

[Prob a bug] Neutral roles win if crewmates do their tasks #138

Closed Stivek16 closed 1 year ago

Stivek16 commented 1 year ago

Im pretty sure that neutral roles shouldnt win when tasks are finished, esspecially the neutral killing roles.

AlchlcDvl commented 1 year ago

the only neutrals capable of winning from tasks are survivors and guardian angels with crew targets

Stivek16 commented 1 year ago

I won with pestilence by tasks once

AlchlcDvl commented 1 year ago

were you amnesiac turned plaguebearer by any chance?

Stivek16 commented 1 year ago

No, but it dosent happen anymore idk why

AlchlcDvl commented 1 year ago

then it's probably a rare unintentional bug, try repeating the events of the game to see what might be causing it in case it happens again

eDonnes124 commented 1 year ago

This isn't the only way for neutrals to win with crewmates. This bug has existed since the beginning of Town of Us (even before I took over). The same goes for GA/Surv sometimes not winning with Imps when they should.

Er1ckW commented 1 year ago

It seems game never finished by humansTask. I add logs in EndGame.cs.

namespace TownOfUs.NeutralRoles.GlitchMod
{
    [HarmonyPatch(typeof(GameManager), nameof(GameManager.RpcEndGame))]
    public class EndGame
    {
        public static bool Prefix(GameManager __instance, [HarmonyArgument(0)] GameOverReason reason)
        {
            PluginSingleton<TownOfUs>.Instance.Log.LogMessage("Game Over Reason:" + reason.ToString());
            if (reason != GameOverReason.HumansByVote && reason != GameOverReason.HumansByTask) return true;

            foreach (var role in Role.AllRoles)
                if (role.RoleType == RoleEnum.Glitch)
                    ((Glitch) role).Loses();

            var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                (byte) CustomRPC.GlitchLose,
                SendOption.Reliable, -1);
            AmongUsClient.Instance.FinishRpcImmediately(writer);

            return true;
        }
    }
}
  1. When only 1 killing-neutral and 1 impostor remain in the game, the ghost crewmates complete all the tasks, but impostor wins. [Message:Town Of Us] Game Over Reason:ImpostorByKill
  2. If impostor is dead, left 1 killing- neutral role and 2 crewmates, crewmates complete all the tasks and win the game. But log is[Message:Town Of Us] Game Over Reason:HumansByVote.
  3. No one died, and crewmates complete all the tasks, killing-neutral wins the game with crewmates, no log output.

I try to fix this bug below, it solves all the problems and not affects haunter and phantom, but I'm not sure that's best practice.

https://github.com/eDonnes124/Town-Of-Us-R/blob/4528c3fddc388efa8ff791317c2728d56312fc47/source/Patches/Roles/Role.cs#L633

if (GameData.Instance.TotalTasks <= GameData.Instance.CompletedTasks)
{
    GameManager.Instance.RpcEndGame(GameOverReason.HumansByTask, false);
}
eDonnes124 commented 1 year ago

Fixed in v5.0.0.