if(!val.equals(""))
{
boolean open = Integer.parseInt(val) == 1;
while(st.hasMoreTokens())
{
DoorInstance door = ReflectionUtils.getDoor(Integer.parseInt(st.nextToken()));
if(open)
door.openMe(player, true);
else
door.closeMe(player, true);
}
}
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/" + getTemplate().npcId + "-d.htm");
player.sendPacket(html);
}
else if(actualCommand.equalsIgnoreCase("tax_set")) // tax rates control
{
if(!isHaveRigths(player, Clan.CP_CS_TAXES))
{
player.sendPacket(SystemMsg.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
return;
}
if(!val.equals(""))
{
int maxTax = 15;
int tax = Integer.parseInt(val);
if(tax < 0 || tax > maxTax)
{
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/chamberlain-hightax.htm");
html.replace("%CurrentTax%", String.valueOf(castle.getTaxPercent()));
player.sendPacket(html);
return;
}
castle.setTaxPercent(player, tax);
}
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/chamberlain-settax.htm");
html.replace("%CurrentTax%", String.valueOf(castle.getTaxPercent()));
player.sendPacket(html);
}
else if(actualCommand.equalsIgnoreCase("upgrade_castle"))
{
if(!checkSiegeFunctions(player))
return;
showChatWindow(player, "castle/chamberlain/chamberlain-upgrades.htm");
}
else if(actualCommand.equalsIgnoreCase("reinforce"))
{
if(!checkSiegeFunctions(player))
return;
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/doorStrengthen-" + castle.getName() + ".htm");
player.sendPacket(html);
}
else if(actualCommand.equalsIgnoreCase("trap_select"))
{
if(!checkSiegeFunctions(player))
return;
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/trap_select-" + castle.getName() + ".htm");
player.sendPacket(html);
}
else if(actualCommand.equalsIgnoreCase("buy_trap"))
{
if(!checkSiegeFunctions(player))
return;
if(castle.getSiegeEvent().getObjects(CastleSiegeEvent.BOUGHT_ZONES).contains(val))
{
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/trapAlready.htm");
player.sendPacket(html);
return;
}
List<CastleDamageZoneObject> objects = castle.getSiegeEvent().getObjects(val);
long price = 0;
for(CastleDamageZoneObject o : objects)
price += o.getPrice();
if(player.getClan().getAdenaCount() < price)
{
player.sendPacket(SystemMsg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
return;
}
player.getClan().getWarehouse().destroyItemByItemId(ItemTemplate.ITEM_ID_ADENA, price);
castle.getSiegeEvent().addObject(CastleSiegeEvent.BOUGHT_ZONES, val);
CastleDamageZoneDAO.getInstance().insert(castle, val);
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/trapSuccess.htm");
player.sendPacket(html);
}
else if(actualCommand.equalsIgnoreCase("door_manage"))
{
if(!isHaveRigths(player, Clan.CP_CS_ENTRY_EXIT))
{
player.sendPacket(SystemMsg.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
return;
}
if(castle.getSiegeEvent().isInProgress())
{
showChatWindow(player, "residence2/castle/chamberlain_saius021.htm");
return;
}
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/doorManage.htm");
html.replace("%id%", val);
html.replace("%type%", st.nextToken());
player.sendPacket(html);
}
else if(actualCommand.equalsIgnoreCase("upgrade_door_confirm"))
{
if(!isHaveRigths(player, Clan.CP_CS_MANAGE_SIEGE))
{
player.sendPacket(SystemMsg.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
return;
}
int id = Integer.parseInt(val);
int type = Integer.parseInt(st.nextToken());
int level = Integer.parseInt(st.nextToken());
long price = getDoorCost(type, level);
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/doorConfirm.htm");
html.replace("%id%", String.valueOf(id));
html.replace("%level%", String.valueOf(level));
html.replace("%type%", String.valueOf(type));
html.replace("%price%", String.valueOf(price));
player.sendPacket(html);
}
else if(actualCommand.equalsIgnoreCase("upgrade_door"))
{
if(checkSiegeFunctions(player))
return;
int id = Integer.parseInt(val);
int type = Integer.parseInt(st.nextToken());
int level = Integer.parseInt(st.nextToken());
long price = getDoorCost(type, level);
List<DoorObject> doorObjects = castle.getSiegeEvent().getObjects(SiegeEvent.DOORS);
DoorObject targetDoorObject = null;
for(DoorObject o : doorObjects)
if(o.getUId() == id)
{
targetDoorObject = o;
break;
}
DoorInstance door = targetDoorObject.getDoor();
int upgradeHp = (door.getMaxHp() - door.getUpgradeHp()) * level - door.getMaxHp();
if(price == 0 || upgradeHp < 0)
{
player.sendMessage(new CustomMessage("common.Error", player));
return;
}
if(door.getUpgradeHp() >= upgradeHp)
{
int oldLevel = door.getUpgradeHp() / (door.getMaxHp() - door.getUpgradeHp()) + 1;
NpcHtmlMessage html = new NpcHtmlMessage(player, this);
html.setFile("castle/chamberlain/doorAlready.htm");
html.replace("%level%", String.valueOf(oldLevel));
player.sendPacket(html);
return;
}
if(player.getClan().getAdenaCount() < price)
{
player.sendPacket(SystemMsg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
return;
}
player.getClan().getWarehouse().destroyItemByItemId(ItemTemplate.ITEM_ID_ADENA, price);
targetDoorObject.setUpgradeValue(castle.<SiegeEvent<?, ?>> getSiegeEvent(), upgradeHp);
CastleDoorUpgradeDAO.getInstance().insert(door.getDoorId(), upgradeHp);
}
else if(actualCommand.equalsIgnoreCase("report")) // Report page
{
if(!isHaveRigths(player, Clan.CP_CS_USE_FUNCTIONS))
{