Skip to content

Commit c84a2fa

Browse files
sruonatom0s
andcommitted
Exdata definitions
Escutcheons Weapon unlock Soul plate Soul reflectors Fish Co-Authored-By: atom0s <atom0s@users.noreply.github.com>
1 parent 7f0c0ab commit c84a2fa

39 files changed

Lines changed: 943 additions & 420 deletions

scripts/commands/addfish.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ local function error(player, msg)
1717
player:printToPlayer('!addfish <fish> <length> <weight> <optional:ranked>')
1818
end
1919

20-
commandObj.onTrigger = function(player, item, length, weight, ranked)
20+
commandObj.onTrigger = function(player, itemId, length, weight, ranked)
2121
-- Load needed text ids for players current zone..
2222
local ID = zones[player:getZoneID()]
2323
local itemToGet = 0
2424
ranked = ranked and 1 or 0
2525

2626
-- validate item
27-
if item == nil then
27+
if itemId == nil then
2828
-- No Item Provided
2929
error(player, 'No Item ID given.')
3030
return
31-
elseif item ~= nil and tonumber(item) == nil then
31+
elseif itemId ~= nil and tonumber(itemId) == nil then
3232
-- Item was provided, but was not a number. Try text lookup.
3333
local retItems = utils.filterArray(xi.fishingContest.fish, function(_, fish)
34-
return fish.name == item
34+
return fish.name == itemId
3535
end)
3636

3737
if #retItems ~= 1 then
38-
player:printToPlayer(string.format('Item %s not found in fish table.', item))
38+
player:printToPlayer(string.format('Item %s not found in fish table.', itemId))
3939
return
4040
end
4141

4242
itemToGet = retItems[1].id
43-
elseif tonumber(item) ~= nil then
43+
elseif tonumber(itemId) ~= nil then
4444
-- Number was provided, so just use it
45-
itemToGet = item
45+
itemToGet = itemId
4646
end
4747

4848
-- At this point, if there's no item found, exit out of the function
@@ -68,11 +68,14 @@ commandObj.onTrigger = function(player, item, length, weight, ranked)
6868
return
6969
end
7070

71-
-- Give the GM the item...
72-
local obtained = player:addItem({ id = itemToGet,
73-
quantity = 1,
74-
exdata = xi.fishingContest.createExData(length, weight, ranked) })
75-
if obtained then
71+
-- Give the GM the item and set exdata...
72+
local item = player:addItem({ id = itemToGet, quantity = 1 })
73+
if item then
74+
item:setExData({
75+
size = length,
76+
weight = weight,
77+
isRanked = ranked == 1,
78+
})
7679
player:messageSpecial(ID.text.ITEM_OBTAINED, itemToGet)
7780
end
7881
end

scripts/enum/item.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,13 +1657,15 @@ xi.item =
16571657
CHUNK_OF_KAOLIN = 2475,
16581658
SPOOL_OF_PLATINUM_SILK_THREAD = 2476,
16591659
SOUL_PLATE = 2477,
1660+
SOUL_REFLECTOR = 2478,
16601661
CHOCOBET_TICKET = 2479,
16611662
RACE_COMPLETION_CERTIFICATE = 2481,
16621663
MERCENARY_CAMP_ENTRY_SLIP = 2487,
16631664
ALEXANDRITE = 2488,
16641665
FORBIDDEN_KEY = 2490,
16651666
LEUJAOAM_OBSERVATION_LOG = 2491,
16661667
ILRUSI_TRAVEL_LEDGER = 2495,
1668+
OFFICIAL_SOUL_REFLECTOR = 2500,
16671669
BLACK_PUPPET_TURBAN = 2501,
16681670
WHITE_PUPPET_TURBAN = 2502,
16691671
HANDFUL_OF_ALMONDS = 2503,
@@ -10510,6 +10512,7 @@ xi.item =
1051010512
TWINNED_SHIELD = 26414,
1051110513
ADAPA_SHIELD = 26420,
1051210514
NUSKU_SHIELD = 26421,
10515+
JOINERS_ASPIS = 26423,
1051310516
DIAMOND_ASPIS = 26488,
1051410517
TROTH = 26489,
1051510518
POROGGO_FLEECE = 26514,

scripts/globals/fishing_contest.lua

Lines changed: 14 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
xi = xi or {}
55
xi.fishingContest = xi.fishingContest or {}
66

