Skip to content

Commit a8ee534

Browse files
fix: mechanical fishing rod (#731)
* fix: mechanical fishing rod It behaves as a regular fishing rod with all it's features, plus adds the mechanical fish if you use it in yalahar sewers just as real Tibia. * Lua code format - (Stylua) --------- Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com>
1 parent 08d7900 commit a8ee534

1 file changed

Lines changed: 293 additions & 20 deletions

File tree

data-global/scripts/actions/other/mechanical_fishing.lua

Lines changed: 293 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,193 @@
1-
local waterIds = { 622, 4597, 4598, 4599, 4600, 4601, 4602, 4609, 4610, 4611, 4612, 4613, 4614, 629, 630, 631, 632, 633, 634, 7236, 9582, 13988, 13989 }
1+
local waterIds = { 622, 4597, 4598, 4599, 4600, 12561, 12563, 4601, 4602, 4609, 4610, 4611, 4612, 4613, 4614, 629, 630, 631, 632, 633, 634, 7236, 9582, 12560, 12561, 12562, 12563, 12558, 12559, 13988, 13989, 21414, 21312 }
2+
23
local lootTrash = { 3119, 3123, 3264, 3409, 3578 }
34
local lootCommon = { 3035, 3051, 3052, 3580, 236, 237 }
45
local lootRare = { 3026, 3029, 3032, 7158, 7159 }
56
local lootVeryRare = { 281, 282, 9303 }
7+
local lootVeryRare1 = { 281, 12557 }
8+
local lootRare1 = { 3026, 12557 }
9+
local lootCommon1 = { 3035, 237, 12557 }
10+
11+
local fishableWaterIds = {
12+
4597,
13+
4598,
14+
4599,
15+
4600,
16+
4601,
17+
4602,
18+
629,
19+
630,
20+
631,
21+
632,
22+
633,
23+
634,
24+
21312,
25+
}
26+
27+
local nonFishableWaterIds = {
28+
4609,
29+
4610,
30+
4611,
31+
4612,
32+
4613,
33+
4614,
34+
4809,
35+
4810,
36+
4811,
37+
4812,
38+
4813,
39+
4814,
40+
21314,
41+
}
42+
43+
local dirtyWaterFishable = { 12561, 12562, 12563 }
44+
local dirtyWaterSpent = { 12558, 12559, 12560 }
45+
46+
local dirtyWaterTransform = {
47+
[12561] = 12558,
48+
[12562] = 12559,
49+
[12563] = 12560,
50+
}
51+
52+
local SHIMMER_COOLDOWN_STORAGE = 20526
53+
local SHIMMER_COUNT_STORAGE = 20527
54+
local SHIMMER_COOLDOWN_SECONDS = 20 * 60 * 60
55+
56+
local transformToNonFishable = {
57+
[4597] = { to = 4609, decay = true },
58+
[4598] = { to = 4610, decay = true },
59+
[4599] = { to = 4611, decay = true },
60+
[4600] = { to = 4612, decay = true },
61+
[4601] = { to = 4613, decay = true },
62+
[4602] = { to = 4614, decay = true },
63+
[629] = { to = 4809, decay = true },
64+
[630] = { to = 4810, decay = true },
65+
[631] = { to = 4811, decay = true },
66+
[632] = { to = 4812, decay = true },
67+
[633] = { to = 4813, decay = true },
68+
[634] = { to = 4814, decay = true },
69+
[21312] = { to = 21314, decay = true },
70+
}
71+
72+
local elementals = {
73+
chances = {
74+
{ from = 0, to = 500, itemId = 3026 }, -- white pearl
75+
{ from = 501, to = 801, itemId = 3029 }, -- small sapphire
76+
{ from = 802, to = 1002, itemId = 3032 }, -- small emerald
77+
{ from = 1003, to = 1053, itemId = 281 }, -- giant shimmering pearl (green)
78+
{ from = 1054, to = 1104, itemId = 282 }, -- giant shimmering pearl (brown)
79+
{ from = 1105, to = 1115, itemId = 9303 }, -- leviathan's amulet
80+
},
81+
}
82+
683
local useWorms = true
784

85+
local YALAHAR_SEWERS = {
86+
fromX = 32736,
87+
fromY = 31142,
88+
toX = 32854,
89+
toY = 31260,
90+
z = 8,
91+
}
92+
local MECHANICAL_FISH_ID = 9307
93+
local NAIL_ID = 953
94+
95+
local function isInYalaharSewers(position)
96+
return position.x >= YALAHAR_SEWERS.fromX and position.x <= YALAHAR_SEWERS.toX and position.y >= YALAHAR_SEWERS.fromY and position.y <= YALAHAR_SEWERS.toY and position.z == YALAHAR_SEWERS.z
97+
end
98+
99+
local function refreeIceHole(position)
100+
local iceHole = Tile(position):getItemById(7237)
101+
if iceHole then
102+
iceHole:transform(7200)
103+
end
104+
end
105+
106+
local function handleDirtyWaterFishing(player, target, toPosition)
107+
local targetId = target.itemid
108+
109+
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
110+
111+
if player:getItemCount(3492) > 0 then
112+
player:addSkillTries(SKILL_FISHING, 1, true)
113+
end
114+
115+
local successChance = math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50)
116+
if math.random(100) > successChance then
117+
return true
118+
end
119+
120+
if useWorms and not player:removeItem("worm", 1) then
121+
return true
122+
end
123+
124+
local newId = dirtyWaterTransform[targetId]
125+
if newId then
126+
target:transform(newId)
127+
target:decay()
128+
end
129+
local dirtyWaterRoll = math.random(100)
130+
131+
if dirtyWaterRoll <= 30 then
132+
if math.random(100) == 100 then
133+
local cooldownExpiry = player:getStorageValue(SHIMMER_COOLDOWN_STORAGE)
134+
if cooldownExpiry ~= -1 and os.time() < cooldownExpiry then
135+
player:addItem(3111, 1)
136+
return true
137+
end
138+
139+
player:addItem(12557, 1)
140+
player:setStorageValue(SHIMMER_COOLDOWN_STORAGE, os.time() + SHIMMER_COOLDOWN_SECONDS)
141+
142+
local currentCount = player:getStorageValue(SHIMMER_COUNT_STORAGE)
143+
if currentCount == -1 then
144+
currentCount = 0
145+
end
146+
currentCount = currentCount + 1
147+
player:setStorageValue(SHIMMER_COUNT_STORAGE, currentCount)
148+
149+
if currentCount >= 50 and not player:hasAchievement("Biodegradable") then
150+
player:addAchievement("Biodegradable")
151+
end
152+
153+
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A Shimmer Swimmer! It is said that this creature only appears once each day in the murkiest of waters!")
154+
else
155+
player:addItem(3111, 1)
156+
end
157+
end
158+
159+
return true
160+
end
161+
162+
local function handleDesertFishing(player, target, toPosition)
163+
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
164+
165+
if player:getItemCount(3492) > 0 then
166+
player:addSkillTries(SKILL_FISHING, 1, true)
167+
end
168+
169+
local successChance = math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50)
170+
if math.random(100) > successChance then
171+
return true
172+
end
173+
174+
if useWorms and not player:removeItem("worm", 1) then
175+
return true
176+
end
177+
178+
target:transform(13988)
179+
target:decay()
180+
181+
if math.random(100) == 1 then
182+
player:addItem(13992, 1)
183+
if not player:hasAchievement("Desert Fisher") then
184+
player:addAchievement("Desert Fisher")
185+
end
186+
end
187+
188+
return true
189+
end
190+
8191
local mechanicalFishing = Action()
9192

