StringTokenizer tokenizer = new StringTokenizer(command.replace("\r\n", "<br1>"));
String actualCommand = tokenizer.nextToken();
if (actualCommand.equalsIgnoreCase("map"))
{
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile(getMapDialog());
msg.replace("%lang%", player.getLang());
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("list_all"))
{
int page = Integer.parseInt(tokenizer.nextToken());
List<ClanHallAuctionEvent> events = new ArrayList<>();
for (ClanHall ch : ResidenceHolder.getInstance().getResidenceList(ClanHall.class))
{
if ((ch.getSiegeEvent().getClass() == ClanHallAuctionEvent.class) && ch.getSiegeEvent().isInProgress())
{
events.add(ch.<ClanHallAuctionEvent> getSiegeEvent());
}
}
if (events.isEmpty())
{
player.sendPacket(SystemMsg.THERE_ARE_NO_CLAN_HALLS_UP_FOR_AUCTION);
showChatWindow(player, 0);
return;
}
int min = CH_PAGE_SIZE * page;
int max = min + CH_PAGE_SIZE;
if (min > events.size())
{
min = 0;
max = min + CH_PAGE_SIZE;
}
if (max > events.size())
{
max = events.size();
}
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_list_clanhalls.htm");
StringBuilder b = new StringBuilder();
for (int i = min; i < max; i++)
{
ClanHallAuctionEvent event = events.get(i);
List<AuctionSiegeClanObject> attackers = event.getObjects(SiegeEvent.ATTACKERS);
Calendar endDate = event.getEndSiegeDate();
String out = CH_IN_LIST.replace("%id%", String.valueOf(event.getId())).replace("%min_bid%", String.valueOf(event.getResidence().getAuctionMinBid())).replace("%size%", String.valueOf(attackers.size())).replace("%date%", DATE_FORMAT.format(endDate.getTimeInMillis()));
b.append(out);
}
msg.replace("%list%", b.toString());
if (events.size() > max)
{
msg.replace("%next_button%", "<td>" + HtmlUtils.NEXT_BUTTON + "</td>");
msg.replace("%next_bypass%", "-h npc_%objectId%_list_all " + (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%_list_all " + (page - 1));
}
else
{
msg.replace("%prev_button%", StringUtils.EMPTY);
}
player.sendPacket(msg);
}
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);
player.sendPacket(SystemMsg.YOU_HAVE_CANCELED_YOUR_BID);
showChatWindow(player, 0);
}
else if (actualCommand.equalsIgnoreCase("register_start"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(player.getClan().getHasHideout());
if ((clanHall.getSiegeEvent().getClass() != ClanHallAuctionEvent.class) || clanHall.getSiegeEvent().isInProgress())
{
return;
}
if ((clanHall.getLastSiegeDate().getTimeInMillis() + WEEK) > System.currentTimeMillis())
{
player.sendPacket(SystemMsg.IT_HAS_NOT_YET_BEEN_SEVEN_DAYS_SINCE_CANCELING_AN_AUCTION);
onBypassFeedback(player, "info");
return;
}
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_clanhall_register_start.htm");
msg.replace("%id%", String.valueOf(player.getClan().getHasHideout()));
msg.replace("%adena%", String.valueOf(player.getClan().getWarehouse().getCountOf(ItemTemplate.ITEM_ID_ADENA)));
msg.replace("%deposit%", String.valueOf(clanHall.getDeposit()));
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("register_next"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(player.getClan().getHasHideout());
if ((clanHall.getSiegeEvent().getClass() != ClanHallAuctionEvent.class) || clanHall.getSiegeEvent().isInProgress())
{
showChatWindow(player, 0);
return;
}
if (player.getClan().getWarehouse().getCountOf(ItemTemplate.ITEM_ID_ADENA) < clanHall.getDeposit())
{
player.sendPacket(SystemMsg.THERE_IS_NOT_ENOUGH_ADENA_IN_THE_CLAN_HALL_WAREHOUSE);
onBypassFeedback(player, "register_start");
return;
}
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_clanhall_register_next.htm");
msg.replace("%min_bid%", String.valueOf(clanHall.getBaseMinBid()));
msg.replace("%last_bid%", String.valueOf(clanHall.getBaseMinBid())); // TODO [VISTALL] get last bid
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("register_next2"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(player.getClan().getHasHideout());
if ((clanHall.getSiegeEvent().getClass() != ClanHallAuctionEvent.class) || clanHall.getSiegeEvent().isInProgress())
{
showChatWindow(player, 0);
return;
}
int day = Integer.parseInt(tokenizer.nextToken());
long bid = -1;
String comment = StringUtils.EMPTY;
if (tokenizer.hasMoreTokens())
{
try
{
bid = Long.parseLong(tokenizer.nextToken());
}
catch (Exception e)
{
}
}
if (tokenizer.hasMoreTokens())
{
comment = tokenizer.nextToken();
while (tokenizer.hasMoreTokens())
{
comment += " " + tokenizer.nextToken();
}
}
comment = comment.substring(0, Math.min(comment.length(), Byte.MAX_VALUE));
if (bid <= -1)
{
onBypassFeedback(player, "register_next");
return;
}
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, day);
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_clanhall_register_confirm.htm");
msg.replace("%description%", comment);
msg.replace("%day%", String.valueOf(day));
msg.replace("%bid%", String.valueOf(bid));
msg.replace("%base_bid%", String.valueOf(clanHall.getBaseMinBid()));
msg.replace("%hour%", String.valueOf(cal.get(Calendar.HOUR_OF_DAY)));
msg.replace("%date%", DATE_FORMAT.format(cal.getTimeInMillis()));
player.sendPacket(msg);
}
else if (actualCommand.equalsIgnoreCase("register_confirm"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(player.getClan().getHasHideout());
if ((clanHall.getSiegeEvent().getClass() != ClanHallAuctionEvent.class) || clanHall.getSiegeEvent().isInProgress())
{
showChatWindow(player, 0);
return;
}
if ((clanHall.getLastSiegeDate().getTimeInMillis() + WEEK) > System.currentTimeMillis())
{
player.sendPacket(SystemMsg.IT_HAS_NOT_YET_BEEN_SEVEN_DAYS_SINCE_CANCELING_AN_AUCTION);
onBypassFeedback(player, "info");
return;
}
int day = Integer.parseInt(tokenizer.nextToken());
long bid = Long.parseLong(tokenizer.nextToken());
String comment = StringUtils.EMPTY;
if (tokenizer.hasMoreTokens())
{
comment = tokenizer.nextToken();
while (tokenizer.hasMoreTokens())
{
comment += " " + tokenizer.nextToken();
}
}
if (bid <= -1)
{
onBypassFeedback(player, "register_next");
return;
}
clanHall.setAuctionMinBid(bid);
clanHall.setAuctionDescription(comment);
clanHall.setAuctionLength(day);
clanHall.getSiegeDate().setTimeInMillis(System.currentTimeMillis());
clanHall.setJdbcState(JdbcEntityState.UPDATED);
clanHall.update();
clanHall.getSiegeEvent().reCalcNextTime(false);
onBypassFeedback(player, "info");
player.sendPacket(SystemMsg.YOU_HAVE_REGISTERED_FOR_A_CLAN_HALL_AUCTION);
}
else if (actualCommand.equals("cancel_start"))
{
if (!firstChecks(player))
{
showChatWindow(player, 0);
return;
}
ClanHall clanHall = ResidenceHolder.getInstance().getResidence(player.getClan().getHasHideout());
if ((clanHall.getSiegeEvent().getClass() != ClanHallAuctionEvent.class) || !clanHall.getSiegeEvent().isInProgress())
{
showChatWindow(player, 0);
return;
}
NpcHtmlMessage msg = new NpcHtmlMessage(player, this);
msg.setFile("residence2/clanhall/auction_clanhall_cancel_confirm.htm");
msg.replace("%deposit%", String.valueOf(clanHall.getDeposit()));
player.sendPacket(msg);
}
else if (actualCommand.equals("cancel_confirm"))
{