Exemplo n.º 1
0
        public static UnitEntityData GetUnitUnderMouse()
        {
            UnitEntityView hoverUnit = Game.Instance?.UI?.SelectionManagerPC?.HoverUnit;

            if (hoverUnit != null)
            {
                return(hoverUnit.EntityData);
            }

            Camera camera = Game.GetCamera();

            if (camera == null)
            {
                return((UnitEntityData)null);
            }

            foreach (RaycastHit raycastHit in Physics.RaycastAll(camera.ScreenPointToRay(Input.mousePosition), camera.farClipPlane, 21761))
            {
                GameObject gameObject = raycastHit.collider.gameObject;
                if (gameObject.CompareTag("SecondarySelection"))
                {
                    while (!(bool)((UnityEngine.Object)gameObject.GetComponent <UnitEntityView>()) && (bool)((UnityEngine.Object)gameObject.transform.parent))
                    {
                        gameObject = gameObject.transform.parent.gameObject;
                    }
                }
                UnitEntityView component = gameObject.GetComponent <UnitEntityView>();
                if ((bool)((UnityEngine.Object)component))
                {
                    return(component.EntityData);
                }
            }
            return((UnitEntityData)null);
        }
Exemplo n.º 2
0
        public static UnitEntityData GetUnitUnderMouse()
        {
            if (Game.Instance.IsControllerMouse)
            {
                Game           instance       = Game.Instance;
                UnitEntityView unitEntityView = (instance != null) ? instance.UI.SelectionManagerPC.HoverUnit : null;
                if (unitEntityView != null)
                {
                    return(unitEntityView.EntityData);
                }
            }
            Vector2 v      = Game.Instance.IsControllerGamepad ? RewiredCursorController.CursorPos : new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            Camera  camera = Game.GetCamera();

            foreach (RaycastHit raycastHit in Physics.RaycastAll(camera.ScreenPointToRay(v), camera.farClipPlane, 2118913))
            {
                GameObject gameObject = raycastHit.collider.gameObject;
                if (gameObject.CompareTag("SecondarySelection"))
                {
                    while (!gameObject.GetComponent <UnitEntityView>() && gameObject.transform.parent)
                    {
                        gameObject = gameObject.transform.parent.gameObject;
                    }
                }
                UnitEntityView component = gameObject.GetComponent <UnitEntityView>();
                if (component)
                {
                    return(component.EntityData);
                }
            }
            return(null);
        }
Exemplo n.º 3
0
 public void HandleHoverChange([NotNull] UnitEntityView unitEntityView, bool isHover)
 {
     if (isHover)
     {
         _currentUnit = unitEntityView.Data;
     }
 }
Exemplo n.º 4
0
 static bool Prefix(UnitEntityView __instance, ref bool __result)
 {
     if (IsInCombat())
     {
         __result = __instance.AnimationManager?.IsStandUp ?? false;
         return(false);
     }
     return(true);
 }
        static void HideSlot(UnitEntityView __instance, ItemSlot slot, ref bool dirty)
        {
            var ee = __instance.ExtractEquipmentEntities(slot).ToList();

            if (ee.Count > 0)
            {
                __instance.CharacterAvatar.RemoveEquipmentEntities(ee);
                dirty = true;
            }
        }
 /*
  * Fix "bug" where Male Ranger Cape would hide hair and ears         *
  */
 static void FixRangerCloak(UnitEntityView view)
 {
     foreach (var ee in view.CharacterAvatar.EquipmentEntities)
     {
         if (ee.name == "EE_Ranger_M_Cape")
         {
             ee.HideBodyParts &= ~(BodyPartType.Hair | BodyPartType.Hair2 | BodyPartType.Ears);
         }
     }
 }
        /*
         * Fix "bug" where Male Ranger Cape would hide hair and ears         *
         */
        /*  static void FixRangerCloak(UnitEntityView view)
         * {
         *    foreach (var ee in view.CharacterAvatar.EquipmentEntities)
         *    {
         *        if (ee.name == "EE_Ranger_M_Cape")
         *        {
         *            ee.HideBodyParts &= ~(BodyPartType.Hair | BodyPartType.Ears);
         *        }
         *    }
         * }*/
        public static void NoClassOutfit(UnitEntityView view)
        {
            var classOutfit = view.EntityData.Descriptor.Progression.GetEquipmentClass();
            var oldClothes  = classOutfit.LoadClothes(view.EntityData.Descriptor.Gender, view.EntityData.Descriptor.Progression.Race);

            view.CharacterAvatar.RemoveEquipmentEntities(oldClothes);
            var newClothes = BlueprintRoot.Instance.CharGen.LoadClothes(view.EntityData.Descriptor.Gender);

            view.CharacterAvatar.AddEquipmentEntities(newClothes);
        }