10193
function mechanicalFishing.onUse(player, item, fromPosition, target, toPosition, isHotkey)
@@ -13,6 +196,59 @@ function mechanicalFishing.onUse(player, item, fromPosition, target, toPosition,
13196
end
14197

15198
local targetId = target.itemid
199+
200+
if isInYalaharSewers(toPosition) and player:getItemCount(NAIL_ID) > 0 then
201+
if table.contains(nonFishableWaterIds, targetId) or table.contains(dirtyWaterSpent, targetId) then
202+
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
203+
return true
204+
end
205+
206+
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
207+
208+
player:addSkillTries(SKILL_FISHING, 1, true)
209+
210+
local successChance = math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50)
211+
if math.random(100) > successChance then
212+
return true
213+
end
214+
215+
player:removeItem(NAIL_ID, 1)
216+
217+
if transformToNonFishable[targetId] then
218+
local transformInfo = transformToNonFishable[targetId]
219+
target:transform(transformInfo.to)
220+
if transformInfo.decay then
221+
target:decay()
222+
end
223+
end
224+
225+
player:addItem(MECHANICAL_FISH_ID, 1)
226+
return true
227+
end
228+
229+
if table.contains(dirtyWaterSpent, targetId) then
230+
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
231+
return true
232+
end
233+
234+
if table.contains(dirtyWaterFishable, targetId) then
235+
return handleDirtyWaterFishing(player, target, toPosition)
236+
end
237+
238+
if targetId == 13989 then
239+
return handleDesertFishing(player, target, toPosition)
240+
end
241+
242+
if targetId == 13988 then
243+
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
244+
return true
245+
end
246+
247+
if table.contains(nonFishableWaterIds, targetId) then
248+
toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
249+
return true
250+
end
251+
16252
if targetId == 9582 then
17253
local owner = target:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER)
18254
if owner ~= 0 and owner ~= player.uid then
@@ -21,15 +257,30 @@ function mechanicalFishing.onUse(player, item, fromPosition, target, toPosition,
21257
end
22258

23259
toPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
24-
target:remove()
260+
target:transform(target.itemid + 1)
25261

262+
local chance = math.random(10000)
263+
for i = 1, #elementals.chances do
264+
local randomItem = elementals.chances[i]
265+
if chance >= randomItem.from and chance <= randomItem.to then
266+
player:addItem(randomItem.itemId, 1)
267+
end
268+
if chance > 1115 then
269+
player:say("There was just rubbish in it.", TALKTYPE_MONSTER_SAY)
270+
return true
271+
end
272+
end
273+
end
274+
275+
if targetId == 12560 then
276+
toPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
26277
local rareChance = math.random(100)
27278
if rareChance == 1 then
28-
player:addItem(lootVeryRare[math.random(#lootVeryRare)], 1)
279+
player:addItem(lootVeryRare1[math.random(#lootVeryRare1)], 1)
29280
elseif rareChance <= 3 then
30-
player:addItem(lootRare[math.random(#lootRare)], 1)
281+
player:addItem(lootRare1[math.random(#lootRare1)], 1)
31282
elseif rareChance <= 10 then
32-
player:addItem(lootCommon[math.random(#lootCommon)], 1)
283+
player:addItem(lootCommon1[math.random(#lootCommon1)], 1)
33284
else
34285
player:addItem(lootTrash[math.random(#lootTrash)], 1)
35286
end
@@ -44,38 +295,60 @@ function mechanicalFishing.onUse(player, item, fromPosition, target, toPosition,
44295
return true
45296
end
46297

47-
player:addSkillTries(SKILL_FISHING, 1, true)
48-
if math.random(100) <= math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50) then
49-
if useWorms and not player:removeItem("nail", 1) then
50-
return true
51-
end
52-
53-
if targetId == 13988 then
54-
target:transform(targetId + 1)
55-
target:decay()
56-
298+
if useWorms and targetId == 21414 and player:removeItem("worm", 1) then
299+
if player:getStorageValue(Storage.Quest.U10_55.Dawnport.TheDormKey) == 2 then
57300
if math.random(100) >= 97 then
58-
player:addItem(13992, 1)
301+
player:addItem(21402, 1)
302+
player:setStorageValue(Storage.Quest.U10_55.Dawnport.TheDormKey, 3)
303+
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "With a giant splash, you heave an enormous fish out of the water.")
59304
return true
60305
end
61-
elseif targetId == 7236 then
62-
target:transform(targetId + 1)
63-
target:decay()
306+
elseif math.random(100) <= math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50) then
307+
player:addItem(3578, 1)
308+
end
309+
end
310+
311+
if player:getItemCount(3492) > 0 and table.contains(fishableWaterIds, targetId) then
312+
player:addSkillTries(SKILL_FISHING, 1, true)
313+
end
314+
315+
if math.random(100) <= math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50) then
316+
if useWorms and not player:removeItem("worm", 1) then
317+
return true
318+
end
64319

320+
if targetId == 7236 then
321+
target:transform(7237)
322+
local position = target:getPosition()
323+
addEvent(refreeIceHole, 1000 * 60 * 15, position)
65324
local rareChance = math.random(100)
66325
if rareChance == 1 then
67326
player:addItem(7158, 1)
327+
player:addAchievementProgress("Exquisite Taste", 250)
68328
return true
69329
elseif rareChance <= 4 then
70330
player:addItem(3580, 1)
331+
player:addAchievementProgress("Exquisite Taste", 250)
71332
return true
72333
elseif rareChance <= 10 then
73334
player:addItem(7159, 1)
335+
player:addAchievementProgress("Exquisite Taste", 250)
74336
return true
75337
end
76338
end
77-
player:addItem("mechanical fish", 1)
339+
340+
if transformToNonFishable[targetId] then
341+
local transformInfo = transformToNonFishable[targetId]
342+
target:transform(transformInfo.to)
343+
if transformInfo.decay then
344+
target:decay()
345+
end
346+
end
347+
348+
player:addItem(3578, 1)
349+
player:addAchievementProgress("Here, Fishy Fishy!", 250)
78350
end
351+
79352
return true
80353
end
81354

0 commit comments

Comments
 (0)