home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / Dema / ankh_demo_en.exe / media / lua / template.lua < prev   
Encoding:
Text File  |  2005-09-14  |  9.9 KB  |  247 lines

  1. -----------------------------------------------------------------------
  2. -- the table where all the functions/methods go to
  3. -----------------------------------------------------------------------
  4. %1 = {
  5.    quest,
  6.    name,
  7.    locations,
  8.    iactors,
  9.    triggers,
  10.    conversations,
  11.    cutscenes,
  12.    checklist
  13. }
  14. -----------------------------------------------------------------------
  15.  
  16. -----------------------------------------------------------------------
  17. -- init function
  18. -----------------------------------------------------------------------
  19. function %1:init()
  20.    local questName = "%1"
  21.    -- the quest object stores the C++ object pointer (Quest object)
  22.    self.quest = QuestMgr:createQuest(questName)
  23.    self.name  = questName
  24.    
  25.    -- the locations associated with this quest
  26.    self.locations = {
  27.    }
  28.  
  29.    -- the interactor objects associated with this quest
  30.    self.iactors = {  
  31.    }
  32.  
  33.    -- the conversations associated with this quest
  34.    self.conversations = {
  35.    }
  36.    
  37.    -- the cutscenes associated with this quest
  38.    self.cutscenes = {
  39.    }
  40.  
  41.    -- the triggers associated with this quest
  42.    --self.quest:addTrigger("trig_%1", "home")
  43.  
  44.    -- the checklist of little tasks associated with this quest
  45.    self.checklist = {
  46.    }
  47.  
  48.    -- associate the locations with the quest
  49.    for key, value in ipairs(self.locations) do
  50.       self.quest:addLocation(value)
  51.    end
  52.    -- associate the interactors with the quest
  53.    for key, value in ipairs(self.iactors) do
  54.       self.quest:addInteractor(value)
  55.    end
  56.    -- associate the conversations with the quest
  57.    for key, value in ipairs(self.conversations) do
  58.       self.quest:addConversation(value)
  59.    end
  60.    -- associate the cutscenes with the quest
  61.    for key, value in ipairs(self.cutscenes) do
  62.       self.quest:addCutscene(value)
  63.    end
  64.    -- associate the list items with the quest
  65.    for key, value in ipairs(self.checklist) do
  66.       self.quest:addTaskToCheckList(value)
  67.    end
  68.  
  69.    -- subscribe the lua functions to call
  70.    self.quest:subscribeLocationEntered(self.name .. ":onLocationEntered")
  71.    self.quest:subscribeLocationLeft(self.name .. ":onLocationLeft")
  72.    self.quest:subscribeInteractorEvent(self.name .. ":onInteractorEvent")
  73.    self.quest:subscribeInteractorEntered(self.name .. ":onMouseEnteredInteractor")
  74.    self.quest:subscribeInteractorLeft(self.name .. ":onMouseLeftInteractor")
  75.    self.quest:subscribeLocationFadingInFinished(self.name .. ":onLocationFadingInFinished")
  76.    self.quest:subscribeConversationEvent(self.name .. ":onConversationEvent")
  77.    self.quest:subscribeConversationFinished(self.name .. ":onConversationFinished")
  78.    self.quest:subscribeCutsceneFinished(self.name .. ":onCutsceneFinished")
  79.    self.quest:subscribeTriggerEvent(self.name .. ":onTriggerEvent")   
  80.    self.quest:subscribeCheckListChanged(self.name .. ":updateConfigurationsFromCheckList")
  81. end
  82. -----------------------------------------------------------------------
  83.  
  84. --------------------------------------------------------------------------
  85. -- sets the quest active and updates the iactor configurations
  86. --------------------------------------------------------------------------
  87. function %1:activate()
  88.    _LogInfo(self.name .. ":activate", self.name)
  89.    self.quest:setActive(true)
  90.    self:initializeConfigurations()
  91. end
  92. -----------------------------------------------------------------------
  93.  
  94. -----------------------------------------------------------------------
  95. -- sets the quest inactive and resets the iactor configurations
  96. -----------------------------------------------------------------------
  97. function %1:deactivate()
  98.    _LogInfo("%1:deactivate", "called")
  99.    self.quest:setActive(false)
  100. end
  101. -----------------------------------------------------------------------
  102.  
  103. -----------------------------------------------------------------------
  104. -- lua slot called when an action was performed on an interactor
  105. -- associated with this quest
  106. -----------------------------------------------------------------------
  107. function %1:onInteractorEvent(p_Interactor, p_ActionID, p_InteractedInteractor)
  108.    _LogInfo("%1:onInteractorEvent", p_Interactor)
  109.  
  110.    local questState = self.quest:getState()
  111.    local iactor     = GameEntityMgr:getInteractor(p_Interactor)
  112. end
  113. -----------------------------------------------------------------------
  114.  
  115. -----------------------------------------------------------------------
  116. -- lua slot called when the mouse entered an iactor associated 
  117. -- with this quest
  118. -----------------------------------------------------------------------
  119. function %1:onMouseEnteredInteractor(p_Interactor)
  120.    _LogInfo("%1:onMouseEnteredInteractor", p_Interactor)
  121. end
  122. -----------------------------------------------------------------------
  123.  
  124. -----------------------------------------------------------------------
  125. -- lua slot called when the mouse left an iactor associated 
  126. -- with this quest
  127. -----------------------------------------------------------------------
  128. function %1:onMouseLeftInteractor(p_Interactor)
  129.    _LogInfo("%1:onMouseLeftInteractor", p_Interactor)
  130. end
  131. -----------------------------------------------------------------------
  132.  
  133. -----------------------------------------------------------------------
  134. -- lua slot called when the player entered a location that is associated
  135. -- with this quest
  136. -----------------------------------------------------------------------
  137. function %1:onLocationEntered(p_Location)
  138.    _LogInfo("%1:onLocationEntered", p_Location)
  139. end
  140. -----------------------------------------------------------------------
  141.  
  142. -----------------------------------------------------------------------
  143. -- lua slot called when the player left a location that is associated
  144. -- with this quest
  145. -----------------------------------------------------------------------
  146. function %1:onLocationLeft(p_Location)
  147.    _LogInfo("%1:onLocationLeft", p_Location)
  148. end
  149. -----------------------------------------------------------------------
  150.  
  151. -----------------------------------------------------------------------
  152. -- lua slot called whenever a location associated with this quest
  153. -- has finished fading in
  154. -----------------------------------------------------------------------
  155. function %1:onLocationFadingInFinished(p_Location)
  156.    _LogInfo("%1:onLocationFadingInFinished", p_Location)
  157. end
  158. -----------------------------------------------------------------------
  159.  
  160. -----------------------------------------------------------------------
  161. -- lua slot called when a cutscene associated with this quest was
  162. -- finished
  163. -----------------------------------------------------------------------
  164. function %1:onCutsceneFinished(p_Cutscene)
  165.    _LogInfo("%1:onCutsceneFinished", p_Cutscene)
  166. end
  167. -----------------------------------------------------------------------
  168.  
  169. -----------------------------------------------------------------------
  170. -- lua slot called when a conversation associated with this quest
  171. -- was finished
  172. -----------------------------------------------------------------------
  173. function %1:onConversationFinished(p_Conversation)
  174.    _LogInfo("%1:onConversationFinished", p_Conversation)
  175. end
  176. ----------------------------------------------------------------------
  177.  
  178. -----------------------------------------------------------------------
  179. -- lua slot called when a conversation associated with this quest
  180. -- has fired a special event
  181. -----------------------------------------------------------------------
  182. function %1:onConversationEvent(p_Conversation, p_Event)
  183.    _LogInfo("%1:onConversationEvent", p_Conversation .. ":" .. p_Event)
  184. end
  185. -----------------------------------------------------------------------
  186.  
  187. -----------------------------------------------------------------------
  188. -- lua slot called when a trigger associated with this quest
  189. -- has fired its event
  190. -----------------------------------------------------------------------
  191. function %1:onTriggerEvent(p_Trigger)
  192.    _LogInfo("%1:onTriggerEvent", p_Trigger)
  193. end
  194. -----------------------------------------------------------------------
  195.  
  196. -----------------------------------------------------------------------
  197. -- sets the interactor configurations for the iactors associated with
  198. -- this quest according to the quest's current state
  199. -----------------------------------------------------------------------
  200. function %1:initConfigurations()
  201.    _LogInfo("%1:initConfigurations", "")
  202.    local questState = self.quest:getState()
  203.    -- default case, quest just initialized
  204.    if questState == "Initialized" then
  205.       for key, value in ipairs(self.iactors) do
  206.      local configName = self.name .. "_" .. value
  207.      _LogInfo("setting config: '" .. value .. "' to '" .. configName .. "'","")
  208.      if InteractorConfigurationMgr:isConfigurationPresent(configName) then
  209.         local iactor = GameEntityMgr:getInteractor(value)
  210.         iactor:setConfiguration(configName, true)
  211.      else
  212.         _LogWarning("lua", "No such config: " .. configName)
  213.      end
  214.       end
  215.    end
  216. end
  217. -----------------------------------------------------------------------
  218.  
  219. -----------------------------------------------------------------------
  220. -- check function
  221. -----------------------------------------------------------------------
  222. function %1:updateFromCheckList()
  223. end
  224. -----------------------------------------------------------------------
  225.  
  226. -----------------------------------------------------------------------
  227. -- sets the given checklist element to true after the given amount of
  228. -- time (in seconds)
  229. -----------------------------------------------------------------------
  230. function %1:setDoneDelayed(p_Task, p_Time)
  231.    TimedEventMgr:createTimedEvent("%1.quest:setDone(\"" .. p_Task .. "\")", 
  232.                   p_Time)
  233. end
  234. -----------------------------------------------------------------------
  235.  
  236. -----------------------------------------------------------------------
  237. -- Encapsulates picking up an object
  238. -----------------------------------------------------------------------
  239. function %1:pickupItem(p_Item, p_Animation, p_Sentence,
  240.                p_BlockTime, p_TaskToSet,
  241.                p_TimeToSetTask)
  242.    player:say(p_Sentence)
  243.    player:blendToPlayOnceAndBack(p_Animation)
  244.    MouseIface:blockInput(p_BlockTime)
  245.    self:setDoneDelayed(p_TaskToSet, p_TimeToSetTask)
  246. end
  247. -----------------------------------------------------------------------