static void Postfix(ChangeUnitSize __instance, ref Size __result) { var change_type = Helpers.GetField <int>(__instance, "m_Type"); if (change_type == 0) { __result = __instance.Owner.Ensure <UnitPartSizeOverride>().getSize().Shift(__instance.SizeDelta); } }
private static BlueprintFeature AddSpiderCompanion() { PortraitData portraitData = new PortraitData("AdvancedMartialArtsSpider"); BlueprintPortrait portrait = Helpers.Create <BlueprintPortrait>(); portrait.Data = portraitData; Main.library.AddAsset(portrait, Helpers.getGuid("GiantSpiderPortrait")); BlueprintUnitFact reducedReachFact = Main.library.Get <BlueprintUnitFact>("c33f2d68d93ceee488aa4004347dffca"); BlueprintFeature weaponFinesse = Main.library.Get <BlueprintFeature>("90e54424d682d104ab36436bd527af09"); BlueprintFeature animalCompanionUpgradeCentipede = Main.library.Get <BlueprintFeature>("c938099ca0438b242b3edecfa9083e9f"); BlueprintUnit animalCompanionUnitCentipede = Main.library.Get <BlueprintUnit>("f9df16ffd0c8cec4d99a0ae6f025a3f8"); BlueprintUnit giantSpider = Main.library.CopyAndAdd <BlueprintUnit>("c4b33e5fd3d3a6f46b2aade647b0bf25", "GiantSpiderCompanion", Helpers.getGuid("GiantSpiderCompanion")); BlueprintItemWeapon Bite1d6 = Main.library.Get <BlueprintItemWeapon>("a000716f88c969c499a535dadcf09286"); BlueprintItemWeapon EmptyHandWeapon = Main.library.Get <BlueprintItemWeapon>("20375b5a0c9243d45966bd72c690ab74"); giantSpider.Brain = animalCompanionUnitCentipede.Brain; giantSpider.ComponentsArray = animalCompanionUnitCentipede.ComponentsArray; giantSpider.Body = animalCompanionUnitCentipede.Body; giantSpider.AddFacts = giantSpider.AddFacts.AddToArray(weaponFinesse); giantSpider.Faction = Main.library.Get <BlueprintFaction>("d8de50cc80eb4dc409a983991e0b77ad"); // Neutral faction Helpers.SetField(giantSpider, "m_Portrait", portrait); BlueprintUnitAsksList giantSpiderBarks = Main.library.CopyAndAdd <BlueprintUnitAsksList>("7d340f75a57c47d45b0e79200a6b5eac", "SpiderAnimalCompanionBarks", Helpers.getGuid("SpiderAnimalCompanionBarks")); UnitAsksComponent component = giantSpiderBarks.GetComponent <UnitAsksComponent>(); foreach (var componentAnimationBark in component.AnimationBarks) { if (componentAnimationBark.AnimationEvent == MappedAnimationEventType.AlertSound1 || componentAnimationBark.AnimationEvent == MappedAnimationEventType.AlertSound2) { componentAnimationBark.Cooldown = 10f; componentAnimationBark.DelayMin = 5f; } } ChangeUnitSize unitSize = Helpers.Create <ChangeUnitSize>(x => x.SizeDelta = 1); FieldInfo typeField = unitSize.GetType().GetField("m_Type", BindingFlags.NonPublic | BindingFlags.Instance); object delta = unitSize.GetType().GetNestedType("ChangeType", BindingFlags.NonPublic).GetField("Delta").GetValue(unitSize); typeField.SetValue(unitSize, delta); AddMechanicsFeature addMechanicsFeature = Helpers.Create <AddMechanicsFeature>(); Traverse traverse = Traverse.Create(addMechanicsFeature); traverse.Field("m_Feature").SetValue(AddMechanicsFeature.MechanicsFeatureType.IterativeNaturalAttacks); typeField.SetValue(unitSize, delta); BlueprintFeature animalCompanionFeatureSpider = Main.library.CopyAndAdd <BlueprintFeature>("f9ef7717531f5914a9b6ecacfad63f46", "AnimalCompanionFeatureGiantSpider", Helpers.getGuid("AnimalCompanionFeatureGiantSpider")); animalCompanionFeatureSpider.SetNameDescription("Animal Companion — Giant Spider", "Size Medium\nSpeed 30 ft.\nAC +1 natural armor\nAttack bite (1d6 plus poison)\nAbility Scores Str 11, Dex 17, Con 12, Int 1, Wis 10, Cha 2\nSpecial Attacks poison (frequency 1 round (4); effect 1d2 Str damage; cure 1 save; Con-based DC)\nCMD +8 vs. trip.\nAt 7th level size becomes Large, Str +2, Dex +8, Con +4, +2 natural armor."); AddPet addPetFact = animalCompanionFeatureSpider.ComponentsArray.OfType <AddPet>().First(); animalCompanionFeatureSpider.RemoveComponent(addPetFact); addPetFact = UnityEngine.Object.Instantiate(addPetFact); animalCompanionFeatureSpider.AddComponent(addPetFact); addPetFact.Pet = giantSpider; addPetFact.UpgradeFeature = Helpers.CreateFeature( "AnimalCompanionUpgradeGiantSpider", "", "", Helpers.getGuid("AnimalCompanionUpgradeGiantSpider"), animalCompanionUpgradeCentipede.Icon, FeatureGroup.None, unitSize, Helpers.Create <AddStatBonus>(x => { x.Stat = StatType.AC; x.Value = 2; x.Descriptor = ModifierDescriptor.NaturalArmor; }), Helpers.Create <AddStatBonus>(x => { x.Stat = StatType.Strength; x.Value = 2; }), Helpers.Create <AddStatBonus>(x => { x.Stat = StatType.Dexterity; x.Value = 8; }), Helpers.Create <AddStatBonus>(x => { x.Stat = StatType.Constitution; x.Value = 4; }), addMechanicsFeature, Helpers.CreateAddFacts(reducedReachFact) ); addPetFact.UpgradeLevel = 7; return(animalCompanionFeatureSpider); }