public static bool IsDefault(this MechComponentDef item) { if (item == null) { return(false); } var f = item.Flags <CCFlags>(); if (f == null) { return(false); } return(f.Default); }
public static void Postfix(MechComponentDef componentDef, ref UIColor __result) { try { var f = componentDef.Flags <CCFlags>(); if (f.Invalid) { __result = Control.Settings.InvalidFlagBackgroundColor; } else if (f.Default) { __result = Control.Settings.DefaultFlagBackgroundColor; } } catch (Exception e) { Control.LogError(e); } }
public static bool CheckDefaults(ref MechComponentDef def) { if (def == null) { Control.LogError("Get NULL component in salvage!"); return(false); } if (!def.Flags <CCFlags>().NoSalvage) { return(true); } var lootable = def.GetComponent <LootableDefault>(); if (lootable == null) { Control.LogDebug(DType.SalvageProccess, $"---- default, no lootable - skipped"); return(false); } MechComponentDef component = null; switch (def.ComponentType) { case ComponentType.AmmunitionBox: if (UnityGameInstance.BattleTechGame.DataManager.AmmoBoxDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.AmmoBoxDefs.Get(lootable.ItemID); } break; case ComponentType.Weapon: if (UnityGameInstance.BattleTechGame.DataManager.WeaponDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.WeaponDefs.Get(lootable.ItemID); } break; case ComponentType.Upgrade: if (UnityGameInstance.BattleTechGame.DataManager.UpgradeDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.UpgradeDefs.Get(lootable.ItemID); } break; case ComponentType.HeatSink: if (UnityGameInstance.BattleTechGame.DataManager.HeatSinkDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.HeatSinkDefs.Get(lootable.ItemID); } break; case ComponentType.JumpJet: if (UnityGameInstance.BattleTechGame.DataManager.JumpJetDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.JumpJetDefs.Get(lootable.ItemID); } break; } if (component == null || component.Flags <CCFlags>().NoSalvage) { Control.LogDebug(DType.SalvageProccess, $"---- default, lootable {lootable.ItemID} not found or notsalvagable - skipped"); return(false); } Control.LogDebug(DType.SalvageProccess, $"---- default, lootable {lootable.ItemID} replaced"); def = component; return(true); }
public static bool AddToFinalSalvage(ref SalvageDef def) { if (def.MechComponentDef == null) { return(true); } if (!def.MechComponentDef.Flags <CCFlags>().NoSalvage) { return(true); } var lootable = def.MechComponentDef.GetComponent <LootableDefault>(); if (lootable == null) { return(false); } MechComponentDef component = null; switch (def.ComponentType) { case ComponentType.AmmunitionBox: if (UnityGameInstance.BattleTechGame.DataManager.AmmoBoxDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.AmmoBoxDefs.Get(lootable.ItemID); } break; case ComponentType.Weapon: if (UnityGameInstance.BattleTechGame.DataManager.WeaponDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.WeaponDefs.Get(lootable.ItemID); } break; case ComponentType.Upgrade: if (UnityGameInstance.BattleTechGame.DataManager.UpgradeDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.UpgradeDefs.Get(lootable.ItemID); } break; case ComponentType.HeatSink: if (UnityGameInstance.BattleTechGame.DataManager.HeatSinkDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.HeatSinkDefs.Get(lootable.ItemID); } break; case ComponentType.JumpJet: if (UnityGameInstance.BattleTechGame.DataManager.JumpJetDefs.Exists(lootable.ItemID)) { component = UnityGameInstance.BattleTechGame.DataManager.JumpJetDefs.Get(lootable.ItemID); } break; } if (component == null || component.Flags <CCFlags>().NoSalvage) { return(false); } SalvageDef salvageDef = new SalvageDef(); salvageDef.MechComponentDef = component; salvageDef.Description = new DescriptionDef(component.Description); salvageDef.RewardID = def.RewardID; salvageDef.Type = SalvageDef.SalvageType.COMPONENT; salvageDef.ComponentType = def.ComponentType; salvageDef.Damaged = false; salvageDef.Weight = def.Weight; salvageDef.Count = 1; def = salvageDef; return(true); }