@Test
public void startAttackingPet() {
final Player jekyll = PlayerTestHelper.createPlayer("jekyll");
final Player hyde = PlayerTestHelper.createPlayer("hyde");
final Sheep sheep = new Sheep();
zone.add(hyde);
zone.add(sheep);
// attacking wild sheep should be ok
StendhalRPAction.startAttack(hyde, sheep);
assertSame("Attacking a sheep in unprotected area", hyde.getAttackTarget(), sheep);
hyde.stopAttack();
// also if you are the owner
sheep.setOwner(hyde);
StendhalRPAction.startAttack(hyde, sheep);
assertSame("Attacking a sheep in unprotected area", hyde.getAttackTarget(), sheep);
hyde.stopAttack();
// but attacking someone elses pet is a no-no
sheep.setOwner(jekyll);
StendhalRPAction.startAttack(hyde, sheep);
assertNull("Attacking someone else's sheep", hyde.getAttackTarget());
assertEquals("message at attacking someone else's sheep",
"You pity jekyll's sheep too much to kill it.",
hyde.events().get(0).get("text"));
hyde.stopAttack();
hyde.clearEvents();
sheep.setOwner(null);
// Protected. should fail
protectMap();
StendhalRPAction.startAttack(hyde, sheep);
assertNull("Attacking a sheep in protected area ", hyde.getAttackTarget());
assertEquals("message at attacking a sheep in protected area",
"The powerful protective aura in this place prevents you from attacking that sheep.",
getPrivateReply(hyde));
hyde.stopAttack();
hyde.clearEvents();
// the same with an owned sheep
sheep.setOwner(hyde);
StendhalRPAction.startAttack(hyde, sheep);
assertNull("Attacking a sheep in protected area ", hyde.getAttackTarget());
assertEquals("message at attacking a sheep in protected area",
"The powerful protective aura in this place prevents you from attacking hyde's sheep.",
getPrivateReply(hyde));
hyde.clearEvents();
// ...regarless of the owner
sheep.setOwner(jekyll);
StendhalRPAction.startAttack(hyde, sheep);
assertNull("Attacking a sheep in protected area ", hyde.getAttackTarget());
assertEquals("message at attacking a sheep in protected area",
"The powerful protective aura in this place prevents you from attacking jekyll's sheep.",
getPrivateReply(hyde));