Major refactoring - internal server state machine implemented

This commit is contained in:
Vladislav Khorev committed 2026-10-29 00:09:16 +06:00
1 parent 71c654e5b6
commit 66e93d46f4
48 files changed
+3948 -3696

No files matched your search

+129 -136
View File
@@ -1,14 +1,6 @@
CONST_MSG_EMPTY = "(пусто)"
CONST_MSG_WHERE = "Бекзат, ты где? Я жду..."
hall_door_opened = false
teacher_door_opened = false
player_hold_book = false
teacher_arrived_to_library = false
teacher_told_about_book = false
--[[
0 - day0
1 - darklands
@@ -17,14 +9,6 @@ teacher_told_about_book = false
4 - day
]]
was_state_when_player_left = 0
was_day_when_player_left = 0
morning_can_open_door_index = 0
morning_did_open_door_index = 0
ghost_gone = false
function dialog_aiperi_give_key()
local player_hold_key = game_api.getIntValue("player_hold_key")
@@ -65,7 +49,7 @@ function knife_dialog_zone001_enter_callback()
if (player_hold_knife == 0) then
local lection_is_over = game_api.getIntValue("lection_is_over")
if lection_is_over == 1 then
game_api.npc_stop_and_rotate_to_player(1)
game_api.npc_stop_and_rotate_to_player("npc_02_woman")
if (player_hold_key == 1) then
game_api.start_dialogue("knife_dialog002")
else
@@ -79,7 +63,7 @@ function knife_dialog_zone001_enter_callback()
if (aiperi_talked_after_knife == 0) then
game_api.start_dialogue("knife_dialog_second001")
end
game_api.set_trigger_zone_enabled(1, false)
game_api.set_trigger_zone_enabled("knife_dialog_zone001", false)
end
end
end
@@ -110,11 +94,11 @@ game_api.set_trigger_zone_callbacks("knife_dialog_zone001",
function on_knife_pickup()
game_api.pickup_item("knife")
game_api.deactivate_interactive_object("Knife001")
game_api.set_npc_enabled(1, false)
game_api.set_npc_enabled("npc_02_woman", false)
game_api.setIntValue("player_hold_knife", 1)
game_api.set_trigger_zone_enabled(2, true)
game_api.npc_walk_to(0, -4.57412, 0, 6.78495, on_teacher_arrived2)
game_api.set_trigger_zone_enabled("teacher_dialog_zone001", true)
game_api.npc_walk_to("npc_teacher01", -4.57412, 0, 6.78495, on_teacher_arrived2)
game_api.quest_set_objective_completed("aiperi_knife", "aiperi_knife_take")
game_api.player_stop()
end
@@ -133,14 +117,14 @@ function on_book_pickup()
player_hold_book = true
game_api.quest_set_objective_completed("study_project", "study_project_book")
game_api.start_dialogue("book_dialog003")
--game_api.set_trigger_zone_enabled(3, true)
--game_api.set_trigger_zone_enabled("book_dialog_zone001", true)
end
else
game_api.remove_item("book")
game_api.activate_interactive_object("Book001")
player_hold_book = false
game_api.start_dialogue("book_dialog004")
--game_api.set_trigger_zone_enabled(3, false)
--game_api.set_trigger_zone_enabled("book_dialog_zone001", false)
end
else
print("on_book_pickup step2")
@@ -218,14 +202,14 @@ function on_cake_clicked()
game_api.player_stop()
end
function on_npc_interact(npc_index)
function on_npc_interact(npc_id)
local player_ghost_aware = game_api.getIntValue("ghost_aware")
local player_hold_key = game_api.getIntValue("player_hold_key")
local day = game_api.getIntValue("day")
print("[Lua] NPC interaction! Index: " .. tostring(npc_index))
if npc_index == 1 then
game_api.player_stop_and_rotate_to_npc(1)
print("[Lua] NPC interaction! ID: " .. tostring(npc_id))
if npc_id == "npc_02_woman" then
game_api.player_stop_and_rotate_to_npc("npc_02_woman")
if (game_api.is_dawn()) or (day > 0) then
game_api.start_dialogue("dialog_aiperi_morning001")
else
@@ -236,8 +220,8 @@ function on_npc_interact(npc_index)
end
end
end
if npc_index == 0 then
game_api.player_stop_and_rotate_to_npc(0)
if npc_id == "npc_teacher01" then
game_api.player_stop_and_rotate_to_npc("npc_teacher01")
if (day == 0) then
if (teacher_arrived_to_library) then
if (teacher_told_about_book) then
@@ -264,8 +248,8 @@ function on_npc_interact(npc_index)
end
end
end
if npc_index == 2 then
game_api.player_stop_and_rotate_to_npc(2)
if npc_id == "npc_04_ghost" then
game_api.player_stop_and_rotate_to_npc("npc_04_ghost")
local report_card_signed = game_api.getIntValue("report_card_signed")
if (report_card_signed == 1) then
game_api.start_dialogue("dialog_with_ghost003")
@@ -273,18 +257,18 @@ function on_npc_interact(npc_index)
game_api.start_dialogue("dialog_with_ghost001")
end
end
if npc_index == 6 then
game_api.player_stop_and_rotate_to_npc(6)
if npc_id == "npc_altynai" then
game_api.player_stop_and_rotate_to_npc("npc_altynai")
game_api.start_dialogue("dialog_female_student002")
end
end
function on_quest_over()
ghost_gone = true
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)
game_api.set_npc_enabled("npc_04_ghost", false)
game_api.set_npc_enabled("ghost_01x", false)
game_api.set_npc_enabled("ghost_02x", false)
game_api.set_npc_enabled("ghost_03x", false)
game_api.quest_set_objective_completed("ghost_release", "ghost_release_show")
game_api.start_cutscene("game_complete_cutscene001")
@@ -297,7 +281,7 @@ end
function teacher_zone001_enter_callback()
game_api.start_dialogue("teacher_dialog002")
game_api.set_trigger_zone_enabled(2, false)
game_api.set_trigger_zone_enabled("teacher_dialog_zone001", false)
teacher_told_about_book = true
game_api.player_stop()
end
@@ -474,9 +458,9 @@ function on_hall_door_click()
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, callback_deactivate_cover_main_hall)
game_api.set_npc_enabled(0, true)
game_api.set_npc_enabled(6, true)
game_api.npc_rotate_to(6, 180)
game_api.set_npc_enabled("npc_teacher01", true)
game_api.set_npc_enabled("npc_altynai", true)
game_api.npc_rotate_to("npc_altynai", 180)
game_api.play_sound("audio/702171__foxfire__door-opening.ogg")
game_api.player_stop()
end
@@ -558,22 +542,22 @@ function on_n2_door_click()
end
function on_teacher_arrived()
game_api.npc_rotate_to(0, 180)
game_api.npc_rotate_to("npc_teacher01", 180)
teacher_arrived_to_library = true
end
function on_student_arrived()
game_api.npc_rotate_to(6, 270)
game_api.npc_rotate_to("npc_altynai", 270)
end
function on_teacher_arrived2()
game_api.npc_rotate_to(0, 0)
game_api.npc_rotate_to("npc_teacher01", 0)
end
function book_dialog_zone001_enter_callback()
if (game_api.is_darklands()) then
game_api.start_dialogue("ghost_dialog002")
game_api.set_trigger_zone_enabled(3, false)
game_api.set_trigger_zone_enabled("book_dialog_zone001", false)
game_api.advance_darklands_hud()
else
if (player_hold_book) and (game_api.is_night() == false) then
@@ -621,9 +605,9 @@ function on_sleep_cutscene()
print("Cutscene 2 done!")
game_api.set_night()
--game_api.set_trigger_zone_enabled(1, false)
game_api.set_npc_enabled(0, false)
game_api.set_npc_enabled(6, false)
--game_api.set_trigger_zone_enabled("knife_dialog_zone001", false)
game_api.set_npc_enabled("npc_teacher01", false)
game_api.set_npc_enabled("npc_altynai", false)
game_api.switch_navigation(16)
game_api.set_object_rotation("Room_N_2_Leaf001", 0)
game_api.set_object_rotation("Hall_Leaf001", 0)
@@ -649,14 +633,14 @@ function on_teacher_arrived_intermediate()
game_api.rotate_object("Room_N_2_Leaf001", -90, 0.5, nil)
game_api.fade_object("Room_Cover_North_3_001", 0, 0.5, callback_deactivate_cover_n3)
game_api.switch_navigation(2)
game_api.npc_walk_to(0, 4.94194, 0, 6.64111, on_teacher_arrived)
game_api.npc_walk_to("npc_teacher01", 4.94194, 0, 6.64111, on_teacher_arrived)
game_api.play_sound("audio/702171__foxfire__door-opening.ogg")
end
function on_lection_cutscene_fadein_callback()
print("Lection cutscene in progress!")
-- -0.0234149 0 10.1139
game_api.npc_set_position(0, 0.0, 0.0, 10.1139)
game_api.npc_set_position("npc_teacher01", 0.0, 0.0, 10.1139)
--4.91002 0 10.375
--game_api.player_set_position(-2.41002, 0, 10.375)
@@ -670,10 +654,10 @@ function callback_on_lection_cutscene_over()
print("Cutscene done!")
game_api.setIntValue("lection_is_over", 1)
game_api.set_npc_enabled(1, true)
game_api.npc_rotate_to(1, 180)
game_api.npc_walk_to(0, 0.758123, 0, 6.50063, on_teacher_arrived_intermediate)
game_api.npc_walk_to(6, 5.28998, 0, -5.525, on_student_arrived)
game_api.set_npc_enabled("npc_02_woman", true)
game_api.npc_rotate_to("npc_02_woman", 180)
game_api.npc_walk_to("npc_teacher01", 0.758123, 0, 6.50063, on_teacher_arrived_intermediate)
game_api.npc_walk_to("npc_altynai", 5.28998, 0, -5.525, on_student_arrived)
local aiperi_knife_aware = game_api.getIntValue("aiperi_knife_aware")
@@ -715,38 +699,36 @@ function on_bookshelf_teacher_clicked()
on_report_card_pickup()
end
first_time_darklands = true
function callback_enter_darklands()
if (first_time_darklands) then
game_api.start_dialogue("ghost_dialog001")
first_time_darklands = false
end
game_api.set_trigger_zone_enabled(1, false)
game_api.set_trigger_zone_enabled("knife_dialog_zone001", false)
game_api.set_npc_enabled(0, false)
game_api.set_npc_enabled(1, false)
game_api.set_npc_enabled(6, false)
game_api.set_npc_enabled("npc_teacher01", false)
game_api.set_npc_enabled("npc_02_woman", false)
game_api.set_npc_enabled("npc_altynai", false)
if (ghost_gone) then
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)
game_api.set_npc_enabled("npc_04_ghost", false)
game_api.set_npc_enabled("ghost_01x", false)
game_api.set_npc_enabled("ghost_02x", false)
game_api.set_npc_enabled("ghost_03x", false)
else
game_api.set_npc_enabled(2, true)
game_api.set_npc_enabled(3, true)
game_api.set_npc_enabled(4, true)
game_api.set_npc_enabled(5, true)
game_api.set_npc_enabled("npc_04_ghost", true)
game_api.set_npc_enabled("ghost_01x", true)
game_api.set_npc_enabled("ghost_02x", true)
game_api.set_npc_enabled("ghost_03x", true)
game_api.npc_set_hp(3, 35)
game_api.npc_set_hp(4, 35)
game_api.npc_set_hp(5, 35)
game_api.npc_set_hp("ghost_01x", 35)
game_api.npc_set_hp("ghost_02x", 35)
game_api.npc_set_hp("ghost_03x", 35)
game_api.npc_set_position(3, 0, 0, -6.4)
game_api.npc_set_position(4, -5.0, 0, 12)
game_api.npc_set_position(5, 5.0, 0, 12)
game_api.npc_set_position("ghost_01x", 0, 0, -6.4)
game_api.npc_set_position("ghost_02x", -5.0, 0, 12)
game_api.npc_set_position("ghost_03x", 5.0, 0, 12)
end
game_api.switch_navigation(5)
@@ -755,13 +737,13 @@ end
function callback_exit_darklands()
game_api.start_cutscene("darklands_exit001")
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)
game_api.set_npc_enabled(6, false)
game_api.set_npc_enabled("npc_teacher01", false)
game_api.set_npc_enabled("npc_02_woman", false)
game_api.set_npc_enabled("npc_04_ghost", false)
game_api.set_npc_enabled("ghost_01x", false)
game_api.set_npc_enabled("ghost_02x", false)
game_api.set_npc_enabled("ghost_03x", false)
game_api.set_npc_enabled("npc_altynai", false)
morning_did_open_door_index = 0
setDay1MorningSetup()
@@ -873,13 +855,13 @@ function setDay0setup()
game_api.deactivate_interactive_object("Note001")
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)
game_api.set_npc_enabled(6, false)
game_api.set_npc_enabled("npc_teacher01", false)
game_api.set_npc_enabled("npc_02_woman", false)
game_api.set_npc_enabled("npc_04_ghost", false)
game_api.set_npc_enabled("ghost_01x", false)
game_api.set_npc_enabled("ghost_02x", false)
game_api.set_npc_enabled("ghost_03x", false)
game_api.set_npc_enabled("npc_altynai", false)
game_api.activate_interactive_object("car001")
game_api.activate_interactive_object("car001wheels")
@@ -903,7 +885,6 @@ function setDay1setup()
game_api.activate_interactive_object("Room_Cover_South_2_001")
game_api.deactivate_interactive_object("Room_Cover_South_3_001")
game_api.set_object_rotation("Room_N_0_Leaf001", 0)
game_api.set_object_rotation("Room_N_1_Leaf001", -90)
game_api.set_object_rotation("Room_N_2_Leaf001", -90)
game_api.set_object_rotation("Room_S_0_Leaf001", 0)
@@ -911,15 +892,15 @@ function setDay1setup()
game_api.set_object_rotation("Room_S_2_Leaf001", 90)
game_api.set_object_rotation("Hall_Leaf001", 90)
game_api.set_npc_enabled(0, true)
game_api.set_npc_enabled(1, true)
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)
game_api.set_npc_enabled(6, true)
game_api.set_npc_enabled("npc_teacher01", true)
game_api.set_npc_enabled("npc_02_woman", true)
game_api.set_npc_enabled("npc_04_ghost", false)
game_api.set_npc_enabled("ghost_01x", false)
game_api.set_npc_enabled("ghost_02x", false)
game_api.set_npc_enabled("ghost_03x", false)
game_api.set_npc_enabled("npc_altynai", true)
game_api.npc_set_position(1, 0.98998, 0, -7.525)
game_api.npc_set_position("npc_02_woman", 0.98998, 0, -7.525)
game_api.deactivate_interactive_object("Cake001")
@@ -939,7 +920,6 @@ function setDay1MorningSetup()
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)
@@ -964,15 +944,15 @@ function setDay1MorningSetup()
-- TODO: Make check for teacher_door_opened false or true
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)
game_api.set_npc_enabled(6, false)
game_api.set_npc_enabled("npc_teacher01", false)
game_api.set_npc_enabled("npc_02_woman", false)
game_api.set_npc_enabled("npc_04_ghost", false)
game_api.set_npc_enabled("ghost_01x", false)
game_api.set_npc_enabled("ghost_02x", false)
game_api.set_npc_enabled("ghost_03x", false)
game_api.set_npc_enabled("npc_altynai", false)
game_api.npc_set_position(1, 0.98998, 0, -7.525)
game_api.npc_set_position("npc_02_woman", 0.98998, 0, -7.525)
if morning_did_open_door_index == 1 then
game_api.deactivate_interactive_object("Room_Cover_South_1_001")
@@ -1043,7 +1023,6 @@ function setDay1NightSetup()
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)
@@ -1059,13 +1038,13 @@ function setDay1NightSetup()
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)
game_api.set_npc_enabled(6, false)
game_api.set_npc_enabled("npc_teacher01", false)
game_api.set_npc_enabled("npc_02_woman", false)
game_api.set_npc_enabled("npc_04_ghost", false)
game_api.set_npc_enabled("ghost_01x", false)
game_api.set_npc_enabled("ghost_02x", false)
game_api.set_npc_enabled("ghost_03x", false)
game_api.set_npc_enabled("npc_altynai", false)
game_api.deactivate_interactive_object("car001")
game_api.deactivate_interactive_object("car001wheels")
@@ -1222,8 +1201,8 @@ game_api.set_chat_callbacks(
)
function callback_aiperi_dialog_morning()
game_api.player_stop_and_rotate_to_npc(1)
game_api.npc_stop_and_rotate_to_player(1)
game_api.player_stop_and_rotate_to_npc("npc_02_woman")
game_api.npc_stop_and_rotate_to_player("npc_02_woman")
game_api.start_dialogue("dialog_aiperi_morning001")
end
@@ -1246,9 +1225,9 @@ function on_aiperi_opens_door()
end
--Aiperi incoming
game_api.npc_set_position(1, 0, 0, 6.5)
game_api.set_npc_enabled(1, true)
game_api.npc_walk_to(1, 0.0, 0, 9.1, callback_aiperi_dialog_morning)
game_api.npc_set_position("npc_02_woman", 0, 0, 6.5)
game_api.set_npc_enabled("npc_02_woman", true)
game_api.npc_walk_to("npc_02_woman", 0.0, 0, 9.1, callback_aiperi_dialog_morning)
game_api.player_walk_to(0.0, 0.0, 10.0, nil)
game_api.play_sound("audio/702171__foxfire__door-opening.ogg")
@@ -1268,9 +1247,9 @@ function on_aiperi_opens_door()
end
--Aiperi incoming
game_api.npc_set_position(1, 0.0, 0, 6.43818)
game_api.set_npc_enabled(1, true)
game_api.npc_walk_to(1, 2.34349, 0, 6.31229, callback_aiperi_dialog_morning)
game_api.npc_set_position("npc_02_woman", 0.0, 0, 6.43818)
game_api.set_npc_enabled("npc_02_woman", true)
game_api.npc_walk_to("npc_02_woman", 2.34349, 0, 6.31229, callback_aiperi_dialog_morning)
game_api.player_walk_to(3.52174, 0, 6.28993, nil)
game_api.play_sound("audio/702171__foxfire__door-opening.ogg")
@@ -1290,9 +1269,9 @@ function on_aiperi_opens_door()
end
--Aiperi incoming
game_api.npc_set_position(1, 0, 0, -1.7911)
game_api.set_npc_enabled(1, true)
game_api.npc_walk_to(1, 2.11898, 0, -1.7074, callback_aiperi_dialog_morning)
game_api.npc_set_position("npc_02_woman", 0, 0, -1.7911)
game_api.set_npc_enabled("npc_02_woman", true)
game_api.npc_walk_to("npc_02_woman", 2.11898, 0, -1.7074, callback_aiperi_dialog_morning)
game_api.player_walk_to(3.36055, 0, -2.0345, nil)
game_api.play_sound("audio/702171__foxfire__door-opening.ogg")
@@ -1312,9 +1291,9 @@ function on_aiperi_opens_door()
game_api.switch_navigation(9)
end
--Aiperi incoming
game_api.npc_set_position(1, 0, 0, -1.7911)
game_api.set_npc_enabled(1, true)
game_api.npc_walk_to(1, -2.454, 0, -1.61871, callback_aiperi_dialog_morning)
game_api.npc_set_position("npc_02_woman", 0, 0, -1.7911)
game_api.set_npc_enabled("npc_02_woman", true)
game_api.npc_walk_to("npc_02_woman", -2.454, 0, -1.61871, callback_aiperi_dialog_morning)
game_api.player_walk_to(-3.63363, 0, -1.50727, nil)
game_api.play_sound("audio/702171__foxfire__door-opening.ogg")
@@ -1334,9 +1313,9 @@ function on_aiperi_opens_door()
end
--Aiperi incoming
game_api.npc_set_position(1, 0, 0, -9.77948)
game_api.set_npc_enabled(1, true)
game_api.npc_walk_to(1, -2.53977, 0, -9.77852, callback_aiperi_dialog_morning)
game_api.npc_set_position("npc_02_woman", 0, 0, -9.77948)
game_api.set_npc_enabled("npc_02_woman", true)
game_api.npc_walk_to("npc_02_woman", -2.53977, 0, -9.77852, callback_aiperi_dialog_morning)
game_api.player_walk_to(-3.64494, 0, -9.66711, nil)
game_api.play_sound("audio/702171__foxfire__door-opening.ogg")
@@ -1345,7 +1324,24 @@ function on_aiperi_opens_door()
end
function on_aiperi_morning_dialog_finished()
game_api.npc_walk_to(1, 0.98998, 0, -7.525, nil)
game_api.npc_walk_to("npc_02_woman", 0.98998, 0, -7.525, nil)
end
function callback_init_location()
hall_door_opened = false
teacher_door_opened = false
player_hold_book = false
teacher_arrived_to_library = false
teacher_told_about_book = false
was_state_when_player_left = 0
was_day_when_player_left = 0
morning_can_open_door_index = 0
morning_did_open_door_index = 0
ghost_gone = false
first_time_darklands = true
setDay0setup()
game_api.switch_navigation(0)
end
function callback_enter_location()
@@ -1437,6 +1433,7 @@ function callback_exit_location()
end
game_api.set_location_callbacks(
callback_init_location,
callback_enter_location,
callback_exit_location
)
@@ -1467,9 +1464,5 @@ end
game_api.set_cutscene_callback("game_complete_cutscene001", callback_game_complete_cutscene)
setDay0setup()
game_api.switch_navigation(0)
--debugAllOpen()
print("Lua script loaded successfully!---!")