mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 00:31:51 +00:00
Trade issue (#117)
* Update Game.java Adding ShiftDropping to items with the wield option as default. The options still have double Drop like the shiftdrop for use option as default. * Trade issues Resolved issues around the trading system: 1. Can't trade anymore when other player isn't close; 2. Trade interface now close when other player disconnect or click the minimap; 3. Players cant no longer store items in the trade interface; 4. Items are properly distributed after any player closes the trade interface; 5. Added a message saying 'Trade completed.' after a trade is completed;
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package redone.game.players;
|
||||
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.w3c.dom.ranges.Range;
|
||||
import redone.Constants;
|
||||
import redone.event.CycleEvent;
|
||||
import redone.event.CycleEventContainer;
|
||||
@@ -47,11 +49,15 @@ public class Trading {
|
||||
if (!CastleWars.deleteCastleWarsItems(player, id)) {
|
||||
return;
|
||||
}
|
||||
if (!player.inTrade && o.tradeRequested && o.tradeWith == player.playerId && player.playerIsBusy() == false && o.playerIsBusy() == false) {
|
||||
player.getTrading().openTrade();
|
||||
o.getTrading().openTrade();
|
||||
} else if (!player.inTrade && player.playerIsBusy() == false && o.playerIsBusy() == false) {
|
||||
|
||||
if (!player.inTrade && o.tradeRequested && o.tradeWith == player.playerId && player.playerIsBusy() == false && o.playerIsBusy() == false) { //start trading process
|
||||
if (!isCloseTo(o)) {
|
||||
player.getActionSender().sendMessage("Player is not close enough. Retry when you are closer...");
|
||||
} else {
|
||||
player.getTrading().openTrade();
|
||||
o.getTrading().openTrade();
|
||||
}
|
||||
} else if (!player.inTrade && player.playerIsBusy() == false && o.playerIsBusy() == false) { //send trade request
|
||||
//Problem = sends the request then walk to player. Solution= change processing order. Fix= Send message when trying to open the trade interface if the other player isn't closer than 3 tiles.
|
||||
player.tradeRequested = true;
|
||||
player.getActionSender().sendMessage("Sending trade request...");
|
||||
o.getActionSender()
|
||||
@@ -63,7 +69,15 @@ public class Trading {
|
||||
Misc.println("Error requesting trade.");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCloseTo(Client tradedPlayer) {
|
||||
ValueRange PlayerCoordRangeX = ValueRange.of(tradedPlayer.currentX - 3, tradedPlayer.currentX + 3);
|
||||
ValueRange PlayerCoordRangeY = ValueRange.of(tradedPlayer.currentY - 3, tradedPlayer.currentY + 3);
|
||||
if (PlayerCoordRangeX.isValidIntValue(player.currentX) && PlayerCoordRangeY.isValidIntValue(player.currentY)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void openTrade() {
|
||||
Client o = (Client) PlayerHandler.players[player.tradeWith];
|
||||
|
||||
@@ -294,11 +308,10 @@ public class Trading {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!player.inTrade) {
|
||||
if (!player.inTrade || !o.inTrade) {
|
||||
declineTrade();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Item.itemStackable[itemID] || Item.itemIsNote[itemID]) {
|
||||
boolean inTrade = false;
|
||||
for (GameItem item : offeredItems) {
|
||||
|
||||
@@ -2431,10 +2431,13 @@ public class ClickingButtons implements PacketType {
|
||||
|
||||
}
|
||||
Client ot = (Client) PlayerHandler.players[player.tradeWith];
|
||||
if (ot == null) {
|
||||
if (ot == null || !ot.inTrade) {
|
||||
player.getTrading().declineTrade();
|
||||
player.getActionSender().sendMessage(
|
||||
"Trade declined as the other player has disconnected.");
|
||||
ot.getTrading().declineTrade();
|
||||
ot.getActionSender().sendMessage(
|
||||
"Trade declined as you disconnected.");
|
||||
break;
|
||||
}
|
||||
player.getPlayerAssistant().sendFrame126(
|
||||
@@ -2525,6 +2528,11 @@ public class ClickingButtons implements PacketType {
|
||||
ot1.acceptedTrade = true;
|
||||
player.getTrading().giveItems();
|
||||
ot1.getTrading().giveItems();
|
||||
//here
|
||||
player.getActionSender().sendMessage(
|
||||
"@red@Trade completed.");
|
||||
ot1.getActionSender().sendMessage(
|
||||
"@red@Trade completed.");
|
||||
break;
|
||||
}
|
||||
ot1.getPlayerAssistant().sendFrame126(
|
||||
|
||||
@@ -20,8 +20,9 @@ public class ClickingStuff implements PacketType {
|
||||
if(player.isShopping)
|
||||
player.isShopping = false;
|
||||
if (player.inTrade) {
|
||||
if (!player.acceptedTrade) {
|
||||
Client opponent = (Client) PlayerHandler.players[player.tradeWith];
|
||||
Client opponent = (Client) PlayerHandler.players[player.tradeWith];
|
||||
if (!player.acceptedTrade || !opponent.inTrade || opponent == null) {
|
||||
opponent = (Client) PlayerHandler.players[player.tradeWith];
|
||||
opponent.tradeAccepted = false;
|
||||
player.tradeAccepted = false;
|
||||
opponent.tradeStatus = 0;
|
||||
@@ -32,8 +33,9 @@ public class ClickingStuff implements PacketType {
|
||||
opponent.getActionSender().sendMessage("@red@Other player has declined the trade.");
|
||||
Misc.println("trade reset");
|
||||
player.getTrading().declineTrade();
|
||||
opponent.getTrading().declineTrade();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(player.openDuel && player.duelStatus >= 1 && player.duelStatus <= 4) {
|
||||
Client o = (Client) PlayerHandler.players[player.duelingWith];
|
||||
|
||||
Reference in New Issue
Block a user