-
Notifications
You must be signed in to change notification settings - Fork 144
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
Port Herblore plugin to Kotlin #396
Conversation
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.
Have some feedback but nothing major. This looks pretty good.
stop() | ||
} | ||
|
||
if (player.inventory.remove(finished.unf_potion, 1) > 0) { |
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.
player.inventory.remove(id, amount)
returns the number of items that was removed. If you only want to remove one, you can write player.inventory.remove(id)
intead, which returns a boolean indicating if one value was removed/.
MAGIC(id = 3042, unf_potion = UnfinishedPotion.LANTADYME, ingredient = NormalIngredient.POTATO_CACTUS.id, level = 76, experience = 172.5), | ||
ZAMORAK_BREW(id = 189, unf_potion = UnfinishedPotion.TORSTOL, ingredient = NormalIngredient.JANGERBERRIES.id, level = 78, experience = 175.0); | ||
|
||
val unf_potion = unf_potion.id |
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.
Only used internally. May as well inline this where it's used.
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.
What do you exactly mean with this? All the other things have been fixed now!
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.
Just means use the UnfinishedPotion
as the value inside FinishedPotion
, and call unf_potion.id
(or unfinished.id
, whatever it's called now). If you press Ctrl+Shift+N
in IntelliJ it can do this for you.
|
||
val unf_potion = unf_potion.id | ||
companion object { | ||
private val FINISHED_POTION = FinishedPotion.values().associateBy { Pair(it.unf_potion, it.ingredient) } |
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.
i.e.
Pair(it.unfinishedPotion.id, it.ingredient)
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.
What do you exactly mean with this? All the other things have been fixed now!
|
||
enum class FinishedPotion ( | ||
val id: Int, | ||
unf_potion: UnfinishedPotion, |
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.
should be camelCase
|
||
on { ItemOnItemMessage::class } | ||
.where { id == PESTLE_MORTAR || id == KNIFE } | ||
.where { targetId == PESTLE_MORTAR || targetId == KNIFE } |
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.
You can only apply where once, so you'll need to fold this into a single expression.
.where { (id == PESTLE_MORTAR || id == KNIFE) && (targetId == PESTLE_MORTAR || targetId == KNIFE) }
CC @Major- thoughts?
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.
We'll write some shim code to improve this as part of #395. Fine for now.
|
||
class CrushIngredientAction (val player: Player, val ingredient: CrushIngredient) : AsyncAction<Player>(1, false, player) { | ||
override fun action(): ActionBlock = { | ||
if (player.inventory.remove(ingredient.id, 1) > 0) { |
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.
Same as other remove() calls below.
import java.util.* | ||
|
||
private val MIXING_ANIM = Animation(363) | ||
val WATER_VIAL = 227 |
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.
Is this used outside of here? If not you can use const val
cc @Major- we should be distributing code style settings at this point. |
@Chivvon there's also some code-style changes needed throughout - could you run your code through IntelliJ's auto formatter? The .editorconfig we ship should apply most changes. |
Looking good, thank you for the contribution! |
import org.apollo.game.message.impl.ItemOnItemMessage | ||
|
||
on { ItemOptionMessage::class } | ||
.where { option == 1 } |
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.
Could you reduce this to 4 spaces instead of 8? I think .editorconfig should be doing that (cc @Major- if it's not).
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.
(and same below)
} | ||
|
||
on { ItemOnItemMessage::class } | ||
. where { id == WATER_VIAL || targetId == WATER_VIAL } |
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.
Remove the extra whitespace before the dots here.
stop() | ||
} | ||
|
||
if (player.inventory.remove(finished.unfinished.id)) { |
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.
Ah, just re-read the Inventory
docs. You can shorten this to: player.inventory.remove(finished.unfinished.id, finished.ingredient)
.
plugin { | ||
name = "herblore_skill" | ||
authors = [ | ||
"Chivvon" |
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.
Same here with indentation (8 spaces to 4).
} | ||
} | ||
|
||
class MakeUnFinishedPotionAction(val player: Player, val unfinished: UnfinishedPotion) : AsyncAction<Player>(1, false, player) { |
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.
MakeUnfinishedPotionAction
please
val level = mob.herblore.current | ||
|
||
if (level < unfinished.level) { | ||
player.sendMessage("You need an herblore level of ${unfinished.level} to make this unfinished potion.") |
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.
should be "a Herblore level"
if (player.inventory.remove(WATER_VIAL)) { | ||
if (player.inventory.remove(unfinished.herb)) { | ||
player.inventory.add(unfinished.id) | ||
player.sendMessage("You have successfully made the ${Definitions.item(unfinished.id)!!.name.toLowerCase()}.") |
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.
This message should be "You mix the ${Definitions.item(unfinished.id)!!.name.toLowerCase()}. into your potion."
val level: Int, | ||
val experience: Double | ||
) { | ||
ATTACK(id = 121, unfinished = UnfinishedPotion.GUAM, ingredient = NormalIngredient.EYE_NEWT.id, level = 1, experience = 25.0), |
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.
Can you statically import all of the enumerators in UnfinishedPotion
, NormalIngredient
, and CrushIngredient
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.
How would I do this if NormalIngredient and CrushedIngredient are using the val ingredient: Int?
Or did i just misunderstand what you ment?
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.
you can do:
import UnfinishedPotion.*
and change
- unfinished = UnfinishedPotion.GUAM
+ unfinished = GUAM
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.
Got it!
import java.util.* | ||
|
||
private val GRINDING_ANIM = Animation(364) | ||
val PESTLE_MORTAR = 233 |
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.
These ints can be const
.
val level = mob.herblore.current | ||
|
||
if (level < herb.level) { | ||
player.sendMessage("You need an herblore level of ${herb.level} to clean this herb.") |
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.
Should be a Herblore level
if (player.inventory.removeSlot(slot, 1) > 0) { | ||
player.inventory.add(herb.identified) | ||
player.herblore.experience += herb.experience | ||
player.sendMessage("You identify the herb as a ${Definitions.item(herb.identified)!!.name.toLowerCase()}.") |
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.
Can you add a // TODO handle indefinite article
comment here please
|
||
on { ItemOnItemMessage::class } | ||
. then { | ||
val finished = FinishedPotion[Pair(targetId, id)] ?: return@then |
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.
You need to check which way round the id
and targetId
should go here - it needs to be unfinished
first, ingredient
second, so you should check which is which.
} | ||
|
||
on { ItemOnItemMessage::class } | ||
.where { (id == PESTLE_MORTAR || id == KNIFE) && (targetId == PESTLE_MORTAR || targetId == KNIFE) } |
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.
This check is wrong - will only pass if both id
and targetId
are a knife or a pestle & mortar.
on { ItemOnItemMessage::class } | ||
. where { id == WATER_VIAL || targetId == WATER_VIAL } | ||
. then { | ||
val unfinished = UnfinishedPotion[id] ?: return@then |
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.
Same thing with the on
handler below, you need to make sure what you pass to UnfinishedPotion
is actually the ingredient id (not the vial of water).
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.
That is the way I intially wanted to write the code. I just didn't know how to do it with plugin format you guys provided, "the on/where"-format.
I'm still not sure how to do that logic in apollo with kotlin.
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.
Just something like:
val unfinishedId = if (id == WATER_VIAL) {
targetId
} else {
id
}
val unfinished = UnfinishedPotion[unfinishedId]!!
review :)