Beispiel #1
0
        // Calculate the initiative modifiers from all components based upon a MechDef. For whatever reason they
        //  reverse the modifier right out of the gate, such that these values are positives automatically
        public static int GetNormalizedComponentModifier(MechDef mechDef)
        {
            int unitInit = 0;

            if (mechDef.Inventory != null)
            {
                MechComponentRef[] inventory = mechDef.Inventory;
                foreach (MechComponentRef mechComponentRef in inventory)
                {
                    if (mechComponentRef.Def != null && mechComponentRef.Def.statusEffects != null)
                    {
                        EffectData[] statusEffects = mechComponentRef.Def.statusEffects;
                        foreach (EffectData effect in statusEffects)
                        {
                            if (MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, true, null) == 0)
                            {
                                unitInit += MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, false, null);
                            }
                        }
                    }
                }
            }

            Mod.Log.Debug($"Normalized BaseInit for mechDef:{mechDef.Name} is unitInit:{unitInit}");
            return(unitInit);
        }
        // return false so original function does not get called.
        public static bool Prefix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText,
                                  UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC)
        {
            if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null)
            {
                return(false);
            }
            if (__instance.SelectedMech == null || __instance.SelectedMech.MechDef == null || __instance.SelectedMech.MechDef.Chassis == null)
            {
                ___initiativeObj.SetActive(false);
                return(false);
            }
            if (__instance.SelectedPilot == null || __instance.SelectedPilot.Pilot == null || __instance.SelectedPilot.Pilot.pilotDef == null)
            {
                ___initiativeObj.SetActive(false);
                return(false);
            }
            ___initiativeObj.SetActive(true);

            int num  = 1;            // default to assault phase
            int num2 = 0;            // default to no modification by effects

            float f_walkSpeed = __instance.SelectedMech.MechDef.Chassis.MovementCapDef.MaxWalkDistance;

            if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseSpecialMinSpeed)
            {
                num = 5;                  //special phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseLightMinSpeed)
            {
                num = 4;                  //light phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseMediumMinSpeed)
            {
                num = 3;                  //medium phase
            }
            else if (f_walkSpeed >= TheEngineInitiative.Settings.MechPhaseHeavyMinSpeed)
            {
                num = 2;                  //heavy phase
            }
            // check if pilot mods initiative
            if (__instance.SelectedPilot.Pilot.pilotDef.AbilityDefs != null)
            {
                foreach (AbilityDef abilityDef in __instance.SelectedPilot.Pilot.pilotDef.AbilityDefs)
                {
                    foreach (EffectData effect in abilityDef.EffectData)
                    {
                        if (MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, true, null) == 0)
                        {
                            num2 += MechStatisticsRules.GetInitiativeModifierFromEffectData(effect, false, null);
                        }
                    }
                }
            }
            // check if any of the mech's inventory changes initiative.
            if (__instance.SelectedMech.MechDef.Inventory != null)
            {
                foreach (MechComponentRef mechComponentRef in __instance.SelectedMech.MechDef.Inventory)
                {
                    if (mechComponentRef.Def != null && mechComponentRef.Def.statusEffects != null)
                    {
                        foreach (EffectData effect2 in mechComponentRef.Def.statusEffects)
                        {
                            if (MechStatisticsRules.GetInitiativeModifierFromEffectData(effect2, true, null) == 0)
                            {
                                num2 += MechStatisticsRules.GetInitiativeModifierFromEffectData(effect2, false, null);
                            }
                        }
                    }
                }
            }
            // is there a lance bonus?
            int num3 = 0;

            if (___LC != null)
            {
                num3 = ___LC.lanceInitiativeModifier;
            }
            num2 += num3;

            // make sure initiative is within the valid range.
            int num4 = Mathf.Clamp(num + num2, 1, 5);

            //set our text.
            ___initiativeText.SetText($"{num4}");
            if (___initiativeTooltip != null)
            {
                // build the tooltip.  Going to use the mech's name and tell where its speed puts it, initiative-wise.
                string tooltipTitle = $"{__instance.SelectedMech.MechDef.Name}";
                string tooltipText  = "A max walking speed of " + $"{f_walkSpeed}" + "m per turn means this mech moves in initiative phase " + $"{num}" + ".";

                // if there are effects, tell the player what they've changed initiative to.
                if (num2 != 0)
                {
                    tooltipText += " Effects have modified this to phase " + $"{num4}" + ".";
                }
                BaseDescriptionDef initiativeData = new BaseDescriptionDef("MB_MIW_MECH_TT", tooltipTitle, tooltipText, null);
                ___initiativeTooltip.enabled = true;
                ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData));
            }
            // if we've been bumped up, make it gold, if bumped down, make it red, else white.
            ___initiativeColor.SetUIColor((num2 > 0) ? UIColor.Gold : ((num2 < 0) ? UIColor.Red : UIColor.White));

            return(false);
        }