Unstuck green dragon bots

Converted Edgeville <-> GE Shortcut to use Listener
Made Green Dragon bots use that listener so they don't all get stuck outside the GE tunnel
::botinfo no longer requires moderator privileges
Added option to ForceMovement that lets the entity stay locked
This commit is contained in:
Dan Ginovker 2022-10-10 13:09:54 +00:00 committed by Ryan
parent e0b9c0ab50
commit 924e9bd2a6
5 changed files with 142 additions and 129 deletions

View file

@ -1,110 +0,0 @@
package core.game.interaction.object;
import core.cache.def.impl.SceneryDefinition;
import core.game.node.entity.player.link.diary.DiaryType;
import core.plugin.Initializable;
import core.game.node.entity.skill.Skills;
import core.game.interaction.OptionHandler;
import core.game.node.Node;
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 rs09.game.world.GameWorld;
import core.game.world.map.Location;
import core.game.world.update.flag.context.Animation;
import core.plugin.Plugin;
/**
* Handles the grand exchange shortcut.
* @author Emperor
* @version 1.0
*/
@Initializable
public final class GrandExchangeShortcut extends OptionHandler {
/**
* The climbing down animation.
*/
private static final Animation CLIMB_DOWN = Animation.create(2589);
/**
* The crawling through animation.
*/
private static final Animation CRAWL_THROUGH = Animation.create(2590);
/**
* The climbing up animation.
*/
private static final Animation CLIMB_UP = Animation.create(2591);
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
SceneryDefinition.forId(9311).getHandlers().put("option:climb-into", this);
SceneryDefinition.forId(9312).getHandlers().put("option:climb-into", this);
return null;
}
@Override
public boolean handle(final Player player, Node node, String option) {
if (player.getSkills().getLevel(Skills.AGILITY) < 21) {
player.getDialogueInterpreter().sendDialogue("You need an Agility level of at least 21 to do this.");
return true;
}
player.lock(4);
final Scenery o = (Scenery) node;
if (o.getId() == 9311) {
ForceMovement.run(player, Location.create(3138, 3516, 0), o.getLocation(), CLIMB_DOWN);
GameWorld.getPulser().submit(new Pulse(1, player) {
int count;
@Override
public boolean pulse() {
switch (++count) {
case 2:
player.animate(CRAWL_THROUGH);
player.getProperties().setTeleportLocation(Location.create(3143, 3514, 0));
break;
case 3:
ForceMovement.run(player, Location.create(3143, 3514, 0), Location.create(3144, 3514, 0), CLIMB_UP);
// Use the shortcut under the wall, north-west of the Grand<br><br>Exchange
player.getAchievementDiaryManager().finishTask(player, DiaryType.VARROCK, 1, 8);
return true;
}
return false;
}
});
} else {
ForceMovement.run(player, Location.create(3144, 3514, 0), o.getLocation(), CLIMB_DOWN);
GameWorld.getPulser().submit(new Pulse(1, player) {
int count;
@Override
public boolean pulse() {
switch (++count) {
case 2:
player.animate(CRAWL_THROUGH);
player.getProperties().setTeleportLocation(Location.create(3139, 3516, 0));
break;
case 3:
ForceMovement.run(player, Location.create(3139, 3516, 0), Location.create(3138, 3516, 0), CLIMB_UP);
// Use the shortcut under the wall, north-west of the Grand<br><br>Exchange
player.getAchievementDiaryManager().finishTask(player, DiaryType.VARROCK, 1, 8);
return true;
}
return false;
}
});
}
return true;
}
@Override
public Location getDestination(Node n, Node node) {
if (((Scenery) node).getId() == 9311) {
return Location.create(3138, 3516, 0);
}
return Location.create(3144, 3514, 0);
}
}

View file