Exemplo n.º 8
0
        static public void Postfix(UnitEntityView __instance)
        {
            var unit = __instance.EntityData;

            if (unit.Descriptor.HasFact(kip_up_buff) && unit.Descriptor.Resources.GetResourceAmount(resource) > 0 && unit.CombatState.Cooldown.SwiftAction == 0.0f)
            {
                unit.CombatState.Cooldown.SwiftAction = 6.0f;
                unit.Descriptor.Resources.Spend(resource, 1);
                unit.CombatState.Cooldown.MoveAction = 0.0f;
            }
        }
Exemplo n.º 9
0
            static bool Prefix(UnitMovementAgent __instance, ref float deltaTime, ref float?__state)
            {
                if (IsInCombat())
                {
                    //                          passing     acting      ending      delaying
                    // not in combat            o           x           x           x
                    // in combat - not current  x           x           x           x
                    // in combat - current      x           o           x           x

                    bool           canMove       = default;
                    bool           isInForceMode = __instance.GetIsInForceMode();
                    UnitEntityView view          = __instance.Unit;

                    if (IsPassing())
                    {
                        canMove = !(view?.EntityData?.IsInCombat ?? false);
                    }
                    else
                    {
                        canMove = (view?.EntityData).IsCurrentUnit() && IsActing() &&
                                  !(view.AnimationManager?.IsPreventingMovement ?? false) &&
                                  !view.IsCommandsPreventMovement && __instance.IsReallyMoving;

                        if (canMove)
                        {
                            CurrentTurn().TickMovement(ref deltaTime, isInForceMode);

                            if (deltaTime <= 0f)
                            {
                                canMove = false;
                            }
                            else if (!isInForceMode)
                            {
                                // disable acceleration effect
                                __state = __instance.GetMinSpeed();
                                __instance.SetMinSpeed(1f);
                                __instance.SetWarmupTime(0f);
                                __instance.SetSlowDownTime(0f);
                            }
                        }
                    }

                    if (!canMove)
                    {
                        if (!isInForceMode)
                        {
                            __instance.Stop();
                        }
                        return(false);
                    }
                }
                return(true);
            }
Exemplo n.º 10
0
        static public void maybeAddCharacter(UnitEntityView original)
        {
            var character = original.GetComponent <Character>();

            if (character == null)
            {
                character = original.gameObject.AddComponent <Character>();
                //BlueprintRoot.Instance.CharGen.FemaleDoll
                var drow = ResourcesLibrary.TryGetResource <UnitEntityView>("a65d9da806faa8f4ca078dfe942bf458", true);
                CloneMonobehaviour(drow.GetComponentInChildren <Character>(), character);
                character.BakedCharacter = CreateBakedCharacter(original.gameObject);
            }
        }
        public override void RunAction()
        {
            UnitEntityData caster = this.Context.MaybeCaster;

            if (caster == null)
            {
                UberDebug.LogError((UnityEngine.Object) this, (object)"Caster is missing", (object[])Array.Empty <object>());
            }
            var unit = this.Target.Unit;

            if (unit == null || !unit.Descriptor.State.IsDead || unit.Descriptor.State.HasCondition(UnitCondition.Petrified))
            {
                return;
            }

            var            blueprint       = unit.Blueprint;
            Rounds         duration        = this.DurationValue.Calculate(this.Context);
            Vector3        clampedPosition = ObstacleAnalyzer.GetNearestNode(this.Target.Point).clampedPosition;
            UnitEntityView unitEntityView  = blueprint.Prefab.Load(false);

            var target_size = unit.Descriptor.OriginalSize;

            float radius = !((UnityEngine.Object)unitEntityView != (UnityEngine.Object)null) ? 0.5f : unitEntityView.Corpulence;

            FreePlaceSelector.PlaceSpawnPlaces(1, radius, clampedPosition);

            Vector3        relaxedPosition = FreePlaceSelector.GetRelaxedPosition(0, true);
            UnitEntityData animated_unit   = this.Context.TriggerRule <RuleSummonUnit>(new RuleSummonUnit(caster, blueprint, relaxedPosition, duration, 0)
            {
                Context           = this.Context,
                DoNotLinkToCaster = this.do_not_link_to_caster
            }).SummonedUnit;

            if (this.SummonPool != null)
            {
                GameHelper.RegisterUnitInSummonPool(this.SummonPool, animated_unit);
            }

            var level_up_component = animated_unit.Blueprint.GetComponent <AddClassLevels>();

            int current_level = level_up_component.Levels;

            animated_unit.Descriptor.State.AddCondition(UnitCondition.Unlootable, (Kingmaker.UnitLogic.Buffs.Buff)null);

            using (this.Context.GetDataScope(animated_unit))
            {
                this.AfterSpawn.Run();
            }

            unit.Descriptor.AddFact(Common.no_animate_feature);
        }
