Emberveil sourcetests/OwnerHatDamageCheck.java
import com.rs2.game.players.*;import com.rs2.game.items.*;import com.rs2.game.npcs.*;import com.rs2.game.content.combat.melee.*;import org.apollo.cache.*;import org.apollo.cache.decoder.*;import java.nio.file.*;import java.util.*;
/** Isolated equipment and actual NPC hit application; never saves any player. */
public final class OwnerHatDamageCheck {
static int checks;static void check(boolean b,String s){checks++;if(!b)throw new AssertionError(s);}
static class F extends Client {
F(){super(null,1);playerName=playerName2="bonds";playerRights=3;tutorialProgress=36;respawnTimer=-6;isActive=true;absX=3233;absY=3229;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});}
public void flushOutStream(){getOutStream().currentOffset=0;}
}
static int[] hits(F p,int attempts){int max=0,total=0;Npc n=new Npc(1,9);n.defence=0;NpcHandler.npcs[1]=n;for(int i=0;i<attempts;i++){n.HP=n.MaxHP=10000;p.getCombatAssistant().applyNpcMeleeDamage(1,1);check(n.hitDiff<=p.getCombatAssistant().meleeMaxHit(),"damage bounded by calculated maximum");check(n.HP==10000-n.hitDiff,"actual monster health reduced");max=Math.max(max,n.hitDiff);total+=n.hitDiff;}return new int[]{max,total};}
public static void main(String[]args)throws Exception {
new ItemDefinitionDecoder(new IndexedFileSystem(Paths.get("data/cache"),true)).run();ItemDefinitions.load();
F p=new F();p.playerEquipment[p.playerWeapon]=4151;p.playerEquipmentN[p.playerWeapon]=1;p.getItemAssistant().resetBonus();p.getItemAssistant().getBonus();
int baseBonus=p.playerBonus[10],baseMax=p.getCombatAssistant().meleeMaxHit();int[] before=hits(p,1000);
p.playerItems[0]=15000;p.playerItemsN[0]=1;check(p.getItemAssistant().wearItem(14999,0),"real equip succeeds");check(p.playerEquipment[p.playerHat]==14999,"custom hat equipped");check(p.playerBonus[10]==baseBonus+500,"real equip adds500 strength");
int hatMax=p.getCombatAssistant().meleeMaxHit();check(hatMax>baseMax,"maximum melee hit increases");int[] after=hits(p,1000);check(after[0]>baseMax,"real applied hit exceeds previous maximum");check(after[1]>before[1]*2,"aggregate actual damage materially higher");
System.out.println("DAMAGE: 99Strength, whip, no prayers/potions: strength bonus "+baseBonus+" -> "+p.playerBonus[10]+"; melee max "+baseMax+" -> "+hatMax+"; actual NPC hit samples max "+before[0]+" -> "+after[0]);
p.getItemAssistant().removeItem(p.playerHat);check(p.playerEquipment[p.playerHat]==-1,"real unequip succeeds");check(p.getItemAssistant().playerHasItem(14999),"same hat returned to inventory");check(p.playerBonus[10]==baseBonus,"unequip removes500");check(p.getCombatAssistant().meleeMaxHit()==baseMax,"unequip restores normal damage");
p.isBanking=true;p.lastMainFrameInterface=MainFrameIDs.BANK;
int slot=p.getItemAssistant().getItemSlot(14999);check(p.getItemAssistant().bankItem(14999,slot,1),"existing hat deposits");int bankSlot=-1;for(int i=0;i<p.bankItems.length;i++)if(p.bankItems[i]==15000&&p.bankItemsN[i]==1)bankSlot=i;check(bankSlot>=0,"one hat in bank");
p.getItemAssistant().fromBank(14999,bankSlot,1);check(p.getItemAssistant().playerHasItem(14999),"existing hat withdraws");check(p.bankItemsN[bankSlot]==0,"withdraw does not duplicate");
check(!p.getItemAssistant().addItem(14999,1),"second inventory copy refused");
p.playerName="darren";p.playerEquipment[p.playerHat]=14999;p.getItemAssistant().resetBonus();p.getItemAssistant().getBonus();check(p.playerBonus[10]==baseBonus,"other account gets no500");
System.out.println("PASS "+checks+" equipment, damage and owner isolation checks");
}
}