@ -0,0 +1,107 @@
package core.game.interaction.`object`
import api.*
import core.game.node.entity.impl.ForceMovement
import core.game.node.entity.impl.ForceMovement.direction
import core.game.node.entity.player.Player
import core.game.node.entity.player.link.diary.DiaryType
import core.game.node.entity.skill.Skills
import core.game.node.scenery.Scenery
import core.game.system.task.Pulse
import core.game.world.map.Location
import core.game.world.update.flag.context.Animation
import core.plugin.Initializable
import rs09.game.interaction.IntType
import rs09.game.interaction.InteractionListener
/**
* Handles the grand exchange shortcut.
* @author Emperor
* @author dginovker
* @version 2.0
*/
@Initializable
class GrandExchangeShortcut : InteractionListener {
companion object {
/**
* The shortcut configs
*/
val SHORTCUTS = mapOf(
9311 to listOf(
Location.create(3138, 3516, 0), // Run to loc
Location.create(3143, 3514, 0), // Crawl through tele loc
Location.create(3144, 3514, 0), // End loc
),
9312 to listOf(
Location.create(3144, 3514, 0), // Run to loc
Location.create(3139, 3516, 0), // Crawl through tele loc
Location.create(3138, 3516, 0), // End loc
)
)
/**
* The climbing down animation.
*/
private val CLIMB_DOWN = Animation.create(2589)
/**
* The crawling through animation.
*/
private val CRAWL_THROUGH = Animation.create(2590)
/**
* The climbing up animation.
*/
private val CLIMB_UP = Animation.create(2591)
}
override fun defineListeners() {
on(SHORTCUTS.keys.toIntArray(), IntType.SCENERY, "climb-into") { player, node ->
if (!hasLevelDyn(player, Skills.AGILITY, 21)) {
sendDialogue(player, "You need an Agility level of at least 21 to do this.")
return@on true
}
lock(player, 4)
val o = node as Scenery
val path = SHORTCUTS[o.id]!!
ForceMovement.run(player, path[0], o.location, ForceMovement.WALK_ANIMATION, CLIMB_DOWN, direction(path[0], o.location), ForceMovement.WALKING_SPEED, ForceMovement.WALKING_SPEED, false);
runCrawlPulse(player, path)
return@on true
}
}
private fun runCrawlPulse(player: Player, path: List<Location>) {
submitIndividualPulse(player, object : Pulse(1, player) {
var count = 0
var reachedStart = false
override fun pulse(): Boolean {
// If the player hasn't reached path[0], don't do anything
if (!reachedStart && player.location != path[0]) {
return false
}
reachedStart = true
when (++count) {
2 -> {
teleport(player, path[1])
visualize(player, CRAWL_THROUGH, -1)
}
3 -> {
ForceMovement.run(
player,
path[1],
path[2],
CLIMB_UP
)
// Use the shortcut under the wall, north-west of the Grand<br><br>Exchange
player.achievementDiaryManager.finishTask(player, DiaryType.VARROCK, 1, 8)
unlock(player)
return true
}
}
return false
}
})
}
}

View file