Exemplo n.º 12
0
        static void ShowDollRoom(UnitEntityData unit, bool pregenMode = true)
        {
            if (unit == null)
            {
                throw new Exception("ShowDollRoom received null unit");
            }
            var dollRoom = Game.Instance.UI.Common.DollRoom;

            if (dollRoom != null)
            {
                CharGenDollRoom component = Game.Instance.UI.Common.DollRoom.GetComponent <CharGenDollRoom>();
                if (component)
                {
                    component.CreateDolls();
                }
                else
                {
                    Main.Error("CharGenDollRoom is null");
                }
                dollRoom.SetUnit(unit);
                if (pregenMode)
                {
                    BlueprintUnit  blueprint      = unit.Blueprint;
                    UnitEntityView unitEntityView = blueprint.Prefab.Load(false);
                    if (unitEntityView != null)
                    {
                        Character characterComponent = unitEntityView.GetComponent <Character>();
                        Character character          = dollRoom.CreateAvatar(characterComponent, blueprint.name);
                        character.AnimationManager.IsInCombat = false;
                        dollRoom.SetAvatar(character);
                    }
                    else
                    {
                        Main.Error("ShowDollRoom.unitEntityView is null");
                    }
                }
                //dollRoom.Show(true);
                if (dollRoom.Unit == null)
                {
                    Main.Error("Failed to set DollRoom.Unit");
                }
                if (dollRoom.GetAvatar() == null)
                {
                    Main.Error("Failed to set DollRoom.Avatar");
                }
            }
            else
            {
                Main.Error("Game.Instance.UI.Common.DollRoom is null");
            }
        }
            static bool Prefix(UnitEntityData __instance, ref UnitEntityView __result)
            {
                try
                {
                    if (!Main.enabled)
                    {
                        return(true);
                    }
                    if (!__instance.IsPlayerFaction)
                    {
                        return(true);
                    }
                    var characterSettings = Main.settings.GetCharacterSettings(__instance);
                    if (characterSettings == null)
                    {
                        return(true);
                    }
                    if (characterSettings.overrideView == null || characterSettings.overrideView == "")
                    {
                        return(true);
                    }
                    foreach (Kingmaker.UnitLogic.UnitFact fact in __instance.Buffs.RawFacts)
                    {
                        if (fact.Active && !fact.Deactivating)
                        {
                            Buff buff = (Buff)fact;
                            if (buff.GetComponent <Polymorph>() != null)
                            {
                                return(true);
                            }
                        }
                    }

                    UnitEntityView template = GetView(characterSettings.overrideView);
                    if (template == null)
                    {
                        Main.Log("Overriding invalid view " + characterSettings.overrideView);
                        return(true);
                    }
                    Quaternion rotation = (!template.ForbidRotation) ? Quaternion.Euler(0f, __instance.Orientation, 0f) : Quaternion.identity;
                    __result = UnityEngine.Object.Instantiate(template, __instance.Position, rotation);
                    //Prevent halflings from running too fast
                    Traverse.Create(__result).Field("m_IgnoreRaceAnimationSettings").SetValue(true);
                    return(false);
                } catch (Exception ex)
                {
                    Main.Error(ex);
                    return(true);
                }
            }
 static void Postfix(UnitEntityView __instance)
 {
     try
     {
         if (!Main.enabled)
         {
             return;
         }
         UpdateModel(__instance);
     }
     catch (Exception ex)
     {
         Main.Error(ex);
     }
 }
