1-- Set the namespace according to the map name.
2local ns = {};
3setmetatable(ns, {__index = _G});
4layna_forest_cave1_2_script = ns;
5setfenv(1, ns);
6
7-- The map name, subname and location image
8map_name = "Layna Forest Cave"
9map_image_filename = "data/story/common/locations/desert_cave.png"
10map_subname = ""
11
12-- The music file used as default background music on this map.
13-- Other musics will have to handled through scripting.
14music_filename = "data/music/shrine-OGA-yd.ogg"
15
16-- c++ objects instances
17local Map = nil
18local EventManager = nil
19local Effects = nil
20
21-- the main character handler
22local hero = nil
23
24-- Dialogues sprites
25local bronann = nil
26local kalya = nil
27
28-- the main map loading code
29function Load(m)
30
31    Map = m;
32    Effects = Map:GetEffectSupervisor();
33    EventManager = Map:GetEventSupervisor();
34    Map:SetUnlimitedStamina(false);
35
36    Map:SetMinimapImage("data/story/layna_forest/minimaps/layna_forest_cave1_2_minimap.png");
37
38    _CreateCharacters();
39    _CreateObjects();
40    _CreateEnemies();
41
42    -- Set the camera focus on hero
43    Map:SetCamera(hero);
44    -- This is a dungeon map, we'll use the front battle member sprite as default sprite.
45    Map:SetPartyMemberVisibleSprite(hero);
46
47    _CreateEvents();
48    _CreateZones();
49
50    -- Add a mediumly dark overlay
51    Map:GetEffectSupervisor():EnableAmbientOverlay("data/visuals/ambient/dark.png", 0.0, 0.0, false);
52    -- Add the background and foreground animations
53    Map:GetScriptSupervisor():AddScript("data/story/layna_forest/layna_forest_caves_background_anim.lua");
54
55    -- The script file which will handle the display of the stone sign image.
56    Map:GetScriptSupervisor():AddScript("data/story/layna_forest/layna_forest_cave1_2_stone_sign_image.lua");
57end
58
59-- the map update function handles checks done on each game tick.
60function Update()
61    -- Check whether the character is in one of the zones
62    _CheckZones();
63
64    -- Check whether the monsters have been defeated
65    _CheckMonstersStates();
66end
67
68-- Character creation
69function _CreateCharacters()
70    -- Default hero and position
71    hero = CreateSprite(Map, "Bronann", 3, 15, vt_map.MapMode.GROUND_OBJECT);
72    hero:SetDirection(vt_map.MapMode.EAST);
73    hero:SetMovementSpeed(vt_map.MapMode.NORMAL_SPEED);
74
75    if (GlobalManager:GetMapData():GetPreviousLocation() == "from forest SE") then
76        hero:SetDirection(vt_map.MapMode.NORTH);
77        hero:SetPosition(112, 94);
78    elseif (GlobalManager:GetMapData():GetPreviousLocation() == "from_layna_wolf_cave") then
79        hero:SetDirection(vt_map.MapMode.WEST);
80        hero:SetPosition(122, 15);
81    end
82
83    bronann = CreateSprite(Map, "Bronann", 0, 0, vt_map.MapMode.GROUND_OBJECT);
84    bronann:SetDirection(vt_map.MapMode.NORTH);
85    bronann:SetMovementSpeed(vt_map.MapMode.NORMAL_SPEED);
86    bronann:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
87    bronann:SetVisible(false);
88
89    kalya = CreateSprite(Map, "Kalya", 0, 0, vt_map.MapMode.GROUND_OBJECT);
90    kalya:SetDirection(vt_map.MapMode.NORTH);
91    kalya:SetMovementSpeed(vt_map.MapMode.NORMAL_SPEED);
92    kalya:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
93    kalya:SetVisible(false);
94end
95
96-- Special object blocking the exit
97local blocking_rock = nil
98
99-- Special NPC used a sign
100local stone_sign = nil
101
102function _CreateObjects()
103    local object = nil
104    local npc = nil
105    local event = nil
106
107    -- Treasure chest, accessible later from the next cave.
108    local chest1 = CreateTreasure(Map, "layna_forest_cave1_2_chest", "Wood_Chest1", 116, 38, vt_map.MapMode.GROUND_OBJECT);
109    chest1:SetDrunes(50);
110    chest1:AddItem(16, 2); -- Candy
111
112    -- Adapt the light color according to the time of the day.
113    local light_color_red = 1.0;
114    local light_color_green = 1.0;
115    local light_color_blue = 1.0;
116    local light_color_alpha = 0.8;
117    if (GlobalManager:GetGameEvents():GetEventValue("story", "layna_forest_crystal_event_done") == 1) then
118        local tw_value = GlobalManager:GetGameEvents():GetEventValue("story", "layna_forest_twilight_value");
119        if (tw_value >= 4 and tw_value < 6) then
120            light_color_red = 0.83;
121            light_color_green = 0.72;
122            light_color_blue = 0.70;
123            light_color_alpha = 0.29;
124        elseif (tw_value >= 6 and tw_value < 8) then
125            light_color_red = 0.62;
126            light_color_green = 0.50;
127            light_color_blue = 0.59;
128            light_color_alpha = 0.49;
129        elseif (tw_value >= 8) then
130            light_color_red = 0.30;
131            light_color_green = 0.30;
132            light_color_blue = 0.46;
133            light_color_alpha = 0.60;
134        end
135    end
136
137    -- Add a halo showing the cave entrances
138    vt_map.Halo.Create("data/visuals/lights/torch_light_mask.lua", 113, 109,
139            vt_video.Color(light_color_red, light_color_green, light_color_blue, light_color_alpha));
140    vt_map.Halo.Create("data/visuals/lights/torch_light_mask.lua", 0, 18,
141            vt_video.Color(light_color_red, light_color_green, light_color_blue, light_color_alpha));
142
143    -- Add different halo light, representing holes of light coming from the ceiling
144    vt_map.Halo.Create("data/visuals/lights/right_ray_light.lua", 23, 17,
145            vt_video.Color(light_color_red, light_color_green, light_color_blue, light_color_alpha));
146    vt_map.Halo.Create("data/visuals/lights/right_ray_light.lua", 15, 50,
147            vt_video.Color(light_color_red, light_color_green, light_color_blue, light_color_alpha));
148    vt_map.Halo.Create("data/visuals/lights/right_ray_light.lua", 37, 84,
149            vt_video.Color(light_color_red, light_color_green, light_color_blue, light_color_alpha));
150
151    -- Create the stone sign telling what to do to pass the test...
152    CreateObject(Map, "Stone Sign1", 22, 10, vt_map.MapMode.GROUND_OBJECT);
153
154    -- Create an invisible sprite, used to handle the dialogue
155    stone_sign = CreateSprite(Map, "Butterfly", 22, 11, vt_map.MapMode.GROUND_OBJECT);
156    stone_sign:SetName(vt_system.Translate("Stone sign"));
157    stone_sign:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
158    stone_sign:SetVisible(false);
159
160    _UpdateStoneSignDialogue();
161
162    -- Decorations
163    CreateObject(Map, "Rock1", 107, 96, vt_map.MapMode.GROUND_OBJECT);
164    CreateObject(Map, "Rock1", 117, 96, vt_map.MapMode.GROUND_OBJECT);
165
166    -- The blocking rock
167    blocking_rock = CreateObject(Map, "Rock3", 112, 96, vt_map.MapMode.GROUND_OBJECT);
168
169    -- Remove the block if all enemies have already been defeated
170    if (GlobalManager:GetGameEvents():DoesEventExist("story", "layna_forest_cave2_monsters_defeated")) then
171        blocking_rock:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
172        blocking_rock:SetVisible(false);
173    end
174end
175
176function _UpdateStoneSignDialogue()
177    local dialogue = nil
178    local text = nil
179
180    stone_sign:ClearDialogueReferences();
181
182    if (GlobalManager:GetGameEvents():DoesEventExist("story", "kalya_stone_sign_dialogue_done")) then
183        dialogue = vt_map.SpriteDialogue.Create();
184        text = vt_system.Translate("'Here, only your enemies prevent you from going further.''");
185        dialogue:AddLine(text, stone_sign);
186        stone_sign:AddDialogueReference(dialogue);
187    else
188        -- Start the stone sign dialogue event
189        dialogue = vt_map.SpriteDialogue.Create();
190        text = vt_system.Translate("...");
191        dialogue:AddLineEvent(text, kalya, "Start dialogue about stone sign", "Display the stone sign image");
192        stone_sign:AddDialogueReference(dialogue);
193    end
194end
195
196-- Special event references which destinations must be updated just before being called.
197local move_next_to_bronann_event = nil
198local move_next_to_bronann_event2 = nil
199
200-- Creates all events and sets up the entire event sequence chain
201function _CreateEvents()
202    local event = nil
203    local dialogue = nil
204    local text = nil
205
206    -- Map transition events
207    vt_map.MapTransitionEvent.Create("to cave 1-1", "data/story/layna_forest/layna_forest_cave1_1_map.lua",
208                                     "data/story/layna_forest/layna_forest_cave1_1_script.lua", "from_layna_cave_1_2");
209
210    vt_map.MapTransitionEvent.Create("to south east exit", "data/story/layna_forest/layna_forest_south_east_map.lua",
211                                     "data/story/layna_forest/layna_forest_south_east_script.lua", "from_layna_cave_1_2");
212
213    vt_map.MapTransitionEvent.Create("to wolf cave", "data/story/layna_forest/layna_forest_wolf_cave_map.lua",
214                                     "data/story/layna_forest/layna_forest_wolf_cave_script.lua",  "from_layna_cave_1_2");
215
216    -- Generic events
217    vt_map.ChangeDirectionSpriteEvent.Create("Kalya looks north", kalya, vt_map.MapMode.NORTH);
218    vt_map.ChangeDirectionSpriteEvent.Create("Bronann looks north", bronann, vt_map.MapMode.NORTH);
219    vt_map.ChangeDirectionSpriteEvent.Create("Bronann looks south", bronann, vt_map.MapMode.SOUTH);
220    vt_map.LookAtSpriteEvent.Create("Kalya looks at Bronann", kalya, bronann);
221    vt_map.LookAtSpriteEvent.Create("Bronann looks at Kalya", bronann, kalya);
222
223    vt_map.ScriptedSpriteEvent.Create("kalya:SetCollision(NONE)", kalya, "Sprite_Collision_off", "");
224    vt_map.ScriptedSpriteEvent.Create("kalya:SetCollision(ALL)", kalya, "Sprite_Collision_on", "");
225
226    -- Dialogue
227    event = vt_map.ScriptedEvent.Create("Start dialogue about stone sign", "stone_sign_dialogue_start", "");
228    event:AddEventLinkAtEnd("Kalya moves next to Bronann");
229
230    -- NOTE: The actual destination is set just before the actual start call
231    move_next_to_bronann_event = vt_map.PathMoveSpriteEvent.Create("Kalya moves next to Bronann", kalya, 0, 0, false);
232    move_next_to_bronann_event:AddEventLinkAtEnd("kalya:SetCollision(ALL)");
233    move_next_to_bronann_event:AddEventLinkAtEnd("Kalya looks north");
234
235    event = vt_map.ScriptedEvent.Create("Display the stone sign image", "stone_sign_image_start", "stone_sign_image_update")
236    event:AddEventLinkAtEnd("Kalya reads the scripture");
237
238    dialogue = vt_map.SpriteDialogue.Create();
239    text = vt_system.Translate("'Here, only your enemies prevent you from going further.'");
240    dialogue:AddLineEventEmote(text, kalya, "", "Bronann looks at Kalya", "thinking dots");
241    text = vt_system.Translate("You are able to decipher this writing, Kalya?");
242    dialogue:AddLineEmote(text, bronann, "thinking dots");
243    text = vt_system.Translate("Somehow. I'm not sure how I am able to, but I can read it.");
244    dialogue:AddLineEvent(text, kalya, "Kalya looks at Bronann", "Bronann looks north");
245    text = vt_system.Translate("However, I don't know what it means.");
246    dialogue:AddLineEmote(text, bronann, "thinking dots");
247    text = vt_system.Translate("Let's look around. We might find out.");
248    dialogue:AddLine(text, kalya);
249    event = vt_map.DialogueEvent.Create("Kalya reads the scripture", dialogue);
250    event:AddEventLinkAtEnd("kalya:SetCollision(NONE)");
251    event:AddEventLinkAtEnd("kalya goes back to party");
252
253    event = vt_map.PathMoveSpriteEvent.Create("kalya goes back to party", kalya, bronann, false);
254    event:AddEventLinkAtEnd("end of stone sign dialogue");
255
256    event = vt_map.ScriptedEvent.Create("end of stone sign dialogue", "end_of_stone_sign_dialogue", "");
257    event:AddEventLinkAtEnd("Bronann looks north");
258
259    -- Dialogue when all the enemies are dead.
260    dialogue = vt_map.SpriteDialogue.Create();
261    text = vt_system.Translate("Something heavy seems to have fallen nearby.");
262    dialogue:AddLineEmote(text, kalya, "exclamation");
263    vt_map.DialogueEvent.Create("Hero dialogue during tremor", dialogue);
264
265    -- Kalya sees the mechanisms to go out.
266    event = vt_map.ScriptedEvent.Create("Kalya sees the cave exit", "see_the_exit_dialogue_start", "");
267    event:AddEventLinkAtEnd("Exit seen: Kalya moves next to Bronann");
268
269    -- NOTE the actual coords will be set at event start.
270    move_next_to_bronann_event2 = vt_map.PathMoveSpriteEvent.Create("Exit seen: Kalya moves next to Bronann", kalya, 0, 0, false);
271    move_next_to_bronann_event2:AddEventLinkAtEnd("Kalya says 'Look!'");
272
273    vt_map.LookAtSpriteEvent.Create("Kalya looks at the rock", kalya, 112, 92);
274
275    dialogue = vt_map.SpriteDialogue.Create();
276    text = vt_system.Translate("Look!");
277    dialogue:AddLineEventEmote(text, kalya, "Kalya looks at the rock", "", "exclamation");
278    event = vt_map.DialogueEvent.Create("Kalya says 'Look!'", dialogue);
279    event:AddEventLinkAtEnd("Set_Camera(kalya)");
280
281    event = vt_map.ScriptedSpriteEvent.Create("Set_Camera(kalya)", kalya, "Set_Camera", "");
282    event:AddEventLinkAtEnd("Kalya comes close to the rock");
283
284    event = vt_map.PathMoveSpriteEvent.Create("Kalya comes close to the rock", kalya, 112, 89, false);
285    event:AddEventLinkAtEnd("Kalya looks at the rock");
286    event:AddEventLinkAtEnd("Bronann looks at Kalya");
287    event:AddEventLinkAtEnd("Kalya tells there is an exit behind the rock");
288
289    dialogue = vt_map.SpriteDialogue.Create();
290    text = vt_system.Translate("I can feel a breeze and see light entering the cave from around this rock. Orlinn must have gone through here.");
291    dialogue:AddLine(text, kalya);
292    text = vt_system.Translate("There are signs engraved on this rock, too. This looks like some kind of mechanism my family used long ago.");
293    dialogue:AddLineEvent(text, kalya, "Kalya looks at Bronann", "");
294    text = vt_system.Translate("Your family? Long ago?");
295    dialogue:AddLineEmote(text, bronann, "interrogation");
296    text = vt_system.Translate("Err, nevermind. We must find a way to make this move. Let's look around.");
297    dialogue:AddLineEmote(text, kalya, "exclamation");
298    event = vt_map.DialogueEvent.Create("Kalya tells there is an exit behind the rock", dialogue);
299    event:AddEventLinkAtEnd("Set_Camera(bronann)");
300
301    event = vt_map.ScriptedSpriteEvent.Create("Set_Camera(bronann)", bronann, "Set_Camera", "");
302    event:AddEventLinkAtEnd("Exit seen: kalya goes back to party");
303
304    event = vt_map.PathMoveSpriteEvent.Create("Exit seen: kalya goes back to party", kalya, bronann, false);
305    event:AddEventLinkAtEnd("end of exit seen dialogue");
306
307    event = vt_map.ScriptedEvent.Create("end of exit seen dialogue", "end_of_exit_seen_dialogue", "");
308    event:AddEventLinkAtEnd("Bronann looks south");
309end
310
311-- local members used to know whether the monsters have been defeated.
312local monster1_defeated = false;
313local monster2_defeated = false;
314local monster3_defeated = false;
315local monster4_defeated = false;
316local monsters_defeated = false;
317
318local roam_zone1 = nil
319local roam_zone2 = nil
320local roam_zone3 = nil
321local roam_zone4 = nil
322
323function _CreateEnemies()
324    local enemy = nil
325
326    if (GlobalManager:GetGameEvents():DoesEventExist("story", "layna_forest_cave2_monsters_defeated")) then
327        monsters_defeated = true;
328    end
329
330    -- Monsters that can only be beaten once
331    -- Hint: left, right, top, bottom
332    roam_zone1 = vt_map.EnemyZone.Create(26, 30, 43, 50);
333    if (monsters_defeated == false) then
334        enemy = CreateEnemySprite(Map, "slime");
335        _SetBattleEnvironment(enemy);
336        enemy:NewEnemyParty();
337        enemy:AddEnemy(1);
338        enemy:AddEnemy(1);
339        enemy:AddEnemy(1);
340        enemy:AddEnemy(1);
341        enemy:AddEnemy(1);
342        roam_zone1:AddEnemy(enemy, 1);
343        roam_zone1:SetSpawnsLeft(1); -- This monster shall spawn only one time.
344    end
345
346    -- Hint: left, right, top, bottom
347    roam_zone2 = vt_map.EnemyZone.Create(35, 43, 13, 20);
348    if (monsters_defeated == false) then
349        enemy = CreateEnemySprite(Map, "slime");
350        _SetBattleEnvironment(enemy);
351        enemy:NewEnemyParty();
352        enemy:AddEnemy(1);
353        enemy:AddEnemy(2);
354        enemy:AddEnemy(1);
355        enemy:AddEnemy(2);
356        enemy:AddEnemy(1);
357        roam_zone2:AddEnemy(enemy, 1);
358        roam_zone2:SetSpawnsLeft(1); -- This monster shall spawn only one time.
359    end
360
361    roam_zone3 = vt_map.EnemyZone.Create(61, 67, 40, 48);
362    if (monsters_defeated == false) then
363        enemy = CreateEnemySprite(Map, "slime");
364        _SetBattleEnvironment(enemy);
365        enemy:NewEnemyParty();
366        enemy:AddEnemy(1);
367        enemy:AddEnemy(2);
368        enemy:AddEnemy(2);
369        enemy:AddEnemy(2);
370        enemy:AddEnemy(1);
371        roam_zone3:AddEnemy(enemy, 1);
372        roam_zone3:SetSpawnsLeft(1); -- This monster shall spawn only one time.
373    end
374
375    roam_zone4 = vt_map.EnemyZone.Create(89, 100, 12, 15);
376    if (monsters_defeated == false) then
377        enemy = CreateEnemySprite(Map, "bat");
378        _SetBattleEnvironment(enemy);
379        enemy:NewEnemyParty();
380        enemy:AddEnemy(6);
381        enemy:AddEnemy(2);
382        enemy:AddEnemy(6);
383        enemy:AddEnemy(2);
384        enemy:AddEnemy(1);
385        roam_zone4:AddEnemy(enemy, 1);
386        roam_zone4:SetSpawnsLeft(1); -- This monster shall spawn only one time.
387    end
388end
389
390-- check whether all the monsters dies, to open the door
391function _CheckMonstersStates()
392    if (monster1_defeated == false and roam_zone1:GetSpawnsLeft() == 0) then
393        monster1_defeated = true;
394    end
395
396    if (monster2_defeated == false and roam_zone2:GetSpawnsLeft() == 0) then
397        monster2_defeated = true;
398    end
399
400    if (monster3_defeated == false and roam_zone3:GetSpawnsLeft() == 0) then
401        monster3_defeated = true;
402    end
403
404    if (monster4_defeated == false and roam_zone4:GetSpawnsLeft() == 0) then
405        monster4_defeated = true;
406    end
407
408    -- Open the door when every monster is defeated, and set the event has done.
409    if (monsters_defeated == false
410            and monster1_defeated and monster2_defeated
411            and monster3_defeated and monster4_defeated) then
412        monsters_defeated = true;
413
414        blocking_rock:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
415        blocking_rock:SetVisible(false);
416        AudioManager:PlaySound("data/sounds/cave-in.ogg");
417        Effects:ShakeScreen(0.6, 1000, vt_mode_manager.EffectSupervisor.SHAKE_FALLOFF_GRADUAL);
418
419        hero:SetMoving(false);
420        -- Trigger the dialogue event about the shaking...
421        EventManager:StartEvent("Hero dialogue during tremor");
422
423        GlobalManager:GetGameEvents():SetEventValue("story", "layna_forest_cave2_monsters_defeated", 1);
424    end
425end
426
427-- zones
428local to_cave_1_1 = nil
429local to_cave_exit = nil
430local to_wolf_cave_zone = nil
431local seeing_the_exit_zone = nil
432
433-- Create the different map zones triggering events
434function _CreateZones()
435    -- N.B.: left, right, top, bottom
436    to_cave_1_1_zone = vt_map.CameraZone.Create(0, 1, 11, 16);
437
438    to_cave_exit_zone = vt_map.CameraZone.Create(108, 116, 95, 96);
439    to_cave_exit_zone:SetInteractionIcon("data/gui/map/exit_anim.lua")
440
441    to_wolf_cave_zone = vt_map.CameraZone.Create(122, 124, 12, 14);
442    seeing_the_exit_zone = vt_map.CameraZone.Create(99, 122, 80, 96);
443end
444
445-- Check whether the active camera has entered a zone. To be called within Update()
446function _CheckZones()
447    if (to_cave_1_1_zone:IsCameraEntering() == true) then
448        hero:SetMoving(false);
449        EventManager:StartEvent("to cave 1-1");
450    elseif (to_cave_exit_zone:IsCameraEntering() == true) then
451        hero:SetMoving(false);
452        EventManager:StartEvent("to south east exit");
453    elseif (to_wolf_cave_zone:IsCameraEntering() == true) then
454        hero:SetMoving(false);
455        EventManager:StartEvent("to wolf cave");
456    elseif (monsters_defeated == false
457            and GlobalManager:GetGameEvents():GetEventValue("story", "kalya_layna_forest_cave1_2_exit_dialogue_done") == 0) then
458        if (seeing_the_exit_zone:IsCameraEntering() == true and Map:CurrentState() == vt_map.MapMode.STATE_EXPLORE) then
459            EventManager:StartEvent("Kalya sees the cave exit");
460        end
461    end
462end
463
464-- Sets common battle environment settings for enemy sprites
465function _SetBattleEnvironment(enemy)
466    enemy:SetBattleMusicTheme("data/music/heroism-OGA-Edward-J-Blakeley.ogg");
467    enemy:SetBattleBackground("data/battles/battle_scenes/desert_cave/desert_cave.png");
468    -- Add the background and foreground animations
469    enemy:AddBattleScript("data/battles/battle_scenes/desert_cave_battle_anim.lua");
470end
471
472-- Map Custom functions
473-- Used through scripted events
474map_functions = {
475    Sprite_Collision_on = function(sprite)
476        if (sprite ~= nil) then
477            sprite:SetCollisionMask(vt_map.MapMode.ALL_COLLISION);
478        end
479    end,
480
481    Sprite_Collision_off = function(sprite)
482        if (sprite ~= nil) then
483            sprite:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
484        end
485    end,
486
487    Set_Camera = function(sprite)
488        if (sprite ~= nil) then Map:SetCamera(sprite, 800); end
489    end,
490
491    -- Kalya and Bronann read the engraved text
492    stone_sign_dialogue_start = function()
493        Map:PushState(vt_map.MapMode.STATE_SCENE);
494        hero:SetMoving(false);
495
496        bronann:SetPosition(hero:GetXPosition(), hero:GetYPosition());
497        bronann:SetDirection(hero:GetDirection())
498        Map:SetCamera(bronann)
499        bronann:SetVisible(true)
500        hero:SetVisible(false)
501        hero:SetPosition(0, 0)
502
503        kalya:SetVisible(true);
504        kalya:SetPosition(bronann:GetXPosition(), bronann:GetYPosition());
505        bronann:SetCollisionMask(vt_map.MapMode.ALL_COLLISION);
506        bronann:SetDirection(vt_map.MapMode.NORTH);
507        kalya:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
508
509        move_next_to_bronann_event:SetDestination(bronann:GetXPosition() + 2.0, bronann:GetYPosition(), false)
510    end,
511
512    stone_sign_image_start = function()
513        -- Trigger the display of the image.
514        GlobalManager:GetGameEvents():SetEventValue("story", "layna_forest_cave1_2_show_sign_image", 1)
515    end,
516
517    -- Returns true when the image has finished to display.
518    stone_sign_image_update = function()
519        if (GlobalManager:GetGameEvents():GetEventValue("story", "layna_forest_cave1_2_show_sign_image") == 0) then
520            return true;
521        end
522        return false;
523    end,
524
525    end_of_stone_sign_dialogue = function()
526        Map:PopState();
527        kalya:SetPosition(0, 0);
528        kalya:SetVisible(false);
529        kalya:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
530
531        hero:SetPosition(bronann:GetXPosition(), bronann:GetYPosition());
532        hero:SetDirection(bronann:GetDirection())
533        Map:SetCamera(hero)
534        hero:SetVisible(true)
535        bronann:SetVisible(false)
536        bronann:SetPosition(0, 0)
537
538        -- Set event as done
539        GlobalManager:GetGameEvents():SetEventValue("story", "kalya_stone_sign_dialogue_done", 1);
540        _UpdateStoneSignDialogue();
541    end,
542
543    -- Kalya and Bronann see the exit
544    see_the_exit_dialogue_start = function()
545        Map:PushState(vt_map.MapMode.STATE_SCENE);
546        hero:SetMoving(false);
547
548        bronann:SetPosition(hero:GetXPosition(), hero:GetYPosition());
549        bronann:SetDirection(hero:GetDirection())
550        Map:SetCamera(bronann)
551        bronann:SetVisible(true)
552        hero:SetVisible(false)
553        hero:SetPosition(0, 0)
554
555        kalya:SetVisible(true);
556        kalya:SetPosition(bronann:GetXPosition(), bronann:GetYPosition());
557        bronann:SetCollisionMask(vt_map.MapMode.ALL_COLLISION);
558        bronann:SetDirection(vt_map.MapMode.SOUTH);
559        kalya:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
560
561        move_next_to_bronann_event2:SetDestination(bronann:GetXPosition() + 2.0, bronann:GetYPosition(), false);
562    end,
563
564    end_of_exit_seen_dialogue = function()
565        kalya:SetPosition(0, 0);
566        kalya:SetVisible(false);
567        kalya:SetCollisionMask(vt_map.MapMode.NO_COLLISION);
568
569        hero:SetPosition(bronann:GetXPosition(), bronann:GetYPosition());
570        hero:SetDirection(bronann:GetDirection())
571        Map:SetCamera(hero)
572        hero:SetVisible(true)
573        bronann:SetVisible(false)
574        bronann:SetPosition(0, 0)
575
576        -- Set event as done
577        GlobalManager:GetGameEvents():SetEventValue("story", "kalya_layna_forest_cave1_2_exit_dialogue_done", 1);
578        Map:PopState();
579    end
580}
581