Emberveil sourcetests/AgilityCheck.java
import com.rs2.Constants;
import com.rs2.event.CycleEventHandler;
import com.rs2.game.players.*;
import com.rs2.game.content.skills.agility.*;
import com.rs2.game.items.ItemDefinitions;
import org.apollo.cache.IndexedFileSystem;
import org.apollo.cache.decoder.ItemDefinitionDecoder;
import java.nio.file.Paths;
import java.util.*;
/** Course handlers, movement queues and scheduled events using disposable players. */
public final class AgilityCheck {
static int checks,failures;
static class Runner extends Client {
Runner(int id){super(null,id);playerName="agilityqa"+id;tutorialProgress=36;isActive=true;
Arrays.fill(playerEquipment,-1);Arrays.fill(playerLevel,99);Arrays.fill(playerXP,13034431);
getOutStream().packetEncryption=new org.apollo.util.security.IsaacRandom(new int[]{1,2,3,4});}
@Override public void flushOutStream(){getOutStream().currentOffset=0;}
}
static void check(boolean value,String label){checks++;if(!value){failures++;System.out.println("FAIL: "+label);}}
static void place(Runner p,int x,int y,int h){
p.absX=x;p.absY=y;p.heightLevel=h;p.mapRegionX=(x>>3)-6;p.mapRegionY=(y>>3)-6;
p.currentX=x-p.mapRegionX*8;p.currentY=y-p.mapRegionY*8;p.teleportToX=p.teleportToY=-1;
p.newWalkCmdSteps=0;p.resetWalkingQueue();p.getPlayerAction().setAction(false);p.getPlayerAction().canWalk(true);
}
static void tick(Runner p){p.postProcessing();p.getNextPlayerMovement();p.preProcessing();p.getAgility().agilityProcess();CycleEventHandler.getSingleton().process();}
static boolean click(Runner p,String course,int id){
switch(course){case "Gnome":return p.getGnomeStrongHold().gnomeCourse(id);case "Barbarian":return p.getBarbarianAgility().barbarianCourse(id);
case "Wilderness":return p.getWildernessAgility().wildernessCourse(id);case "ApeAtoll":return p.getApeAtollAgility().apeAtollCourse(id);
case "Werewolf":return p.getWerewolfAgility().werewolfCourse(id);case "Pyramid":return p.getPyramidAgility().pyramidCourse(id);}
return false;
}
static void obstacle(Runner p,String course,int id,int x,int y,int h,int endX,int endY,int endH){
place(p,x,y,h);int xp=p.playerXP[16];
check(click(p,course,id),course+" recognizes "+id);
for(int i=0;i<65;i++)tick(p);
check(p.absX==endX&&p.absY==endY&&p.heightLevel==endH,course+" obstacle "+id+" destination: "+p.absX+","+p.absY+","+p.heightLevel);
check(!p.getPlayerAction().inAction&&p.getPlayerAction().canWalk,course+" obstacle "+id+" releases movement");
check(p.playerXP[16]>=xp,course+" obstacle "+id+" never removes XP");
CycleEventHandler.getSingleton().stopEvents(p);
}
public static void main(String[] args)throws Exception {
Constants.XP_RATE=4;
new ItemDefinitionDecoder(new IndexedFileSystem(Paths.get("data/cache"),true)).run();ItemDefinitions.load();
Runner p=new Runner(1);
for(int id:new int[]{2295,2285,2313,2312,2314,2286,154,4058,2282,2294,2284,2302,1948,2288,2283,2311,2297,2328,5138,5133,5134,5135,5152,5136,5141,12568,12570,12573,12576,12578,12618})
check(p.getAgility().getXp(id)>=0,"nonnegative obstacle XP "+id);
obstacle(p,"Gnome",2295,2474,3436,0,2474,3429,0);
obstacle(p,"Gnome",2285,2471,3426,0,2471,3424,1);
obstacle(p,"Gnome",2313,2473,3423,1,2473,3420,2);
obstacle(p,"Gnome",2312,2477,3420,2,2483,3420,2);
obstacle(p,"Gnome",2314,2485,3419,2,2485,3419,0);
obstacle(p,"Gnome",2286,2485,3425,0,2485,3427,0);
obstacle(p,"Gnome",154,2484,3430,0,2484,3437,0);
obstacle(p,"Gnome",4058,2487,3430,0,2487,3437,0);
Runner other=new Runner(2);place(other,2485,3425,0);click(other,"Gnome",2286);for(int i=0;i<5;i++)tick(other);
check(other.absY==3427,"Gnome net cooldown is per player");
obstacle(p,"Barbarian",2282,2551,3554,0,2551,3549,0);
obstacle(p,"Barbarian",2294,2551,3546,0,2541,3546,0);
obstacle(p,"Barbarian",2284,2539,3546,0,2538,3546,1);
obstacle(p,"Barbarian",2302,2536,3547,1,2532,3547,1);
obstacle(p,"Barbarian",3205,2532,3546,1,2532,3546,0);
obstacle(p,"Barbarian",1948,2541,3553,0,2543,3553,0);
obstacle(p,"Wilderness",2288,3004,3937,0,3004,3950,0);
obstacle(p,"Wilderness",2283,3005,3953,0,3005,3958,0);
obstacle(p,"Wilderness",2311,3002,3960,0,2996,3960,0);
obstacle(p,"Wilderness",2297,3002,3945,0,2994,3945,0);
obstacle(p,"Wilderness",2328,2993,3937,0,2993,3933,0);
p.npcId2=1480;
int apeStartXp=p.playerXP[16];
obstacle(p,"ApeAtoll",12568,2755,2742,0,2753,2742,0);
obstacle(p,"ApeAtoll",12570,2753,2742,0,2753,2742,2);
obstacle(p,"ApeAtoll",12573,2752,2741,2,2747,2741,0);
obstacle(p,"ApeAtoll",12576,2747,2741,0,2742,2741,0);
obstacle(p,"ApeAtoll",12578,2751,2731,0,2756,2731,0);
obstacle(p,"ApeAtoll",12618,2756,2731,0,2755,2742,0);
check(p.playerXP[16]-apeStartXp==580*4,"Ape Atoll complete lap awards 580 base XP at 4x");
obstacle(p,"Werewolf",5138,3538,9873,0,3538,9875,0);
obstacle(p,"Werewolf",5133,3539,9892,0,3539,9894,0);
obstacle(p,"Werewolf",5134,3539,9895,0,3539,9897,0);
obstacle(p,"Werewolf",5135,3539,9898,0,3539,9900,0);
obstacle(p,"Werewolf",5152,3538,9904,0,3538,9910,0);
obstacle(p,"Werewolf",5136,3533,9910,0,3530,9910,0);
obstacle(p,"Werewolf",5141,3530,9910,0,3528,9871,0);
obstacle(p,"Pyramid",10857,3357,2832,0,3357,2835,1);
obstacle(p,"Pyramid",10865,3354,2848,1,3354,2850,1);
obstacle(p,"Pyramid",10857,3356,2832,1,3356,2835,2);
obstacle(p,"Pyramid",10857,3359,2834,2,3359,2837,3);
obstacle(p,"Pyramid",10857,3361,2836,3,3364,2830,0);
obstacle(p,"Pyramid",10852,3343,2830,0,3349,2830,0);
obstacle(p,"Pyramid",10852,3349,2830,0,3343,2830,0);
obstacle(p,"Pyramid",10868,3375,2845,1,3375,2839,1);
obstacle(p,"Pyramid",10868,3370,2835,1,3364,2835,1);
obstacle(p,"Pyramid",10860,3364,2832,1,3359,2832,1);
obstacle(p,"Pyramid",10886,3372,2841,2,3372,2836,2);
obstacle(p,"Pyramid",10888,3359,2842,3,3359,2847,3);
obstacle(p,"Pyramid",10884,3363,2851,1,3368,2851,1);
obstacle(p,"Pyramid",10882,3357,2836,2,3357,2841,2);
obstacle(p,"Pyramid",10861,3366,2834,2,3363,2834,2);
obstacle(p,"Pyramid",10859,3370,2843,3,3370,2840,3);
for(String course:new String[]{"Barbarian","Wilderness","ApeAtoll","Werewolf","Pyramid"}) {
int id=course.equals("Barbarian")?2282:course.equals("Wilderness")?2288:course.equals("ApeAtoll")?12568:course.equals("Werewolf")?5138:10857;
int x=course.equals("Barbarian")?2551:course.equals("Wilderness")?3004:course.equals("ApeAtoll")?2755:course.equals("Werewolf")?3538:3357;
int y=course.equals("Barbarian")?3554:course.equals("Wilderness")?3937:course.equals("ApeAtoll")?2742:course.equals("Werewolf")?9873:2832;
place(p,x,y,0);p.playerLevel[16]=1;int xp=p.playerXP[16];click(p,course,id);
check(p.playerXP[16]==xp && !p.getPlayerAction().inAction,course+" enforces entry level");p.playerLevel[16]=99;
}
place(p,2474,3436,0);p.isRunning2=false;click(p,"Gnome",2295);for(int i=0;i<10;i++)tick(p);
check(!p.isRunning2,"Agility preserves walking preference");
place(p,2474,3436,0);p.isRunning2=true;click(p,"Gnome",2295);for(int i=0;i<10;i++)tick(p);
check(p.isRunning2,"Agility restores running preference");
place(p,2474,3436,0);click(p,"Gnome",2295);p.disconnected=true;for(int i=0;i<10;i++)tick(p);p.disconnected=false;
check(!p.getPlayerAction().inAction && p.getPlayerAction().canWalk,"Disconnected traversal releases its lock");
place(p,0,0,0);int before=p.playerXP[16];click(p,"Gnome",2295);
check(p.playerXP[16]==before,"No Gnome XP for invalid starting position");
System.out.println("Agility checks="+checks+" failures="+failures);
System.exit(failures==0?0:1);
}
}