Exemplo n.º 15
0
        static public void TryReplaceView(UnitDescriptor Owner, UnitViewLink Prefab)
        {
            if (!Owner.Unit.View)
            {
                return;
            }
            UnitEntityView unitEntityView = Prefab.Load(true);

            if (unitEntityView == null)
            {
                return;
            }
            foreach (Buff buff in Owner.Buffs)
            {
                buff.ClearParticleEffect();
            }
            UnitEntityView oldView = Owner.Unit.View;
            UnitEntityView newView = UnityEngine.Object.Instantiate(unitEntityView).GetComponent <UnitEntityView>();

            newView.UniqueId = Owner.Unit.UniqueId;
            newView.transform.SetParent(oldView.transform.parent, false);
            newView.transform.position = oldView.transform.position;
            newView.transform.rotation = oldView.transform.rotation;
            newView.DisableSizeScaling = false;
            newView.Blueprint          = Owner.Blueprint;
            var character = newView.GetComponent <Character>();

            if (character == null)
            {
                character = newView.gameObject.AddComponent <Character>();
                character.AnimatorPrefab = BlueprintRoot.Instance.CharGen.FemaleDoll.AnimatorPrefab;
                character.BakedCharacter = CreateBakedCharacter(newView.gameObject);
                //BlueprintRoot.Instance.CharGen.FemaleDoll

                /*var drow = ResourcesLibrary.TryGetResource<UnitEntityView>("a65d9da806faa8f4ca078dfe942bf458", true);
                 * CloneMonobehaviour(drow.GetComponentInChildren<Character>(), character);
                 * character.BakedCharacter = CreateBakedCharacter(newView.gameObject);*/
            }
            Owner.Unit.AttachToViewOnLoad(newView);
            Owner.Unit.Commands.InterruptAll((UnitCommand cmd) => !(cmd is UnitMoveTo));
            var selectionManager = Game.Instance.UI.SelectionManager;

            if (selectionManager != null)
            {
                selectionManager.ForceCreateMarks();
            }
            UnityEngine.Object.Destroy(oldView.gameObject);
        }
 public void HandleHoverChange(UnitEntityView unitEntityView, bool isHover)
 {
     if (unitEntityView.EntityData == Unit)
     {
         if (isHover)
         {
             _button.OnSelect(null);
             OnEnter(Unit);
         }
         else
         {
             _button.OnDeselect(null);
             OnExit(Unit);
         }
     }
 }
 static void Postfix(UnitEntityView __instance, ref float __result)
 {
     try
     {
         if (!Main.enabled)
         {
             return;
         }
         if (__instance.EntityData == null)
         {
             return;
         }
         if (!__instance.EntityData.IsPlayerFaction)
         {
             return;
         }
         var characterSettings = Main.settings.GetCharacterSettings(__instance.EntityData);
         if (characterSettings == null)
         {
             return;
         }
         if (!characterSettings.overrideScale || !characterSettings.overrideScaleCheatMode)
         {
             return;
         }
         if (characterSettings.overrideScaleShapeshiftOnly &&
             !__instance.EntityData.Body.IsPolymorphed)
         {
             return;
         }
         Size originalSize = __instance.EntityData.Descriptor.OriginalSize;
         Size size         = __instance.EntityData.Descriptor.State.Size;
         if (__instance.DisableSizeScaling) //Used when polymorphed
         {
             originalSize = size;
         }
         float sizeDiff = characterSettings.overrideScaleAdditive ?
                          ((int)size + characterSettings.additiveScaleFactor - (int)originalSize) :
                          (characterSettings.overrideScaleFactor - (int)originalSize);
         float sizeScale = Mathf.Pow(1 / 0.66f, sizeDiff);
         __result = sizeScale;
     }
     catch (Exception ex)
     {
         Main.Error(ex);
     }
 }
        public override void RunAction()
        {
            UnitEntityData maybeCaster = this.Context.MaybeCaster;

            if (maybeCaster == null)
            {
                UberDebug.LogError((UnityEngine.Object) this, (object)"Caster is missing", (object[])Array.Empty <object>());
            }
            else
            {
                Rounds         duration        = this.DurationValue.Calculate(this.Context);
                int            count           = this.CountValue.Calculate(this.Context);
                int            level           = this.LevelValue.Calculate(this.Context);
                Vector3        clampedPosition = ObstacleAnalyzer.GetNearestNode(this.Target.Point).clampedPosition;
                UnitEntityView unitEntityView  = this.Blueprint.Prefab.Load(false);
                float          radius          = (UnityEngine.Object)unitEntityView != (UnityEngine.Object)null ? unitEntityView.Corpulence : 0.5f;
                FreePlaceSelector.PlaceSpawnPlaces(count, radius, clampedPosition);
                for (int index = 0; index < count; ++index)
                {
                    Vector3        relaxedPosition = FreePlaceSelector.GetRelaxedPosition(index, true);
                    UnitEntityData summonedUnit    = this.Context.TriggerRule <RuleSummonUnit>(new RuleSummonUnit(maybeCaster, this.Blueprint, relaxedPosition, duration, level)
                    {
                        Context           = this.Context,
                        DoNotLinkToCaster = this.DoNotLinkToCaster
                    }).SummonedUnit;
                    var weapon = getWeapon();
                    if (weapon != null)
                    {
                        ItemsCollection.DoWithoutEvents((Action)(() => summonedUnit.Body.PrimaryHand.InsertItem(weapon.CreateEntity())));
                    }

                    if (attack_mark_buff != null)
                    {
                        summonedUnit.Ensure <UnitPartSpiritualWeaponTargetMark>().buff = attack_mark_buff;
                    }
                    if ((UnityEngine.Object) this.SummonPool != (UnityEngine.Object)null)
                    {
                        GameHelper.RegisterUnitInSummonPool(this.SummonPool, summonedUnit);
                    }
                    using (this.Context.GetDataScope((TargetWrapper)summonedUnit))
                        this.AfterSpawn.Run();

                    summonedUnit.Descriptor.CustomName = custom_name;
                    EventBus.RaiseEvent <IUnitNameHandler>((Action <IUnitNameHandler>)(h => h.OnUnitNameChanged(summonedUnit)));
                }
            }
        }
        public static void PreloadUnit(UnitEntityView __instance)
        {
            if (__instance == null)
            {
                return;
            }
            var unit = __instance.EntityData;

            if (!unit.IsPlayerFaction)
            {
                return;
            }
            var characterSettings = Main.settings.GetCharacterSettings(unit);

            if (characterSettings == null)
            {
                return;
            }
            var blueprintRace = unit.Descriptor.Progression.Race;
            var race          = blueprintRace?.RaceId ?? Race.Human;
            var gender        = unit.Gender;

            TryPreloadKEE(characterSettings.overrideHelm, gender, race);
            TryPreloadKEE(characterSettings.overrideShirt, gender, race);
            TryPreloadKEE(characterSettings.overrideArmor, gender, race);
            TryPreloadKEE(characterSettings.overrideBracers, gender, race);
            TryPreloadKEE(characterSettings.overrideGloves, gender, race);
            TryPreloadKEE(characterSettings.overrideBoots, gender, race);
            TryPreloadEE(characterSettings.overrideTattoo, gender, race);
            foreach (var kv in characterSettings.overrideWeapons)
            {
                TryPreloadWeapon(kv.Value, gender, race);
            }
            if (!string.IsNullOrEmpty(characterSettings.overrideView))
            {
                ResourcesLibrary.PreloadResource <GameObject>(characterSettings.overrideView);
            }
            if (characterSettings.classOutfit.Name == "None")
            {
                var clothes = gender == Gender.Male ? BlueprintRoot.Instance.CharGen.MaleClothes : BlueprintRoot.Instance.CharGen.FemaleClothes;
                foreach (var clothing in clothes)
                {
                    clothing.Preload();
                }
            }
        }
 static void Postfix(UnitEntityView __instance, ref float __result)
 {
     try
     {
         if (!Main.enabled)
         {
             return;
         }
         if (!__instance.EntityData.IsPlayerFaction)
         {
             return;
         }
         var characterSettings = Main.settings.GetCharacterSettings(__instance.EntityData);
         if (characterSettings == null)
         {
             return;
         }
         if (!characterSettings.overrideScale || characterSettings.overrideScaleCheatMode)
         {
             return;
         }
         if (characterSettings.overrideScaleShapeshiftOnly &&
             !__instance.EntityData.Body.IsPolymorphed)
         {
             return;
         }
         __result *= __instance.GetSizeScale();
         var sizeDiff = 0f;
         if (characterSettings.overrideScaleAdditive)
         {
             sizeDiff = (int)__instance.EntityData.Descriptor.State.Size + characterSettings.additiveScaleFactor - (int)__instance.EntityData.Descriptor.OriginalSize;
         }
         else
         {
             sizeDiff = characterSettings.overrideScaleFactor - (int)__instance.EntityData.Descriptor.OriginalSize;
         }
         var newScaleFactor = Mathf.Pow(1 / 0.66f, sizeDiff);
         __result /= newScaleFactor;
     }
     catch (Exception ex)
     {
         Main.Error(ex);
     }
 }
