44xi = xi or {}
55xi .fishingContest = xi .fishingContest or {}
66
7- local exDataIndex =
8- {
9- LENGTH = 0x00 ,
10- WEIGHT = 0x02 ,
11- RANKED = 0x04 ,
12- }
13-
147xi .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
120113end
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
124115local 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 )
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-
283229xi .fishingContest .selectContestFish = function ()
284230 return utils .randomEntry (xi .fishingContest .fish )[' id' ]
285231end
@@ -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