Advertisement
Guest User

Untitled

a guest
Oct 6th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.92 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. function onCreatureAppear(cid)          npcHandler:onCreatureAppear(cid)            end
  6. function onCreatureDisappear(cid)       npcHandler:onCreatureDisappear(cid)         end
  7. function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)        end
  8. function onThink()              npcHandler:onThink()                    end
  9.  
  10. local blessMsgs =
  11. {
  12.     'You have been blessed with the Spiritual Shielding.',
  13.     'You have been blessed with the Spark of the Phoenix.',
  14.     'You have been blessed with the Embrace of Tibia.',
  15.     'You have been blessed with the Fire of the Suns.',
  16.     'You have been blessed with the Wisdom of Solitude.'
  17. }
  18.  
  19. local chooseBless = {}
  20.  
  21. local function creatureSayCallback(cid, type, msg)
  22.     if not npcHandler:isFocused(cid) then
  23.         return false
  24.     end
  25.  
  26.     local msg = msg:lower()
  27.    
  28.     local player = Player(cid)
  29.  
  30.     if npcHandler.topic[ cid ] == 0 then
  31.    
  32.         if ( msg == "heal" ) then
  33.             if player:getHealth() < 50 then
  34.                 player:addHealth(50 - player:getHealth())
  35.                 local conditions = {CONDITION_POISON, CONDITION_FIRE, CONDITION_ENERGY, CONDITION_BLEEDING, CONDITION_PARALYZE, CONDITION_DROWN, CONDITION_FREEZING, CONDITION_DAZZLED, CONDITION_CURSED}
  36.                 for i = 1, #conditions do
  37.                     if player:getCondition(conditions[i]) then
  38.                         player:removeCondition(conditions[i])
  39.                     end
  40.                 end
  41.                 npcHandler:say("You are hurt, my child. I will heal your wounds.", cid)
  42.             else
  43.                 npcHandler:say("You aren't looking that bad. Sorry, I can't help you. But if you are looking for additional protection you should go on the {pilgrimage} of ashes or get the protection of the {twist of fate} here.", cid)
  44.             end
  45.            
  46.         elseif isInArray( { "blessing", "blessings" }, msg ) then
  47.             local amount = player:getBlessings()
  48.             npcHandler:say( string.format( "There are five blessings available in five sacred places: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}. You have %d out of 5 blessings. I can also provide you with {all} blessings at once.  Additionally, you can also receive the {twist of fate} here.", amount ), cid )
  49.             npcHandler.topic[ cid ] = 2
  50.         end
  51.        
  52.     elseif ( npcHandler.topic[ cid ] == 2 ) then
  53.    
  54.         local cost = getBlessingsCost(player:getLevel())
  55.         if isInArray( { "spiritual", "spiritual shielding" }, msg  ) then
  56.             npcHandler:say( string.format( "For %d gold coins I will bless you with the Spiritual Shielding. Is that okay?", cost ), cid )
  57.             chooseBless[ cid ] = 1
  58.             npcHandler.topic[cid] = 3
  59.         elseif isInArray( { "phoenix", "spark of the phoenix" }, msg ) then
  60.             npcHandler:say( string.format( "For %d gold coins I will bless you with the Spark of the Phoenix. Is that okay?", cost ), cid )
  61.             chooseBless[ cid ] = 2
  62.             npcHandler.topic[cid] = 3
  63.         elseif isInArray( { "embrace", "embrace of tibia" }, msg ) then
  64.             npcHandler:say( string.format( "For %d gold coins I will bless you with the Embrace of Tibia. Is that okay?", cost ), cid )
  65.             chooseBless[ cid ] = 3
  66.             npcHandler.topic[cid] = 3
  67.         elseif isInArray( { "suns", "fire of the suns" }, msg ) then
  68.             npcHandler:say( string.format( "For %d gold coins I will bless you with the Fire of the Suns. Is that okay?", cost ), cid )
  69.             chooseBless[ cid ] = 4
  70.             npcHandler.topic[cid] = 3
  71.         elseif isInArray( { "solitude", "wisdom of solitude" }, msg ) then
  72.             npcHandler:say( string.format( "For %d gold coins I will bless you with the Wisdom of Solitude. Is that okay?", cost ), cid )
  73.             chooseBless[ cid ] = 5
  74.             npcHandler.topic[cid] = 3
  75.         elseif ( msg == "twist of fate" ) then
  76.             npcHandler:say({
  77.                 "This is a special blessing I can bestow upon you once you have obtained at least one of the other blessings and which functions a bit differently. ...",
  78.                 "It only works when you're killed by other adventurers, which means that at least half of the damage leading to your death was caused by others, not by monsters or the environment. ...",
  79.                 "The {twist of fate} will not reduce the death penalty like the other blessings, but instead prevent you from losing your other blessings as well as the amulet of loss, should you wear one. It costs the same as the other blessings. ...",
  80.                 "Would you like to receive that protection for a sacrifice of " .. getPvpBlessingCost(player:getLevel()) .. " gold, child?"
  81.             }, cid)
  82.            
  83.             npcHandler.topic[cid] = 1
  84.         elseif ( msg == "all" ) then
  85.        
  86.             if player:getBlessings() == 5 then
  87.                 npcHandler:say("You already possess all blessings.", cid )
  88.                 npcHandler.topic[cid] = 0
  89.                 return true
  90.             end
  91.            
  92.             npcHandler:say( string.format( "For %d  gold coins, I will bless you with all the blessings you don't already have. Is that okay?", player:getBlessingPrices() ), cid )
  93.             npcHandler.topic[cid] = 4
  94.         elseif ( msg == "no" ) then
  95.             npcHandler:say("Fine. You are free to decline my offer.", cid)
  96.             npcHandler.topic[cid] = 0
  97.         else
  98.             npcHandler:say( "I can't understand you.", cid )
  99.             npcHandler.topic[cid] = 0
  100.         end
  101.        
  102.     elseif ( msg == "yes" ) then
  103.         if npcHandler.topic[cid] == 1 then
  104.             if player:getBlessings() > 0 or player:getItemCount(2173) > 0 then
  105.                 if not player:hasBlessing(6) then
  106.                     if player:removeMoney(getPvpBlessingCost(player:getLevel())) then
  107.                         player:addBlessing(6)
  108.                         npcHandler:say("So receive the protection of the twist of fate, pilgrim.", cid)
  109.                     else
  110.                         npcHandler:say("Oh. You do not have enough money.", cid)
  111.                     end
  112.                 else
  113.                     npcHandler:say("You already possess this blessing.", cid)
  114.                 end
  115.             else
  116.                 npcHandler:say("You don't have any of the other blessings nor an amulet of loss, so it wouldn't make sense to bestow this protection on you now. Remember that it can only protect you from the loss of those!", cid)
  117.             end
  118.             npcHandler.topic[cid] = 0
  119.         elseif npcHandler.topic[cid] == 3 then
  120.             local cost = getBlessingsCost(player:getLevel())
  121.             if player:hasBlessing( chooseBless[ cid ] ) then
  122.                 npcHandler:say("Gods have already blessed you with this blessing!", cid)
  123.             else
  124.                 if player:removeMoney( cost ) then
  125.                     npcHandler:say( blessMsgs[ chooseBless[ cid ] ], cid )
  126.                     player:addBlessing( chooseBless[ cid ] )
  127.                     player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
  128.                 else
  129.                     npcHandler:say("Oh. You do not have enough money.", cid)
  130.                 end
  131.             end
  132.             npcHandler.topic[cid] = 0
  133.         elseif npcHandler.topic[cid] == 4 then
  134.             if player:getBlessingsCount( ) == 6 then
  135.                 npcHandler:say("You already possess all blessings.", cid)
  136.             else
  137.                 local allCost = player:getBlessingPrices()
  138.                 if player:removeMoney( allCost ) then
  139.                     player:addAllBlessings()
  140.                     player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
  141.                     npcHandler:say( "Now you have been blessed by all five Gods!", cid )
  142.                 else
  143.                     npcHandler:say("Oh. You do not have enough money.", cid)
  144.                 end
  145.             end
  146.             npcHandler.topic[cid] = 0
  147.         end
  148.     elseif ( msg == "no" ) and npcHandler.topic[cid] >= 1 then
  149.         npcHandler:say("Fine. You are free to decline my offer.", cid)
  150.         npcHandler.topic[cid] = 0
  151.     elseif npcHandler.topic[ cid ] >= 1 then
  152.         npcHandler:say( "I can't understand you.", cid )
  153.         npcHandler.topic[cid] = 0
  154.     end
  155.    
  156.     return true
  157. end
  158.  
  159. keywordHandler:addKeyword({'pilgrimage'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Whenever you receive a lethal wound, your vital force is damaged and there is a chance that you lose some of your equipment. With every single of the five {blessings} you have, this damage and chance of loss will be reduced.'})
  160. --[[
  161. keywordHandler:addKeyword({'spiritual'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can ask for the blessing of spiritual shielding in the whiteflower temple south of Thais.'})
  162. keywordHandler:addKeyword({'phoenix'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The spark of the phoenix is given by the dwarven priests of earth and fire in Kazordoon.'})
  163. keywordHandler:addKeyword({'embrace'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The druids north of Carlin will provide you with the embrace of Tibia.'})
  164. keywordHandler:addKeyword({'suns'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can ask for the blessing of the two suns in the suntower near Ab\'Dendriel.'})
  165. keywordHandler:addKeyword({'solitude'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Talk to the hermit Eremo on the isle of Cormaya about this blessing.'})
  166. --]]
  167.  
  168. npcHandler:setMessage(MESSAGE_GREET, "Welcome, young |PLAYERNAME|! If you are heavily wounded or poisoned, I can {heal} you for free.")
  169. npcHandler:setMessage(MESSAGE_WALKAWAY, "Remember: If you are heavily wounded or poisoned, I can heal you for free.")
  170. npcHandler:setMessage(MESSAGE_FAREWELL, "May the gods bless you, |PLAYERNAME|!")
  171.  
  172. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  173. npcHandler:addModule(FocusModule:new())
  174.  
  175. ynpc = YNPC:new( npcHandler )
  176. --ynpc:initialize()
  177.  
  178. local HEAL = 1
  179. local BLESSINGS = 2
  180. local CHOOSEBLESSINGS = 3
  181. local BLESSINGYES = 4
  182. local BLESSINGNO = 5
  183. local DONTUNDERSTAND = 6
  184.  
  185. local function healPlayer( cid )
  186.     local player = Player( cid )
  187.     if player:getHealth() < 50 then
  188.         player:addHealth(50 - player:getHealth())
  189.         local conditions = {CONDITION_POISON, CONDITION_FIRE, CONDITION_ENERGY, CONDITION_BLEEDING, CONDITION_PARALYZE, CONDITION_DROWN, CONDITION_FREEZING, CONDITION_DAZZLED, CONDITION_CURSED}
  190.         for i = 1, #conditions do
  191.             if player:getCondition(conditions[i]) then
  192.                 player:removeCondition(conditions[i])
  193.             end
  194.         end
  195.         npcHandler:say("You are hurt, my child. I will heal your wounds.", cid)
  196.     else
  197.         npcHandler:say("You aren't looking that bad. Sorry, I can't help you. But if you are looking for additional protection you should go on the {pilgrimage} of ashes or get the protection of the {twist of fate} here.", cid)
  198.     end
  199.    
  200.     return true
  201. end
  202.  
  203. local function sayBlessings( cid )
  204.     local player = Player( cid )
  205.     local amount = player:getBlessings()
  206.     npcHandler:say( string.format( "There are five blessings available in five sacred places: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}. You have %d out of 5 blessings. I can also provide you with {all} blessings at once.  Additionally, you can also receive the {twist of fate} here.", amount ), cid )
  207.     --ynpc:setCurrentTopic( cid, CHOOSEBLESSINGS )
  208.     return true
  209. end
  210.  
  211. local function chooseBlessings( cid, msg )
  212.  
  213.     local player = Player( cid )
  214.    
  215.     local cost = getBlessingsCost(player:getLevel())
  216.    
  217.     if isInArray( { "spiritual", "spiritual shielding" }, msg  ) then
  218.         npcHandler:say( string.format( "For %d gold coins I will bless you with the Spiritual Shielding. Is that okay?", cost ), cid )
  219.         chooseBless[ cid ] = 1
  220.     elseif isInArray( { "phoenix", "spark of the phoenix" }, msg ) then
  221.         npcHandler:say( string.format( "For %d gold coins I will bless you with the Spark of the Phoenix. Is that okay?", cost ), cid )
  222.         chooseBless[ cid ] = 2
  223.     elseif isInArray( { "embrace", "embrace of tibia" }, msg ) then
  224.         npcHandler:say( string.format( "For %d gold coins I will bless you with the Embrace of Tibia. Is that okay?", cost ), cid )
  225.         chooseBless[ cid ] = 3
  226.     elseif isInArray( { "suns", "fire of the suns" }, msg ) then
  227.         npcHandler:say( string.format( "For %d gold coins I will bless you with the Fire of the Suns. Is that okay?", cost ), cid )
  228.         chooseBless[ cid ] = 4
  229.     elseif isInArray( { "solitude", "wisdom of solitude" }, msg ) then
  230.         npcHandler:say( string.format( "For %d gold coins I will bless you with the Wisdom of Solitude. Is that okay?", cost ), cid )
  231.         chooseBless[ cid ] = 5
  232.     elseif ( msg == "twist of fate" ) then
  233.         npcHandler:say({
  234.             "This is a special blessing I can bestow upon you once you have obtained at least one of the other blessings and which functions a bit differently. ...",
  235.             "It only works when you're killed by other adventurers, which means that at least half of the damage leading to your death was caused by others, not by monsters or the environment. ...",
  236.             "The {twist of fate} will not reduce the death penalty like the other blessings, but instead prevent you from losing your other blessings as well as the amulet of loss, should you wear one. It costs the same as the other blessings. ...",
  237.             "Would you like to receive that protection for a sacrifice of " .. getPvpBlessingCost(player:getLevel()) .. " gold, child?"
  238.         }, cid)
  239.        
  240.         chooseBless[ cid ] = 6
  241.     elseif ( msg == "all" ) then
  242.    
  243.         if player:getBlessings() == 5 then
  244.             npcHandler:say("You already possess all blessings.", cid )
  245.             ynpc:reset( cid )
  246.             return false
  247.         end
  248.        
  249.         npcHandler:say( string.format( "For %d  gold coins, I will bless you with all the blessings you don't already have. Is that okay?", player:getBlessingPrices() ), cid )
  250.         chooseBless[ cid ] = 7
  251.     elseif ( msg == "no" ) then
  252.         npcHandler:say("Fine. You are free to decline my offer.", cid)
  253.         chooseBless[ cid ] = 0
  254.         ynpc:reset( cid )
  255.         return false
  256.     else
  257.         ynpc:doTopic( cid, DONTUNDERSTAND )
  258.         return false
  259.     end
  260.    
  261.     return true
  262. end
  263.  
  264. local function buyBlessings( cid )
  265.     local player = Player( cid )
  266.     if chooseBless[ cid ] == 6 then
  267.         if player:getBlessings() > 0 or player:getItemCount(2173) > 0 then
  268.             if not player:hasBlessing(6) then
  269.                 if player:removeMoney(getPvpBlessingCost(player:getLevel())) then
  270.                     player:addBlessing(6)
  271.                     npcHandler:say("So receive the protection of the twist of fate, pilgrim.", cid)
  272.                 else
  273.                     npcHandler:say("Oh. You do not have enough money.", cid)
  274.                 end
  275.             else
  276.                 npcHandler:say("You already possess this blessing.", cid)
  277.             end
  278.         else
  279.             npcHandler:say("You don't have any of the other blessings nor an amulet of loss, so it wouldn't make sense to bestow this protection on you now. Remember that it can only protect you from the loss of those!", cid)
  280.         end
  281.     elseif ( chooseBless[ cid ] >= 1 ) and ( chooseBless[ cid ] <= 5 ) then
  282.         local cost = getBlessingsCost(player:getLevel())
  283.         if player:hasBlessing( chooseBless[ cid ] ) then
  284.             npcHandler:say("Gods have already blessed you with this blessing!", cid)
  285.         else
  286.             if player:removeMoney( cost ) then
  287.                 npcHandler:say( blessMsgs[ chooseBless[ cid ] ], cid )
  288.                 player:addBlessing( chooseBless[ cid ] )
  289.                 player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
  290.             else
  291.                 npcHandler:say("Oh. You do not have enough money.", cid)
  292.             end
  293.         end
  294.     elseif chooseBless[ cid ] == 7 then
  295.         if player:getBlessings() == 5 then
  296.             npcHandler:say("You already possess all blessings.", cid)
  297.         else
  298.             local allCost = player:getBlessingPrices()
  299.             if player:removeMoney( allCost ) then
  300.                 player:addAllBlessings()
  301.                 player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
  302.                 npcHandler:say( "Now you have been blessed by all five Gods!", cid )
  303.             else
  304.                 npcHandler:say("Oh. You do not have enough money.", cid)
  305.             end
  306.         end
  307.     end
  308.    
  309.     return true
  310. end
  311.  
  312. --Opções iniciais( quando o player começa a conversa com o npc ) de topicos
  313. ynpc:setDefaultTopics( { HEAL, BLESSINGS } )
  314.  
  315. ynpc:addTopic( {
  316.     id = DONTUNDERSTAND,
  317.     words    = {},
  318.     answer = "I don't understand you.",
  319.     next     = {},
  320.     default  = { reset = true }
  321. } )
  322.  
  323. ynpc:addTopic( {
  324.     id = HEAL,
  325.     words    = { "heal", "heal" },
  326.     answer = healPlayer,
  327.     next     = {},
  328.     default = {message = "I don't understand you.", reset = true}
  329. } )
  330.  
  331. ynpc:addTopic( {
  332.     id = BLESSINGS,
  333.     words = { "blessing", "blessings" },
  334.     answer = sayBlessings,
  335.     next = { CHOOSEBLESSINGS },
  336.     default = {topic = DONTUNDERSTAND}
  337. } )
  338.  
  339. ynpc:addTopic( {
  340.     id = CHOOSEBLESSINGS,
  341.     words = { "any" },
  342.     answer = chooseBlessings,
  343.     next = { BLESSINGYES, BLESSINGNO },
  344.     default = {message = "I don't understand you.", reset = true }
  345. } )
  346.  
  347. ynpc:addTopic( {
  348.     id = BLESSINGYES,
  349.     words = { "yes" },
  350.     answer = buyBlessings,
  351.     next = {}
  352. } )
  353.  
  354. ynpc:addTopic( {
  355.     id = BLESSINGNO,
  356.     words = { "no" },
  357.     answer = "Fine. You are free to decline my offer.",
  358.     next = {}
  359. } )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement