Beispiel #1
0
        internal static bool Prefix(AddPet __instance)
        {
            if (!__instance.Owner.IsPlayerFaction)
            {
                return(true);
            }
            if (__instance.SpawnedPet == null)
            {
                return(false);
            }
            AddClassLevels component = __instance.SpawnedPet.Blueprint.GetComponent <AddClassLevels>();

            if (component == null)
            {
                return(false);
            }

            int pet_level = 0;
            var eidolon   = __instance.SpawnedPet.Blueprint.GetComponent <Eidolon.EidolonComponent>();

            if (eidolon == null)
            {
                var tr = Harmony12.Traverse.Create(__instance);
                pet_level = tr.Method("GetPetLevel").GetValue <int>();
            }
            else
            {
                pet_level = eidolon.getEidolonLevel(__instance);
            }
            //Main.logger.Log("Pet level: " + __instance.SpawnedPet.Descriptor.Progression.CharacterLevel.ToString());
            //Main.logger.Log("Should be: " + pet_level.ToString());

            if (pet_level > __instance.SpawnedPet.Descriptor.Progression.CharacterLevel)
            {
                if (__instance.SpawnedPet.Descriptor.Progression.CharacterLevel == 0)
                {
                    component.LevelUp(__instance.SpawnedPet.Descriptor, 1);
                }
                var exp = Game.Instance.BlueprintRoot.Progression.XPTable.GetBonus(pet_level);
                Harmony12.Traverse.Create(__instance.SpawnedPet.Descriptor.Progression).Property("Experience").SetValue(exp);
                EventBus.RaiseEvent <IUnitGainExperienceHandler>((Action <IUnitGainExperienceHandler>)(h => h.HandleUnitGainExperience(__instance.SpawnedPet.Descriptor, exp)));
                //Main.logger.Log("Pet level now: " + __instance.SpawnedPet.Descriptor.Progression.CharacterLevel.ToString());
            }

            if (eidolon != null)
            {//no upgrade for eidolon, since they are performed through summoner
                return(false);
            }
            int?rank = __instance.Owner.GetFact((BlueprintUnitFact)__instance.LevelRank)?.GetRank();

            if (Mathf.Min(20, !rank.HasValue ? 0 : rank.Value) < __instance.UpgradeLevel)
            {
                return(false);
            }
            __instance.SpawnedPet.Descriptor.Progression.Features.AddFeature(__instance.UpgradeFeature, (MechanicsContext)null);
            return(false);
        }
Beispiel #2
0
            private static bool Prefix(ref Kingmaker.UnitLogic.FactLogic.AddPet __instance)
            {
                if (!ModSettings.enableSuperPet)
                {
                    return(true);
                }
                if (__instance.SpawnedPet == null)
                {
                    return(false);
                }
                AddClassLevels component = __instance.SpawnedPet.Blueprint.GetComponent <AddClassLevels>();

                if (!component)
                {
                    return(false);
                }
                int characterLevel = __instance.SpawnedPet.Descriptor.Progression.CharacterLevel;
                //int petLevel = __instance.GetPetLevel(); // function is private, and we have duplicated it ...
                int petLevel = 0;

                AnimalCompanionPatch2.Prefix(ref __instance, ref petLevel);
                int num = petLevel - characterLevel;

                if (num > 0)
                {
                    component.LevelUp(__instance.SpawnedPet.Descriptor, num);
                }
                int  a    = RankToLevel.Length;
                Fact fact = __instance.Owner.GetFact(__instance.LevelRank);
                int? num2 = (fact != null) ? new int?(fact.GetRank()) : null;
                int  num3 = UnityEngine.Mathf.Min(a, (num2 == null) ? 0 : num2.Value);

                if (num3 >= __instance.UpgradeLevel)
                {
                    __instance.SpawnedPet.Descriptor.Progression.Features.AddFeature(__instance.UpgradeFeature, null);
                }
                return(false);
            }