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

Port Herblore plugin to Kotlin #396

Merged
merged 1 commit into from Apr 8, 2018
Merged

Port Herblore plugin to Kotlin #396

merged 1 commit into from Apr 8, 2018

Conversation

ghost
Copy link

@ghost ghost commented Apr 6, 2018

review :)

@ghost ghost closed this Apr 6, 2018
@ghost ghost deleted the herblore branch April 6, 2018 15:25
@ghost ghost restored the herblore branch April 6, 2018 15:31
@garyttierney garyttierney reopened this Apr 6, 2018
@garyttierney garyttierney changed the base branch from master to kotlin-experiments April 6, 2018 15:32
@Major- Major- changed the title Herblore Port Herblore plugin to Kotlin Apr 6, 2018
@garyttierney garyttierney added plugin ruby-to-kotlin Part of the port from ruby to kotlin labels Apr 6, 2018
Copy link
Contributor

@garyttierney garyttierney left a 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) {
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Author

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!

Copy link
Member

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

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)

Copy link
Author

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,
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 camelCase


on { ItemOnItemMessage::class }
.where { id == PESTLE_MORTAR || id == KNIFE }
.where { targetId == PESTLE_MORTAR || targetId == KNIFE }
Copy link
Contributor

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?

Copy link
Member

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

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
Copy link
Contributor

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

@garyttierney
Copy link
Contributor

cc @Major- we should be distributing code style settings at this point.

@garyttierney
Copy link
Contributor

@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.

@tlf30
Copy link
Contributor

tlf30 commented Apr 6, 2018

Looking good, thank you for the contribution!

import org.apollo.game.message.impl.ItemOnItemMessage

on { ItemOptionMessage::class }
.where { option == 1 }
Copy link
Contributor

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).

Copy link
Contributor

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 }
Copy link
Contributor

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

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"
Copy link
Contributor

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

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.")
Copy link
Member

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()}.")
Copy link
Member

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),
Copy link
Member

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

Copy link
Author

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?

Copy link
Contributor

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

Copy link
Author

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
Copy link
Member

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.")
Copy link
Member

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()}.")
Copy link
Member

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
Copy link
Member

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) }
Copy link
Member

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
Copy link
Member

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).

Copy link
Author

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.

Copy link
Member

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]!!

@Major- Major- merged commit a528379 into apollo-rsps:kotlin-experiments Apr 8, 2018
Major- added a commit that referenced this pull request Apr 8, 2018
@ghost ghost deleted the herblore branch May 4, 2018 13:15
@ghost ghost restored the herblore branch May 4, 2018 13:15
@ghost ghost deleted the herblore branch May 4, 2018 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin ruby-to-kotlin Part of the port from ruby to kotlin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants