Working on night mode and how player goes in

This commit is contained in:
Vladislav Khorev 2026-06-04 21:41:32 +03:00
parent 1d3bea452c
commit 9221ab68ac
8 changed files with 550 additions and 274 deletions

View File

@ -11,7 +11,78 @@
"colorR": 4.0,
"colorG": 3.2,
"colorB": 2.4,
"autoLight": false
"autoLight": true,
"autoLightDistance": 6.0
},
{
"id": "lamp_teacher_room",
"positionX": -4.15666,
"positionY": 5.0,
"positionZ": 4.27091,
"directionX": 0.0,
"directionY": -1.0,
"directionZ": 0.0,
"colorR": 4.0,
"colorG": 3.2,
"colorB": 2.4,
"autoLight": true,
"autoLightDistance": 6.0
},
{
"id": "lamp_student_room",
"positionX": 3.60541,
"positionY": 5.0,
"positionZ": -4.36552,
"directionX": 0.0,
"directionY": -1.0,
"directionZ": 0.0,
"colorR": 4.0,
"colorG": 3.2,
"colorB": 2.4,
"autoLight": true,
"autoLightDistance": 6.0
},
{
"id": "lamp_s1_room",
"positionX": -3.90337,
"positionY": 5.0,
"positionZ": -4.00563,
"directionX": 0.0,
"directionY": -1.0,
"directionZ": 0.0,
"colorR": 4.0,
"colorG": 3.2,
"colorB": 2.4,
"autoLight": true,
"autoLightDistance": 6.0
},
{
"id": "lamp_s0_room",
"positionX": -3.90337,
"positionY": 5.0,
"positionZ": -12.485,
"directionX": 0.0,
"directionY": -1.0,
"directionZ": 0.0,
"colorR": 4.0,
"colorG": 3.2,
"colorB": 2.4,
"autoLight": true,
"autoLightDistance": 6.0
},
{
"id": "lamp_hall_room",
"positionX": 0.0,
"positionY": 5.0,
"positionZ": 11.7949,
"directionX": 0.0,
"directionY": -1.0,
"directionZ": 0.0,
"colorR": 4.0,
"colorG": 3.2,
"colorB": 2.4,
"autoLight": true,
"autoLightDistance": 6.0
}
]
}

View File

