Example #1
0
        public static void Prefix(ExileController __instance, [HarmonyArgument(0)] ref GameData.PlayerInfo exiled, [HarmonyArgument(1)] bool tie)
        {
            lastExiled = exiled;

            // Medic shield
            if (Medic.medic != null && AmongUsClient.Instance.AmHost && Medic.futureShielded != null && !Medic.medic.Data.IsDead)   // We need to send the RPC from the host here, to make sure that the order of shifting and setting the shield is correct(for that reason the futureShifted and futureShielded are being synced)
            {
                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.MedicSetShielded, Hazel.SendOption.Reliable, -1);
                writer.Write(Medic.futureShielded.PlayerId);
                AmongUsClient.Instance.FinishRpcImmediately(writer);
                RPCProcedure.medicSetShielded(Medic.futureShielded.PlayerId);
            }

            // Madmate exiled
            if (AmongUsClient.Instance.AmHost &&
                exiled != null &&
                ((CreatedMadmate.exileCrewmate &&
                  exiled.Object.hasModifier(ModifierType.CreatedMadmate)) ||
                 (Madmate.exileCrewmate &&
                  exiled.Object.hasModifier(ModifierType.Madmate))))
            {
                // pick random crewmate
                PlayerControl target = pickRandomCrewmate(exiled.PlayerId);
                if (target != null)
                {
                    // exile the picked crewmate
                    MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
                                                                                      (byte)CustomRPC.UncheckedExilePlayer,
                                                                                      Hazel.SendOption.Reliable,
                                                                                      -1);
                    writer.Write(target.PlayerId);
                    AmongUsClient.Instance.FinishRpcImmediately(writer);
                    RPCProcedure.uncheckedExilePlayer(target.PlayerId);
                }
            }

            // Shifter shift
            if (Shifter.shifter != null && AmongUsClient.Instance.AmHost && Shifter.futureShift != null)   // We need to send the RPC from the host here, to make sure that the order of shifting and erasing is correct (for that reason the futureShifted and futureErased are being synced)
            {
                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ShifterShift, Hazel.SendOption.Reliable, -1);
                writer.Write(Shifter.futureShift.PlayerId);
                AmongUsClient.Instance.FinishRpcImmediately(writer);
                RPCProcedure.shifterShift(Shifter.futureShift.PlayerId);
            }
            Shifter.futureShift = null;

            // Eraser erase
            if (Eraser.eraser != null && AmongUsClient.Instance.AmHost && Eraser.futureErased != null)    // We need to send the RPC from the host here, to make sure that the order of shifting and erasing is correct (for that reason the futureShifted and futureErased are being synced)
            {
                foreach (PlayerControl target in Eraser.futureErased)
                {
                    if (target != null && target.canBeErased())
                    {
                        MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ErasePlayerRoles, Hazel.SendOption.Reliable, -1);
                        writer.Write(target.PlayerId);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);
                        RPCProcedure.erasePlayerRoles(target.PlayerId);
                    }
                }
            }
            Eraser.futureErased = new List <PlayerControl>();

            // Trickster boxes
            if (Trickster.trickster != null && JackInTheBox.hasJackInTheBoxLimitReached())
            {
                JackInTheBox.convertToVents();
            }

            // Witch execute casted spells
            if (Witch.witch != null && Witch.futureSpelled != null && AmongUsClient.Instance.AmHost)
            {
                bool exiledIsWitch            = exiled != null && exiled.PlayerId == Witch.witch.PlayerId;
                bool witchDiesWithExiledLover = exiled != null && Lovers.bothDie && exiled.Object.isLovers() && exiled.Object.getPartner() == Witch.witch;

                if ((witchDiesWithExiledLover || exiledIsWitch) && Witch.witchVoteSavesTargets)
                {
                    Witch.futureSpelled = new List <PlayerControl>();
                }
                foreach (PlayerControl target in Witch.futureSpelled)
                {
                    if (target != null && !target.Data.IsDead && Helpers.checkMuderAttempt(Witch.witch, target, true) == MurderAttemptResult.PerformKill)
                    {
                        MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.WitchSpellCast, Hazel.SendOption.Reliable, -1);
                        writer.Write(target.PlayerId);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);
                        RPCProcedure.witchSpellCast(target.PlayerId);
                    }
                }
            }
            Witch.futureSpelled = new List <PlayerControl>();

            // SecurityGuard vents and cameras
            var allCameras = ShipStatus.Instance.AllCameras.ToList();

            MapOptions.camerasToAdd.ForEach(camera => {
                camera.gameObject.SetActive(true);
                camera.gameObject.GetComponent <SpriteRenderer>().color = Color.white;
                allCameras.Add(camera);
            });
            ShipStatus.Instance.AllCameras = allCameras.ToArray();
            MapOptions.camerasToAdd        = new List <SurvCamera>();

            foreach (Vent vent in MapOptions.ventsToSeal)
            {
                PowerTools.SpriteAnim animator = vent.GetComponent <PowerTools.SpriteAnim>();
                animator?.Stop();
                vent.EnterVentAnim = vent.ExitVentAnim = null;
                vent.myRend.sprite = animator == null?SecurityGuard.getStaticVentSealedSprite() : SecurityGuard.getAnimatedVentSealedSprite();

                if (SubmergedCompatibility.isSubmerged() && vent.Id == 0)
                {
                    vent.myRend.sprite = SecurityGuard.getSubmergedCentralUpperSealedSprite();
                }
                if (SubmergedCompatibility.isSubmerged() && vent.Id == 14)
                {
                    vent.myRend.sprite = SecurityGuard.getSubmergedCentralLowerSealedSprite();
                }
                vent.myRend.color = Color.white;
                vent.name         = "SealedVent_" + vent.name;
            }
            MapOptions.ventsToSeal = new List <Vent>();

            // 1 = reset per turn
            if (MapOptions.restrictDevices == 1)
            {
                MapOptions.resetDeviceTimes();
            }
        }