diff --git a/resources/config2/teleports_uni_exterior.json b/resources/config2/teleports_uni_exterior.json index 8899439..6d22b3a 100644 --- a/resources/config2/teleports_uni_exterior.json +++ b/resources/config2/teleports_uni_exterior.json @@ -15,15 +15,15 @@ }, { "id": "tp_loc2_to_loc1", - "positionX": 8.2, + "positionX": 6.6335, "positionY": 0.0, - "positionZ": -9.9, + "positionZ": -9.65, "radius": 1.5, "active": true, "destinationLocation": "uni_interior", - "destinationPositionX": 2.64621, + "destinationPositionX": 1.05971, "destinationPositionY": 0.0, - "destinationPositionZ": -9.37259, + "destinationPositionZ": -9.63831, "destinationRotationY": -1.5708 } ] diff --git a/resources/config2/teleports_uni_interior.json b/resources/config2/teleports_uni_interior.json index b9331d1..1626099 100644 --- a/resources/config2/teleports_uni_interior.json +++ b/resources/config2/teleports_uni_interior.json @@ -2,15 +2,15 @@ "teleports": [ { "id": "tp_loc1_to_loc2", - "positionX": 2.64621, + "positionX": 3.39902, "positionY": 0.0, - "positionZ": -9.37259, - "radius": 1.5, + "positionZ": -10.1046, + "radius": 1.8, "active": true, "destinationLocation": "uni_exterior", - "destinationPositionX": 8.2, + "destinationPositionX": 8.9718, "destinationPositionY": 0.0, - "destinationPositionZ": -9.9, + "destinationPositionZ": -9.57324, "destinationRotationY": 0.0 } ] diff --git a/resources/config2/trigger_zones_uni_exterior.json b/resources/config2/trigger_zones_uni_exterior.json index 3b53b96..eb06d33 100644 --- a/resources/config2/trigger_zones_uni_exterior.json +++ b/resources/config2/trigger_zones_uni_exterior.json @@ -4,7 +4,7 @@ "id": "taxi_zone001", "positionX": -15.0359, "positionY": 0.0, - "positionZ": -30.2937, + "positionZ": -36.135, "radius": 4.0, "hysteresis": 0.4, "enabled": true diff --git a/resources/start_dorm.lua b/resources/start_dorm.lua index c0e9739..70c31ee 100644 --- a/resources/start_dorm.lua +++ b/resources/start_dorm.lua @@ -244,6 +244,7 @@ game_api.set_location_callbacks( print("Enter location dorm") local hp = game_api.getFloatValue("player_hp") game_api.set_player_hp(hp) + game_api.set_teleport_active(0, false) end, function() print("Exit location dorm") @@ -257,5 +258,13 @@ game_api.deactivate_interactive_object("Room_Cover_LivingRoom_W_N_2_001") game_api.rotate_object("Door_Utility_-1_1_2_Leaf_001", 90, 0.01, nil) game_api.rotate_object("Door_Utility_-1_-1_2_Leaf_001", -90, 0.01, nil) +game_api.set_call_taxi_callback( + function() + game_api.set_teleport_active(0, true) + game_api.set_trigger_zone_enabled(0, false) + end +) + + game_api.switch_navigation(0) print("Lua script loaded successfully--!") \ No newline at end of file diff --git a/resources/start_uni_exterior.lua b/resources/start_uni_exterior.lua index cb1ac93..26c3460 100644 --- a/resources/start_uni_exterior.lua +++ b/resources/start_uni_exterior.lua @@ -55,6 +55,7 @@ game_api.set_location_callbacks( print("Enter location uni exterior") local hp = game_api.getFloatValue("player_hp") game_api.set_player_hp(hp) + game_api.set_teleport_active(0, false) end, function() print("Exit location uni exterior") @@ -74,4 +75,25 @@ game_api.set_trigger_zone_callbacks("darklands_exit002", game_api.set_trigger_zone_callbacks("darklands_exit003", darklands_exit001_enter_callback, nil -) \ No newline at end of file +) + + +function taxi_zone001_enter_callback() +game_api.start_dialogue("dialog_taxi001") +game_api.set_trigger_zone_enabled(0, false) +end + + +game_api.set_call_taxi_callback( + function() + game_api.set_teleport_active(0, true) + game_api.set_trigger_zone_enabled(0, false) + end +) + + +game_api.set_trigger_zone_callbacks("taxi_zone001", + taxi_zone001_enter_callback, + nil +) + diff --git a/src/Game.cpp b/src/Game.cpp index 25725c1..f99e6f2 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -368,10 +368,7 @@ namespace ZL if (currentLocation) { - if (currentLocation->teleportZones.size() > 0) - { - currentLocation->teleportZones[0].active = true; - } + currentLocation->scriptEngine.callCallTaxiCallback(); } }; diff --git a/src/ScriptEngine.cpp b/src/ScriptEngine.cpp index cfdf791..36bd547 100644 --- a/src/ScriptEngine.cpp +++ b/src/ScriptEngine.cpp @@ -26,6 +26,7 @@ namespace ZL { sol::protected_function darklandsEnterCallback; sol::protected_function darklandsExitCallback; sol::protected_function triggerNightEnterCallback; + sol::protected_function callTaxiCallback; sol::protected_function chatOpenCallbacks[3]; }; @@ -382,6 +383,12 @@ namespace ZL { this_impl->triggerNightEnterCallback = onEnter.as(); }); + api.set_function("set_call_taxi_callback", + [this_impl = impl.get()](sol::object onTaxi) { + if (onTaxi.is()) + this_impl->callTaxiCallback = onTaxi.as(); + }); + api.set_function("set_trigger_zone_enabled", [game](int index, bool value) { auto& triggerZones = game->triggerZones; @@ -392,6 +399,29 @@ namespace ZL { triggerZones[index].enabled = value; }); + // set_teleport_active(index, active) — activates or deactivates a teleport zone by index. + // Swaps the particle effect texture to match the new state. + api.set_function("set_teleport_active", + [game](int index, bool value) { + auto& zones = game->teleportZones; + if (index < 0 || index >= static_cast(zones.size())) { + std::cerr << "[script] set_teleport_active: index " << index << " out of range\n"; + return; + } + zones[index].setActive(value); + }); + + // is_teleport_active(index) → bool + api.set_function("is_teleport_active", + [game](int index) -> bool { + auto& zones = game->teleportZones; + if (index < 0 || index >= static_cast(zones.size())) { + std::cerr << "[script] is_teleport_active: index " << index << " out of range\n"; + return false; + } + return zones[index].active; + }); + // npc_set_hp(index, value) — sets an NPC's current HP directly. api.set_function("npc_set_hp", @@ -837,6 +867,15 @@ namespace ZL { } } + void ScriptEngine::callCallTaxiCallback() { + if (!impl || !impl->callTaxiCallback.valid()) return; + auto result = impl->callTaxiCallback(); + if (!result.valid()) { + sol::error err = result; + std::cerr << "[SCRIPT] call_taxi callback error: " << err.what() << "\n"; + } + } + void ScriptEngine::callCutsceneCompleteCallback(const std::string& cutsceneId) { if (!impl) return; auto it = impl->cutsceneCompleteCallbacks.find(cutsceneId); diff --git a/src/ScriptEngine.h b/src/ScriptEngine.h index 750489b..cad7889 100644 --- a/src/ScriptEngine.h +++ b/src/ScriptEngine.h @@ -49,6 +49,7 @@ public: void callCutsceneCompleteCallback(const std::string& cutsceneId); void callChatOpenCallback(int chatIndex); + void callCallTaxiCallback(); private: struct Impl; diff --git a/src/TeleportZone.cpp b/src/TeleportZone.cpp index 21db1a1..056418b 100644 --- a/src/TeleportZone.cpp +++ b/src/TeleportZone.cpp @@ -6,6 +6,8 @@ namespace ZL { void TeleportZone::initSparks(std::shared_ptr activeTex, std::shared_ptr inactiveTex) { + activeTexture = activeTex; + inactiveTexture = inactiveTex; sparks = std::make_unique(); std::vector emitPoints; emitPoints.push_back(Vector3f{ position.x(), position.y(), position.z() }); @@ -25,6 +27,13 @@ void TeleportZone::initSparks(std::shared_ptr activeTex, std::shared_pt sparks->markConfigured(); } +void TeleportZone::setActive(bool isActive) +{ + active = isActive; + if (sparks && activeTexture && inactiveTexture) + sparks->setTexture(isActive ? activeTexture : inactiveTexture); +} + void TeleportZone::update(float deltaMs) { if (sparks) sparks->update(deltaMs); diff --git a/src/TeleportZone.h b/src/TeleportZone.h index 23bf882..389a6b8 100644 --- a/src/TeleportZone.h +++ b/src/TeleportZone.h @@ -17,8 +17,11 @@ struct TeleportZone { Eigen::Vector3f destinationPosition = Eigen::Vector3f::Zero(); float destinationRotationY = 0.0f; std::unique_ptr sparks; + std::shared_ptr activeTexture; + std::shared_ptr inactiveTexture; void initSparks(std::shared_ptr activeTex, std::shared_ptr inactiveTex); + void setActive(bool isActive); void update(float deltaMs); void prepareForDraw(const Eigen::Matrix4f& viewMatrix); void draw(Renderer& renderer, float zoom, int width, int height);