Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Mystery box additions #434

Merged
merged 11 commits into from
Mar 26, 2020
199 changes: 181 additions & 18 deletions scripts/zones/Windurst_Walls/npcs/Arbitrix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,210 @@
local ID = require("scripts/zones/Windurst_Walls/IDs")
require("scripts/globals/settings")
-----------------------------------
local adoulinOptionOff = 0x80
local pictlogicaOptionOff = 0x100
local wantedOptionOff = 0x1000
local hideOptionFlags = adoulinOptionOff + pictlogicaOptionOff + wantedOptionOff

function onTrigger(player, npc)
local playerAgeDays = (os.time() - player:getTimeCreated()) / 86400

local dailyTallyPoints = player:getCurrency("daily_tally")
local firstVisit = dailyTallyPoints == -1

local gobbieBoxUsed = player:getCharVar("gobbieBoxUsed")
local specialDialUsed = 1
local adoulinDialUsed = 1
local pictlogicaDialUsed = 1
local wantedDialUsed = 1

local adoulinOptionOff = 0x80
local pictlogicaOptionOff = 0x100
local wantedOptionOff = 0x1000
local hideOptionFlags = adoulinOptionOff + pictlogicaOptionOff + wantedOptionOff
local specialDialUsed = player:getMaskBit(gobbieBoxUsed, 0) and 1 or 0
local adoulinDialUsed = player:getMaskBit(gobbieBoxUsed, 1) and 1 or 0
local pictlogicaDialUsed = player:getMaskBit(gobbieBoxUsed, 2) and 1 or 0
local wantedDialUsed = player:getMaskBit(gobbieBoxUsed, 3) and 1 or 0
local holdingItem = player:getCharVar("gobbieBoxHoldingItem")

if playerAgeDays >= GOBBIE_BOX_MIN_AGE and firstVisit then
player:startEvent(519)
elseif playerAgeDays >= GOBBIE_BOX_MIN_AGE then
player:startEvent(520, specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, dailyTallyPoints)
if holdingItem ~= 0 then
player:startEvent(521)
else
player:startEvent(520, specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, dailyTallyPoints)
end
else
player:messageSpecial(ID.text.YOU_MUST_WAIT_ANOTHER_N_DAYS, GOBBIE_BOX_MIN_AGE - playerAgeDays)
end
end

function onEventUpdate(player, csid, option)
local dailyTallyPoints = player:getCurrency("daily_tally")
local holdingItem = player:getCharVar("gobbieBoxHoldingItem")
local gobbieBoxUsed = player:getCharVar("gobbieBoxUsed")
local specialDialUsed = player:getMaskBit(gobbieBoxUsed, 0) and 1 or 0
local adoulinDialUsed = player:getMaskBit(gobbieBoxUsed, 1) and 1 or 0
local pictlogicaDialUsed = player:getMaskBit(gobbieBoxUsed, 2) and 1 or 0
local wantedDialUsed = player:getMaskBit(gobbieBoxUsed, 3) and 1 or 0
local itemid = 0

