Emberveil sourcetests/OwnerSlayerDirectCheck.java
import com.rs2.game.content.emberveil.*;import com.rs2.game.content.skills.slayer.Slayer;import com.rs2.game.npcs.*;import com.rs2.util.NpcSpawn;import com.rs2.world.clip.*;import org.apollo.cache.*;import org.apollo.cache.decoder.*;import com.google.gson.Gson;import java.io.*;import java.nio.file.*;import java.util.*;import com.rs2.net.*;import com.rs2.net.packets.*;import io.netty.buffer.Unpooled;
public final class OwnerSlayerDirectCheck {
static int checks;static void check(boolean b,String text){checks++;if(!b)throw new AssertionError(text);}
static void command(OwnerSlayerLiveCheck.F p,String text){byte[] bytes=(text+"\n").getBytes(java.nio.charset.StandardCharsets.US_ASCII);Packet packet=new Packet(103,Packet.Type.VARIABLE,Unpooled.wrappedBuffer(bytes));PacketHandler.processPacket(p,packet);}
public static void main(String[]args)throws Exception {
NPCDefinition.init();
IndexedFileSystem c=new IndexedFileSystem(Paths.get("data/cache"),true);new ItemDefinitionDecoder(c).run();new ObjectDefinitionDecoder(c).run();RegionFactory.load(c);
NpcSpawn[] spawns=new Gson().fromJson(new FileReader("data/cfg/spawns.json"),NpcSpawn[].class);int i=1;for(NpcSpawn s:spawns){Npc n=new Npc(i,s.getId());n.absX=n.makeX=s.getX();n.absY=n.makeY=s.getY();n.heightLevel=s.getHeight();NpcHandler.npcs[i++]=n;}
int task=args.length>0?Integer.parseInt(args[0]):103,left=args.length>1?Integer.parseInt(args[1]):52;
OwnerSlayerLiveCheck.F p=new OwnerSlayerLiveCheck.F(task,left);int[] d=SlayerTaskTeleport.destination(task);check(d!=null,"assignment has live monster");
p.isBanking=true;p.isShopping=true;p.teleTimer=9;p.isTeleporting=true;p.newLocation=1;p.logoutDelay=System.currentTimeMillis();p.npcIndex=1;p.underAttackBy2=1;
for(String name:new String[]{"slayertask","::slayertask"," SlAyErTaSk ","slayzone"}){command(p,name);check(p.teleportToX==d[0]&&p.teleportToY==d[1],"packet command queues exact destination");check(p.teleTimer==0&&!p.isBanking&&!p.isShopping,"old spell and bank state cleared");p.getNextPlayerMovement();check(p.absX==d[0]&&p.absY==d[1]&&p.heightLevel==d[2],"actual movement reaches assigned monster");}
check(p.taskAmount==left,"assignment preserved");
for(String name:new String[]{"darren","strelly"}){p=new OwnerSlayerLiveCheck.F(task,left);p.playerName=name;command(p,"slayertask");check(p.teleportToX==-1,"other account denied");}
p=new OwnerSlayerLiveCheck.F(task,left);p.playerRights=0;command(p,"slayertask");check(p.teleportToX==-1,"name alone denied");
p=new OwnerSlayerLiveCheck.F(task,left);p.inTrade=true;command(p,"slayertask");check(p.teleportToX==-1,"trade protected");p.inTrade=false;p.inDuel=true;command(p,"slayertask");check(p.teleportToX==-1,"duel protected");p.inDuel=false;p.isDead=true;command(p,"slayertask");check(p.teleportToX==-1,"dead protected");
p=new OwnerSlayerLiveCheck.F(task,0);command(p,"slayertask");check(p.teleportToX==-1,"no assignment protected");
int destinations=0;for(Slayer.Task t:Slayer.Task.values())if(SlayerTaskTeleport.destination(t.getNpcId())!=null)destinations++;check(destinations==50,"all50 assigned monster destinations");
System.out.println("PASS "+checks+" full command packet, repeated direct movement, owner permission and transaction checks; "+destinations+" task destinations; current task="+task+" destination="+d[0]+","+d[1]+","+d[2]);
}
}