package net.sf.l2j.gameserver.model.actor.instance;
import javolution.text.TextBuilder;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.network.L2GameClient;
import net.sf.l2j.gameserver.serverpackets.ActionFailed;
import net.sf.l2j.gameserver.serverpackets.MyTargetSelected;
import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.serverpackets.InventoryUpdate;
import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
import net.sf.l2j.gameserver.serverpackets.UserInfo;
import net.sf.l2j.gameserver.templates.L2NpcTemplate;
public class L2RecomInstance extends L2FolkInstance
{
public L2RecomInstance(int objectId, L2NpcTemplate template)
{
super(objectId, template);
}
@Override public String getHtmlPath(int npcId, int val)
{
String pom = "";
if (val == 0) pom = "" + npcId;
else pom = npcId + "-" + val;
return "data/html/Recom/" + pom + ".htm";
}
private void Recommend(L2PcInstance player)
{
player.setRecomHave(player.getRecomHave() + 20);
player.broadcastUserInfo();
InventoryUpdate iu = new InventoryUpdate();
player.getInventory().destroyItemByItemId("Coin", 4037, 1, player, null);
player.getInventory().updateDatabase();
player.sendPacket(iu);
}
@Override public void onBypassFeedback(L2PcInstance player, String command)
{
int Coin = 1;
if (command.startsWith("Rec"))
{
if (player.getInventory().getInventoryItemCount(4037, 0) >= Coin)
{
Recommend(player);
}
}
else
{
// this class dont know any other commands, let forward
// the command to the parent class
super.onBypassFeedback(player, command);
}
}
@Override public void onActionShift(L2GameClient client)
{
L2PcInstance player = client.getActiveChar();
if (player == null) return;
if (player.getAccessLevel() >= Config.GM_ACCESSLEVEL)
{
player.setTarget(this);
MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
player.sendPacket(my);
if (isAutoAttackable(player))
{
StatusUpdate su = new StatusUpdate(getObjectId());
su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
player.sendPacket(su);
}
NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
TextBuilder html1 = new TextBuilder("<html><body><table border=0>");
html1.append("<tr><td>Current Target:</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td>Object ID: " + getObjectId() + "</td></tr>");
html1.append("<tr><td>Template ID: " + getTemplate().npcId + "</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td>HP: " + getCurrentHp() + "</td></tr>");
html1.append("<tr><td>MP: " + getCurrentMp() + "</td></tr>");
html1.append("<tr><td>Level: " + getLevel() + "</td></tr>");
html1.append("<tr><td><br></td></tr>");
html1.append("<tr><td>Class: " + getClass().getName() + "</td></tr>");
html1.append("<tr><td><br></td></tr>");
//changed by terry 2005-02-22 21:45
html1.append("</table><table><tr><td><button value=\"Edit NPC\" action=\"bypass -h admin_edit_npc "
+ getTemplate().npcId
+ "\" width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>");
html1.append("<td><button value=\"Kill\" action=\"bypass -h admin_kill\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
html1.append("<tr><td><button value=\"Show DropList\" action=\"bypass -h admin_show_droplist "
+ getTemplate().npcId
+ "\" width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
html1.append("<td><button value=\"Delete\" action=\"bypass -h admin_delete\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
html1.append("</table>");
if (player.isGM())
{
html1.append("<button value=\"View Shop\" action=\"bypass -h admin_showShop "
+ getTemplate().npcId
+ "\" width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></br>");
html1.append("<button value=\"Lease next week\" action=\"bypass -h npc_" + getObjectId()
+ "_Lease\" width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
html1.append("<button value=\"Abort current leasing\" action=\"bypass -h npc_"
+ getObjectId()
+ "_Lease next\" width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
html1.append("<button value=\"Manage items\" action=\"bypass -h npc_" + getObjectId()
+ "_Lease manage\" width=100 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
}
html1.append("</body></html>");
html.setHtml(html1.toString());
player.sendPacket(html);
}
player.sendPacket(new ActionFailed());
}
@Override public boolean isMovementDisabled()
{
return true;
}
}