/* * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ package com.l2jserver.gameserver.model.quest; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.Calendar; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import com.l2jserver.L2DatabaseFactory; import com.l2jserver.gameserver.cache.HtmCache; import com.l2jserver.gameserver.instancemanager.QuestManager; import com.l2jserver.gameserver.model.actor.L2Character; import com.l2jserver.gameserver.model.actor.L2Npc; import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.model.itemcontainer.PcInventory; import com.l2jserver.gameserver.network.serverpackets.ExShowQuestMark; import com.l2jserver.gameserver.network.serverpackets.PlaySound; import com.l2jserver.gameserver.network.serverpackets.QuestList; import com.l2jserver.gameserver.network.serverpackets.TutorialCloseHtml; import com.l2jserver.gameserver.network.serverpackets.TutorialEnableClientEvent; import com.l2jserver.gameserver.network.serverpackets.TutorialShowHtml; import com.l2jserver.gameserver.network.serverpackets.TutorialShowQuestionMark; import com.l2jserver.gameserver.util.Util; /** * @author Luis Arias */ public final class QuestState { protected static final Logger _log = Logger.getLogger(QuestState.class.getName()); /** The name of the quest of this QuestState */ private final String _questName; /** The "owner" of this QuestState object */ private final L2PcInstance _player; /** The current state of the quest */ private byte _state; /** A map of key->value pairs containing the quest state variables and their values */ private Map _vars; /** * boolean flag letting QuestStateManager know to exit quest when cleaning up */ private boolean _isExitQuestOnCleanUp = false; /** * This enumerate represent the different quest types. */ public static enum QuestType { REPEATABLE, ONE_TIME, DAILY } /** * Constructor of the QuestState. Creates the QuestState object and sets the player's progress of the quest to this QuestState. * @param quest the {@link Quest} object associated with the QuestState * @param player the owner of this {@link QuestState} object * @param state the initial state of the quest */ public QuestState(Quest quest, L2PcInstance player, byte state) { _questName = quest.getName(); _player = player; _state = state; player.setQuestState(this); } /** * @return the name of the quest of this QuestState */ public String getQuestName() { return _questName; } /** * @return the {@link Quest} object of this QuestState */ public Quest getQuest() { return QuestManager.getInstance().getQuest(_questName); } /** * @return the {@link L2PcInstance} object of the owner of this QuestState */ public L2PcInstance getPlayer() { return _player; } /** * @return the current State of this QuestState * @see com.l2jserver.gameserver.model.quest.State */ public byte getState() { return _state; } /** * @return {@code true} if the State of this QuestState is CREATED, {@code false} otherwise * @see com.l2jserver.gameserver.model.quest.State */ public boolean isCreated() { return (_state == State.CREATED); } /** * @return {@code true} if the State of this QuestState is STARTED, {@code false} otherwise * @see com.l2jserver.gameserver.model.quest.State */ public boolean isStarted() { return (_state == State.STARTED); } /** * @return {@code true} if the State of this QuestState is COMPLETED, {@code false} otherwise * @see com.l2jserver.gameserver.model.quest.State */ public boolean isCompleted() { return (_state == State.COMPLETED); } /** * @param state the new state of the quest to set * @return {@code true} if state was changed, {@code false} otherwise * @see #setState(byte state, boolean saveInDb) * @see com.l2jserver.gameserver.model.quest.State */ public boolean setState(byte state) { return setState(state, true); } /** * Change the state of this quest to the specified value. * @param state the new state of the quest to set * @param saveInDb if {@code true}, will save the state change in the database * @return {@code true} if state was changed, {@code false} otherwise * @see com.l2jserver.gameserver.model.quest.State */ public boolean setState(byte state, boolean saveInDb) { if (_state == state) { return false; } final boolean newQuest = isCreated(); _state = state; if (saveInDb) { if (newQuest) { Quest.createQuestInDb(this); } else { Quest.updateQuestInDb(this); } } _player.sendPacket(new QuestList()); return true; } /** * 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 * @return String (equal to parameter "val") */ public String setInternal(String var, String val) { if (_vars == null) { _vars = new HashMap<>(); } if (val == null) { val = ""; } _vars.put(var, val); return val; } /** * Return value of parameter "val" after adding the couple (var,val) in class variable "vars".
* Actions:
*