Esempio n. 1
0
 public bool IsPlayerRole(ModdedPlayerClass player, string roleName)
 {
     if (player?.Role?.RoleName == roleName)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
        public void RpcAssignRole(ModdedPlayerClass player, Role role)
        {
            AssignRole(player, role);

            MessageWriter writer = AmongUsClient.Instance.StartRpc(PlayerControl.LocalPlayer.NetId, (byte)Packets.AssignRole, SendOption.Reliable);

            writer.Write(player._Object.PlayerId);
            writer.Write(role.RoleName);
            writer.EndMessage();
        }
Esempio n. 3
0
        public void RpcCreateCrucio(Vector2 pos, ModdedPlayerClass Owner)
        {
            CreateCrucio(pos, Owner);

            MessageWriter writer = AmongUsClient.Instance.StartRpc(PlayerControl.LocalPlayer.NetId, (byte)Packets.CreateCrucio, SendOption.Reliable);

            writer.Write(Owner._Object.PlayerId);
            writer.Write(pos.x);
            writer.Write(pos.y);
            writer.EndMessage();
        }
Esempio n. 4
0
        public string GetRoleHexColor(PlayerControl player)
        {
            ModdedPlayerClass moddedPlayer = Main.Instance.ModdedPlayerById(player.PlayerId);

            if (moddedPlayer.Role == null)
            {
                return("<#FFFFFF>");
            }

            return(Extensions.ToTextColor(moddedPlayer.Role.RoleColor));
        }
Esempio n. 5
0
        public void Handle(byte packetId, MessageReader reader)
        {
            switch (packetId)
            {
            case (byte)Packets.AssignRole:
                byte              playerId   = reader.ReadByte();
                string            roleName   = reader.ReadString();
                ModdedPlayerClass rolePlayer = Main.Instance.ModdedPlayerById(playerId);
                switch (roleName)
                {
                case "Voldemort":
                    rolePlayer.Role = new Voldemort(rolePlayer);
                    break;

                case "Bellatrix":
                    rolePlayer.Role = new Bellatrix(rolePlayer);
                    break;

                case "Harry":
                    rolePlayer.Role = new Harry(rolePlayer);
                    break;

                case "Hermione":
                    rolePlayer.Role = new Hermione(rolePlayer);
                    break;

                case "Ron":
                    rolePlayer.Role = new Ron(rolePlayer);
                    break;
                }
                break;

            case (byte)Packets.FixLightsRpc:
                var switchSystem = ShipStatus.Instance.Systems[SystemTypes.Electrical].Cast <SwitchSystem>();
                switchSystem.ActualSwitches = switchSystem.ExpectedSwitches;
                break;

            case (byte)Packets.ForceAllVotes:
                byte forcePlayer = reader.ReadByte();
                Main.Instance.ForceAllVotes((sbyte)forcePlayer);
                break;

            case (byte)Packets.CreateCurse:
                byte    casterId  = reader.ReadByte();
                Vector2 direction = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                Main.Instance.CreateCurse(direction, Main.Instance.ModdedPlayerById(casterId));
                break;

            case (byte)Packets.CreateCrucio:
                byte    blinderId       = reader.ReadByte();
                Vector2 crucioDirection = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                Main.Instance.CreateCrucio(crucioDirection, Main.Instance.ModdedPlayerById(blinderId));
                break;

            case (byte)Packets.DestroyCurse:
                Main.Instance.DestroyCurse();
                break;

            case (byte)Packets.DestroyCrucio:
                System.Console.WriteLine("Received DestroyCrucio packet");
                Main.Instance.DestroyCrucio();
                break;

            case (byte)Packets.KillPlayerUnsafe:
                byte killerId            = reader.ReadByte();
                byte targetId            = reader.ReadByte();
                bool isCurseKill         = reader.ReadBoolean();
                ModdedPlayerClass target = Main.Instance.ModdedPlayerById(targetId);
                ModdedPlayerClass killer = Main.Instance.ModdedPlayerById(killerId);
                Main.Instance.KillPlayer(killer._Object, target._Object, isCurseKill);
                break;

            case (byte)Packets.DeactivatePlayer:
                byte blindId            = reader.ReadByte();
                ModdedPlayerClass blind = Main.Instance.ModdedPlayerById(blindId);
                Main.Instance.CrucioBlind(blind._Object);
                break;

            case (byte)Packets.StartControlling:
                byte controllerId            = reader.ReadByte();
                byte controlledId            = reader.ReadByte();
                ModdedPlayerClass controller = Main.Instance.ModdedPlayerById(controllerId);
                ModdedPlayerClass controlled = Main.Instance.ModdedPlayerById(controlledId);
                Main.Instance.ControlPlayer(controller._Object, controlled._Object);
                break;

            case (byte)Packets.MoveControlledPlayer:
                byte          moveId     = reader.ReadByte();
                Vector3       newVel     = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                PlayerControl movePlayer = Main.Instance.ModdedPlayerById(moveId)._Object;
                if (movePlayer.AmOwner)
                {
                    movePlayer.MyPhysics.body.velocity = newVel;
                }
                break;

            case (byte)Packets.InvisPlayer:
                byte          invisId     = reader.ReadByte();
                PlayerControl invisPlayer = Main.Instance.ModdedPlayerById(invisId)._Object;
                Main.Instance.InvisPlayer(invisPlayer);
                break;

            case (byte)Packets.DefensiveDuelist:
                byte          ddId     = reader.ReadByte();
                PlayerControl ddPlayer = Main.Instance.ModdedPlayerById(ddId)._Object;
                Main.Instance.DefensiveDuelist(ddPlayer);
                break;

            case (byte)Packets.RevivePlayer:
                byte reviveId = reader.ReadByte();
                foreach (PlayerControl player in PlayerControl.AllPlayerControls)
                {
                    if (player.PlayerId != reviveId)
                    {
                        continue;
                    }
                    if (!player.Data.IsDead)
                    {
                        continue;
                    }

                    player.Revive();
                    foreach (DeadBody body in UnityEngine.Object.FindObjectsOfType <DeadBody>())
                    {
                        if (body.ParentId == reviveId)
                        {
                            UnityEngine.Object.Destroy(body.gameObject);
                        }
                    }
                }
                break;

            case (byte)Packets.TeleportPlayer:
                var teleportId  = reader.ReadByte();
                var teleportPos = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                foreach (PlayerControl player in PlayerControl.AllPlayerControls)
                {
                    if (teleportId == player.PlayerId)
                    {
                        player.NetTransform.SnapTo(teleportPos);
                    }
                }
                break;

            case (byte)Packets.SpawnItem:
                var itemId       = reader.ReadInt32();
                var itemPosition = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                var velocity     = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                if (itemId == 3)
                {
                    Main.Instance.SpawnItem(itemId, itemPosition, velocity);
                }
                else
                {
                    Main.Instance.SpawnItem(itemId, itemPosition);
                }
                break;

            case (byte)Packets.TryPickupItem:
                if (!AmongUsClient.Instance.AmHost)
                {
                    return;
                }

                var targetPlayer = reader.ReadByte();
                var pickupId     = reader.ReadInt32();
                if (Main.Instance.AllItems.Any(x => x.Id == pickupId))
                {
                    List <WorldItem> allMatches = Main.Instance.AllItems.FindAll(x => x.Id == pickupId);
                    foreach (WorldItem item in allMatches)
                    {
                        item.Delete();
                    }
                    Main.Instance.AllItems.RemoveAll(x => x.IsPickedUp);

                    MessageWriter writer = AmongUsClient.Instance.StartRpc(PlayerControl.LocalPlayer.NetId, (byte)Packets.GiveItem, SendOption.Reliable);
                    writer.Write(targetPlayer);
                    writer.Write(pickupId);
                    writer.EndMessage();
                }
                break;

            case (byte)Packets.GiveItem:
                var targetPlayer2 = reader.ReadByte();
                var pickupId2     = reader.ReadInt32();

                if (targetPlayer2 != PlayerControl.LocalPlayer.PlayerId)
                {
                    return;
                }

                if (Main.Instance.GetLocalModdedPlayer().HasItem(pickupId2))
                {
                    return;
                }

                Main.Instance.GiveGrabbedItem(pickupId2);
                Main.Instance.AllItems.RemoveAll(x => x.IsPickedUp);
                break;

            case (byte)Packets.DestroyItem:
                if (!AmongUsClient.Instance.AmHost)
                {
                    var targetItemId            = reader.ReadInt32();
                    List <WorldItem> allMatches = Main.Instance.AllItems.FindAll(x => x.Id == targetItemId);
                    foreach (WorldItem item in allMatches)
                    {
                        item.Delete();
                    }
                    Main.Instance.AllItems.RemoveAll(x => x.IsPickedUp);
                }
                break;
            }
        }
Esempio n. 6
0
        public System.Collections.IEnumerator CoCastCurse(Vector3 mousePosition, ModdedPlayerClass Owner)
        {
            DateTime now        = DateTime.UtcNow;
            int      curseindex = 0;

            CurseObject?.Destroy();
            CurseObject = new GameObject();
            SpriteRenderer curseRender = CurseObject.AddComponent <SpriteRenderer>();
            Rigidbody2D    curseRigid  = CurseObject.AddComponent <Rigidbody2D>();

            CurseObject.SetActive(true);
            BoxCollider2D curseCollider = CurseObject.AddComponent <BoxCollider2D>();

            curseRender.enabled              = true;
            curseRigid.transform.position    = Owner._Object.myRend.bounds.center;
            curseRender.transform.localScale = new Vector2(1f, 1f);

            Vector3 v        = mousePosition - Owner._Object.myRend.bounds.center;
            float   dist     = Vector2.Distance(mousePosition, Owner._Object.myRend.bounds.center);
            Vector3 d        = v * 3f * (2f / dist);
            float   AngleRad = Mathf.Atan2(mousePosition.y - Owner._Object.myRend.bounds.center.y, mousePosition.x - Owner._Object.myRend.bounds.center.x);
            float   AngleDeg = (180 / (float)Math.PI) * AngleRad;

            curseCollider.autoTiling = false;
            curseCollider.edgeRadius = 0;
            curseCollider.size       = Owner._Object.Collider.bounds.size * 2;
            curseRigid.velocity      = new Vector2(d.x, d.y);
            CurseObject.layer        = 8;

            while (true)
            {
                if (CurseObject == null)
                {
                    yield break;
                }

                if (curseindex <= 5)
                {
                    curseRender.sprite = Assets.CurseSprite[0];
                }
                else
                {
                    curseRender.sprite = Assets.CurseSprite[1];
                }

                if (curseindex >= 10)
                {
                    curseindex = 0;
                }

                curseindex++;

                curseRigid.rotation     = AngleDeg;
                curseRigid.drag         = 0;
                curseRigid.angularDrag  = 0;
                curseRigid.inertia      = 0;
                curseRigid.gravityScale = 0;

                Vector2 oldVelocity = curseRigid.velocity;

                yield return(null);

                if (CurseObject == null)
                {
                    yield break;
                }

                if (curseRigid.velocity != oldVelocity && Owner._Object.AmOwner)
                {
                    RpcDestroyCurse();
                    yield break;
                }

                foreach (PlayerControl player in PlayerControl.AllPlayerControls)
                {
                    if (player.Data.IsDead || player.Data.Disconnected || Owner._Object == player || player.Data.IsImpostor)
                    {
                        continue;
                    }

                    if (!player.myRend.bounds.Intersects(curseRender.bounds))
                    {
                        continue;
                    }

                    if (!Owner._Object.AmOwner)
                    {
                        yield break;
                    }

                    RpcDestroyCurse();

                    if (ModdedPlayerById(player.PlayerId).Immortal)
                    {
                        yield break;
                    }

                    if (GetPlayerRoleName(ModdedPlayerById(player.PlayerId)) == "Harry")
                    {
                        RpcKillPlayer(Owner._Object, Owner._Object);
                    }
                    else
                    {
                        RpcKillPlayer(Owner._Object, player);
                    }

                    yield break;
                }

                if (now.AddSeconds(5) >= DateTime.UtcNow && !MeetingHud.Instance && AmongUsClient.Instance.GameState == InnerNetClient.GameStates.Started)
                {
                    continue;
                }

                RpcDestroyCurse();
                yield break;
            }
        }
Esempio n. 7
0
 public void CreateCrucio(Vector2 pos, ModdedPlayerClass Owner)
 {
     Reactor.Coroutines.Start(CoCastCrucio(pos, Owner));
 }
Esempio n. 8
0
 public string GetPlayerRoleName(ModdedPlayerClass player)
 {
     return(player?.Role?.RoleName);
 }
Esempio n. 9
0
 public void AssignRole(ModdedPlayerClass player, Role role)
 {
     player.Role = role;
 }
Esempio n. 10
0
 public void CreateCurse(Vector2 pos, ModdedPlayerClass Owner)
 {
     Reactor.Coroutines.Start(CoCastCurse(pos, Owner));
     Owner._Object.SetKillTimer(PlayerControl.GameOptions.KillCooldown);
 }