*/
@Test
public void testHasValidTarget() {
final StendhalRPZone zone = new StendhalRPZone("hthtest");
final HandToHand hth = new HandToHand();
final Creature creature = new Creature();
assertFalse("is not attacking", hth.hasValidTarget(creature));
final RPEntity victim = new RPEntity() {
@Override
public boolean isInvisibleToCreatures() {
return mockinvisible;
}
@Override
protected void dropItemsOn(final Corpse corpse) {
}
@Override
public void logic() {
}
};
victim.put("id", 1);
creature.setTarget(victim);
mockinvisible = true;
assertTrue(victim.isInvisibleToCreatures());
assertFalse("victim is invisible", hth.hasValidTarget(creature));
mockinvisible = false;
assertFalse(victim.isInvisibleToCreatures());
zone.add(victim);
assertFalse("not in same zone", hth.hasValidTarget(creature));
zone.add(creature);
assertFalse("in same zone, on same spot and dead", hth.hasValidTarget(creature));
creature.setTarget(victim);
victim.setHP(1);
assertTrue("in same zone, on same spot", hth.hasValidTarget(creature));
victim.setPosition(12, 0);
assertTrue("in same zone, not too far away", hth.hasValidTarget(creature));
victim.setPosition(13, 0);
assertFalse("in same zone, too far away", hth.hasValidTarget(creature));
}