diff --git a/Assets/GothicVR/Resources/Prefabs/UI Element Prefabs/VRPlayer.prefab b/Assets/GothicVR/Resources/Prefabs/UI Element Prefabs/VRPlayer.prefab index 18aa770f0..b2302b62b 100644 --- a/Assets/GothicVR/Resources/Prefabs/UI Element Prefabs/VRPlayer.prefab +++ b/Assets/GothicVR/Resources/Prefabs/UI Element Prefabs/VRPlayer.prefab @@ -128,134 +128,6 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 ---- !u!1 &589842099468929089 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 9113810631379704788} - - component: {fileID: 367388854615376469} - m_Layer: 7 - m_Name: HeroVoice - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &9113810631379704788 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 589842099468929089} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 3286136463054414638} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!82 &367388854615376469 -AudioSource: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 589842099468929089} - m_Enabled: 1 - serializedVersion: 4 - OutputAudioMixerGroup: {fileID: 0} - m_audioClip: {fileID: 0} - m_PlayOnAwake: 1 - m_Volume: 1 - m_Pitch: 1 - Loop: 0 - Mute: 0 - Spatialize: 0 - SpatializePostEffects: 0 - Priority: 128 - DopplerLevel: 1 - MinDistance: 1 - MaxDistance: 500 - Pan2D: 0 - rolloffMode: 0 - BypassEffects: 0 - BypassListenerEffects: 0 - BypassReverbZones: 0 - rolloffCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - panLevelCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - spreadCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 0 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - reverbZoneMixCustomCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 --- !u!1 &2063933424735589160 GameObject: m_ObjectHideFlags: 0 @@ -6188,6 +6060,7 @@ GameObject: - component: {fileID: 3286136461781483593} - component: {fileID: 3490461415993468589} - component: {fileID: 5331787116829108395} + - component: {fileID: 2500770934419847238} m_Layer: 7 m_Name: VRPlayer m_TagString: Player @@ -6299,7 +6172,7 @@ AudioSource: OutputAudioMixerGroup: {fileID: 0} m_audioClip: {fileID: 0} m_PlayOnAwake: 1 - m_Volume: 0.25 + m_Volume: 1 m_Pitch: 1 Loop: 0 Mute: 0 @@ -6343,7 +6216,7 @@ AudioSource: m_Curve: - serializedVersion: 3 time: 0 - value: 1 + value: 0 inSlope: 0 outSlope: 0 tangentMode: 0 @@ -6406,6 +6279,44 @@ CapsuleCollider: m_Height: 2 m_Direction: 1 m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &2500770934419847238 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3286136461781483594} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: da21e4a06ee346319b0a6dc74e0dcc61, type: 3} + m_Name: + m_EditorClassIdentifier: + npcSound: {fileID: 0} + bip01: {fileID: 0} + colliderRootMotion: {fileID: 0} + head: {fileID: 0} + headMorph: {fileID: 0} + mdmName: + baseMdsName: + overlayMdsName: + perceptionTime: 0 + walkMode: 0 + bodyState: 0 + currentInteractable: {fileID: 0} + currentInteractableSlot: {fileID: 0} + currentInteractableStateId: -1 + prevStateStart: 0 + stateStart: 0 + stateLoop: 0 + stateEnd: 0 + isStateTimeActive: 0 + stateTime: 0 + currentLoopState: 0 + hasItemEquipped: 0 + currentItem: 0 + usedItemSlot: + itemAnimationState: -1 + isClonedFromAnother: 0 --- !u!1 &3286136462172449750 GameObject: m_ObjectHideFlags: 0 @@ -8253,8 +8164,7 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 - m_Children: - - {fileID: 9113810631379704788} + m_Children: [] m_Father: {fileID: 3329884094427662597} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!20 &3286136463054414635 diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/Interactable.prefab b/Assets/GothicVR/Resources/Prefabs/Vobs/Vob.prefab similarity index 96% rename from Assets/GothicVR/Resources/Prefabs/Vobs/Interactable.prefab rename to Assets/GothicVR/Resources/Prefabs/Vobs/Vob.prefab index f0939167f..f894812a3 100644 --- a/Assets/GothicVR/Resources/Prefabs/Vobs/Interactable.prefab +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/Vob.prefab @@ -11,7 +11,7 @@ GameObject: - component: {fileID: 2022050282646122291} - component: {fileID: 5252305678164495226} m_Layer: 0 - m_Name: Interactable + m_Name: Vob m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -44,5 +44,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 024fa582612e45c0afcf4ba9d756341e, type: 3} m_Name: m_EditorClassIdentifier: - k__BackingField: k__BackingField: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/Interactable.prefab.meta b/Assets/GothicVR/Resources/Prefabs/Vobs/Vob.prefab.meta similarity index 100% rename from Assets/GothicVR/Resources/Prefabs/Vobs/Interactable.prefab.meta rename to Assets/GothicVR/Resources/Prefabs/Vobs/Vob.prefab.meta diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobContainer.prefab b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobContainer.prefab new file mode 100644 index 000000000..1f432da1f --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobContainer.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6503575194566409312 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2022050282646122291} + - component: {fileID: 6383736313796596418} + m_Layer: 0 + m_Name: oCMobContainer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2022050282646122291 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + serializedVersion: 2 + m_LocalRotation: {x: 0.69465834, y: 0, z: 0, w: 0.71933985} + m_LocalPosition: {x: -328.3223, y: 27.197954, z: -177.9182} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 88, y: 0, z: 0} +--- !u!114 &6383736313796596418 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3647fae04a904a6dbba443f755b63a7d, type: 3} + m_Name: + m_EditorClassIdentifier: + k__BackingField: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobContainer.prefab.meta b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobContainer.prefab.meta new file mode 100644 index 000000000..8c25954b9 --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobContainer.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5b976afb7b07d42428afd6ea3d11447f +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobDoor.prefab b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobDoor.prefab new file mode 100644 index 000000000..19cadc6cd --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobDoor.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6503575194566409312 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2022050282646122291} + - component: {fileID: 2607151182155886275} + m_Layer: 0 + m_Name: oCMobDoor + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2022050282646122291 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + serializedVersion: 2 + m_LocalRotation: {x: 0.69465834, y: 0, z: 0, w: 0.71933985} + m_LocalPosition: {x: -328.3223, y: 27.197954, z: -177.9182} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 88, y: 0, z: 0} +--- !u!114 &2607151182155886275 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: aa8549f9b79448e4b3ebd6901ded3136, type: 3} + m_Name: + m_EditorClassIdentifier: + k__BackingField: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobDoor.prefab.meta b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobDoor.prefab.meta new file mode 100644 index 000000000..d8df9fdda --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobDoor.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e89efd3323eb2c745920b2737e10ae35 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobInter.prefab b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobInter.prefab new file mode 100644 index 000000000..60dfd01e6 --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobInter.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6503575194566409312 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2022050282646122291} + - component: {fileID: 862177027832733350} + m_Layer: 0 + m_Name: oCMobInter + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2022050282646122291 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + serializedVersion: 2 + m_LocalRotation: {x: 0.69465834, y: 0, z: 0, w: 0.71933985} + m_LocalPosition: {x: -328.3223, y: 27.197954, z: -177.9182} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 88, y: 0, z: 0} +--- !u!114 &862177027832733350 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fcee438f16834e5f8768391122403ab5, type: 3} + m_Name: + m_EditorClassIdentifier: + k__BackingField: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobInter.prefab.meta b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobInter.prefab.meta new file mode 100644 index 000000000..5bfe074f0 --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobInter.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5cb5a7a24ef7b8142b2fc8672fa8f1fa +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobMovable.prefab b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobMovable.prefab new file mode 100644 index 000000000..a59adbb7c --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobMovable.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6503575194566409312 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2022050282646122291} + - component: {fileID: 1223192878683548434} + m_Layer: 0 + m_Name: oCMobMovable + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2022050282646122291 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + serializedVersion: 2 + m_LocalRotation: {x: 0.69465834, y: 0, z: 0, w: 0.71933985} + m_LocalPosition: {x: -328.3223, y: 27.197954, z: -177.9182} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 88, y: 0, z: 0} +--- !u!114 &1223192878683548434 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6503575194566409312} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a183092aa29e4a39b4c79965145291c3, type: 3} + m_Name: + m_EditorClassIdentifier: + k__BackingField: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobMovable.prefab.meta b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobMovable.prefab.meta new file mode 100644 index 000000000..31353f5ff --- /dev/null +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/oCMobMovable.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5db7afd48e69a814b8c6bf519cba88e8 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab b/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab index 44e6c92eb..5ef37a6fd 100644 --- a/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab +++ b/Assets/GothicVR/Resources/Prefabs/Vobs/zCVobSpot.prefab @@ -47,12 +47,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 13f4f324c4e84a1b8d8427d29f1d2deb, type: 3} m_Name: m_EditorClassIdentifier: - k__BackingField: k__BackingField: - fp: - Name: - Position: {x: 0, y: 0, z: 0} - IsLocked: 0 --- !u!33 &4250102412515220408 MeshFilter: m_ObjectHideFlags: 0 diff --git a/Assets/GothicVR/Scripts/Caches/PrefabCache.cs b/Assets/GothicVR/Scripts/Caches/PrefabCache.cs index f313159a7..43f9cf54d 100644 --- a/Assets/GothicVR/Scripts/Caches/PrefabCache.cs +++ b/Assets/GothicVR/Scripts/Caches/PrefabCache.cs @@ -13,8 +13,12 @@ public enum PrefabType { Npc, WayPoint, + Vob, VobItem, + VobContainer, + VobDoor, VobInteractable, + VobMovable, VobSpot, VobPfx, VobMusic, @@ -29,8 +33,12 @@ private static string GetPath(PrefabType type) { PrefabType.Npc => "Prefabs/Npc", PrefabType.WayPoint => "Prefabs/WayPoint", + PrefabType.Vob => "Prefabs/Vobs/Vob", PrefabType.VobItem => "Prefabs/Vobs/oCItem", - PrefabType.VobInteractable => "Prefabs/Vobs/Interactable", + PrefabType.VobContainer => "Prefabs/Vobs/oCMobContainer", + PrefabType.VobDoor => "Prefabs/Vobs/oCMobDoor", + PrefabType.VobInteractable => "Prefabs/Vobs/oCMobInter", + PrefabType.VobMovable => "Prefabs/Vobs/oCMobMovable", PrefabType.VobSpot => "Prefabs/Vobs/zCVobSpot", PrefabType.VobPfx => "Prefabs/Vobs/vobPfx", PrefabType.VobMusic => "Prefabs/Vobs/oCZoneMusic", diff --git a/Assets/GothicVR/Scripts/Creator/NpcCreator.cs b/Assets/GothicVR/Scripts/Creator/NpcCreator.cs index 35efee222..39b82cf63 100644 --- a/Assets/GothicVR/Scripts/Creator/NpcCreator.cs +++ b/Assets/GothicVR/Scripts/Creator/NpcCreator.cs @@ -43,7 +43,7 @@ private static NpcProperties GetProperties(NpcInstance npc) private static GameObject GetNpcGo(NpcInstance npcInstance) { - return GetProperties(npcInstance).gameObject; + return GetProperties(npcInstance).go; } /// @@ -222,10 +222,22 @@ public static NpcInstance ExtHlpGetNpc(int instanceId) return properties.npcInstance; } + public static int ExtHlpGetInstanceId(DaedalusInstance instance) + { + if (instance == null) + return -1; + return instance.Index; + } + public static void ExtNpcPerceptionEnable(NpcInstance npc, VmGothicEnums.PerceptionType perception, int function) { var props = GetProperties(npc); props.Perceptions[perception] = function; + } + public static void ExtNpcPerceptionDisable(NpcInstance npc, VmGothicEnums.PerceptionType perception) + { + var props = GetProperties(npc); + props.Perceptions[perception] = -1; } public static void ExtNpcSetPerceptionTime(NpcInstance npc, float time) diff --git a/Assets/GothicVR/Scripts/Creator/Sounds/SoundCreator.cs b/Assets/GothicVR/Scripts/Creator/Sounds/SoundCreator.cs index 7a13ca59c..b5f1be367 100644 --- a/Assets/GothicVR/Scripts/Creator/Sounds/SoundCreator.cs +++ b/Assets/GothicVR/Scripts/Creator/Sounds/SoundCreator.cs @@ -38,9 +38,21 @@ public static SoundData GetSoundArrayFromVfs(string name) public static AudioClip ToAudioClip(SoundData wavFile) { - var audioClip = - AudioClip.Create("Sound", wavFile.sound.Length/wavFile.channels, wavFile.channels, wavFile.sampleRate, false); - audioClip.SetData(wavFile.sound, 0); + AudioClip audioClip; + + try + { + audioClip = + AudioClip.Create("Sound", wavFile.sound.Length / wavFile.channels, wavFile.channels, + wavFile.sampleRate, false); + audioClip.SetData(wavFile.sound, 0); + } + catch (Exception e) + { + Debug.LogError(e); + audioClip = AudioClip.Create("Sound", 1, 1, 44100, false); + audioClip.SetData(new float[] { 0 }, 0); // almost empty audio + } return audioClip; } diff --git a/Assets/GothicVR/Scripts/Creator/VobCreator.cs b/Assets/GothicVR/Scripts/Creator/VobCreator.cs index a3f481e22..323ed72ab 100644 --- a/Assets/GothicVR/Scripts/Creator/VobCreator.cs +++ b/Assets/GothicVR/Scripts/Creator/VobCreator.cs @@ -267,15 +267,21 @@ private static GameObject GetPrefab(IVirtualObject vob) go = PrefabCache.TryGetObject(PrefabCache.PrefabType.VobMusic); break; case VirtualObjectType.oCMOB: + go = PrefabCache.TryGetObject(PrefabCache.PrefabType.Vob); + break; case VirtualObjectType.oCMobFire: case VirtualObjectType.oCMobInter: case VirtualObjectType.oCMobBed: - case VirtualObjectType.oCMobDoor: - case VirtualObjectType.oCMobContainer: - case VirtualObjectType.oCMobSwitch: case VirtualObjectType.oCMobWheel: + case VirtualObjectType.oCMobSwitch: go = PrefabCache.TryGetObject(PrefabCache.PrefabType.VobInteractable); break; + case VirtualObjectType.oCMobDoor: + go = PrefabCache.TryGetObject(PrefabCache.PrefabType.VobDoor); + break; + case VirtualObjectType.oCMobContainer: + go = PrefabCache.TryGetObject(PrefabCache.PrefabType.VobContainer); + break; default: return new GameObject(name); } @@ -350,9 +356,21 @@ public static void CreateItem(int itemId, GameObject go) CreateItemMesh(item, go); } - + + public static void CreateItem(int itemId, string spawnpoint, GameObject go) + { + var item = AssetCache.TryGetItemData(itemId); + + var position = WayNetHelper.GetWayNetPoint(spawnpoint).Position; + + CreateItemMesh(item, go, position); + } + public static void CreateItem(string itemName, GameObject go) { + if (itemName == "") + return; + var item = AssetCache.TryGetItemData(itemName); CreateItemMesh(item, go); @@ -600,10 +618,10 @@ private static GameObject CreateItemMesh(Item vob, ItemInstance item, GameObject return MeshCreatorFacade.CreateVob(item.Visual, mrm, vob.Position.ToUnityVector(), vob.Rotation.ToUnityQuaternion(), true, parentGosNonTeleport[vob.Type], go); } - private static GameObject CreateItemMesh(ItemInstance item, GameObject go) + private static GameObject CreateItemMesh(ItemInstance item, GameObject go, UnityEngine.Vector3 position = default) { var mrm = AssetCache.TryGetMrm(item.Visual); - return MeshCreatorFacade.CreateVob(item.Visual, mrm, default, default, false, parent: go); + return MeshCreatorFacade.CreateVob(item.Visual, mrm, position, default, false, parent: go); } private static GameObject CreateDecal(IVirtualObject vob) diff --git a/Assets/GothicVR/Scripts/Manager/DialogHelper.cs b/Assets/GothicVR/Scripts/Manager/DialogHelper.cs index 713a62cf7..838820c31 100644 --- a/Assets/GothicVR/Scripts/Manager/DialogHelper.cs +++ b/Assets/GothicVR/Scripts/Manager/DialogHelper.cs @@ -28,7 +28,7 @@ public static void StartDialog(NpcProperties properties) // There is at least one important entry, the NPC wants to talk to the hero about. else if (TryGetImportant(properties.Dialogs, out var infoInstance)) { - properties.gameObject.GetComponent().ClearState(true); + properties.go.GetComponent().ClearState(true); GameData.Dialogs.CurrentDialog.Instance = infoInstance; @@ -36,7 +36,7 @@ public static void StartDialog(NpcProperties properties) } else { - properties.gameObject.GetComponent().ClearState(false); + properties.go.GetComponent().ClearState(false); var selectableDialogs = new List(); foreach (var dialog in properties.Dialogs) @@ -76,7 +76,7 @@ public static void ExtAiOutput(NpcInstance self, NpcInstance target, string outp npcProps.AnimationQueue.Enqueue(new Output( new(AnimationAction.Type.AIOutput, int0: speakerId, string0: outputName), - npcProps.gameObject)); + npcProps.go)); } /// @@ -118,7 +118,7 @@ public static void ExtAiStopProcessInfos(NpcInstance npc) props.AnimationQueue.Enqueue(new StopProcessInfos( new(AnimationAction.Type.AIStopProcessInfo), - props.gameObject)); + props.go)); } public static void SelectionClicked(int npcInstanceIndex, int dialogId, bool isMainDialog) @@ -154,12 +154,12 @@ private static void CallInformation(int npcInstanceIndex, int information, bool // We always want to have a method to get the dialog menu back once all dialog lines are talked. npcProperties.AnimationQueue.Enqueue(new StartProcessInfos( new(AnimationAction.Type.UnityStartProcessInfos, int0: information), - npcProperties.gameObject)); + npcProperties.go)); } private static GameObject GetNpc(NpcInstance npc) { - return GetProperties(npc).gameObject; + return GetProperties(npc).go; } private static NpcProperties GetProperties(NpcInstance npc) diff --git a/Assets/GothicVR/Scripts/Manager/GvrBootstrapper.cs b/Assets/GothicVR/Scripts/Manager/GvrBootstrapper.cs index d50403ade..0fc8e67b5 100644 --- a/Assets/GothicVR/Scripts/Manager/GvrBootstrapper.cs +++ b/Assets/GothicVR/Scripts/Manager/GvrBootstrapper.cs @@ -153,10 +153,7 @@ private static void LoadGothicVm(string g1Dir) var fullPath = Path.GetFullPath(Path.Join(g1Dir, "/_work/DATA/scripts/_compiled/GOTHIC.DAT")); GameData.GothicVm = new DaedalusVm(fullPath); - // If we don't set it early, other calls within VM will fail. - // TODO - Could be moved to a separate Hero.cs class and set during GvrEvents.GeneralSceneLoaded event. - var hero = GameData.GothicVm.InitInstance("hero"); - GameData.GothicVm.GlobalHero = hero; + NpcHelper.LoadHero(); VmGothicExternals.RegisterExternals(); } diff --git a/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs b/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs index d37af63a5..4a1e6d613 100644 --- a/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs +++ b/Assets/GothicVR/Scripts/Manager/GvrSceneManager.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using GVR.Caches; using GVR.Creator; using GVR.Debugging; using GVR.Extensions; @@ -27,7 +28,6 @@ public class GvrSceneManager : SingletonBehaviour private bool generalSceneLoaded; private GameObject startPoint; - private GameObject player; private bool debugFreshlyDoneLoading; @@ -244,21 +244,14 @@ public void MoveToWorldScene(GameObject go) SceneManager.MoveGameObjectToScene(go, SceneManager.GetSceneByName(GameData.WorldScene.Value.name)); } - private void SetPlayer() - { - player = generalScene.GetRootGameObjects().FirstOrDefault(go => go.name == "PlayerController").transform.Find("VRPlayer").gameObject; - } public void TeleportPlayerToSpot() { - if (player == null) - SetPlayer(); + if (startPoint == null) + return; - if (startPoint != null) - { - player.transform.position = startPoint.transform.position; - player.transform.rotation = startPoint.transform.rotation; - } + var player = NpcHelper.GetHeroGameObject(); + player.transform.SetPositionAndRotation(startPoint.transform.position, startPoint.transform.rotation); } } } diff --git a/Assets/GothicVR/Scripts/Manager/NpcHelper.cs b/Assets/GothicVR/Scripts/Manager/NpcHelper.cs index 4ba21c4bf..ef9a9da87 100644 --- a/Assets/GothicVR/Scripts/Manager/NpcHelper.cs +++ b/Assets/GothicVR/Scripts/Manager/NpcHelper.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using GVR.Caches; using GVR.Debugging; @@ -11,6 +12,7 @@ using GVR.Properties; using GVR.Vm; using UnityEngine; +using UnityEngine.SceneManagement; using ZenKit.Daedalus; namespace GVR.Manager @@ -30,7 +32,7 @@ public static bool ExtIsMobAvailable(NpcInstance npcInstance, string vobName) public static bool ExtWldIsFPAvailable(NpcInstance npc, string fpNamePart) { var props = GetProperties(npc); - var npcGo = props.gameObject; + var npcGo = props.go; var freePoints = WayNetHelper.FindFreePointsWithName(npcGo.transform.position, fpNamePart, fpLookupDistance); foreach (var fp in freePoints) @@ -70,6 +72,30 @@ public static bool ExtIsNextFpAvailable(NpcInstance npc, string fpNamePart) return true; } + public static int ExtWldGetMobState(NpcInstance npcInstance, string scheme) + { + var npcGo = GetNpc(npcInstance); + + var props = GetProperties(npcInstance); + + VobProperties vob; + + if (props.currentInteractable != null) + vob = props.currentInteractable.GetComponent(); + else + vob = VobHelper.GetFreeInteractableWithin10M(npcGo.transform.position, scheme); + + if (vob == null || vob.visualScheme != scheme) + return -1; + + if (vob is InteractiveProperties interactiveVob) + { + return Math.Max(0, interactiveVob.Properties.State); + } + + return -1; + } + public static ItemInstance ExtGetEquippedArmor(NpcInstance npc) { var armor = GetProperties(npc).EquippedItems @@ -78,6 +104,37 @@ public static ItemInstance ExtGetEquippedArmor(NpcInstance npc) return armor; } + public static bool ExtNpcHasEquippedArmor(NpcInstance npc) + { + return ExtGetEquippedArmor(npc) != null; + } + + public static ItemInstance ExtNpcGetEquippedMeleeWeapon(NpcInstance npc) + { + var meleeWeapon = GetProperties(npc).EquippedItems + .FirstOrDefault(i => i.MainFlag == (int)VmGothicEnums.ItemFlags.ITEM_KAT_NF); + + return meleeWeapon; + } + + public static bool ExtNpcHasEquippedMeleeWeapon(NpcInstance npc) + { + return ExtNpcGetEquippedMeleeWeapon(npc) != null; + } + + public static ItemInstance ExtNpcGetEquippedRangedWeapon(NpcInstance npc) + { + var rangedWeapon = GetProperties(npc).EquippedItems + .FirstOrDefault(i => i.MainFlag == (int)VmGothicEnums.ItemFlags.ITEM_KAT_FF); + + return rangedWeapon; + } + + public static bool ExtNpcHasEquippedRangedWeapon(NpcInstance npc) + { + return ExtNpcGetEquippedRangedWeapon(npc) != null; + } + public static bool ExtIsNpcOnFp(NpcInstance npc, string vobNamePart) { var freePoint = GetProperties(npc).CurrentFreePoint; @@ -88,23 +145,30 @@ public static bool ExtIsNpcOnFp(NpcInstance npc, string vobNamePart) return freePoint.Name.ContainsIgnoreCase(vobNamePart); } - public static bool ExtWldDetectNpcEx(NpcInstance npc, int npcInstance, int aiState, int guild, bool ignorePlayer) + public static bool ExtWldDetectNpcEx(NpcInstance npc, int npcInstanceIndex, int aiState, int guild, + bool ignorePlayer) { var npcGo = GetNpc(npc); var npcPos = npcGo.transform.position; - + // FIXME - currently hard coded with 20m, but needs to be imported from ZenKit: daedalus_classes.h::c_npc::senses and senses_range - float distance = 20f; // 20m - + float sensesRange = npc.SensesRange / 100; // cm -> m + float distance = sensesRange * sensesRange; // 20m + // FIXME - Add Guild check // FIXME - Add Hero check // FIXME - Add AiState check // FIXME - Add NpcCinstance check (only look for specific NPC) - + var foundNpc = LookupCache.NpcCache.Values - .Where(i => Vector3.Distance(i.gameObject.transform.position, npcPos) <= distance) - .Where(i => i.gameObject != npcGo) - .OrderBy(i => Vector3.Distance(i.gameObject.transform.position, npcPos)) + .Where(i => i.go != null) + .Where(i => npcInstanceIndex == -1 || i.npcInstance.Index == npcInstanceIndex) + // .Where(i => !i.IsDead) + // .Where(i => aiState == -1 || i.CurrentAiState == aiState) + // .Where(i => guild == -1 || i.GuildId == guild) + .Where(i => ignorePlayer) + .Where(i => Vector3.Distance(i.go.transform.position, npcPos) <= distance) + .OrderBy(i => Vector3.Distance(i.go.transform.position, npcPos)) .FirstOrDefault(); return (foundNpc != null); @@ -118,9 +182,77 @@ public static int ExtNpcHasItems(NpcInstance npc, uint itemId) return 0; } + public static int ExtNpcGetDistToWp(NpcInstance npc, string waypointName) + { + var npcGo = GetNpc(npc); + var npcPos = npcGo.transform.position; + + var waypoint = WayNetHelper.GetWayNetPoint(waypointName); + + if (waypoint == null || npcGo) + return int.MaxValue; + + return (int)Vector3.Distance(npcPos, waypoint.Position); + } + + public static bool ExtNpcCanSeeNpc(NpcInstance npc, NpcInstance other) + { + var npcGo = GetNpc(npc); + var otherGo = GetNpc(other); + + if (npcGo == null || otherGo == null) + return false; + + var headBone = npcGo.FindChildRecursively("BIP01 HEAD").transform; + + var inSightRange = Vector3.Distance(npcGo.transform.position, otherGo.transform.position) <= + npc.SensesRange; + + Vector3 directionToTarget = (otherGo.transform.position - headBone.position).normalized; + float angleToTarget = Vector3.Angle(headBone.forward, directionToTarget); + + var inFov = angleToTarget <= 50.0f; // OpenGothic assumes 100 fov for NPCs + + var inLineOfSight = Physics.Linecast(headBone.position, directionToTarget); + + return inSightRange && inFov && inLineOfSight; + } + + public static void ExtNpcClearAiQueue(NpcInstance npc) + { + var props = GetProperties(npc); + props.AnimationQueue.Clear(); + } + + public static void ExtNpcClearInventory(NpcInstance npc) + { + var props = GetProperties(npc); + props.Items.Clear(); + } + + public static string ExtNpcGetNextWp(NpcInstance npc) + { + var pos = GetProperties(npc).transform.position; + + return WayNetHelper.FindNearestWayPoint(pos, true).Name; + } + + public static int ExtNpcGetTalentSkill(NpcInstance npc, int skillId) + { + var props = GetProperties(npc); + + // FIXME - this is related to overlays for the npc's + return 0; + } + + public static int ExtNpcGetTalentValue(NpcInstance npc, int skillId) + { + return GetProperties(npc).Talents[(VmGothicEnums.Talent)skillId]; + } + private static GameObject GetNpc(NpcInstance npc) { - return GetProperties(npc).gameObject; + return GetProperties(npc).go; } private static NpcProperties GetProperties(NpcInstance npc) @@ -133,7 +265,7 @@ public static void ExtAiWait(NpcInstance npc, float seconds) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new Wait( new(AnimationAction.Type.AIWait, float0: seconds), - props.gameObject)); + props.go)); } public static void ExtAiUseMob(NpcInstance npc, string target, int state) @@ -141,7 +273,7 @@ public static void ExtAiUseMob(NpcInstance npc, string target, int state) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new UseMob( new(AnimationAction.Type.AIUseMob, string0: target, int0: state), - props.gameObject)); + props.go)); } public static void ExtAiStandUp(NpcInstance npc) @@ -152,7 +284,7 @@ public static void ExtAiStandUp(NpcInstance npc) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new StandUp( new(AnimationAction.Type.AIStandUp), - props.gameObject)); + props.go)); } public static void ExtAiSetWalkMode(NpcInstance npc, VmGothicEnums.WalkMode walkMode) @@ -165,7 +297,7 @@ public static void ExtAiGoToFp(NpcInstance npc, string freePointName) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new GoToFp( new(AnimationAction.Type.AIGoToFP, string0: freePointName), - props.gameObject)); + props.go)); } public static void ExtAiGoToNextFp(NpcInstance npc, string fpNamePart) @@ -173,7 +305,7 @@ public static void ExtAiGoToNextFp(NpcInstance npc, string fpNamePart) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new GoToNextFp( new(AnimationAction.Type.AIGoToNextFp, string0: fpNamePart), - props.gameObject)); + props.go)); } public static void ExtAiGoToWp(NpcInstance npc, string wayPointName) @@ -181,15 +313,18 @@ public static void ExtAiGoToWp(NpcInstance npc, string wayPointName) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new GoToWp( new(AnimationAction.Type.AIGoToWP, string0: wayPointName), - props.gameObject)); + props.go)); } public static void ExtAiGoToNpc(NpcInstance self, NpcInstance other) { + if (other == null) + return; + var props = GetProperties(self); props.AnimationQueue.Enqueue(new GoToNpc( new(AnimationAction.Type.AIGoToNpc, int0: other.Id, int1: other.Index), - props.gameObject)); + props.go)); } public static void ExtAiAlignToFp(NpcInstance npc) @@ -197,7 +332,7 @@ public static void ExtAiAlignToFp(NpcInstance npc) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new AlignToFp( new(AnimationAction.Type.AIAlignToFp), - props.gameObject)); + props.go)); } public static void ExtAiAlignToWp(NpcInstance npc) @@ -205,7 +340,7 @@ public static void ExtAiAlignToWp(NpcInstance npc) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new AlignToWp( new(AnimationAction.Type.AIAlignToWp), - props.gameObject)); + props.go)); } public static void ExtAiPlayAni(NpcInstance npc, string name) @@ -213,7 +348,7 @@ public static void ExtAiPlayAni(NpcInstance npc, string name) var props = GetProperties(npc); props.AnimationQueue.Enqueue(new PlayAni( new(AnimationAction.Type.AIPlayAni, string0: name), - props.gameObject)); + props.go)); } public static void ExtAiStartState(NpcInstance npc, int action, bool stopCurrentState, string wayPointName) @@ -221,7 +356,59 @@ public static void ExtAiStartState(NpcInstance npc, int action, bool stopCurrent var props = GetProperties(npc); props.AnimationQueue.Enqueue(new StartState( new(AnimationAction.Type.AIStartState, int0: action, bool0: stopCurrentState, string0: wayPointName), - props.gameObject)); + props.go)); + } + + public static void ExtAiLookAt(NpcInstance npc, string wayPointName) + { + var props = GetProperties(npc); + props.AnimationQueue.Enqueue(new LookAt( + new(AnimationAction.Type.AILookAt, string0: wayPointName), + props.go)); + } + + public static void ExtAiLookAtNpc(NpcInstance npc, NpcInstance other) + { + if (other == null) + return; + + var props = GetProperties(npc); + props.AnimationQueue.Enqueue(new LookAtNpc( + new(AnimationAction.Type.AILookAtNpc, int0: other.Id, int1: other.Index), + props.go)); + } + + public static void ExtAiContinueRoutine(NpcInstance npc) + { + var props = GetProperties(npc); + props.AnimationQueue.Enqueue(new ContinueRoutine( + new(AnimationAction.Type.AIContinueRoutine), + props.go)); + } + + public static void ExtAiTurnToNpc(NpcInstance npc, NpcInstance other) + { + if (other == null) + return; + + var props = GetProperties(npc); + props.AnimationQueue.Enqueue(new TurnToNpc( + new(AnimationAction.Type.AITurnToNpc, int0: other.Id, int1: other.Index), + props.go)); + } + + public static void ExtAiPlayAniBS(NpcInstance npc, string name, int bodyState) + { + var props = GetProperties(npc); + props.AnimationQueue.Enqueue(new PlayAniBS( + new(AnimationAction.Type.AIPlayAnimBs, string0: name, int0: bodyState), + props.go)); + } + + public static void ExtAiUnequipArmor(NpcInstance npc) + { + var props = GetProperties(npc); + props.BodyData.Armor = 0; } /// @@ -242,7 +429,7 @@ public static void ExtNpcSetStateTime(NpcInstance npc, int seconds) { GetProperties(npc).stateTime = seconds; } - + /// /// State means the final state where the animation shall go to. /// example: @@ -256,7 +443,7 @@ public static void ExtAiUseItemToState(NpcInstance npc, int itemId, int animatio var props = GetProperties(npc); props.AnimationQueue.Enqueue(new UseItemToState( new(AnimationAction.Type.AIUseItemToState, int0: itemId, int1: animationState), - props.gameObject)); + props.go)); } public static bool ExtNpcWasInState(NpcInstance npc, uint action) @@ -269,7 +456,7 @@ public static VmGothicEnums.BodyState ExtGetBodyState(NpcInstance npc) { return GetProperties(npc).bodyState; } - + /// /// Return position distance in cm. /// @@ -278,14 +465,14 @@ public static int ExtNpcGetDistToNpc(NpcInstance npc1, NpcInstance npc2) if (npc1 == null || npc2 == null) return int.MaxValue; - var npc1Pos = LookupCache.NpcCache[npc1.Index].gameObject.transform.position; + var npc1Pos = LookupCache.NpcCache[npc1.Index].go.transform.position; Vector3 npc2Pos; // If hero if (npc2.Id == 0) npc2Pos = Camera.main!.transform.position; else - npc2Pos = LookupCache.NpcCache[npc2.Index].gameObject.transform.position; + npc2Pos = LookupCache.NpcCache[npc2.Index].go.transform.position; return (int)(Vector3.Distance(npc1Pos, npc2Pos) * 100); } @@ -296,7 +483,7 @@ public static void ExtAiDrawWeapon(NpcInstance npc) props.AnimationQueue.Enqueue(new DrawWeapon( new(AnimationAction.Type.AIDrawWeapon), - props.gameObject)); + props.go)); } public static void ExtNpcExchangeRoutine(NpcInstance npcInstance, string routineName) @@ -311,7 +498,7 @@ public static void ExtNpcExchangeRoutine(NpcInstance npcInstance, string routine } var npcGo = LookupCache.NpcCache[npcInstance.Index]; - ExchangeRoutine(npcGo.gameObject, npcInstance, newRoutine.Index); + ExchangeRoutine(npcGo.go, npcInstance, newRoutine.Index); } public static void ExchangeRoutine(GameObject go, NpcInstance npcInstance, int routineIndex) @@ -335,5 +522,24 @@ public static void ExchangeRoutine(GameObject go, NpcInstance npcInstance, int r var startRoutine = routineComp.CurrentRoutine; go.GetComponent().StartRoutine(startRoutine.action, startRoutine.waypoint); } + + public static void LoadHero() + { + var hero = GameData.GothicVm.InitInstance("hero"); + GameData.GothicVm.GlobalHero = hero; + } + + public static GameObject GetHeroGameObject() + { + var heroIndex = GameData.GothicVm.GlobalHero!.Index; + + if (!LookupCache.NpcCache.TryGetValue(heroIndex, out var heroProperties)) + { + LookupCache.NpcCache[heroIndex] = GameObject.FindWithTag(Constants.PlayerTag).GetComponent(); + heroProperties = LookupCache.NpcCache[heroIndex]; + } + + return heroProperties.go; + } } } diff --git a/Assets/GothicVR/Scripts/Manager/VobHelper.cs b/Assets/GothicVR/Scripts/Manager/VobHelper.cs index f216deb9f..a5d9f9721 100644 --- a/Assets/GothicVR/Scripts/Manager/VobHelper.cs +++ b/Assets/GothicVR/Scripts/Manager/VobHelper.cs @@ -1,5 +1,6 @@ using System.Linq; using GVR.Caches; +using GVR.Creator; using GVR.Creator.Sounds; using GVR.Data; using GVR.Extensions; @@ -24,6 +25,13 @@ public static VobProperties GetFreeInteractableWithin10M(Vector3 position, strin .FirstOrDefault(); } + public static void ExtWldInsertItem(int itemInstance, string spawnpoint) + { + if (string.IsNullOrEmpty(spawnpoint) || itemInstance <= 0) + return; + VobCreator.CreateItem(itemInstance, spawnpoint, null); + } + [CanBeNull] public static GameObject GetNearestSlot(GameObject go, Vector3 position) { diff --git a/Assets/GothicVR/Scripts/Manager/WayNetHelper.cs b/Assets/GothicVR/Scripts/Manager/WayNetHelper.cs index ceb239dac..2df92d3ee 100644 --- a/Assets/GothicVR/Scripts/Manager/WayNetHelper.cs +++ b/Assets/GothicVR/Scripts/Manager/WayNetHelper.cs @@ -44,13 +44,14 @@ public static List FindFreePointsWithName(Vector3 lookupPosition, str return matchingFreePoints.ToList(); } - public static WayPoint FindNearestWayPoint(Vector3 lookupPosition) + public static WayPoint FindNearestWayPoint(Vector3 lookupPosition, bool findSecondNearest = false) { - var nearestWayPoint = GameData.WayPoints + var wayPoint = GameData.WayPoints .OrderBy(pair => Vector3.Distance(pair.Value.Position, lookupPosition)) - .First(); + .Skip(findSecondNearest ? 1 : 0) + .FirstOrDefault(); - return nearestWayPoint.Value; + return wayPoint.Value; } [CanBeNull] diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs index e9d54d191..7abdc31bb 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractRotateAnimationAction.cs @@ -1,10 +1,7 @@ using System; -using GVR.Caches; using GVR.Creator; using GVR.Vm; -using GVR.Vob.WayNet; using UnityEngine; -using ZenKit; namespace GVR.Npc.Actions.AnimationActions { diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs index 6a1cb698a..ede56b5f4 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AbstractWalkAnimationAction.cs @@ -1,5 +1,4 @@ using System; -using GVR.Caches; using GVR.Creator; using GVR.Vm; using UnityEngine; diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AiDrawWeapon.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AiDrawWeapon.cs index b826f6b4f..fdc963e0a 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AiDrawWeapon.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AiDrawWeapon.cs @@ -1,4 +1,3 @@ -using GVR.Caches; using GVR.Creator; using GVR.Data.ZkEvents; using GVR.Extensions; diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToFp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToFp.cs index 2b022604a..74117b7d8 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToFp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToFp.cs @@ -1,4 +1,3 @@ -using GVR.Manager; using UnityEngine; namespace GVR.Npc.Actions.AnimationActions diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToWp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToWp.cs index ec3d0f1e5..758485f4c 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToWp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/AlignToWp.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; namespace GVR.Npc.Actions.AnimationActions @@ -9,7 +10,15 @@ public AlignToWp(AnimationAction action, GameObject npcGo) : base(action, npcGo) protected override Vector3 GetRotationDirection() { - return Props.CurrentWayPoint.Direction; + try + { + return Props.CurrentWayPoint.Direction; + } + catch (Exception e) + { + Debug.LogError(e); + return Vector3.zero; + } } } } diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/ContinueRoutine.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/ContinueRoutine.cs new file mode 100644 index 000000000..8e6f2f1ae --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/ContinueRoutine.cs @@ -0,0 +1,25 @@ +using GVR.Npc.Routines; +using UnityEngine; + +namespace GVR.Npc.Actions.AnimationActions +{ + public class ContinueRoutine : AbstractAnimationAction + { + public ContinueRoutine(AnimationAction action, GameObject npcGo) : base(action, npcGo) + { + } + + public override void Start() + { + var ai = Props.GetComponent(); + + ai.ClearState(false); + + var routine = Props.GetComponent().CurrentRoutine; + + ai.StartRoutine(routine.action, routine.waypoint); + + IsFinishedFlag = true; + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/ContinueRoutine.cs.meta b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/ContinueRoutine.cs.meta new file mode 100644 index 000000000..2a9d6f3ce --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/ContinueRoutine.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 930e2b99fa11482e9b2902fe973afe06 +timeCreated: 1706378486 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs index ec7069317..948f0642d 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToFp.cs @@ -1,8 +1,5 @@ -using System.Collections.Generic; -using System.Linq; using GVR.Manager; using GVR.Vob.WayNet; -using GVR.World; using UnityEngine; namespace GVR.Npc.Actions.AnimationActions diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNextFp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNextFp.cs index 437984d95..8999b57db 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNextFp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNextFp.cs @@ -1,6 +1,3 @@ -using System.Linq; -using GVR.Manager; -using GVR.Vob.WayNet; using UnityEngine; namespace GVR.Npc.Actions.AnimationActions diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs index 2d1d1db56..3c768488e 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToNpc.cs @@ -1,4 +1,3 @@ -using System; using GVR.Caches; using UnityEngine; @@ -11,15 +10,12 @@ public class GoToNpc : AbstractWalkAnimationAction private int otherIndex => Action.Int1; public GoToNpc(AnimationAction action, GameObject npcGo) : base(action, npcGo) - { } + { + } public override void Start() { - // Hero - if (otherId == 0) - destinationTransform = Camera.main!.transform; - else - destinationTransform = LookupCache.NpcCache[otherIndex].transform; + destinationTransform = LookupCache.NpcCache[otherIndex].transform; } protected override Vector3 GetWalkDestination() @@ -35,4 +31,4 @@ public override void AnimationEndEventCallback() IsFinishedFlag = false; } } -} +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs index 7c440b9f8..3dcbed9c1 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/GoToWp.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using GVR.Manager; +using GVR.Vob.WayNet; using GVR.World; using UnityEngine; @@ -17,19 +18,23 @@ public GoToWp(AnimationAction action, GameObject npcGo) : base(action, npcGo) public override void Start() { + var currentWaypoint = Props.CurrentWayPoint ?? WayNetHelper.FindNearestWayPoint(Props.transform.position); + var destinationWaypoint = (WayPoint)WayNetHelper.GetWayNetPoint(destination); + /* * 1. AI_StartState() can get called multiple times until it won't share the WP. (e.g. ZS_SLEEP -> ZS_StandAround()) * 2. Happens (e.g.) during spawning. As we spawn NPCs onto their current WayPoints, they don't need to walk there from entrance of OC. */ - if (destination == "" || Props.CurrentWayPoint.Name == destination) + if (destinationWaypoint == null || destinationWaypoint.Name == "" || currentWaypoint.Name == destination) { IsFinishedFlag = true; return; } - route = new Stack(WayNetHelper.FindFastestPath(Props.CurrentWayPoint.Name, destination)); + route = new Stack(WayNetHelper.FindFastestPath(currentWaypoint.Name, + destinationWaypoint.Name)); } - + public override void OnTriggerEnter(Collider coll) { if (walkState != WalkState.Walk) diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAt.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAt.cs new file mode 100644 index 000000000..20b2fbcb2 --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAt.cs @@ -0,0 +1,19 @@ +using GVR.Manager; +using UnityEngine; + +namespace GVR.Npc.Actions.AnimationActions +{ + public class LookAt : AbstractRotateAnimationAction + { + private Transform destinationTransform; + private string waypointName => Action.String0; + + public LookAt(AnimationAction action, GameObject npcGo) : base(action, npcGo) + { } + + protected override Vector3 GetRotationDirection() + { + return WayNetHelper.GetWayNetPoint(waypointName).Direction; + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAt.cs.meta b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAt.cs.meta new file mode 100644 index 000000000..ffd0e9070 --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAt.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 97ed74311d6d4890a13cf7b5df98429a +timeCreated: 1706368440 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAtNpc.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAtNpc.cs new file mode 100644 index 000000000..9114f7291 --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAtNpc.cs @@ -0,0 +1,34 @@ +using GVR.Caches; +using UnityEngine; + +namespace GVR.Npc.Actions.AnimationActions +{ + public class LookAtNpc : AbstractRotateAnimationAction + { + private Transform destinationTransform; + private int otherId => Action.Int0; + private int otherIndex => Action.Int1; + + public LookAtNpc(AnimationAction action, GameObject npcGo) : base(action, npcGo) + { + } + + public override void Start() + { + destinationTransform = LookupCache.NpcCache[otherIndex].transform; + } + + protected override Vector3 GetRotationDirection() + { + return (destinationTransform.position - NpcGo.transform.position).normalized; + } + + + public override void AnimationEndEventCallback() + { + base.AnimationEndEventCallback(); + + IsFinishedFlag = false; + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAtNpc.cs.meta b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAtNpc.cs.meta new file mode 100644 index 000000000..59d81b3bd --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/LookAtNpc.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0f9fb2f3048f454cb942f07b927e68e6 +timeCreated: 1706368460 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/Output.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/Output.cs index e688d6a79..b6b94dfbb 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/Output.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/Output.cs @@ -4,6 +4,7 @@ using GVR.Creator.Sounds; using GVR.Extensions; using GVR.Globals; +using GVR.Manager; using UnityEngine; using Random = UnityEngine.Random; @@ -28,8 +29,7 @@ public override void Start() // If NPC talked before, we stop it immediately (As some audio samples are shorter than the actual animation) AnimationCreator.StopAnimation(NpcGo); - // FIXME - Play sound file on Hero's AudioSource - Use global lookup for Hero's AudioSource component - GameObject.Find("HeroVoice").GetComponent().PlayOneShot(audioClip); + NpcHelper.GetHeroGameObject().GetComponent().PlayOneShot(audioClip); // FIXME - Show subtitles somewhere next to Hero (== ourself/main camera) } // NPC diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAni.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAni.cs index 582b8ab50..f10679467 100644 --- a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAni.cs +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAni.cs @@ -1,4 +1,3 @@ -using GVR.Caches; using GVR.Creator; using UnityEngine; @@ -7,11 +6,12 @@ namespace GVR.Npc.Actions.AnimationActions public class PlayAni : AbstractAnimationAction { public PlayAni(AnimationAction action, GameObject npcGo) : base(action, npcGo) - { } + { + } public override void Start() { AnimationCreator.PlayAnimation(Props.mdsNames, Action.String0, NpcGo); } } -} +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAniBS.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAniBS.cs new file mode 100644 index 000000000..edf7355a8 --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAniBS.cs @@ -0,0 +1,19 @@ +using GVR.Creator; +using GVR.Vm; +using UnityEngine; + +namespace GVR.Npc.Actions.AnimationActions +{ + public class PlayAniBS : AbstractAnimationAction + { + public PlayAniBS(AnimationAction action, GameObject npcGo) : base(action, npcGo) + { + } + + public override void Start() + { + Props.bodyState = (VmGothicEnums.BodyState)Action.Int0; + AnimationCreator.PlayAnimation(Props.mdsNames, Action.String0, NpcGo); + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAniBS.cs.meta b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAniBS.cs.meta new file mode 100644 index 000000000..4a81e1473 --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/PlayAniBS.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 49882c933dc94625a20aeadb25ea3fa0 +timeCreated: 1706449409 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/TurnToNpc.cs b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/TurnToNpc.cs new file mode 100644 index 000000000..4f07ec86b --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/TurnToNpc.cs @@ -0,0 +1,34 @@ +using GVR.Caches; +using UnityEngine; + +namespace GVR.Npc.Actions.AnimationActions +{ + public class TurnToNpc : AbstractRotateAnimationAction + { + private Transform destinationTransform; + private int otherId => Action.Int0; + private int otherIndex => Action.Int1; + + public TurnToNpc(AnimationAction action, GameObject npcGo) : base(action, npcGo) + { + } + + public override void Start() + { + destinationTransform = LookupCache.NpcCache[otherIndex].transform; + } + + protected override Vector3 GetRotationDirection() + { + return (destinationTransform.position - NpcGo.transform.position).normalized; + } + + + public override void AnimationEndEventCallback() + { + base.AnimationEndEventCallback(); + + IsFinishedFlag = false; + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/TurnToNpc.cs.meta b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/TurnToNpc.cs.meta new file mode 100644 index 000000000..5b6877679 --- /dev/null +++ b/Assets/GothicVR/Scripts/Npc/Actions/AnimationActions/TurnToNpc.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 15ba12c38da5456cb3991d977ef9356c +timeCreated: 1706447436 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Npc/AiHandler.cs b/Assets/GothicVR/Scripts/Npc/AiHandler.cs index 0427ad9fe..dd944a1d3 100644 --- a/Assets/GothicVR/Scripts/Npc/AiHandler.cs +++ b/Assets/GothicVR/Scripts/Npc/AiHandler.cs @@ -12,6 +12,7 @@ namespace GVR.Npc public class AiHandler : BasePlayerBehaviour, IAnimationCallbacks { private static DaedalusVm vm => GameData.GothicVm; + private const int DaedalusLoopContinue = 0; private void Start() { @@ -48,18 +49,30 @@ private void Update() case NpcProperties.LoopState.Start: if (properties.stateLoop == 0) return; + vm.Call(properties.stateStart); + properties.currentLoopState = NpcProperties.LoopState.Loop; - vm.Call(properties.stateLoop, properties.npcInstance); break; case NpcProperties.LoopState.Loop: - vm.Call(properties.stateLoop, properties.npcInstance); + // Check return type as not every loop returns int. + if (vm.GetSymbolByIndex(properties.stateLoop)!.ReturnType == DaedalusDataType.Int) + { + var loopResponse = vm.Call(properties.stateLoop); + // Some ZS_*_Loop return !=0 when they want to quit. + if (loopResponse != DaedalusLoopContinue) + properties.currentLoopState = NpcProperties.LoopState.End; + } + else + { + vm.Call(properties.stateLoop); + } break; } } // Go on else { - Debug.Log($"Start playing >{properties.AnimationQueue.Peek().GetType()}< on >{properties.gameObject.name}<"); + Debug.Log($"Start playing >{properties.AnimationQueue.Peek().GetType()}< on >{properties.go.name}<"); PlayNextAnimation(properties.AnimationQueue.Dequeue()); } } @@ -86,10 +99,6 @@ public void StartRoutine(int action, string wayPointName) // But it's required as it checks immediately how long the Cauldron is already been whirled. properties.isStateTimeActive = true; properties.stateTime = 0; - - // We always need to set "self" before executing any Daedalus function. - vm.GlobalSelf = properties.npcInstance; - vm.Call(action); } /// @@ -100,7 +109,7 @@ public void ClearState(bool stopCurrentStateImmediately) if (stopCurrentStateImmediately) { properties.currentLoopState = NpcProperties.LoopState.None; - AnimationCreator.StopAnimation(properties.gameObject); + AnimationCreator.StopAnimation(properties.go); } else { diff --git a/Assets/GothicVR/Scripts/Player/BasicMovement/ControllerManager.cs b/Assets/GothicVR/Scripts/Player/BasicMovement/ControllerManager.cs index 0a29f8dc6..ae066374b 100644 --- a/Assets/GothicVR/Scripts/Player/BasicMovement/ControllerManager.cs +++ b/Assets/GothicVR/Scripts/Player/BasicMovement/ControllerManager.cs @@ -1,4 +1,3 @@ -using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -6,6 +5,7 @@ using GVR.Extensions; using GVR.Globals; using GVR.GothicVR.Scripts.Manager; +using GVR.Manager; using GVR.Util; using TMPro; using UnityEngine; @@ -35,9 +35,10 @@ public class ControllerManager : SingletonBehaviour AudioSource mapaudio; AudioClip scrollsound; - private void Start() + protected override void Awake() { - GvrEvents.ZenKitBootstrapped.AddListener(Initialize); + base.Awake(); + Initialize(); } private void Initialize() @@ -69,11 +70,11 @@ private void Initialize() private void OnDestroy() { - leftPrimaryButtonAction.Disable(); - leftSecondaryButtonAction.Disable(); + leftPrimaryButtonAction?.Disable(); + leftSecondaryButtonAction?.Disable(); - rightPrimaryButtonAction.Disable(); - rightSecondaryButtonAction.Disable(); + rightPrimaryButtonAction?.Disable(); + rightSecondaryButtonAction?.Disable(); } public void ShowRayCasts() diff --git a/Assets/GothicVR/Scripts/Properties/AbstractProperties.cs b/Assets/GothicVR/Scripts/Properties/AbstractProperties.cs index e479ec446..d54c6f118 100644 --- a/Assets/GothicVR/Scripts/Properties/AbstractProperties.cs +++ b/Assets/GothicVR/Scripts/Properties/AbstractProperties.cs @@ -6,4 +6,4 @@ public abstract class AbstractProperties : MonoBehaviour { public GameObject go => gameObject; } -} \ No newline at end of file +} diff --git a/Assets/GothicVR/Scripts/Properties/ContainerProperties.cs b/Assets/GothicVR/Scripts/Properties/ContainerProperties.cs new file mode 100644 index 000000000..cf6d8f487 --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/ContainerProperties.cs @@ -0,0 +1,20 @@ +using ZenKit.Vobs; + +namespace GVR.Properties +{ + public class ContainerProperties : InteractiveProperties + { + public new Container Properties; + + public override void SetData(IVirtualObject data) + { + if (data is Container containerData) + { + Properties = containerData; + base.Properties = containerData; + } + + base.SetData(data); + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/ContainerProperties.cs.meta b/Assets/GothicVR/Scripts/Properties/ContainerProperties.cs.meta new file mode 100644 index 000000000..94581cde1 --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/ContainerProperties.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3647fae04a904a6dbba443f755b63a7d +timeCreated: 1706397507 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/DoorProperties.cs b/Assets/GothicVR/Scripts/Properties/DoorProperties.cs new file mode 100644 index 000000000..64d0b29b1 --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/DoorProperties.cs @@ -0,0 +1,20 @@ +using ZenKit.Vobs; + +namespace GVR.Properties +{ + public class DoorProperties : InteractiveProperties + { + public new Door Properties; + + public override void SetData(IVirtualObject data) + { + if (data is Door doorData) + { + Properties = doorData; + base.Properties = doorData; + } + + base.SetData(data); + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/DoorProperties.cs.meta b/Assets/GothicVR/Scripts/Properties/DoorProperties.cs.meta new file mode 100644 index 000000000..e08183341 --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/DoorProperties.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: aa8549f9b79448e4b3ebd6901ded3136 +timeCreated: 1706397557 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/InteractiveProperties.cs b/Assets/GothicVR/Scripts/Properties/InteractiveProperties.cs new file mode 100644 index 000000000..af447a41c --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/InteractiveProperties.cs @@ -0,0 +1,20 @@ +using ZenKit.Vobs; + +namespace GVR.Properties +{ + public class InteractiveProperties : MovableProperties + { + public new InteractiveObject Properties; + + public override void SetData(IVirtualObject data) + { + if (data is InteractiveObject InteractiveData) + { + Properties = InteractiveData; + base.Properties = InteractiveData; + } + + base.SetData(data); + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/InteractiveProperties.cs.meta b/Assets/GothicVR/Scripts/Properties/InteractiveProperties.cs.meta new file mode 100644 index 000000000..8a8714d4d --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/InteractiveProperties.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fcee438f16834e5f8768391122403ab5 +timeCreated: 1706397330 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/MovableProperties.cs b/Assets/GothicVR/Scripts/Properties/MovableProperties.cs new file mode 100644 index 000000000..978264336 --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/MovableProperties.cs @@ -0,0 +1,20 @@ +using ZenKit.Vobs; + +namespace GVR.Properties +{ + public class MovableProperties : VobProperties + { + public new MovableObject Properties; + + public override void SetData(IVirtualObject data) + { + if (data is MovableObject movableData) + { + Properties = movableData; + base.Properties = movableData; + } + + base.SetData(data); + } + } +} \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/MovableProperties.cs.meta b/Assets/GothicVR/Scripts/Properties/MovableProperties.cs.meta new file mode 100644 index 000000000..20d430282 --- /dev/null +++ b/Assets/GothicVR/Scripts/Properties/MovableProperties.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a183092aa29e4a39b4c79965145291c3 +timeCreated: 1706397164 \ No newline at end of file diff --git a/Assets/GothicVR/Scripts/Properties/VobProperties.cs b/Assets/GothicVR/Scripts/Properties/VobProperties.cs index aabfff0b2..99e36bd06 100644 --- a/Assets/GothicVR/Scripts/Properties/VobProperties.cs +++ b/Assets/GothicVR/Scripts/Properties/VobProperties.cs @@ -15,7 +15,7 @@ public class VobProperties : AbstractProperties public IVirtualObject Properties; - public void SetData(IVirtualObject data) + public virtual void SetData(IVirtualObject data) { Properties = data; diff --git a/Assets/GothicVR/Scripts/Vm/VmGothicExternals.cs b/Assets/GothicVR/Scripts/Vm/VmGothicExternals.cs index 8156f516a..a34efabaf 100644 --- a/Assets/GothicVR/Scripts/Vm/VmGothicExternals.cs +++ b/Assets/GothicVR/Scripts/Vm/VmGothicExternals.cs @@ -7,6 +7,7 @@ using GVR.Globals; using GVR.GothicVR.Scripts.Manager; using GVR.Manager; +using GVR.World; using UnityEngine; using ZenKit; using ZenKit.Daedalus; @@ -41,6 +42,13 @@ public static void RegisterExternals() vm.RegisterExternal("AI_DrawWeapon", AI_DrawWeapon); vm.RegisterExternal("AI_Output", AI_Output); vm.RegisterExternal("AI_StopProcessInfos", AI_StopProcessInfos); + vm.RegisterExternal("AI_LookAt", AI_LookAt); + vm.RegisterExternal("AI_LookAtNPC", AI_LookAtNPC); + vm.RegisterExternal("AI_ContinueRoutine", AI_ContinueRoutine); + vm.RegisterExternal("AI_TurnToNPC", AI_TurnToNPC); + vm.RegisterExternal("AI_PlayAniBS", AI_PlayAniBS); + vm.RegisterExternal("AI_UnequipArmor", AI_UnequipArmor); + // Apply Options // Doc @@ -51,6 +59,7 @@ public static void RegisterExternals() vm.RegisterExternal("Hlp_IsValidItem", Hlp_IsValidItem); vm.RegisterExternal("Hlp_IsValidNpc", Hlp_IsValidNpc); vm.RegisterExternal("Hlp_GetNpc", Hlp_GetNpc); + vm.RegisterExternal("Hlp_GetInstanceId", Hlp_GetInstanceId); // Info vm.RegisterExternal("Info_ClearChoices", Info_ClearChoices); @@ -91,6 +100,20 @@ public static void RegisterExternals() // PxVm.pxVmRegisterExternal(vmPtr, "Npc_RemoveInvItems", Npc_RemoveInvItems); vm.RegisterExternal("EquipItem", EquipItem); vm.RegisterExternal("Npc_GetDistToNpc", Npc_GetDistToNpc); + vm.RegisterExternal("Npc_HasEquippedArmor", Npc_HasEquippedArmor); + vm.RegisterExternal("Npc_GetEquippedMeleeWeapon", Npc_GetEquippedMeleeWeapon); + vm.RegisterExternal("Npc_HasEquippedMeleeWeapon", Npc_HasEquippedMeleeWeapon); + vm.RegisterExternal("Npc_GetEquippedRangedWeapon", Npc_GetEquippedRangedWeapon); + vm.RegisterExternal("Npc_HasEquippedRangedWeapon", Npc_HasEquippedRangedWeapon); + vm.RegisterExternal("Npc_GetDistToWP", Npc_GetDistToWP); + vm.RegisterExternal("Npc_PercDisable", Npc_PercDisable); + vm.RegisterExternal("Npc_CanSeeNpc", Npc_CanSeeNpc); + vm.RegisterExternal("Npc_ClearAiQueue", Npc_ClearAiQueue); + // vm.RegisterExternal("Npc_ClearInventory", Npc_ClearInventory); + vm.RegisterExternal("Npc_GetNextWp", Npc_GetNextWp); + // vm.RegisterExternal("Npc_GetTalentSkill", Npc_GetTalentSkill); + vm.RegisterExternal("Npc_GetTalentValue", Npc_GetTalentValue); + // Print vm.RegisterExternal("PrintDebug", PrintDebug); @@ -102,6 +125,7 @@ public static void RegisterExternals() // Day Routine vm.RegisterExternal("TA_MIN", TA_MIN); + vm.RegisterExternal("TA", TA); vm.RegisterExternal("Npc_ExchangeRoutine", Npc_ExchangeRoutine); // World @@ -111,6 +135,11 @@ public static void RegisterExternals() vm.RegisterExternal("Wld_DetectNpc", Wld_DetectNpc); vm.RegisterExternal("Wld_DetectNpcEx", Wld_DetectNpcEx); vm.RegisterExternal("Wld_IsNextFPAvailable", Wld_IsNextFPAvailable); + vm.RegisterExternal("Wld_SetTime", Wld_SetTime); + vm.RegisterExternal("Wld_GetDay", Wld_GetDay); + vm.RegisterExternal("Wld_IsTime", Wld_IsTime); + vm.RegisterExternal("Wld_GetMobState", Wld_GetMobState); + vm.RegisterExternal("Wld_InsertItem", Wld_InsertItem); // Misc vm.RegisterExternal("ConcatStrings", ConcatStrings); @@ -127,13 +156,19 @@ public static void DefaultExternal(DaedalusVm vm, DaedalusSymbol sym) //throw new NotImplementedException("External >" + value + "< not registered but required by DaedalusVM."); try { - var npcName = LookupCache.NpcCache[GameData.GothicVm.GlobalSelf.Index].gameObject.name; - Debug.LogWarning($"Method >{sym.Name}< not yet implemented in DaedalusVM (called on >{npcName}<)."); + if (GameData.GothicVm.GlobalSelf == null) + { + Debug.LogWarning($"Method >{sym.Name}< not yet implemented in DaedalusVM."); + } + else + { + var npcName = LookupCache.NpcCache[GameData.GothicVm.GlobalSelf.Index].go.name; + Debug.LogWarning($"Method >{sym.Name}< not yet implemented in DaedalusVM (called on >{npcName}<)."); + } } catch (Exception) { Debug.LogError("Bug in getting Npc. Fix or delete."); - Debug.LogWarning($"Method >{sym.Name}< not yet implemented in DaedalusVM."); } } @@ -224,6 +259,36 @@ public static void AI_StopProcessInfos(NpcInstance npc) DialogHelper.ExtAiStopProcessInfos(npc); } + public static void AI_LookAt(NpcInstance npc, string waypoint) + { + NpcHelper.ExtAiLookAt(npc, waypoint); + } + + public static void AI_LookAtNPC(NpcInstance npc, NpcInstance target) + { + NpcHelper.ExtAiLookAtNpc(npc, target); + } + + public static void AI_ContinueRoutine(NpcInstance npc) + { + NpcHelper.ExtAiContinueRoutine(npc); + } + + public static void AI_TurnToNPC(NpcInstance npc, NpcInstance target) + { + NpcHelper.ExtAiTurnToNpc(npc, target); + } + + public static void AI_PlayAniBS(NpcInstance npc, string name, int bodyState) + { + NpcHelper.ExtAiPlayAniBS(npc, name, bodyState); + } + + public static void AI_UnequipArmor(NpcInstance npc) + { + NpcHelper.ExtAiUnequipArmor(npc); + } + #endregion #region Apply Options @@ -272,6 +337,11 @@ public static NpcInstance Hlp_GetNpc(int instanceId) return NpcCreator.ExtHlpGetNpc(instanceId); } + public static int Hlp_GetInstanceId(DaedalusInstance instanceId) + { + return NpcCreator.ExtHlpGetInstanceId(instanceId); + } + #endregion #region Info @@ -549,6 +619,73 @@ public static int Npc_GetDistToNpc(NpcInstance npc1, NpcInstance npc2) { return NpcHelper.ExtNpcGetDistToNpc(npc1, npc2); } + + public static int Npc_HasEquippedArmor(NpcInstance npc) + { + return NpcHelper.ExtNpcHasEquippedArmor(npc) ? 1 : 0; + } + + public static ItemInstance Npc_GetEquippedMeleeWeapon(NpcInstance npc) + { + return NpcHelper.ExtNpcGetEquippedMeleeWeapon(npc); + } + + public static int Npc_HasEquippedMeleeWeapon(NpcInstance npc) + { + return NpcHelper.ExtNpcHasEquippedMeleeWeapon(npc) ? 1 : 0; + } + + public static ItemInstance Npc_GetEquippedRangedWeapon(NpcInstance npc) + { + return NpcHelper.ExtNpcGetEquippedRangedWeapon(npc); + } + + public static int Npc_HasEquippedRangedWeapon(NpcInstance npc) + { + return NpcHelper.ExtNpcHasEquippedRangedWeapon(npc) ? 1 : 0; + } + + public static int Npc_GetDistToWP(NpcInstance npc, string waypoint) + { + return NpcHelper.ExtNpcGetDistToWp(npc, waypoint); + } + + public static void Npc_PercDisable(NpcInstance npc, int perception) + { + NpcCreator.ExtNpcPerceptionDisable(npc, (VmGothicEnums.PerceptionType)perception); + } + + public static int Npc_CanSeeNpc(NpcInstance npc, NpcInstance target) + { + return NpcHelper.ExtNpcCanSeeNpc(npc, target) ? 1 : 0; + } + + public static void Npc_ClearAiQueue(NpcInstance npc) + { + NpcHelper.ExtNpcClearAiQueue(npc); + } + + public static void Npc_ClearInventory(NpcInstance npc) + { + NpcHelper.ExtNpcClearInventory(npc); + } + + public static string Npc_GetNextWp(NpcInstance npc) + { + return NpcHelper.ExtNpcGetNextWp(npc); + } + + public static int Npc_GetTalentSkill(NpcInstance npc, int skillId) + { + return NpcHelper.ExtNpcGetTalentSkill(npc, skillId); + } + + public static int Npc_GetTalentValue(NpcInstance npc, int skillId) + { + return NpcHelper.ExtNpcGetTalentValue(npc, skillId); + } + + #endregion @@ -560,6 +697,12 @@ public static void TA_MIN(NpcInstance npc, int startH, int startM, int stopH, in { NpcCreator.ExtTaMin(npc, startH, startM, stopH, stopM, action, waypoint); } + + public static void TA(NpcInstance npc, int startH, int stopH, int action, + string waypoint) + { + NpcCreator.ExtTaMin(npc, startH, 0, stopH, 0, action, waypoint); + } public static void Npc_ExchangeRoutine(NpcInstance self, string routineName) { @@ -613,6 +756,46 @@ public static int Wld_IsNextFPAvailable(NpcInstance npc, string fpNamePart) return Convert.ToInt32(result); } + public static void Wld_SetTime(int hour, int minute) + { + GameTime.I.SetTime(hour, minute); + } + + public static int Wld_GetDay() + { + return GameTime.I.GetDay(); + } + + public static int Wld_IsTime(int beginHour, int beginMinute, int endHour, int endMinute) + { + var begin = new TimeSpan(beginHour, beginMinute, 0); + var end = new TimeSpan(endHour, endMinute, 0); + + var now = DateTime.Now.TimeOfDay; + + if (begin <= end && begin <= now && now < end) + { + return 1; + } + + if (begin > end && (begin < now || now <= end)) // begin and end span across midnight + { + return 1; + } + + return 0; + } + + public static int Wld_GetMobState(NpcInstance npc, string scheme) + { + return NpcHelper.ExtWldGetMobState(npc, scheme); + } + + public static void Wld_InsertItem(int itemInstance, string spawnpoint) + { + VobHelper.ExtWldInsertItem(itemInstance, spawnpoint); + } + #endregion #region Misc diff --git a/Assets/GothicVR/Scripts/World/GameTime.cs b/Assets/GothicVR/Scripts/World/GameTime.cs index b655ebf54..81b49e005 100644 --- a/Assets/GothicVR/Scripts/World/GameTime.cs +++ b/Assets/GothicVR/Scripts/World/GameTime.cs @@ -102,6 +102,11 @@ public int GetDay() return time.Day; } + public void SetTime(int hour, int minute) + { + time = new DateTime(time.Year, time.Month, time.Day, hour, minute, 0); + } + public float GetSkyTime() { TimeSpan currentTime = time.TimeOfDay;