Exemplo n.º 21
0
        public override void RunAction()
        {
            UnitEntityData maybeCaster = base.Context.MaybeCaster;

            if (maybeCaster == null)
            {
                UberDebug.LogError(this, "Caster is missing", Array.Empty <object>());
                return;
            }
            Vector3 vector = base.Target.Point;

            vector += new Vector3(-3, 0, -2);
            vector  = ObstacleAnalyzer.GetNearestNode(vector).clampedPosition;
            UnitEntityView unitEntityView = this.Blueprint.Prefab.Load(false);
            float          radius         = (unitEntityView != null) ? unitEntityView.Corpulence : 0.5f;

            FreePlaceSelector.PlaceSpawnPlaces(3, radius, vector);
            Game.Instance.EntityCreator.SpawnUnit(this.Blueprint, vector, Quaternion.identity, maybeCaster.HoldingState);
        }
Exemplo n.º 22
0
            static bool Prefix(UnitMovementAgent __instance, ref float deltaTime)
            {
                if (IsInCombat())
                {
                    //                          passing     acting      ending      delaying
                    // not in combat            o           x           x           x
                    // in combat - not current  x           x           x           x
                    // in combat - current      x           o           x           x

                    bool           canMove       = default;
                    bool           isInForceMode = __instance.GetIsInForceMode();
                    UnitEntityView view          = __instance.Unit;

                    if (IsPassing())
                    {
                        canMove = !(view?.EntityData?.IsInCombat ?? false);
                    }
                    else
                    {
                        if (canMove = (view?.EntityData).IsCurrentUnit() && IsActing() &&
                                      !(view.AnimationManager?.IsPreventingMovement ?? false) &&
                                      !view.IsCommandsPreventMovement && __instance.IsReallyMoving)
                        {
                            CurrentTurn().TickMovement(ref deltaTime, isInForceMode);
                            canMove = deltaTime > 0f;
                        }
                        else
                        {
                            canMove = false;
                        }
                    }

                    if (!canMove)
                    {
                        if (!isInForceMode)
                        {
                            __instance.Stop();
                        }
                        return(false);
                    }
                }
                return(true);
            }
        static bool OverrideEquipment(UnitEntityView __instance, ItemSlot slot, string assetId, ref bool dirty)
        {
            var kee = ResourcesLibrary.TryGetBlueprint <KingmakerEquipmentEntity>(assetId);

            if (kee == null)
            {
                return(false);
            }
            var ee = kee.Load(__instance.EntityData.Descriptor.Gender, __instance.EntityData.Descriptor.Progression.Race.RaceId);

            if (ee == null)
            {
                return(false);
            }
            HideSlot(__instance, slot, ref dirty);
            __instance.CharacterAvatar.AddEquipmentEntities(ee);
            dirty = true;
            return(true);
        }
