1-- Set the namespace according to the map name. 2local ns = {}; 3setmetatable(ns, {__index = _G}); 4layna_village_bronanns_home_script = ns; 5setfenv(1, ns); 6 7-- The map name, subname and location image 8map_name = "" 9map_image_filename = "" 10map_subname = "Bronann's home" 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/Caketown_1-OGA-mat-pablo.ogg" 15 16-- c++ objects instances 17local Map = nil 18local DialogueManager = nil 19local EventManager = nil 20local Effects = nil 21 22-- The main character handlers 23local bronann = nil 24local carson = nil 25local malta = nil 26local quest2_start_scene = false 27 28-- Used at the beginning to show the wooden sword when giving it to Bronann 29local wooden_sword = nil 30 31-- the main map loading code 32function Load(m) 33 34 Map = m; 35 DialogueManager = Map:GetDialogueSupervisor() 36 EventManager = Map:GetEventSupervisor() 37 Effects = Map:GetEffectSupervisor() 38 39 Map:SetUnlimitedStamina(true); 40 41 _CreateCharacters(); 42 _CreateNPCs(); 43 _CreateObjects(); 44 45 -- Set the camera focus on bronann 46 Map:SetCamera(bronann); 47 48 _CreateEvents(); 49 _CreateZones(); 50end 51 52function Update() 53 -- Check whether the character is in one of the zones 54 _CheckZones(); 55end 56 57 58-- Character creation 59function _CreateCharacters() 60 -- default position and direction 61 bronann = CreateSprite(Map, "Bronann", 46.5, 11.5, vt_map.MapMode.GROUND_OBJECT); 62 bronann:SetDirection(vt_map.MapMode.SOUTH); 63 bronann:SetMovementSpeed(vt_map.MapMode.NORMAL_SPEED); 64 65 -- set up the position according to the previous map 66 if (GlobalManager:GetMapData():GetPreviousLocation() == "from_village_center") then 67 bronann:SetPosition(39.5, 22.5); 68 bronann:SetDirection(vt_map.MapMode.NORTH); 69 AudioManager:PlaySound("data/sounds/door_close.wav"); 70 end 71end 72 73function _CreateNPCs() 74 local event = nil 75 local dialogue = nil 76 local text = nil 77 78 carson = CreateSprite(Map, "Carson", 33.5, 11.5, vt_map.MapMode.GROUND_OBJECT); 79 80 event = vt_map.RandomMoveSpriteEvent.Create("Dad random move", carson, 2000, 2000); 81 event:AddEventLinkAtEnd("Dad random move", 3000); -- Loop on itself 82 83 if (GlobalManager:GetGameEvents():DoesEventExist("story", "Quest2_forest_event_done") == true) then 84 -- Carson isn't here anymore 85 carson:SetVisible(false); 86 carson:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 87 carson:SetPosition(0, 0); 88 else 89 EventManager:StartEvent("Dad random move"); 90 end 91 92 _UpdateCarsonDialogue() 93 94 malta = CreateSprite(Map, "Malta", 33.1, 17.5, vt_map.MapMode.GROUND_OBJECT); 95 malta:SetDirection(vt_map.MapMode.SOUTH); 96 97 _UpdateMotherDialogue(); 98 99 -- Make her walk in front of the table to prepare the lunch. 100 event = vt_map.PathMoveSpriteEvent.Create("Kitchen: Mother goes middle", malta, 33.1, 19.9, false); 101 event:AddEventLinkAtEnd("Kitchen: Mother looks left"); 102 event = vt_map.ChangeDirectionSpriteEvent.Create("Kitchen: Mother looks left", malta, vt_map.MapMode.WEST); 103 event:AddEventLinkAtEnd("Kitchen: Mother goes right", 2000); 104 event = vt_map.PathMoveSpriteEvent.Create("Kitchen: Mother goes right", malta, 35, 19.9, false); 105 event:AddEventLinkAtEnd("Kitchen: Mother looks down"); 106 event = vt_map.ChangeDirectionSpriteEvent.Create("Kitchen: Mother looks down", malta, vt_map.MapMode.SOUTH); 107 event:AddEventLinkAtEnd("Kitchen: Mother goes middle 2", 2000); 108 event = vt_map.PathMoveSpriteEvent.Create("Kitchen: Mother goes middle 2", malta, 33.1, 19.9, false); 109 event:AddEventLinkAtEnd("Kitchen: Mother goes up"); 110 event = vt_map.PathMoveSpriteEvent.Create("Kitchen: Mother goes up", malta, 33.1, 17.5, false); 111 event:AddEventLinkAtEnd("Kitchen: Mother looks left 2"); 112 event = vt_map.ChangeDirectionSpriteEvent.Create("Kitchen: Mother looks left 2", malta, vt_map.MapMode.WEST); 113 event:AddEventLinkAtEnd("Kitchen: Mother goes middle", 2000); 114 115 -- The mother routine event 116 EventManager:StartEvent("Kitchen: Mother goes middle"); 117 118 -- The Hero's first noble quest briefing... 119 vt_map.ScriptedSpriteEvent.Create("Start Quest1", malta, "StartQuest1", ""); 120 121 event = vt_map.ChangeDirectionSpriteEvent.Create("Quest1: Mother looks south", malta, vt_map.MapMode.SOUTH); 122 event:AddEventLinkAtEnd("Mother calls Bronann"); 123 124 dialogue = vt_map.SpriteDialogue.Create(); 125 text = vt_system.Translate("Bronann!"); 126 dialogue:AddLine(text, malta); 127 128 event = vt_map.DialogueEvent.Create("Mother calls Bronann", dialogue); 129 event:SetStopCameraMovement(true); 130 event:AddEventLinkAtEnd("SetCameraOnMother"); 131 event:AddEventLinkAtEnd("BronannLooksUp"); 132 133 vt_map.ChangeDirectionSpriteEvent.Create("BronannLooksUp", bronann, vt_map.MapMode.NORTH); 134 135 event = vt_map.ScriptedSpriteEvent.Create("SetCameraOnMother", malta, "Map_SetCamera", ""); 136 event:AddEventLinkAtEnd("ClearDialogueRefOnMother"); 137 138 event = vt_map.ScriptedSpriteEvent.Create("ClearDialogueRefOnMother", malta, "ClearDialogueReferences", ""); 139 event:AddEventLinkAtEnd("Mother moves near entrance1"); 140 141 event = vt_map.PathMoveSpriteEvent.Create("Mother moves near entrance1", malta, 38, 19, false); 142 event:AddEventLinkAtEnd("MotherLooksSouth2"); 143 144 event = vt_map.ChangeDirectionSpriteEvent.Create("MotherLooksSouth2", malta, vt_map.MapMode.SOUTH); 145 event:AddEventLinkAtEnd("Mother quest1 dialogue"); 146 147 dialogue = vt_map.SpriteDialogue.Create(); 148 text = vt_system.Translate("Now that you're *finally* up, could you go buy some barley meal for us?"); 149 dialogue:AddLine(text, malta); 150 text = vt_system.Translate("Barley meal? Again?"); 151 dialogue:AddLineEmote(text, bronann, "sweat drop"); 152 text = vt_system.Translate("Hmph, just go boy. You'll be free after that, ok?"); 153 dialogue:AddLine(text, malta); 154 155 event = vt_map.DialogueEvent.Create("Mother quest1 dialogue", dialogue); 156 event:AddEventLinkAtEnd("Map_PopState"); 157 event:AddEventLinkAtEnd("SetQuest1DialogueDone"); 158 event:AddEventLinkAtEnd("SetCameraOnBronann"); 159 event:AddEventLinkAtEnd("Kitchen: Mother goes middle", 300); 160 161 -- Common events. 162 -- Pop Map state 163 vt_map.ScriptedEvent.Create("Map_PopState", "Map_PopState", ""); 164 165 -- Set the opening dialogue as done 166 vt_map.ScriptedEvent.Create("SetQuest1DialogueDone", "Quest1MotherStartDialogueDone", ""); 167 168 vt_map.ScriptedSpriteEvent.Create("SetCameraOnBronann", bronann, "Map_SetCamera", ""); 169end 170 171 172function _CreateObjects() 173 local object = nil 174 175 CreateObject(Map, "Chair1", 47, 18, vt_map.MapMode.GROUND_OBJECT); 176 177 CreateObject(Map, "Chair1_inverted", 41, 18, vt_map.MapMode.GROUND_OBJECT); 178 CreateObject(Map, "Chair1_north", 44, 15.3, vt_map.MapMode.GROUND_OBJECT); 179 CreateObject(Map, "Table1", 44, 19, vt_map.MapMode.GROUND_OBJECT); 180 CreateObject(Map, "Barrel1", 31, 14, vt_map.MapMode.GROUND_OBJECT); 181 CreateObject(Map, "Vase1", 31, 16, vt_map.MapMode.GROUND_OBJECT); 182 CreateObject(Map, "Flower Pot1", 48.5, 11, vt_map.MapMode.GROUND_OBJECT); 183 CreateObject(Map, "Flower Pot1", 31, 9, vt_map.MapMode.GROUND_OBJECT); 184 185 --lights 186 object = CreateObject(Map, "Left Window Light 2", 31, 15, vt_map.MapMode.GROUND_OBJECT); 187 object:SetDrawOnSecondPass(true); -- Above any other ground object 188 object:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 189 190 object = CreateObject(Map, "Right Window Light 2", 49, 15, vt_map.MapMode.GROUND_OBJECT); 191 object:SetDrawOnSecondPass(true); -- Above any other ground object 192 object:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 193 194 -- Turn the food and dishes are objects to permit the update of their visible status. 195 plate_pile = CreateObject(Map, "Plate Pile1", 31, 22, vt_map.MapMode.GROUND_OBJECT); 196 salad = CreateObject(Map, "Salad1", 31, 18, vt_map.MapMode.GROUND_OBJECT); 197 green_pepper = CreateObject(Map, "Green Pepper1", 31, 20, vt_map.MapMode.GROUND_OBJECT); 198 bread = CreateObject(Map, "Bread1", 31, 22, vt_map.MapMode.GROUND_OBJECT); 199 sauce_pot = CreateObject(Map, "Sauce Pot1", 33, 22, vt_map.MapMode.GROUND_OBJECT); 200 knife = CreateObject(Map, "Knife1", 35, 22, vt_map.MapMode.GROUND_OBJECT); 201 202 -- The wooden sword sprite 203 wooden_sword = CreateObject(Map, "Wooden Sword1", 1, 1, vt_map.MapMode.GROUND_OBJECT); 204 wooden_sword:SetVisible(false); 205 wooden_sword:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 206 207 _UpdateDishesAndFood(); 208end 209 210-- Creates all events and sets up the entire event sequence chain 211function _CreateEvents() 212 local event = nil 213 local text = nil 214 local dialogue = nil 215 216 -- Triggered Events 217 vt_map.MapTransitionEvent.Create("to village", "data/story/layna_village/layna_village_center_map.lua", 218 "data/story/layna_village/layna_village_center_script.lua", "from_bronanns_home"); 219 220 vt_map.MapTransitionEvent.Create("to Bronann's 1st floor", "data/story/layna_village/layna_village_bronanns_home_first_floor_map.lua", 221 "data/story/layna_village/layna_village_bronanns_home_first_floor_script.lua", "from_bronanns_home"); 222 223 -- Generic events 224 vt_map.ScriptedEvent.Create("Audio:FadeOutMusic()", "Audio_FadeOutMusic", ""); 225 vt_map.ScriptedEvent.Create("Audio:ResumeMusic()", "Audio_ResumeMusic", ""); 226 227 vt_map.ChangeDirectionSpriteEvent.Create("Carson looks west", carson, vt_map.MapMode.WEST) 228 vt_map.ChangeDirectionSpriteEvent.Create("Carson looks east", carson, vt_map.MapMode.EAST) 229 vt_map.ChangeDirectionSpriteEvent.Create("Carson looks north", carson, vt_map.MapMode.NORTH) 230 vt_map.ChangeDirectionSpriteEvent.Create("Malta looks west", malta, vt_map.MapMode.WEST) 231 vt_map.ChangeDirectionSpriteEvent.Create("Malta looks east", malta, vt_map.MapMode.EAST) 232 vt_map.ChangeDirectionSpriteEvent.Create("Malta looks north", malta, vt_map.MapMode.NORTH) 233 vt_map.ChangeDirectionSpriteEvent.Create("Bronann looks west", bronann, vt_map.MapMode.WEST) 234 vt_map.ChangeDirectionSpriteEvent.Create("Bronann looks east", bronann, vt_map.MapMode.EAST) 235 vt_map.ChangeDirectionSpriteEvent.Create("Bronann looks north", bronann, vt_map.MapMode.NORTH) 236 vt_map.ChangeDirectionSpriteEvent.Create("Bronann looks south", bronann, vt_map.MapMode.SOUTH) 237 238 vt_map.LookAtSpriteEvent.Create("Carson looks at Bronann", carson, bronann) 239 240 -- Quest events 241 242 -- End quest 1 (Barley meal retrieval) and prepare map for what's next. 243 event = vt_map.ScriptedEvent.Create("Quest1: end and transition to after-dinner", "Quest1Done", ""); 244 event:AddEventLinkAtEnd("Quest1: Terminate mother and father events"); 245 246 event = vt_map.ScriptedEvent.Create("Quest1: Terminate mother and father events", "TerminateMotherAndFatherEvents", ""); 247 event:AddEventLinkAtEnd("Fade out to after dinner"); 248 249 event = vt_map.ScriptedEvent.Create("Fade out to after dinner", "FadeOutToAfterDinner", "CheckFadeInOrOut"); 250 event:AddEventLinkAtEnd("Fade in to after dinner"); 251 252 event = vt_map.ScriptedEvent.Create("Fade in to after dinner", "FadeInToAfterDinner", "CheckFadeInOrOut"); 253 event:AddEventLinkAtEnd("Bronann is told the truth - part 1"); 254 event:AddEventLinkAtEnd("Carson looks west"); 255 256 -- Quest 2 start: Bronann is told the truth 257 dialogue = vt_map.SpriteDialogue.Create(); 258 text = vt_system.Translate("Thanks for helping me out with the dishes.") 259 dialogue:AddLine(text, malta) 260 text = vt_system.Translate("Say, mom? Why is the village entrance blocked?") 261 dialogue:AddLineEventEmote(text, bronann, "", "Bronann looks at both parents", "thinking dots") 262 text = vt_system.Translate("...") 263 dialogue:AddLineEmote(text, malta, "sweat drop") 264 event = vt_map.DialogueEvent.Create("Bronann is told the truth - part 1", dialogue) 265 -- Make a pause here 266 event:AddEventLinkAtEnd("Carson looks south to think") 267 event:AddEventLinkAtEnd("Audio:FadeOutMusic()") 268 269 vt_map.AnimateSpriteEvent.Create("Bronann looks at both parents", bronann, "searching", 1000) 270 271 event = vt_map.ChangeDirectionSpriteEvent.Create("Carson looks south to think", carson, vt_map.MapMode.SOUTH) 272 event:AddEventLinkAtEnd("Carson looks at Bronann for part 2", 2000) 273 274 event = vt_map.LookAtSpriteEvent.Create("Carson looks at Bronann for part 2", carson, bronann) 275 event:AddEventLinkAtEnd("Bronann is told the truth - part 2") 276 277 dialogue = vt_map.SpriteDialogue.Create() 278 text = vt_system.Translate("All of the village elders' nerves are on edge. There is something going on here! Why won't you tell me?") 279 dialogue:AddLineEmote(text, bronann, "interrogation") 280 text = vt_system.Translate("Bronann, there is something we, your mother and I, have to tell you.") 281 dialogue:AddLine(text, carson) 282 text = vt_system.Translate("Sorry son. In fact, we've been willing to tell you since quite a lot of time now.") 283 dialogue:AddLineEmote(text, carson, "thinking dots") 284 -- tr: sentence is cut on purpose 285 text = vt_system.Translate("We chose to live in this village for a reason, we ") 286 dialogue:AddLineEvent(text, malta, "Malta looks at Bronann", "") 287 event = vt_map.DialogueEvent.Create("Bronann is told the truth - part 2", dialogue) 288 event:AddEventLinkAtEnd("Bright light") 289 event:AddEventLinkAtEnd("Bronann looks east", 500) 290 event:AddEventLinkAtEnd("Carson looks north", 600) 291 event:AddEventLinkAtEnd("Malta looks west", 800) 292 event:AddEventLinkAtEnd("Bronann looks west", 1000) 293 event:AddEventLinkAtEnd("Malta looks east", 1200) 294 event:AddEventLinkAtEnd("Carson looks west", 1300) 295 event:AddEventLinkAtEnd("Bronann looks south", 2900) 296 event:AddEventLinkAtEnd("Malta looks at Bronann", 3100) 297 event:AddEventLinkAtEnd("Carson looks at Bronann", 3200) 298 299 event = vt_map.ChangeDirectionSpriteEvent.Create("Malta looks at Bronann", malta, vt_map.MapMode.NORTH) 300 301 event = vt_map.ScriptedEvent.Create("Bright light", "BrightLightStart", "BrightLightUpdate") 302 event:AddEventLinkAtEnd("Bronann wonders what was that", 500) 303 event:AddEventLinkAtEnd("Bronann looks at both parents") 304 305 dialogue = vt_map.SpriteDialogue.Create() 306 text = vt_system.Translate("Huh? What was that light?") 307 dialogue:AddLineEmote(text, bronann, "interrogation") 308 text = vt_system.Translate("Bronann! Wait!") 309 dialogue:AddLine(text, carson) 310 event = vt_map.DialogueEvent.Create("Bronann wonders what was that", dialogue) 311 event:AddEventLinkAtEnd("Bronann runs out of the house") 312 event:AddEventLinkAtEnd("Carson goes after Bronann", 200) 313 314 -- Make Bronann leave house 315 event = vt_map.PathMoveSpriteEvent.Create("Bronann runs out of the house", bronann, 40, 24.5, true) 316 event:AddEventLinkAtEnd("Bronann disappears after running out of the house") 317 318 vt_map.PathMoveSpriteEvent.Create("Carson goes after Bronann", carson, 40, 22, false) 319 320 event = vt_map.ScriptedSpriteEvent.Create("Bronann disappears after running out of the house", bronann, "MakeInvisible", "") 321 event:AddEventLinkAtEnd("Map_PopState") 322 event:AddEventLinkAtEnd("Set Meal Event done") 323 event:AddEventLinkAtEnd("to village") 324 325 vt_map.ScriptedEvent.Create("Set Meal Event done", "SetMealEventDone", "") 326end 327 328-- zones 329local home_exit_zone = nil 330local to_bronanns_room_zone = nil 331 332function _CreateZones() 333 -- N.B.: left, right, top, bottom 334 home_exit_zone = vt_map.CameraZone.Create(38, 41, 24, 25); 335 to_bronanns_room_zone = vt_map.CameraZone.Create(44, 47, 8, 9); 336 337 quest2_start_scene = false; 338end 339 340function _CheckZones() 341 -- Don't check that zone when dealing with the quest 2 start scene. 342 if (quest2_start_scene == false and home_exit_zone:IsCameraEntering() == true) then 343 -- Prevent Bronann from exiting until his mother talked to him 344 if (GlobalManager:GetGameEvents():DoesEventExist("bronanns_home", "quest1_mother_start_dialogue_done") == false) then 345 Map:PushState(vt_map.MapMode.STATE_SCENE); 346 EventManager:StartEvent("Start Quest1"); 347 else 348 EventManager:StartEvent("to village"); 349 AudioManager:PlaySound("data/sounds/door_open2.wav"); 350 end 351 end 352 if (to_bronanns_room_zone:IsCameraEntering() == true) then 353 EventManager:StartEvent("to Bronann's 1st floor"); 354 end 355end 356 357-- Internal Custom functions 358function _UpdateDishesAndFood() 359 if (GlobalManager:GetGameEvents():DoesEventExist("story", "Quest2_started") == true) then 360 -- Show the plate pile, hide the rest 361 plate_pile:SetVisible(true); 362 plate_pile:SetCollisionMask(vt_map.MapMode.ALL_COLLISION); 363 364 salad:SetVisible(false); 365 salad:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 366 green_pepper:SetVisible(false); 367 green_pepper:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 368 bread:SetVisible(false); 369 bread:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 370 sauce_pot:SetVisible(false); 371 sauce_pot:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 372 knife:SetVisible(false); 373 knife:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 374 else 375 -- Show the food, hide the plate pile 376 plate_pile:SetVisible(false); 377 plate_pile:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 378 379 salad:SetVisible(true); 380 salad:SetCollisionMask(vt_map.MapMode.ALL_COLLISION); 381 green_pepper:SetVisible(true); 382 green_pepper:SetCollisionMask(vt_map.MapMode.ALL_COLLISION); 383 bread:SetVisible(true); 384 bread:SetCollisionMask(vt_map.MapMode.ALL_COLLISION); 385 sauce_pot:SetVisible(true); 386 sauce_pot:SetCollisionMask(vt_map.MapMode.ALL_COLLISION); 387 knife:SetVisible(true); 388 knife:SetCollisionMask(vt_map.MapMode.ALL_COLLISION); 389 end 390end 391 392function _UpdateCarsonDialogue() 393 local dialogue = nil 394 local text = nil 395 local event = nil 396 397 carson:ClearDialogueReferences() 398 399 if (GlobalManager:GetGameEvents():DoesEventExist("story", "well_rats_beaten") == true) then 400 dialogue = vt_map.SpriteDialogue.Create() 401 text = vt_system.Translate("Nice job, son.") 402 dialogue:AddLine(text, carson) 403 carson:AddDialogueReference(dialogue) 404 return; 405 elseif (GlobalManager:GetGameEvents():DoesEventExist("story", "Carson_wooden_sword_given") == true) then 406 dialogue = vt_map.SpriteDialogue.Create() 407 text = vt_system.Translate("Please go and see Olivia. She will explain everything to you.") 408 dialogue:AddLine(text, carson) 409 carson:AddDialogueReference(dialogue) 410 return; 411 else 412 -- Show sword event 413 -- First dialogue - speaks of Olivia's quest 414 dialogue = vt_map.SpriteDialogue.Create() 415 text = vt_system.Translate("Hey son! Did you sleep well? Hmm, now where did I leave that oil lamp?") 416 dialogue:AddLine(text, carson); 417 text = vt_system.Translate("Hi Dad! Um, I don't know. Sorry.") 418 dialogue:AddLineEmote(text, bronann, "thinking dots") 419 text = vt_system.Translate("Nah, no problem, I'll find it somewhere, eventually.") 420 dialogue:AddLine(text, carson) 421 text = vt_system.Translate("By the way, I have great news for you, son.") 422 dialogue:AddLine(text, carson) 423 text = vt_system.Translate("Something you've been waiting for. Come here I'll show you.") 424 dialogue:AddLine(text, carson) 425 dialogue:SetEventAtDialogueEnd("Show sword start event") 426 carson:AddDialogueReference(dialogue) 427 428 event = vt_map.ScriptedEvent.Create("Show sword start event", "StartSwordShowScene", "") 429 event:AddEventLinkAtEnd("Bronann goes in front of Carson") 430 event:AddEventLinkAtEnd("Carson goes in front of Bronann") 431 432 event = vt_map.PathMoveSpriteEvent.Create("Carson goes in front of Bronann", carson, 34, 12, false) 433 event:AddEventLinkAtEnd("Carson looks at Bronann 2") 434 vt_map.ChangeDirectionSpriteEvent.Create("Carson looks at Bronann 2", carson, vt_map.MapMode.EAST) 435 436 event = vt_map.PathMoveSpriteEvent.Create("Bronann goes in front of Carson", bronann, 36, 12, false) 437 event:AddEventLinkAtEnd("Bronann looks at Carson") 438 439 event = vt_map.ChangeDirectionSpriteEvent.Create("Bronann looks at Carson", bronann, vt_map.MapMode.WEST) 440 event:AddEventLinkAtEnd("Carson gives sword to Bronann dialogue") 441 442 dialogue = vt_map.SpriteDialogue.Create() 443 text = vt_system.Translate("Today, you're going to help Olivia with this.") 444 dialogue:AddLineEvent(text, carson, "", "Show sword event") 445 vt_map.DialogueEvent.Create("Carson gives sword to Bronann dialogue", dialogue) 446 447 -- Show Wooden Sword 448 event = vt_map.ScriptedEvent.Create("Show sword event", "ShowSwordEvent", "ShowSwordEventUpdate") 449 event:AddEventLinkAtEnd("Carson gives sword part 2") 450 451 dialogue = vt_map.SpriteDialogue.Create() 452 text = vt_system.Translate("Wow, your practice sword. Many thanks Dad.") 453 dialogue:AddLineEmote(text, bronann, "exclamation") 454 text = vt_system.Translate("Your mother and I believe you've now grown enough to start dealing with the critters around the village.") 455 dialogue:AddLineEvent(text, carson, "", "Carson hide sword event") 456 vt_map.DialogueEvent.Create("Carson gives sword part 2", dialogue) 457 458 -- Hide Wooden Sword 459 event = vt_map.ScriptedEvent.Create("Carson hide sword event", "HideSwordEvent", "") 460 event:AddEventLinkAtEnd("Add the wooden sword in inventory") 461 462 event = vt_map.TreasureEvent.Create("Add the wooden sword in inventory"); 463 event:AddItem(10001, 1); -- The wooden sword item 464 event:AddEventLinkAtEnd("Carson gives sword part 3"); 465 466 dialogue = vt_map.SpriteDialogue.Create() 467 text = vt_system.Translate("Go see Olivia. She will explain everything to you.") 468 dialogue:AddLineEvent(text, carson, "", "End Sword Giving scene event") 469 vt_map.DialogueEvent.Create("Carson gives sword part 3", dialogue) 470 471 event = vt_map.ScriptedEvent.Create("End Sword Giving scene event", "EndSwordShowEvent", "") 472 end 473end 474 475function _UpdateMotherDialogue() 476 local dialogue = nil 477 local text = nil 478 local event = nil 479 480 malta:ClearDialogueReferences(); 481 482 if (GlobalManager:GetGameEvents():DoesEventExist("story", "Malta_Items_given") == true) then 483 dialogue = vt_map.SpriteDialogue.Create(); 484 text = vt_system.Translate("Bronann, promise me that you'll be careful, ok?"); 485 dialogue:AddLine(text, malta); 486 malta:AddDialogueReference(dialogue); 487 return; 488 end 489 if (GlobalManager:GetGameEvents():DoesEventExist("story", "Quest2_forest_event_done") == true) then 490 -- Bronann'mother gives some items to Bronann. 491 dialogue = vt_map.SpriteDialogue.Create(); 492 text = vt_system.Translate("So, finally you're going away."); 493 dialogue:AddLineEmote(text, malta, "thinking dots"); 494 text = vt_system.Translate("Please, take this. It's not much but I hope it will help."); 495 dialogue:AddLineEvent(text, malta, "", "Prepare item giving scene"); 496 malta:AddDialogueReference(dialogue); 497 498 event = vt_map.ScriptedEvent.Create("Prepare item giving scene", "StartItemGivingScene", ""); 499 event:AddEventLinkAtEnd("Malta gives items") 500 501 event = vt_map.TreasureEvent.Create("Malta gives items"); 502 event:AddItem(16, 1) -- Candy 503 event:AddItem(11, 2) -- Tiny Moon Juice 504 event:AddItem(15, 1) -- Lotus Petal 505 event:AddEventLinkAtEnd("Bronann says thanks") 506 507 dialogue = vt_map.SpriteDialogue.Create(); 508 text = vt_system.Translate("Thanks, mom."); 509 dialogue:AddLine(text, bronann); 510 text = vt_system.Translate("Take care, my son."); 511 dialogue:AddLine(text, malta); 512 event = vt_map.DialogueEvent.Create("Bronann says thanks", dialogue) 513 event:AddEventLinkAtEnd("Update Malta's dialogue after giving items"); 514 515 event = vt_map.ScriptedEvent.Create("Update Malta's dialogue after giving items", "EndItemGivingScene", ""); 516 return; 517 end 518 if (GlobalManager:GetGameEvents():DoesEventExist("story", "quest1_barley_meal_done") == true 519 and GlobalManager:GetGameEvents():DoesEventExist("story", "well_rats_beaten") == true) then 520 -- Got some barley meal, Mom! 521 dialogue = vt_map.SpriteDialogue.Create(); 522 text = vt_system.Translate("(sigh)... Got it, mom!"); 523 dialogue:AddLine(text, bronann); 524 text = vt_system.Translate("Perfect timing, let's have dinner."); 525 dialogue:AddLineEvent(text, malta, "", "Quest1: end and transition to after-dinner"); 526 malta:AddDialogueReference(dialogue); 527 elseif (GlobalManager:GetGameEvents():DoesEventExist("story", "quest1_barley_meal_done") == true 528 and GlobalManager:GetGameEvents():DoesEventExist("story", "well_rats_beaten") == false) then 529 -- Still dad's quest to do 530 dialogue = vt_map.SpriteDialogue.Create(); 531 text = vt_system.Translate("(sigh)... Got it, mom!"); 532 dialogue:AddLine(text, bronann); 533 text = vt_system.Translate("Perfect timing, I'll cook dinner. Have you helped your father yet?"); 534 dialogue:AddLine(text, malta); 535 malta:AddDialogueReference(dialogue); 536 elseif (GlobalManager:GetGameEvents():DoesEventExist("bronanns_home", "quest1_mother_start_dialogue_done") == true) then 537 -- 1st quest dialogue 538 dialogue = vt_map.SpriteDialogue.Create("ep1_bronann_home_talk_about_barley_meal"); 539 text = vt_system.Translate("Could you go and buy some barley meal for the three of us?"); 540 dialogue:AddLine(text, malta); 541 malta:AddDialogueReference(dialogue); 542 elseif (GlobalManager:GetGameEvents():DoesEventExist("bronanns_home", "quest1_mother_start_dialogue_done") == false) then 543 -- Begining dialogue 544 dialogue = vt_map.SpriteDialogue.Create("ep1_bronann_home_talk_with_mother1"); 545 text = vt_system.Translate("Hi son, did you have a nightmare again last night?"); 546 dialogue:AddLine(text, malta); 547 text = vt_system.Translate("Hi mom. Huh, how did you know?"); 548 dialogue:AddLineEmote(text, bronann, "interrogation"); 549 text = vt_system.Translate("Eh eh? Have you already forgotten that I'm your mother?"); 550 dialogue:AddLine(text, malta); 551 malta:AddDialogueReference(dialogue); 552 else 553 -- Last default dialogue 554 dialogue = vt_map.SpriteDialogue.Create(); 555 text = vt_system.Translate("Don't venture too far, I'll need your help soon!"); 556 dialogue:AddLine(text, malta); 557 malta:AddDialogueReference(dialogue); 558 end 559end 560 561-- Handle sword location 562local wooden_sword_x_offset_start = 0.5 563local wooden_sword_x_offset = 0 564 565-- Light event 566local bright_light_time = 0.0 567local bright_light_color = vt_video.Color(1.0, 1.0, 1.0, 1.0); 568 569-- Map Custom functions 570map_functions = { 571 572 Map_PopState = function() 573 Map:PopState(); 574 end, 575 576 Map_SetCamera = function(sprite) 577 Map:SetCamera(sprite, 800); 578 end, 579 580 Audio_FadeOutMusic = function() 581 AudioManager:FadeOutActiveMusic(2000); 582 end, 583 584 MakeInvisible = function(sprite) 585 if (sprite ~= nil) then 586 sprite:SetVisible(false); 587 sprite:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 588 end 589 end, 590 591 ClearDialogueReferences = function(sprite) 592 sprite:ClearDialogueReferences(); 593 end, 594 595 StartQuest1 = function(sprite) 596 EventManager:EndAllEvents(sprite); 597 sprite:SetMoving(false); -- in case she's moving 598 EventManager:StartEvent("Quest1: Mother looks south"); 599 end, 600 601 Quest1MotherStartDialogueDone = function() 602 GlobalManager:GetGameEvents():SetEventValue("bronanns_home", "quest1_mother_start_dialogue_done", 1); 603 _UpdateMotherDialogue(); 604 GlobalManager:GetGameQuests():AddQuestLog("get_barley"); 605 end, 606 607 Quest1Done = function() 608 GlobalManager:GetGameEvents():SetEventValue("story", "Quest1_done", 1); 609 end, 610 611 TerminateMotherAndFatherEvents = function() 612 -- Start scene 613 Map:PushState(vt_map.MapMode.STATE_SCENE); 614 -- Stop everyone 615 carson:SetMoving(false); 616 carson:ClearDialogueReferences(); 617 EventManager:EndAllEvents(carson); 618 malta:SetMoving(false); 619 malta:ClearDialogueReferences(); 620 EventManager:EndAllEvents(malta); 621 622 bronann:SetMoving(false); 623 end, 624 625 FadeOutToAfterDinner = function() 626 VideoManager:FadeScreen(vt_video.Color(0.0, 0.0, 0.0, 1.0), 1000); 627 end, 628 629 CheckFadeInOrOut = function() 630 if (VideoManager:IsFading() == true) then 631 return false; 632 end 633 return true; 634 end, 635 636 FadeInToAfterDinner = function() 637 -- Place characters 638 bronann:SetPosition(41.5, 15.0); 639 bronann:SetDirection(vt_map.MapMode.SOUTH); 640 641 malta:SetPosition(40, 19); 642 malta:SetDirection(vt_map.MapMode.EAST); 643 carson:SetPosition(48, 19); 644 carson:SetDirection(vt_map.MapMode.WEST); 645 646 -- Remove the barley meal key item from inventory 647 local barley_meal_item_id = 70002; 648 local inventory_handler = GlobalManager:GetInventoryHandler() 649 if (inventory_handler:IsItemInInventory(barley_meal_item_id) == true) then 650 inventory_handler:RemoveFromInventory(barley_meal_item_id); 651 end 652 653 -- Set the quest 2 as started 654 GlobalManager:GetGameEvents():SetEventValue("story", "Quest2_started", 1) 655 -- Make the food and dishes not appear anymore, once the dinner is done. 656 _UpdateDishesAndFood(); 657 658 VideoManager:FadeIn(1000); 659 660 -- Flag used to disable the warp zone temporarily 661 quest2_start_scene = true; 662 end, 663 664 StartItemGivingScene = function() 665 Map:PushState(vt_map.MapMode.STATE_SCENE); 666 EventManager:EndAllEvents(malta); 667 bronann:SetMoving(false); 668 end, 669 670 EndItemGivingScene = function() 671 GlobalManager:GetGameEvents():SetEventValue("story", "Malta_Items_given", 1); 672 _UpdateMotherDialogue() 673 Map:PopState() 674 end, 675 676 StartSwordShowScene = function() 677 Map:PushState(vt_map.MapMode.STATE_SCENE) 678 EventManager:EndAllEvents(carson) 679 carson:SetMoving(false) 680 bronann:SetMoving(false) 681 end, 682 683 ShowSwordEvent = function() 684 -- Show sword 685 wooden_sword:SetPosition(carson:GetXPosition() + wooden_sword_x_offset_start, carson:GetYPosition() - 1.0); 686 wooden_sword_x_offset = wooden_sword_x_offset_start 687 wooden_sword:SetVisible(true) 688 end, 689 690 ShowSwordEventUpdate = function() 691 -- Move sword slowly to Bronann 692 local update_x = SystemManager:GetUpdateTime() / 200.0 693 wooden_sword_x_offset = wooden_sword_x_offset + update_x 694 wooden_sword:SetPosition(carson:GetXPosition() + wooden_sword_x_offset, carson:GetYPosition() - 1.0); 695 if (wooden_sword_x_offset < 1.0) then 696 return false 697 else 698 return true 699 end 700 end, 701 702 HideSwordEvent = function() 703 -- Hide sword 704 wooden_sword:SetVisible(false); 705 wooden_sword:SetPosition(0.0, 0.0); 706 end, 707 708 EndSwordShowEvent = function() 709 GlobalManager:GetGameEvents():SetEventValue("story", "Carson_wooden_sword_given", 1) 710 _UpdateCarsonDialogue() 711 Map:PopState() 712 EventManager:StartEvent("Dad random move") 713 end, 714 715 BrightLightStart = function() 716 bright_light_time = 0.0; 717 Effects:ShakeScreen(0.6, 6000, vt_mode_manager.EffectSupervisor.SHAKE_FALLOFF_GRADUAL); 718 AudioManager:PlaySound("data/sounds/rumble.wav"); 719 AudioManager:FadeOutActiveMusic(2000); 720 end, 721 722 BrightLightUpdate = function() 723 bright_light_time = bright_light_time + 2.5 * SystemManager:GetUpdateTime(); 724 725 if (bright_light_time < 5000.0) then 726 bright_light_color:SetAlpha(bright_light_time / 5000.0); 727 Map:GetEffectSupervisor():EnableLightingOverlay(bright_light_color); 728 return false; 729 end 730 731 if (bright_light_time < 10000) then 732 bright_light_color:SetAlpha((10000.0 - bright_light_time) / 5000.0); 733 Map:GetEffectSupervisor():EnableLightingOverlay(bright_light_color); 734 return false; 735 end 736 737 -- end of the two-step fade in and out 738 return true; 739 end, 740 741 MakeInvisible = function(sprite) 742 if (sprite ~= nil) then 743 sprite:SetVisible(false); 744 sprite:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 745 end 746 end, 747 748 SetMealEventDone = function() 749 GlobalManager:GetGameEvents():SetEventValue("story", "meal_event_done", 1) 750 end 751} 752