Use Set for quest timers and initialize conditions.
This commit is contained in:
@@ -28,7 +28,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -88,9 +87,9 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
public static final Logger LOGGER = Logger.getLogger(Quest.class.getName());
|
||||
|
||||
/** Map containing lists of timers from the name of the timer. */
|
||||
private final Map<String, List<QuestTimer>> _questTimers = new HashMap<>();
|
||||
private final Map<String, Set<QuestTimer>> _questTimers = new HashMap<>();
|
||||
/** Map containing all the start conditions. */
|
||||
private Set<QuestCondition> _startCondition = null;
|
||||
private final Set<QuestCondition> _startCondition = ConcurrentHashMap.newKeySet(1);
|
||||
|
||||
private final int _questId;
|
||||
private final byte _initialState = State.CREATED;
|
||||
@@ -264,7 +263,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
* Gets the quest timers.
|
||||
* @return the quest timers
|
||||
*/
|
||||
public Map<String, List<QuestTimer>> getQuestTimers()
|
||||
public Map<String, Set<QuestTimer>> getQuestTimers()
|
||||
{
|
||||
return _questTimers;
|
||||
}
|
||||
@@ -280,9 +279,14 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
*/
|
||||
public void startQuestTimer(String name, long time, Npc npc, PlayerInstance player, boolean repeating)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (_questTimers)
|
||||
{
|
||||
final List<QuestTimer> timers = _questTimers.computeIfAbsent(name, k -> new CopyOnWriteArrayList<>());
|
||||
final Set<QuestTimer> timers = _questTimers.getOrDefault(name, ConcurrentHashMap.newKeySet(1));
|
||||
// If there exists a timer with this name, allow the timer only if the [npc, player] set is unique nulls act as wildcards.
|
||||
if (getQuestTimer(name, npc, player) == null)
|
||||
{
|
||||
@@ -305,7 +309,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<QuestTimer> timers = _questTimers.get(name);
|
||||
final Set<QuestTimer> timers = _questTimers.get(name);
|
||||
if ((timers == null) || timers.isEmpty())
|
||||
{
|
||||
return null;
|
||||
@@ -333,7 +337,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
return;
|
||||
}
|
||||
|
||||
final List<QuestTimer> timers = _questTimers.get(name);
|
||||
final Set<QuestTimer> timers = _questTimers.get(name);
|
||||
if ((timers == null) || timers.isEmpty())
|
||||
{
|
||||
return;
|
||||
@@ -363,7 +367,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
return;
|
||||
}
|
||||
|
||||
final List<QuestTimer> timers = _questTimers.get(name);
|
||||
final Set<QuestTimer> timers = _questTimers.get(name);
|
||||
if ((timers == null) || timers.isEmpty())
|
||||
{
|
||||
return;
|
||||
@@ -391,7 +395,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
return;
|
||||
}
|
||||
|
||||
final List<QuestTimer> timers = _questTimers.get(timer.toString());
|
||||
final Set<QuestTimer> timers = _questTimers.get(timer.toString());
|
||||
if (timers != null)
|
||||
{
|
||||
timers.remove(timer);
|
||||
@@ -2811,7 +2815,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
|
||||
// Cancel all pending timers before reloading.
|
||||
// If timers ought to be restarted, the quest can take care of it with its code (example: save global data indicating what timer must be restarted).
|
||||
for (List<QuestTimer> timers : _questTimers.values())
|
||||
for (Set<QuestTimer> timers : _questTimers.values())
|
||||
{
|
||||
for (QuestTimer timer : timers)
|
||||
{
|
||||
@@ -2891,16 +2895,6 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
*/
|
||||
private Set<QuestCondition> getStartConditions()
|
||||
{
|
||||
if (_startCondition == null)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (_startCondition == null)
|
||||
{
|
||||
_startCondition = ConcurrentHashMap.newKeySet(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _startCondition;
|
||||
}
|
||||
|
||||
@@ -2911,11 +2905,6 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
*/
|
||||
public boolean canStartQuest(PlayerInstance player)
|
||||
{
|
||||
if (_startCondition == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (QuestCondition cond : _startCondition)
|
||||
{
|
||||
if (!cond.test(player))
|
||||
@@ -2935,7 +2924,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
public String getStartConditionHtml(PlayerInstance player, Npc npc)
|
||||
{
|
||||
final QuestState qs = getQuestState(player, false);
|
||||
if ((_startCondition == null) || ((qs != null) && !qs.isCreated()))
|
||||
if ((qs != null) && !qs.isCreated())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -2947,6 +2936,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
return cond.getHtml(npc);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user