コード例 #1
0
ファイル: Stake.java プロジェクト: Delcorum/WrathServer
  public static boolean stakeItem(Player player, int itemId, int amount, int slot) {
    if (!player.getInventory().contains(itemId) || !player.getDuel().isDueling()) {
      return false;
    }

    if (player.getInterfaceState().getCurrentInterface() != 37888) {
      return false;
    }

    if (new Item(itemId).getDefinition().isUntradeable()) {
      player.sendMessage("This item is currently untradeable and cannot be staked.");
      return false;
    }

    Player playerToDuel =
        GameService.getWorld().getByUsername(player.getDuel().getDuelingWith()).get();

    if (playerToDuel == null) {
      return false;
    }

    if (player.getDuel().getStatus() != DuelingStatus.WAITING_FIRST_ACCEPT
            && player.getDuel().getStatus() != DuelingStatus.ACCEPTED_FIRST_INTERFACE
        || playerToDuel.getDuel().getStatus() != DuelingStatus.WAITING_FIRST_ACCEPT
            && playerToDuel.getDuel().getStatus() != DuelingStatus.ACCEPTED_FIRST_INTERFACE) {
      DuelArenaHandler.declineDuel(player, true);
      return false;
    }

    if (player.getInventory().getItemAmount(itemId) < amount) {
      amount = player.getInventory().getItemAmount(itemId);

      if (amount == 0 || player.getInventory().getItemAmount(itemId) < amount) {
        return false;
      }
    }

    if (player.getDuel().getStakeInventory().add(new Item(itemId, amount))) {
      player.getInventory().remove(new Item(itemId, amount));
    }

    DuelArenaHandler.updateStakedItems(player, playerToDuel);

    player.getSession().send(new SendStringPacket("", 6684));
    playerToDuel.getSession().send(new SendStringPacket("", 6684));

    player.getDuel().setStatus(DuelingStatus.WAITING_FIRST_ACCEPT);
    playerToDuel.getDuel().setStatus(DuelingStatus.WAITING_FIRST_ACCEPT);
    player.setAttribute("stake_change_delay", System.currentTimeMillis());
    return true;
  }