@ -75,6 +75,11 @@ public class ForceMovement extends Pulse {
*/
private int pathSpeed;
/**
* Whether to unlock the entity after the ForceMovement completes
*/
private boolean unlockAfter;
/**
* Constructs a new {@code ForceMovement} {@code Object}.
* @param e The entity.
@ -83,8 +88,12 @@ public class ForceMovement extends Pulse {
* @param startAnim The start animation.
* @param animation The animation
* @param direction The direction.
* @param commenceSpeed The commencing speed.
* @param pathSpeed The path speed.
* @param unlockAfter Whether to unlock the entity after the ForceMovement completes
*
*/
public ForceMovement(Entity e, Location start, Location destination, Animation startAnim, Animation animation, Direction direction, int commenceSpeed, int pathSpeed) {
public ForceMovement(Entity e, Location start, Location destination, Animation startAnim, Animation animation, Direction direction, int commenceSpeed, int pathSpeed, boolean unlockAfter) {
super(1, e);
this.entity = e;
this.start = start;
@ -94,6 +103,7 @@ public class ForceMovement extends Pulse {
this.direction = direction;
this.commenceSpeed = commenceSpeed;
this.pathSpeed = pathSpeed;
this.unlockAfter = unlockAfter;
}
/**
@ -105,11 +115,11 @@ public class ForceMovement extends Pulse {
* @param speed The path speed.
*/
public ForceMovement(Entity e, Location start, Location end, Animation animation, int speed) {
this(e, start, end, WALK_ANIMATION, animation, direction(start, end), WALKING_SPEED, speed);
this(e, start, end, WALK_ANIMATION, animation, direction(start, end), WALKING_SPEED, speed, false);
}
public ForceMovement(Entity e, Location destination, int startSpeed, int animSpeed){
this(e,e.getLocation(),destination,WALK_ANIMATION,WALK_ANIMATION,direction(e.getLocation(),destination),startSpeed,animSpeed);
this(e,e.getLocation(),destination,WALK_ANIMATION,WALK_ANIMATION,direction(e.getLocation(),destination),startSpeed,animSpeed, false);
}
/**
@ -120,7 +130,7 @@ public class ForceMovement extends Pulse {
* @param animation the animation.
*/
public ForceMovement(Entity e, Location start, Location destination, Animation animation) {
this(e, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED);
this(e, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED, false);
}
/**
@ -130,7 +140,7 @@ public class ForceMovement extends Pulse {
* @param animation the animation.
*/
public ForceMovement(Location start, Location destination, Animation animation) {
this(null, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED);
this(null, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED, false);
}
/**
@ -140,7 +150,7 @@ public class ForceMovement extends Pulse {
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location destination) {
return run(e, e.getLocation(), destination, WALK_ANIMATION, WALK_ANIMATION, direction(e.getLocation(), destination), WALKING_SPEED, WALKING_SPEED);
return run(e, e.getLocation(), destination, WALK_ANIMATION, WALK_ANIMATION, direction(e.getLocation(), destination), WALKING_SPEED, WALKING_SPEED, false);
}
/**
@ -151,7 +161,7 @@ public class ForceMovement extends Pulse {
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location start, Location destination) {
return run(e, start, destination, WALK_ANIMATION, WALK_ANIMATION, direction(e.getLocation(), destination), WALKING_SPEED, WALKING_SPEED);
return run(e, start, destination, WALK_ANIMATION, WALK_ANIMATION, direction(e.getLocation(), destination), WALKING_SPEED, WALKING_SPEED, false);
}
/**
@ -163,7 +173,7 @@ public class ForceMovement extends Pulse {
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location start, Location destination, Animation animation) {
return run(e, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED);
return run(e, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED, false);
}
/**
@ -176,7 +186,7 @@ public class ForceMovement extends Pulse {
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location start, Location destination, Animation animation, int speed) {
return run(e, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, speed);
return run(e, start, destination, WALK_ANIMATION, animation, direction(start, destination), WALKING_SPEED, speed, false);
}
/**
@ -188,7 +198,7 @@ public class ForceMovement extends Pulse {
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location start, Location destination, Animation startAnim, Animation animation) {
return run(e, start, destination, startAnim, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED);
return run(e, start, destination, startAnim, animation, direction(start, destination), WALKING_SPEED, WALKING_SPEED, false);
}
/**
@ -201,7 +211,7 @@ public class ForceMovement extends Pulse {
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location start, Location destination, Animation startAnim, Animation animation, Direction direction) {
return run(e, start, destination, startAnim, animation, direction, WALKING_SPEED, WALKING_SPEED);
return run(e, start, destination, startAnim, animation, direction, WALKING_SPEED, WALKING_SPEED, false);
}
/**
@ -215,7 +225,11 @@ public class ForceMovement extends Pulse {
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location start, Location destination, Animation startAnim, Animation animation, Direction direction, int pathSpeed) {
return run(e, start, destination, startAnim, animation, direction, WALKING_SPEED, pathSpeed);
return run(e, start, destination, startAnim, animation, direction, WALKING_SPEED, pathSpeed, false);
}
public static ForceMovement run(Entity e, Location start, Location destination, Animation startAnim, Animation animation, Direction direction, int commenceSpeed, int pathSpeed) {
return run(e, start, destination, startAnim, animation, direction, commenceSpeed, pathSpeed, false);
}
/**
@ -227,14 +241,14 @@ public class ForceMovement extends Pulse {
* @param direction The direction.
* @return The created ForceMovement object.
*/
public static ForceMovement run(Entity e, Location start, Location destination, Animation startAnim, Animation animation, Direction direction, int commenceSpeed, int pathSpeed) {
public static ForceMovement run(Entity e, Location start, Location destination, Animation startAnim, Animation animation, Direction direction, int commenceSpeed, int pathSpeed, boolean unlockAfter) {
if (startAnim != null) {
startAnim.setPriority(Animator.Priority.VERY_HIGH);
}
if (animation != null) {
animation.setPriority(Animator.Priority.VERY_HIGH);
}
ForceMovement fm = new ForceMovement(e, start, destination, startAnim, animation, direction, commenceSpeed, pathSpeed);
ForceMovement fm = new ForceMovement(e, start, destination, startAnim, animation, direction, commenceSpeed, pathSpeed, unlockAfter);
fm.start();
e.lock();
GameWorld.getPulser().submit(fm);
@ -242,7 +256,7 @@ public class ForceMovement extends Pulse {
}
public static ForceMovement run(Entity e, Location destination, int commenceSpeed, int pathSpeed){
return run(e,e.getLocation(),destination,WALK_ANIMATION,WALK_ANIMATION,direction(e.getLocation(),destination),commenceSpeed,pathSpeed);
return run(e,e.getLocation(),destination,WALK_ANIMATION,WALK_ANIMATION,direction(e.getLocation(),destination),commenceSpeed,pathSpeed, false);
}
/**
@ -333,7 +347,7 @@ public class ForceMovement extends Pulse {
if (endAnimation != null) {
entity.animate(endAnimation);
}
entity.unlock();
if (unlockAfter) entity.unlock();
}
/**

View file

@ -20,6 +20,8 @@ import core.tools.RandomFunction
import org.rs09.consts.Items
import rs09.game.ai.AIRepository
import rs09.game.ai.pvmbots.CombatBotAssembler
import rs09.game.interaction.IntType
import rs09.game.interaction.InteractionListeners
import rs09.game.node.entity.combat.CombatSwingHandler
import rs09.game.node.entity.combat.handlers.MagicSwingHandler
import rs09.game.node.entity.combat.handlers.MeleeSwingHandler
@ -173,7 +175,7 @@ class GreenDragonKiller(val style: CombatStyle, area: ZoneBorders? = null) : Scr
else {
val shortcut = scriptAPI.getNearestNode("Underwall Tunnel",true)
shortcut ?: return
shortcut.interaction.handle(bot,shortcut.interaction[0])
InteractionListeners.run(shortcut.id, IntType.SCENERY, "climb-into", bot, shortcut)
}
} else {
if (!edgevilleLine.insideBorder(bot) && bot.location.y < 3520) {
@ -197,7 +199,7 @@ class GreenDragonKiller(val style: CombatStyle, area: ZoneBorders? = null) : Scr
if(bot.location == Location.create(3136, 3517, 0)){
val shortcut = scriptAPI.getNearestNode("Underwall Tunnel",true)
shortcut ?: return
shortcut.interaction.handle(bot,shortcut.interaction[0])
InteractionListeners.run(shortcut.id, IntType.SCENERY, "climb-into", bot, shortcut)
} else {
scriptAPI.walkTo(Location.create(3136, 3517, 0))
}

View file

@ -197,7 +197,7 @@ class MiscCommandSet : CommandSet(Privilege.ADMIN){
/**
* Lists information about a bot
*/
define("botinfo", Privilege.MODERATOR, "::botinfo <lt>botname<gt>", "Prints debug information about a bot"){ player, args ->
define("botinfo", Privilege.STANDARD, "::botinfo <lt>botname<gt>", "Prints debug information about a bot"){ player, args ->
val scriptInstances = AIRepository.PulseRepository
// Find the bot with the given name (non-case sensitive)