void OnMouseGrabPartClick(Part part) { if (KISAddonPointer.isRunning) { return; } if (hoverInventoryGui()) { return; } if (HighLogic.LoadedSceneIsFlight) { if (grabOk && HasActivePickupInRange(part)) { Pickup(part); } } if (HighLogic.LoadedSceneIsEditor) { if (ModuleKISInventory.GetAllOpenInventories().Count == 0) { return; } Pickup(part); } }
/// <summary>Creates a new part from save.</summary> public KIS_Item(AvailablePart availablePart, ConfigNode itemNode, ModuleKISInventory inventory, float quantity = 1) { // Get part node this.availablePart = availablePart; partNode = new ConfigNode(); itemNode.GetNode("PART").CopyTo(partNode); // init config this.InitConfig(availablePart, inventory, quantity); // Get mass if (itemNode.HasValue("resourceMass")) { resourceMass = float.Parse(itemNode.GetValue("resourceMass")); } else { resourceMass = availablePart.partPrefab.GetResourceMass(); } if (itemNode.HasValue("contentMass")) { contentMass = float.Parse(itemNode.GetValue("contentMass")); } if (itemNode.HasValue("contentCost")) { contentCost = float.Parse(itemNode.GetValue("contentCost")); } if (itemNode.HasValue("inventoryName")) { inventoryName = itemNode.GetValue("inventoryName"); } }
private void unloadCargo() { if (Events ["stopUnloadCargo"].active) { KIS_Item found = findCargo(); if (found == null) { updateMenu(); return; } ModuleKISInventory tgtInventory = findStorageFor(null); if (tgtInventory == null) { Debug.Log("No target Inventory found"); return; } if (!tgtInventory.showGui) { tgtInventory.ShowInventory(); } ModuleKISInventory.MoveItem(found, tgtInventory, tgtInventory.GetFreeSlot()); Invoke("unloadCargo", calculateDelay(found.availablePart, false)); } else { updateMenu(); } }
public void DragToInventory(ModuleKISInventory destInventory, int destSlot) { if (prefabModule) { prefabModule.OnDragToInventory(this, destInventory, destSlot); } }
public static void DecoupleFromAll(Part p) { SendKISMessage(p, MessageAction.Decouple); if (p.parent) { p.decouple(); //name container if needed ModuleKISInventory inv = p.GetComponent <ModuleKISInventory>(); if (inv) { if (inv.invName != "") { p.vessel.vesselName = inv.part.partInfo.title + " | " + inv.invName; } else { p.vessel.vesselName = inv.part.partInfo.title; } } } if (p.children.Count != 0) { DecoupleAllChilds(p); } }
/// <summary>Creates a new item, given a saved state.</summary> /// <remarks> /// It's intentionally private. The items must be restored thru the factory methods. /// </remarks> /// <seealso cref="RestoreItemFromNode"/> KIS_Item(AvailablePart availablePart, ConfigNode itemNode, ModuleKISInventory inventory, int quantity) { this.availablePart = availablePart; this.inventory = inventory; this.quantity = quantity; SetPrefabModule(); this.stackable = CheckItemStackable(availablePart); this.partNode = new ConfigNode(); itemNode.GetNode("PART").CopyTo(partNode); ConfigAccessor.ReadFieldsFromNode( itemNode, GetType(), this, group: StdPersistentGroups.PartPersistant); this.itemVolume = KISAPI.PartUtils.GetPartVolume(availablePart, partNode: partNode); // COMPATIBILITY: Set/restore the dry cost and mass. // TODO(ihsoft): This code is only needed for the pre-1.17 KIS version saves. Drop it one day. if (this.itemDryMass < float.Epsilon || this.itemDryCost < float.Epsilon) { this._itemDryMass = KISAPI.PartUtils.GetPartDryMass(availablePart, partNode: partNode); this._itemDryCost = KISAPI.PartUtils.GetPartDryCost(availablePart, partNode: partNode); DebugEx.Warning("Calculated values for a pre 1.17 version save: dryMass={0}, dryCost={1}", this.itemDryMass, this.itemDryCost); } RecalculateResources(); }
/// <summary>Creates a new part from scene.</summary> /// <remarks> /// It's intentionally private. The items must be created thru the factory methods. /// </remarks> /// <seealso cref="CreateItemFromScenePart"/> KIS_Item(Part part, ModuleKISInventory inventory, int quantity) { this.availablePart = part.partInfo; this.inventory = inventory; this.quantity = quantity; SetPrefabModule(); this.partNode = KISAPI.PartNodeUtils.PartSnapshot(part); this.itemVolume = KISAPI.PartUtils.GetPartVolume(part.partInfo, partNode: partNode); // Don't trust the part's mass. It can be affected by too many factors. this._itemDryMass = part.partInfo.partPrefab.mass + part.GetModuleMass(part.partInfo.partPrefab.mass); this._itemDryCost = part.partInfo.cost + part.GetModuleCosts(part.partInfo.cost); foreach (var resource in part.Resources) { this._resourceMass += (float)resource.amount * resource.info.density; this._resourceCost += (float)resource.amount * resource.info.unitCost; } // Handle the case when the item is a container. var itemInventories = part.Modules.OfType <ModuleKISInventory>(); foreach (var itemInventory in itemInventories) { this._contentMass += itemInventory.contentsMass; this._contentCost += itemInventory.contentsCost; } // Fix dry mass/cost since it's reported by the container modules. this._itemDryMass -= this._contentMass; this._itemDryCost -= this._contentCost; }
private void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; prefabModule = availablePart.partPrefab.GetComponent <ModuleKISItem>(); volume = KIS_Shared.GetPartVolume(availablePart); cost = GetCost(); // Set launchID if (partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (prefabModule) { equipable = prefabModule.equipable; stackable = prefabModule.stackable; equipSlot = prefabModule.equipSlot; usableFromEva = prefabModule.usableFromEva; usableFromContainer = prefabModule.usableFromContainer; usableFromPod = prefabModule.usableFromPod; usableFromEditor = prefabModule.usableFromEditor; carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { Logger.logInfo( "No non-stackable module or a resource found on the part, set the item as stackable"); stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name) || availablePart.name.IndexOf('.') != -1 && KISAddonConfig.stackableList.Contains(availablePart.name.Replace('.', '_'))) { Logger.logInfo("Part name present in settings.cfg (node StackableItemOverride)," + " force item as stackable"); stackable = true; } }
/// <summary> /// Checks if the current equipped equipment is different from the previous equipped equipment. /// Throws an event if equipment changed. /// </summary> /// <param name="inventory">Inventory to compare to the previous inventory.</param> private void CheckEquipmentChange(ModuleKISInventory inventory) { //No inventory. if (inventory == null) { //Only send "Changed" event if something changed. if (previousEquipment != null && EquipmentChanged != null) { EquipmentChanged(this, null); } previousEquipment = null; return; } //No items in inventory. if (inventory.items.Values.Count == 0) { //Only send "Changed" event if something changed. if (previousEquipment != null && EquipmentChanged != null) { EquipmentChanged(this, null); } previousEquipment = null; return; } //Items in inventory. foreach (KIS_Item item in inventory.items.Values) { if (!_equippedTools.Contains(item)) { //Only get equipped items. if (!item.equipped) { continue; } //Add equipped items. _equippedTools.Add(item); } //Remove unequipped items. else if (!item.equipped) { _equippedTools.Remove(item); } } //Only sent a "Changed" event when something changed. if ((previousEquipment == null || !previousEquipment.Equals(_equippedTools)) && EquipmentChanged != null) { EquipmentChanged(this, _equippedTools); //Fire EquipmentChanged event. } previousEquipment = _equippedTools.ToArray(); }
private void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; this.prefabModule = availablePart.partPrefab.GetComponent <ModuleKISItem>(); this.volume = GetVolume(); this.cost = GetCost(); // Set launchID if (this.partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (this.prefabModule) { if (this.prefabModule.volumeOverride > 0) { this.volume = this.prefabModule.volumeOverride; } this.equipable = prefabModule.equipable; this.stackable = prefabModule.stackable; this.equipSlot = prefabModule.equipSlot; this.usableFromEva = prefabModule.usableFromEva; this.usableFromContainer = prefabModule.usableFromContainer; this.usableFromPod = prefabModule.usableFromPod; this.usableFromEditor = prefabModule.usableFromEditor; this.carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { KIS_Shared.DebugLog("No non-stackable module and ressource found on the part, set item as stackable"); this.stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name)) { KIS_Shared.DebugLog("Part name present in settings.cfg (node StackableItemOverride), force item as stackable"); this.stackable = true; } }
/// <summary>Adds the specified items into the inventory.</summary> /// <param name="inventory">An inventory to add items into.</param> /// <param name="itemNames">A list of names of the parts to add.</param> void AddItems(ModuleKISInventory inventory, List<string> itemNames) { foreach (var defItemName in itemNames) { var defPart = PartLoader.getPartInfoByName(defItemName); if (defPart != null) { inventory.AddItem(defPart.partPrefab); } else { Logger.logError("Cannot make item {0} specified as a default for the pod seat", defItemName); } } }
/// <summary> /// Called every 20ms. /// </summary> private void FixedUpdate() { if (FlightGlobals.ActiveVessel == null) { return; } ModuleKISInventory inventory = FlightGlobals.ActiveVessel.GetComponent <ModuleKISInventory>(); CheckEquipmentChange(inventory); }
/// <summary>Presents the span item dialog.</summary> /// <remarks> /// There can be only one dialog active. If a dialog for a different inventory is requested, then /// it substitutes any dialog that was presented before. /// </remarks> /// <param name="inventory">The inventory to bound the dialog to.</param> public static void ShowDialog(ModuleKISInventory inventory) { if (dialog != null) { Destroy(dialog); } dialog = new GameObject("KisDebug-ItemSpawnDialog"); var dlg = dialog.AddComponent <SpawnItemDialog>(); dlg.tgtInventory = inventory; DebugEx.Info("Spawn item dialog created for inventory: {0}", inventory); }
/// <summary>Creates a new part from scene.</summary> /// <remarks> /// It's intentionally private. The items must be created thru the factory methods. /// </remarks> /// <seealso cref="CreateItemFromScenePart"/> KIS_Item(Part part, ModuleKISInventory inventory, int quantity) { this.availablePart = part.partInfo; this.inventory = inventory; this.quantity = quantity; SetPrefabModule(); this.stackable = CheckItemStackable(availablePart); this.partNode = KISAPI.PartNodeUtils.PartSnapshot(part); this.itemVolume = KISAPI.PartUtils.GetPartVolume(part.partInfo, partNode: partNode); CaptureItemStateFromPart(part); }
public void OnMove(ModuleKISInventory srcInventory, ModuleKISInventory destInventory) { if (srcInventory != destInventory && equipped) { Unequip(); } if (prefabModule) { PlaySound(prefabModule.moveSndPath); } else { PlaySound(inventory.defaultMoveSndPath); } }
private ModuleKISInventory findStorageFor(Part p) { ModuleKISInventory found = null; foreach (string node in storageNodes.Split(',')) { AttachNode search_in = part.FindAttachNode(node.Trim()); found = findStorageFor(p, search_in); if (found) { break; } } return(found); /* determine weight for each storageNode */ }
private void SetInventoryConfig(ConfigNode node, ModuleKISInventory moduleInventory) { if (node.HasValue("inventoryKey")) { moduleInventory.evaInventoryKey = node.GetValue("inventoryKey"); } if (node.HasValue("rightHandKey")) { moduleInventory.evaRightHandKey = node.GetValue("rightHandKey"); } if (node.HasValue("helmetKey")) { moduleInventory.evaHelmetKey = node.GetValue("helmetKey"); } if (node.HasValue("slotsX")) { moduleInventory.slotsX = int.Parse(node.GetValue("slotsX")); } if (node.HasValue("slotsY")) { moduleInventory.slotsY = int.Parse(node.GetValue("slotsY")); } if (node.HasValue("slotSize")) { moduleInventory.slotSize = int.Parse(node.GetValue("slotSize")); } if (node.HasValue("itemIconResolution")) { moduleInventory.itemIconResolution = int.Parse(node.GetValue("itemIconResolution")); } if (node.HasValue("selfIconResolution")) { moduleInventory.selfIconResolution = int.Parse(node.GetValue("selfIconResolution")); } if (node.HasValue("maxVolume")) { moduleInventory.maxVolume = float.Parse(node.GetValue("maxVolume")); } if (node.HasValue("openSndPath")) { moduleInventory.openSndPath = node.GetValue("openSndPath"); } if (node.HasValue("closeSndPath")) { moduleInventory.closeSndPath = node.GetValue("closeSndPath"); } }
/// <summary>Creates an item, restored form the save file.</summary> /// <param name="itemNode">The item config node to load the data from.</param> /// <param name="inventory">The owner inventory of the item.</param> /// <returns>The item instance.</returns> public static KIS_Item RestoreItemFromNode(ConfigNode itemNode, ModuleKISInventory inventory) { var qty = ConfigAccessor.GetValueByPath <int>(itemNode, "quantity") ?? 0; var partName = itemNode.GetValue("partName"); AvailablePart avPart = null; if (partName != null) { avPart = PartLoader.getPartInfoByName(partName); } if (qty == 0 || partName == null || avPart == null) { DebugEx.Error("Bad item config:\n{0}", itemNode); throw new ArgumentException("Bad item config node", "itemNode"); } return(new KIS_Item(avPart, itemNode, inventory, qty)); }
/// <summary>Gives a nicer name to a vessel created during KIS deatch operation.</summary> /// <remarks>When a part is pulled out of inventory or assembly deatched from a vessel it gets a /// standard name saying it's now "debris". When using KIS such parts are not actually debris. /// This method renames vessel depening on the case: /// <list type=""> /// <item>Single part vessels are named after the part's title.</item> /// <item>Multiple parts vessels are named after the source vessel name.</item> /// </list> /// Also, vessel's type is reset to <c>VesselType.Unknown</c>.</remarks> /// <param name="part">A part of the vessel to get name and vessel from.</param> public static void RenameAssemblyVessel(Part part) { part.vessel.vesselType = VesselType.Unknown; part.vessel.vesselName = part.partInfo.title; ModuleKISInventory inv = part.GetComponent <ModuleKISInventory>(); if (inv && inv.invName.Length > 0) { // Add inventory name suffix if any. part.vessel.vesselName += string.Format(" ({0})", inv.invName); } // For assemblies add number of parts. if (part.vessel.parts.Count > 1) { part.vessel.vesselName += string.Format(" with {0} parts", part.vessel.parts.Count - 1); } }
/// <summary>Creates a new item, given a saved state.</summary> /// <remarks> /// It's intentionally private. The items must be restored thru the factory methods. /// </remarks> /// <seealso cref="RestoreItemFromNode"/> KIS_Item(AvailablePart availablePart, ConfigNode itemNode, ModuleKISInventory inventory, int quantity) { this.availablePart = availablePart; this.inventory = inventory; this.quantity = quantity; SetPrefabModule(); this.stackable = CheckItemStackable(availablePart); this.partNode = new ConfigNode(); itemNode.GetNode("PART").CopyTo(partNode); ConfigAccessor.ReadFieldsFromNode( itemNode, GetType(), this, group: StdPersistentGroups.PartPersistant); this.itemVolume = KISAPI.PartUtils.GetPartVolume(availablePart, partNode: partNode); // COMPATIBILITY: Set/restore the dry cost and mass. // TODO(ihsoft): This code is only needed for the pre-1.17 KIS version saves. Drop it one day. if (this.itemDryMass < float.Epsilon || this.itemDryCost < float.Epsilon) { this._itemDryMass = KISAPI.PartUtils.GetPartDryMass(availablePart, partNode: partNode); this._itemDryCost = KISAPI.PartUtils.GetPartDryCost(availablePart, partNode: partNode); DebugEx.Warning("Calculated values for a pre 1.17 version save: dryMass={0}, dryCost={1}", this.itemDryMass, this.itemDryCost); } // COMPATIBILITY: Set/restore the resources cost and mass. // TODO(ihsoft): This code is only needed for the pre-1.17 KIS version saves. Drop it one day. var resourceNodes = PartNodeUtils.GetModuleNodes(partNode, "RESOURCE"); if (resourceNodes.Any() && (this.itemResourceMass < float.Epsilon || this.itemResourceCost < float.Epsilon)) { var oldResourceMass = this.itemResourceMass; foreach (var resourceNode in resourceNodes) { var resource = new ProtoPartResourceSnapshot(resourceNode); this._resourceMass += (float)resource.amount * resource.definition.density; this._resourceCost += (float)resource.amount * resource.definition.unitCost; } DebugEx.Warning("Calculated values for a pre 1.17 version save:" + " oldResourceMass={0}, newResourceMass={1}, resourceCost={2}", oldResourceMass, this.itemResourceMass, this.itemResourceCost); } }
public override void OnStart(StartState state) { print("[KBrain] OnStart"); base.OnStart(state); //KIS needs a skin with arms to attach objects to SkinnedMeshRenderer skin = this.part.gameObject.AddComponent <SkinnedMeshRenderer>(); skin.name = "body01"; Transform rightArm = new GameObject().transform; rightArm.position = this.transform.position; rightArm.name = "bn_r_mid_a01"; rightArm.parent = this.transform; Transform leftArm = new GameObject().transform; leftArm.position = this.transform.position; leftArm.name = "bn_l_mid_a01"; leftArm.parent = this.transform; Transform[] bones = new Transform[2]; bones[0] = rightArm; bones[1] = leftArm; skin.bones = bones; //set initial inventory ModuleKISInventory inventory = this.part.Modules.GetModule <ModuleKISInventory>(); inventory.invType = this.originalInventory; inventory.enabled = true; inventory.invName = "Brain's"; inventory.Events["ShowInventory"].active = true; //refresh part menu inventory.Events["ShowInventory"].guiActive = false; inventory.Events["ShowInventory"].guiActive = true; }
/// <summary>Creates a new part from scene.</summary> public KIS_Item(Part part, ModuleKISInventory inventory, float quantity = 1) { // Get part node this.availablePart = PartLoader.getPartInfoByName(part.partInfo.name); this.partNode = new ConfigNode(); KIS_Shared.PartSnapshot(part).CopyTo(this.partNode); // init config this.InitConfig(availablePart, inventory, quantity); // Get mass this.resourceMass = part.GetResourceMass(); ModuleKISInventory itemInventory = part.GetComponent <ModuleKISInventory>(); if (itemInventory) { this.contentMass = itemInventory.GetContentMass(); this.contentCost = itemInventory.GetContentCost(); if (itemInventory.invName != "") { this.inventoryName = itemInventory.invName; } } }
public static bool IsOccupied(ModuleKISInventory inventory) { return (inventory.invType != ModuleKISInventory.InventoryType.Pod || inventory.part.protoModuleCrew.Any(protoCrewMember => protoCrewMember.seatIdx == inventory.podSeat)); }
public virtual void OnDragToInventory(KIS_Item item, ModuleKISInventory destInventory, int destSlot) { }
public void Awake() { // Set inventory module for every eva kerbal KIS_Shared.DebugLog("Set KIS config..."); ConfigNode nodeSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig"); if (nodeSettings == null) { KIS_Shared.DebugError("KIS settings.cfg not found or invalid !"); return; } // Set global settings ConfigNode nodeGlobal = nodeSettings.GetNode("Global"); if (nodeGlobal.HasValue("itemDebug")) { ModuleKISInventory.debugContextMenu = bool.Parse(nodeGlobal.GetValue("itemDebug")); } if (nodeGlobal.HasValue("breathableAtmoPressure")) { breathableAtmoPressure = float.Parse(nodeGlobal.GetValue("breathableAtmoPressure")); } ConfigNode nodeEvaInventory = nodeSettings.GetNode("EvaInventory"); ConfigNode nodeEvaPickup = nodeSettings.GetNode("EvaPickup"); ConfigNode nodeStackable = nodeSettings.GetNode("StackableItemOverride"); ConfigNode nodeStackableModule = nodeSettings.GetNode("StackableModule"); // Set stackable items list stackableList.Clear(); foreach (string partName in nodeStackable.GetValues("partName")) { stackableList.Add(partName); } // Set stackable module list stackableModules.Clear(); foreach (string moduleName in nodeStackableModule.GetValues("moduleName")) { stackableModules.Add(moduleName); } //-------Male Kerbal // Adding module to EVA cause an unknown error but work Part evaPrefab = PartLoader.getPartInfoByName("kerbalEVA").partPrefab; try { evaPrefab.AddModule("ModuleKISInventory"); } catch {} try { evaPrefab.AddModule("ModuleKISPickup"); } catch { } // Set inventory module for eva ModuleKISInventory evaInventory = evaPrefab.GetComponent <ModuleKISInventory>(); if (evaInventory) { if (nodeGlobal.HasValue("kerbalDefaultMass")) { evaInventory.kerbalDefaultMass = float.Parse(nodeGlobal.GetValue("kerbalDefaultMass")); } SetInventoryConfig(nodeEvaInventory, evaInventory); evaInventory.invType = ModuleKISInventory.InventoryType.Eva; KIS_Shared.DebugLog("Eva inventory module loaded successfully"); } // Set pickup module for eva ModuleKISPickup evaPickup = evaPrefab.GetComponent <ModuleKISPickup>(); if (evaPickup) { if (nodeEvaPickup.HasValue("grabKey")) { KISAddonPickup.grabKey = nodeEvaPickup.GetValue("grabKey"); } if (nodeEvaPickup.HasValue("attachKey")) { KISAddonPickup.attachKey = nodeEvaPickup.GetValue("attachKey"); } if (nodeEvaPickup.HasValue("allowPartAttach")) { evaPickup.allowPartAttach = bool.Parse(nodeEvaPickup.GetValue("allowPartAttach")); } if (nodeEvaPickup.HasValue("allowStaticAttach")) { evaPickup.allowStaticAttach = bool.Parse(nodeEvaPickup.GetValue("allowStaticAttach")); } if (nodeEvaPickup.HasValue("allowPartStack")) { evaPickup.allowPartStack = bool.Parse(nodeEvaPickup.GetValue("allowPartStack")); } if (nodeEvaPickup.HasValue("maxDistance")) { evaPickup.maxDistance = float.Parse(nodeEvaPickup.GetValue("maxDistance")); } if (nodeEvaPickup.HasValue("grabMaxMass")) { evaPickup.grabMaxMass = float.Parse(nodeEvaPickup.GetValue("grabMaxMass")); } if (nodeEvaPickup.HasValue("dropSndPath")) { evaPickup.dropSndPath = nodeEvaPickup.GetValue("dropSndPath"); } if (nodeEvaPickup.HasValue("attachPartSndPath")) { evaPickup.attachPartSndPath = nodeEvaPickup.GetValue("attachPartSndPath"); } if (nodeEvaPickup.HasValue("detachPartSndPath")) { evaPickup.detachPartSndPath = nodeEvaPickup.GetValue("detachPartSndPath"); } if (nodeEvaPickup.HasValue("attachStaticSndPath")) { evaPickup.attachStaticSndPath = nodeEvaPickup.GetValue("attachStaticSndPath"); } if (nodeEvaPickup.HasValue("detachStaticSndPath")) { evaPickup.detachStaticSndPath = nodeEvaPickup.GetValue("detachStaticSndPath"); } if (nodeEvaPickup.HasValue("draggedIconResolution")) { KISAddonPickup.draggedIconResolution = int.Parse(nodeEvaPickup.GetValue("draggedIconResolution")); } KIS_Shared.DebugLog("Eva pickup module loaded successfully"); } //-------Female Kerbal // Adding module to EVA cause an unknown error but work Part evaFemalePrefab = PartLoader.getPartInfoByName("kerbalEVAfemale").partPrefab; try { evaFemalePrefab.AddModule("ModuleKISInventory"); } catch { } try { evaFemalePrefab.AddModule("ModuleKISPickup"); } catch { } // Set inventory module for eva ModuleKISInventory evaFemaleInventory = evaFemalePrefab.GetComponent <ModuleKISInventory>(); if (evaFemaleInventory) { if (nodeGlobal.HasValue("kerbalDefaultMass")) { evaFemaleInventory.kerbalDefaultMass = float.Parse(nodeGlobal.GetValue("kerbalDefaultMass")); } SetInventoryConfig(nodeEvaInventory, evaFemaleInventory); evaFemaleInventory.invType = ModuleKISInventory.InventoryType.Eva; KIS_Shared.DebugLog("Eva inventory module loaded successfully"); } // Set pickup module for eva ModuleKISPickup evaFemalePickup = evaFemalePrefab.GetComponent <ModuleKISPickup>(); if (evaFemalePickup) { if (nodeEvaPickup.HasValue("grabKey")) { KISAddonPickup.grabKey = nodeEvaPickup.GetValue("grabKey"); } if (nodeEvaPickup.HasValue("attachKey")) { KISAddonPickup.attachKey = nodeEvaPickup.GetValue("attachKey"); } if (nodeEvaPickup.HasValue("allowPartAttach")) { evaFemalePickup.allowPartAttach = bool.Parse(nodeEvaPickup.GetValue("allowPartAttach")); } if (nodeEvaPickup.HasValue("allowStaticAttach")) { evaFemalePickup.allowStaticAttach = bool.Parse(nodeEvaPickup.GetValue("allowStaticAttach")); } if (nodeEvaPickup.HasValue("allowPartStack")) { evaFemalePickup.allowPartStack = bool.Parse(nodeEvaPickup.GetValue("allowPartStack")); } if (nodeEvaPickup.HasValue("maxDistance")) { evaFemalePickup.maxDistance = float.Parse(nodeEvaPickup.GetValue("maxDistance")); } if (nodeEvaPickup.HasValue("grabMaxMass")) { evaFemalePickup.grabMaxMass = float.Parse(nodeEvaPickup.GetValue("grabMaxMass")); } if (nodeEvaPickup.HasValue("dropSndPath")) { evaFemalePickup.dropSndPath = nodeEvaPickup.GetValue("dropSndPath"); } if (nodeEvaPickup.HasValue("attachPartSndPath")) { evaFemalePickup.attachPartSndPath = nodeEvaPickup.GetValue("attachPartSndPath"); } if (nodeEvaPickup.HasValue("detachPartSndPath")) { evaFemalePickup.detachPartSndPath = nodeEvaPickup.GetValue("detachPartSndPath"); } if (nodeEvaPickup.HasValue("attachStaticSndPath")) { evaFemalePickup.attachStaticSndPath = nodeEvaPickup.GetValue("attachStaticSndPath"); } if (nodeEvaPickup.HasValue("detachStaticSndPath")) { evaFemalePickup.detachStaticSndPath = nodeEvaPickup.GetValue("detachStaticSndPath"); } if (nodeEvaPickup.HasValue("draggedIconResolution")) { KISAddonPickup.draggedIconResolution = int.Parse(nodeEvaPickup.GetValue("draggedIconResolution")); } KIS_Shared.DebugLog("Eva pickup module loaded successfully"); } // Set inventory module for every pod with crew capacity KIS_Shared.DebugLog("Loading pod inventory..."); foreach (AvailablePart avPart in PartLoader.LoadedPartsList) { if (avPart.name == "kerbalEVA") { continue; } if (avPart.name == "kerbalEVA_RD") { continue; } if (avPart.name == "kerbalEVAfemale") { continue; } if (!avPart.partPrefab) { continue; } if (avPart.partPrefab.CrewCapacity < 1) { continue; } KIS_Shared.DebugLog("Found part with CrewCapacity : " + avPart.name); for (int i = 0; i < avPart.partPrefab.CrewCapacity; i++) { try { ModuleKISInventory moduleInventory = avPart.partPrefab.AddModule("ModuleKISInventory") as ModuleKISInventory; SetInventoryConfig(nodeEvaInventory, moduleInventory); moduleInventory.podSeat = i; moduleInventory.invType = ModuleKISInventory.InventoryType.Pod; KIS_Shared.DebugLog("Pod inventory module(s) for seat " + i + " loaded successfully"); } catch { KIS_Shared.DebugWarning("Pod inventory module(s) for seat " + i + " can't be loaded !"); } } } }
/// <summary>Creates an item from a part in the scene.</summary> /// <param name="part">The part to clone. It must be fully initialized.</param> /// <param name="inventory">The owner inventory of the item.</param> /// <param name="quantity">The number of items in the slot.</param> /// <returns>The item instance.</returns> public static KIS_Item CreateItemFromScenePart(Part part, ModuleKISInventory inventory, int quantity = 1) { return(new KIS_Item(part, inventory, quantity)); }
public static bool HasFreeSlot(ModuleKISInventory inventory) { return(!inventory.isFull()); }
public override void OnStart(StartState state) { storage = part.FindModuleImplementing <ModuleKISInventory>(); }
public static bool HasFreeSpace(ModuleKISInventory inventory, WorkshopItem item) { return(inventory.GetContentVolume() + KIS_Shared.GetPartVolume(item.Part) <= inventory.maxVolume); }
public void BrainSwitch() { if (!activated) { //disable all other inventories, eva kerbal should only have one List <ModuleKISInventory> list = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISInventory>(); foreach (ModuleKISInventory inv in list) { inv.Events["ShowInventory"].active = false; } //get a engineer on-board ProtoCrewMember pcm = new ProtoCrewMember(ProtoCrewMember.KerbalType.Unowned); //adding "brain" to module, if one is not there already if (this.part.protoModuleCrew.Count == 0) { //couldn't find a way to set the RepairSkill skill, asking for new kerbals until one has it bool foundRepairSkill = false; int abort = 0; while (!foundRepairSkill) { pcm = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Unowned); pcm.name = "Brain"; //check for skill foreach (var expEffect in pcm.experienceTrait.Effects) { if (expEffect.ToString().ToLower().IndexOf("repairskill") != -1) { foundRepairSkill = true; } } //check so we don't loop indefinately if (abort++ > 128) { this.isActivated = activated; print("[KBrain] Couldn't find a brain with RepairSkill, aborting."); return; } } pcm.rosterStatus = ProtoCrewMember.RosterStatus.Assigned; this.part.AddCrewmemberAt(pcm, 0); } //change to eva if (this.vessel.vesselType != VesselType.EVA) { this.originalType = (int)this.vessel.vesselType; } this.vessel.vesselType = VesselType.EVA; //set inventory to eva ModuleKISInventory inventory = this.part.Modules.GetModule <ModuleKISInventory>(); this.originalInventory = inventory.invType; inventory.invType = ModuleKISInventory.InventoryType.Eva; inventory.enabled = true; inventory.invName = "Brain's"; inventory.Events["ShowInventory"].active = true; print("[KBrain] Vessel Eva: " + this.vessel.isEVA); this.activated = true; } else { //change back from eva if (this.originalType != (int)VesselType.EVA) { this.part.vessel.vesselType = (VesselType)this.originalType; } else { this.part.vessel.vesselType = VesselType.Probe; } //set inventory back to what it was ModuleKISInventory inventory = this.part.Modules.GetModule <ModuleKISInventory>(); inventory.invType = this.originalInventory; inventory.invName = "Brain's"; inventory.Events["ShowInventory"].active = true; //enable all other inventories List <ModuleKISInventory> list = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISInventory>(); foreach (ModuleKISInventory inv in list) { if (inv.part != this.part)//skip the other part inventory { inv.Events["ShowInventory"].active = true; } } this.activated = false; } }