Esempio n. 1
0
        private void MoveDrop(Part tgtPart, Vector3 pos, Quaternion rot)
        {
            KIS_Shared.DebugLog("Move part");
            ModuleKISPickup modulePickup = GetActivePickupNearest(pos);

            if (modulePickup)
            {
                if (movingPart.parent)
                {
                    bool movingPartMounted   = false;
                    ModuleKISPartMount partM = movingPart.parent.GetComponent <ModuleKISPartMount>();
                    if (partM)
                    {
                        if (partM.PartIsMounted(movingPart))
                        {
                            movingPartMounted = true;
                        }
                    }
                    if (!movingPartMounted)
                    {
                        AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(modulePickup.detachPartSndPath), movingPart.transform.position);
                    }
                }
                AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(modulePickup.dropSndPath), pos);
            }
            KIS_Shared.DecoupleFromAll(movingPart);
            movingPart.transform.position = pos;
            movingPart.transform.rotation = rot;
            KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.DropEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart);
            KISAddonPointer.StopPointer();
            movingPart = null;
        }
Esempio n. 2
0
 public void Unequip()
 {
     if (!prefabModule)
     {
         return;
     }
     if (equipMode == EquipMode.Model)
     {
         UnityEngine.Object.Destroy(equippedGameObj);
         if (prefabModule.equipRemoveHelmet)
         {
             inventory.SetHelmet(true);
         }
     }
     if (equipMode == EquipMode.Part || equipMode == EquipMode.Physic)
     {
         KIS_Shared.DebugLog("Update config node of equipped part : " + this.availablePart.title);
         partNode.ClearData();
         KIS_Shared.PartSnapshot(equippedPart).CopyTo(partNode);
         equippedPart.Die();
     }
     evaTransform    = null;
     equippedPart    = null;
     equippedGameObj = null;
     equipped        = false;
     PlaySound(prefabModule.moveSndPath);
     prefabModule.OnUnEquip(this);
 }
Esempio n. 3
0
 public static void StopPointer()
 {
     KIS_Shared.DebugLog("StopPointer(pointer)");
     running = false;
     ResetMouseOver();
     InputLockManager.RemoveControlLock("KISpointer");
 }
Esempio n. 4
0
        private void MoveAttach(Part tgtPart, Vector3 pos, Quaternion rot, string srcAttachNodeID = null, AttachNode tgtAttachNode = null)
        {
            KIS_Shared.DebugLog("Move part & attach");
            KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.AttachStart, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode);
            KIS_Shared.DecoupleFromAll(movingPart);
            movingPart.transform.position = pos;
            movingPart.transform.rotation = rot;

            ModuleKISItem moduleItem            = movingPart.GetComponent <ModuleKISItem>();
            bool          useExternalPartAttach = false;

            if (moduleItem)
            {
                if (moduleItem.useExternalPartAttach)
                {
                    useExternalPartAttach = true;
                }
            }
            if (tgtPart && !useExternalPartAttach)
            {
                KIS_Shared.CouplePart(movingPart, tgtPart, srcAttachNodeID, tgtAttachNode);
            }
            KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.AttachEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode);
            KISAddonPointer.StopPointer();
            movingPart  = null;
            draggedItem = null;
            draggedPart = null;
        }
Esempio n. 5
0
        private Part CreateAttach(Part tgtPart, Vector3 pos, Quaternion rot, string srcAttachNodeID = null, AttachNode tgtAttachNode = null)
        {
            KIS_Shared.DebugLog("Create part & attach");
            Part newPart;

            draggedItem.StackRemove(1);
            bool useExternalPartAttach = false;

            if (draggedItem.prefabModule)
            {
                if (draggedItem.prefabModule.useExternalPartAttach)
                {
                    useExternalPartAttach = true;
                }
            }
            if (tgtPart && !useExternalPartAttach)
            {
                newPart = KIS_Shared.CreatePart(draggedItem.partNode, pos, rot, draggedItem.inventory.part, tgtPart, srcAttachNodeID, tgtAttachNode, OnPartCoupled);
            }
            else
            {
                newPart = KIS_Shared.CreatePart(draggedItem.partNode, pos, rot, draggedItem.inventory.part);
                KIS_Shared.SendKISMessage(newPart, KIS_Shared.MessageAction.AttachEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode);
            }
            KISAddonPointer.StopPointer();
            movingPart  = null;
            draggedItem = null;
            draggedPart = null;
            return(newPart);
        }
