static void Postfix(LanceConfiguratorPanel __instance, ref LanceConfiguration __result, LanceLoadoutSlot[] ___loadoutSlots) { try { if (CustomUnitsAPI.Detected()) { return; } Fields.callsigns.Clear(); LanceConfiguration lanceConfiguration = new LanceConfiguration(); for (int i = 0; i < ___loadoutSlots.Length; i++) { LanceLoadoutSlot lanceLoadoutSlot = ___loadoutSlots[i]; MechDef mechDef = null; PilotDef pilotDef = null; if (lanceLoadoutSlot.SelectedMech != null) { mechDef = lanceLoadoutSlot.SelectedMech.MechDef; } if (lanceLoadoutSlot.SelectedPilot != null) { pilotDef = lanceLoadoutSlot.SelectedPilot.Pilot.pilotDef; } if (mechDef != null && pilotDef != null) { if (i < Settings.DEFAULT_MECH_SLOTS) { lanceConfiguration.AddUnit(__instance.playerGUID, mechDef, pilotDef); } else { //if (i >= BiggerDrops.settings.additinalMechSlots + Settings.DEFAULT_MECH_SLOTS) { break; } Logger.M.TWL(0, "LanceConfiguratorPanel.CreateLanceConfiguration. Index:" + i + " additional slots border:" + (BiggerDrops.settings.additinalMechSlots + Settings.DEFAULT_MECH_SLOTS) + " player slots border:" + (BiggerDrops.settings.additinalPlayerMechSlots + Settings.DEFAULT_MECH_SLOTS)); if (i >= BiggerDrops.settings.additinalPlayerMechSlots + Settings.DEFAULT_MECH_SLOTS) { Fields.callsigns.Add(pilotDef.Description.Callsign); //EMPLOYER ID Logger.M.WL(1, "adding to employer lance " + Settings.EMPLOYER_LANCE_GUID + " mech:" + mechDef.Description.Id + " pilot:" + pilotDef.Description.Id); lanceConfiguration.AddUnit(Settings.EMPLOYER_LANCE_GUID, mechDef, pilotDef); } else { Logger.M.WL(1, "adding to player lance " + __instance.playerGUID + " mech:" + mechDef.Description.Id + " pilot:" + pilotDef.Description.Id); lanceConfiguration.AddUnit(__instance.playerGUID, mechDef, pilotDef); } } } } __result = lanceConfiguration; } catch (Exception e) { Logger.LogError(e); } }
public static void Postfix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC) { Mod.Log.Trace?.Write("LLS:RID:post - entered."); if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null || ___initiativeTooltip == null) { return; } bool bothSelected = __instance.SelectedMech != null && __instance.SelectedPilot != null; if (!bothSelected) { ___initiativeText.SetText("-"); ___initiativeColor.SetUIColor(UIColor.MedGray); } else { // --- MECH --- MechDef selectedMechDef = __instance.SelectedMech.MechDef; List <string> details = new List <string>(); // Static initiative from tonnage int initPhase = PhaseHelper.TonnageToPhase((int)Math.Ceiling(__instance.SelectedMech.MechDef.Chassis.Tonnage)); int initLabelVal = (Mod.MaxPhase + 1) - initPhase; details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_BASE], new object[] { initLabelVal }).ToString()); // Any bonuses from equipment int componentBonus = UnitHelper.GetNormalizedComponentModifier(__instance.SelectedMech.MechDef); string componentColor = "FFFFFF"; if (componentBonus > 0) { componentColor = "00FF00"; } if (componentBonus < 0) { componentColor = "FF0000"; } details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_COMPONENT], new object[] { componentColor, componentBonus }).ToString()); Mod.Log.Debug?.Write($"Component bonus is: {componentBonus}"); // --- LANCE --- int lanceBonus = 0; if (___LC != null) { lanceBonus = ___LC.lanceInitiativeModifier; } string lanceColor = "FFFFFF"; if (lanceBonus > 0) { lanceColor = "00FF00"; } if (lanceBonus < 0) { lanceColor = "FF0000"; } details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_LANCE], new object[] { lanceColor, lanceBonus }).ToString()); // --- PILOT --- // TODO: Get pilot modifiers from abilities - coordinate with BD Pilot selectedPilot = __instance.SelectedPilot.Pilot; int pilotBonus = 0; foreach (Ability ability in selectedPilot.PassiveAbilities) { foreach (EffectData effectData in ability.Def.EffectData) { if (effectData.effectType == EffectType.StatisticEffect && effectData.statisticData != null && effectData.statisticData.statName == "BaseInitiative") { int mod = Int32.Parse(effectData.statisticData.modValue) * -1; if (effectData.statisticData.operation == StatCollection.StatOperation.Int_Add) { pilotBonus += mod; } else if (effectData.statisticData.operation == StatCollection.StatOperation.Int_Subtract) { pilotBonus -= mod; } } } } string pilotColor = "FFFFFF"; if (pilotBonus > 0) { pilotColor = "00FF00"; } if (pilotBonus < 0) { pilotColor = "FF0000"; } details.Add(new Text(Mod.Config.LocalizedText[ModConfig.LT_TT_PILOT], new object[] { pilotColor, pilotBonus }).ToString()); // --- Badge --- int summaryInitLabel = initLabelVal + componentBonus + pilotBonus + lanceBonus; if (summaryInitLabel > Mod.MaxPhase) { summaryInitLabel = Mod.MaxPhase; } else if (summaryInitLabel < Mod.MinPhase) { summaryInitLabel = Mod.MinPhase; } ___initiativeText.SetText($"{summaryInitLabel}"); ___initiativeText.color = Color.black; ___initiativeColor.SetUIColor(UIColor.White); // --- Tooltip --- string tooltipTitle = $"{selectedMechDef.Name}: {selectedPilot.Name}"; string detailsS = String.Join("\n", details.ToArray()); string tooltipText = new Text(Mod.Config.LocalizedText[ModConfig.LT_LC_TT_SUMMARY], new object[] { detailsS, summaryInitLabel }).ToString(); BaseDescriptionDef initiativeData = new BaseDescriptionDef("LLS_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } }
// 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); }
public static void Postfix(LanceLoadoutSlot __instance, GameObject ___initiativeObj, TextMeshProUGUI ___initiativeText, UIColorRefTracker ___initiativeColor, HBSTooltip ___initiativeTooltip, LanceConfiguratorPanel ___LC) { if (___initiativeObj == null || ___initiativeText == null || ___initiativeColor == null || ___initiativeTooltip == null) { return; } //SkillBasedInit.Logger.Log($"LanceLoadoutSlot::RefreshInitiativeData::post - disabling text"); bool bothSelected = __instance.SelectedMech != null && __instance.SelectedPilot != null; if (!bothSelected) { ___initiativeText.SetText("-"); ___initiativeColor.SetUIColor(UIColor.MedGray); } else { int initValue = 0; // --- MECH --- MechDef selectedMechDef = __instance.SelectedMech.MechDef; List <string> details = new List <string>(); // Static initiative from tonnage float tonnage = __instance.SelectedMech.MechDef.Chassis.Tonnage; int tonnageMod = UnitHelper.GetTonnageModifier(tonnage); initValue += tonnageMod; details.Add($"Tonnage Base: {tonnageMod}"); // Any special modifiers by type - NA, Mech is the only type // Any modifiers that come from the chassis/mech/vehicle defs int componentsMod = UnitHelper.GetNormalizedComponentModifier(selectedMechDef); initValue += componentsMod; if (componentsMod > 0) { details.Add($"<space=2em><color=#00FF00>{componentsMod:+0} components</color>"); } else if (componentsMod < 0) { details.Add($"<space=2em><color=#FF0000>{componentsMod:0} components</color>"); } // Modifier from the engine int engineMod = UnitHelper.GetEngineModifier(selectedMechDef); initValue += engineMod; if (engineMod > 0) { details.Add($"<space=2em><color=#00FF00>{engineMod:+0} engine</color>"); } else if (engineMod < 0) { details.Add($"<space=2em><color=#FF0000>{engineMod:0} engine</color>"); } // --- PILOT --- Pilot selectedPilot = __instance.SelectedPilot.Pilot; int tacticsMod = PilotHelper.GetTacticsModifier(selectedPilot); details.Add($"<space=2em>{tacticsMod:+0} tactics"); initValue += tacticsMod; int pilotTagsMod = PilotHelper.GetTagsModifier(selectedPilot); details.AddRange(PilotHelper.GetTagsModifierDetails(selectedPilot)); initValue += pilotTagsMod; int[] randomnessBounds = PilotHelper.GetRandomnessBounds(selectedPilot); // --- LANCE --- if (___LC != null) { initValue += ___LC.lanceInitiativeModifier; if (___LC.lanceInitiativeModifier > 0) { details.Add($"<space=2em><color=#00FF00>{___LC.lanceInitiativeModifier:+0} lance</color>"); } else if (___LC.lanceInitiativeModifier < 0) { details.Add($"<space=2em><color=#FF0000>{___LC.lanceInitiativeModifier:0} lance</color>"); } } // --- Badge --- ___initiativeText.SetText($"{initValue}"); ___initiativeText.color = Color.black; ___initiativeColor.SetUIColor(UIColor.White); // --- Tooltip --- int maxInit = Math.Max(initValue - randomnessBounds[0], Mod.MinPhase); int minInit = Math.Max(initValue - randomnessBounds[1], Mod.MinPhase); details.Add($"Total:{initValue}"); details.Add($"<space=2em><color=#FF0000>-{randomnessBounds[0]} to -{randomnessBounds[1]} randomness</color> (piloting)"); details.Add($"<b>Expected Phase<b>: {maxInit} to {minInit}"); string tooltipTitle = $"{selectedMechDef.Name}: {selectedPilot.Name}"; string tooltipText = String.Join("\n", details.ToArray()); BaseDescriptionDef initiativeData = new BaseDescriptionDef("LLS_MECH_TT", tooltipTitle, tooltipText, null); ___initiativeTooltip.enabled = true; ___initiativeTooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(initiativeData)); } }