public static List <HPUsage> GetHardpointUsage(this MechDef mech, IEnumerable <InvItem> inventory = null) { var result = new List <HPUsage>(); if (mech != null) { foreach (var location in DefaultsDatabase.SingleLocations) { var usage = mech.GetHardpointUsage(location, inventory); if (usage != null) { foreach (var hpUsage in usage) { var item = result.FirstOrDefault(i => i.hpInfo.WeaponCategory.ID == hpUsage.WeaponCategoryID); if (item == null) { result.Add(new HPUsage(hpUsage)); } else { item.Total += hpUsage.Total; item.Used += hpUsage.Used; } } } } } return(result); }
public static bool SetHardpoints(MechBayMechInfoWidget __instance, LocalizableText ___jumpjetHardpointText, LocalizableText ___ballisticHardpointText, MechDef ___selectedMech) { try { var hardpoints = __instance.GetComponent <UIModuleHPHandler>(); if (hardpoints == null) { hardpoints = __instance.gameObject.AddComponent <UIModuleHPHandler>(); hardpoints.Init(__instance, ___ballisticHardpointText.gameObject, ___jumpjetHardpointText.gameObject, new Vector2(-5, -58)); } var usage = ___selectedMech.GetHardpointUsage(); hardpoints.SetData(usage); hardpoints.SetJJ(___selectedMech.GetJJCountByMechDef(), ___selectedMech.GetJJMaxByMechDef()); } catch (Exception e) { Control.LogError(e); } return(false); }