|
| 1 | +-------------------------------------------------------- |
| 2 | +require("scripts/globals/settings") |
| 3 | +require("scripts/globals/utils") |
| 4 | +------------------------------------------------------- |
| 5 | + |
| 6 | +tpz = tpz or {} |
| 7 | +tpz.mystery = tpz.mystery or {} |
| 8 | + |
| 9 | +local adoulinOptionOff = 0x80 |
| 10 | +local pictlogicaOptionOff = 0x100 |
| 11 | +local wantedOptionOff = 0x1000 |
| 12 | +local hideOptionFlags = adoulinOptionOff + pictlogicaOptionOff + wantedOptionOff |
| 13 | +local costs = |
| 14 | +{ |
| 15 | + [1] = 10, |
| 16 | + [2] = 10, |
| 17 | + [3] = 10, |
| 18 | + [4] = 10, |
| 19 | + [5] = 10, |
| 20 | + [6] = 50 |
| 21 | +} |
| 22 | +local keyToDial = |
| 23 | +{ |
| 24 | + [8973] = 6, -- special dial |
| 25 | + [9217] = 9, -- abjuration |
| 26 | + [9218] = 10, -- fortune |
| 27 | + --[????] = 11, -- furnishing |
| 28 | + [9274] = 13, -- anniversary |
| 29 | +} |
| 30 | +local abjurationItems = |
| 31 | +{ |
| 32 | + 1314,1315,1316,1317,1318, -- dryadic |
| 33 | + 1319,1320,1321,1322,1323, -- earthen |
| 34 | + 1324,1325,1326,1327,1328, -- aquarian |
| 35 | + 1329,1330,1331,1332,1333, -- martial |
| 36 | + 1334,1335,1336,1337,1338, -- wyrmal |
| 37 | + 1339,1340,1341,1342,1343, -- neptunal |
| 38 | + 1441,1442, -- food |
| 39 | + 2429,2430,2431,2432,2433, -- phantasmal |
| 40 | + 2434,2435,2436,2437,2438, -- hadean |
| 41 | + 3559,3560,3561,3562,3563, -- corvine |
| 42 | + 3564,3565,3566,3567,3568, -- supernal |
| 43 | + 3569,3570,3571,3572,3573, -- transitory |
| 44 | + 3574,3575,3576,3577,3578, -- foreboding |
| 45 | + 3579,3580,3581,3582,3583, -- lenitive |
| 46 | + 8762,8763,8764,8765,8766, -- bushin |
| 47 | + 8767,8768,8769,8770,8771, -- vale |
| 48 | + 8772,8773,8774,8775,8776, -- grove |
| 49 | + 8777,8778,8779,8780,8781, -- triton |
| 50 | + 8782,8783,8784,8785,8786, -- shinryu |
| 51 | + 8787,8788,8789,8790,8791, -- abyssal |
| 52 | + 9105,9106,9107,9108,9109, -- cronian |
| 53 | + 9110,9111,9112,9113,9114, -- arean |
| 54 | + 9115,9116,9117,9118,9119, -- jovian |
| 55 | + 9120,9121,9122,9123,9124, -- venerian |
| 56 | + 9125,9126,9127,9128,9129, -- cyllenian |
| 57 | +} |
| 58 | +local fortuneItems = |
| 59 | +{ |
| 60 | + 5737,5736, -- alexandrite |
| 61 | + 6180,6183,6532, -- pluton |
| 62 | + 6181,6184,6535, -- beitetsu |
| 63 | + 6182,6185,6534, -- rift boulder |
| 64 | + 5854,5855,5856,5857,5858, -- frayed pouches |
| 65 | + 5109,5110,5111,5112,5946,5947,6264,6345,6346,6370,6486,6487,6488 -- frayed sacks |
| 66 | +} |
| 67 | +local anniversaryItems = |
| 68 | +{ |
| 69 | + 9274 -- just give them back their key until this table can be populated |
| 70 | +} |
| 71 | +local gobbieJunk = |
| 72 | +{ |
| 73 | + 507, |
| 74 | + 508, |
| 75 | + 510, |
| 76 | + 511, |
| 77 | + 566, |
| 78 | + 568, |
| 79 | + 1239, |
| 80 | + 1868, |
| 81 | + 2542, |
| 82 | + 2543, |
| 83 | + 4539, |
| 84 | + 4543, |
| 85 | + 9777, |
| 86 | + 15203, |
| 87 | + 18180, |
| 88 | + 19220 |
| 89 | +} |
| 90 | +tpz.mystery.onTrade = function (player, npc, trade, events) |
| 91 | + if trade:getItemCount() == 1 then |
| 92 | + local tradeID = trade:getItemId(0) |
| 93 | + if keyToDial[tradeID] ~= nil then |
| 94 | + if player:getFreeSlotsCount() == 0 then |
| 95 | + player:startEvent(events.FULL_INV, tradeID, keyToDial[tradeID]) |
| 96 | + return false |
| 97 | + end |
| 98 | + player:setLocalVar("gobbieBoxKey", tradeID) |
| 99 | + player:startEvent(events.KEY_TRADE, tradeID, keyToDial[tradeID]) |
| 100 | + else -- trade for points |
| 101 | + return false |
| 102 | + end |
| 103 | + else |
| 104 | + return false |
| 105 | + end |
| 106 | +end |
| 107 | + |
| 108 | +tpz.mystery.onTrigger = function (player, npc, events) |
| 109 | + local event = events |
| 110 | + local playerAgeDays = (os.time() - player:getTimeCreated()) / 86400 |
| 111 | + local dailyTallyPoints = player:getCurrency("daily_tally") |
| 112 | + local firstVisit = dailyTallyPoints == -1 |
| 113 | + local gobbieBoxUsed = player:getCharVar("gobbieBoxUsed") |
| 114 | + local specialDialUsed = utils.mask.getBit(gobbieBoxUsed, 0) and 1 or 0 |
| 115 | + local adoulinDialUsed = utils.mask.getBit(gobbieBoxUsed, 1) and 1 or 0 |
| 116 | + local pictlogicaDialUsed = utils.mask.getBit(gobbieBoxUsed, 2) and 1 or 0 |
| 117 | + local wantedDialUsed = utils.mask.getBit(gobbieBoxUsed, 3) and 1 or 0 |
| 118 | + local holdingItem = player:getCharVar("gobbieBoxHoldingItem") |
| 119 | + |
| 120 | + if playerAgeDays >= GOBBIE_BOX_MIN_AGE and firstVisit then |
| 121 | + player:startEvent(event.INTRO) |
| 122 | + elseif playerAgeDays >= GOBBIE_BOX_MIN_AGE then |
| 123 | + if holdingItem ~= 0 then |
| 124 | + player:startEvent(event.HOLDING_ITEM) |
| 125 | + else |
| 126 | + player:startEvent(event.DEFAULT, specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, dailyTallyPoints) |
| 127 | + end |
| 128 | + else |
| 129 | + player:messageSpecial(zones[player:getZoneID()].text.YOU_MUST_WAIT_ANOTHER_N_DAYS, GOBBIE_BOX_MIN_AGE - playerAgeDays + 1) |
| 130 | + end |
| 131 | +end |
| 132 | + |
| 133 | +tpz.mystery.onEventUpdate = function (player, csid, option, events) |
| 134 | + local event = events |
| 135 | + local dailyTallyPoints = player:getCurrency("daily_tally") |
| 136 | + local holdingItem = player:getCharVar("gobbieBoxHoldingItem") |
| 137 | + local gobbieBoxUsed = player:getCharVar("gobbieBoxUsed") |
| 138 | + local specialDialUsed = utils.mask.getBit(gobbieBoxUsed, 0) and 1 or 0 |
| 139 | + local adoulinDialUsed = utils.mask.getBit(gobbieBoxUsed, 1) and 1 or 0 |
| 140 | + local pictlogicaDialUsed = utils.mask.getBit(gobbieBoxUsed, 2) and 1 or 0 |
| 141 | + local wantedDialUsed = utils.mask.getBit(gobbieBoxUsed, 3) and 1 or 0 |
| 142 | + local itemID = 0 |
| 143 | + |
| 144 | + if csid == event.KEY_TRADE then |
| 145 | + if option == 1 then |
| 146 | + local keyID = player:getLocalVar("gobbieBoxKey") |
| 147 | + player:setLocalVar("gobbieBoxKey", 0) |
| 148 | + switch (keyToDial[keyID]): caseof |
| 149 | + { |
| 150 | + [6] = function() itemID = SelectDailyItem(player, 6) end, -- special dial |
| 151 | + [9] = function() -- abjuration |
| 152 | + itemID = abjurationItems[math.random(1, #abjurationItems)] |
| 153 | + if player:hasItem(itemID) then |
| 154 | + itemID = gobbieJunk[math.random(1, #gobbieJunk)] |
| 155 | + end |
| 156 | + end, |
| 157 | + [10] = function() itemID = fortuneItems[math.random(1, #fortuneItems)] end, -- fortune |
| 158 | + --[??] = function() end, -- furnishing |
| 159 | + [13] = function()-- anniversary |
| 160 | + if math.random(1,100) == 1 then -- 1% chance for ANV exclusive item? |
| 161 | + itemID = anniversaryItems[math.random(1, #anniversaryItems)] |
| 162 | + else |
| 163 | + itemID = SelectDailyItem(player, 6) |
| 164 | + end |
| 165 | + end |
| 166 | + } |
| 167 | + player:setCharVar("gobbieBoxHoldingItem", itemID) |
| 168 | + player:tradeComplete() |
| 169 | + player:updateEvent(itemID, keyToDial[keyID], 3) |
| 170 | + elseif option == 2 then |
| 171 | + if holdingItem > 0 and npcUtil.giveItem(player, holdingItem) then |
| 172 | + player:setCharVar("gobbieBoxHoldingItem", 0) |
| 173 | + end |
| 174 | + player:updateEvent(itemID, 0) |
| 175 | + end |
| 176 | + elseif csid == event.DEFAULT then |
| 177 | + if option == 4 then |
| 178 | + player:updateEvent(SelectDailyItem(player, 6), SelectDailyItem(player, 6), SelectDailyItem(player, 6), 0, 0, 0, 0, dailyTallyPoints) -- peek |
| 179 | + else |
| 180 | + local dial = math.floor(option / 8) |
| 181 | + local option_type = option % 8 |
| 182 | + local dial_used = false |
| 183 | + local dial_cost = costs[dial] |
| 184 | + local dial_mask = false |
| 185 | + if dial >= 6 then |
| 186 | + dial_mask = dial - 6 |
| 187 | + dial_used = utils.mask.getBit(gobbieBoxUsed, dial_mask) |
| 188 | + end |
| 189 | + switch (option_type): caseof |
| 190 | + { |
| 191 | + [1] = function() |
| 192 | + if dial_used then |
| 193 | + player:updateEvent(1, dial, 2) -- already used this dial |
| 194 | + elseif dailyTallyPoints >= dial_cost then |
| 195 | + itemID = SelectDailyItem(player, dial) |
| 196 | + player:setCharVar("gobbieBoxHoldingItem", itemID) |
| 197 | + player:setCurrency("daily_tally", dailyTallyPoints - dial_cost) |
| 198 | + if dial_mask then |
| 199 | + player:setCharVar("gobbieBoxUsed", utils.mask.setBit(gobbieBoxUsed, dial_mask, true)) |
| 200 | + end |
| 201 | + player:updateEvent(itemID, dial, 0) |
| 202 | + else |
| 203 | + player:updateEvent(1, dial, 1) -- not enough points |
| 204 | + end |
| 205 | + end, |
| 206 | + [2] = function() |
| 207 | + if player:getFreeSlotsCount() == 0 then |
| 208 | + player:updateEvent(holdingItem, 0, 0, 1) -- inventory full, exit event |
| 209 | + player:messageSpecial(zones[player:getZoneID()].text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item." |
| 210 | + end |
| 211 | + end, |
| 212 | + [5] = function() |
| 213 | + if holdingItem > 0 and npcUtil.giveItem(player, holdingItem) then |
| 214 | + player:setCharVar("gobbieBoxHoldingItem", 0) |
| 215 | + end |
| 216 | + player:updateEvent(specialDialUsed, adoulinDialUsed, pictlogicaDialUsed, wantedDialUsed, 0, 0, hideOptionFlags, dailyTallyPoints) |
| 217 | + end, |
| 218 | + } |
| 219 | + end |
| 220 | + end |
| 221 | +end |
| 222 | + |
| 223 | +tpz.mystery.onEventFinish = function (player, csid, option, events) |
| 224 | + local event = events |
| 225 | + if csid == event.INTRO then |
| 226 | + player:setCurrency("daily_tally", 50) |
| 227 | + elseif csid == event.HOLDING_ITEM then |
| 228 | + if player:getFreeSlotsCount() == 0 then |
| 229 | + player:messageSpecial(zones[player:getZoneID()].text.ITEM_CANNOT_BE_OBTAINED + 2) -- generic "Cannot obtain the item." |
| 230 | + elseif npcUtil.giveItem(player, player:getCharVar("gobbieBoxHoldingItem")) then |
| 231 | + player:setCharVar("gobbieBoxHoldingItem", 0) |
| 232 | + end |
| 233 | + end |
| 234 | +end |
0 commit comments