1-- Set the namespace according to the map name. 2local ns = {}; 3setmetatable(ns, {__index = _G}); 4layna_village_center_shop_script = ns; 5setfenv(1, ns); 6 7-- The map name, subname and location image 8map_name = "Mountain Village of Layna" 9map_image_filename = "data/story/common/locations/mountain_village.png" 10map_subname = "Flora's Boutique" 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 EventManager = nil 19 20-- The main character handlers 21local bronann = nil 22 23-- NPCs 24local flora = nil 25 26-- the main map loading code 27function Load(m) 28 29 Map = m; 30 EventManager = Map:GetEventSupervisor(); 31 32 Map:SetUnlimitedStamina(true); 33 34 _CreateCharacters(); 35 _CreateNPCs(); 36 _CreateObjects(); 37 38 -- Set the camera focus on bronann 39 Map:SetCamera(bronann); 40 41 _CreateEvents(); 42 _CreateZones(); 43 44 -- The only entrance close door sound 45 AudioManager:PlaySound("data/sounds/door_close.wav"); 46end 47 48function Update() 49 -- Check whether the character is in one of the zones 50 _CheckZones(); 51end 52 53-- Character creation 54function _CreateCharacters() 55 -- default position and direction 56 bronann = CreateSprite(Map, "Bronann", 32.0, 27.0, vt_map.MapMode.GROUND_OBJECT); 57 bronann:SetDirection(vt_map.MapMode.NORTH); 58 bronann:SetMovementSpeed(vt_map.MapMode.NORMAL_SPEED); 59end 60 61function _CreateNPCs() 62 local npc = CreateNPCSprite(Map, "Woman1", vt_system.Translate("Flora"), 39, 20, vt_map.MapMode.GROUND_OBJECT); 63 npc:SetDirection(vt_map.MapMode.SOUTH); 64 65 -- The npc is too far away from the Hero so we make an invisible doppelgänger 66 flora = CreateNPCSprite(Map, "Woman1", vt_system.Translate("Flora"), 39, 22, vt_map.MapMode.GROUND_OBJECT); 67 flora:SetVisible(false); 68 flora:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 69 _UpdateFloraDialogue(); 70end 71 72function _CreateObjects() 73 local object = nil 74 75 CreateObject(Map, "Flower Pot1", 41, 20, vt_map.MapMode.GROUND_OBJECT); 76 CreateObject(Map, "Flower Pot2", 35, 20, vt_map.MapMode.GROUND_OBJECT); 77 CreateObject(Map, "Table1", 27, 17, vt_map.MapMode.GROUND_OBJECT); 78 CreateObject(Map, "Table1", 33, 17, vt_map.MapMode.GROUND_OBJECT); 79 80 -- lights 81 object = CreateObject(Map, "Right Window Light 2", 41, 10, vt_map.MapMode.GROUND_OBJECT); 82 object:SetDrawOnSecondPass(true); -- Above any other ground object 83 object:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 84 85 object = CreateObject(Map, "Right Window Light 2", 41, 17, vt_map.MapMode.GROUND_OBJECT); 86 object:SetDrawOnSecondPass(true); -- Above any other ground object 87 object:SetCollisionMask(vt_map.MapMode.NO_COLLISION); 88end 89 90-- Creates all events and sets up the entire event sequence chain 91function _CreateEvents() 92 local event = nil 93 94 -- Triggered Events 95 vt_map.MapTransitionEvent.Create("to village", "data/story/layna_village/layna_village_center_map.lua", 96 "data/story/layna_village/layna_village_center_script.lua", "from_shop"); 97 98 event = vt_map.ShopEvent.Create("layna: open shop", "Flora's Shop"); 99 event:SetShopName(vt_system.UTranslate("Flora's Shop")); 100 101 -- Items 102 event:AddItem(1, 0); -- (infinite) Tiny Potion 103 event:AddItem(11, 0); -- (infinite) Tiny Moon Juice 104 event:AddItem(30003, 1); -- Tunic for Bronann 105 event:AddItem(30004, 1); -- Leather Cloak for Kalya 106 -- Trades 107 event:AddTrade(1, 0); -- (infinite) Small Potion 108 event:AddTrade(1001, 0); -- (infinite) Minor Elixirs 109 110 event:SetPriceLevels(vt_shop.ShopMode.SHOP_PRICE_VERY_GOOD, -- Flora is a good friend 111 vt_shop.ShopMode.SHOP_PRICE_STANDARD); 112 event:AddScript("data/story/layna_village/tutorial_shop_dialogs.lua"); 113 114 -- Quest events 115 vt_map.ScriptedEvent.Create("SetQuest1DialogueDone", "Quest1FloraDialogueDone", ""); 116 vt_map.ScriptedEvent.Create("Quest2: Talked to Flora", "Quest2FloraDialogueDone", ""); 117end 118 119-- zones 120local shop_exit_zone = nil 121 122function _CreateZones() 123 -- N.B.: left, right, top, bottom 124 shop_exit_zone = vt_map.CameraZone.Create(30, 34, 28, 29); 125end 126 127function _CheckZones() 128 if (shop_exit_zone:IsCameraEntering() == true) then 129 bronann:SetMoving(false); 130 EventManager:StartEvent("to village"); 131 -- The only entrance close door sound 132 AudioManager:PlaySound("data/sounds/door_open2.wav"); 133 end 134end 135 136-- Custom inner map functions 137function _UpdateFloraDialogue() 138 local dialogue = nil 139 local text = nil 140 141 flora:ClearDialogueReferences(); 142 143 if (GlobalManager:GetGameEvents():DoesEventExist("story", "Quest2_forest_event_done") == true) then 144 -- nothing special 145 elseif (GlobalManager:GetGameEvents():DoesEventExist("layna_center_shop", "quest1_flora_dialogue_done") == true) then 146 -- Just repeat the last dialogue sentence, when the dialogue is already done. 147 dialogue = vt_map.SpriteDialogue.Create("ep1_layna_village_flora_about_georges"); 148 text = vt_system.Translate("Just find Lilly and he should give you some barley meal, ok?"); 149 dialogue:AddLine(text, flora); 150 text = vt_system.Translate("She's probably walking her dog near the river at this time of the day."); 151 dialogue:AddLine(text, flora); 152 flora:AddDialogueReference(dialogue); 153 return; 154 elseif (GlobalManager:GetGameEvents():DoesEventExist("bronanns_home", "quest1_mother_start_dialogue_done") == true) then 155 dialogue = vt_map.SpriteDialogue.Create(); 156 text = vt_system.Translate("Hi Bronann! What can I do for you?"); 157 dialogue:AddLine(text, flora); 158 text = vt_system.Translate("Hi Flora! Do you have some barley meal left?"); 159 dialogue:AddLine(text, bronann); 160 text = vt_system.Translate("Oh sorry, our mayor came earlier and took all the rest of it."); 161 dialogue:AddLine(text, flora); 162 text = vt_system.Translate("Times are becoming harder now. We've got less food than before."); 163 dialogue:AddLine(text, flora); 164 text = vt_system.Translate("This is the first time that I've seen you wear such a worrisome expression."); 165 dialogue:AddLineEmote(text, bronann, "interrogation"); 166 text = vt_system.Translate("Nevermind. Don't worry about me. Just find Lilly and she should give you some, ok?"); 167 dialogue:AddLine(text, flora); 168 text = vt_system.Translate("She's probably walking her dog near the river at this time of the day."); 169 -- Set the quest dialogue as seen by the player. 170 dialogue:AddLineEvent(text, flora, "", "SetQuest1DialogueDone"); 171 flora:AddDialogueReference(dialogue); 172 return; 173 end 174 175 -- Default behaviour 176 dialogue = vt_map.SpriteDialogue.Create("ep1_layna_village_flora_default"); 177 text = vt_system.Translate("Hi Bronann! What can I do for you?"); 178 dialogue:AddLineEvent(text, flora, "", "layna: open shop"); 179 flora:AddDialogueReference(dialogue); 180end 181 182-- Map Custom functions 183map_functions = { 184 185 Quest1FloraDialogueDone = function() 186 GlobalManager:GetGameEvents():SetEventValue("layna_center_shop", "quest1_flora_dialogue_done", 1); 187 _UpdateFloraDialogue(); 188 end, 189 190 Quest2FloraDialogueDone = function() 191 GlobalManager:GetGameEvents():SetEventValue("story", "Quest2_flora_dialogue_done", 1); 192 end 193} 194