Esempio n. 6
0
 private void UpdateKey()
 {
     if (isRunning)
     {
         if (
             Input.GetKeyDown(KeyCode.Escape) ||
             Input.GetKeyDown(KeyCode.Return)
             )
         {
             KIS_Shared.DebugLog("Cancel key pressed, stop eva attach mode");
             StopPointer();
             SendPointerClick(PointerTarget.Nothing, Vector3.zero, Quaternion.identity, null, null);
         }
         if (GameSettings.Editor_toggleSymMethod.GetKeyDown())
         {
             if (pointerTarget != PointerTarget.PartMount)
             {
                 if (pointer)
                 {
                     UnityEngine.Object.Destroy(pointer);
                 }
                 attachNodeIndex++;
                 if (attachNodeIndex > (attachNodes.Count - 1))
                 {
                     attachNodeIndex = 0;
                 }
                 ResetMouseOver();
                 SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null);
             }
         }
     }
 }
Esempio n. 7
0
        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;
            }
        }
Esempio n. 8
0
 public virtual void OnPartUnpack()
 {
     if (allowStaticAttach == 0)
     {
         return;
     }
     if (useExternalStaticAttach)
     {
         return;
     }
     if (staticAttached)
     {
         KIS_Shared.DebugLog("Re-attach static object (OnPartUnpack)");
         GroundAttach();
     }
 }
Esempio n. 9
0
 public static void StartPointer(Part partToMoveAndAttach, OnPointerClick pClick, OnPointerState pState, Transform from = null)
 {
     if (!running)
     {
         KIS_Shared.DebugLog("StartPointer(pointer)");
         customRot        = Vector3.zero;
         aboveDistance    = 0;
         partToAttach     = partToMoveAndAttach;
         sourceTransform  = from;
         running          = true;
         SendPointerClick = pClick;
         SendPointerState = pState;
         // Set possible attach nodes
         attachNodes.Clear();
         if (partToAttach.attachRules.srfAttach)
         {
             KIS_Shared.DebugLog("Surface node set to default");
             attachNodes.Add(partToMoveAndAttach.srfAttachNode);
         }
         else if (partToAttach.attachNodes.Count == 0)
         {
             KIS_Shared.DebugLog("No attach nodes found, surface node set to default");
             attachNodes.Add(partToMoveAndAttach.srfAttachNode);
         }
         else if (partToAttach.findAttachNode("bottom") != null)
         {
             KIS_Shared.DebugLog("Bottom node set to default");
             attachNodes.Add(partToAttach.findAttachNode("bottom"));
         }
         else
         {
             KIS_Shared.DebugLog(partToAttach.attachNodes[0].id + " node set to default");
             attachNodes.Add(partToAttach.attachNodes[0]);
         }
         foreach (AttachNode an in partToMoveAndAttach.attachNodes)
         {
             if (!attachNodes.Contains(an))
             {
                 attachNodes.Add(an);
                 KIS_Shared.DebugLog("Node : " + an.id + " added");
             }
         }
         attachNodeIndex = 0;
         InputLockManager.SetControlLock(ControlTypes.ALLBUTCAMERAS, "KISpointer");
     }
 }
Esempio n. 10
0
        private Part CreateDrop(Part tgtPart, Vector3 pos, Quaternion rot)
        {
            KIS_Shared.DebugLog("Create & drop part");
            ModuleKISPickup modulePickup = GetActivePickupNearest(pos);

            draggedItem.StackRemove(1);
            Part newPart = KIS_Shared.CreatePart(draggedItem.partNode, pos, rot, draggedItem.inventory.part);

            KIS_Shared.SendKISMessage(newPart, KIS_Shared.MessageAction.DropEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart);
            KISAddonPointer.StopPointer();
            draggedItem = null;
            draggedPart = null;
            if (modulePickup)
            {
                AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(modulePickup.dropSndPath), pos);
            }
            return(newPart);
        }
Esempio n. 11
0
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            if (useFrom != KIS_Item.UseFrom.KeyUp)
            {
                item.StackRemove();
                eatCount++;

                if (eatCount > 3)
                {
                    KIS_Shared.DebugLog("Burp incoming...");
                    System.Random rnd   = new System.Random();
                    int           delay = rnd.Next(1, 5);
                    item.inventory.DelayedAction(Burp, item, delay);
                    eatCount = 0;
                }
                item.inventory.PlaySound(eatSndPath, false, false);
            }
        }
Esempio n. 12
0
 public void OnSave(ConfigNode node)
 {
     node.AddValue("partName", this.availablePart.name);
     node.AddValue("slot", slot);
     node.AddValue("quantity", quantity);
     node.AddValue("equipped", equipped);
     node.AddValue("resourceMass", resourceMass);
     node.AddValue("contentMass", contentMass);
     node.AddValue("contentCost", contentCost);
     if (inventoryName != "")
     {
         node.AddValue("inventoryName", inventoryName);
     }
     if (equipped && (equipMode == EquipMode.Part || equipMode == EquipMode.Physic))
     {
         KIS_Shared.DebugLog("Update config node of equipped part : " + this.availablePart.title);
         partNode.ClearData();
         KIS_Shared.PartSnapshot(equippedPart).CopyTo(partNode);
     }
     partNode.CopyTo(node.AddNode("PART"));
 }
Esempio n. 13
0
 private void Pickup()
 {
     icon = new KIS_IconViewer(draggedPart, draggedIconResolution);
     KISAddonCursor.StartPartDetection();
     grabActive = false;
     KISAddonCursor.CursorDisable();
     if (HighLogic.LoadedSceneIsFlight)
     {
         InputLockManager.SetControlLock(ControlTypes.VESSEL_SWITCHING, "KISpickup");
         // Disable jetpack mouse control (workaround as SetControlLock didn't have any effect on this)
         KerbalEVA Keva = FlightGlobals.ActiveVessel.rootPart.GetComponent <KerbalEVA>();
         if (Keva)
         {
             if (Keva.JetpackDeployed)
             {
                 Keva.JetpackDeployed = false;
                 jetpackLock          = true;
                 KIS_Shared.DebugLog("Jetpack mouse input disabled");
             }
         }
     }
 }
Esempio n. 14
0
        public void Drop(Part fromPart = null)
        {
            KIS_Shared.DebugLog("Drop item");
            if (fromPart == null)
            {
                fromPart = inventory.part;
            }
            Quaternion rot;
            Vector3    pos;

            if (prefabModule)
            {
                rot = evaTransform.rotation * Quaternion.Euler(prefabModule.equipDir);
                pos = evaTransform.TransformPoint(prefabModule.equipPos);
            }
            else
            {
                rot = inventory.part.transform.rotation;
                pos = inventory.part.transform.position + new Vector3(0, 1, 0);
            }
            KIS_Shared.CreatePart(partNode, pos, rot, fromPart);
            StackRemove(1);
        }
Esempio n. 15
0
 public void GroundDetach()
 {
     if (staticAttached)
     {
         KIS_Shared.DebugLog("Removing static rigidbody and fixed joint on " + this.part.partInfo.title);
         if (fixedJoint)
         {
             Destroy(fixedJoint);
         }
         if (connectedGameObject)
         {
             Destroy(connectedGameObject);
         }
         fixedJoint          = null;
         connectedGameObject = null;
         staticAttached      = false;
         ModuleKISPickup modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position);
         if (modulePickup)
         {
             KIS_Shared.PlaySoundAtPoint(modulePickup.detachStaticSndPath, this.transform.position);
         }
     }
 }
Esempio n. 16
0
        public static void CouplePart(Part srcPart, Part tgtPart, string srcAttachNodeID = null, AttachNode tgtAttachNode = null)
        {
            // Node links
            if (srcAttachNodeID != null)
            {
                if (srcAttachNodeID == "srfAttach")
                {
                    KIS_Shared.DebugLog("Attach type : " + srcPart.srfAttachNode.nodeType + " | ID : " + srcPart.srfAttachNode.id);
                    srcPart.attachMode = AttachModes.SRF_ATTACH;
                    srcPart.srfAttachNode.attachedPart = tgtPart;
                }
                else
                {
                    AttachNode srcAttachNode = srcPart.findAttachNode(srcAttachNodeID);
                    if (srcAttachNode != null)
                    {
                        KIS_Shared.DebugLog("Attach type : " + srcPart.srfAttachNode.nodeType + " | ID : " + srcAttachNode.id);
                        srcPart.attachMode         = AttachModes.STACK;
                        srcAttachNode.attachedPart = tgtPart;
                        if (tgtAttachNode != null)
                        {
                            tgtAttachNode.attachedPart = srcPart;
                        }
                    }
                    else
                    {
                        KIS_Shared.DebugError("Source attach node not found !");
                    }
                }
            }
            else
            {
                KIS_Shared.DebugWarning("Missing source attach node !");
            }

            srcPart.Couple(tgtPart);
        }
Esempio n. 17
0
        public void GroundAttach()
        {
            KIS_Shared.DebugLog("Create kinematic rigidbody");
            if (connectedGameObject)
            {
                Destroy(connectedGameObject);
            }
            GameObject obj = new GameObject("KISBody");

            obj.AddComponent <Rigidbody>();
            obj.rigidbody.mass        = 100;
            obj.rigidbody.isKinematic = true;
            obj.transform.position    = this.part.transform.position;
            obj.transform.rotation    = this.part.transform.rotation;
            connectedGameObject       = obj;

            KIS_Shared.DebugLog("Create fixed joint on the kinematic rigidbody");
            if (fixedJoint)
            {
                Destroy(fixedJoint);
            }
            FixedJoint CurJoint = this.part.gameObject.AddComponent <FixedJoint>();

            CurJoint.breakForce     = staticAttachBreakForce;
            CurJoint.breakTorque    = staticAttachBreakForce;
            CurJoint.connectedBody  = obj.rigidbody;
            fixedJoint              = CurJoint;
            this.part.vessel.Landed = true;
            staticAttached          = true;
            ModuleKISPickup modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position);

            if (modulePickup)
            {
                KIS_Shared.PlaySoundAtPoint(modulePickup.attachStaticSndPath, this.transform.position);
            }
        }
Esempio n. 18
0
 void OnDragReleased()
 {
     KISAddonCursor.CursorDefault();
     if (HighLogic.LoadedSceneIsFlight)
     {
         InputLockManager.RemoveControlLock("KISpickup");
         // Re-enable jetpack mouse control (workaround as SetControlLock didn't have any effect on this)
         KerbalEVA Keva = FlightGlobals.ActiveVessel.rootPart.GetComponent <KerbalEVA>();
         if (Keva)
         {
             if (jetpackLock)
             {
                 Keva.JetpackDeployed = true;
                 jetpackLock          = false;
                 KIS_Shared.DebugLog("Jetpack mouse input re-enabled");
             }
         }
     }
     if (hoverInventoryGui())
     {
         // Couroutine to let time to KISModuleInventory to catch the draggedPart
         StartCoroutine(WaitAndStopDrag());
     }
     else
     {
         ModuleKISPartDrag pDrag = null;
         if (KISAddonCursor.hoveredPart)
         {
             if (KISAddonCursor.hoveredPart != draggedPart)
             {
                 pDrag = KISAddonCursor.hoveredPart.GetComponent <ModuleKISPartDrag>();
             }
         }
         if (pDrag)
         {
             if (draggedItem != null)
             {
                 draggedItem.DragToPart(KISAddonCursor.hoveredPart);
                 pDrag.OnItemDragged(draggedItem);
             }
             else
             {
                 pDrag.OnPartDragged(draggedPart);
             }
         }
         else
         {
             if (HighLogic.LoadedSceneIsEditor)
             {
                 if (draggedItem != null)
                 {
                     draggedItem.Delete();
                 }
             }
             if (HighLogic.LoadedSceneIsFlight)
             {
                 if (draggedItem != null)
                 {
                     Drop(draggedItem);
                 }
                 else
                 {
                     movingPart = draggedPart;
                     Drop(movingPart, movingPart);
                 }
             }
         }
         icon        = null;
         draggedPart = null;
     }
     KISAddonCursor.StopPartDetection();
 }
