Example #1
0
        private bool ValidateRoleList(RoleCollection availableRoles, out ValueCounterDictionary <Type> remainingSlots)
        {
            remainingSlots = new();
            // This exists to prevent impossible role lists like more than 6 Coven roles in a game (since all the Coven roles are unique)
            var remainingAlignmentSlots = new ValueCounterDictionary <Faction>();

            foreach (var t in availableRoles)
            {
                var instance = RoleInstancePool.Instance[t];
                remainingSlots.Add(t, instance.MaximumOccurrences);
                remainingAlignmentSlots.Add(instance.Faction, instance.MaximumOccurrences);
            }

            foreach (var slot in roleSlots)
            {
                if (slot is RoleAlignment alignment)
                {
                }
                else
                {
                    var role = slot as Role;

                    // This is probably the greatest usage of inline variable declarations via is
                    alignment = role.FullAlignment;
                    var type = role.GetType();
                    remainingSlots.Subtract(type);
                    if (remainingSlots[type] < 0)
                    {
                        return(false);
                    }
                }

                var faction = alignment.Faction;

                if (faction == Faction.Any)
                {
                    continue;
                }

                remainingAlignmentSlots.Subtract(faction);
                if (remainingAlignmentSlots[faction] < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
 /// <summary>Returns this instance. This implementation does not perform any unnecessary computations.</summary>
 /// <param name="availableRoles">This argument is ignored in this implementation.</param>
 /// <param name="random">This argument is ignored in this implementation.</param>
 /// <returns>This <seealso cref="Role"/> instance.</returns>
 public Role GenerateRandomRole(RoleCollection availableRoles, Random random) => this;