1package com.osroyale.game.world.entity.mob.player.exchange;
3import com.google.common.collect.ImmutableSet;
4import com.osroyale.content.activity.ActivityType;
5import com.osroyale.content.gambling.GambleStage;
6import com.osroyale.game.task.impl.DuelNotificationTask;
7import com.osroyale.game.task.impl.SessionRemovalNotificationTask;
8import com.osroyale.game.world.World;
9import com.osroyale.game.world.entity.mob.player.Player;
10import com.osroyale.game.world.entity.mob.player.PlayerRight;
11import com.osroyale.game.world.items.Item;
12import com.osroyale.game.world.items.containers.ItemContainer;
13import com.osroyale.game.world.items.containers.inventory.Inventory;
14import com.osroyale.game.world.position.Position;
17import java.util.function.Consumer;
63 public static final Set<ExchangeSession>
SESSIONS =
new HashSet<>();
81 private Object attachment;
124 player.exchangeSession.reset();
137 player.message(
"This player is currently is a " +
type.name +
" with another player.");
141 player.message(
"You cannot " +
type.name +
" with yourself.");
154 player.message(
"You can not " +
type.name +
" as you are an iron man.");
158 player.message(
other.getName() +
" can not be " +
type.name +
"d as they are an iron man.");
161 if (
player.exchangeSession.requested_players.contains(
other)) {
162 player.message(
"You have already sent a request to this player.");
165 if (
player.locking.locked()) {
166 player.message(
"You cannot send a " +
type.name +
" request right now.");
169 if (
other.locking.locked()) {
170 player.message(
other.getName() +
" is currently busy.");
173 if (
player.playerAssistant.busy()) {
174 player.message(
"Please finish what you are doing before you do that.");
177 if (
other.playerAssistant.busy()) {
178 player.message(
other.getName() +
" is currently busy.");
182 player.message(
"You can not do that whilst in a duel!");
186 other.message(
"You can not do that whilst in a duel!");
193 player.exchangeSession.reset();
201 Item invItem =
player.inventory.get(slot);
202 if (invItem ==
null) {
205 if (!Item.valid(invItem) || !
player.inventory.contains(invItem.getId())) {
218 player.message(
"You can't offer this item.");
221 Item item =
new Item(invItem.getId(), amount);
222 int count =
player.inventory.computeAmountForId(item.getId());
223 if (item.getAmount() > count) {
224 item.setAmount(count);
227 player.inventory.remove(item);
236 Item containerItem = this.item_containers.get(
player).get(slot);
237 if (
player ==
null || containerItem ==
null) {
240 if (!Item.valid(containerItem) || !
this.item_containers.get(
player).contains(containerItem.getId())) {
252 Item item =
new Item(containerItem.getId(), amount == -1 ?
this.item_containers.get(
player).computeAmountForId(containerItem.getId()) : amount);
254 if (item.getAmount() > count) {
255 item.setAmount(count);
258 player.inventory.add(item);
261 if (this.player.equals(
player)) {
275 this.attachment = attachment;
285 return Objects.nonNull(attachment);
290 return SESSIONS.stream().anyMatch(session -> allMatch(session,
player.getName(),
other.getName()) && session.type.equals(
type));
307 player.message(
"There is nothing in your inventory to deposit!");
311 List<Item> transfer =
new ArrayList<>();
312 for (Item item : inventory.
getItems()) {
313 if (item ==
null || !item.isTradeable()) {
320 this.item_containers.get(
player).addAll(transfer);
332 player.message(
"There is nothing in this container to withdraw!");
335 player.inventory.addAll(container);
344 if (!session.isPresent() || session.get().finalized) {
348 session.get().finalized =
true;
352 session.get().forEach(
player -> {
354 items.forEach(
player.inventory::add);
376 return SESSIONS.stream().filter(s -> anyMatch(s,
player.getName())).findAny();
386 return SESSIONS.stream().filter(s -> s.type.equals(
type) && anyMatch(s,
player.getName())).findAny();
396 return SESSIONS.stream().filter(s -> allMatch(s,
player.getName(),
other.getName())).findAny();
406 return SESSIONS.stream().filter(s -> allMatch(s,
player.getName(),
other.getName()) && s.type.equals(
type)).findAny();
414 public void forEach(Consumer<Player> action) {
425 return p.
getName().equals(
player.getName()) ? this.other : this.player;
428 private static boolean anyMatch(
ExchangeSession session, String name) {
432 private static boolean allMatch(
ExchangeSession session, String name, String otherName) {
433 return Arrays.stream(
new String[]{session.player.getName(), session.other.getName()}).anyMatch(n -> n.equals(name) || n.equals(otherName));
static void schedule(Task task)
abstract boolean canRemoveItem(Player player, Item item, int slot)
final Map< Player, ItemContainer > item_containers
ExchangeSession(Player player, Player other, ExchangeSessionType type)
static Optional< ExchangeSession > getSession(Player player, ExchangeSessionType type)
abstract boolean canAddItem(Player player, Item item, int slot)
static final Set< ExchangeSession > SESSIONS
void depositeAll(Player player)
abstract void accept(Player player, String COMPONENT)
abstract boolean onButtonClick(Player player, int button)
Player getOther(Player p)
final boolean add(Player player, int slot, int amount)
abstract void updateMainComponents(String component)
static boolean inSession(Player player, ExchangeSessionType type)
static Optional< ExchangeSession > getSession(Player player, Player other)
void finalize(ExchangeCompletionType type)
abstract boolean onRequest()
static Optional< ExchangeSession > getSession(Player player)
static boolean inSession(Player player, Player other, ExchangeSessionType type)
abstract void updateOfferComponents()
final ExchangeSessionType type
void forEach(Consumer< Player > action)
static Optional< ExchangeSession > getSession(Player player, Player other, ExchangeSessionType type)
void withdrawAll(Player player)
void setAttachment(Object attachment)
final Item get(int index)
boolean removeAll(Collection<? extends Item > items)
static boolean isIronman(Player player)