internal static void Postfix( MechLabMechInfoWidget __instance, ref MechLabPanel ___mechLab, ref MechLabHardpointElement[] ___hardpoints) { try { var mechDef = ___mechLab.activeMechDef; if (mechDef == null) { return; } var inventory = mechDef.Inventory.Select(x => x.Def); var hardpoints = MechDefBuilder.Locations.SelectMany(x => mechDef.Chassis.GetLocationDef(x).Hardpoints).ToArray(); var calc = new HardpointOmniUsageCalculator(inventory, hardpoints); //Control.mod.Logger.Log(calc); __instance.totalBallisticHardpoints = calc.Ballistic.TheoreticalMax; __instance.totalEnergyHardpoints = calc.Energy.TheoreticalMax; __instance.totalMissileHardpoints = calc.Missile.TheoreticalMax; __instance.totalSmallHardpoints = calc.Small.TheoreticalMax; ___hardpoints[0].SetData(WeaponCategoryEnumeration.GetBallistic(), calc.Ballistic.HardpointTotalString); ___hardpoints[1].SetData(WeaponCategoryEnumeration.GetEnergy(), calc.Energy.HardpointTotalString); ___hardpoints[2].SetData(WeaponCategoryEnumeration.GetMissile(), calc.Missile.HardpointTotalString); ___hardpoints[3].SetData(WeaponCategoryEnumeration.GetSupport(), calc.Small.HardpointTotalString); } catch (Exception e) { Control.mod.Logger.LogError(e); } }
internal static void Postfix( MechDef mechDef, MechLabHardpointElement ___BallisticHardPointElement, MechLabHardpointElement ___EnergyHardPointElement, MechLabHardpointElement ___MissileHardPointElement, MechLabHardpointElement ___SmallHardPointElement) { try { if (mechDef == null) { return; } var inventory = mechDef.Inventory.Select(x => x.Def); var hardpoints = MechDefBuilder.Locations.SelectMany(x => mechDef.Chassis.GetLocationDef(x).Hardpoints).ToArray(); var calc = new HardpointOmniUsageCalculator(inventory, hardpoints); //Control.mod.Logger.Log(calc); ___BallisticHardPointElement.SetData(WeaponCategoryEnumeration.GetBallistic(), calc.Ballistic.HardpointString); ___EnergyHardPointElement.SetData(WeaponCategoryEnumeration.GetEnergy(), calc.Energy.HardpointString); ___MissileHardPointElement.SetData(WeaponCategoryEnumeration.GetMissile(), calc.Missile.HardpointString); ___SmallHardPointElement.SetData(WeaponCategoryEnumeration.GetSupport(), calc.Small.HardpointString); } catch (Exception e) { Control.mod.Logger.LogError(e); } }
internal static void SetJumpJetHardpointCount(MechLabMechInfoWidget widget, MechLabPanel mechLab, MechLabHardpointElement[] hardpoints) { if (mechLab == null || mechLab.activeMechDef == null || mechLab.activeMechInventory == null) { return; } if (mechLab.activeMechDef.Chassis == null) { return; } var current = mechLab.headWidget.currentJumpjetCount + mechLab.centerTorsoWidget.currentJumpjetCount + mechLab.leftTorsoWidget.currentJumpjetCount + mechLab.rightTorsoWidget.currentJumpjetCount + mechLab.leftArmWidget.currentJumpjetCount + mechLab.rightArmWidget.currentJumpjetCount + mechLab.leftLegWidget.currentJumpjetCount + mechLab.rightLegWidget.currentJumpjetCount; var stats = new MechDefMovementStatistics(mechLab.activeMechDef); widget.totalJumpjets = stats.JumpJetCount; if (hardpoints == null || hardpoints[4] == null) { return; } hardpoints[4].SetData(WeaponCategoryEnumeration.GetAMS(), $"{current} / {widget.totalJumpjets}"); }
internal HardpointOmniUsageCalculator(IEnumerable <MechComponentDef> items, HardpointDef[] hardpoints) { stats[WeaponCategoryEnumeration.GetBallistic()] = new HardpointStat(WeaponCategoryEnumeration.GetBallistic()); stats[WeaponCategoryEnumeration.GetEnergy()] = new HardpointStat(WeaponCategoryEnumeration.GetEnergy()); stats[WeaponCategoryEnumeration.GetMissile()] = new HardpointStat(WeaponCategoryEnumeration.GetMissile()); stats[WeaponCategoryEnumeration.GetSupport()] = new HardpointStat(WeaponCategoryEnumeration.GetSupport()); SetUsage(items); SetMax(hardpoints); }
public void LoadValue(string value) { WeaponCategory = WeaponCategoryEnumeration.GetWeaponCategoryByName(value); if (WeaponCategory == null) { WeaponCategory = WeaponCategoryEnumeration.GetNotSetValue(); } if (!WeaponCategory.Is_NotSet) { HPinfo = HardpointController.Instance[WeaponCategory]; } }
public void OnLoaded(Dictionary <string, object> values) { AddWeaponCategory = WeaponCategoryEnumeration.GetWeaponCategoryByName(AddHardpoint); if (AddWeaponCategory == null) { AddWeaponCategory = WeaponCategoryEnumeration.GetNotSetValue(); } UseWeaponCategory = WeaponCategoryEnumeration.GetWeaponCategoryByName(UseHardpoint); if (UseWeaponCategory == null) { UseWeaponCategory = WeaponCategoryEnumeration.GetNotSetValue(); } }
public void LoadValue(string value) { Control.LogDebug(DType.Hardpoints, $"UseHardpoint LoadValue for {Def.Description.Id}: {value}"); var cat = WeaponCategoryEnumeration.GetWeaponCategoryByName(value); WeaponCategory = cat ?? WeaponCategoryEnumeration.GetNotSetValue(); hpInfo = WeaponCategory.Is_NotSet ? null : HardpointController.Instance[WeaponCategory]; if (hpInfo != null && !hpInfo.AllowOnWeapon) { Control.LogError($"{Def.Description.Id} use {value} weapon category that cannot be used on weapons"); hpInfo = null; WeaponCategory = WeaponCategoryEnumeration.GetNotSetValue(); } Control.LogDebug(DType.Hardpoints, $"- {cat.WeaponCategoryID}:{cat.Name}/{cat.FriendlyName}"); }
internal static void SetJumpJetHardpointCount(MechLabMechInfoWidget widget, MechLabPanel mechLab, MechLabHardpointElement[] hardpoints) { if (hardpoints == null || hardpoints[4] == null) { return; } var mechDef = mechLab?.CreateMechDef(); if (mechDef == null) { return; } var stats = new MechDefMovementStatistics(mechDef); widget.totalJumpjets = stats.JumpJetMaxCount; hardpoints[4].SetData(WeaponCategoryEnumeration.GetAMS(), $"{stats.JumpJetCount} / {stats.JumpJetMaxCount}"); }
internal static void SetJumpJetHardpointCount(MechLabMechInfoWidget widget, MechLabPanel mechLab, MechLabHardpointElement[] hardpoints) { if (mechLab == null || mechLab.activeMechDef == null || mechLab.activeMechInventory == null) { return; } if (mechLab.activeMechDef.Chassis == null) { return; } var engine = mechLab.GetEngine(); var current = mechLab.headWidget.currentJumpjetCount + mechLab.centerTorsoWidget.currentJumpjetCount + mechLab.leftTorsoWidget.currentJumpjetCount + mechLab.rightTorsoWidget.currentJumpjetCount + mechLab.leftArmWidget.currentJumpjetCount + mechLab.rightArmWidget.currentJumpjetCount + mechLab.leftLegWidget.currentJumpjetCount + mechLab.rightLegWidget.currentJumpjetCount; if (engine == null) { widget.totalJumpjets = 0; } else { widget.totalJumpjets = engine.CoreDef.GetMovement(mechLab.activeMechDef.Chassis.Tonnage).JumpJetCount; } widget.totalJumpjets = Mathf.Min(widget.totalJumpjets, mechLab.activeMechDef.Chassis.MaxJumpjets); if (hardpoints == null || hardpoints[4] == null) { return; } hardpoints[4].SetData(WeaponCategoryEnumeration.GetAMS(), $"{current} / {widget.totalJumpjets}"); }
public bool Complete() { if (ID == null) { Control.LogError($"Empty WeaponCategory"); return(false); } WeaponCategory = WeaponCategoryEnumeration.GetWeaponCategoryByName(ID); if (WeaponCategory == null || WeaponCategory.Is_NotSet) { Control.LogError($"Unknown WeaponCategory {ID}"); return(false); } if (Compatible == null || Compatible.Length == 0) { Compatible = new[] { ID }; } else { if (!Compatible.Contains(ID)) { Compatible.Add(ID); } } CompatibleID = Compatible .Distinct() .Select(i => WeaponCategoryEnumeration.GetWeaponCategoryByName(i)) .Where(i => i != null) .Select(i => i.ID) .ToHashSet(); return(true); }
internal static WeaponCategoryValue MapToBasicType(WeaponCategoryValue value) { if (value.IsBallistic) { return(WeaponCategoryEnumeration.GetBallistic()); } else if (value.IsEnergy) { return(WeaponCategoryEnumeration.GetEnergy()); } else if (value.IsMissile) { return(WeaponCategoryEnumeration.GetMissile()); } else if (value.IsSupport) { return(WeaponCategoryEnumeration.GetSupport()); } else { throw new System.Exception("nope"); } }
internal static WeaponCategoryValue MapToBasicType(WeaponCategoryValue value) { if (value.IsBallistic) { return(WeaponCategoryEnumeration.GetBallistic()); } else if (value.IsEnergy) { return(WeaponCategoryEnumeration.GetEnergy()); } else if (value.IsMissile) { return(WeaponCategoryEnumeration.GetMissile()); } else if (value.IsSupport) { return(WeaponCategoryEnumeration.GetSupport()); } else { Control.mod.Logger.LogWarning($"Unsupported weapon category for {value.ID}"); return(WeaponCategoryEnumeration.GetNotSetValue()); } }
public void Setup(Dictionary <string, Dictionary <string, VersionManifestEntry> > customResources) { //SetupDefaults(); foreach (var hp in SettingsResourcesTools.Enumerate <HardpointInfo>("CCHardpoints", customResources)) { if (hp.Complete()) { if (Control.Settings.DEBUG_ShowLoadedHardpoints) { Control.Log($"Hardpoint {hp.ID} loaded, [{hp.CompatibleID.Aggregate("", (last, next) => last + " " + WeaponCategoryEnumeration.GetWeaponCategoryByID(next).FriendlyName)}]"); } HardpointsByName[hp.ID] = hp; HardpointsByID[hp.WeaponCategory.ID] = hp; } } HardpointsList = HardpointsByName.Values.OrderBy(i => i.CompatibleID.Count).ToList(); HardpointInfo omni; if (HardpointsByID.TryGetValue(Control.Settings.OmniCategoryID, out omni)) { var list = HardpointsList .Where(i => i.Visible && i.AllowOnWeapon) .Select(i => new { name = i.ID, id = i.WeaponCategory.ID }) .ToArray(); omni.CompatibleID = list.Select(i => i.id).ToHashSet(); } if (Control.Settings.DEBUG_ShowLoadedHardpoints) { Control.Log($"Hardpoints: Total {HardpointsList?.Count ?? 0} Loaded"); if (omni != null) { Control.Log($"- omni list [{omni.CompatibleID.Aggregate("", (last, next) => last + " " + WeaponCategoryEnumeration.GetWeaponCategoryByID(next).FriendlyName)}]"); } else { Control.Log("- no omni hardpoint definition load"); } } }