Emberveil source

tests/OwnerSlayerTeleportCheck.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.*;
public final class OwnerSlayerTeleportCheck {
 static int checks;
 static void check(boolean b,String text){checks++;if(!b)throw new AssertionError(text);}
 static class F extends MemberQuestsCheck.Fixture {
  F(){playerName=playerName2="bonds";playerRights=3;slayerTask=1615;taskAmount=20;pos(3233,3229,0);}
 }
 static void command(F p){check(Emberveil.handle(p,"SlAyZoNe",new String[0]),"slayzone command dispatched");}
 public static void main(String[]args)throws Exception {
  IndexedFileSystem c=new IndexedFileSystem(Paths.get("data/cache"),true);new NpcDefinitionDecoder(c).run();new ObjectDefinitionDecoder(c).run();RegionFactory.load(c);
  Arrays.fill(NpcHandler.npcs,null);NpcSpawn[] spawns=new Gson().fromJson(new FileReader("data/cfg/spawns.json"),NpcSpawn[].class);int index=1;
  for(NpcSpawn s:spawns){Npc n=new Npc(index,s.getId());n.absX=n.makeX=s.getX();n.absY=n.makeY=s.getY();n.heightLevel=s.getHeight();NpcHandler.npcs[index++]=n;}
  int found=0;
  for(Slayer.Task task:Slayer.Task.values()){
   int[] d=SlayerTaskTeleport.destination(task.getNpcId());
   if(d==null){System.out.println("NO DESTINATION "+task);continue;}
   check((Region.getClipping(d[0],d[1],d[2])&0x1280100)==0,"clear landing "+task);check(d[2]>=0&&d[2]<=3,"public plane "+task);found++;
  }
  check(found>30,"broad task coverage");
  F p=new F();p.playerName="darren";command(p);check(!p.isTeleporting,"co-owner denied");p.playerName="strelly";command(p);check(!p.isTeleporting,"other named staff denied");p.playerName="bonds";p.playerRights=0;command(p);check(!p.isTeleporting,"owner name alone insufficient");
  p=new F();p.taskAmount=0;command(p);check(!p.isTeleporting,"completed task denied");p.taskAmount=20;p.slayerTask=-1;command(p);check(!p.isTeleporting,"no assignment denied");p.slayerTask=999999;command(p);check(!p.isTeleporting,"missing spawn safely denied");
  p=new F();p.inTrade=true;command(p);check(!p.isTeleporting,"trade denied");p.inTrade=false;p.isBanking=true;command(p);check(!p.isTeleporting,"bank denied");p.isBanking=false;p.npcIndex=1;command(p);check(!p.isTeleporting,"outgoing combat denied");p.npcIndex=0;p.underAttackBy2=1;command(p);check(!p.isTeleporting,"incoming combat denied");p.underAttackBy2=0;p.logoutDelay=System.currentTimeMillis();command(p);check(!p.isTeleporting,"recent combat denied");p.logoutDelay=0;p.teleBlockDelay=System.currentTimeMillis();p.teleBlockLength=60000;command(p);check(!p.isTeleporting,"teleblock preserved");p.teleBlockLength=0;p.pos(3100,3850,0);p.wildLevel=40;command(p);check(!p.isTeleporting,"deep wilderness preserved");
  p=new F();int[] d=SlayerTaskTeleport.destination(p.slayerTask);command(p);check(p.isTeleporting&&p.teleX==d[0]&&p.teleY==d[1]&&p.teleHeight==d[2],"owner reaches assigned spawn");check(p.slayerTask==1615&&p.taskAmount==20,"assignment unchanged");command(p);check(p.teleX==d[0]&&p.teleTimer==10,"repeat does not restart active teleport");
  p=new F();p.slayerTask=103;p.taskAmount=52;p.isTeleporting=true;p.teleTimer=0;command(p);int[] ghost=SlayerTaskTeleport.destination(103);check(p.teleX==ghost[0]&&p.teleY==ghost[1]&&p.isTeleporting,"bonds ghost assignment teleports despite completed teleport flag");
  p.teleTimer=0;p.teleX=p.teleY=0;check(Emberveil.handle(p,"slayertask",new String[0]),"original command retained");check(p.isTeleporting&&p.teleX==ghost[0]&&p.teleY==ghost[1],"repeated task teleport without walking");
  p=new F();p.isTeleporting=false;p.teleTimer=5;command(p);check(!p.isTeleporting,"active timer blocks overlapping teleport even without flag");
  Arrays.fill(NpcHandler.npcs,null);Npc n=new Npc(1,1615);n.makeX=3420;n.makeY=3560;n.spawnedBy=2;NpcHandler.npcs[1]=n;check(SlayerTaskTeleport.destination(1615)==null,"personal spawns excluded");n.spawnedBy=0;n.heightLevel=4;check(SlayerTaskTeleport.destination(1615)==null,"private instance excluded");
  System.out.println("PASS "+checks+" owner Slayer teleport checks; "+found+" task destinations");
 }
}