Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fishing #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package gg.rsmod.plugins.content.skills.fishing.action

import gg.rsmod.game.fs.def.ItemDef
import gg.rsmod.game.model.entity.Player
import gg.rsmod.game.model.queue.QueueTask
import gg.rsmod.plugins.api.Skills
import gg.rsmod.plugins.api.ext.filterableMessage
import gg.rsmod.plugins.api.ext.interpolate
import gg.rsmod.plugins.api.ext.playSound
import gg.rsmod.plugins.api.ext.player
import gg.rsmod.plugins.content.skills.fishing.data.Fish
import gg.rsmod.plugins.content.skills.fishing.data.FishingOption
import kotlin.random.Random

/**
* @author Vashmeed
*/
object Fishing {
suspend fun fish(it: QueueTask, option: FishingOption) {
val p = it.player

if (!canFish(p, option)) {
return
}

while (true) {
p.animate(option.animationId)
it.wait(2)

if (!canFish(p, option)) {
p.animate(-1)
break
}

val level = p.getSkills().getCurrentLevel(Skills.FISHING)
if (level.interpolate(minChance = 60, maxChance = 190, minLvl = 1, maxLvl = 99, cap = 255)) {
p.filterableMessage("You catch some fish.")
p.playSound(3600)
if (option.bait != null)
p.inventory.remove(option.bait)
val node = reward(p, option)

p.inventory.add(node.item)
p.addXp(Skills.FISHING, node.experience)
}
it.wait(2)
}
}

private fun reward(p: Player, option: FishingOption): Fish {
if (option.equals(FishingOption.BIG_NET)) {
when (Random.nextInt(0, 100)) {
0 -> Fish.OYSTER
50 -> Fish.CASKET
90 -> Fish.SEAWEED
}
}
if (option.equals(FishingOption.LURE) && p.inventory.contains(10087)) {
return Fish.RAINBOW_FISH
}
return option.fishType.filter { p.getSkills().getMaxLevel(Skills.FISHING) >= it.levelReq }.random()
}

private fun canFish(p: Player, npc: FishingOption): Boolean {
val tool = FishingOption.values.firstOrNull { p.getSkills().getMaxLevel(Skills.FISHING) >= it.levelReq && (p.equipment.contains(npc.toolId) || p.inventory.contains(npc.toolId)) }
if (tool == null) {
p.message("You need a ${p.world.definitions.get(ItemDef::class.java, npc.toolId).name} to fish here.")
return false
}

if (npc.bait != null) {
val bait = FishingOption.values.firstOrNull { (p.inventory.contains(npc.bait)) }
if (bait == null) {
p.message("You need ${p.world.definitions.get(ItemDef::class.java, npc.bait).name} to bait this fish.")
return false
}
}
if (p.getSkills().getMaxLevel(Skills.FISHING) < npc.levelReq) {
p.message("You need a Fishing level of ${npc.levelReq} to fish here.")
return false
}

if (p.inventory.isFull) {
p.message("Your inventory is too full to hold any more fish.")
return false
}

return true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package gg.rsmod.plugins.content.skills.fishing.data

import gg.rsmod.plugins.api.cfg.Items

/**
* @author Vashmeed
*/
enum class Fish(val item: Int, val levelReq: Int, val experience: Double) {
SHRIMP(
item = Items.RAW_SHRIMPS,
levelReq = 1,
experience = 10.0
),
SARDINE(
item = Items.RAW_SARDINE,
levelReq = 5,
experience = 20.0
),
KARAMBWANJI(
item = Items.RAW_KARAMBWANJI,
levelReq = 5,
experience = 5.0
),
HERRING(
item = Items.RAW_HERRING,
levelReq = 10,
experience = 30.0
),
ANCHOVIE(
item = Items.RAW_ANCHOVIES,
levelReq = 15,
experience = 40.0
),
MACKEREL(
item = Items.RAW_MACKEREL,
levelReq = 16,
experience = 20.0
),
TROUT(
item = Items.RAW_TROUT,
levelReq = 20,
experience = 50.0
),
COD(
item = Items.RAW_COD,
levelReq = 23,
experience = 45.0
),
PIKE(
item = Items.RAW_PIKE,
levelReq = 25,
experience = 60.0
),
SLIMY_EEL(
item = Items.RAW_SLIMY_EEL,
levelReq = 28,
experience = 65.0
),
SALMON(
item = Items.RAW_SALMON,
levelReq = 30,
experience = 70.0
),
FROG_SPAWN(
item = Items.FROG_SPAWN,
levelReq = 33,
experience = 75.0
),
TUNA(
item = Items.RAW_TUNA,
levelReq = 35,
experience = 80.0
),
RAINBOW_FISH(
item = Items.RAW_RAINBOW_FISH,
levelReq = 38,
experience = 80.0
),
CAVE_EEL(
item = Items.RAW_CAVE_EEL,
levelReq = 38,
experience = 80.0
),
LOBSTER(
item = Items.RAW_LOBSTER,
levelReq = 40,
experience = 90.0
),
BASS(
item = Items.RAW_BASS,
levelReq = 46,
experience = 100.0
),
SWORDFISH(
item = Items.RAW_SWORDFISH,
levelReq = 50,
experience = 100.0
),
LAVA_EEL(
item = Items.RAW_LAVA_EEL,
levelReq = 53,
experience = 100.0
),
MONKFISH(
item = Items.RAW_MONKFISH,
levelReq = 62,
experience = 120.0
),
KARAMBWAN(
item = Items.RAW_KARAMBWAN,
levelReq = 65,
experience = 105.0
),
SHARK(
item = Items.RAW_SHARK,
levelReq = 76,
experience = 110.0
),
SEA_TURTLE(
item = Items.RAW_SEA_TURTLE,
levelReq = 79,
experience = 38.0
),
MANTA_RAY(
item = Items.RAW_MANTA_RAY,
levelReq = 81,
experience = 46.0
),
SEAWEED(
item = Items.SEAWEED,
levelReq = 16,
experience = 1.0
),
CASKET(
item = Items.CASKET,
levelReq = 16,
experience = 10.0
),
OYSTER(
item = Items.OYSTER,
levelReq = 16,
experience = 10.0
),
DARK_CRAB(
item = Items.RAW_DARK_CRAB,
levelReq = 85,
experience = 130.0
);

companion object {
val values = enumValues<Fish>()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package gg.rsmod.plugins.content.skills.fishing.data

/**
*
* @author Vashmeed
*
* @property toolId The tool required for the specified option
* @property levelReq The minimum level required to fish
* @property animationId The animation the player plays when using this option
* @property bait The bait the fishing spot requires if any
* @property option The string of the npc option text
* @property fishType the amount of time that the npc stuns the player for
*/
enum class FishingOption(val toolId: Int, val levelReq: Int, val animationId: Int, val bait: Int?, val option: String, val fishType: Array<Fish>) {
NET(
toolId = 303,
levelReq = 1,
animationId = 621,
bait = null,
option = "net",
fishType = arrayOf(Fish.SHRIMP, Fish.ANCHOVIE)
),
SMALL_NET(
toolId = 303,
levelReq = 1,
animationId = 621,
bait = null,
option = "small net",
fishType = arrayOf(Fish.SHRIMP, Fish.ANCHOVIE)
),
BAIT(
toolId = 307,
levelReq = 5,
animationId = 622,
bait = 313,
option = "bait",
fishType = arrayOf(Fish.SARDINE, Fish.HERRING)
),
BAIT_EEL(
toolId = 307,
levelReq = 5,
animationId = 622,
bait = 313,
option = "bait",
fishType = arrayOf(Fish.CAVE_EEL)
),
LURE(
toolId = 309,
levelReq = 20,
animationId = 622,
bait = 314,
option = "lure",
fishType = arrayOf(Fish.TROUT, Fish.SALMON, Fish.RAINBOW_FISH)
),
FISH(
toolId = 309,
levelReq = 20,
animationId = 622,
bait = 314,
option = "fish",
fishType = arrayOf(Fish.TROUT, Fish.SALMON, Fish.RAINBOW_FISH)
),
USE_ROD(
toolId = 309,
levelReq = 20,
animationId = 622,
bait = 314,
option = "use-rod",
fishType = arrayOf(Fish.TROUT, Fish.SALMON, Fish.RAINBOW_FISH)
),
L_BAIT(
toolId = 307,
levelReq = 25,
animationId = 622,
bait = 313,
option = "bait",
fishType = arrayOf(Fish.PIKE)
),
CAGE(
toolId = 301,
levelReq = 40,
animationId = 619,
bait = null,
option = "cage",
fishType = arrayOf(Fish.LOBSTER)
),
HARPOON(
toolId = 311,
levelReq = 35,
animationId = 618,
bait = null,
option = "harpoon",
fishType = arrayOf(Fish.TUNA, Fish.SWORDFISH)
),
BARB_HARPOON(
toolId = 10129,
levelReq = 35,
animationId = 618,
bait = null,
option = "harpoon",
fishType = arrayOf(Fish.TUNA, Fish.SWORDFISH)
),
CATCH(
toolId = 10129,
levelReq = 35,
animationId = 618,
bait = null,
option = "catch",
fishType = arrayOf(Fish.TUNA, Fish.SWORDFISH)
),
BIG_NET(
toolId = 305,
levelReq = 16,
animationId = 620,
bait = null,
option = "big net",
fishType = arrayOf(Fish.MACKEREL, Fish.COD, Fish.BASS)
),
N_HARPOON(
toolId = 311,
levelReq = 76,
animationId = 618,
bait = null,
option = "harpoon",
fishType = arrayOf(Fish.SHARK)
),
H_NET(
toolId = 303,
levelReq = 1,
animationId = 621,
bait = null,
option = "net",
fishType = arrayOf(Fish.MONKFISH)
),
C_CAGE(
toolId = 301,
levelReq = 85,
animationId = 619,
bait = 14943,
option = "cage",
fishType = arrayOf(Fish.DARK_CRAB)
);

companion object {
val values = enumValues<FishingOption>()
}
}
Loading