protected void TransferResourceFromEVA(string resourceName)
        {
            double availableSpace = GetResourceAmount(resourceName, true) - GetResourceAmount(resourceName);
            double toAdd          = 0d;

            for (int i = 0; i < FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.InventorySlots; i++)
            {
                if (availableSpace > 0d)
                {
                    if (!FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.IsSlotEmpty(i))
                    {
                        StoredPart sPart = FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.storedParts[i];
                        if (sPart.partName == RefuelCargoPartName)
                        {
                            ProtoPartResourceSnapshot res = sPart.snapshot.resources.Find(x => x.resourceName == resourceName);
                            double availableResource      = res.amount;
                            double addable = UtilMath.Min(availableSpace, availableResource);
                            toAdd += addable;

                            Utils.Log($"Removed {addable} {resourceName} from {sPart.partName} ({availableResource} units in part, {availableSpace} space in target)");

                            availableSpace = UtilMath.Clamp(availableSpace - addable, 0, availableSpace);
                            res.amount     = UtilMath.Clamp(res.amount - addable, 0d, res.maxAmount);
                        }
                    }
                }
            }
            ScreenMessages.PostScreenMessage(new ScreenMessage(Localizer.Format("#LOC_SystemHeat_ModuleSystemHeatFissionFuelContainer_Message_Stored",
                                                                                toAdd.ToString("F2"),
                                                                                resourceName,
                                                                                part.partInfo.title
                                                                                ), 5.0f, ScreenMessageStyle.UPPER_CENTER));;
            Utils.Log($"Added {toAdd} {resourceName} to {part.partInfo.title}");
            part.RequestResource(resourceName, -toAdd, ResourceFlowMode.NO_FLOW);
        }
        protected double GetResourceEVAAmount(string resourceName)
        {
            double amt = 0d;

            if (FlightGlobals.ActiveVessel.evaController != null)
            {
                for (int i = 0; i < FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.InventorySlots; i++)
                {
                    if (!FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.IsSlotEmpty(i))
                    {
                        StoredPart sPart = FlightGlobals.ActiveVessel.evaController.ModuleInventoryPartReference.storedParts[i];
                        if (sPart.partName == RefuelCargoPartName)
                        {
                            ProtoPartResourceSnapshot res = sPart.snapshot.resources.Find(x => x.resourceName == resourceName);
                            amt += res.amount;
                        }
                    }
                }
            }
            return(amt);
        }
Exemplo n.º 3
0
        private static void AddPartToInventory(string partName, ModuleInventoryPart inv)
        {
            AvailablePart ap      = PartLoader.getPartInfoByName(partName);
            var           pp      = new ProtoPartSnapshot(ap.partPrefab, null);
            int           slotIdx = inv.FirstEmptySlot();

            if (slotIdx < 0)
            {
                KCTDebug.LogError($"Part {inv.part.name} does not have inventory space to add {partName}");
                return;
            }

            StoredPart storedPart = new StoredPart(partName, slotIdx)
            {
                snapshot      = pp,
                variantName   = pp.moduleVariantName,
                quantity      = 1,
                stackCapacity = pp.moduleCargoStackableQuantity
            };

            inv.storedParts.Add(storedPart.slotIndex, storedPart);
        }