|
@@ -23,18 +23,22 @@ import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.logging.Level;
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
import com.l2jserver.Config;
|
|
|
import com.l2jserver.L2DatabaseFactory;
|
|
|
import com.l2jserver.gameserver.cache.HtmCache;
|
|
|
+import com.l2jserver.gameserver.enums.CategoryType;
|
|
|
+import com.l2jserver.gameserver.enums.Race;
|
|
|
import com.l2jserver.gameserver.enums.TrapAction;
|
|
|
import com.l2jserver.gameserver.instancemanager.QuestManager;
|
|
|
import com.l2jserver.gameserver.model.L2Object;
|
|
@@ -46,6 +50,7 @@ import com.l2jserver.gameserver.model.actor.L2Summon;
|
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
|
import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
|
|
|
import com.l2jserver.gameserver.model.base.AcquireSkillType;
|
|
|
+import com.l2jserver.gameserver.model.base.ClassId;
|
|
|
import com.l2jserver.gameserver.model.events.AbstractScript;
|
|
|
import com.l2jserver.gameserver.model.events.EventType;
|
|
|
import com.l2jserver.gameserver.model.events.listeners.AbstractEventListener;
|
|
@@ -77,6 +82,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
private final ReentrantReadWriteLock _rwLock = new ReentrantReadWriteLock();
|
|
|
private final WriteLock _writeLock = _rwLock.writeLock();
|
|
|
private final ReadLock _readLock = _rwLock.readLock();
|
|
|
+ private final Map<Predicate<L2PcInstance>, String> _startCondition = new LinkedHashMap<>();
|
|
|
|
|
|
private final int _questId;
|
|
|
private final String _name;
|
|
@@ -407,6 +413,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(qs.getPlayer(), e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(qs.getPlayer(), res);
|
|
|
}
|
|
@@ -425,6 +432,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(player, res);
|
|
|
}
|
|
@@ -444,6 +452,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(player, res);
|
|
|
}
|
|
@@ -510,9 +519,8 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
* @param event
|
|
|
* @param npc
|
|
|
* @param player
|
|
|
- * @return {@code false} if there was an error or the message was sent, {@code true} otherwise
|
|
|
*/
|
|
|
- public final boolean notifyEvent(String event, L2Npc npc, L2PcInstance player)
|
|
|
+ public final void notifyEvent(String event, L2Npc npc, L2PcInstance player)
|
|
|
{
|
|
|
String res = null;
|
|
|
try
|
|
@@ -521,9 +529,10 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- return showError(player, e);
|
|
|
+ showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
- return showResult(player, res, npc);
|
|
|
+ showResult(player, res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -539,6 +548,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(player, res);
|
|
|
}
|
|
@@ -558,28 +568,37 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(killer, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(killer, res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param npc
|
|
|
- * @param activeChar
|
|
|
- * @return {@code false} if there was an error or the message was sent, {@code true} otherwise
|
|
|
+ * @param player
|
|
|
*/
|
|
|
- public final boolean notifyTalk(L2Npc npc, L2PcInstance activeChar)
|
|
|
+ public final void notifyTalk(L2Npc npc, L2PcInstance player)
|
|
|
{
|
|
|
String res = null;
|
|
|
try
|
|
|
{
|
|
|
- res = onTalk(npc, activeChar);
|
|
|
+ final String startConditionHtml = getStartConditionHtml(player);
|
|
|
+ if (!player.hasQuestState(_name) && (startConditionHtml != null))
|
|
|
+ {
|
|
|
+ res = startConditionHtml;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ res = onTalk(npc, player);
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- return showError(activeChar, e);
|
|
|
+ showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
- activeChar.setLastQuestNpcObject(npc.getObjectId());
|
|
|
- return showResult(activeChar, res, npc);
|
|
|
+ player.setLastQuestNpcObject(npc.getObjectId());
|
|
|
+ showResult(player, res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -598,6 +617,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(player, res, npc);
|
|
|
}
|
|
@@ -619,6 +639,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(player, res);
|
|
|
}
|
|
@@ -626,31 +647,20 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
/**
|
|
|
* @param item
|
|
|
* @param player
|
|
|
- * @return
|
|
|
*/
|
|
|
- public final boolean notifyItemTalk(L2ItemInstance item, L2PcInstance player)
|
|
|
+ public final void notifyItemTalk(L2ItemInstance item, L2PcInstance player)
|
|
|
{
|
|
|
String res = null;
|
|
|
try
|
|
|
{
|
|
|
res = onItemTalk(item, player);
|
|
|
- if (res != null)
|
|
|
- {
|
|
|
- if (res.equalsIgnoreCase("true"))
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- else if (res.equalsIgnoreCase("false"))
|
|
|
- {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- return showError(player, e);
|
|
|
+ showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
- return showResult(player, res);
|
|
|
+ showResult(player, res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -667,9 +677,8 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
* @param item
|
|
|
* @param player
|
|
|
* @param event
|
|
|
- * @return
|
|
|
*/
|
|
|
- public final boolean notifyItemEvent(L2ItemInstance item, L2PcInstance player, String event)
|
|
|
+ public final void notifyItemEvent(L2ItemInstance item, L2PcInstance player, String event)
|
|
|
{
|
|
|
String res = null;
|
|
|
try
|
|
@@ -677,21 +686,18 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
res = onItemEvent(item, player, event);
|
|
|
if (res != null)
|
|
|
{
|
|
|
- if (res.equalsIgnoreCase("true"))
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- else if (res.equalsIgnoreCase("false"))
|
|
|
+ if (res.equalsIgnoreCase("true") || res.equalsIgnoreCase("false"))
|
|
|
{
|
|
|
- return false;
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- return showError(player, e);
|
|
|
+ showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
- return showResult(player, res);
|
|
|
+ showResult(player, res);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -711,6 +717,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(caster, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(caster, res);
|
|
|
}
|
|
@@ -731,6 +738,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(attacker, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(attacker, res);
|
|
|
}
|
|
@@ -750,6 +758,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
showError(player, e);
|
|
|
+ return;
|
|
|
}
|
|
|
showResult(player, res);
|
|
|
}
|
|
@@ -777,6 +786,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
{
|
|
|
showError(player, e);
|
|
|
}
|
|
|
+ return;
|
|
|
}
|
|
|
if (player != null)
|
|
|
{
|
|
@@ -820,6 +830,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
{
|
|
|
showError(player, e);
|
|
|
}
|
|
|
+ return;
|
|
|
}
|
|
|
if (player != null)
|
|
|
{
|
|
@@ -845,6 +856,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
{
|
|
|
showError(player, e);
|
|
|
}
|
|
|
+ return;
|
|
|
}
|
|
|
if (player != null)
|
|
|
{
|
|
@@ -2768,4 +2780,89 @@ public class Quest extends AbstractScript implements IIdentifiable
|
|
|
{
|
|
|
return _isCustom;
|
|
|
}
|
|
|
+
|
|
|
+ public boolean canStartQuest(L2PcInstance player)
|
|
|
+ {
|
|
|
+ for (Predicate<L2PcInstance> cond : _startCondition.keySet())
|
|
|
+ {
|
|
|
+ if (!cond.test(player))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getStartConditionHtml(L2PcInstance player)
|
|
|
+ {
|
|
|
+ for (Map.Entry<Predicate<L2PcInstance>, String> startRequirement : _startCondition.entrySet())
|
|
|
+ {
|
|
|
+ if (!startRequirement.getKey().test(player))
|
|
|
+ {
|
|
|
+ return startRequirement.getValue();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addStartCondition(Predicate<L2PcInstance> questStartRequirement, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(questStartRequirement, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addLevelCondition(int minLevel, int maxLevel, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> (p.getLevel() >= minLevel) && (p.getLevel() <= maxLevel), html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addMinLevelCondition(int minLevel, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.getLevel() >= minLevel, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addMaxLevelCondition(int maxLevel, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.getLevel() <= maxLevel, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addRaceCondition(Race race, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.getRace() == race, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addNotRaceCondition(Race race, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.getRace() != race, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addCompletedQuestCondition(String name, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.hasQuestState(name) && p.getQuestState(name).isCompleted(), html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addClassIdCondition(ClassId classId, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.getClassId() == classId, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addNotClassIdCondition(ClassId classId, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.getClassId() != classId, html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addIsSubClassActiveCondition(String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.isSubClassActive(), html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addIsNotSubClassActiveCondition(String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> !p.isSubClassActive(), html);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addInCategoryCondition(CategoryType categoryType, String html)
|
|
|
+ {
|
|
|
+ _startCondition.put(p -> p.isInCategory(categoryType), html);
|
|
|
+ }
|
|
|
}
|