if csid == 520 and option == 4 then -- Peek items
player:updateEvent(200, 200, 200)
elseif csid == 520 and option == 9 then
player:updateEvent(1, 1, (dailyTallyPoints >= 10) or 1)
elseif csid == 520 and option == 10 then
-- Deliver Dial 1
if csid == 520 then
switch (option): caseof
{
[4] = function() -- Peek items
player:updateEvent(player:selectDailyItem(6), player:selectDailyItem(6), player:selectDailyItem(6))
end,
[9] = function() -- Dial 1
cocosolos marked this conversation as resolved.
Show resolved Hide resolved
if dailyTallyPoints >= 10 then
itemid = player:selectDailyItem(1)
player:setCharVar("gobbieBoxHoldingItem", itemid)
player:setCurrency("daily_tally", dailyTallyPoints - 10)
player:updateEvent(itemid, 1, 0)
else
player:updateEvent(1, 1, 1) -- not enough points
end
end,
[10] = function()
if player:getFreeSlotsCount() == 0 then
player:updateEvent(holdingItem, 0, 0, 1) -- inventory full, exit event
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item."
end
end,
[13] = function() -- Dial 1 Finish
if dailyTallyPoints >= 10 then
if npcUtil.giveItem(player, holdingItem) then
player:setCharVar("gobbieBoxHoldingItem", 0)
end
end
player:updateEvent(specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, player:getCurrency("daily_tally"))
end,
[17] = function() -- Dial 2
if dailyTallyPoints >= 10 then
itemid = player:selectDailyItem(2)
player:setCharVar("gobbieBoxHoldingItem", itemid)
player:setCurrency("daily_tally", dailyTallyPoints - 10)
player:updateEvent(itemid, 2, 0)
else
player:updateEvent(1, 2, 1) -- not enough points
end
end,
[18] = function()
if player:getFreeSlotsCount() == 0 then
player:updateEvent(holdingItem, 0, 0, 1) -- inventory full, exit event
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item."
end
end,
[21] = function() -- Dial 2 Finish
if dailyTallyPoints >= 10 then
if npcUtil.giveItem(player, holdingItem) then
player:setCharVar("gobbieBoxHoldingItem", 0)
end
end
player:updateEvent(specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, player:getCurrency("daily_tally"))
end,
[25] = function() -- Dial 3
if dailyTallyPoints >= 10 then
itemid = player:selectDailyItem(3)
player:setCharVar("gobbieBoxHoldingItem", itemid)
player:setCurrency("daily_tally", dailyTallyPoints - 10)
player:updateEvent(itemid, 3, 0)
else
player:updateEvent(1, 3, 1) -- not enough points
end
end,
[26] = function()
if player:getFreeSlotsCount() == 0 then
player:updateEvent(holdingItem, 0, 0, 1) -- inventory full, exit event
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item."
end
end,
[29] = function() -- Dial 3 Finish
if dailyTallyPoints >= 10 then
if npcUtil.giveItem(player, holdingItem) then
player:setCharVar("gobbieBoxHoldingItem", 0)
end
end
player:updateEvent(specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, player:getCurrency("daily_tally"))
end,
[33] = function() -- Dial 4
if dailyTallyPoints >= 10 then
itemid = player:selectDailyItem(4)
player:setCharVar("gobbieBoxHoldingItem", itemid)
player:setCurrency("daily_tally", dailyTallyPoints - 10)
player:updateEvent(itemid, 4, 0)
else
player:updateEvent(1, 4, 1) -- not enough points
end
end,
[34] = function()
if player:getFreeSlotsCount() == 0 then
player:updateEvent(holdingItem, 0, 0, 1) -- inventory full, exit event
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item."
end
end,
[37] = function() -- Dial 4 Finish
if dailyTallyPoints >= 10 then
if npcUtil.giveItem(player, holdingItem) then
player:setCharVar("gobbieBoxHoldingItem", 0)
end
end
player:updateEvent(specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, player:getCurrency("daily_tally"))
end,
[41] = function() -- Dial 5
if dailyTallyPoints >= 10 then
itemid = player:selectDailyItem(5)
player:setCharVar("gobbieBoxHoldingItem", itemid)
player:setCurrency("daily_tally", dailyTallyPoints - 10)
player:updateEvent(itemid, 5, 0)
else
player:updateEvent(1, 5, 1) -- not enough points
end
end,
[42] = function()
if player:getFreeSlotsCount() == 0 then
player:updateEvent(holdingItem, 0, 0, 1) -- inventory full, exit event
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item."
end
end,
[45] = function() -- Dial 5 Finish
if dailyTallyPoints >= 10 then
if npcUtil.giveItem(player, holdingItem) then
player:setCharVar("gobbieBoxHoldingItem", 0)
end
end
player:updateEvent(specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, player:getCurrency("daily_tally"))
end,
[49] = function() -- Special Dial
if specialDialUsed == 1 then
player:updateEvent(1, 6, 2) -- already used this dial
elseif dailyTallyPoints >= 50 then
itemid = player:selectDailyItem(6)
player:setCharVar("gobbieBoxHoldingItem", itemid)
player:setCurrency("daily_tally", dailyTallyPoints - 50)
player:setMaskBit(gobbieBoxUsed, "gobbieBoxUsed", 0, true)
player:updateEvent(itemid, 6, 0)
else
player:updateEvent(1, 6, 1) -- not enough points
end
end,
[50] = function()
if player:getFreeSlotsCount() == 0 then
player:updateEvent(holdingItem, 0, 0, 1) -- inventory full, exit event
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item."
end
end,
[53] = function() -- Special Dial Finish
if dailyTallyPoints >= 50 then
if npcUtil.giveItem(player, holdingItem) then
player:setCharVar("gobbieBoxHoldingItem", 0)
end
end
player:updateEvent(specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, player:getCurrency("daily_tally"))
end,
}
end
end

function onEventFinish(player, csid, option)
if csid == 519 then
player:setCurrency("daily_tally", 50)
elseif csid == 521 then
if player:getFreeSlotsCount() == 0 then
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item."
elseif npcUtil.giveItem(player, player:getCharVar("gobbieBoxHoldingItem")) then
player:setCharVar("gobbieBoxHoldingItem", 0)
ibm2431 marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Loading