Esempio n. 19
0
        private static IEnumerator WaitAndCouple(Part newPart, Part tgtPart = null, string srcAttachNodeID = null, AttachNode tgtAttachNode = null, OnPartCoupled onPartCoupled = null)
        {
            // Get relative position & rotation
            Vector3    toPartLocalPos = Vector3.zero;
            Quaternion toPartLocalRot = Quaternion.identity;

            if (tgtPart)
            {
                if (tgtAttachNode == null)
                {
                    // Local position & rotation from part
                    toPartLocalPos = tgtPart.transform.InverseTransformPoint(newPart.transform.position);
                    toPartLocalRot = Quaternion.Inverse(tgtPart.transform.rotation) * newPart.transform.rotation;
                }
                else
                {
                    // Local position & rotation from node (KAS winch connector)
                    toPartLocalPos = tgtAttachNode.nodeTransform.InverseTransformPoint(newPart.transform.position);
                    toPartLocalRot = Quaternion.Inverse(tgtAttachNode.nodeTransform.rotation) * newPart.transform.rotation;
                }
            }

            // Wait part to initialize
            while (!newPart.started && newPart.State != PartStates.DEAD)
            {
                KIS_Shared.DebugLog("CreatePart - Waiting initialization of the part...");
                if (tgtPart)
                {
                    // Part stay in position
                    if (tgtAttachNode == null)
                    {
                        newPart.transform.position = tgtPart.transform.TransformPoint(toPartLocalPos);
                        newPart.transform.rotation = tgtPart.transform.rotation * toPartLocalRot;
                    }
                    else
                    {
                        newPart.transform.position = tgtAttachNode.nodeTransform.TransformPoint(toPartLocalPos);
                        newPart.transform.rotation = tgtAttachNode.nodeTransform.rotation * toPartLocalRot;
                    }
                }
                yield return(null);
            }
            // Part stay in position
            if (tgtAttachNode == null)
            {
                newPart.transform.position = tgtPart.transform.TransformPoint(toPartLocalPos);
                newPart.transform.rotation = tgtPart.transform.rotation * toPartLocalRot;
            }
            else
            {
                newPart.transform.position = tgtAttachNode.nodeTransform.TransformPoint(toPartLocalPos);
                newPart.transform.rotation = tgtAttachNode.nodeTransform.rotation * toPartLocalRot;
            }
            KIS_Shared.DebugLog("CreatePart - Coupling part...");
            CouplePart(newPart, tgtPart, srcAttachNodeID, tgtAttachNode);

            if (onPartCoupled != null)
            {
                onPartCoupled(newPart, tgtPart, tgtAttachNode);
            }
        }
