Advertisement
Guest User

Quest Refactor (located between the menu and NPC code)

a guest
Sep 20th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1.  
  2. ---------------------------------------
  3. --Quest Module
  4. ---------------------------------------
  5. local Quest = {}
  6. Quest.__index = Quest
  7.  
  8. function Quest.new(npc, player, questname, itemtype, item, affection)
  9.     local quest = {}
  10.     setmetatable(quest, Quest)
  11.  
  12.     quest.name = name
  13.     quest.affection
  14.     quest.questParent
  15.  
  16.     quest.questScripts = require 'npcquestscripts'     
  17.     if quest.questScripts[quest.name] then
  18.       quest.giveQuestSucceedScript = quest.questScripts[quest.name][1] or nil
  19.       quest.giveQuestSucceedPrompt = quest.questScripts[quest.name][2] or nil
  20.       quest.giveQuestFailScript = quest.questScripts[quest.name][3] or nil
  21.       quest.completeQuestSucceedScript = quest.questScripts[quest.name][4] or nil
  22.       quest.completeQuestFailScript = quest.questScripts[quest.name][5] or nil
  23.     end
  24.  
  25.     npc.walking = false
  26.     npc.stare = false
  27.     player.freeze = true
  28.  
  29.     if player.quest~=nil and player.quest~=quest.name then
  30.         self:giveQuestFail()
  31.     elseif player.quest== quest.name and not player.inventory:hasMaterial('flowers') then
  32.         self:completeQuestFail()
  33.     elseif player.quest== quest.name and player.inventory:hasMaterial('flowers')
  34.         player.inventory:removeManyItems(1,{name='flowers',type='material'})
  35.         self:completeQuestSucceed()
  36.     else
  37.         self:giveQuestSucceed()
  38.     end
  39.  
  40. end
  41.  
  42. function Quest:giveQuestSucceed(npc, player)
  43.     Dialog.new(self.giveQuestSucceedScript, function()
  44.         prompt.new(self.giveQuestSucceedPrompt, function(result)
  45.             if result == 'Yes' then
  46.                 player.quest = self.name
  47.                 player.questParent = self.questParent
  48.             end
  49.  
  50.         self:finish()
  51.     end)
  52. end
  53.  
  54. function Quest:giveQuestFail(npc, player)
  55.     Dialog.new(self.giveQuestFailScript, function()
  56.         self:finish()
  57.     end)
  58. end
  59.  
  60. function Quest:completeQuestSucceed(npc, player, affection)
  61.     Dialog.new(self.completeQuestSucceedScript, function()
  62.         self:affection(self.affection)
  63.         player.quest = nil
  64.         self:finish()
  65.     end)
  66. end
  67.  
  68. function Quest:completeQuestFail(npc, player)
  69.     Dialog.new(self.completeQuestFailScript, function()
  70.         self:finish()
  71.     end)
  72. end
  73.  
  74. function Quest:finish(npc, player)
  75.     npc.prompt = nil
  76.     npc.fixed = false
  77.     npc.walking = true
  78.     f
  79.     npc.menu:close(player)
  80. end
  81.  
  82. function Quest:affection(affection)
  83.     if npc.levels[npc.name] then
  84.         npc.levels[npc.name][1] = npc.levels[npc.name][1] + self.affection
  85.     end
  86.     npc:affectionUpdate(affection)
  87.     player:affectionUpdate(questParent,affection)
  88.  
  89. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement