affectedPlayer.clearDuelOptions();
affectedPlayer.resetAllExceptDueling();
player.getActionSender().sendDuelWindowOpen();
affectedPlayer.getActionSender().sendDuelWindowOpen();
world.addEntryToSnapshots(new Activity(player.getUsername(),
player.getUsername() + " sent duel request "
+ affectedPlayer.getUsername() + " at: "
+ player.getX() + "/" + player.getY() + " | "
+ affectedPlayer.getX() + "/"
+ affectedPlayer.getY()));
}
break;
case 252: // Duel accepted
affectedPlayer = player.getWishToDuel();
if (affectedPlayer == null || busy(affectedPlayer)
|| !player.isDueling() || !affectedPlayer.isDueling()) { // This
// shouldn't
// happen
player.setSuspiciousPlayer(true);
unsetOptions(player);
unsetOptions(affectedPlayer);
return;
}
player.setDuelOfferAccepted(true);
player.getActionSender().sendDuelAcceptUpdate();
affectedPlayer.getActionSender().sendDuelAcceptUpdate();
if (affectedPlayer.isDuelOfferAccepted()) {
player.getActionSender().sendDuelAccept();
affectedPlayer.getActionSender().sendDuelAccept();
}
world.addEntryToSnapshots(new Activity(player.getUsername(), player
.getUsername()
+ " accepted duel request "
+ affectedPlayer.getUsername()
+ " at: "
+ player.getX()
+ "/"
+ player.getY()
+ " | "
+ affectedPlayer.getX()
+ "/"
+ affectedPlayer.getY()));
break;
case 87: // Confirm accepted
affectedPlayer = player.getWishToDuel();
if (affectedPlayer == null || busy(affectedPlayer)
|| !player.isDueling() || !affectedPlayer.isDueling()
|| !player.isDuelOfferAccepted()
|| !affectedPlayer.isDuelOfferAccepted()) { // This
// shouldn't
// happen
player.setSuspiciousPlayer(true);
unsetOptions(player);
unsetOptions(affectedPlayer);
return;
}
player.setDuelConfirmAccepted(true);
if (affectedPlayer.isDuelConfirmAccepted()) {
world.addEntryToSnapshots(new Activity(player.getUsername(),
player.getUsername() + " started duel "
+ affectedPlayer.getUsername() + " at: "
+ player.getX() + "/" + player.getY() + " | "
+ affectedPlayer.getX() + "/"
+ affectedPlayer.getY()));
player.getActionSender().sendDuelWindowClose();
player.getActionSender().sendMessage("Commencing Duel");
affectedPlayer.getActionSender().sendDuelWindowClose();
affectedPlayer.getActionSender().sendMessage("Commencing Duel");
player.resetAllExceptDueling();
player.setBusy(true);
player.setStatus(Action.DUELING_PLAYER);
affectedPlayer.resetAllExceptDueling();
affectedPlayer.setBusy(true);
affectedPlayer.setStatus(Action.DUELING_PLAYER);
if (player.getDuelSetting(3)) {
int slot = 0;
for (InvItem item : player.getInventory().getItems()) {
if (item.wielded) {
player.getInventory().setWield(slot, false);
player.updateWornItems(
ItemAttributes.getWieldable(item.id)
.getWieldPos(),
player.getPlayerAppearance().getSprite(
ItemAttributes
.getWieldable(item.id)
.getWieldPos()));
}
slot++;
}
player.getActionSender().sendSound("click");
player.getActionSender().sendInventory();
player.getActionSender().sendEquipmentStats();
slot = 0;
for (InvItem item : affectedPlayer.getInventory()
.getItems()) {
if (item.wielded) {
affectedPlayer.getInventory().setWield(slot, false);
affectedPlayer.updateWornItems(
ItemAttributes.getWieldable(item.id)
.getWieldPos(),
affectedPlayer.getPlayerAppearance()
.getSprite(
ItemAttributes
.getWieldable(
item.id)
.getWieldPos()));
}
slot++;
}
affectedPlayer.getActionSender().sendSound("click");
affectedPlayer.getActionSender().sendInventory();
affectedPlayer.getActionSender().sendEquipmentStats();
}
if (player.getDuelSetting(2)) {
for (int x = 0; x < 14; x++) {
if (player.isPrayerActivated(x)) {
player.removePrayerDrain(x);
player.setPrayer(x, false);
}
if (affectedPlayer.isPrayerActivated(x)) {
affectedPlayer.removePrayerDrain(x);
affectedPlayer.setPrayer(x, false);
}
}
player.getActionSender().sendPrayers();
affectedPlayer.getActionSender().sendPrayers();
}
player.setFollowing(affectedPlayer);
WalkToMobEvent walking = new WalkToMobEvent(player,
affectedPlayer, 1) {
public void arrived() {
Instance.getDelayedEventHandler().add(
new SingleEvent(owner, 300) {
public void action() {
Player affectedPlayer = (Player) affectedMob;
owner.resetPath();
if (!owner.nextTo(affectedPlayer)) {
unsetOptions(owner);
unsetOptions(affectedPlayer);
return;
}
affectedPlayer.resetPath();
owner.resetAllExceptDueling();
affectedPlayer.resetAllExceptDueling();
owner.setLocation(
affectedPlayer.getLocation(),
true);
for (Player p : owner.getViewArea()
.getPlayersInView()) {
p.removeWatchedPlayer(owner);
}
owner.setSprite(9);
owner.setOpponent(affectedMob);
owner.setCombatTimer();
affectedPlayer.setSprite(8);
affectedPlayer.setOpponent(owner);
affectedPlayer.setCombatTimer();
Player attacker, opponent;
if (owner.getCombatLevel() > affectedPlayer
.getCombatLevel()) {
attacker = affectedPlayer;
opponent = owner;
} else if (affectedPlayer
.getCombatLevel() > owner
.getCombatLevel()) {
attacker = owner;
opponent = affectedPlayer;
} else if (DataConversions.random(0, 1) == 1) {
attacker = owner;
opponent = affectedPlayer;
} else {
attacker = affectedPlayer;
opponent = owner;
}
DuelEvent dueling = new DuelEvent(
attacker, opponent);
dueling.setLastRun(0);
Instance.getDelayedEventHandler().add(
dueling);
}
});
}
public void failed() {
Player affectedPlayer = (Player) affectedMob;
owner.getActionSender().sendMessage(
"Error walking to "
+ affectedPlayer.getUsername()
+ " (known bug)");
affectedPlayer.getActionSender().sendMessage(
"Error walking to " + owner.getUsername()
+ " (known bug)");
unsetOptions(owner);
unsetOptions(affectedPlayer);
owner.setBusy(false);
affectedPlayer.setBusy(false);
}
};
walking.setLastRun(GameEngine.getTime() + 500);
Instance.getDelayedEventHandler().add(walking);
}
break;
case 35: // Decline duel
affectedPlayer = player.getWishToDuel();
if (affectedPlayer == null || busy(affectedPlayer)
|| !player.isDueling() || !affectedPlayer.isDueling()) { // This
// shouldn't
// happen
player.setSuspiciousPlayer(true);
unsetOptions(player);
unsetOptions(affectedPlayer);
return;
}
affectedPlayer.getActionSender().sendMessage(
player.getUsername() + " has declined the duel.");
unsetOptions(player);
unsetOptions(affectedPlayer);
world.addEntryToSnapshots(new Activity(player.getUsername(), player
.getUsername()
+ " declined duel "
+ affectedPlayer.getUsername()
+ " at: "
+ player.getX()