Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
ColorNameNPC.java
#1
Сборка l2openfree 533

Вопрос о том, как работает ColorNameNPC.java

после того, как я включил его в scripts.cfg я зашел в игру и поставил NPC(ID50023) подхожу к нему он мне пишет:
[Изображение: 1234.png]

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");
}
}
Ответ
#2
Как работает данный НПС я так и не понял, объясните кто знает.
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  Lineage2 java Chronicle3 сборка AlexBayev 0 275 07-20-2024, 05:23 PM
Последний пост: AlexBayev
  Порекомендуйте хорошую Java сборку L2 GF (PTS не потяну ибо навыков 0 ) Force 0 842 10-28-2023, 12:02 PM
Последний пост: Force
  Java dev hired! Krasib 0 1,103 08-15-2022, 10:00 AM
Последний пост: Krasib
  SVN ссылки Java серверов. PROGRAMMATOR 284 234,120 11-19-2020, 08:50 PM
Последний пост: AbsolutePower
  Java координаты, различия PTS и Java, какие сборки хороши (iL) varted 5 2,481 09-12-2018, 08:29 AM
Последний пост: varted
  l2 c4 java estorq 0 1,316 08-17-2018, 10:07 PM
Последний пост: estorq
  Топовая Java сборка под х3 и х1200 NovaPlanet 32 8,356 11-22-2016, 11:38 AM
Последний пост: 6bit
  Java в Class virusoflove 1 1,738 10-17-2016, 09:04 AM
Последний пост: Rolfer
  Помогите поставить Java сервер la2 c3! Winst 0 1,180 10-16-2016, 12:34 PM
Последний пост: Winst
  Ищу стабильную сборка java сервера HF introzorn 12 6,160 10-14-2016, 09:34 PM
Последний пост: Mangol

Перейти к форуму:


Пользователи, просматривающие эту тему: 2 Гость(ей)