7-
local exDataIndex =
8-
{
9-
LENGTH = 0x00,
10-
WEIGHT = 0x02,
11-
RANKED = 0x04,
12-
}
13-
147
xi.fishingContest.fish =
158
{
169
-- NOTE: If you don't want certain fish included in the contest (era restrictions, or whatever),
@@ -119,8 +112,6 @@ local function findFishSlot(trade, fish)
119112
return 0
120113
end
121114

122-
-- The npcUtil.giveItem function currently does not support custom exdata
123-
-- Since we need to include the measurements of the fish, we need a modified function
124115
local function giveFish(player, params)
125116
params = params or {}
126117
local ID = zones[player:getZoneID()]
@@ -134,7 +125,12 @@ local function giveFish(player, params)
134125
end
135126

136127
-- give items to player
137-
if player:addItem(params) then
128+
local fishItem = player:addItem({ id = fishid, quantity = params.quantity or 1 })
129+
if fishItem then
130+
if params.exdata then
131+
fishItem:setExData(params.exdata)
132+
end
133+
138134
player:messageSpecial(ID.text.ITEM_OBTAINED, fishid)
139135
else
140136
player:messageSpecial(ID.text.ITEM_CANNOT_BE_OBTAINED, fishid)
@@ -230,56 +226,6 @@ end
230226
-- GLOBAL FUNCTIONS
231227
-----------------------------------
232228

233-
-- Create the table of exdata
234-
xi.fishingContest.createExData = function(length, weight, ranked)
235-
-- If the provided data table has a nil value, the key will not be passed to the setExData function
236-
-- setExData only accepts one-byte keys and vals so we need to break down the 16-bit vars
237-
local exData = {}
238-
if length ~= nil then
239-
exData[exDataIndex.LENGTH ] = bit.band(length, 0x00FF)
240-
exData[exDataIndex.LENGTH + 1] = bit.rshift(bit.band(length, 0xFF00), 8)
241-
end
242-
243-
if weight ~= nil then
244-
exData[exDataIndex.WEIGHT ] = bit.band(weight, 0x00FF)
245-
exData[exDataIndex.WEIGHT + 1] = bit.rshift(bit.band(weight, 0xFF00), 8)
246-
end
247-
248-
if ranked ~= nil then
249-
exData[exDataIndex.RANKED ] = ranked
250-
end
251-
252-
return exData
253-
end
254-
255-
-- Read the necessary data from the exdata
256-
xi.fishingContest.getFishData = function(fishItem)
257-
local fishData = fishItem:getExData()
258-
local fishTable = {}
259-
260-
fishTable['length'] = (bit.lshift(fishData[exDataIndex.LENGTH + 1], 8) + fishData[exDataIndex.LENGTH]) or 0
261-
fishTable['weight'] = (bit.lshift(fishData[exDataIndex.WEIGHT + 1], 8) + fishData[exDataIndex.WEIGHT]) or 0
262-
fishTable['ranked'] = fishData[exDataIndex.RANKED]
263-
264-
return fishTable
265-
end
266-
267-
-- Update the fish exdata
268-
xi.fishingContest.setFishData = function(fishItem, length, weight, ranked)
269-
-- Data Table should have only three possible options: 'length', 'width', and 'ranked'
270-
if fishItem == nil then
271-
return
272-
end
273-
274-
-- If the provided data table has a nil value, the key will not be passed to the setExData function
275-
-- setExData only accepts one-byte keys and vals so we need to break down the 16-bit vars
276-
local newExData = xi.fishingContest.createExData(length, weight, ranked)
277-
278-
if newExData ~= nil then
279-
fishItem:setExData(newExData)
280-
end
281-
end
282-
283229
xi.fishingContest.selectContestFish = function()
284230
return utils.randomEntry(xi.fishingContest.fish)['id']
285231
end
@@ -327,25 +273,25 @@ xi.fishingContest.onTrade = function(player, npc, trade)
327273
npcUtil.tradeHasExactly(trade, contest['fishid'])
328274
then
329275
local fishItem = trade:getItem(findFishSlot(trade, contest['fishid']))
330-
local fishData = xi.fishingContest.getFishData(fishItem)
276+
local fishData = fishItem:getExData()
331277

332278
if fishData == nil then
333279
return
334280
elseif
335-
fishData['ranked'] == 1 or
336-
fishData['length'] == 0 or
337-
fishData['weight'] == 0
281+
fishData.isRanked or
282+
fishData.size == 0 or
283+
fishData.weight == 0
338284
then
339285
-- Fish has already been ranked previously
340286
player:startEvent(10007, { [4] = 1 })
341287
else
342288
-- Fish is a valid entry, not previously ranked
343289
-- Player local vars used to hold submission data until end of event
344-
player:setLocalVar('[FishContest]Length', fishData['length'])
345-
player:setLocalVar('[FishContest]Weight', fishData['weight'])
290+
player:setLocalVar('[FishContest]Length', fishData.size)
291+
player:setLocalVar('[FishContest]Weight', fishData.weight)
346292

347293
player:startEvent(10007, {
348-
[5] = scoreFish(fishData['length'], fishData['weight'], contest['criteria']),
294+
[5] = scoreFish(fishData.size, fishData.weight, contest['criteria']),
349295
[6] = player:getContestScore(),
350296
})
351297
end
@@ -452,7 +398,7 @@ xi.fishingContest.onEventFinish = function(player, csid, option, npc)
452398
local weight = player:getLocalVar('[FishContest]Weight')
453399
local obtained = giveFish(player, { id = contest['fishid'],
454400
quantity = 1,
455-
exdata = xi.fishingContest.createExData(length, weight, 1) })
401+
exdata = { size = length, weight = weight, isRanked = true } })
456402
if obtained then
457403
player:confirmTrade()
458404
player:delGil(500) -- Pay the registration fee of 500 gil.

0 commit comments

Comments
 (0)