Exemple #1
0
        private static void CheckTanksAndLaunch(bool fillTanks)
        {
            foreach (PartCrewAssignment crewedPart in KCTGameStates.LaunchedCrew)
            {
                foreach (CrewMemberAssignment assign in crewedPart.CrewList)
                {
                    ProtoCrewMember pcm = assign?.PCM;
                    if (pcm == null)
                    {
                        continue;
                    }
                    ModuleInventoryPart inv = pcm.KerbalInventoryModule;
                    inv.storedParts.Clear();

                    if (assign.HasJetpack)
                    {
                        AddPartToInventory(JetpackPartName, inv);
                    }
                    if (assign.HasChute)
                    {
                        AddPartToInventory(ChutePartName, inv);
                    }

                    pcm.SaveInventory(pcm.KerbalInventoryModule);
                }
            }

            KCTGameStates.Settings.RandomizeCrew = AssignRandomCrew;
            KCTGameStates.LaunchedVessel.Launch(fillTanks);

            GUIStates.ShowShipRoster       = false;
            _crewListWindowPosition.height = 1;
        }
Exemple #2
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                try
                {
                    rK = "evaRepairKit";                                            // assign repair kit to string

                    foreach (var part in FlightGlobals.ActiveVessel.Parts)          // check all parts for inventory AND command ability
                    {
                        if (part.HasModuleImplementing <ModuleInventoryPart>() && part.HasModuleImplementing <ModuleCommand>())
                        {
                            ModuleInventoryPart mPI = part.GetComponent <ModuleInventoryPart>();
                            int nbOfSlots           = mPI.TotalEmptySlots();                        // number of empty slots

                            if (nbOfSlots != 0)
                            {
                                for (int x = 0; x < nbOfSlots; x++)
                                {
                                    if (mPI.IsSlotEmpty(x))
                                    {
                                        mPI.StoreCargoPartAtSlot(rK, x);                       // add repair kit to first empty slot
                                        mPI.UpdateStackAmountAtSlot(x, 4);                     // make them stack so 4 per slot
                                    }
                                }
                            }
                        }
                    }
                }
                catch { // non-flight scene error
                }
            }
        }
        protected override bool VesselMeetsCondition(Vessel vessel)
        {
            List <Part> parts = vessel.Parts;
            double      count = 0;

            foreach (var part in parts)
            {
                PartModuleList modules = part.Modules;
                foreach (var module in modules)
                {
                    if (module.moduleName == "ModuleInventoryPart")
                    {
                        ModuleInventoryPart inv = (ModuleInventoryPart)module;
                        DictionaryValueList <int, StoredPart> storedParts = inv.storedParts;
                        for (int i = 0; i < storedParts.Count; i++)
                        {
                            if (storedParts[i].partName == partName)
                            {
                                count += storedParts[i].quantity;
                            }
                        }
                    }
                }
            }
            return(count >= partCount);
        }
        protected virtual void setupInventories()
        {
            WBIKISInventoryWrapper inventory;

            //If we're in the editor then hide the seat inventories
            //For inflatable modules that are deflated
            foreach (PartModule partModule in this.part.Modules)
            {
                if (partModule.moduleName == "ModuleKISInventory")
                {
                    inventory = new WBIKISInventoryWrapper(partModule);
                    if (inventory.maxVolume == WBIKISSeatInventoryConfig.maxSeatVolume)
                    {
                        if (isInflatable && isDeployed == false)
                        {
                            partModule.isEnabled = false;
                            partModule.enabled   = false;
                        }

                        else
                        {
                            partModule.isEnabled = true;
                            partModule.enabled   = true;
                        }
                    }
                }
            }
        }
Exemple #5
0
        private void OnModuleInventoryChanged(ModuleInventoryPart moduleInventoryPart)
        {
            if (HighLogic.LoadedScene != GameScenes.FLIGHT)
            {
                return;
            }

            if (moduleInventoryPart != inventory)
            {
                return;
            }

            List <GameObject> equipedHelmets = new List <GameObject>();
            List <GameObject> equipedProps   = new List <GameObject>();


            storedParts       = inventory.storedParts.Values.Where(sp => !props.Keys.Contains(sp.partName)).ToList();
            storedAttachments = inventory.storedParts.Values.Where(sp => props.Keys.Contains(sp.partName)).ToList();

            foreach (var helmetsComponent in helmetsComponents)
            {
                if (storedAttachments.Any(sa => sa.partName == helmetsComponent.Key))
                {
                    helmetsComponent.Value.gameObject.SetActive(true);
                    helmetsComponent.Value.isEquiped = true;
                    equipedHelmets.Add(helmetsComponent.Value.gameObject);
                }
                else
                {
                    helmetsComponent.Value.gameObject.SetActive(false);
                    helmetsComponent.Value.isEquiped = false;
                }
            }

            foreach (var propComponent in propComponents)
            {
                if (storedAttachments.Any(sa => sa.partName == propComponent.Key))
                {
                    if (equipedHelmets.Count != 0 && propComponent.Value.module.propType == PropType.HELMETPROP)
                    {
                        propComponent.Value.gameObject.SetActive(false);
                        propComponent.Value.isEquiped = false;
                    }
                    else
                    {
                        propComponent.Value.gameObject.SetActive(true);
                        propComponent.Value.isEquiped = true;
                        equipedProps.Add(propComponent.Value.gameObject);
                    }
                }
                else
                {
                    propComponent.Value.gameObject.SetActive(false);
                    propComponent.Value.isEquiped = false;
                }

                updatePack = true;
            }
        }
