Создание квеста "Тетрадь смерти" с сбором фрагментов
В этом гайде мы создадим квест "Тетрадь смерти", в котором игроку нужно будет собрать несколько фрагментов, выпадающих с мобов в различных зонах, чтобы собрать тетрадь смерти целиком. Квест будет включать в себя:- Начальный NPC.
- Убийство мобов в 10 зонах для получения фрагментов.
- Сбор всех фрагментов.
- Возвращение к NPC для получения награды.
Структура квеста
- Начальный NPC: NPC, который начнет квест.
- Зоны с мобами: 10 зон, где нужно убивать мобов, чтобы получить фрагменты.
- Сбор фрагментов: 10 различных фрагментов, которые нужно собрать.
- Возвращение к NPC: Вернуться к начальному NPC для завершения квеста и получения награды.
Исходный код квеста
Code:
package quests;
import java.util.List;
import l2.gameserver.Config;
import l2.gameserver.model.GameObject;
import l2.gameserver.model.Player;
import l2.gameserver.model.instances.NpcInstance;
import l2.gameserver.model.quest.Quest;
import l2.gameserver.model.quest.QuestState;
import l2.gameserver.network.l2.s2c.SystemMessage;
import l2.gameserver.scripts.ScriptFile;
public class _893_death_note extends Quest implements ScriptFile {
private static final int startNpcId = 45052; // NPC, с которого начинается квест
private static final int[] targetNpcIds = {40085, 40086, 40087, 40088, 40089, 40090, 40091, 40092, 40093, 40094}; // NPC, которых нужно убивать
private static final int[] questItemIds = {9884, 9885, 9886, 9887, 9888, 9889, 9890, 9891, 9892, 9893}; // Фрагменты, которые нужно собрать
private static final int rewardItemId = 9503; // Награда за выполнение квеста
public _893_death_note() {
super(1);
addStartNpc(startNpcId);
addTalkId(startNpcId);
for (int id : targetNpcIds) {
addKillId(id);
}
for (int itemId : questItemIds) {
addQuestItem(itemId);
}
}
public void onLoad() {}
public void onReload() {}
public void onShutdown() {}
public String onEvent(String event, QuestState st, NpcInstance npc) {
String htmltext = event;
if (event.equalsIgnoreCase("startQuest.htm")) {
st.setCond(1);
st.setState(2);
st.playSound("ItemSound.quest_accept");
htmltext = "startedQuest.htm";
}
return htmltext;
}
public String onTalk(NpcInstance npc, QuestState st) {
String htmltext = "noquest";
int npcId = npc.getNpcId();
int cond = st.getCond();
if (npcId == startNpcId) {
if (cond == 0) {
if (st.getPlayer().getLevel() >= 10) {
htmltext = "startQuest.htm";
} else {
st.exitCurrentQuest(true);
return "lowLevel.htm";
}
} else if (cond == 1) {
htmltext = "progressQuest.htm";
} else if (cond == 2) {
boolean allItemsCollected = true;
for (int itemId : questItemIds) {
if (st.getQuestItemsCount(itemId) == 0) {
allItemsCollected = false;
break;
}
}
if (allItemsCollected) {
for (int itemId : questItemIds) {
st.takeItems(itemId, -1);
}
st.giveItems(rewardItemId, 1);
st.playSound("ItemSound.quest_finish");
st.exitCurrentQuest(true);
htmltext = "completedQuest.htm";
} else {
htmltext = "progressQuest.htm";
}
}
}
return htmltext;
}
public String onKill(NpcInstance npc, QuestState st) {
int cond = st.getCond();
int npcId = npc.getNpcId();
if (cond == 1) {
for (int i = 0; i < targetNpcIds.length; i++) {
if (npcId == targetNpcIds[i]) {
if (st.getQuestItemsCount(questItemIds[i]) == 0) {
st.giveItems(questItemIds[i], 1);
st.playSound("ItemSound.quest_middle");
st.setCond(2);
return null;
}
}
}
}
return null;
}
}
Пояснение кода
- Класс _893_death_note наследует Quest и реализует ScriptFile.
- NPC и предметы:
- startNpcId = 45052: NPC, с которого начинается квест.
- targetNpcIds = {40085, 40086, 40087, 40088, 40089, 40090, 40091, 40092, 40093, 40094}: NPC, которых нужно убивать.
- questItemIds = {9884, 9885, 9886, 9887, 9888, 9889, 9890, 9891, 9892, 9893}: Фрагменты, которые нужно собрать.
- rewardItemId = 9503: Награда за выполнение квеста.
- Методы:
- onEvent: Обрабатывает события, такие как начало квеста.
- onTalk: Обрабатывает разговоры с NPC.
- onKill: Обрабатывает убийства NPC и проверяет, выполнены ли условия квеста.
Замена параметров
Если вам нужно изменить параметры для квеста, используйте следующие инструкции:- NPC начала квеста: замените addStartNpc(45052) и if (npcId == startNpcId) на новый ID.
- NPC для убийства: замените addKillId(40085) и if (npcId == targetNpcIds) на новый ID.
[*]ID предметов: замените addQuestItem(9884) и st.takeItems(itemId, -1) на новый ID.
[*]Награда за выполнение: замените st.giveItems(9503, 1) на новый ID.
Страницы квеста
Создайте папку data/html-ru/quests/_893_death_note и добавьте HTML-файлы для отображения текста квеста.- startQuest.htm: Страница при начале квеста.
- startedQuest.htm: Страница после начала квеста.
- progressQuest.htm: Страница при прогрессе квеста.
- completedQuest.htm: Страница при завершении квеста.
- lowLevel.htm: Страница для игроков с низким уровнем.
Code:
<!-- startQuest.htm -->
<html>
<body>
<center>
<font color="LEVEL">Начало квеста</font><br>
<button value="Принять квест" action="bypass -h Quest _893_death_note startQuest.htm" width=100 height=20 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df">
</center>
</body>
</html>
Code:
<!-- startedQuest.htm -->
<html>
<body>
<center>
<font color="LEVEL">Квест начался</font><br>
Идите в первую зону и убейте мобов для получения фрагментов.<br>
</center>
</body>
</html>
Code:
<!-- progressQuest.htm -->
<html>
<body>
<center>
<font color="LEVEL">Прогресс квеста</font><br>
Соберите все фрагменты и вернитесь.<br>
</center>
</body>
</html>
Code:
<!-- completedQuest.htm -->
<html>
<body>
<center>
<font color="LEVEL">Квест завершен</font><br>
Поздравляем! Вы собрали все фрагменты и получили награду.<br>
</center>
</body>
</html>
Code:
<!-- lowLevel.htm -->
<html>
<body>
<center>
<font color="LEVEL">Недостаточный уровень</font><br>
Ваш уровень слишком низкий для выполнения этого квеста.<br>
</center>
</body>
</html>
Пример предметов в data/items
Добавьте следующие элементы в файл data/items:
Code:
<etcitem id="9884" name="Death Note Fragment 1">
<set name="price" value="0"/>
<set name="class" value="OTHER"/>
<set name="crystal_type" value="NONE"/>
<set name="destroyable" value="false"/>
<set name="icon" value="icon.etc_scroll_of_escape_i00"/>
<set name="stackable" value="true"/>
<set name="tradeable" value="true"/>
<set name="dropable" value="true"/>
<set name="type" value="QUEST"/>
</etcitem>
<etcitem id="9885" name="Death Note Fragment 2">
<!-- аналогичные настройки для других фрагментов -->
</etcitem>
...
<etcitem id="9893" name="Death Note Fragment 10">
<!-- аналогичные настройки для других фрагментов -->
</etcitem>
Строки в questname-e.dat
Добавьте следующие строки в файл questname-e.dat:
Code:
1 893 1 a,Quest Death Note\0 a,Collect Death Note Fragments\0 a,Light Yagami asked you to collect 10 Death Note Fragments. Go to the target locations and kill NPCs until you get the items.\\n\0 1 9884 1 1 174175.00000000 -88742.00000000 -5138.00000000 10 80 2 a,Death Note Zone\0 1 1 1 45052 82779.00000000 149417.00000000 -3494.00000000 a,No Requirements\0 a,Yagami Light will reward those who bring him the Death Note Fragments.\0 0 0 0 0 0 67
1 893 2 a,Quest Death Note\0 a,Return to Yagami Light\0 a,You have collected all Death Note Fragments. Go to Yagami Light - Giran.\\n\0 0 0 82779.00000000 149417.00000000 -3494.00000000 10 80 2 a,Light Yagami\0 0 1 1 45052 82779.00000000 149417.00000000 -3494.00000000 a,No Requirements\0 a,Light Yagami asked you to collect 10 Death Note Fragments, for which you will receive a special reward. Kill the target NPCs to get the items.\0 0 0 0 0 0 67