Minor correction to withinDistance to check for Z axis
Tar Barrel Handler added with REAL mechanics
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
package core.game.interaction.`object`
|
||||||
|
|
||||||
|
import core.cache.def.impl.ObjectDefinition
|
||||||
|
import core.game.interaction.OptionHandler
|
||||||
|
import core.game.node.Node
|
||||||
|
import core.game.node.`object`.ObjectBuilder
|
||||||
|
import core.game.node.entity.player.Player
|
||||||
|
import core.game.node.item.Item
|
||||||
|
import core.plugin.Initializable
|
||||||
|
import core.plugin.Plugin
|
||||||
|
import core.tools.Items
|
||||||
|
import core.tools.RandomFunction
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Woah, with love
|
||||||
|
* Item(s):
|
||||||
|
* Swamp tar - ID: 1939
|
||||||
|
* Object(s):
|
||||||
|
* Tar barrel (full) - ID: 16860 | Tar barrel (empty) - ID: 16688
|
||||||
|
* Option(s):
|
||||||
|
* "Take-from"
|
||||||
|
*/
|
||||||
|
@Initializable
|
||||||
|
class TarBarrelHandler : OptionHandler() {
|
||||||
|
|
||||||
|
val FULL_TAR_BARREL_16860 = 16860
|
||||||
|
val EMPTY_TAR_BARREL_16688 = 16688
|
||||||
|
val EMPTY_BARREL_STRING = "The barrel became empty!"
|
||||||
|
|
||||||
|
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||||
|
ObjectDefinition.forId(FULL_TAR_BARREL_16860).handlers["option:take-from"] = this
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handle(player: Player?, node: Node?, option: String?): Boolean {
|
||||||
|
player ?: return false
|
||||||
|
node ?: return false
|
||||||
|
|
||||||
|
val incrementAmount = RandomFunction.random(83, 1000)
|
||||||
|
|
||||||
|
when (option) {
|
||||||
|
"take-from" -> {
|
||||||
|
if (player.inventory.isFull) {
|
||||||
|
player.sendMessage("Not enough space in your inventory!")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.asObject().charge >= 0) {
|
||||||
|
node.asObject().charge = node.asObject().charge - incrementAmount
|
||||||
|
player.inventory.add(Item(Items.SWAMP_TAR_1939))
|
||||||
|
|
||||||
|
if (node.asObject().charge <= 0) {
|
||||||
|
player.sendMessage(EMPTY_BARREL_STRING)
|
||||||
|
ObjectBuilder.replace(node.asObject(), node.asObject().transform(EMPTY_TAR_BARREL_16688),38)
|
||||||
|
node.asObject().charge = 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,8 +65,6 @@ public final class Location extends Node {
|
|||||||
this(x + RandomFunction.getRandom(randomizer), y + RandomFunction.getRandom(randomizer), z);
|
this(x + RandomFunction.getRandom(randomizer), y + RandomFunction.getRandom(randomizer), z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Location.
|
* Construct a new Location.
|
||||||
* @param x The x-coordinate.
|
* @param x The x-coordinate.
|
||||||
@@ -219,6 +217,10 @@ public final class Location extends Node {
|
|||||||
* @return If you're within the other distance.
|
* @return If you're within the other distance.
|
||||||
*/
|
*/
|
||||||
public boolean withinDistance(Location other, int dist) {
|
public boolean withinDistance(Location other, int dist) {
|
||||||
|
if (other.z != z) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int a = (other.x - x);
|
int a = (other.x - x);
|
||||||
int b = (other.y - y);
|
int b = (other.y - y);
|
||||||
double product = Math.sqrt((a*a) + (b*b));
|
double product = Math.sqrt((a*a) + (b*b));
|
||||||
|
|||||||
Reference in New Issue
Block a user