From 9b11a3486d38da1e891d1ee54b1e3b12808ac4e0 Mon Sep 17 00:00:00 2001 From: PrinterLUA Date: Mon, 14 Jul 2014 12:14:58 +0200 Subject: [PATCH] Rework The Oracle Now oracle is working, but note: The npc was changed in the Update 8.2 when the Island of Destiny was introduced. Thank you also for the firstitems.lua, i was able to merge the code into The Oracle. The rookgaard is under progress, when we reach to that point we shall updated The Oracle Again. --- data/npc/scripts/The Oracle.lua | 218 +++++++++++++++++++------------- 1 file changed, 132 insertions(+), 86 deletions(-) diff --git a/data/npc/scripts/The Oracle.lua b/data/npc/scripts/The Oracle.lua index bd70e13a6..a8cdbde2a 100644 --- a/data/npc/scripts/The Oracle.lua +++ b/data/npc/scripts/The Oracle.lua @@ -2,101 +2,147 @@ local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) -function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end -function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end -function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end -function onThink() npcHandler:onThink() end +local vocation = {} +local town = {} -function oracle(cid, message, keywords, parameters, node) - if(not npcHandler:isFocused(cid)) then - return false - end +local config = { - local cityNode = node:getParent():getParent() - local vocNode = node:getParent() + towns = { + ["venore"] = 1, + ["thais"] = 2, + ["carlin"] = 4 + }, + + vocations = { + ["sorcerer"] = { + text = "A SORCERER! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!", + vocationId = 1, + --equipment spellbook, wand of vortex, magician's robe, mage hat, studded legs, leather boots, scarf + {{2175, 1}, {2190, 1}, {8819, 1}, {8820, 1}, {2468, 1}, {2643, 1}, {2661, 1}}, + --container rope, shovel, mana potion + {{2120, 1}, {2554, 1}, {7620, 1}} + }, - local destination = cityNode:getParameters().destination - local town = cityNode:getParameters().town - local vocation = vocNode:getParameters().vocation + ["druid"] = { + text = "A DRUID! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!", + vocationId = 2, + --equipment spellbook, snakebite rod, magician's robe, mage hat, studded legs, leather boots scarf + {{2175, 1}, {2182, 1}, {8819, 1}, {8820, 1}, {2468, 1}, {2643, 1}, {2661, 1}}, + --container rope, shovel, mana potion + {{2120, 1}, {2554, 1}, {7620, 1}} + }, - if(destination ~= nil and vocation ~= nil and town ~= nil) then - if(getPlayerLevel(cid) < parameters.level) then - npcHandler:say('You must first reach level ' .. parameters.level .. '!', cid) - npcHandler:resetNpc() - else - if(getPlayerVocation(cid) > 0) then - npcHandler:say('Sorry, You already have a vocation!') - npcHandler:resetNpc() - else - doPlayerSetVocation(cid, vocation) - doPlayerSetTown(cid, town) - npcHandler:resetNpc() + ["paladin"] = { + text = "A PALADIN! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!", + vocationId = 3, + --equipment dwrven shield, 5 spear, ranger's cloak, ranger legs scarf, legion helmet + {{2525, 1}, {2389, 5}, {2660, 1}, {8923, 1}, {2643, 1}, {2661, 1}, {2480, 1}}, + --container rope, shovel, health potion, bow, 50 arrow + {{2120, 1}, {2554, 1}, {7618, 1}, {2456, 1}, {2544, 50}} + }, - local tmp = getCreaturePosition(cid) - doTeleportThing(cid, destination) - doSendMagicEffect(tmp, CONST_ME_POFF) - doSendMagicEffect(destination, CONST_ME_TELEPORT) - end - end - end + ["knight"] = { + text = "A KNIGHT! ARE YOU SURE? THIS DECISION IS IRREVERSIBLE!", + vocationId = 4, + --equipment dwarven shield, steel axe, brass armor, brass helmet, brass legs scarf + {{2525, 1}, {8601, 1}, {2465, 1}, {2460, 1}, {2478, 1}, {2643, 1}, {2661, 1}}, + --container jagged sword, daramian mace, rope, shovel, health potion + {{8602, 1}, {2439, 1}, {2120, 1}, {2554, 1}, {7618, 1}} + } + } +} - return true +function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end +function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end +function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end +function onThink() npcHandler:onThink() end + +local function greetCallback(cid) + local player = Player(cid) + local level = player:getLevel() + if level < 8 then + npcHandler:say("CHILD! COME BACK WHEN YOU HAVE GROWN UP!", cid) + return false + elseif level > 9 then + npcHandler:say(player:getName() ..", I CAN'T LET YOU LEAVE - YOU ARE TOO STRONG ALREADY! YOU CAN ONLY LEAVE WITH LEVEL 9 OR LOWER.", cid) + return false + elseif player:getVocation():getId() > 0 then + npcHandler:say("YOU ALREADY HAVE A VOCATION!", cid) + return false + else + npcHandler:setMessage(MESSAGE_GREET, player:getName() ..", ARE YOU PREPARED TO FACE YOUR DESTINY?") + end + return true end -function greetCallback(cid) - if(getPlayerLevel(cid) < 8) then - npcHandler:say('COME BACK WHEN YOU GROW UP, CHILD!') - return false - else - return true - end +local function creatureSayCallback(cid, type, msg) + if not npcHandler:isFocused(cid) then + return false + end + + local player = Player(cid) + if npcHandler.topic[cid] == 0 then + if msgcontains(msg, "yes") then + npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {CARLIN}, {THAIS}, OR {VENORE}?", cid) + npcHandler.topic[cid] = 1 + end + elseif npcHandler.topic[cid] == 1 then + local cityTable = config.towns[string.lower(msg)] + if cityTable then + town[cid] = cityTable + npcHandler:say("IN ".. string.upper(msg) .."! AND WHAT PROFESSION HAVE YOU CHOSEN: {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid) + npcHandler.topic[cid] = 2 + else + npcHandler:say("IN WHICH TOWN DO YOU WANT TO LIVE: {CARLIN}, {THAIS}, OR {VENORE}?", cid) + end + elseif npcHandler.topic[cid] == 2 then + local vocationTable = config.vocations[string.lower(msg)] + if vocationTable then + npcHandler:say(vocationTable.text, cid) + npcHandler.topic[cid] = 3 + vocation[cid] = vocationTable.vocationId + else + npcHandler:say("{KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid) + end + elseif npcHandler.topic[cid] == 3 then + if msgcontains(msg, "yes") then + npcHandler:say("SO BE IT!", cid) + player:setVocation(Vocation(vocation[cid])) + player:setTown(Town(town[cid])) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + player:teleportTo(Town(town[cid]):getTemplePosition()) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + local targetVocation = config.vocations[string.lower(Vocation(vocation[cid]):getName())] + for i = 1, #targetVocation[1] do + player:addItem(targetVocation[1][i][1], targetVocation[1][i][2]) + end + local backpack = player:addItem(1988) + for i = 1, #targetVocation[2] do + backpack:addItem(targetVocation[2][i][1], targetVocation[2][i][2]) + end + else + npcHandler:say("THEN WHAT? {KNIGHT}, {PALADIN}, {SORCERER}, OR {DRUID}?", cid) + npcHandler.topic[cid] = 2 + end + end + return true +end + +local function onAddFocus(cid) + town[cid] = 0 + vocation[cid] = 0 end -npcHandler:setCallback(CALLBACK_GREET, greetCallback) -npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|. Are you prepared to face your destiny?') -local yesNode = KeywordNode:new({'yes'}, oracle, {level = 8}) -local noNode = KeywordNode:new({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Then what vocation do you want to become?'}) +local function onReleaseFocus(cid) + town[cid] = nil + vocation[cid] = nil +end -local node1 = keywordHandler:addKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'What city do you wish to live in? {Rhyves}, {Varak} or {Jorvik}?'}) - local node2 = node1:addChildKeyword({'varak'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, town = 1, destination = {x=242, y=429, z=12}, text = 'Varak, eh? So what vocation do you wish to become? {Sorcerer}, {druid}, {paladin} or {knight}?'}) - local node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, vocation = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, vocation = 2, onlyFocus = true, text = 'Are you sure that a druid is what you wish to become? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, vocation = 3, onlyFocus = true, text = 'A ranged marksman. Are you sure? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, vocation = 4, onlyFocus = true, text = 'A mighty warrior. Is that your final decision? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node2 = node1:addChildKeyword({'rhyves'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, town = 1, destination = {x=159, y=387, z=6}, text = 'Rhyves, eh? So what vocation do you wish to become? {Sorcerer}, {druid}, {paladin} or {knight}?'}) - node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, vocation = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, vocation = 2, onlyFocus = true, text = 'Are you sure that a druid is what you wish to become? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, vocation = 3, onlyFocus = true, text = 'A ranged marksman. Are you sure? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, vocation = 4, onlyFocus = true, text = 'A mighty warrior. Is that your final decision? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node2 = node1:addChildKeyword({'jorvik'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, town = 1, destination = {x=469, y=172, z=7}, text = 'Jorvik, eh? So what vocation do you wish to become? {Sorcerer}, {druid}, {paladin} or {knight}?'}) - node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, vocation = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, vocation = 2, onlyFocus = true, text = 'Are you sure that a druid is what you wish to become? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, vocation = 3, onlyFocus = true, text = 'A ranged marksman. Are you sure? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) - node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, vocation = 4, onlyFocus = true, text = 'A mighty warrior. Is that your final decision? This decision is irreversible!'}) - node3:addChildKeywordNode(yesNode) - node3:addChildKeywordNode(noNode) -keywordHandler:addKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Then come back when you are ready.'}) +npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus) +npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus) -npcHandler:addModule(FocusModule:new()) +npcHandler:setCallback(CALLBACK_GREET, greetCallback) +npcHandler:setMessage(MESSAGE_FAREWELL, "COME BACK WHEN YOU ARE PREPARED TO FACE YOUR DESTINY!") +npcHandler:setMessage(MESSAGE_WALKAWAY, "COME BACK WHEN YOU ARE PREPARED TO FACE YOUR DESTINY!") +npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) +npcHandler:addModule(FocusModule:new()) \ No newline at end of file