Esempio n. 1
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. 2
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. 3
0
        public void Drop(Part fromPart = null)
        {
            Logger.logInfo("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. 4
0
        public void Equip()
        {
            // Only equip EVA kerbals.
            if (!prefabModule || !inventory.vessel.isEVA)
            {
                return;
            }
            Logger.logInfo("Equip item {0}", this.availablePart.name);

            //Check skill if needed
            if (!String.IsNullOrEmpty(prefabModule.equipSkill))
            {
                bool skillFound = false;
                List <ProtoCrewMember> protoCrewMembers = inventory.vessel.GetVesselCrew();
                foreach (var expEffect in protoCrewMembers[0].experienceTrait.Effects)
                {
                    if (expEffect.ToString().Replace("Experience.Effects.", "") == prefabModule.equipSkill)
                    {
                        skillFound = true;
                        break;
                    }
                }
                if (!skillFound)
                {
                    ScreenMessaging.ShowPriorityScreenMessage(
                        "This item can only be used by a kerbal with the skill : {0}",
                        prefabModule.equipSkill);
                    PlaySound(KIS_Shared.bipWrongSndPath);
                    return;
                }
            }

            // Check if already carried
            if (equipSlot != null)
            {
                KIS_Item equippedItem = inventory.GetEquipedItem(equipSlot);
                if (equippedItem != null)
                {
                    if (equippedItem.carriable)
                    {
                        ScreenMessaging.ShowPriorityScreenMessage(
                            "Cannot equip item, slot <{0}> already used for carrying {1}",
                            equipSlot, equippedItem.availablePart.title);
                        PlaySound(KIS_Shared.bipWrongSndPath);
                        return;
                    }
                    equippedItem.Unequip();
                }
            }

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

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

                if (!evaTransform)
                {
                    Logger.logError("evaTransform not found ! ");
                    return;
                }

                Part alreadyEquippedPart =
                    this.inventory.part.vessel.Parts.Find(p => p.partInfo.name == this.availablePart.name);
                if (alreadyEquippedPart)
                {
                    Logger.logInfo("Part: {0} already found on eva", availablePart.name);
                    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. 5
0
        public void Equip(ActorType actorType = ActorType.API)
        {
            // Only equip EVA kerbals.
            if (!prefabModule || inventory.invType != ModuleKISInventory.InventoryType.Eva)
            {
                Debug.LogWarningFormat("Cannot equip item from inventory type: {0}", inventory.invType);
                return;
            }
            if (quantity > 1)
            {
                ScreenMessaging.ShowPriorityScreenMessage(CannotEquipItemStackedMsg);
                UISounds.PlayBipWrong();
                return;
            }
            Debug.LogFormat("Equip item {0} in mode {1}", availablePart.title, equipMode);

            // Check if the skill is needed. Skip the check in the sandbox modes.
            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX &&
                HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX &&
                !String.IsNullOrEmpty(prefabModule.equipSkill))
            {
                bool skillFound = false;
                List <ProtoCrewMember> protoCrewMembers = inventory.vessel.GetVesselCrew();
                foreach (var expEffect in protoCrewMembers[0].experienceTrait.Effects)
                {
                    if (expEffect.ToString().Replace("Experience.Effects.", "") == prefabModule.equipSkill)
                    {
                        skillFound = true;
                        break;
                    }
                }
                if (!skillFound)
                {
                    if (actorType == ActorType.Player)
                    {
                        ScreenMessaging.ShowPriorityScreenMessage(
                            CannotEquipRestrictedToSkillMsg.Format(prefabModule.equipSkill));
                        UISounds.PlayBipWrong();
                    }
                    return;
                }
            }

            // Check if slot is already occupied.
            if (equipSlot != null)
            {
                KIS_Item equippedItem = inventory.GetEquipedItem(equipSlot);
                if (equippedItem != null)
                {
                    if (equippedItem.carriable && actorType == ActorType.Player)
                    {
                        ScreenMessaging.ShowPriorityScreenMessage(
                            CannotEquipAlreadyCarryingMsg.Format(equipSlot, equippedItem.availablePart.title));
                        UISounds.PlayBipWrong();
                        return;
                    }
                    equippedItem.Unequip();
                }
            }

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

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

                if (!evaTransform)
                {
                    Debug.LogError("evaTransform not found ! ");
                    return;
                }

                var alreadyEquippedPart = inventory.part.FindChildPart(availablePart.name);
                if (alreadyEquippedPart)
                {
                    Debug.LogFormat("Part {0} already found on eva, use it as the item", availablePart.name);
                    equippedPart = alreadyEquippedPart;
                    // This magic is copied from the KervalEVA.OnVesselGoOffRails() method.
                    // There must be at least 3 fixed frames delay before updating the colliders.
                    AsyncCall.WaitForPhysics(
                        equippedPart, 3, () => false,
                        failure: () => OnEquippedPartReady(equippedPart));
                    if (equipMode == EquipMode.Part)
                    {
                        // Ensure the part doesn't have rigidbody and is not affected by physics.
                        // The part may not like it.
                        equippedPart.PhysicsSignificance = 1; // Disable physics on the part.
                        UnityEngine.Object.Destroy(equippedPart.rb);
                    }
                }
                else
                {
                    Vector3    equipPos = evaTransform.TransformPoint(prefabModule.equipPos);
                    Quaternion equipRot = evaTransform.rotation * Quaternion.Euler(prefabModule.equipDir);
                    equippedPart = KIS_Shared.CreatePart(
                        partNode, equipPos, equipRot, inventory.part, inventory.part,
                        srcAttachNodeId: "srfAttach",
                        onPartReady: OnEquippedPartReady,
                        createPhysicsless: equipMode != EquipMode.Physic);
                }
                if (equipMode == EquipMode.Part)
                {
                    equippedGameObj = equippedPart.gameObject;
                }
            }

            if (prefabModule.equipRemoveHelmet)
            {
                inventory.SetHelmet(false);
            }
            if (actorType == ActorType.Player)
            {
                UISoundPlayer.instance.Play(prefabModule.moveSndPath);
            }
            equipped = true;
            prefabModule.OnEquip(this);
        }
Esempio n. 6
0
        public void Equip(ActorType actorType = ActorType.API)
        {
            // Only equip EVA kerbals.
            if (!prefabModule || inventory.invType != ModuleKISInventory.InventoryType.Eva)
            {
                DebugEx.Warning("Cannot equip item from inventory type: {0}", inventory.invType);
                return;
            }
            if (quantity > 1)
            {
                ScreenMessaging.ShowPriorityScreenMessage(CannotEquipItemStackedMsg);
                UISounds.PlayBipWrong();
                return;
            }
            DebugEx.Info("Equip item: partName={0}, mode={1}", availablePart.title, equipMode);

            // Check if the skill is needed. Skip the check in the sandbox modes.
            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX &&
                HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX &&
                !String.IsNullOrEmpty(prefabModule.equipSkill))
            {
                bool skillFound = false;
                List <ProtoCrewMember> protoCrewMembers = inventory.vessel.GetVesselCrew();
                foreach (var expEffect in protoCrewMembers[0].experienceTrait.Effects)
                {
                    if (expEffect.ToString().Replace("Experience.Effects.", "") == prefabModule.equipSkill)
                    {
                        skillFound = true;
                        break;
                    }
                }
                if (!skillFound)
                {
                    if (actorType == ActorType.Player)
                    {
                        ScreenMessaging.ShowPriorityScreenMessage(
                            CannotEquipRestrictedToSkillMsg.Format(prefabModule.equipSkill));
                        UISounds.PlayBipWrong();
                    }
                    return;
                }
            }

            // Check if slot is already occupied.
            if (equipSlot != null)
            {
                KIS_Item equippedItem = inventory.GetEquipedItem(equipSlot);
                if (equippedItem != null && equippedItem != this)
                {
                    if (equippedItem.carriable && actorType == ActorType.Player)
                    {
                        ScreenMessaging.ShowPriorityScreenMessage(
                            CannotEquipAlreadyCarryingMsg.Format(equipSlot, equippedItem.availablePart.title));
                        UISounds.PlayBipWrong();
                        return;
                    }
                    equippedItem.Unequip();
                }
            }

            // Find the bone for this item to follow.
            evaTransform =
                KISAddonConfig.FindEquipBone(inventory.part.transform, prefabModule.equipBoneName);
            if (evaTransform == null)
            {
                return; // Cannot equip!
            }
            if (equipMode == EquipMode.Model)
            {
                var modelGo = availablePart.partPrefab.FindModelTransform("model").gameObject;
                equippedGameObj = UnityEngine.Object.Instantiate(modelGo);
                equippedGameObj.transform.parent = inventory.part.transform;
                foreach (Collider col in equippedGameObj.GetComponentsInChildren <Collider>())
                {
                    UnityEngine.Object.DestroyImmediate(col);
                }
            }
            else
            {
                var alreadyEquippedPart = inventory.part.FindChildPart(availablePart.name);
                if (alreadyEquippedPart)
                {
                    DebugEx.Info("Part {0} already found on eva, use it as the item", availablePart.name);
                    equippedPart = alreadyEquippedPart;
                    // This magic is copied from the KervalEVA.OnVesselGoOffRails() method.
                    // There must be at least 3 fixed frames delay before updating the colliders.
                    AsyncCall.WaitForPhysics(
                        equippedPart, 3, () => false,
                        failure: () => OnEquippedPartReady(equippedPart));
                    if (equipMode == EquipMode.Part)
                    {
                        // Ensure the part doesn't have rigidbody and is not affected by physics.
                        // The part may not like it.
                        equippedPart.PhysicsSignificance = 1; // Disable physics on the part.
                        UnityEngine.Object.Destroy(equippedPart.rb);
                    }
                }
                else
                {
                    Vector3    equipPos = evaTransform.TransformPoint(prefabModule.equipPos);
                    Quaternion equipRot = evaTransform.rotation * Quaternion.Euler(prefabModule.equipDir);
                    equippedPart = KIS_Shared.CreatePart(
                        partNode, equipPos, equipRot, inventory.part,
                        coupleToPart: inventory.part,
                        srcAttachNodeId: "srfAttach",
                        onPartReady: OnEquippedPartReady,
                        createPhysicsless: equipMode != EquipMode.Physic);
                }
                if (equipMode == EquipMode.Part)
                {
                    equippedGameObj = equippedPart.gameObject;
                }
            }

            // Hide the stock meshes if the custom helmet is equipped.
            if (equipSlot == HelmetSlotName)
            {
                var kerbalModule = inventory.part.FindModuleImplementing <KerbalEVA>();
                if (kerbalModule.helmetTransform != null)
                {
                    for (var i = 0; i < kerbalModule.helmetTransform.childCount; i++)
                    {
                        kerbalModule.helmetTransform.GetChild(i).gameObject.SetActive(false);
                    }
                    if (equippedGameObj != null)
                    {
                        equippedGameObj.transform.parent = kerbalModule.helmetTransform;
                    }
                }
                else
                {
                    DebugEx.Warning("Kerbal model doesn't have helmet transform: {0}", inventory);
                }
            }

            if (actorType == ActorType.Player)
            {
                UISoundPlayer.instance.Play(prefabModule.moveSndPath);
            }
            equipped = true;
            prefabModule.OnEquip(this);
            inventory.StartCoroutine(AlignEquippedPart());
        }
Esempio n. 7
0
        public void Equip(ActorType actorType = ActorType.API)
        {
            // Only equip EVA kerbals.
            if (!prefabModule || inventory.invType != ModuleKISInventory.InventoryType.Eva)
            {
                Debug.LogWarningFormat("Cannot equip item from inventory type: {0}", inventory.invType);
                return;
            }
            if (quantity > 1)
            {
                ScreenMessaging.ShowPriorityScreenMessage("Cannot equip stacked items");
                UISounds.PlayBipWrong();
                return;
            }
            Debug.LogFormat("Equip item {0} in mode {1}", availablePart.title, equipMode);

            // Check skill if needed. Skip the check in sandbox modes.
            if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX &&
                HighLogic.CurrentGame.Mode != Game.Modes.SCIENCE_SANDBOX &&
                !String.IsNullOrEmpty(prefabModule.equipSkill))
            {
                bool skillFound = false;
                List <ProtoCrewMember> protoCrewMembers = inventory.vessel.GetVesselCrew();
                foreach (var expEffect in protoCrewMembers[0].experienceTrait.Effects)
                {
                    if (expEffect.ToString().Replace("Experience.Effects.", "") == prefabModule.equipSkill)
                    {
                        skillFound = true;
                        break;
                    }
                }
                if (!skillFound)
                {
                    if (actorType == ActorType.Player)
                    {
                        ScreenMessaging.ShowPriorityScreenMessage(
                            "This item can only be used by a kerbal with the skill : {0}",
                            prefabModule.equipSkill);
                        UISounds.PlayBipWrong();
                    }
                    return;
                }
            }

            // Check if slot is already occupied.
            if (equipSlot != null)
            {
                KIS_Item equippedItem = inventory.GetEquipedItem(equipSlot);
                if (equippedItem != null)
                {
                    if (equippedItem.carriable && actorType == ActorType.Player)
                    {
                        ScreenMessaging.ShowPriorityScreenMessage(
                            "Cannot equip item, slot <{0}> already used for carrying {1}",
                            equipSlot, equippedItem.availablePart.title);
                        UISounds.PlayBipWrong();
                        return;
                    }
                    equippedItem.Unequip();
                }
            }

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

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

                if (!evaTransform)
                {
                    Debug.LogError("evaTransform not found ! ");
                    return;
                }

                var alreadyEquippedPart = inventory.part.FindChildPart(availablePart.name);
                if (alreadyEquippedPart)
                {
                    Debug.LogFormat("Part {0} already found on eva, use it as the item", availablePart.name);
                    equippedPart = alreadyEquippedPart;
                    OnEquippedPartReady(equippedPart);
                }
                else
                {
                    Vector3    equipPos = evaTransform.TransformPoint(prefabModule.equipPos);
                    Quaternion equipRot = evaTransform.rotation * Quaternion.Euler(prefabModule.equipDir);
                    equippedPart = KIS_Shared.CreatePart(
                        partNode, equipPos, equipRot, inventory.part, inventory.part,
                        srcAttachNodeId: "srfAttach",
                        onPartReady: OnEquippedPartReady,
                        createPhysicsless: equipMode != EquipMode.Physic);
                }
                if (equipMode == EquipMode.Part)
                {
                    equippedGameObj = equippedPart.gameObject;
                }
            }

            if (prefabModule.equipRemoveHelmet)
            {
                inventory.SetHelmet(false);
            }
            if (actorType == ActorType.Player)
            {
                UISoundPlayer.instance.Play(prefabModule.moveSndPath);
            }
            equipped = true;
            prefabModule.OnEquip(this);
        }