else if (actualCommand.equalsIgnoreCase("info"))
{
String fileName = null;
ClanHall clanHall = null;
SiegeClanObject siegeClan = null;
if (tokenizer.hasMoreTokens())
{
int id = Integer.parseInt(tokenizer.nextToken());
clanHall = ResidenceHolder.getInstance().getResidence(id);
fileName = "residence2/clanhall/auction_clanhall_info_main.htm";
}
else
{
clanHall = player.getClan() == null ? null : player.getClan().getHasHideout() > 0 ? ResidenceHolder.getInstance().<ClanHall> getResidence(player.getClan().getHasHideout()) : null;
if ((clanHall != null) && (clanHall.getSiegeEvent().getClass() == ClanHallAuctionEvent.class))
{
if (clanHall.getSiegeEvent().isInProgress())
{
fileName = "residence2/clanhall/auction_clanhall_info_owner_sell.htm";
}
else
{
fileName = "residence2/clanhall/auction_clanhall_info_owner.htm";
}
}
else
{
for (ClanHall ch : ResidenceHolder.getInstance().getResidenceList(ClanHall.class))
{
if ((ch.getSiegeEvent().getClass() == ClanHallAuctionEvent.class) && ((siegeClan = ch.getSiegeEvent().getSiegeClan(SiegeEvent.ATTACKERS, player.getClan())) != null))
{
clanHall = ch;
break;
}
}
if (siegeClan == null)
{
player.sendPacket(SystemMsg.THERE_ARE_NO_OFFERINGS_I_OWN_OR_I_MADE_A_BID_FOR);
showChatWindow(player, 0);
return;
}
fileName = "residence2/clanhall/auction_clanhall_info_bidded.htm";
}
}
ClanHallAuctionEvent auctionEvent = clanHall.getSiegeEvent();
List<AuctionSiegeClanObject> attackers = auctionEvent.getObjects(SiegeEvent.ATTACKERS);
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile(fileName);
msg.replace("%id%", String.valueOf(clanHall.getId()));
msg.replace("%bigger_size%", String.valueOf(attackers.size()));
msg.replace("%grade%", String.valueOf(clanHall.getGrade()));
msg.replace("%rental_fee%", String.valueOf(clanHall.getRentalFee()));
Clan owner = clanHall.getOwner();
msg.replace("%owner%", owner == null ? StringUtils.EMPTY : owner.getName());
msg.replace("%owner_leader%", owner == null ? StringUtils.EMPTY : owner.getLeaderName());
msg.replace("%description%", clanHall.getAuctionDescription());
msg.replace("%min_bid%", String.valueOf(clanHall.getAuctionMinBid()));
Calendar c = auctionEvent.getEndSiegeDate();
msg.replace("%date%", DATE_FORMAT.format(c.getTimeInMillis()));
msg.replace("%hour%", String.valueOf(c.get(Calendar.HOUR_OF_DAY)));
int remainingTime = (int) ((c.getTimeInMillis() - System.currentTimeMillis()) / 60000L);
msg.replace("%remaining_hour%", String.valueOf(remainingTime / 60));
msg.replace("%remaining_minutes%", String.valueOf(remainingTime % 60));
if (siegeClan != null)
{
msg.replace("%my_bid%", String.valueOf(siegeClan.getParam()));
}
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("bidder_list"))
{
int id = Integer.parseInt(tokenizer.nextToken());
int page = Integer.parseInt(tokenizer.nextToken());
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(id);
ClanHallAuctionEvent auctionEvent = clanHall.getSiegeEvent();
List<AuctionSiegeClanObject> attackers = auctionEvent.getObjects(SiegeEvent.ATTACKERS);
if (!auctionEvent.isInProgress())
{
return;
}
int min = BIDDER_PAGE_SIZE * page;
int max = min + BIDDER_PAGE_SIZE;
if (min > attackers.size())
{
min = 0;
max = min + BIDDER_PAGE_SIZE;
}
if (max > attackers.size())
{
max = attackers.size();
}
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_bidder_list.htm");
msg.replace("%id%", String.valueOf(id));
StringBuilder b = new StringBuilder();
for (int i = min; i < max; i++)
{
AuctionSiegeClanObject siegeClan = attackers.get(i);
String t = BIDDER_IN_LIST.replace("%id%", String.valueOf(id)).replace("%clan_name%", siegeClan.getClan().getName()).replace("%date%", DATE_FORMAT.format(siegeClan.getDate()));
b.append(t);
}
msg.replace("%list%", b.toString());
if (attackers.size() > max)
{
msg.replace("%next_button%", "<td>" + HtmlUtils.NEXT_BUTTON + "</td>");
msg.replace("%next_bypass%", "-h npc_%objectId%_bidder_list " + id + " " + (page + 1));
}
else
{
msg.replace("%next_button%", StringUtils.EMPTY);
}
if (page != 0)
{
msg.replace("%prev_button%", "<td>" + HtmlUtils.PREV_BUTTON + "</td>");
msg.replace("%prev_bypass%", "-h npc_%objectId%_bidder_list " + id + " " + (page - 1));
}
else
{
msg.replace("%prev_button%", StringUtils.EMPTY);
}
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("bid_start"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
int id = Integer.parseInt(tokenizer.nextToken());
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(id);
ClanHallAuctionEvent auctionEvent = clanHall.getSiegeEvent();
if (!auctionEvent.isInProgress())
{
return;
}
long minBid = clanHall.getAuctionMinBid();
AuctionSiegeClanObject siegeClan = auctionEvent.getSiegeClan(SiegeEvent.ATTACKERS, player.getClan());
if (siegeClan != null)
{
minBid = siegeClan.getParam();
}
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_bid_start.htm");
msg.replace("%id%", String.valueOf(id));
msg.replace("%min_bid%", String.valueOf(minBid));
msg.replace("%clan_adena%", String.valueOf(player.getClan().getWarehouse().getCountOf(ItemTemplate.ITEM_ID_ADENA)));
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("bid_next"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
int id = Integer.parseInt(tokenizer.nextToken());
long bid = 0;
if (tokenizer.hasMoreTokens())
{
try
{
bid = NUMBER_FORMAT.parse(tokenizer.nextToken()).longValue();
}
catch (ParseException e)
{
//
}
}
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(id);
ClanHallAuctionEvent auctionEvent = clanHall.getSiegeEvent();
if (!auctionEvent.isInProgress())
{
return;
}
if (!checkBid(player, auctionEvent, bid))
{
return;
}
long minBid = clanHall.getAuctionMinBid();
AuctionSiegeClanObject siegeClan = auctionEvent.getSiegeClan(SiegeEvent.ATTACKERS, player.getClan());
if (siegeClan != null)
{
minBid = siegeClan.getParam();
}
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_bid_confirm.htm");
msg.replace("%id%", String.valueOf(id));
msg.replace("%bid%", String.valueOf(bid));
msg.replace("%min_bid%", String.valueOf(minBid));
Calendar c = auctionEvent.getEndSiegeDate();
msg.replace("%date%", DATE_FORMAT.format(c.getTimeInMillis()));
msg.replace("%hour%", String.valueOf(c.get(Calendar.HOUR_OF_DAY)));
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("bid_confirm"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
int id = Integer.parseInt(tokenizer.nextToken());
final long bid = Long.parseLong(tokenizer.nextToken());
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(id);
ClanHallAuctionEvent auctionEvent = clanHall.getSiegeEvent();
if (!auctionEvent.isInProgress())
{
return;
}
for (ClanHall ch : ResidenceHolder.getInstance().getResidenceList(ClanHall.class))
{
if ((clanHall != ch) && (ch.getSiegeEvent().getClass() == ClanHallAuctionEvent.class) && ch.getSiegeEvent().isInProgress() && (ch.getSiegeEvent().getSiegeClan(SiegeEvent.ATTACKERS, player.getClan()) != null))
{
player.sendPacket(SystemMsg.SINCE_YOU_HAVE_ALREADY_SUBMITTED_A_BID_YOU_ARE_NOT_ALLOWED_TO_PARTICIPATE_IN_ANOTHER_AUCTION_AT_THIS_TIME);
onBypassFeedback(player, "bid_start " + id);
return;
}
}
if (!checkBid(player, auctionEvent, bid))
{
return;
}
long consumeBid = bid;
AuctionSiegeClanObject siegeClan = auctionEvent.getSiegeClan(SiegeEvent.ATTACKERS, player.getClan());
if (siegeClan != null)
{
consumeBid -= siegeClan.getParam();
if (bid <= siegeClan.getParam())
{
player.sendPacket(SystemMsg.THE_BID_AMOUNT_MUST_BE_HIGHER_THAN_THE_PREVIOUS_BID);
onBypassFeedback(player, "bid_start " + auctionEvent.getId());
return;
}
}
player.getClan().getWarehouse().destroyItemByItemId(ItemTemplate.ITEM_ID_ADENA, consumeBid);
if (siegeClan != null)
{
siegeClan.setParam(bid);
SiegeClanDAO.getInstance().update(clanHall, siegeClan);
}
else
{
siegeClan = new AuctionSiegeClanObject(SiegeEvent.ATTACKERS, player.getClan(), bid);
auctionEvent.addObject(SiegeEvent.ATTACKERS, siegeClan);
SiegeClanDAO.getInstance().insert(clanHall, siegeClan);
}
player.sendPacket(SystemMsg.YOUR_BID_HAS_BEEN_SUCCESSFULLY_PLACED);
onBypassFeedback(player, "info");
}
else if (actualCommand.equalsIgnoreCase("cancel_bid"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
int id = Integer.parseInt(tokenizer.nextToken());
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(id);
ClanHallAuctionEvent auctionEvent = clanHall.getSiegeEvent();
if (!auctionEvent.isInProgress())
{
return;
}
AuctionSiegeClanObject siegeClan = auctionEvent.getSiegeClan(SiegeEvent.ATTACKERS, player.getClan());
if (siegeClan == null)
{
return;
}
long returnVal = siegeClan.getParam() - (long) (siegeClan.getParam() * 0.1);
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_bid_cancel.htm");
msg.replace("%id%", String.valueOf(id));
msg.replace("%bid%", String.valueOf(siegeClan.getParam()));
msg.replace("%return%", String.valueOf(returnVal));
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("cancel_bid_confirm"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
int id = Integer.parseInt(tokenizer.nextToken());
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(id);
ClanHallAuctionEvent auctionEvent = clanHall.getSiegeEvent();
if (!auctionEvent.isInProgress())
{
return;
}
AuctionSiegeClanObject siegeClan = auctionEvent.getSiegeClan(SiegeEvent.ATTACKERS, player.getClan());
if (siegeClan == null)
{
return;
}
long returnVal = siegeClan.getParam() - (long) (siegeClan.getParam() * 0.1);
player.getClan().getWarehouse().addItem(ItemTemplate.ITEM_ID_ADENA, returnVal);
auctionEvent.removeObject(SiegeEvent.ATTACKERS, siegeClan);
SiegeClanDAO.getInstance().delete(clanHall, siegeClan);