Exemplo n.º 24
0
 private void LevelUp(UnitDescriptor unit, int levels, bool fromFact)
 {
     using (new IgnorePrerequisites())
     {
         ClassLevelLimit component       = unit.Blueprint.GetComponent <ClassLevelLimit>();
         int             classLevelLimit = component == null ? int.MaxValue : component.LevelLimit;
         if (ElementsContext.GetData <DefaultBuildData>() != null)
         {
             classLevelLimit = 0;
         }
         Dictionary <SelectionEntry, HashSet <int> > selectionsHistory = new Dictionary <SelectionEntry, HashSet <int> >();
         HashSet <int> spellHistory = (instance.SelectSpells.Length <= 0) ? null : new HashSet <int>();
         for (int i = 0; i < levels; i++)
         {
             if (unit.Progression.CharacterLevel < classLevelLimit)
             {
                 Main.Log($"A: Adding level {i} unitlevel {unit.Progression.CharacterLevel}");
                 this.AddLevel(unit, selectionsHistory, spellHistory);
             }
             else
             {
                 Main.Log($"B: Adding level {i} unitlevel {unit.Progression.CharacterLevel}");
                 LevelUpPlanUnitHolder levelUpPlanUnitHolder = unit.Get <LevelUpPlanUnitHolder>();
                 if (levelUpPlanUnitHolder != null)
                 {
                     UnitDescriptor    unitDescriptor    = levelUpPlanUnitHolder.RequestPlan();
                     LevelUpController levelUpController = this.AddLevel(unitDescriptor, selectionsHistory, spellHistory);
                     unit.Progression.AddLevelPlan(levelUpController.GetPlan());
                 }
             }
         }
         this.PrepareSpellbook(unit);
         unit.Progression.ReapplyFeaturesOnLevelUp();
         UnitEntityView view = unit.Unit.View;
         if (view != null)
         {
             view.UpdateClassEquipment();
         }
         RestController.ApplyRest(unit);
     }
 }
 static void Postfix(UnitEntityView __instance)
 {
     try
     {
         if (!Main.enabled)
         {
             return;
         }
         if (__instance.EntityData == null)
         {
             return;
         }
         if (!__instance.EntityData.IsPlayerFaction)
         {
             return;
         }
         var characterSettings = Main.settings.GetCharacterSettings(__instance.EntityData);
         if (characterSettings == null)
         {
             return;
         }
         if (!characterSettings.overrideScale || characterSettings.overrideScaleCheatMode)
         {
             return;
         }
         if (__instance.EntityData.Body == null)
         {
             return;
         }
         if (characterSettings.overrideScaleShapeshiftOnly &&
             !__instance.EntityData.Body.IsPolymorphed)
         {
             return;
         }
         OverrideSize(__instance, characterSettings);
     }
     catch (Exception ex)
     {
         Main.Error(ex);
     }
 }
        /*
         * Based on Polymorph.TryReplaceView. Replaces view, only used when changing view through UI
         * When id is null or "", rebuilds original view
         */
        public static void ReplaceView(UnitEntityData unit, string id)
        {
            var original = unit.View;

            foreach (Buff buff in unit.Buffs)
            {
                buff.ClearParticleEffect();
            }
            UnitEntityView template = GetView(id);

            if (template == null)
            {
                template = unit.Blueprint.Prefab.Load();
            }
            var instance = UnityEngine.Object.Instantiate(template).GetComponent <UnitEntityView>();

            instance.UniqueId = unit.UniqueId;
            instance.transform.SetParent(original.transform.parent);
            instance.transform.position = original.transform.position;
            instance.transform.rotation = original.transform.rotation;
            if (!string.IsNullOrEmpty(id))
            {
                instance.DisableSizeScaling = true;
                //Prevent halflings from running too fast
                Traverse.Create(instance).Field("m_IgnoreRaceAnimationSettings").SetValue(true);
            }
            instance.Blueprint = unit.Blueprint;
            unit.AttachToViewOnLoad(instance);
            unit.Commands.InterruptAll((UnitCommand cmd) => !(cmd is UnitMoveTo));
            SelectionManager selectionManager = Game.Instance.UI.SelectionManager;

            if (selectionManager != null)
            {
                selectionManager.ForceCreateMarks();
            }
            UnityEngine.Object.Destroy(original.gameObject);
            if (string.IsNullOrEmpty(id))
            {
                CharacterManager.RebuildCharacter(unit);
            }
        }
        public static float GetRealSizeScale(UnitEntityView __instance, Settings.CharacterSettings characterSettings)
        {
            var originalScale = __instance.GetSizeScale();
            int originalSize  = (int)__instance.EntityData.Descriptor.OriginalSize;

            if (__instance.DisableSizeScaling)
            {
                originalSize = (int)__instance.EntityData.Descriptor.State.Size;
            }
            float sizeScale = 1;

            if (characterSettings.overrideScaleAdditive)
            {
                sizeScale = originalScale * Mathf.Pow(1 / 0.66f, characterSettings.additiveScaleFactor);
            }
            else
            {
                sizeScale = Mathf.Pow(1 / 0.66f, characterSettings.overrideScaleFactor - originalSize);
            }
            return(sizeScale);
        }