Esempio n. 20
0
        public void Equip()
        {
            if (!prefabModule)
            {
                return;
            }
            KIS_Shared.DebugLog("Equip item " + this.availablePart.name);

            //Check skill if needed
            if (prefabModule.equipSkill != null && prefabModule.equipSkill != "")
            {
                bool skillFound = false;
                List <ProtoCrewMember> protoCrewMembers = inventory.vessel.GetVesselCrew();
                foreach (Experience.ExperienceEffect expEffect in protoCrewMembers[0].experienceTrait.Effects)
                {
                    if (expEffect.ToString().Replace("Experience.Effects.", "") == prefabModule.equipSkill)
                    {
                        skillFound = true;
                    }
                }
                if (!skillFound)
                {
                    ScreenMessages.PostScreenMessage("This item can only be used by a kerbal with the skill : " + prefabModule.equipSkill, 5f, ScreenMessageStyle.UPPER_CENTER);
                    PlaySound(KIS_Shared.bipWrongSndPath);
                    return;
                }
            }

            // Check if already carried
            if (equipSlot != null)
            {
                KIS_Item equippedItem = inventory.GetEquipedItem(equipSlot);
                if (equippedItem != null)
                {
                    if (equippedItem.carriable)
                    {
                        ScreenMessages.PostScreenMessage("Cannot equip item, slot <" + equipSlot + "> already used for carrying " + equippedItem.availablePart.title, 5f, ScreenMessageStyle.UPPER_CENTER);
                        PlaySound(KIS_Shared.bipWrongSndPath);
                        return;
                    }
                    equippedItem.Unequip();
                }
            }

            if (equipMode == EquipMode.Model)
            {
                GameObject modelGo = availablePart.partPrefab.FindModelTransform("model").gameObject;
                equippedGameObj = Mesh.Instantiate(modelGo) as GameObject;
                foreach (Collider col in equippedGameObj.GetComponentsInChildren <Collider>())
                {
                    UnityEngine.Object.DestroyImmediate(col);
                }
                evaTransform = null;
                List <SkinnedMeshRenderer> skmrs = new List <SkinnedMeshRenderer>(inventory.part.GetComponentsInChildren <SkinnedMeshRenderer>() as SkinnedMeshRenderer[]);
                foreach (SkinnedMeshRenderer skmr in skmrs)
                {
                    if (skmr.name != prefabModule.equipMeshName)
                    {
                        continue;
                    }
                    foreach (Transform bone in skmr.bones)
                    {
                        if (bone.name != prefabModule.equipBoneName)
                        {
                            continue;
                        }
                        evaTransform = bone.transform;
                        break;
                    }
                }

                if (!evaTransform)
                {
                    KIS_Shared.DebugError("evaTransform not found ! ");
                    UnityEngine.Object.Destroy(equippedGameObj);
                    return;
                }
            }
            if (equipMode == EquipMode.Part || equipMode == EquipMode.Physic)
            {
                evaTransform = null;
                List <SkinnedMeshRenderer> skmrs = new List <SkinnedMeshRenderer>(inventory.part.GetComponentsInChildren <SkinnedMeshRenderer>() as SkinnedMeshRenderer[]);
                foreach (SkinnedMeshRenderer skmr in skmrs)
                {
                    if (skmr.name != prefabModule.equipMeshName)
                    {
                        continue;
                    }
                    foreach (Transform bone in skmr.bones)
                    {
                        if (bone.name != prefabModule.equipBoneName)
                        {
                            continue;
                        }
                        evaTransform = bone.transform;
                        break;
                    }
                }

                if (!evaTransform)
                {
                    KIS_Shared.DebugError("evaTransform not found ! ");
                    return;
                }

                Part alreadyEquippedPart = this.inventory.part.vessel.Parts.Find(p => p.partInfo.name == this.availablePart.name);
                if (alreadyEquippedPart)
                {
                    KIS_Shared.DebugLog("Part : " + this.availablePart.name + " already found on eva");
                    equippedPart = alreadyEquippedPart;
                    OnEquippedPartCoupled(equippedPart);
                }
                else
                {
                    Vector3    equipPos = evaTransform.TransformPoint(prefabModule.equipPos);
                    Quaternion equipRot = evaTransform.rotation * Quaternion.Euler(prefabModule.equipDir);
                    equippedPart = KIS_Shared.CreatePart(partNode, equipPos, equipRot, this.inventory.part, this.inventory.part, null, null, OnEquippedPartCoupled);
                }
                if (equipMode == EquipMode.Part)
                {
                    equippedGameObj = equippedPart.gameObject;
                }
            }

            if (prefabModule.equipRemoveHelmet)
            {
                inventory.SetHelmet(false);
            }
            PlaySound(prefabModule.moveSndPath);
            equipped = true;
            prefabModule.OnEquip(this);
        }
Esempio n. 21
0
        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 !");
                    }
                }
            }
        }