Fix nitpicks in Woodcutting plugin

This commit is contained in:
Major
2018-03-28 01:21:12 +01:00
parent 45a0b43eee
commit 173623b76b
3 changed files with 73 additions and 105 deletions
+20 -15
View File
@@ -1,23 +1,28 @@
package org.apollo.game.plugin.skills.woodcutting
import org.apollo.game.model.Animation;
import org.apollo.game.model.Animation
import org.apollo.game.model.entity.Player
import org.apollo.game.plugin.api.woodcutting
//Animation IDs thanks to Deadly A G S at rune-server.ee
enum class Axe(val id: Int, val level: Int, val animation: Animation, val pulses: Int) {
RUNE(1359, 41, Animation(867), 3),
ADAMANT(1357, 31, Animation(869), 4),
MITHRIL(1355, 21, Animation(871), 5),
BLACK(1361, 11, Animation(873), 6),
STEEL(1353, 6, Animation(875), 6),
IRON(1349, 1, Animation(877), 7),
BRONZE(1351, 1, Animation(879), 8);
enum class Axe(val id: Int, val level: Int, animation: Int, val pulses: Int) {
BRONZE(id = 1351, level = 1, animation = 879, pulses = 8),
IRON(id = 1349, level = 1, animation = 877, pulses = 7),
STEEL(id = 1353, level = 6, animation = 875, pulses = 6),
BLACK(id = 1361, level = 11, animation = 873, pulses = 6),
MITHRIL(id = 1355, level = 21, animation = 871, pulses = 5),
ADAMANT(id = 1357, level = 31, animation = 869, pulses = 4),
RUNE(id = 1359, level = 41, animation = 867, pulses = 3);
val animation = Animation(animation)
companion object {
private val AXES = Axe.values()
fun getAxes(): Array<Axe> {
return AXES
private val AXES = Axe.values().sortedByDescending { it.level }
fun bestFor(player: Player): Axe? {
return AXES.asSequence()
.filter { it.level <= player.woodcutting.current }
.filter { player.equipment.contains(it.id) || player.inventory.contains(it.id) }
.firstOrNull()
}
}
}
+34 -61
View File
@@ -1,67 +1,27 @@
package org.apollo.game.plugin.skills.woodcutting
private val NORMAL_STUMP = 1342
private val ACHEY_STUMP = 3371
private val OAK_STUMP = 1342
private val WILLOW_STUMP = 1342
private val TEAK_STUMP = 1342
private val MAPLE_STUMP = 1342
private val MAHOGANY_STUMP = 1342
private val YEW_STUMP = 1342
private val MAGIC_STUMP = 1324
private val NORMAL_OBJECTS = hashSetOf(
1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1285, 1286, 1289, 1290, 1291, 1315,
1316, 1318, 1330, 1331, 1332, 1365, 1383, 1384, 2409, 3033, 3034, 3035, 3036, 3881, 3882,
3883, 5902, 5903, 5904, 10041
)
private val ACHEY_OBJECTS = hashSetOf(
2023
)
private val OAK_OBJECTS = hashSetOf(
1281, 3037
)
private val WILLOW_OBJECTS = hashSetOf(
5551, 5552, 5553
)
private val TEAK_OBJECTS = hashSetOf(
9036
)
private val MAPLE_OBJECTS = hashSetOf(
1307, 4674
)
private val MAHOGANY_OBJECTS = hashSetOf(
9034
)
private val YEW_OBJECTS = hashSetOf(
1309
)
private val MAGIC_OBJECTS = hashSetOf(
1292, 1306
)
/**
* values thanks to: http://oldschoolrunescape.wikia.com/wiki/Woodcutting
/*
* Values thanks to: http://oldschoolrunescape.wikia.com/wiki/Woodcutting
* https://twitter.com/JagexKieren/status/713409506273787904
*/
enum class Tree(val id: Int, val objects: HashSet<Int>, val stump: Int, val level: Int, val exp: Double, val chance: Double) {
NORMAL(1511, NORMAL_OBJECTS, NORMAL_STUMP, 1, 25.0, 100.0),
ACHEY(2862, ACHEY_OBJECTS, ACHEY_STUMP, 1, 25.0, 100.0),
OAK(1521, OAK_OBJECTS, OAK_STUMP, 15, 37.5, 0.125),
WILLOW(1519, WILLOW_OBJECTS, WILLOW_STUMP, 30, 67.5, 0.125),
TEAK(6333, TEAK_OBJECTS, TEAK_STUMP, 35, 85.0, 0.125),
MAPLE(1517, MAPLE_OBJECTS, MAPLE_STUMP, 45, 100.0, 0.125),
MAHOGANY(6332, MAHOGANY_OBJECTS, MAHOGANY_STUMP, 50, 125.0, 0.125),
YEW(1515, YEW_OBJECTS, YEW_STUMP, 60, 175.0, 0.125),
MAGIC(1513, MAGIC_OBJECTS, MAGIC_STUMP, 75, 250.0, 0.125);
enum class Tree(
val objects: Set<Int>,
val id: Int,
val stump: Int,
val level: Int,
val exp: Double,
val chance: Double
) {
NORMAL(NORMAL_OBJECTS, id = 1511, stump = 1342, level = 1, exp = 25.0, chance = 100.0),
ACHEY(ACHEY_OBJECTS, id = 2862, stump = 3371, level = 1, exp = 25.0, chance = 100.0),
OAK(OAK_OBJECTS, id = 1521, stump = 1342, level = 15, exp = 37.5, chance = 12.5),
WILLOW(WILLOW_OBJECTS, id = 1519, stump = 1342, level = 30, exp = 67.5, chance = 12.5),
TEAK(TEAK_OBJECTS, id = 6333, stump = 1342, level = 35, exp = 85.0, chance = 12.5),
MAPLE(MAPLE_OBJECTS, id = 1517, stump = 1342, level = 45, exp = 100.0, chance = 12.5),
MAHOGANY(MAHOGANY_OBJECTS, id = 6332, stump = 1342, level = 50, exp = 125.0, chance = 12.5),
YEW(YEW_OBJECTS, id = 1515, stump = 1342, level = 60, exp = 175.0, chance = 12.5),
MAGIC(MAGIC_OBJECTS, id = 1513, stump = 1324, level = 75, exp = 250.0, chance = 12.5);
companion object {
private val TREES = Tree.values().flatMap { tree -> tree.objects.map { Pair(it, tree) } }.toMap()
@@ -69,4 +29,17 @@ enum class Tree(val id: Int, val objects: HashSet<Int>, val stump: Int, val leve
}
}
private val NORMAL_OBJECTS = hashSetOf(
1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1285, 1286, 1289, 1290, 1291, 1315,
1316, 1318, 1330, 1331, 1332, 1365, 1383, 1384, 2409, 3033, 3034, 3035, 3036, 3881, 3882,
3883, 5902, 5903, 5904, 10041
)
private val ACHEY_OBJECTS = hashSetOf(2023)
private val OAK_OBJECTS = hashSetOf(1281, 3037)
private val WILLOW_OBJECTS = hashSetOf(5551, 5552, 5553)
private val TEAK_OBJECTS = hashSetOf(9036)
private val MAPLE_OBJECTS = hashSetOf(1307, 4674)
private val MAHOGANY_OBJECTS = hashSetOf(9034)
private val YEW_OBJECTS = hashSetOf(1309)
private val MAGIC_OBJECTS = hashSetOf(1292, 1306)
@@ -1,3 +1,4 @@
import org.apollo.game.GameConstants
import org.apollo.game.action.ActionBlock
import org.apollo.game.action.AsyncDistancedAction
@@ -13,17 +14,24 @@ import org.apollo.game.plugin.api.rand
import org.apollo.game.plugin.api.woodcutting
import org.apollo.game.plugin.skills.woodcutting.Axe
import org.apollo.game.plugin.skills.woodcutting.Tree
import java.util.Optional
import java.util.concurrent.TimeUnit
// TODO Accurate chopping rates, e.g. https://twitter.com/JagexKieren/status/713403124464107520
on { ObjectActionMessage::class }
.where { option == 1 }
.then { player ->
Tree.lookup(id)?.let { WoodcuttingAction.start(this, player, it) }
}
class WoodcuttingTarget(private val objectId: Int, val position: Position, val tree: Tree) {
/**
* Get the tree object in the world
*/
fun getObject(world: World): Optional<GameObject> {
fun getObject(world: World): GameObject? {
val region = world.regionRepository.fromPosition(position)
return region.findObject(position, objectId)
return region.findObject(position, objectId).orElse(null)
}
/**
@@ -44,23 +52,12 @@ class WoodcuttingAction(
private const val TREE_SIZE = 2
private const val MINIMUM_RESPAWN_TIME = 30L // In seconds
/**
* Find the highest level axe the player has
*/
private fun axeFor(player: Player): Axe? {
return Axe.getAxes()
.filter { it.level <= player.woodcutting.current }
.filter { player.equipment.contains(it.id) || player.inventory.contains(it.id) }
.sortedByDescending { it.level }
.firstOrNull()
}
/**
* Starts a [WoodcuttingAction] for the specified [Player], terminating the [ObjectActionMessage] that triggered
* it.
*/
fun start(message: ObjectActionMessage, player: Player, wood: Tree) {
val axe = axeFor(player)
val axe = Axe.bestFor(player)
if (axe != null) {
if (player.inventory.freeSlots() == 0) {
player.inventory.forceCapacityExceeded()
@@ -92,33 +89,26 @@ class WoodcuttingAction(
wait(tool.pulses)
//Check that the object exists in the world
// Check that the object exists in the world
val obj = target.getObject(mob.world)
if (!obj.isPresent) {
if (obj == null) {
stop()
}
if (mob.inventory.add(target.tree.id)) {
val logName = Definitions.item(target.tree.id)?.name?.toLowerCase()
val logName = Definitions.item(target.tree.id)!!.name.toLowerCase()
mob.sendMessage("You managed to cut some $logName.")
mob.woodcutting.experience += target.tree.exp
}
if (target.isCutDown()) {
//respawn time: http://runescape.wikia.com/wiki/Trees
// respawn time: http://runescape.wikia.com/wiki/Trees
val respawn = TimeUnit.SECONDS.toMillis(MINIMUM_RESPAWN_TIME + rand(150)) / GameConstants.PULSE_DELAY
mob.world.expireObject(obj.get(), target.tree.stump, respawn.toInt())
mob.world.expireObject(obj!!, target.tree.stump, respawn.toInt())
stop()
}
}
}
}
on { ObjectActionMessage::class }
.where { option == 1 }
.then {
val tree = Tree.lookup(id)
if (tree != null) {
WoodcuttingAction.start(this, it, tree)
}
}
}