home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / Dema / ankh_demo_en.exe / media / lua / AnkhQuest_TriggerControl.lua < prev    next >
Encoding:
Text File  |  2005-10-01  |  10.3 KB  |  268 lines

  1. -----------------------------------------------------------------------
  2. -- the table where all the functions/methods go to
  3. -----------------------------------------------------------------------
  4. TriggerControl = {
  5.    quest,
  6.    name,
  7.    locations,
  8.    iactors,
  9.    checklist
  10. }
  11. -----------------------------------------------------------------------
  12.  
  13. -----------------------------------------------------------------------
  14. -- init function
  15. -----------------------------------------------------------------------
  16. function TriggerControl:init()
  17.    local questName = "TriggerControl"
  18.    -- the quest object stores the C++ object pointer (Quest object)
  19.    self.quest = QuestMgr:createQuest(questName)
  20.    self.name  = questName
  21.    
  22.    -- the locations associated with this quest
  23.    self.locations = {
  24.       "bazar",
  25.       "desert_beach",
  26.       "desert_crossing",
  27.       "desert_plain",
  28.       "desert_rock",
  29.       "giza",
  30.       "home",
  31.       "nile",
  32.       "oasis",
  33.       "palace_backdoor",
  34.       "palace_cellar",
  35.       "palace_courtyard",
  36.       "palace_garden",
  37.       "palace_prison",
  38.       "palace_temple",
  39.       "palace_throneroom",
  40.       "ship_wreck",
  41.       "sphinx_inside",
  42.       "sphinx_outside",
  43.       "underworld"
  44.    }
  45.    -- associate the locations with the quest
  46.    for key, value in ipairs(self.locations) do
  47.       self.quest:addLocation(value)
  48.    end
  49.  
  50.    -- the interactor objects associated with this quest
  51.    self.iactors = {
  52.       "iactor_bazar_canal_to_bazar_burger",
  53.       "iactor_bazar_b_to_bazar_plaza",
  54.       "iactor_palace_gate_street_to_bazar_plaza"
  55.    }
  56.  
  57.    -- the checklist of little tasks associated with this quest
  58.    self.checklist = {
  59.       "DinarInShadyShop"
  60.    }
  61.  
  62.    -- associate the triggers with the quest
  63.    self.quest:addTrigger("trig_bazar_stall_to_bazar_burger", "bazar")
  64.    self.quest:addTrigger("trig_home_shadowzone_a", "home")
  65.    self.quest:addTrigger("trig_home_shadowzone_b", "home")
  66.    --self.quest:addTrigger("trig_sphinx_inside_shadowzone_a", "sphinx_inside")
  67.  
  68.    -- associate the interactors with the quest
  69.    for key, value in ipairs(self.iactors) do
  70.       self.quest:addInteractor(value)
  71.    end
  72.    -- associate the list items with the quest
  73.    for key, value in ipairs(self.checklist) do
  74.       self.quest:addTaskToCheckList(value)
  75.    end
  76.  
  77.    -- subscribe the lua functions to call
  78.    self.quest:subscribeLocationEntered(self.name .. ":onLocationEntered")
  79.    self.quest:subscribeLocationLeft(self.name .. ":onLocationLeft")
  80.    self.quest:subscribeInteractorEvent(self.name .. ":onInteractorEvent")
  81.    self.quest:subscribeInteractorEntered(self.name .. ":onMouseEnteredInteractor")
  82.    self.quest:subscribeInteractorLeft(self.name .. ":onMouseLeftInteractor")
  83.    self.quest:subscribeLocationFadingInFinished(self.name .. ":onLocationFadingInFinished")
  84.    self.quest:subscribeTriggerEvent(self.name .. ":onTriggerEvent")   
  85.    self.quest:subscribeTriggerFaceEvent(self.name .. ":onTriggerFaceEvent")   
  86.    self.quest:subscribeCheckListChanged(self.name .. ":updateFromCheckList")   
  87.    
  88.    -- set the initial quest state
  89.    self.quest:setState("Initialized")
  90. end
  91. -----------------------------------------------------------------------
  92.  
  93. --------------------------------------------------------------------------
  94. -- sets the quest active and updates the iactor configurations
  95. --------------------------------------------------------------------------
  96. function TriggerControl:activate()
  97.    _LogInfo(self.name .. ":activate", self.name)
  98.    self.quest:setActive(true)
  99. end
  100. -----------------------------------------------------------------------
  101.  
  102. -----------------------------------------------------------------------
  103. -- sets the quest inactive and resets the iactor configurations
  104. -----------------------------------------------------------------------
  105. function TriggerControl:deactivate()
  106.    _LogInfo("TriggerControl:deactivate", "called")
  107.    self.quest:setActive(false)
  108. end
  109. -----------------------------------------------------------------------
  110.  
  111. -----------------------------------------------------------------------
  112. -- lua slot called when an action was performed on an interactor
  113. -- associated with this quest
  114. -----------------------------------------------------------------------
  115. function TriggerControl:onInteractorEvent(p_Interactor, p_ActionID, p_InteractedInteractor)
  116.    _LogInfo("TriggerControl:onInteractorEvent", p_Interactor)
  117.  
  118.    if p_Interactor == "iactor_bazar_canal_to_bazar_burger" and p_ActionID == Interactor.Leave then
  119.       self.quest:setDone("DinarInShadyShop")
  120.    end
  121.  
  122.    if (p_Interactor == "iactor_bazar_b_to_bazar_plaza" or p_Interactor == "iactor_palace_gate_street_to_bazar_plaza") and
  123.        p_ActionID == Interactor.Leave then
  124.       self.quest:setUndone("DinarInShadyShop")
  125.    end
  126.  
  127. end
  128. -----------------------------------------------------------------------
  129.  
  130. -----------------------------------------------------------------------
  131. -- lua slot called when the mouse entered an iactor associated 
  132. -- with this quest
  133. -----------------------------------------------------------------------
  134. function TriggerControl:onMouseEnteredInteractor(p_Interactor)
  135.    _LogInfo("TriggerControl:onMouseEnteredInteractor", p_Interactor)
  136. end
  137. -----------------------------------------------------------------------
  138.  
  139. -----------------------------------------------------------------------
  140. -- lua slot called when the mouse left an iactor associated 
  141. -- with this quest
  142. -----------------------------------------------------------------------
  143. function TriggerControl:onMouseLeftInteractor(p_Interactor)
  144.    _LogInfo("TriggerControl:onMouseLeftInteractor", p_Interactor)
  145. end
  146. -----------------------------------------------------------------------
  147.  
  148. -----------------------------------------------------------------------
  149. -- lua slot called when the player entered a location that is associated
  150. -- with this quest
  151. -----------------------------------------------------------------------
  152. function TriggerControl:onLocationEntered(p_Location)
  153.    _LogInfo("TriggerControl:onLocationEntered", p_Location)
  154. end
  155. -----------------------------------------------------------------------
  156.  
  157. -----------------------------------------------------------------------
  158. -- lua slot called when the player left a location that is associated
  159. -- with this quest
  160. -----------------------------------------------------------------------
  161. function TriggerControl:onLocationLeft(p_Location)
  162.    _LogInfo("TriggerControl:onLocationLeft", p_Location)
  163.  
  164.    if p_Location == "bazar" then
  165.       CharacterControllerMgr:stop("char_dinar")
  166.    end
  167.  
  168.    --reset assil's diffuse value which could have been altered 
  169.    --by a shadow trigger within the left location
  170.    char_assil:animateDiffuseFactor(1.0)
  171.  
  172. end
  173. -----------------------------------------------------------------------
  174.  
  175. -----------------------------------------------------------------------
  176. -- lua slot called whenever a location associated with this quest
  177. -- has finished fading in
  178. -----------------------------------------------------------------------
  179. function TriggerControl:onLocationFadingInFinished(p_Location)
  180.    _LogInfo("TriggerControl:onLocationFadingInFinished", p_Location)
  181.  
  182.    if p_Location == "bazar" and LocationMgr:getLocationActivePathNodes("bazar") == "plaza" then
  183.       self.quest:setUndone("DinarInShadyShop")
  184.    end
  185.  
  186. end
  187. -----------------------------------------------------------------------
  188.  
  189. -----------------------------------------------------------------------
  190. -- lua slot called when a trigger associated with this quest
  191. -- has fired its event
  192. -----------------------------------------------------------------------
  193. function TriggerControl:onTriggerEvent(p_Trigger)
  194.    _LogInfo("TriggerControl:onTriggerEvent", p_Trigger)
  195. end
  196. -----------------------------------------------------------------------
  197.  
  198. -----------------------------------------------------------------------
  199. -- lua slot called when a trigger associated with this quest
  200. -- has fired its event enhanced with the face the trigger was entered
  201. -----------------------------------------------------------------------
  202. function TriggerControl:onTriggerFaceEvent(p_Trigger,p_FrontFace)
  203.    _LogInfo("TriggerControl:onTriggerFaceEvent", p_Trigger)
  204.  
  205.    if p_Trigger == "trig_bazar_stall_to_bazar_burger" then
  206.       if p_FrontFace then
  207.          self.quest:setDone("DinarInShadyShop")
  208.       else
  209.          self.quest:setUndone("DinarInShadyShop")
  210.       end
  211.    end
  212.  
  213.    if p_Trigger == "trig_home_shadowzone_a" then
  214.       if p_FrontFace then
  215.          char_assil:animateDiffuseFactor(1.0)
  216.       else
  217.          char_assil:animateDiffuseFactor(0.0)
  218.       end
  219.    end   
  220.  
  221.    if p_Trigger == "trig_home_shadowzone_b" then
  222.       if p_FrontFace then
  223.          char_assil:animateDiffuseFactor(1.0)
  224.       else
  225.          char_assil:animateDiffuseFactor(0.0)
  226.       end
  227.    end
  228.  
  229.    --[[if p_Trigger == "trig_sphinx_inside_shadowzone_a" then
  230.       if p_FrontFace then
  231.          char_assil:animateDiffuseFactor(1.0)
  232.       else
  233.          char_assil:animateDiffuseFactor(0.0)
  234.       end
  235.    end 
  236.    ]]
  237. end
  238. -----------------------------------------------------------------------
  239.  
  240. -----------------------------------------------------------------------
  241. -- check function
  242. -----------------------------------------------------------------------
  243. function TriggerControl:updateFromCheckList(p_Task, p_Done)
  244.    --_LogInfo("TriggerControl:updateFromCheckList", "")
  245.  
  246.    if p_Task == "DinarInShadyShop" then
  247.       if not QuestMgr:isQuestActive("Embassy") and not QuestMgr:isQuestActive("Sphinx") and
  248.          not QuestMgr:isQuestActive("SunOfCairo") then
  249.          if p_Done then
  250.             char_dinar:setConfiguration("cfg_char_dinar_shady_shop")
  251.             char_dinar:setPathnodeGraph("dinar")
  252.             char_dinar:setPosition(2216, 645, -5115)
  253.             char_dinar:setYaw(Degree(55))
  254.             CharacterControllerMgr:walk("char_dinar", PinaVector3(2320, 649, -4768), Degree(352))
  255.          else
  256.             char_dinar:setConfiguration("cfg_char_dinar")
  257.             char_dinar:setPathnodeGraph("dinar")
  258.             char_dinar:setPosition(708, 1087, -5487)
  259.             char_dinar:setYaw(Degree(-43))
  260.             CharacterControllerMgr:walk("char_dinar", PinaVector3(895, 1074, -4876), Degree(330))
  261.          end
  262.       end
  263.    end
  264.  
  265. end
  266. -----------------------------------------------------------------------
  267.  
  268.