Example #1
0
 public void Drop(Part part, Part fromPart)
 {
     if (!KISAddonPointer.isRunning)
     {
         ModuleKISPickup pickupModule = GetActivePickupNearest(fromPart);
         if (pickupModule)
         {
             KISAddonPointer.allowPart  = KISAddonPointer.allowEva = KISAddonPointer.allowMount = KISAddonPointer.allowStatic = true;
             KISAddonPointer.allowStack = pickupModule.allowPartStack;
             KISAddonPointer.maxDist    = pickupModule.maxDistance;
             if (draggedItem != null)
             {
                 KISAddonPointer.scale = draggedItem.GetScale();
             }
             else
             {
                 KISAddonPointer.scale = 1;
             }
             KISAddonPointer.StartPointer(part, OnPointerAction, OnPointerState, pickupModule.transform);
             pointerMode = PointerMode.Drop;
         }
         else
         {
             KIS_Shared.DebugError("No active pickup nearest !");
         }
     }
     KISAddonCursor.StopPartDetection();
 }
        public Dictionary <AttachNode, List <string> > GetMounts()
        {
            Dictionary <AttachNode, List <string> > mounts = new Dictionary <AttachNode, List <string> >();
            ConfigNode node = KIS_Shared.GetBaseConfigNode(this);

            foreach (ConfigNode mountNode in node.GetNodes("MOUNT"))
            {
                if (mountNode.HasValue("attachNode") && mountNode.HasValue("allowedPartName"))
                {
                    string     attachNodeName = mountNode.GetValue("attachNode");
                    AttachNode an             = this.part.findAttachNode(attachNodeName);
                    if (an == null)
                    {
                        KIS_Shared.DebugError("GetMountNodes - Node : " + attachNodeName + " not found !");
                        continue;
                    }

                    List <string> allowedPartNames = new List <string>();
                    foreach (string partName in mountNode.GetValues("allowedPartName"))
                    {
                        allowedPartNames.Add(partName.Replace('_', '.'));
                    }
                    mounts.Add(an, allowedPartNames);
                }
            }
            return(mounts);
        }
Example #3
0
        void Awake()
        {
            audioBipWrong          = audioGo.AddComponent <AudioSource>();
            audioBipWrong.volume   = GameSettings.UI_VOLUME;
            audioBipWrong.panLevel = 0;  //set as 2D audiosource

            if (GameDatabase.Instance.ExistsAudioClip(KIS_Shared.bipWrongSndPath))
            {
                audioBipWrong.clip = GameDatabase.Instance.GetAudioClip(KIS_Shared.bipWrongSndPath);
            }
            else
            {
                KIS_Shared.DebugError("Awake(AttachPointer) Bip wrong sound not found in the game database !");
            }
        }
Example #4
0
 public static bool createFXSound(Part part, FXGroup group, string sndPath, bool loop, float maxDistance = 30f)
 {
     group.audio              = part.gameObject.AddComponent <AudioSource>();
     group.audio.volume       = GameSettings.SHIP_VOLUME;
     group.audio.rolloffMode  = AudioRolloffMode.Linear;
     group.audio.dopplerLevel = 0f;
     group.audio.panLevel     = 1f;
     group.audio.maxDistance  = maxDistance;
     group.audio.loop         = loop;
     group.audio.playOnAwake  = false;
     if (GameDatabase.Instance.ExistsAudioClip(sndPath))
     {
         group.audio.clip = GameDatabase.Instance.GetAudioClip(sndPath);
         return(true);
     }
     else
     {
         KIS_Shared.DebugError("Sound not found in the game database !");
         ScreenMessages.PostScreenMessage("Sound file : " + sndPath + " as not been found, please check your KAS installation !", 10, ScreenMessageStyle.UPPER_CENTER);
         return(false);
     }
 }
Example #5
0
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            pageList.Clear();
            ConfigNode node = KIS_Shared.GetBaseConfigNode(this);

            foreach (string page in node.GetValues("page"))
            {
                pageList.Add(page);
            }
            if (pageList.Count > 0)
            {
                pageIndex   = 0;
                pageTotal   = pageList.Count;
                pageTexture = GameDatabase.Instance.GetTexture(pageList[0], false);
                showPage    = true;
                item.inventory.PlaySound(bookOpenSndPath, false, true);
            }
            else
            {
                KIS_Shared.DebugError("The book has no pages configured");
            }
        }
Example #6
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);
        }
Example #7
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 !");
                    }
                }
            }
        }
Example #8
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);
        }