@ -192,6 +192,12 @@ function on_player_door_click()
end
game_api.set_enter_night_callback(
function()
game_api.start_dialogue("dialog_video001")
end
)
game_api.set_location_callbacks(
function()
print("Enter location dorm")
@ -207,14 +213,6 @@ game_api.set_location_callbacks(
game_api.deactivate_interactive_object("Room_Cover_LivingRoom_W_N_2_001")
--debug
--game_api.deactivate_interactive_object("Room_Cover_Bath_W_N_2_001")
--game_api.deactivate_interactive_object("Room_Cover_LivingRoom_W_S_2_001")
--game_api.deactivate_interactive_object("Room_Cover_Main_Hall_And_Corridors_002")
--game_api.deactivate_interactive_object("Room_Cover_Utility_W_N_3_001")
--game_api.deactivate_interactive_object("Room_Cover_Utility_W_S_3_001")
--debug end
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)

View File

@ -32,6 +32,12 @@ game_api.start_dialogue("dialog_contaier001")
end
end
game_api.set_enter_night_callback(
function()
game_api.start_dialogue("dialog_video001")
end
)
game_api.set_darklands_callbacks(
nil,
function()

View File

@ -1,5 +1,3 @@
hall_door_opened = false
teacher_door_opened = false
lection_is_over = false
@ -144,12 +142,9 @@ function on_bookshelf_clicked()
on_book_pickup()
end
function on_npc_interact(npc_index)
print("[Lua] NPC interaction! Index: " .. tostring(npc_index))
if npc_index == 1 then
local day = game_api.getIntValue("day")
if (day == 0) then
@ -171,9 +166,6 @@ function on_npc_interact(npc_index)
game_api.start_dialogue("aiperi_dialog003")
end
end
end
if npc_index == 0 then
if (player_ghost_aware) then
@ -219,7 +211,6 @@ function on_quest_over()
game_api.set_npc_enabled(4, false)
game_api.set_npc_enabled(5, false)
game_api.quest_set_objective_completed("ghost_release", "ghost_release_show")
end
function on_first_ghost_dialog_over()
@ -228,7 +219,6 @@ print("on_first_ghost_dialog_over")
game_api.quest_unlock("ghost_lore")
end
function on_darklands_over()
game_api.set_player_hp(10)
game_api.resetPlayerAfterDeath()
@ -243,7 +233,17 @@ end
function on_library_door_click()
print("on_library_door_click---")
if (player_left_darklands) then
local day = game_api.getIntValue("day")
if (day == 0) then
if (night_time) then
game_api.start_dialogue("door_night_dialog001")
else
if (not lection_is_over) then
game_api.start_dialogue("door_dialog001")
end
end
else
if (morning_can_open_door_index == 5) then
if (morning_did_open_door_index == 0) then
morning_did_open_door_index = 5
@ -258,17 +258,75 @@ function on_library_door_click()
game_api.start_dialogue("door_dialog001")
end
elseif (night_time) then
end
--[[
--if (player_left_darklands) then
if (morning_can_open_door_index == 5) then
if (morning_did_open_door_index == 0) then
morning_did_open_door_index = 5
game_api.start_dialogue("door_unlock_dialog001")
game_api.rotate_object("Room_N_2_Leaf001", -90, 0.5, nil)
game_api.fade_object("Room_Cover_Corridor_001", 0, 0.5, function()
game_api.deactivate_interactive_object("Room_Cover_Corridor_001")
end)
game_api.switch_navigation(12)
end
elseif (night_time && day == 0) then
game_api.start_dialogue("door_night_dialog001")
else
if (not lection_is_over) then
game_api.start_dialogue("door_dialog001")
end
end
end]]
end
function on_teachers_door_click()
print("on_teachers_door_click---")
local day = game_api.getIntValue("day")
print("day is")
print(day)
if (day == 0) then
if (player_hold_key) then
if (not teacher_door_opened) then
teacher_door_opened = true
game_api.rotate_object("Room_S_2_Leaf001", 90, 0.5, nil)
game_api.fade_object("Room_Cover_South_3_001", 0, 0.5, function()
game_api.deactivate_interactive_object("Room_Cover_South_3_001")
end)
game_api.switch_navigation(3)
end
else
game_api.start_dialogue("door_teacher_dialog001")
end
else
print("morning_can_open_door_index is")
print(morning_can_open_door_index)
if (morning_can_open_door_index == 3) then
print("morning_did_open_door_index is")
print(morning_did_open_door_index)
if (morning_did_open_door_index == 0) then
morning_did_open_door_index = 3
game_api.start_dialogue("door_unlock_dialog001")
game_api.rotate_object("Room_S_2_Leaf001", 90, 0.5, nil)
game_api.fade_object("Room_Cover_Corridor_001", 0, 0.5, function()
game_api.deactivate_interactive_object("Room_Cover_Corridor_001")
end)
game_api.switch_navigation(10)
end
else
game_api.start_dialogue("door_dialog001")
end
end
--[[
if (player_left_darklands) then
if (morning_can_open_door_index == 3) then
if (morning_did_open_door_index == 0) then
@ -284,7 +342,6 @@ function on_teachers_door_click()
else
game_api.start_dialogue("door_dialog001")
end
elseif (not player_hold_key) then
game_api.start_dialogue("door_teacher_dialog001")
elseif (not teacher_door_opened) then
@ -294,11 +351,43 @@ function on_teachers_door_click()
game_api.deactivate_interactive_object("Room_Cover_South_3_001")
end)
game_api.switch_navigation(3)
end
end]]
end
function on_hall_door_click()
print("on_hall_door_click---")
local day = game_api.getIntValue("day")
if (day == 0) then
if (not hall_door_opened) then
hall_door_opened = true
game_api.switch_navigation(1)
game_api.rotate_object("Hall_Leaf001", 90, 0.5, nil)
game_api.fade_object("Room_Cover_Main_Hall_001", 0, 0.5, function()
game_api.deactivate_interactive_object("Room_Cover_Main_Hall_001")
end)
game_api.set_npc_enabled(0, true)
end
else
if (morning_can_open_door_index == 6) then
if (morning_did_open_door_index == 0) then
morning_did_open_door_index = 6
game_api.start_dialogue("door_unlock_dialog001")
game_api.rotate_object("Hall_Leaf001", 90, 0.5, nil)
game_api.fade_object("Room_Cover_Corridor_001", 0, 0.5, function()
game_api.deactivate_interactive_object("Room_Cover_Corridor_001")
end)
game_api.switch_navigation(13)
end
else
game_api.start_dialogue("door_dialog001")
end
end
--[[
if (player_left_darklands) then
if (morning_can_open_door_index == 6) then
if (morning_did_open_door_index == 0) then
@ -314,7 +403,6 @@ function on_hall_door_click()
else
game_api.start_dialogue("door_dialog001")
end
elseif (not hall_door_opened) then
hall_door_opened = true
game_api.switch_navigation(1)
@ -323,11 +411,16 @@ function on_hall_door_click()
game_api.deactivate_interactive_object("Room_Cover_Main_Hall_001")
end)
game_api.set_npc_enabled(0, true)
end
end]]
end
function on_s1_door_click()
if (player_left_darklands) then
--if (player_left_darklands) then
if (morning_can_open_door_index == 1) then
if (morning_did_open_door_index == 0) then
morning_did_open_door_index = 1
@ -342,14 +435,13 @@ function on_s1_door_click()
else
game_api.start_dialogue("door_dialog001")
end
else
game_api.start_dialogue("door_dialog001")
--else
-- game_api.start_dialogue("door_dialog001")
--end
end
end
function on_s2_door_click()
if (player_left_darklands) then
--if (player_left_darklands) then
if (morning_can_open_door_index == 2) then
if (morning_did_open_door_index == 0) then
morning_did_open_door_index = 2
@ -364,9 +456,9 @@ function on_s2_door_click()
else
game_api.start_dialogue("door_dialog001")
end
else
game_api.start_dialogue("door_dialog001")
end
--else
-- game_api.start_dialogue("door_dialog001")
--end
end
function on_n2_door_click()
@ -376,7 +468,7 @@ function on_n2_door_click()
print(morning_can_open_door_index)
print("morning_did_open_door_index")
print(morning_did_open_door_index)
if (player_left_darklands) then
--if (player_left_darklands) then
if (morning_can_open_door_index == 4) then
if (morning_did_open_door_index == 0) then
morning_did_open_door_index = 4
@ -393,11 +485,10 @@ function on_n2_door_click()
else
game_api.start_dialogue("door_dialog001")
end
else
game_api.start_dialogue("door_dialog001")
--else
-- game_api.start_dialogue("door_dialog001")
--end
end
end
function on_teacher_arrived()
print("Teacher arrived")
@ -415,7 +506,6 @@ function book_dialog_zone001_enter_callback()
game_api.set_trigger_zone_enabled(3, false)
game_api.advance_darklands_hud()
else
print("book_dialog_zone001_enter_callback step 3")
if (player_hold_book) and (night_time == false) then
print("book_dialog_zone001_enter_callback step 4")
@ -500,7 +590,6 @@ game_api.npc_walk_to(0, 3.19574, 0, 6.45595, on_teacher_arrived)
teacher_arrived = true
end
game_api.set_cutscene_callback("test_cutscene_01", function()
print("Cutscene done!")
lection_is_over = true
@ -516,9 +605,7 @@ game_api.deactivate_interactive_object("Note001")
end
function on_report_card_pickup()
if player_ghost_aware then
local player_has_report_card = game_api.getIntValue("player_has_report_card")
local report_card_signed = game_api.getIntValue("report_card_signed")
@ -535,12 +622,15 @@ else
game_api.start_dialogue("dialog_report_card001")
end
end
function on_bookshelf_teacher_clicked()
on_report_card_pickup()
end
first_time_darklands = true
game_api.set_darklands_callbacks(
function()
if (first_time_darklands) then
@ -756,6 +846,95 @@ function setDay1MorningSetup()
end
end
function setDay1NightSetup()
night_time = true
print("setDay1NightSetup")
morning_did_open_door_index = 0
game_api.deactivate_interactive_object("Room_Cover_North_1_001")
game_api.activate_interactive_object("Room_Cover_North_2_001")
game_api.activate_interactive_object("Room_Cover_North_3_001")
game_api.activate_interactive_object("Room_Cover_South_1_001")
game_api.activate_interactive_object("Room_Cover_South_2_001")
game_api.activate_interactive_object("Room_Cover_South_3_001")
game_api.deactivate_interactive_object("Room_Cover_Corridor_001")
game_api.activate_interactive_object("Room_Cover_Main_Hall_001")
game_api.set_object_rotation("Room_N_0_Leaf001", 0)
game_api.set_object_rotation("Room_N_1_Leaf001", 0)
game_api.set_object_rotation("Room_N_2_Leaf001", 0)
game_api.set_object_rotation("Room_S_0_Leaf001", 0)
game_api.set_object_rotation("Room_S_1_Leaf001", 0)
game_api.set_object_rotation("Room_S_2_Leaf001", 0)
game_api.set_object_rotation("Hall_Leaf001", 0)
game_api.set_object_alpha("Room_Cover_North_1_001", 1)
game_api.set_object_alpha("Room_Cover_North_2_001", 1)
game_api.set_object_alpha("Room_Cover_North_3_001", 1)
game_api.set_object_alpha("Room_Cover_South_1_001", 1)
game_api.set_object_alpha("Room_Cover_South_2_001", 1)
game_api.set_object_alpha("Room_Cover_South_3_001", 1)
game_api.set_object_alpha("Room_Cover_Corridor_001", 1)
game_api.set_object_alpha("Room_Cover_Main_Hall_001", 1)
game_api.set_npc_enabled(0, false)
game_api.set_npc_enabled(1, false)
game_api.set_npc_enabled(2, false)
game_api.set_npc_enabled(3, false)
game_api.set_npc_enabled(4, false)
game_api.set_npc_enabled(5, false)
local px = game_api.get_player_x()
local pz = game_api.get_player_z()
if (pz > 8.0) then
game_api.activate_interactive_object("Room_Cover_Corridor_001")
game_api.deactivate_interactive_object("Room_Cover_Main_Hall_001")
morning_can_open_door_index = 6
print("(pz > 8.0)")
elseif (pz <= 8.0) and (pz > 0) and (px >= 1.5) then
game_api.activate_interactive_object("Room_Cover_Corridor_001")
game_api.deactivate_interactive_object("Room_Cover_North_3_001")
morning_can_open_door_index = 5
print("(pz <= 8.0) and (pz > 0) and (px >= 1.5)")
elseif (pz <= 8.0) and (pz > 0) and (px <= -1.5) then
game_api.activate_interactive_object("Room_Cover_Corridor_001")
game_api.deactivate_interactive_object("Room_Cover_South_3_001")
morning_can_open_door_index = 3
print("(pz <= 8.0) and (pz > 0) and (px <= -1.5)")
elseif (pz <= 0.0) and (pz > -8) and (px >= 1.5) then
game_api.activate_interactive_object("Room_Cover_Corridor_001")
game_api.deactivate_interactive_object("Room_Cover_North_2_001")
morning_can_open_door_index = 4
print("(pz <= 0.0) and (pz > -8) and (px >= 1.5)")
elseif (pz <= 0.0) and (pz > -8) and (px <= -1.5) then
game_api.activate_interactive_object("Room_Cover_Corridor_001")
game_api.deactivate_interactive_object("Room_Cover_South_2_001")
morning_can_open_door_index = 2
print("(pz <= 0.0) and (pz > -8) and (px <= -1.5)")
elseif (pz <= -8.0) and (px <= -1.5) then
game_api.activate_interactive_object("Room_Cover_Corridor_001")
game_api.deactivate_interactive_object("Room_Cover_South_1_001")
morning_can_open_door_index = 1
print("(pz <= -8.0) and (px <= -1.5)")
else
--All set before
morning_can_open_door_index = 0
print("pz and px not working")
end
end
game_api.set_enter_night_callback(
function()
game_api.start_dialogue("dialog_video001")
setDay1NightSetup()
end
)
game_api.set_location_callbacks(
function()

View File

@ -15,7 +15,6 @@
#endif
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
@ -1191,7 +1190,11 @@ namespace ZL
if (darklandsFlashAlpha >= 1.0f) {
if (isNightTransition) {
menuManager.isNight = !menuManager.isNight;
if (currentLocation) currentLocation->dialogueSystem.startDialogue("dialog_video001");
if (currentLocation)
{
//currentLocation->dialogueSystem.startDialogue("dialog_video001");
currentLocation->scriptEngine.callTriggerNightEnterCallback();
}
} else {
isDarklands = !isDarklands;

View File

@ -362,6 +362,7 @@ namespace ZL {
money_ -= amount;
}
void MenuManager::openPhoneBank() {
uiManager.pushMenuFromSavedRoot(phoneBankRoot);
uiManager.setText("balanceText", formatMoney(money_));

View File

@ -25,6 +25,7 @@ namespace ZL {
sol::protected_function locationExitCallback;
sol::protected_function darklandsEnterCallback;
sol::protected_function darklandsExitCallback;
sol::protected_function triggerNightEnterCallback;
};
ScriptEngine::ScriptEngine() = default;
@ -318,6 +319,12 @@ namespace ZL {
this_impl->darklandsExitCallback = onExit.as<sol::protected_function>();
});
api.set_function("set_enter_night_callback",
[this_impl = impl.get()](sol::object onEnter) {
if (onEnter.is<sol::protected_function>())
this_impl->triggerNightEnterCallback = onEnter.as<sol::protected_function>();
});
api.set_function("set_trigger_zone_enabled",
[game](int index, bool value) {
auto& triggerZones = game->triggerZones;
@ -742,6 +749,15 @@ namespace ZL {
}
}
void ScriptEngine::callTriggerNightEnterCallback() {
if (!impl || !impl->triggerNightEnterCallback.valid()) return;
auto result = impl->triggerNightEnterCallback();
if (!result.valid()) {
sol::error err = result;
std::cerr << "[SCRIPT] trigger night enter callback error: " << err.what() << "\n";
}
}
void ScriptEngine::callDarklandsExitCallback() {
if (!impl || !impl->darklandsExitCallback.valid()) return;
auto result = impl->darklandsExitCallback();

View File

@ -44,6 +44,8 @@ public:
void callDarklandsEnterCallback();
void callDarklandsExitCallback();
void callTriggerNightEnterCallback();
void callCutsceneCompleteCallback(const std::string& cutsceneId);
private: