02-20-2010, 06:53 PM
Сборка l2openfree 533
Вопрос о том, как работает ColorNameNPC.java
после того, как я включил его в scripts.cfg я зашел в игру и поставил NPC(ID50023) подхожу к нему он мне пишет:
NPC спаршивает про кол-во дней и про то что необходим определенный итем, но не понятно куда вводить это кол-во дней и какие итемы нужны....
Вот сам ява скрипт:
Вопрос о том, как работает ColorNameNPC.java
после того, как я включил его в scripts.cfg я зашел в игру и поставил NPC(ID50023) подхожу к нему он мне пишет:
NPC спаршивает про кол-во дней и про то что необходим определенный итем, но не понятно куда вводить это кол-во дней и какие итемы нужны....
Вот сам ява скрипт:
Цитата:package custom.ColorNameNPC;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.l2open.L2DatabaseFactory;
import com.l2open.gameserver.datatables.ItemTable;
import com.l2open.gameserver.datatables.PcColorTable;
import com.l2open.gameserver.instancemanager.QuestManager;
import com.l2open.gameserver.model.L2Object;
import com.l2open.gameserver.model.actor.L2Npc;
import com.l2open.gameserver.model.actor.instance.L2PcInstance;
import com.l2open.gameserver.model.quest.Quest;
import com.l2open.gameserver.model.quest.QuestState;
/**
* @author L0ngh0rn
* @since 2009-10-25
*/
public class ColorNameNPC extends Quest
{
private final static int NPC = 50023;
public ColorNameNPC(int questId, String name, String descr)
{
super(questId, name, descr);
addFirstTalkId(NPC);
addStartNpc(NPC);
addTalkId(NPC);
}
@Override
public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
{
String paramEvent[] = event.split(" ");
String action = paramEvent[0];
String value = paramEvent[1];
String htmltext = "";
QuestState st = player.getQuestState(getName());
if (action.equalsIgnoreCase("viewColor"))
htmltext = viewColor(Integer.valueOf(value), st.getPlayer().getName());
else if (action.equalsIgnoreCase("buyColor"))
htmltext = buyColor(value, st);
else if (action.equalsIgnoreCase("page"))
htmltext = page();
return htmltext;
}
@Override
public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
String htmltext = "";
QuestState st = player.getQuestState(getName());
if (st == null)
{
Quest q = QuestManager.getInstance().getQuest(getName());
st = q.newQuestState(player);
}
htmltext = page();
return htmltext;
}
public String page()
{
String htmltext = "";
String dayColor = "SELECT DISTINCT ccl.timeInDays FROM custom_colors_list AS ccl";
htmltext += htmlPage("Title");
htmltext += "Hello I'm here to help you change the color of your name.<br>" + "Select the time in days and choose the color, remember that you must " + "have items for exchange.<br>";
htmltext += "<center>";
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(dayColor);
ResultSet rs = ps.executeQuery();
while (rs.next())
{
htmltext += "<br>";
htmltext += button(rs.getString("timeInDays") + " Days", "viewColor " + rs.getString("timeInDays"), 110, 30);
}
ps.close();
rs.close();
}
catch (Exception e)
{
_log.info("Error while loading data from DB! (page) " + e);
}
finally
{
L2DatabaseFactory.close(con);
}
htmltext += "</center>";
htmltext += htmlPage("Footer");
return htmltext;
}
public String viewColor(int d, String name)
{
String htmltext = "", idItem, value;
String viewList = "SELECT ccl.id, ccl.color, ccl.configPrice FROM custom_colors_list AS ccl " + "WHERE ccl.timeInDays = ? ORDER BY ccl.id ASC";
htmltext += htmlPage("Title");
htmltext += "These are colors for selection of " + d + " days.<br1>" + "Each color has its price, to buy click accept or color desired.<br>" + "Thanks!<br>";
htmltext += "<center>";
htmltext += "<table>";
htmltext += "<tr><td align=\"center\"><img src=\"L2UI.SquareWhite\" width=\"250\" height=\"1\"></td></tr>";
htmltext += "<tr><td>";
htmltext += "<table>";
htmltext += "<tr>";
htmltext += "<td width=\"200\" align=\"center\"> </td>";
htmltext += "<td width=\"50\" align=\"center\"></td>";
htmltext += "</tr>";
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(viewList);
ps.setInt(1, d);
ResultSet rs = ps.executeQuery();
while (rs.next())
{
htmltext += "<tr><td align=\"left\">";
htmltext += "Color - " + link(name, "buyColor " + rs.getString("id"), rs.getString("color")) + "<br1>";
htmltext += "<font color=\"FF9900\">Price:</font><br1>";
String itemList[] = rs.getString("configPrice").split("\\;");
for (int i = 0; i < itemList.length; i++)
{
String item[] = itemList[i].split("\\,");
idItem = item[0];
value = item[1];
htmltext += "$ " + value + " " + ItemTable.getInstance().getTemplate(Integer.parseInt(idItem)).getName() + "<br1>";
}
htmltext += "<br></td>";
htmltext += "<td align=\"center\">";
htmltext += button("Accept", "buyColor " + rs.getString("id"), 50, 30);
htmltext += "</td></tr>";
}
ps.close();
rs.close();
}
catch (Exception e)
{
_log.info("Error while loading data from DB! (viewColor) " + e);
}
finally
{
L2DatabaseFactory.close(con);
}
htmltext += "<tr>";
htmltext += "<td height=\"3\" align=\"center\"> </td>";
htmltext += "<td height=\"3\" align=\"center\"> </td>";
htmltext += "</tr>";
htmltext += "</table>";
htmltext += "</td></tr>";
htmltext += "<tr><td align=\"center\"><img src=\"L2UI.SquareWhite\" width=\"250\" height=\"1\"></td></tr>";
htmltext += "</table><br>";
htmltext += button("Back", "page 0", 50, 30);
htmltext += "</center>";
htmltext += htmlPage("Footer");
return htmltext;
}
public String buyColor(String id, QuestState st)
{
String htmltext = "";
Integer i = 0;
String restoreColor = "SELECT ccl.color, ccl.configPrice, ccl.timeInDays " + "FROM custom_colors_list AS ccl WHERE ccl.id = ?";
htmltext += htmlPage("Title");
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(restoreColor);
ps.setString(1, id);
ResultSet rs = ps.executeQuery();
while (rs.next())
{
String itemList[] = rs.getString("configPrice").split("\\;");
for (i = 0; i < itemList.length; i++)
{
String item[] = itemList[i].split("\\,");
if (st.getQuestItemsCount(Integer.valueOf(item[0])) < Integer.valueOf(item[1]))
{
htmltext += "Ohh you do not have all the necessary items for the purchase of color.<br>";
htmltext += "<br><center>" + button("Back", "page 0", 50, 30) + "</center>";
htmltext += htmlPage("Footer");
return htmltext;
}
}
if (st.getPlayer().getKarma() > 0)
{
htmltext += "You are chaotic, go away please!<br>";
}
else if (st.getPlayer().getPvpFlag() != 0)
{
htmltext += "I cannot add color to name when you are fighting.<br>";
}
else if (st.getPlayer().isAttackingNow() == true)
{
htmltext += "Leave me please!!!<br>";
}
else
{
L2Object target = st.getPlayer();
st.getPlayer().setTarget(st.getPlayer());
for (i = 0; i < itemList.length; i++)
{
String item[] = itemList[i].split("\\,");
st.takeItems(Integer.valueOf(item[0]), Integer.valueOf(item[1]));
}
int color = Integer.decode("0x" + rs.getString("color"));
long time = Long.valueOf(rs.getInt("timeInDays"));
PcColorTable.getInstance().add((L2PcInstance) target, color, System.currentTimeMillis(), (time * 24 * 60 * 60 * 1000));
htmltext += "Okay, I added the color in your name!<br>Come again!<br>";
}
}
ps.close();
rs.close();
}
catch (Exception e)
{
_log.info("Error while loading data from DB! (buyColor) " + e);
}
finally
{
L2DatabaseFactory.close(con);
}
htmltext += "<br><center>" + button("Back", "page 0", 50, 30) + "</center>";
htmltext += htmlPage("Footer");
return htmltext;
}
public String htmlPage(String op)
{
String texto = "";
if (op == "Title")
{
texto += "<html><body><title>Color Manager</title><center><br>" + "<b><font color=ffcc00>Color Manager Information</font></b>" + "<br><img src=\"L2UI_CH3.herotower_deco\" width=\"256\" height=\"32\"><br></center>";
}
else if (op == "Footer")
{
texto += "<br><center><img src=\"L2UI_CH3.herotower_deco\" width=\"256\" height=\"32\"><br>" + "<br><font color=\"303030\">---</font></center></body></html>";
}
else
{
texto = "Not Found!";
}
return texto;
}
public String button(String name, String event, int w, int h)
{
String texto = "";
texto = "<button value=\"" + name + "\" action=\"bypass -h Quest ColorNameNPC " + event + "\" " + "width=\"" + Integer.toString(w) + "\" height=\"" + Integer.toString(h) + "\" " + "back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">";
return texto;
}
public String link(String name, String event, String color)
{
String texto = "";
texto = "<a action=\"bypass -h Quest ColorNameNPC " + event + "\">" + "<font color=\"" + color + "\">" + name + "</font></a>";
return texto;
}
public static void main(String[] args)
{
new ColorNameNPC(-1, "ColorNameNPC", "custom");
}
}