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

Fishing Seaweed & Caskets #425

Open
wants to merge 5 commits into
base: kotlin-experiments
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
Expand Up @@ -19,7 +19,13 @@ enum class Fish(val id: Int, val level: Int, val experience: Double, catchSuffix
LOBSTER(id = 377, level = 40, experience = 90.0),
BASS(id = 363, level = 46, experience = 100.0),
SWORDFISH(id = 371, level = 50, experience = 100.0),
SHARK(id = 383, level = 76, experience = 110.0, catchSuffix = "a shark!");
SHARK(id = 383, level = 76, experience = 110.0, catchSuffix = "a shark!"),

/*
* Junk 'fish'
*/
SEAWEED(id = 401, level = 16, experience = 1.0),
CASKET(id = 405, level = 16, experience = 1.0);

/**
* The name of this fish, formatted so it can be inserted into a message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum class FishingSpot(val npc: Int, private val first: Option, private val seco

NET_HARPOON(
npc = 313,
first = Option.of(tool = FishingTool.BIG_NET, primary = MACKEREL, secondary = COD),
first = Option.of(tool = FishingTool.BIG_NET, primary = MACKEREL, secondary = COD, junk = arrayOf(SEAWEED, CASKET)),
second = Option.of(tool = FishingTool.HARPOON, primary = BASS, secondary = SHARK)
),

Expand Down Expand Up @@ -77,10 +77,16 @@ enum class FishingSpot(val npc: Int, private val first: Option, private val seco
/**
* A [FishingSpot] [Option] that can provide a two different types of fish.
*/
private data class Pair(override val tool: FishingTool, val primary: Fish, val secondary: Fish) : Option() {
private data class Pair(override val tool: FishingTool, val primary: Fish, val secondary: Fish, val junk: Array<Fish>) : Option() {
override val level = Math.min(primary.level, secondary.level)

override fun sample(level: Int): Fish {
if (junk.isNotEmpty() && rand(100) < JUNK_WEIGHTING) {
Copy link
Contributor

@garyttierney garyttierney Apr 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we need a unit test for this, but I'm not quite sure how we go about stubbing the randomness in this case (cc @Major-).

val valid = junk.filter { level >= it.level }
if (valid.isNotEmpty()) {
return valid[rand(valid.size)]
}
}
return if (level < secondary.level || rand(100) < WEIGHTING) {
primary
} else {
Expand All @@ -93,6 +99,11 @@ enum class FishingSpot(val npc: Int, private val first: Option, private val seco
* The weighting factor that causes the lower-level fish to be returned more frequently.
*/
private const val WEIGHTING = 70

/**
* The weighting factor that causes a junk item to be fished more frequently.
*/
private const val JUNK_WEIGHTING = 5
}
}

Expand All @@ -101,9 +112,18 @@ enum class FishingSpot(val npc: Int, private val first: Option, private val seco
fun of(tool: FishingTool, primary: Fish): Option = Single(tool, primary)

fun of(tool: FishingTool, primary: Fish, secondary: Fish): Option {
return when {
primary.level < secondary.level -> Pair(tool, primary, secondary)
else -> Pair(tool, secondary, primary)
return if (primary.level < secondary.level) {
Pair(tool, primary, secondary, emptyArray())
} else {
Pair(tool, secondary, primary, emptyArray())
}
}

fun of(tool: FishingTool, primary: Fish, secondary: Fish, junk: Array<Fish>): Option {
return if (primary.level < secondary.level) {
Pair(tool, primary, secondary, junk)
} else {
Pair(tool, secondary, primary, junk)
}
}
}
Expand Down