Quest condition is now cached in a separate QuestState variable.

This commit is contained in:
MobiusDevelopment
2021-11-13 15:21:57 +00:00
parent 2988292540
commit e9f27b365e
700 changed files with 35311 additions and 33501 deletions

View File

@@ -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");
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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";

View File

@@ -54,9 +54,7 @@ public class Q00019_GoToThePastureland extends Quest
if (event.equals("31302-01.htm"))
{
st.setState(State.STARTED);
st.set("cond", "1");
playSound(player, QuestSound.ITEMSOUND_QUEST_ACCEPT);
st.startQuest();
giveItems(player, YOUNG_WILD_BEAST_MEAT, 1);
}
else if (event.equals("019_finish"))

View File

@@ -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";
}

View File

@@ -95,86 +95,85 @@ public class Q00241_PossessorOfAPreciousSoul1 extends Quest
// Talien
if (event.equalsIgnoreCase("31739-03.htm"))
{
st.set("cond", "1");
st.setState(State.STARTED);
st.startQuest();
}
else if (event.equalsIgnoreCase("31739-07.htm"))
{
st.set("cond", "5");
st.setCond(5);
takeItems(player, LEGEND_OF_SEVENTEEN, 1);
}
else if (event.equalsIgnoreCase("31739-10.htm"))
{
st.set("cond", "9");
st.setCond(9);
takeItems(player, ECHO_CRYSTAL, 1);
}
else if (event.equalsIgnoreCase("31739-13.htm"))
{
st.set("cond", "11");
st.setCond(11);
takeItems(player, POETRY_BOOK, 1);
}
// Gabrielle
else if (event.equalsIgnoreCase("30753-02.htm"))
{
st.set("cond", "2");
st.setCond(2);
}
// Gilmore
else if (event.equalsIgnoreCase("30754-02.htm"))
{
st.set("cond", "3");
st.setCond(3);
}
// Kantabilon
else if (event.equalsIgnoreCase("31042-02.htm"))
{
st.set("cond", "6");
st.setCond(6);
}
else if (event.equalsIgnoreCase("31042-05.htm"))
{
st.set("cond", "8");
st.setCond(8);
takeItems(player, MALRUK_SUCCUBUS_CLAW, 10);
giveItems(player, ECHO_CRYSTAL, 1);
}
// Stedmiel
else if (event.equalsIgnoreCase("30692-02.htm"))
{
st.set("cond", "10");
st.setCond(10);
giveItems(player, POETRY_BOOK, 1);
}
// Virgil
else if (event.equalsIgnoreCase("31742-02.htm"))
{
st.set("cond", "12");
st.setCond(12);
}
else if (event.equalsIgnoreCase("31742-05.htm"))
{
st.set("cond", "18");
st.setCond(18);
}
// Ogmar
else if (event.equalsIgnoreCase("31744-02.htm"))
{
st.set("cond", "13");
st.setCond(13);
}
// Rahorakti
else if (event.equalsIgnoreCase("31336-02.htm"))
{
st.set("cond", "14");
st.setCond(14);
}
else if (event.equalsIgnoreCase("31336-05.htm"))
{
st.set("cond", "16");
st.setCond(16);
takeItems(player, CRIMSON_MOSS, 5);
giveItems(player, RAHORAKTIS_MEDICINE, 1);
}
// Kassandra
else if (event.equalsIgnoreCase("31743-02.htm"))
{
st.set("cond", "17");
st.setCond(17);
takeItems(player, RAHORAKTIS_MEDICINE, 1);
}
// Caradine
else if (event.equalsIgnoreCase("31740-02.htm"))
{
st.set("cond", "19");
st.setCond(19);
}
else if (event.equalsIgnoreCase("31740-05.htm"))
{
@@ -185,7 +184,7 @@ public class Q00241_PossessorOfAPreciousSoul1 extends Quest
// Noel
else if (event.equalsIgnoreCase("31272-02.htm"))
{
st.set("cond", "20");
st.setCond(20);
}
else if (event.equalsIgnoreCase("31272-05.htm"))
{
@@ -193,7 +192,7 @@ public class Q00241_PossessorOfAPreciousSoul1 extends Quest
{
takeItems(player, LUNARGENT, 5);
takeItems(player, HELLFIRE_OIL, 1);
st.set("cond", "21");
st.setCond(21);
}
else
{
@@ -230,7 +229,7 @@ public class Q00241_PossessorOfAPreciousSoul1 extends Quest
break;
}
final int cond = st.getInt("cond");
final int cond = st.getCond();
switch (npc.getId())
{
case TALIEN:

View File

@@ -74,20 +74,19 @@ public class Q00246_PossessorOfAPreciousSoul3 extends Quest
// Caradine
if (event.equalsIgnoreCase("31740-04.htm"))
{
st.set("cond", "1");
st.startQuest();
takeItems(player, CARADINE_LETTER_2, 1);
st.setState(State.STARTED);
}
// Ossian
else if (event.equalsIgnoreCase("31741-02.htm"))
{
st.set("cond", "2");
st.setCond(2);
}
else if (event.equalsIgnoreCase("31741-05.htm"))
{
if (hasQuestItems(player, WATERBINDER) && hasQuestItems(player, EVERGREEN))
{
st.set("cond", "4");
st.setCond(4);
takeItems(player, WATERBINDER, 1);
takeItems(player, EVERGREEN, 1);
}
@@ -100,7 +99,7 @@ public class Q00246_PossessorOfAPreciousSoul3 extends Quest
{
if (hasQuestItems(player, RAIN_SONG))
{
st.set("cond", "6");
st.setCond(6);
takeItems(player, RAIN_SONG, 1);
giveItems(player, RELIC_BOX, 1);
}
@@ -157,12 +156,11 @@ public class Q00246_PossessorOfAPreciousSoul3 extends Quest
break;
}
final int cond = st.getInt("cond");
switch (npc.getId())
{
case CARADINE:
{
if (cond == 1)
if (st.isCond(1))
{
htmltext = "31740-05.htm";
}
@@ -170,7 +168,7 @@ public class Q00246_PossessorOfAPreciousSoul3 extends Quest
}
case OSSIAN:
{
switch (cond)
switch (st.getCond())
{
case 1:
{
@@ -213,7 +211,7 @@ public class Q00246_PossessorOfAPreciousSoul3 extends Quest
}
case LADD:
{
if ((cond == 6) && hasQuestItems(player, RELIC_BOX))
if (st.isCond(6) && hasQuestItems(player, RELIC_BOX))
{
htmltext = "30721-01.htm";
}
@@ -285,7 +283,7 @@ public class Q00246_PossessorOfAPreciousSoul3 extends Quest
}
else
{
st.set("cond", "3");
st.setCond(3);
}
}
}

View File

@@ -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;
}

View File

@@ -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";
}

View File

@@ -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)

View File

@@ -123,9 +123,7 @@ public class Q00631_DeliciousTopChoiceMeat extends Quest
{
if (player.getLevel() >= 65)
{
st.setState(State.STARTED);
st.set("cond", "1");
playSound(player, QuestSound.ITEMSOUND_QUEST_ACCEPT);
st.startQuest();
}
else
{
@@ -147,7 +145,7 @@ public class Q00631_DeliciousTopChoiceMeat extends Quest
}
else
{
st.set("cond", "1");
st.setCond(1);
htmltext = "31537-07.htm";
}
}
@@ -167,7 +165,7 @@ public class Q00631_DeliciousTopChoiceMeat extends Quest
break;
case State.STARTED:
final int cond = st.getInt("cond");
final int cond = st.getCond();
if (cond == 1)
{
htmltext = "31537-03a.htm";
@@ -180,7 +178,7 @@ public class Q00631_DeliciousTopChoiceMeat extends Quest
}
else
{
st.set("cond", "1");
st.setCond(1);
htmltext = "31537-03a.htm";
}
}
@@ -206,7 +204,7 @@ public class Q00631_DeliciousTopChoiceMeat extends Quest
if (giveItemRandomly(partyMember, npc, TOP_QUALITY_MEAT, 1, 120, CHANCES.get(npc.getId()), true))
{
st.set("cond", "2");
st.setCond(2);
}
return null;

View File

@@ -59,9 +59,7 @@ public class Q00647_InfluxOfMachines extends Quest
if (event.equals("32069-02.htm"))
{
st.setState(State.STARTED);
st.set("cond", "1");
playSound(player, QuestSound.ITEMSOUND_QUEST_ACCEPT);
st.startQuest();
}
else if (event.equals("32069-06.htm"))
{
@@ -86,7 +84,7 @@ public class Q00647_InfluxOfMachines extends Quest
break;
case State.STARTED:
final int cond = st.getInt("cond");
final int cond = st.getCond();
if (cond == 1)
{
htmltext = "32069-04.htm";
@@ -117,7 +115,7 @@ public class Q00647_InfluxOfMachines extends Quest
if (giveItemRandomly(partyMember, npc, DESTROYED_GOLEM_SHARD, 1, 500, 0.3, true))
{
st.set("cond", "2");
st.setCond(2);
}
return null;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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))

View File

@@ -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))

View File

@@ -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());
}

View File

@@ -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;
}

View File

@@ -89,7 +89,7 @@ public class QuestList implements IClientOutgoingPacket
}
else
{
packet.writeD(qs.getInt("cond"));
packet.writeD(qs.getCond());
}
}
packet.writeB(new byte[128]);