1package com.runehive.game.world.entity.mob.player.exchange;
3import com.google.common.collect.ImmutableSet;
4import com.runehive.content.activity.ActivityType;
5import com.runehive.content.gambling.GambleStage;
6import com.runehive.game.task.impl.DuelNotificationTask;
7import com.runehive.game.task.impl.SessionRemovalNotificationTask;
8import com.runehive.game.world.World;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.game.world.entity.mob.player.PlayerRight;
11import com.runehive.game.world.items.Item;
12import com.runehive.game.world.items.containers.ItemContainer;
13import com.runehive.game.world.items.containers.inventory.Inventory;
14import com.runehive.game.world.position.Position;
17import java.util.function.Consumer;
26 public static final Set<ExchangeSession>
SESSIONS =
new HashSet<>();
87 player.exchangeSession.reset();
100 player.message(
"This player is currently is a " +
type.name +
" with another player.");
104 player.message(
"You cannot " +
type.name +
" with yourself.");
117 player.message(
"You can not " +
type.name +
" as you are an iron man.");
121 player.message(
other.getName() +
" can not be " +
type.name +
"d as they are an iron man.");
124 if (
player.exchangeSession.requested_players.contains(
other)) {
125 player.message(
"You have already sent a request to this player.");
128 if (
player.locking.locked()) {
129 player.message(
"You cannot send a " +
type.name +
" request right now.");
132 if (
other.locking.locked()) {
133 player.message(
other.getName() +
" is currently busy.");
136 if (
player.playerAssistant.busy()) {
137 player.message(
"Please finish what you are doing before you do that.");
140 if (
other.playerAssistant.busy()) {
141 player.message(
other.getName() +
" is currently busy.");
145 player.message(
"You can not do that whilst in a duel!");
149 other.message(
"You can not do that whilst in a duel!");
156 player.exchangeSession.reset();
165 if (invItem ==
null) {
181 player.message(
"You can't offer this item.");
185 int count =
player.inventory.computeAmountForId(item.
getId());
190 player.inventory.remove(item);
200 if (
player ==
null || containerItem ==
null) {
203 if (!
Item.
valid(containerItem) || !
this.item_containers.get(
player).contains(containerItem.
getId())) {
215 Item item =
new Item(containerItem.
getId(), amount == -1 ?
this.item_containers.get(
player).computeAmountForId(containerItem.
getId()) : amount);
221 player.inventory.add(item);
270 player.message(
"There is nothing in your inventory to deposit!");
274 List<Item> transfer =
new ArrayList<>();
276 if (item ==
null || !item.isTradeable()) {
283 this.item_containers.get(
player).addAll(transfer);
295 player.message(
"There is nothing in this container to withdraw!");
298 player.inventory.addAll(container);
307 if (!session.isPresent() || session.get().finalized) {
311 session.get().finalized =
true;
315 session.get().forEach(
player -> {
388 return p.
getName().equals(
player.getName()) ? this.other : this.player;
Represents the game world.
static void schedule(Task task)
Submits a new event.
This class represents a character controlled by a player.
String getName()
Gets the name of this entity.
boolean equals(Object obj)
final boolean add(Player player, int slot, int amount)
Attempts to deposit an item to the container.
static Optional< ExchangeSession > getSession(Player player)
Gets the session if applicable the player is in.
abstract boolean canRemoveItem(Player player, Item item, int slot)
Checks if the item can be removed from the container.
boolean hasAttachment()
Determines if the trade stage has an attachment.
abstract void updateOfferComponents()
Updates the itemcontainer when an item is offered or removed.
static Optional< ExchangeSession > getSession(Player player, Player other, ExchangeSessionType type)
Gets the session if applicable the player is in.
abstract boolean canAddItem(Player player, Item item, int slot)
Checks if the item can be added to the container.
boolean canOffer
Determines if the player can offer or withdraw items.
static Optional< ExchangeSession > getSession(Player player, ExchangeSessionType type)
Gets the session if applicable the player is in.
final Player other
The other player in this session.
final Player player
The controller of this session.
static final Set< ExchangeSession > SESSIONS
The collection of sessions.
abstract void updateMainComponents(String component)
Updates the main components of the itemcontainer.
Object getAttachment()
Retrieves the attachment object to this class.
boolean request()
Attempts to start an exchange session.
Object attachment
The attachment to the session stage, this will more than likely be a player object that will be attac...
void withdrawAll(Player player)
Withdraws all items from the exchange session.
final Map< Player, ItemContainer > item_containers
The items which are in this exchange session.
boolean finalized
Determines if this exchange has been finalized.
abstract void accept(Player player, String COMPONENT)
The method invoked when a PLAYER accepts a certain exchange component.
static boolean inSession(Player player, Player other, ExchangeSessionType type)
Determines if the player is a session with other which matches the type.
abstract boolean onButtonClick(Player player, int button)
The method invoked when a button is clicked.
ExchangeSession(Player player, Player other, ExchangeSessionType type)
Constructs a new ExchangeSession.
boolean inAnySession()
Determines if the player is any session.
void setAttachment(Object attachment)
Assigns an attachment to this stage object.
void finalize(ExchangeCompletionType type)
Finalizes the exchange session procedure for the specified player in a session.
void forEach(Consumer< Player > action)
Executes the specified action for every player in this session.
abstract boolean onRequest()
The method invoked when a player requests the other player.
static boolean inSession(Player player, ExchangeSessionType type)
Determines if the player is a session which matches the type.
static boolean allMatch(ExchangeSession session, String name, String otherName)
static Optional< ExchangeSession > getSession(Player player, Player other)
Gets the session if applicable the player is in.
void depositeAll(Player player)
Deposites all items to the exchange session.
Player getOther(Player p)
Gets the other player in the exchange session.
abstract void onReset()
Any functionality that should be handled when the itemcontainer closes.
static boolean anyMatch(ExchangeSession session, String name)
final ExchangeSessionType type
The type of this exchange session.
The container class that represents an item that can be interacted with.
final void setAmount(int amount)
Sets the quantity of this item.
final int getId()
Gets the identification of this item.
static boolean valid(Item item)
Determines if item is valid.
final int getAmount()
Gets the quantity of this item.
An abstraction game representing a group of Items.
final Item get(int index)
Gets the Item located on index.
void clear()
Removes all of the items from this container.
boolean removeAll(Collection<? extends Item > items)
Attempts to withdraw items in bulk from this container.
An ItemContainer implementation that manages the inventory for a Player.
void refresh()
Refreshes the players inventory.
Represents a single tile on the game world.
Holds all activity types that are timed.
Holds all the player right data.
static boolean isOwner(Player player)
static boolean isIronman(Player player)
Checks if the player is an ironman.
An enumerated type defining policies for stackable Items.
STANDARD
The STANDARD policy, items are only stacked if they are defined as stackable in their ItemDefinition ...