Exemple #6
0
        public void Start()
        {
            kerbal    = part.Modules.GetModule <KerbalEVA>();
            inventory = kerbal.ModuleInventoryPartReference;

            props = PartLoader.LoadedPartsList.Where(p => p.partPrefab.FindModuleImplementing <ModuleWearableProp>())
                    .ToDictionary(x => x.name, x => x.partPrefab.FindModuleImplementing <ModuleWearableProp>());

            InitializeProps();
        }
Exemple #7
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            kerbalEVA = part.FindModuleImplementing <KerbalEVA>();
            if (kerbalEVA == null)
            {
                return;
            }

            // Get original values
            originalSwimSpeed   = kerbalEVA.swimSpeed;
            originalBuoyancy    = part.buoyancy;
            originalMaxPressure = part.maxPressure;

            // Load EVA overrides for carried cargo parts
            if (kerbalEVA.ModuleInventoryPartReference != null && kerbalEVA.ModuleInventoryPartReference.storedParts.Count > 0)
            {
                ModuleInventoryPart inventory = kerbalEVA.ModuleInventoryPartReference;
                int[] keys = inventory.storedParts.Keys.ToArray();

                for (int index = 0; index < keys.Length; index++)
                {
                    updatePartOverrides(inventory.storedParts[keys[index]].partName);
                }
            }

            // Set initial values if needed.
            if (setInitialValues)
            {
                if (swimSpeedMultiplier > 0)
                {
                    kerbalEVA.swimSpeed = originalSwimSpeed * swimSpeedMultiplier;
                }
                if (buoyancyOverride > 0)
                {
                    part.buoyancy = buoyancyOverride;
                }
                if (maxPressureOverride > 0)
                {
                    part.maxPressure = maxPressureOverride;
                }
            }
        }
        private void Initialize()
        {
            if (_isInitialized)
            {
                return;
            }
            _isInitialized = true;

            _moduleInventoryPart = part.FindModuleImplementing <ModuleInventoryPart>();
            if (_moduleInventoryPart == null)
            {
                return;
            }

            _inventorySlots           = _moduleInventoryPart.InventorySlots;
            _moduleInventoryPartField = _moduleInventoryPart.Fields["packedVolumeLimit"];
            if (_moduleInventoryPartField != null)
            {
                _packedVolumeLimit = (float)_moduleInventoryPartField.GetValue(_moduleInventoryPart);
            }
        }
Exemple #9
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);
        }
Exemple #10
0
        private InventoryConstraints GetCapacity(ModuleInventoryPart inv)
        {
            float totVol  = 0f;
            float totMass = 0f;

            for (int z = 0; z < inv.InventorySlots; z++)
            {
                if (!inv.IsSlotEmpty(z))
                {
                    var invPart = GetPartByName(inv.storedParts[z].partName);
                    totVol  += invPart.partPrefab.FindModuleImplementing <ModuleCargoPart>().packedVolume;
                    totMass += invPart.partPrefab.mass;
                    totMass += invPart.partPrefab.resourceMass;
                }
            }

            InventoryConstraints con;

            if (inv.HasPackedVolumeLimit)
            {
                con.VolumeAvailable = inv.packedVolumeLimit - totVol;
            }
            else
            {
                con.VolumeAvailable = 999f;
            }

            if (inv.HasMassLimit)
            {
                con.MassAvailable = inv.massLimit - totMass;
            }
            else
            {
                con.MassAvailable = 999f;
            }

            return(con);
        }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            SetupAnimations();
            setupColliders();
            inventory = part.FindModuleImplementing <ModuleInventoryPart>();
            if (inventory != null)
            {
                packedVolumeLimit = inventory.packedVolumeLimit;
                if (isInflatable && !isDeployed)
                {
                    inventory.packedVolumeLimit = 0;
                }
            }
            //setupInventories();
//            if (isInflatable && isDeployed == false && HighLogic.LoadedSceneIsFlight)
//                this.part.DespawnIVA();

            if (string.IsNullOrEmpty(animationName))
            {
                this.Events["ToggleInflation"].guiActive          = false;
                this.Events["ToggleInflation"].guiActiveEditor    = false;
                this.Events["ToggleInflation"].guiActiveUnfocused = false;
            }

            else if (flightAnimationOnly)
            {
                Events["ToggleInflation"].guiActiveEditor = false;
            }

            //If this is a one-shot then hide the animation button.
            if (isOneShot && isDeployed && HighLogic.LoadedSceneIsEditor == false)
            {
                Events["ToggleInflation"].active = false;
            }
        }
