Rewrote stiles
Added a new ContentAPI function, animationCycles, that returns the exact number of cycles an animation lasts for (useful for forced movement) Added a new function to Vector objects that allows convertion into Direction objects (useful for transforming locations)
This commit is contained in:
@@ -1,108 +0,0 @@
|
||||
package content.global.skill.agility.shortcuts;
|
||||
|
||||
import core.game.activity.ActivityManager;
|
||||
import core.game.node.entity.impl.PulseType;
|
||||
import core.plugin.Initializable;
|
||||
import content.global.skill.agility.AgilityShortcut;
|
||||
import core.game.interaction.MovementPulse;
|
||||
import core.game.node.entity.impl.ForceMovement;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.scenery.Scenery;
|
||||
import core.game.system.task.Pulse;
|
||||
import core.game.world.GameWorld;
|
||||
import core.game.world.map.Direction;
|
||||
import core.game.world.map.Location;
|
||||
import core.game.world.update.flag.context.Animation;
|
||||
|
||||
/**
|
||||
* Handles a stile shortcut.
|
||||
* @author Vexia
|
||||
*/
|
||||
@Initializable
|
||||
public class StileShortcut extends AgilityShortcut {
|
||||
|
||||
/**
|
||||
* Constructs a new {@Code StileShortcut} {@Code Object}
|
||||
*/
|
||||
public StileShortcut() {
|
||||
super(new int[] { 993, 3730, 7527, 12982, 19222, 22302, 29460, 33842, 34776, 39508, 39509, 39510 }, 1, 0.0, false, 0.0, new String[] { "climb-over" });
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Player player, final Scenery object, String option, boolean failed) {
|
||||
player.getWalkingQueue().reset();
|
||||
Location loc = getLocation(player, object, true);
|
||||
player.getWalkingQueue().addPath(loc.getX(), loc.getY());
|
||||
player.getPulseManager().run(new MovementPulse(player, loc) {
|
||||
@Override
|
||||
public boolean pulse() {
|
||||
climb(player, object);
|
||||
return true;
|
||||
}
|
||||
}, PulseType.STANDARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to climb the stile.
|
||||
* @param player the player.
|
||||
* @param object the object.
|
||||
*/
|
||||
public static void climb(final Player player, final Scenery object) {
|
||||
player.lock(1);
|
||||
int delay = 0;
|
||||
GameWorld.getPulser().submit(new Pulse(delay, player) {
|
||||
@Override
|
||||
public boolean pulse() {
|
||||
ForceMovement movement = new ForceMovement(player, getLocation(player, object, true), getLocation(player, object, false), Animation.create(839)) {
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
if (object.getId() == 19222) {// falconry.
|
||||
handleFalconry(player, object);
|
||||
}
|
||||
}
|
||||
};
|
||||
movement.run(player, 5);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to get the end location.
|
||||
* @param player the player.
|
||||
* @param object the object.
|
||||
* @param start if getting the start loc.
|
||||
* @return the location.
|
||||
*/
|
||||
public static Location getLocation(final Player player, final Scenery object, boolean start) {
|
||||
if ((object.getDirection() == Direction.NORTH || object.getDirection() == Direction.SOUTH)) {
|
||||
if (player.getLocation().getY() <= object.getLocation().getY()) {
|
||||
return start ? object.getLocation() : object.getLocation().transform(0, 1, 0);
|
||||
} else {
|
||||
return start ? object.getLocation().transform(0, 1, 0) : object.getLocation();
|
||||
}
|
||||
} else {
|
||||
if (player.getLocation().getX() <= object.getLocation().getX()) {
|
||||
return start ? object.getLocation() : object.getLocation().transform(1, 0, 0);
|
||||
} else {
|
||||
return start ? object.getLocation().transform(1, 0, 0) : object.getLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to handle the falconry stile.
|
||||
* @param player the player.
|
||||
* @param object the object.
|
||||
*/
|
||||
private static void handleFalconry(final Player player, Scenery object) {
|
||||
if (player.getLocation().equals(Location.create(2371, 3621, 0))) {
|
||||
ActivityManager.start(player, "falconry", false);
|
||||
} else {
|
||||
ActivityManager.getActivity("falconry").leave(player, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package content.global.skill.agility.shortcuts
|
||||
|
||||
import core.api.*
|
||||
import core.api.utils.Vector
|
||||
import core.game.activity.ActivityManager
|
||||
import core.game.interaction.IntType
|
||||
import core.game.interaction.InteractionListener
|
||||
import core.game.interaction.QueueStrength
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.world.map.Direction
|
||||
import core.game.world.map.Location
|
||||
|
||||
class StileShortcut : InteractionListener {
|
||||
val ids = intArrayOf(993, 3730, 7527, 12982, 19222, 22302, 29460, 33842, 34776, 39508, 39509, 39510)
|
||||
val FALCONRY_STILE = 19222
|
||||
override fun defineListeners() {
|
||||
on (ids, IntType.SCENERY, "climb-over") {p, n ->
|
||||
val direction = Vector.betweenLocs(p.location, n.location).toDirection()
|
||||
val startLoc = p.location.transform(direction, 1)
|
||||
val endLoc = p.location.transform(direction, 2)
|
||||
|
||||
p.walkingQueue.reset()
|
||||
p.walkingQueue.addPath(startLoc.x, startLoc.y)
|
||||
forceMove(p, startLoc, endLoc, 0, animationCycles(839), direction, 839)
|
||||
|
||||
queueScript(p, 5, QueueStrength.SOFT) {_ ->
|
||||
val end = endLoc.transform(direction, 1)
|
||||
p.walkingQueue.reset()
|
||||
p.walkingQueue.addPath(end.x, end.y)
|
||||
|
||||
if (n.id == FALCONRY_STILE)
|
||||
handleFalconry(p, endLoc)
|
||||
return@queueScript stopExecuting(p)
|
||||
}
|
||||
return@on true
|
||||
}
|
||||
|
||||
setDest(IntType.SCENERY, ids, "climb-over") {e, n ->
|
||||
return@setDest getInteractLocation(e.location, n.location, getOrientation(n.direction))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
fun getInteractLocation (pLoc: Location, sLoc: Location, orientation: Orientation) : Location {
|
||||
when (orientation) {
|
||||
Orientation.Horizontal -> {
|
||||
if (pLoc.x <= sLoc.x) return sLoc.transform(-1, 0, 0)
|
||||
else return sLoc.transform(2, 0, 0)
|
||||
}
|
||||
Orientation.Vertical -> {
|
||||
if (pLoc.y <= sLoc.y) return sLoc.transform(0, -1, 0)
|
||||
else return sLoc.transform(0, 2, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getOrientation (rotation: Direction) : Orientation {
|
||||
when (rotation) {
|
||||
Direction.EAST, Direction.WEST -> return Orientation.Horizontal
|
||||
else -> return Orientation.Vertical
|
||||
}
|
||||
}
|
||||
|
||||
fun handleFalconry (p: Player, endLoc: Location) {
|
||||
if (endLoc.y == 3619)
|
||||
ActivityManager.start(p, "falconry", false)
|
||||
else
|
||||
ActivityManager.getActivity("falconry").leave(p, false)
|
||||
}
|
||||
}
|
||||
|
||||
enum class Orientation {
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user