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); }
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); }
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); }