Exemple #12
0
        /// <summary>
        /// Overrides OnStart
        /// </summary>
        /// <param name="state">The StartState.</param>
        public override void OnStart(StartState state)
        {
            base.OnStart(state);
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            kerbalEVA = part.FindModuleImplementing <KerbalEVA>();
            if (kerbalEVA == null)
            {
                return;
            }

            // Get original values
            originalSwimSpeed   = kerbalEVA.swimSpeed;
            originalBuoyancy    = part.buoyancy;
            originalMaxPressure = part.maxPressure;

            // Set buoyancy
            if (vessel.Splashed || vessel.altitude <= 0.0f)
            {
                currentBuoyancy = 0.5f;
                maintainDepth   = true;
            }
            part.buoyancy = currentBuoyancy;

            // Load max pressures for the diving suits
            divingSuitPressures = new Dictionary <string, float>();
            if (!string.IsNullOrEmpty(suitMaxPressures))
            {
                string[] suitPressures   = suitMaxPressures.Split(new char[] { ';' });
                string[] suitPressure    = null;
                char[]   splitChar       = new char[] { ',' };
                float    suitMaxPressure = 400f;

                for (int index = 0; index < suitPressures.Length; index++)
                {
                    suitPressure = suitPressures[index].Split(splitChar);
                    if (suitPressure.Length != 2)
                    {
                        continue;
                    }
                    if (float.TryParse(suitPressure[1], out suitMaxPressure))
                    {
                        divingSuitPressures.Add(suitPressure[0], suitMaxPressure);
                    }
                }
            }

            // Load EVA overrides for carried cargo parts
            if (kerbalEVA.ModuleInventoryPartReference != null && kerbalEVA.ModuleInventoryPartReference.storedParts.Count > 0)
            {
                ModuleInventoryPart inventory = kerbalEVA.ModuleInventoryPartReference;
                int[] keys = inventory.storedParts.Keys.ToArray();

                for (int index = 0; index < keys.Length; index++)
                {
                    updatePartOverrides(inventory.storedParts[keys[index]].partName);
                }
            }

            // Set initial values if needed.
            if (setInitialValues)
            {
                kerbalEVA.swimSpeed = originalSwimSpeed * swimSpeedMultiplier;
                updateMaxPressure();
            }

            // Update UI
            cacheLocalStrings();
            updateUI();
        }
Exemple #13
0
 private void OnModuleSlotChanged(ModuleInventoryPart moduleInventoryPart, int i) => OnModuleInventoryChanged(moduleInventoryPart);
Exemple #14
0
 private void getKerbalModules()
 {
     kerbalEVA = part.FindModuleImplementing <KerbalEVA>();
     inventory = kerbalEVA.ModuleInventoryPartReference;
 }
Exemple #15
0
 private void onModuleInventorySlotChanged(ModuleInventoryPart partInventory, int slotIndex)
 {
     onModuleInventoryChanged(partInventory);
 }
Exemple #16
0
        private void onModuleInventoryChanged(ModuleInventoryPart partInventory)
        {
            if (!HighLogic.LoadedSceneIsFlight || partInventory != inventory)
            {
                return;
            }

            // Hide all wearable props and disable their part modules.
            hideAllProps();

            StoredPart storedPart;

            int[]    storedPartKeys = inventory.storedParts.Keys.ToArray();
            string[] moduleNames;
            List <WBIWearableProp> wearableProps;
            WBIWearableProp        wearableProp;
            int count;

            for (int index = 0; index < storedPartKeys.Length; index++)
            {
                storedPart = inventory.storedParts[storedPartKeys[index]];

                // Enable props
                if (wearablePartProps.ContainsKey(storedPart.partName))
                {
                    wearableProps = wearablePartProps[storedPart.partName];
                    count         = wearableProps.Count;
                    for (int propIndex = 0; propIndex < count; propIndex++)
                    {
                        wearableProp = wearableProps[propIndex];

                        wearableProp.prop.SetActive(true);

                        wearableProp.meshTransform.localEulerAngles = wearableProp.rotationOffset;
                        if (wearableProp.bodyLocation != BodyLocations.backOrJetpack)
                        {
                            wearableProp.meshTransform.localPosition = wearableProp.positionOffset;
                        }
                        else
                        {
                            wearableProp.meshTransform.localPosition = inventory.ContainsPart(kJetpackPartName) ? wearableProp.positionOffsetJetpack : wearableProp.positionOffset;
                        }
                    }
                }

                // Enable the part modules
                if (wearablePartModules.ContainsKey(storedPart.partName))
                {
                    moduleNames = wearablePartModules[storedPart.partName];
                    for (int moduleIndex = 0; moduleIndex < moduleNames.Length; moduleIndex++)
                    {
                        if (part.Modules.Contains(moduleNames[moduleIndex]))
                        {
                            part.Modules[moduleNames[moduleIndex]].moduleIsEnabled = true;
                            part.Modules[moduleNames[moduleIndex]].enabled         = true;
                            part.Modules[moduleNames[moduleIndex]].OnActive();
                        }
                    }
                }
            }
        }