}
if (player.getInventory().getSlot(slot).wielded) {
player.getInventory().setWield(slot, false);
ItemWieldableDef def = ItemAttributes
.getWieldable(item.id);
player.updateWornItems(
def.getWieldPos(),
player.getPlayerAppearance().getSprite(
def.getWieldPos()));
}
player.getInventory().remove(item.id, item.amount, false);
}
slot = -1;
for (InvItem item : theirOffer) {
slot++;
if (affectedPlayer.getInventory().countId(item.id) < item.amount) {
affectedPlayer.setSuspiciousPlayer(true);
unsetOptions(player);
unsetOptions(affectedPlayer);
return;
}
if (item.getDef().isMembers() && !World.isMembers()) {
affectedPlayer.getActionSender().sendMessage(
"You can not trade members items.");
unsetOptions(player);
unsetOptions(affectedPlayer);
return;
}
if (affectedPlayer.getInventory().getSlot(slot).wielded) {
affectedPlayer.getInventory().setWield(slot, false);
ItemWieldableDef def = ItemAttributes
.getWieldable(item.id);
affectedPlayer.updateWornItems(
def.getWieldPos(),
affectedPlayer.getPlayerAppearance().getSprite(
def.getWieldPos()));
}
affectedPlayer.getInventory().remove(item.id, item.amount,
false);
}
MiscPacketBuilder loginServer = Instance.getServer()
.getLoginConnector().getActionSender();
long playerhash = DataConversions.usernameToHash(player
.getUsername());
long affectedPlayerhash = DataConversions
.usernameToHash(affectedPlayer.getUsername());
for (InvItem item : myOffer) {
affectedPlayer.getInventory().add(item.id, item.amount,
false);
}
for (InvItem item : theirOffer) {
player.getInventory().add(item.id, item.amount, false);
}
boolean senddata = false;
for (InvItem item : myOffer) {
loginServer.tradeLog(playerhash, affectedPlayerhash,
item.id, item.amount, player.getX(), player.getY(),
1);
if (item.amount > 10000000 || Formulae.isRareItem(item.id))
senddata = true;
}
if (senddata)
DataManager.reportHandler.submitDupeData(
DataConversions.hashToUsername(playerhash),
playerhash);
senddata = false;
for (InvItem item : theirOffer) {
loginServer.tradeLog(affectedPlayerhash, playerhash,
item.id, item.amount, player.getX(), player.getY(),
1);
if (item.amount > 10000000 || Formulae.isRareItem(item.id))
senddata = true;
}
if (senddata)
DataManager.reportHandler.submitDupeData(
DataConversions.hashToUsername(affectedPlayerhash),
affectedPlayerhash);
player.getActionSender().sendInventory();
player.getActionSender().sendEquipmentStats();
long now = GameEngine.getTime();
player.save();
player.setLastSaveTime(now);
affectedPlayer.save();
affectedPlayer.setLastSaveTime(now);
player.getActionSender().sendMessage("Trade completed.");
affectedPlayer.getActionSender().sendInventory();
affectedPlayer.getActionSender().sendEquipmentStats();
affectedPlayer.getActionSender()
.sendMessage("Trade completed.");
unsetOptions(player);
unsetOptions(affectedPlayer);
}
break;
case 216: // Trade declined
affectedPlayer = player.getWishToTrade();
if (affectedPlayer == null || busy(affectedPlayer)
|| !player.isTrading() || !affectedPlayer.isTrading()) { // This
// shouldn't
// happen
player.setSuspiciousPlayer(true);
unsetOptions(player);
unsetOptions(affectedPlayer);
return;
}
affectedPlayer.getActionSender().sendMessage(
player.getUsername() + " has declined the trade.");
unsetOptions(player);
unsetOptions(affectedPlayer);
break;
case 70: // Receive offered item data
affectedPlayer = player.getWishToTrade();
if (affectedPlayer == null
|| busy(affectedPlayer)
|| !player.isTrading()
|| !affectedPlayer.isTrading()
|| (player.isTradeOfferAccepted() && affectedPlayer
.isTradeOfferAccepted())
|| player.isTradeConfirmAccepted()
|| affectedPlayer.isTradeConfirmAccepted()) { // This
// shouldn't
// happen
player.setSuspiciousPlayer(true);
unsetOptions(player);
unsetOptions(affectedPlayer);
return;
}
player.setTradeOfferAccepted(false);
player.setTradeConfirmAccepted(false);
affectedPlayer.setTradeOfferAccepted(false);
affectedPlayer.setTradeConfirmAccepted(false);
// player.getActionSender().sendTradeAcceptUpdate();
// affectedPlayer.getActionSender().sendTradeAcceptUpdate();
Inventory tradeOffer = new Inventory(player);
player.resetTradeOffer();
int count = (int) p.readByte();
for (int slot = 0; slot < count; slot++) {
InvItem tItem = new InvItem(p.readShort(), p.readInt());
if (tItem.amount < 1) {
player.setSuspiciousPlayer(true);
player.setRequiresOfferUpdate(true);
continue;
}
ItemDef def = tItem.getDef();
if (!def.canTrade() && !player.isMod()) {
player.getActionSender().sendMessage(
def.getName()
+ " cannot be traded with other players");
player.setRequiresOfferUpdate(true);
continue;
}
tradeOffer.add(tItem.id, tItem.amount, false);