Quest condition is now cached in a separate QuestState variable.
This commit is contained in:
@@ -567,7 +567,7 @@ public class HallOfErosionAttack extends AbstractNpcAI
|
||||
if (plr != null)
|
||||
{
|
||||
final QuestState qs = plr.getQuestState(Q00696_ConquerTheHallOfErosion.class.getSimpleName());
|
||||
if ((qs != null) && (qs.getInt("cond") == 1))
|
||||
if ((qs != null) && qs.isCond(1))
|
||||
{
|
||||
qs.set("cohemenes", "1");
|
||||
}
|
||||
|
@@ -620,7 +620,7 @@ public class HallOfErosionDefence extends AbstractNpcAI
|
||||
if (player != null)
|
||||
{
|
||||
final QuestState qs = player.getQuestState(Q00697_DefendTheHallOfErosion.class.getSimpleName());
|
||||
if ((qs != null) && (qs.getInt("cond") == 1))
|
||||
if ((qs != null) && qs.isCond(1))
|
||||
{
|
||||
qs.set("defenceDone", 1);
|
||||
}
|
||||
|
@@ -674,7 +674,7 @@ public class HeartInfinityDefence extends AbstractNpcAI
|
||||
for (PlayerInstance player : _world.getAllowed())
|
||||
{
|
||||
final QuestState qs = player.getQuestState(Q00697_DefendTheHallOfErosion.class.getSimpleName());
|
||||
if ((qs != null) && (qs.getInt("cond") == 1))
|
||||
if ((qs != null) && qs.isCond(1))
|
||||
{
|
||||
qs.set("defenceDone", 1);
|
||||
}
|
||||
|
@@ -334,7 +334,7 @@ public class AdminShowQuests implements IAdminCommandHandler
|
||||
{
|
||||
qs = QuestManager.getInstance().getQuest(Integer.parseInt(val[0])).newQuestState(target);
|
||||
qs.setState(State.STARTED);
|
||||
qs.set("cond", "1");
|
||||
qs.setCond(1);
|
||||
target.sendPacket(new QuestList(target));
|
||||
target.sendPacket(new ExShowQuestMark(qs.getQuest().getId()));
|
||||
val[0] = qs.getQuest().getName();
|
||||
|
@@ -111,7 +111,7 @@ public class Q00012_SecretMeetingWithVarkaSilenos extends Quest
|
||||
}
|
||||
case State.STARTED:
|
||||
{
|
||||
final int cond = qs.getInt("cond");
|
||||
final int cond = qs.getCond();
|
||||
if ((npcId == CADMON) && (cond == 1))
|
||||
{
|
||||
htmltext = "31296-04.html";
|
||||
|
@@ -104,7 +104,7 @@ public class Q00182_NewRecruits extends Quest
|
||||
}
|
||||
case State.STARTED:
|
||||
{
|
||||
if (qs.getInt("cond") == 1)
|
||||
if (qs.isCond(1))
|
||||
{
|
||||
htmltext = "32138-04.html";
|
||||
}
|
||||
|
@@ -219,7 +219,7 @@ public class Q00311_ExpulsionOfEvilSpirits extends Quest
|
||||
final PlayerInstance member = qs.getPlayer();
|
||||
if (npc.getId() == VARANGKA)
|
||||
{
|
||||
if ((qs.getInt("cond") != 1))
|
||||
if (!qs.isCond(1))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@@ -219,10 +219,6 @@ public class Q00350_EnhanceYourWeapon extends Quest
|
||||
final QuestState qs = getQuestState(player, true);
|
||||
String htmltext = getNoQuestMsg(player);
|
||||
if (qs.getState() == State.CREATED)
|
||||
{
|
||||
qs.set("cond", "0");
|
||||
}
|
||||
if (qs.getInt("cond") == 0)
|
||||
{
|
||||
htmltext = npc.getId() + "-01.htm";
|
||||
}
|
||||
|
@@ -209,7 +209,7 @@ public class Q00511_AwlUnderFoot extends Quest
|
||||
for (PlayerInstance partyMember : party.getMembers())
|
||||
{
|
||||
final QuestState qs = getQuestState(partyMember, false);
|
||||
if ((qs == null) || (qs.getInt("cond") < 1))
|
||||
if ((qs == null) || (qs.getCond() < 1))
|
||||
{
|
||||
return getHtm(player, "FortressWarden-05.htm").replace("%player%", partyMember.getName());
|
||||
}
|
||||
@@ -418,15 +418,7 @@ public class Q00511_AwlUnderFoot extends Quest
|
||||
else if (qs != null)
|
||||
{
|
||||
final int npcId = npc.getId();
|
||||
int cond = 0;
|
||||
if (qs.getState() == State.CREATED)
|
||||
{
|
||||
qs.set("cond", "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
cond = qs.getInt("cond");
|
||||
}
|
||||
final int cond = qs.getCond();
|
||||
if (_fortDungeons.containsKey(npcId) && (cond == 0))
|
||||
{
|
||||
if (player.getLevel() >= 60)
|
||||
|
@@ -57,9 +57,7 @@ public class Q00694_BreakThroughTheHallOfSuffering extends Quest
|
||||
|
||||
if (event.equals("32603-02.html"))
|
||||
{
|
||||
qs.set("cond", "1");
|
||||
qs.setState(State.STARTED);
|
||||
playSound(player, "ItemSound.quest_accept");
|
||||
qs.startQuest();
|
||||
}
|
||||
return htmltext;
|
||||
}
|
||||
|
@@ -57,9 +57,7 @@ public class Q00695_DefendTheHallOfSuffering extends Quest
|
||||
|
||||
if (event.equals("32603-02.html"))
|
||||
{
|
||||
qs.set("cond", "1");
|
||||
qs.setState(State.STARTED);
|
||||
playSound(player, "ItemSound.quest_accept");
|
||||
qs.startQuest();
|
||||
}
|
||||
return htmltext;
|
||||
}
|
||||
|
@@ -244,7 +244,7 @@ public final class Q00708_PathToBecomingALordGludio extends Quest
|
||||
}
|
||||
else if (qs.isCond(4))
|
||||
{
|
||||
qs.set("cond", "5");
|
||||
qs.setCond(5);
|
||||
htmltext = "35100-09.html";
|
||||
}
|
||||
else if (qs.isCond(5))
|
||||
|
@@ -125,13 +125,13 @@ public final class Q00709_PathToBecomingALordDion extends Quest
|
||||
}
|
||||
case "30735-02.html":
|
||||
{
|
||||
qs.set("cond", "6");
|
||||
qs.setCond(6);
|
||||
break;
|
||||
}
|
||||
case "30735-05.html":
|
||||
{
|
||||
takeItems(player, BLOODY_AXE_BLACK_EPAULETTE, 1);
|
||||
qs.set("cond", "8");
|
||||
qs.setCond(8);
|
||||
break;
|
||||
}
|
||||
case "31418-05.html":
|
||||
@@ -232,7 +232,7 @@ public final class Q00709_PathToBecomingALordDion extends Quest
|
||||
}
|
||||
else if (qs.isCond(1))
|
||||
{
|
||||
qs.set("cond", "2");
|
||||
qs.setCond(2);
|
||||
htmltext = "35142-04.html";
|
||||
}
|
||||
else if (qs.isCond(2) || qs.isCond(3))
|
||||
@@ -241,7 +241,7 @@ public final class Q00709_PathToBecomingALordDion extends Quest
|
||||
}
|
||||
else if (qs.isCond(4))
|
||||
{
|
||||
qs.set("cond", "5");
|
||||
qs.setCond(5);
|
||||
htmltext = "35142-07.html";
|
||||
}
|
||||
else if (qs.isCond(5))
|
||||
|
@@ -45,6 +45,12 @@ public class QuestState
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(QuestState.class.getName());
|
||||
|
||||
// Constants
|
||||
private static final String COND_VAR = "cond";
|
||||
private static final String RESTART_VAR = "restartTime";
|
||||
private static final String MEMO_VAR = "memoState";
|
||||
private static final String MEMO_EX_VAR = "memoStateEx";
|
||||
|
||||
/** The name of the quest of this QuestState */
|
||||
private final String _questName;
|
||||
|
||||
@@ -54,6 +60,9 @@ public class QuestState
|
||||
/** The current state of the quest */
|
||||
private byte _state;
|
||||
|
||||
/** The current condition of the quest */
|
||||
private int _cond = 0;
|
||||
|
||||
/** A map of key->value pairs containing the quest state variables and their values */
|
||||
private Map<String, String> _vars;
|
||||
|
||||
@@ -158,6 +167,7 @@ public class QuestState
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean newQuest = isCreated();
|
||||
_state = state;
|
||||
if (saveInDb)
|
||||
@@ -177,28 +187,39 @@ public class QuestState
|
||||
|
||||
/**
|
||||
* Add parameter used in quests.
|
||||
* @param var String pointing out the name of the variable for quest
|
||||
* @param val String pointing out the value of the variable for quest
|
||||
* @param variable String pointing out the name of the variable for quest
|
||||
* @param value String pointing out the value of the variable for quest
|
||||
*/
|
||||
public void setInternal(String var, String val)
|
||||
public void setInternal(String variable, String value)
|
||||
{
|
||||
if (_vars == null)
|
||||
{
|
||||
_vars = new HashMap<>();
|
||||
}
|
||||
|
||||
String value = val;
|
||||
if (value == null)
|
||||
{
|
||||
value = "";
|
||||
_vars.put(variable, "");
|
||||
return;
|
||||
}
|
||||
|
||||
_vars.put(var, value);
|
||||
if (COND_VAR.equals(variable))
|
||||
{
|
||||
try
|
||||
{
|
||||
_cond = Integer.parseInt(value);
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
_vars.put(variable, value);
|
||||
}
|
||||
|
||||
public void set(String var, int value)
|
||||
public void set(String variable, int value)
|
||||
{
|
||||
set(var, Integer.toString(value));
|
||||
set(variable, Integer.toString(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,33 +233,33 @@ public class QuestState
|
||||
* The key is known as existing if the preceding value of the key (given as result of function put()) is not null.<br>
|
||||
* If the key doesn't exist, the couple is added/created in the database</li>
|
||||
* <ul>
|
||||
* @param var String indicating the name of the variable for quest
|
||||
* @param val String indicating the value of the variable for quest
|
||||
* @param variable String indicating the name of the variable for quest
|
||||
* @param value String indicating the value of the variable for quest
|
||||
*/
|
||||
public void set(String var, String val)
|
||||
public void set(String variable, String value)
|
||||
{
|
||||
if (_vars == null)
|
||||
{
|
||||
_vars = new HashMap<>();
|
||||
}
|
||||
|
||||
String value = val;
|
||||
if (value == null)
|
||||
String newValue = value;
|
||||
if (newValue == null)
|
||||
{
|
||||
value = "";
|
||||
newValue = "";
|
||||
}
|
||||
|
||||
final String old = _vars.put(var, value);
|
||||
final String old = _vars.put(variable, newValue);
|
||||
if (old != null)
|
||||
{
|
||||
Quest.updateQuestVarInDb(this, var, value);
|
||||
Quest.updateQuestVarInDb(this, variable, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Quest.createQuestVarInDb(this, var, value);
|
||||
Quest.createQuestVarInDb(this, variable, newValue);
|
||||
}
|
||||
|
||||
if ("cond".equals(var))
|
||||
if (COND_VAR.equals(variable))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -247,15 +268,24 @@ public class QuestState
|
||||
{
|
||||
previousVal = Integer.parseInt(old);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ignored)
|
||||
{
|
||||
previousVal = 0;
|
||||
}
|
||||
setCond(Integer.parseInt(value), previousVal);
|
||||
int newCond = 0;
|
||||
try
|
||||
{
|
||||
newCond = Integer.parseInt(newValue);
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
|
||||
_cond = newCond;
|
||||
setCond(newCond, previousVal);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, _player.getName() + ", " + _questName + " cond [" + value + "] is not an integer. Value stored, but no packet was sent: " + e.getMessage(), e);
|
||||
LOGGER.log(Level.WARNING, _player.getName() + ", " + _questName + " cond [" + newValue + "] is not an integer. Value stored, but no packet was sent: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,63 +381,69 @@ public class QuestState
|
||||
|
||||
/**
|
||||
* Removes a quest variable from the list of existing quest variables.
|
||||
* @param var the name of the variable to remove
|
||||
* @param variable the name of the variable to remove
|
||||
*/
|
||||
public void unset(String var)
|
||||
public void unset(String variable)
|
||||
{
|
||||
if (_vars == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final String old = _vars.remove(var);
|
||||
final String old = _vars.remove(variable);
|
||||
if (old != null)
|
||||
{
|
||||
Quest.deleteQuestVarInDb(this, var);
|
||||
if (COND_VAR.equals(variable))
|
||||
{
|
||||
_cond = 0;
|
||||
}
|
||||
|
||||
Quest.deleteQuestVarInDb(this, variable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param var the name of the variable to get
|
||||
* @param variable the name of the variable to get
|
||||
* @return the value of the variable from the list of quest variables
|
||||
*/
|
||||
public String get(String var)
|
||||
public String get(String variable)
|
||||
{
|
||||
if (_vars == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _vars.get(var);
|
||||
|
||||
return _vars.get(variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param var the name of the variable to get
|
||||
* @param variable the name of the variable to get
|
||||
* @return the integer value of the variable or 0 if the variable does not exist or its value is not an integer
|
||||
*/
|
||||
public int getInt(String var)
|
||||
public int getInt(String variable)
|
||||
{
|
||||
if (_vars == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
final String variable = _vars.get(var);
|
||||
if ((variable == null) || variable.isEmpty())
|
||||
final String varStr = _vars.get(variable);
|
||||
if ((varStr == null) || varStr.isEmpty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int varint = 0;
|
||||
int varInt = 0;
|
||||
try
|
||||
{
|
||||
varint = Integer.parseInt(variable);
|
||||
varInt = Integer.parseInt(varStr);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Quest " + getQuestName() + ", method getInt(" + var + "), tried to parse a non-integer value (" + variable + "). Char Id: " + _player.getObjectId(), nfe);
|
||||
LOGGER.log(Level.INFO, "Quest " + _questName + ", method getInt(" + variable + "), tried to parse a non-integer value (" + varStr + "). Char Id: " + _player.getObjectId(), nfe);
|
||||
}
|
||||
|
||||
return varint;
|
||||
return varInt;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -418,7 +454,7 @@ public class QuestState
|
||||
*/
|
||||
public boolean isCond(int condition)
|
||||
{
|
||||
return getInt("cond") == condition;
|
||||
return _cond == condition;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,7 +467,7 @@ public class QuestState
|
||||
{
|
||||
if (isStarted())
|
||||
{
|
||||
set("cond", Integer.toString(value));
|
||||
set(COND_VAR, Integer.toString(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,8 +478,9 @@ public class QuestState
|
||||
{
|
||||
if (isStarted())
|
||||
{
|
||||
return getInt("cond");
|
||||
return _cond;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -473,7 +510,8 @@ public class QuestState
|
||||
{
|
||||
return;
|
||||
}
|
||||
set("cond", String.valueOf(value));
|
||||
|
||||
set(COND_VAR, String.valueOf(value));
|
||||
if (playQuestMiddle)
|
||||
{
|
||||
_player.sendPacket(QuestSound.ITEMSOUND_QUEST_MIDDLE.getPacket());
|
||||
@@ -482,7 +520,7 @@ public class QuestState
|
||||
|
||||
public void setMemoState(int value)
|
||||
{
|
||||
set("memoState", String.valueOf(value));
|
||||
set(MEMO_VAR, String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -492,14 +530,15 @@ public class QuestState
|
||||
{
|
||||
if (isStarted())
|
||||
{
|
||||
return getInt("memoState");
|
||||
return getInt(MEMO_VAR);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isMemoState(int memoState)
|
||||
{
|
||||
return getInt("memoState") == memoState;
|
||||
return getInt(MEMO_VAR) == memoState;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -511,8 +550,9 @@ public class QuestState
|
||||
{
|
||||
if (isStarted())
|
||||
{
|
||||
return getInt("memoStateEx" + slot);
|
||||
return getInt(MEMO_EX_VAR + slot);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -523,7 +563,7 @@ public class QuestState
|
||||
*/
|
||||
public void setMemoStateEx(int slot, int value)
|
||||
{
|
||||
set("memoStateEx" + slot, String.valueOf(value));
|
||||
set(MEMO_EX_VAR + slot, String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,7 +615,7 @@ public class QuestState
|
||||
{
|
||||
if (isCreated() && !getQuest().isCustomQuest())
|
||||
{
|
||||
set("cond", "1");
|
||||
set(COND_VAR, "1");
|
||||
setState(State.STARTED);
|
||||
_player.sendPacket(QuestSound.ITEMSOUND_QUEST_ACCEPT.getPacket());
|
||||
}
|
||||
@@ -683,7 +723,7 @@ public class QuestState
|
||||
_player.sendPacket(new TutorialShowQuestionMark(number));
|
||||
}
|
||||
|
||||
// TODO make tutorial voices the same as quest sounds
|
||||
// TODO: make tutorial voices the same as quest sounds
|
||||
public void playTutorialVoice(String voice)
|
||||
{
|
||||
_player.sendPacket(new PlaySound(2, voice, 0, 0, _player.getX(), _player.getY(), _player.getZ()));
|
||||
@@ -703,7 +743,7 @@ public class QuestState
|
||||
}
|
||||
reDo.set(Calendar.HOUR_OF_DAY, getQuest().getResetHour());
|
||||
reDo.set(Calendar.MINUTE, getQuest().getResetMinutes());
|
||||
set("restartTime", String.valueOf(reDo.getTimeInMillis()));
|
||||
set(RESTART_VAR, String.valueOf(reDo.getTimeInMillis()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -712,7 +752,7 @@ public class QuestState
|
||||
*/
|
||||
public boolean isNowAvailable()
|
||||
{
|
||||
final String val = get("restartTime");
|
||||
final String val = get(RESTART_VAR);
|
||||
return (val != null) && (Long.parseLong(val) <= Chronos.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
@@ -64,7 +64,7 @@ public class GmViewQuestInfo implements IClientOutgoingPacket
|
||||
continue;
|
||||
}
|
||||
|
||||
packet.writeD(qs.getInt("cond")); // stage of quest progress
|
||||
packet.writeD(qs.getCond()); // stage of quest progress
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -89,7 +89,7 @@ public class QuestList implements IClientOutgoingPacket
|
||||
}
|
||||
else
|
||||
{
|
||||
packet.writeD(qs.getInt("cond"));
|
||||
packet.writeD(qs.getCond());
|
||||
}
|
||||
}
|
||||
packet.writeB(new byte[128]);
|
||||
|
Reference in New Issue
Block a user