Exemplo n.º 28
0
        public override void RunAction()
        {
            ModStorage.dolls["dolldata0"] = Game.Instance.Player.MainCharacter.Value.Descriptor.Doll;
            ModStorage.dolls["dolldata1"] = Game.Instance.Player.MainCharacter.Value.Descriptor.Doll;
            if (ModStorage.dolls.ContainsKey(dollData_key))
            {
                DollData       doll   = ModStorage.dolls[dollData_key];
                UnitDescriptor unit   = unitEV.GetValue().Descriptor;
                UnitEntityView newViw = doll.CreateUnitView();
                UnitEntityView oldVIw = unit.Unit.View;
                newViw.UniqueId = unit.Unit.UniqueId;
                newViw.transform.SetParent(unit.Unit.View.transform);
                newViw.transform.SetPositionAndRotation(unit.Unit.View.transform.position, unit.Unit.View.transform.rotation);
                newViw.Blueprint = unit.Unit.Blueprint;
                newViw.UpdateBodyEquipmentModel();
                //newViw.UpdateViewActive();
                unit.Doll = doll;
                unit.Unit.AttachToViewOnLoad(newViw);


                //UnityEngine.Object.Destroy(oldVIw.gameObject);
            }
        }
        /*
         * The unitEntityView stores the current scale in m_Scale, and smoothly adjusts to until it is equal to
         * sizeScale from unitEntityView.GetSizeScale()
         * sizeScale is defined as
         * Math.Pow(1 / 0.66, Descriptor.State.Size - Descriptor.OriginalSize;);
         * The actual size is change defined as
         * base.transform.localScale = UnitEntityView.m_OriginalScale * sizeScale;
         */
        static void OverrideSize(UnitEntityView __instance, Settings.CharacterSettings characterSettings)
        {
            var sizeScale       = GetRealSizeScale(__instance, characterSettings);
            var m_OriginalScale = m_OriginalScaleRef(__instance);
            var m_Scale         = __instance.transform.localScale.x / m_OriginalScale.x;

            if (!sizeScale.Equals(m_Scale) && !__instance.DoNotAdjustScale)
            {
                /*float scaleDelta = sizeScale - m_Scale;
                 * float deltaTime = Game.Instance.TimeController.DeltaTime;
                 * float scaleStep = scaleDelta * deltaTime * 2f;
                 * m_Scale = (scaleDelta <= 0f) ? Math.Max(sizeScale, m_Scale + scaleStep) : Math.Min(sizeScale, m_Scale + scaleStep);*/
                m_Scale = sizeScale; //Skip animating
                __instance.transform.localScale = m_OriginalScale * m_Scale;
            }

            if (__instance.ParticlesSnapMap)
            {
                //Is this necessary?
                __instance.ParticlesSnapMap.AdditionalScale = __instance.transform.localScale.x / m_OriginalScale.x;
            }
            //Prevent fighting m_Scale to set transform scale
            m_ScaleRef(__instance) = __instance.GetSizeScale();
        }
        public static void SetHighlight(this UnitEntityData unit, bool highlight)
        {
            UnitEntityView view = unit?.View;

            if (view == null || view.IsHighlighted || (highlight && DoNotMarkInvisibleUnit && !unit.IsVisibleForPlayer))
            {
                return;
            }

            UnitMultiHighlight highlighter = view.GetHighlighter();

            if (highlighter)
            {
                UIRoot uiRoot = UIRoot.Instance;
                Player player = Game.Instance.Player;
                highlighter.BaseColor =
                    // none
                    !highlight ? Color.clear :
                    // loot
                    unit.Descriptor.State.IsDead ? (unit.LootViewed ? uiRoot.VisitedLootColor : uiRoot.StandartUnitLootColor) :
                    // player, neutral, enemy
                    unit.StatusSwitch(uiRoot.AllyHighlightColor, uiRoot.NeutralHighlightColor, uiRoot.EnemyHighlightColor);
            }
        }