public static void CheckComponent(BlueprintScriptableObject obj, BlueprintComponent c) { #if DEBUG var type = c.GetType(); if (IsStatefulComponent(type)) { statefulComponentMessage.AppendLine($"Warning: in object {obj.name}, stateful {type.Name} should be named."); } #endif }
/// <summary>Looks for the first component of the replacement type and overrides the reference. /// Note that you need to detach the component first, otherwise the original gets mutated.</summary> /// <param name="replacement">The new component that should take it's place.</param> /// <returns>Itself for chaining.</returns> public static BlueprintScriptableObject ReplaceDirty(this BlueprintScriptableObject obj, BlueprintComponent replacement) { Type replacementType = replacement.GetType(); for (int i = 0; i < obj.ComponentsArray.Length; i++) { if (obj.ComponentsArray[i].GetType() == replacementType) { obj.ComponentsArray[i] = replacement; return(obj); } } return(null); }
internal static void Append(BlueprintComponent c, String indent = "") { var spellComp = c as SpellComponent; if (spellComp != null) { Append($"{indent}SpellComponent school {spellComp.School.ToString()}"); return; } var spellList = c as SpellListComponent; if (spellList != null) { Append($"{indent}SpellListComponent {spellList.SpellList.name} level {spellList.SpellLevel}"); return; } var spellDesc = c as SpellDescriptorComponent; if (spellDesc != null) { Append($"{indent}SpellDescriptorComponent " + spellDesc.Descriptor.Value.ToString("x")); return; } var execOnCast = c as AbilityExecuteActionOnCast; if (execOnCast != null) { Append($"{indent}AbilityExecuteActionOnCast:"); var conditions = execOnCast.Conditions; if (conditions != null) { Append($"{indent} conditions op {conditions.Operation}:"); foreach (var cond in conditions.Conditions) { Append($"{indent} " + (cond.Not ? "not " : " ") + c.GetType().Name + $" {cond.GetCaption()}"); } } Append($"{indent} actions:"); foreach (var action in execOnCast.Actions.Actions) { Append(action, $"{indent} "); } } var runActions = c as AbilityEffectRunAction; if (runActions != null) { Append($"{indent}AbilityEffectRunAction saving throw {runActions.SavingThrowType}"); foreach (var action in runActions.Actions.Actions) { Append(action, $"{indent} "); } return; } var config = c as ContextRankConfig; if (config != null) { Func <String, object> field = (name) => Helpers.GetField(config, name); var progression = (ContextRankProgression)field("m_Progression"); Append($"{indent}ContextRankConfig type {config.Type} value type " + ((ContextRankBaseValueType)field("m_BaseValueType")) + $" progression {progression}"); if (config.IsBasedOnClassLevel) { Append($"{indent} class level " + ((BlueprintCharacterClass[])field("m_Class"))?.StringJoin(b => b.name)); Append($"{indent} except classes? " + (bool)field("m_ExceptClasses")); } if (config.RequiresArchetype) { Append($"{indent} archetype " + ((BlueprintArchetype)field("Archetype")).name); } if (config.IsBasedOnFeatureRank) { Append($"{indent} feature rank " + ((BlueprintFeature)field("m_Feature")).name); } if (config.IsFeatureList) { Append($"{indent} feature list " + ((BlueprintFeature[])field("m_FeatureList"))?.StringJoin(f => f.name)); } if (config.IsBasedOnStatBonus) { Append($"{indent} stat bonus " + ((StatType)field("m_Stat"))); } if ((bool)field("m_UseMax")) { Append($"{indent} max " + ((int)field("m_Max"))); } if ((bool)field("m_UseMin")) { Append($"{indent} min " + ((int)field("m_Min"))); } if (config.IsDivisionProgression) { Append($"{indent} start level " + ((int)field("m_StartLevel"))); } if (config.IsDivisionProgressionStart) { Append($"{indent} step level " + ((int)field("m_StepLevel"))); } if (progression == ContextRankProgression.Custom) { Append($"{indent} custom progression:"); foreach (var p in (IEnumerable <object>)field("m_CustomProgression")) { Func <String, int> field2 = (name) => (int)Helpers.GetField(p, name); Append($"{indent} base value {field2("BaseValue")} progression {field2("ProgressionValue")}"); } } return; } Append($"{indent}component {c.name}, type {c.GetType().Name}"); var abilityVariants = c as AbilityVariants; if (abilityVariants != null) { foreach (var v in abilityVariants.Variants) { Append(v, $"{indent} "); } } var polymorph = c as Polymorph; if (polymorph != null) { foreach (var f in polymorph.Facts) { Append(f, $"{indent} "); } } var stickyTouch = c as AbilityEffectStickyTouch; if (stickyTouch != null) { Append(stickyTouch.TouchDeliveryAbility, $"{indent} "); } var addIf = c as AddFeatureIfHasFact; if (addIf != null) { Append($"{indent} if {(addIf.Not ? "!" : "")}{addIf.CheckedFact.name} then add {addIf.Feature.name}"); Append(addIf.Feature, $"{indent} "); } var addOnLevel = c as AddFeatureOnClassLevel; if (addOnLevel != null) { Append($"{indent} if level {(addOnLevel.BeforeThisLevel ? "before " : "")}{addOnLevel.Level} then add {addOnLevel.Feature.name}"); Append(addOnLevel.Feature, $"{indent} "); } var addFacts = c as AddFacts; if (addFacts != null) { Append($"{indent} add facts"); foreach (var f in addFacts.Facts) { Append(f, $"{indent} "); } } var prereq = c as Prerequisite; if (prereq != null) { Append($"{indent} prerequisite group {prereq.Group}"); var log = new StringBuilder(); Action <String, object> logIf = (desc, name) => { if (name != null) { log.Append(desc + name); } }; logIf(" class ", (prereq as PrerequisiteClassLevel)?.CharacterClass.name); logIf(" level ", (prereq as PrerequisiteClassLevel)?.Level); logIf(" feature ", (prereq as PrerequisiteFeature)?.Feature.name); logIf(" no feature ", (prereq as PrerequisiteNoFeature)?.Feature.name); logIf(" stat ", (prereq as PrerequisiteStatValue)?.Stat.ToString()); logIf(" value ", (prereq as PrerequisiteStatValue)?.Value); Append($"{indent} {log.ToString()}"); } }