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 2 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,14 @@ 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)
;
Copy link
Contributor

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.


/**
* 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,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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove the data modifier?

Copy link
Contributor

Choose a reason for hiding this comment

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

There's also no reason for junk to be variadic. This constructor isn't a user facing API.

Copy link
Author

@Tomm0017 Tomm0017 Apr 26, 2019

Choose a reason for hiding this comment

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

The data modifier was removed as you can't have variadic values in a data class. I'll fix this though, thanks!

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) {
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 when {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be if-else instead of when.

level < secondary.level || rand(100) < WEIGHTING -> primary
else -> secondary
}
}

Expand All @@ -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
}
}

Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Write this as if-else instead

primary.level < secondary.level -> Pair(tool, primary, secondary, *junk)
else -> Pair(tool, secondary, primary, *junk)
}
}
}
}

Expand Down