public static bool CheckCultistWin() { CLog.Info("CHECK CULTIST WIN:"); int alive = 0; int cultists = 0; foreach (PlayerControl player in PlayerControl.AllPlayerControls) { if (!player.Data.IsDead) { alive++; if (IsCultist(player.PlayerId)) { cultists++; CLog.Info("FOUND ALIVE CULTIST: " + player.name); } } } if (ImpostorDummyCount > 0) { alive--; } if (alive / 2 < cultists) { CLog.Info("-----CULTIST WIN-----"); return(true); } else { CLog.Info("Cultists did not win."); } return(false); }
static void Postfix(byte HKHMBLJFLMC, MessageReader ALMCIJKELCP) { byte packetId = HKHMBLJFLMC; MessageReader reader = ALMCIJKELCP; switch (packetId) { case ((byte)CustomRPC.SetCultist): CLog.Info("Cultist Set Through RPC!"); ClearCultistLists(); DidCultistsWin = false; byte CultistId = ALMCIJKELCP.ReadByte(); foreach (PlayerControl player in PlayerControl.AllPlayerControls) { if (player.PlayerId == CultistId) { InitialCultist = player; AddCultistToLists(player); CLog.Info("SET PLAYER TO CULTIST " + player.name); } } CLog.Info("Setting Cultist Settings"); SetCultistSettings(); CLog.Info("Cultist list after cultist set through RPC:"); break; case ((byte)CustomRPC.ConvertAction): CLog.Info("Conversion from RPC!"); byte CultistThatCalledId = ALMCIJKELCP.ReadByte(); byte TargetId = ALMCIJKELCP.ReadByte(); foreach (PlayerControl player in PlayerControl.AllPlayerControls) { if (player.PlayerId == TargetId && !IsCultist(player.PlayerId)) { CLog.Info(player.Data.PlayerName + "is now a cultist."); AddCultistToLists(player); for (int i = 0; i < player.myTasks.Count; i++) { PlayerTask playerTask = player.myTasks[i]; player.RemoveTask(playerTask); } player.myTasks.Clear(); ImportantTextTask convertedTask = new GameObject("CultistTask").AddComponent <ImportantTextTask>(); convertedTask.transform.SetParent(player.transform, false); convertedTask.Text = PlayerTools.getPlayerById(CultistThatCalledId).name + " converted you to the cult.\nHelp your cult leader convert other crewmates."; player.myTasks.Insert(0, convertedTask); } } if (CheckCultistWin()) { CLog.Info("Cultists won by conversion."); ExecuteCultistWin(); } break; case ((byte)CustomRPC.KillDummy): PlayerControl playerToRemove = null; foreach (var player in PlayerControl.AllPlayerControls) { if (player.name == "IMPOSTOR_DUMMY") { playerToRemove = player; } } if (playerToRemove != null) { CLog.Info("Killing dummy after receiving RPC command."); GameData.Instance.RemovePlayer(playerToRemove.PlayerId); PlayerControl.AllPlayerControls.Remove(playerToRemove); if (CheckCultistWin()) { ExecuteCultistWin(); } } break; case (byte)RPC.MurderPlayer: DisableGameEnd = false; break; case (byte)CustomRPC.ConversionsLeft: byte conversionsLeft = ALMCIJKELCP.ReadByte(); ConversionsLeft = conversionsLeft; break; } }
static void Postfix(MeetingHud __instance) { if (IsCultistUsed) { if (DoCrewmatesWinWhenImpostorsAreDead) { return; } CLog.Info("In Postfix Meeting"); if (AmongUsClient.Instance.AmHost) { bool shouldCreateDummy = false; if (__instance.exiledPlayer != null) { int amntAliveImpostors = 0; int amntAliveCultists = 0; int amntAliveCrewmates = 0; foreach (var player in PlayerControl.AllPlayerControls) { if (!player.Data.IsDead) { if (player.Data.IsImpostor) { amntAliveImpostors++; } else if (IsCultist(player.PlayerId)) { amntAliveCultists++; } else { amntAliveCrewmates++; } } } CLog.Info("Alive Impostors: " + amntAliveImpostors + " amnt alive cultists: " + amntAliveCultists); if (!IsCultist(__instance.exiledPlayer.PlayerId) && (amntAliveCultists > (amntAliveCrewmates + amntAliveImpostors - 1))) { CLog.Info("CULTISTS WIN BY VOTING OFF, not creating dummy.!"); return; } if (IsCultist(__instance.exiledPlayer.PlayerId) && amntAliveCrewmates > 0 && amntAliveCultists <= 1 && amntAliveImpostors == 0) { CLog.Info("Crewmates WIN BY VOTING last Cultists OFF, not creating dummy.!"); return; } //if last impostor just got kicked, might need to create dummy if cultists left in the game if (amntAliveImpostors == 1 && amntAliveCultists > 0 && __instance.exiledPlayer.IsImpostor) { shouldCreateDummy = true; } } // if there was an dummy already we need a new one, if the voting ended in a skip if (ImpostorDummyCount > 0) { shouldCreateDummy = true; } if (shouldCreateDummy) { CLog.Info("Creating Dummy Impostor"); DisableGameEnd = true; ImpostorDummyCount++; var gameObject = new GameObject(nameof(ImpostorDummy)).DontDestroy(); var dummy = gameObject.AddComponent <ImpostorDummy>(); //this means DisableEndGame stays true until after the Death which is Important return; } } CLog.Info("End of postfix!"); DisableGameEnd = false; } }
public static bool Prefix() { if (PlayerControl.LocalPlayer.Data.IsDead) { return(false); } if (PlayerControl.LocalPlayer.Data.IsImpostor) { return(true); } if (IsCultistUsed && CurrentTarget != null && !PlayerControl.LocalPlayer.Data.IsImpostor) { PlayerControl target = CurrentTarget; if (PlayerControl.LocalPlayer == InitialCultist && PlayerTools.GetConversionCooldown() == 0) { bool createNewTask = false; var player = PlayerControl.LocalPlayer; CLog.Info("CULTIST TRYING TO CONVERT!"); CLog.Info("Target is Impostor:" + target.Data.IsImpostor); CLog.Info("Target is Cultist:" + IsCultist(target.PlayerId)); if (!target.Data.IsImpostor && !IsCultist(target.PlayerId)) { if (ConversionsLeft > 0) { MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately( PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ConvertAction, Hazel.SendOption.None, -1); writer.Write(PlayerControl.LocalPlayer.PlayerId); writer.Write(target.PlayerId); AmongUsClient.Instance.FinishRpcImmediately(writer); AddCultistToLists(target); ConversionsLeft--; LastConversion = DateTime.UtcNow; if (CheckCultistWin()) { ExecuteCultistWin(); } var tasksToRemove = new List <PlayerTask>(); foreach (var task in target.myTasks) { if (task.TaskType != TaskTypes.FixComms && task.TaskType != TaskTypes.FixLights && task.TaskType != TaskTypes.ResetReactor && task.TaskType != TaskTypes.ResetSeismic && task.TaskType != TaskTypes.RestoreOxy) { tasksToRemove.Add(task); } } foreach (var taskToRemove in tasksToRemove) { player.RemoveTask(taskToRemove); } target.myTasks.Clear(); CLog.Info("Done with removing tasks for target!"); createNewTask = true; } } if (target.Data.IsImpostor) { LastConversion = DateTime.UtcNow; if (ImpostorConversionAttemptUsesConversion) { if (ConversionsLeft > 0) { ConversionsLeft--; createNewTask = true; } } } if (createNewTask) { MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately( PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ConversionsLeft, Hazel.SendOption.None, -1); writer.Write(ConversionsLeft); AmongUsClient.Instance.FinishRpcImmediately(writer); ImportantTextTask cultLeaderTask = new GameObject("CultistLeaderTask").AddComponent <ImportantTextTask>(); cultLeaderTask.transform.SetParent(player.transform, false); cultLeaderTask.Text = "You are the cult leader.\nConvert crewmates to your cult.\nConversions left: " + ConversionsLeft + "/" + MaxCultistConversions; player.myTasks.Clear(); player.myTasks.Insert(0, cultLeaderTask); } return(false); } } return(true); }