-
Notifications
You must be signed in to change notification settings - Fork 141
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
base: kotlin-experiments
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
), | ||
|
||
|
@@ -77,14 +77,19 @@ 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 class Pair(override val tool: FishingTool, val primary: Fish, val secondary: Fish, vararg val junk: Fish) : Option() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also no reason for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
override val level = Math.min(primary.level, secondary.level) | ||
|
||
override fun sample(level: Int): Fish { | ||
return if (level < secondary.level || rand(100) < WEIGHTING) { | ||
primary | ||
} else { | ||
secondary | ||
if (junk.isNotEmpty() && rand(100) < JUNK_WEIGHTING) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 when { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
level < secondary.level || rand(100) < WEIGHTING -> primary | ||
else -> secondary | ||
} | ||
} | ||
|
||
|
@@ -93,6 +98,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 | ||
} | ||
} | ||
|
||
|
@@ -106,6 +116,13 @@ enum class FishingSpot(val npc: Int, private val first: Option, private val seco | |
else -> Pair(tool, secondary, primary) | ||
} | ||
} | ||
|
||
fun of(tool: FishingTool, primary: Fish, secondary: Fish, junk: Array<Fish>): Option { | ||
return when { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Write this as |
||
primary.level < secondary.level -> Pair(tool, primary, secondary, *junk) | ||
else -> Pair(tool, secondary, primary, *junk) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this semicolon back to the previous line.