Ejemplo n.º 1
0
        public static void Postfix(PlayerControl __instance, bool __state, [HarmonyArgument(0)] PlayerControl target)
        {
            __instance.Data.IsImpostor = __state;

            if (!AmongUsClient.Instance.AmHost)
            {
                return;
            }
            if (target.GetRole().Faction != Faction.Mafia)
            {
                return;
            }

            if (AssignedRoles.Values.Count(role =>
                                           role.Faction == Faction.Mafia && !role.Owner.Data.IsDead &&
                                           role.GetAbility <AbilityKill>() != null) >=
                Main.OptionMafiaKillAlways)
            {
                return;
            }

            Role[] mafiaWithoutKill = AssignedRoles.Values.Where(role =>
                                                                 role.Faction == Faction.Mafia && !role.Owner.Data.IsDead && role.GetAbility <AbilityKill>() == null)
                                      .ToArray();
            if (mafiaWithoutKill.Length == 0)
            {
                return;
            }

            Role newKiller = mafiaWithoutKill[Rng.Next(mafiaWithoutKill.Length)];

            newKiller.AddAbility <Mafioso, AbilityKill>(true);
            WriteRPC(RPC.AddKillAbility, newKiller.Owner.PlayerId);
        }
Ejemplo n.º 2
0
        public static void ConvertVampire(PlayerControl target)
        {
            Vampires.Insert(0, target);
            Role targetRole = target.GetRole();

            targetRole.ClearAbilities();
            targetRole.AddAbility <Vampire, AbilityBite>();
            // TODO: Vielleicht "this" anstatt new AbilityBite übergeben? Andere Vampire sehen dann auch den Cooldown
        }
Ejemplo n.º 3
0
        public static void Prefix([HarmonyArgument(0)] out Il2CppReferenceArray <GameData.PlayerInfo> playerInfos)
        {
            List <Role> assignedRoles = AssignedRoles.Values.ToList();

            foreach (Role r in assignedRoles)
            {
                r.ClearSettings();
            }

            var infected = new List <GameData.PlayerInfo>();
            var roles    = new List <Role>();

            List <Role> availableRoles = Main.Roles.ToList();

            List <RoleSlot>      roleSlots        = Main.GetRoleSlots().ToList();
            List <PlayerControl> availablePlayers = AllPlayers.ToList();

            for (var i = 0; i < roleSlots.Count && availablePlayers.Count > 0; i++)
            {
                RoleSlot           roleSlot         = roleSlots[i];
                var                spawnChance      = 0;
                IEnumerable <Role> possibleRoles    = roleSlot.GetFittingRoles(availableRoles);
                var                roleSpawnChances = new List <RoleSpawnChancePair>();
                foreach (Role possibleRole in possibleRoles)
                {
                    roleSpawnChances.Add(new RoleSpawnChancePair(possibleRole,
                                                                 spawnChance += (int)Main.GetRoleSpawnChance(possibleRole.GetType())));
                }

                // IEnumerable<RoleSpawnChancePair> roleSpawnChances = roleSlot.GetFittingRoles(availableRoles).Select(role => new RoleSpawnChancePair(role, spawnChance += (int) Main.GetRoleSpawnChance(role.GetType())));
                int spawnValue = Rng.Next(spawnChance);
                foreach (RoleSpawnChancePair roleSpawnChance in roleSpawnChances)
                {
                    if (roleSpawnChance.spawnChance > spawnValue)
                    {
                        roles.Add(roleSpawnChance.role);
                        PlayerControl player = availablePlayers[Rng.Next(availablePlayers.Count)];
                        Role.RpcSetRole(roleSpawnChance.role, player);

                        availableRoles.Remove(roleSpawnChance.role);
                        availablePlayers.Remove(player);
                        if (roleSlots[i].IsInfected)
                        {
                            infected.Add(player.Data);
                        }

                        break;
                    }
                }

                /*
                 * Role role = roleSlots[i].GetRole(ref availableRoles);
                 * PlayerControl player = availablePlayers[Rng.Next(availablePlayers.Count)];
                 * Role.SetRole(role, player);
                 *
                 * availableRoles.Remove(role);
                 * availablePlayers.Remove(player);
                 * if (roleSlots[i].IsInfected)
                 * {
                 *  infected.Add(player.Data);
                 * }
                 */
            }

            foreach (Role role in roles)
            {
                role.InitializeRole();
            }

            int killAbilitiesToAdd = (int)Main.OptionMafiaKillStart - roles.Count(role =>
                                                                                  role.Faction == Faction.Mafia && role.GetAbility <AbilityKill>() != null);

            // TODO: Randomize order of adding killAbilities, so you don't have an advantage if you log into lobby earlier than another one
            for (var i = 0; i < roles.Count && killAbilitiesToAdd > 0; i++)
            {
                Role role = roles[i];
                if (role.Faction != Faction.Mafia || role.GetAbility <AbilityKill>() != null)
                {
                    continue;
                }

                role.AddAbility <Mafioso, AbilityKill>(true);
                WriteRPC(RPC.AddKillAbility, role.Owner.PlayerId);
                killAbilitiesToAdd--;
            }

            playerInfos = new Il2CppReferenceArray <GameData.PlayerInfo>(infected.ToArray());
        }