package silentium.gameserver.model.actor.instance;
import silentium.gameserver.data.html.StaticHtmPath;
import silentium.gameserver.instancemanager.CastleManorManager;
import silentium.gameserver.network.serverpackets.NpcHtmlMessage;
import silentium.gameserver.templates.chars.L2NpcTemplate;
/**
* @author l3x
*/
public class L2CastleBlacksmithInstance extends L2NpcInstance
{
protected static final int COND_ALL_FALSE = 0;
protected static final int COND_BUSY_BECAUSE_OF_SIEGE = 1;
protected static final int COND_OWNER = 2;
public L2CastleBlacksmithInstance(int objectId, L2NpcTemplate template)
{
super(objectId, template);
}
@Override
public void onBypassFeedback(L2PcInstance player, String command)
{
if (CastleManorManager.getInstance().isDisabled())
{
NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
html.setFile(StaticHtmPath.NpcHtmPath + "npcdefault.htm", player);
html.replace("%objectId%", String.valueOf(getObjectId()));
html.replace("%npcname%", getName());
player.sendPacket(html);
return;
}
int condition = validateCondition(player);
if (condition <= COND_ALL_FALSE)
return;
if (condition == COND_BUSY_BECAUSE_OF_SIEGE)
return;
else if (condition == COND_OWNER)
{
if (command.startsWith("Chat"))
{
int val = 0;
try
{
val = Integer.parseInt(command.substring(5));
}
catch (IndexOutOfBoundsException ioobe)
{
}
catch (NumberFormatException nfe)
{
}
showChatWindow(player, val);
}
else
{
super.onBypassFeedback(player, command);
}
}
}
@Override
public void showChatWindow(L2PcInstance player, int val)
{
String filename = StaticHtmPath.CastleBlacksmithHtmPath + "castleblacksmith-no.htm";
int condition = validateCondition(player);
if (condition > COND_ALL_FALSE)
{
if (condition == COND_BUSY_BECAUSE_OF_SIEGE)
filename = StaticHtmPath.CastleBlacksmithHtmPath + "castleblacksmith-busy.htm"; // Busy because of siege
else if (condition == COND_OWNER) // Clan owns castle
{
if (val == 0)
filename = StaticHtmPath.CastleBlacksmithHtmPath + "castleblacksmith.htm";
else
filename = StaticHtmPath.CastleBlacksmithHtmPath + "castleblacksmith-" + val + ".htm";
}
}
NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
html.setFile(filename, player);
html.replace("%objectId%", String.valueOf(getObjectId()));
html.replace("%npcname%", getName());
html.replace("%castleid%", Integer.toString(getCastle().getCastleId()));
player.sendPacket(html);
}
protected int validateCondition(L2PcInstance player)
{
if (getCastle() != null && getCastle().getCastleId() > 0)
{
if (player.getClan() != null)
{
if (getCastle().getSiege().getIsInProgress())
return COND_BUSY_BECAUSE_OF_SIEGE;
else if (getCastle().getOwnerId() == player.getClanId() && player.isClanLeader())
return COND_OWNER;
}
}
return COND_ALL_FALSE;
}
}