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;
|
||||
@@ -86,9 +85,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;
|
||||
@@ -262,7 +261,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;
|
||||
}
|
||||
@@ -278,9 +277,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)
|
||||
{
|
||||
@@ -303,7 +307,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;
|
||||
@@ -331,7 +335,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;
|
||||
@@ -361,7 +365,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;
|
||||
@@ -389,7 +393,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);
|
||||
@@ -2765,7 +2769,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)
|
||||
{
|
||||
@@ -2845,16 +2849,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;
|
||||
}
|
||||
|
||||
@@ -2865,11 +2859,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))
|
||||
@@ -2889,7 +2878,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;
|
||||
}
|
||||
@@ -2901,6 +2890,7 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
return cond.getHtml(npc);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user