Beispiel #1
0
 public static void RegisterTrait <TraitType>(BMTraitInfo info)
 {
     info.FinalizeInfo();
     registeredTraits.Add(typeof(TraitType), info);
     RegisterTraitUpgrades <TraitType>(info);
     RegisterTraitConflictGroup <TraitType>(info);
 }
Beispiel #2
0
        /// <summary>
        /// Sets the `isUpgrade` and `upgrade` fields for the given trait.
        /// </summary>
        private static void RegisterUpgrades(Type traitType, BMTraitInfo traitInfo)
        {
            TraitUnlock unlock           = traitInfo.TraitBuilder.Unlock;
            BMTraitInfo upgradeTraitInfo = GetTraitInfo(traitInfo.Upgrade);

            unlock.SetUpgrade(
                upgradeDowngradeDict.ContainsKey(traitType),
                upgradeTraitInfo?.Name
                );
        }
Beispiel #3
0
        private static void RegisterTraitConflictGroup <TraitType>(BMTraitInfo info)
        {
            foreach (ETraitConflictGroup conflictGroup in info.ConflictGroups)
            {
                if (!conflictGroupDict.ContainsKey(conflictGroup))
                {
                    conflictGroupDict[conflictGroup] = new List <Type>();
                }

                conflictGroupDict[conflictGroup].Add(typeof(TraitType));
            }
        }
Beispiel #4
0
        private static void RegisterTraitUpgrades <TraitType>(BMTraitInfo info)
        {
            if (info.Upgrade != null)
            {
                if (!upgradeDowngradeDict.ContainsKey(info.Upgrade))
                {
                    upgradeDowngradeDict[info.Upgrade] = new List <Type>();
                }

                upgradeDowngradeDict[info.Upgrade].Add(typeof(TraitType));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Sets the recommendations for the given trait
        /// </summary>
        private static void RegisterRecommendations(Type traitType, BMTraitInfo traitInfo)
        {
            TraitUnlock      unlock          = traitInfo.TraitBuilder.Unlock;
            HashSet <string> recommendations = new HashSet <string>();

            if (traitInfo.Recommendations.Count > 0)
            {
                foreach (string recommendTrait in traitInfo.Recommendations
                         .Select(type => GetTraitInfo(type)?.Name)
                         .Where(name => name != null))
                {
                    recommendations.Add(recommendTrait);
                }
            }

            // TODO recommend vanilla traits

            unlock.SetRecommendations(recommendations);
        }
Beispiel #6
0
        /// <summary>
        /// Sets the cancellations for the given trait.
        /// </summary>
        private static void RegisterCancellations(Type traitType, BMTraitInfo traitInfo)
        {
            TraitUnlock      unlock        = traitInfo.TraitBuilder.Unlock;
            HashSet <string> cancellations = new HashSet <string>();

            // cancel all traits in this conflictGroup
            if (traitInfo.ConflictGroups.Count > 0)
            {
                foreach (string cancelTrait in traitInfo.ConflictGroups
                         .SelectMany(group => conflictGroupDict[group])
                         .Where(type => type != traitType)                        // prevent trait from cancelling itself
                         .Select(GetTraitInfo)
                         .Where(info => info != null)
                         .Select(info => info.Name))
                {
                    cancellations.Add(cancelTrait);
                }
            }

            // make sure this trait cancels any downgrade-traits
            if (upgradeDowngradeDict.ContainsKey(traitType))
            {
                foreach (string cancelTrait in upgradeDowngradeDict[traitType]
                         .Select(type => GetTraitInfo(type)?.Name)
                         .Where(name => name != null))
                {
                    cancellations.Add(cancelTrait);
                }
            }

            // make sure this trait cancels the upgrade trait
            if (traitInfo.Upgrade != null && registeredTraits.ContainsKey(traitInfo.Upgrade))
            {
                cancellations.Add(registeredTraits[traitInfo.Upgrade].Name);
            }

            // TODO conflicts with vanilla traits

            unlock.SetCancellations(cancellations);
        }