Esempio n. 1
0
        // TODO whats missing for proper locational dynamic slots support
        // track and allow moving of dynamic slots, with a bias towards locational slots near original item.
        // work by tracking and converting "movable", "reserved" and "missing" locational slots per location
        // where each location has to find its reserved slots from the locations nearby (CT more than LT)
        internal MechComponentRef Add(MechComponentDef def, ChassisLocations location = ChassisLocations.None, bool force = false)
        {
            if (def.Is <DynamicSlots>())
            {
                // TODO add support, doesn't work with arm actuators either
                throw new Exception("adding dynamic slots is not supported");
            }

            // find location
            if (location == ChassisLocations.None || LocationCount(location) > 1)
            {
                location = GetLocations()
                           .Where(l => (l & def.AllowedLocations) != 0)
                           .FirstOrDefault(l => GetLocationInfo(l).CalcMaxFree >= def.InventorySize);

                if (location == ChassisLocations.None)
                {
                    return(null);
                }
            }

            var locationInfo      = GetLocationInfo(location);
            var overUseAtLocation = locationInfo.CalcMaxFree < def.InventorySize; // considers locational dynamic slots
            var overUseOverall    = TotalFree < def.InventorySize;                // considers global dynamic slots

            if (!force && (overUseAtLocation || overUseOverall))
            {
                return(null);
            }

            Control.mod.Logger.LogDebug($"  added id={def.Description.Id} location={location} InventorySize={def.InventorySize} InventoryUsage={locationInfo.InventoryUsage} TotalInventoryUsage={TotalInventoryUsage} overUseAtLocation={overUseAtLocation} overUseOverall={overUseOverall}");

            var componentRef = new MechComponentRef(def.Description.Id, null, def.ComponentType, location);

            componentRef.DataManager = DataManager;
            componentRef.RefreshComponentDef();
            Inventory.Add(componentRef);

            Control.mod.Logger.LogDebug($"  adding id={def.Description.Id} location={location} InventorySize={def.InventorySize} InventoryUsage={locationInfo.InventoryUsage} TotalInventoryUsage={TotalInventoryUsage} overUseAtLocation={overUseAtLocation} overUseOverall={overUseOverall}");
            CalculateStats();
            Control.mod.Logger.LogDebug($"  added id={def.Description.Id} location={location} InventorySize={def.InventorySize} InventoryUsage={locationInfo.InventoryUsage} TotalInventoryUsage={TotalInventoryUsage} overUseAtLocation={overUseAtLocation} overUseOverall={overUseOverall}");

            return(componentRef);
        }
 public static bool IsMechConfiguration(MechComponentDef def)
 {
     return MechLabSlotsFeature.settings.MechLabGeneralWidgetEnabled && def.Is<MechConfiguration>();
     //return def.Is<Flags>(out var f) && f.IsSet("mech_configuration");
 }
 internal static bool IsMechConfiguration(MechComponentDef def)
 {
     return(MechLabSlotsFeature.settings.MechLabGeneralWidgetEnabled && def.Is <MechConfiguration>());
 }
Esempio n. 4
0
        public static bool CheckDefaults(ref MechComponentDef def)
        {
            if (def == null)
            {
                Control.LogError("Get NULL component in salvage!");
                return(false);
            }


            var flags = def.GetComponent <Flags>();

            if (flags == null || !flags.NotSalvagable)
            {
                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.Is <Flags>(out flags) && flags.NotSalvagable))
            {
                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);
        }
Esempio n. 5
0
 private bool SetDefault(MechComponentDef item)
 {
     return(item.Is <IDefaultComponent>());
 }
        public static bool AddToFinalSalvage(ref SalvageDef def)
        {
            if (def.MechComponentDef == null)
            {
                return(true);
            }

            var flags = def.MechComponentDef.GetComponent <Flags>();

            if (flags == null || !flags.NotSalvagable)
            {
                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.Is <Flags>(out flags) && flags.NotSalvagable))
            {
                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);
        }