1package com.osroyale.content.gambling;
3import com.osroyale.content.gambling.impl.FiftyFive;
4import com.osroyale.content.gambling.impl.FlowerPoker;
5import com.osroyale.game.world.World;
6import com.osroyale.game.world.entity.mob.Direction;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.entity.mob.player.PlayerRight;
9import com.osroyale.game.world.items.Item;
10import com.osroyale.game.world.items.ItemDefinition;
11import com.osroyale.game.world.items.containers.ItemContainer;
12import com.osroyale.game.world.object.CustomGameObject;
13import com.osroyale.game.world.pathfinding.TraversalMap;
14import com.osroyale.game.world.position.Boundary;
15import com.osroyale.game.world.position.Position;
16import com.osroyale.net.packet.out.*;
17import com.osroyale.util.Utility;
19import java.util.ArrayList;
20import java.util.Objects;
64 private final int INTERFACE_ID = 44750;
68 private final int INVENTORY_ID = 44775;
72 private final int CONFIG = 444;
74 public static final Boundary GAMBLING_ZONE =
new Boundary(3148, 3476, 3181, 3505);
107 public boolean hasConfirmed() {
111 public void setConfirmed(
boolean confirmed) {
137 public void setGame(
Gamble game) {
150 protected ArrayList<CustomGameObject> gameFlowers =
new ArrayList<CustomGameObject>();
152 public ArrayList<CustomGameObject> getGameFlowers() {
157 protected ArrayList<Flowers> flowers =
new ArrayList<Flowers>();
159 public ArrayList<Flowers> getFlowers() {
171 if(!
Boundary.isIn(player, GAMBLING_ZONE))
return false;
173 if (Objects.nonNull(requiredStage) && !player.getGambling().getStage().equals(requiredStage))
return false;
186 player.message(
"You can not gamble as you are an iron man.");
191 player.message(
other.getName() +
" can not gamble as they are an iron man.");
194 if(player.playTime < 6000) {
195 player.message(
"You must have at least 1 hour of play time to gamble.");
201 if (!Objects.isNull(requested)) {
202 System.out.println(
"Accept...");
210 player.getGambling().setOther(
other);
211 player.getGambling().setStage(
GambleStage.SENDING_OFFER);
212 System.out.println(
"send request...");
221 if(player ==
other)
return;
225 player.getGambling().setStage(
GambleStage.SENDING_OFFER);
226 player.getGambling().setOther(
other);
228 if (
other.getGambling().getOther() !=
null && player.getIndex() ==
other.getGambling().getOther().getIndex()) {
229 System.out.println(
"accepted request...");
241 player.getGambling().setConfirmed(
false);
242 player.getGambling().setStage(
GambleStage.PLACING_BET);
243 System.out.println(
"Open the interface for ["+String.format(player.getUsername())+
"] and ["+String.format(
other.getUsername())+
"]...");
250 player.send(
new SendString(
"" + String.format(player.getUsername()), 44768));
251 player.send(
new SendString(
"" + String.format(
other.getUsername()), 44769));
262 if (
other ==
null)
return;
264 if(player.getGambling().getType() ==
null || player.getGambling().getType().equals(
GambleType.NONE)) {
265 player.message(
"You need to select a game first.");
269 if (System.currentTimeMillis() - player.getLastModification() < 5_000) {
270 player.message(
"@red@Something was changed in the last 5 seconds, you cannot accept yet.");
274 if (player.getGambling().getType() !=
other.getGambling().getType())
return;
276 if(player.getGambling().hasConfirmed())
return;
278 player.getGambling().setConfirmed(
true);
280 player.message(
"You have accepted the gamble with "+String.format(
other.getUsername())+
".");
281 other.message(String.format(player.getUsername()) +
" has accepted the gamble.");
283 System.out.println(
"player: " + String.format(player.getUsername()));
284 System.out.println(
"other: " + String.format(
other.getUsername()));
286 if (
other.getGambling().hasConfirmed()) {
289 player.getGambling().setGame(
game);
292 player.getGambling().setStage(
GambleStage.SENDING_OFFER);
294 player.getGambling().setOther(
other);
296 System.out.println(
"Both confirmed start the game...");
312 boolean canPlay =
true;
313 for(
int index = 0; index < 5; index++) {
330 for(Item item : player.getGambling().getContainer()) {
331 if(item ==
null || item.getId() == -1)
continue;
334 player.inventory.
add(item);
336 player.bank.
add(item);
337 player.message(
"@red@You had no room for the "+item.getAmount()+
" x "+item.getDefinition().getName()+
", its been sent to your bank.");
341 player.getGambling().getContainer().
clear();
347 for(Item item :
other.getGambling().getContainer()) {
348 if(item ==
null || item.getId() == -1)
continue;
350 if(
other.inventory.hasCapacityFor(item))
351 other.inventory.add(item);
353 other.bank.add(item);
354 other.message(
"@red@You had no room for the "+item.getAmount()+
" x "+item.getDefinition().getName()+
", its been sent to your bank.");
358 other.getGambling().getContainer().clear();
359 other.inventory.refresh();
360 other.bank.refresh();
376 if(
other ==
null)
return;
380 if (!def.isTradeable()) {
381 player.send(
new SendMessage(
"This is item is untradeable!"));
385 if(!player.inventory.
contains(itemId))
return;
390 if(amount <= 0)
return;
392 Item item =
new Item(itemId, amount);
394 player.inventory.
remove(item, slot);
395 player.getGambling().getContainer().
add(item);
397 player.inventory.
refresh(player, INVENTORY_ID + 1);
399 player.message(
"Not enough space.");
401 player.setLastModification(System.currentTimeMillis());
402 other.setLastModification(System.currentTimeMillis());
419 if(
other ==
null)
return;
421 Item clickedItem = player.getGambling().getContainer().
get(slot);
423 if(clickedItem.getId() != itemId)
return;
425 if(amount > clickedItem.getAmount())
426 amount = clickedItem.getAmount();
428 if(!clickedItem.getDefinition().isStackable() && amount > player.inventory.
getFreeSlots())
431 if(amount <= 0)
return;
433 player.getGambling().getContainer().
remove(itemId, amount);
434 player.inventory.
add(itemId, amount);
437 player.inventory.
refresh(player, INVENTORY_ID + 1);
439 player.setLastModification(System.currentTimeMillis());
440 other.setLastModification(System.currentTimeMillis());
470 private void start(
Player player) {
471 if (!
canGamble(player, GambleStage.SENDING_OFFER))
return;
475 if (
other ==
null)
return;
477 if (
other.getGambling().hasConfirmed()) {
478 if (player.getGambling().getGame() ==
null)
return;
480 if (player.getGambling().getGame().getHost() ==
null)
return;
485 player.getGambling().setStage(GambleStage.IN_PROGRESS);
486 other.getGambling().setStage(GambleStage.IN_PROGRESS);
488 player.setGambleLock(
true);
489 other.setGambleLock(
true);
491 player.getGambling().getGame().gamble();
503 if (host.getGambling().getGame() ==
null)
506 if (host.getGambling().getGame().getHost() ==
null)
509 if (!
World.getPlayers().contains(opponent) &&
World.getPlayers().contains(host)) {
510 give(host.getGambling().getType(),
'H', host, opponent,
false);
511 }
else if (
World.getPlayers().contains(opponent) && !
World.getPlayers().contains(host)) {
512 give(host.getGambling().getType(),
'O', opponent, host,
false);
514 if (hostScore == 55) {
515 host.
speak(
"The roll was a draw, rerolling...");
516 opponent.
speak(
"The roll was a draw, rerolling...");
518 host.getGambling().setStage(
GambleStage.IN_PROGRESS);
519 opponent.getGambling().setStage(
GambleStage.IN_PROGRESS);
520 host.getGambling().getGame().gamble();
524 boolean hostWon = hostScore > opponentScore;
525 give(host.getGambling().getType(), hostWon ?
'H' :
'O', hostWon ? host : opponent, hostWon ? opponent : host,
false);
541 winner.
speak(
"It's a draw!");
542 loser.
speak(
"It's a draw!");
544 removeFlowers(winner);
545 removeFlowers(loser);
547 winner.getGambling().setStage(
GambleStage.IN_PROGRESS);
548 loser.getGambling().setStage(
GambleStage.IN_PROGRESS);
550 winner.getGambling().getGame().gamble();
556 for(Item item : winner.getGambling().getContainer()) {
557 if(item ==
null || item.getId() == -1)
continue;
560 winner.inventory.
add(item);
567 for(Item item : loser.getGambling().getContainer()) {
568 if(item ==
null || item.getId() == -1)
continue;
571 winner.inventory.
add(item);
578 send(gambleType, winnerIdentifier, winner, loser);
599 if (winnerIdentifier ==
'H')
600 winner.
speak(
"The roll was under 55, I have won the 55x2.");
602 winner.
speak(
"The roll was higher then 55, I have won the 55x2.");
605 winner.
speak(
"I have won!");
606 loser.
speak(
"I have lost!");
619 if(
other ==
null)
return;
621 player.getGambling().setConfirmed(
false);
622 player.getGambling().setType(
type);
624 player.setLastModification(System.currentTimeMillis());
626 other.getGambling().setConfirmed(
false);
629 other.setLastModification(System.currentTimeMillis());
638 if(player.getGambling().getStage().equals(
GambleStage.NONE))
641 player.getGambling().setConfirmed(
false);
642 player.getGambling().setGame(
null);
643 player.getGambling().setType(
null);
645 player.setGambleLock(
false);
648 removeFlowers(player);
650 if(player.getGambling().getOther() !=
null)
651 reset(player.getGambling().getOther());
653 player.getGambling().setOther(
null);
656 public void removeFlowers(
Player player) {
658 flowers.unregister();
660 player.getGambling().getGameFlowers().clear();
661 player.getGambling().getFlowers().clear();
void open(Player player, Player other)
void deposit(Player player, int itemId, int slot, int amount)
boolean canGamble(Player player, GambleStage requiredStage)
void withdraw(Player player, int itemId, int slot, int amount)
void acceptRequest(Player player, Player other)
void give(GambleType gambleType, char winnerIdentifier, Player winner, Player loser, boolean draw)
void decline(Player player)
void handleModeSelection(Player player, GambleType type)
boolean canPlayFlowerPokerAtPositon(Player player, Position position)
void sendRequest(Player player, Player other)
void reset(Player player)
void accept(Player player)
void finish(Player host, Player opponent, int hostScore, int opponentScore)
void speak(String forceChat)
static ItemDefinition get(int id)
final Item get(int index)
boolean remove(Item item)
final boolean hasCapacityFor(Item... item)
final int computeAmountForId(int id)
void addOrDrop(List< Item > items)
static boolean isTraversable(Position from, Direction direction, int size)
static Position create(int x, int y, int z)
static String capitalizeSentence(final String string)
static boolean isIronman(Player player)