Removed obsolete quest global data.

This commit is contained in:
MobiusDevelopment 2020-02-03 20:34:59 +00:00
parent 499911b429
commit ddc57a5891
5 changed files with 11 additions and 132 deletions

View File

@ -1,12 +0,0 @@
-- ----------------------------
-- Table structure for global quest data (i.e. quest data not particular to a player)
-- Note: We had considered using character_quests with char_id = 0 for this, but decided
-- against it, primarily for aesthetic purposes, cleaningness of code, expectability, and
-- to keep char-related data purely as char-related data, global purely as global.
-- ----------------------------
CREATE TABLE IF NOT EXISTS `quest_global_data` (
`quest_name` VARCHAR(40) NOT NULL DEFAULT '',
`var` VARCHAR(20) NOT NULL DEFAULT '',
`value` VARCHAR(255) ,
PRIMARY KEY (`quest_name`,`var`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

View File

@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.l2jmobius.Config;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
import org.l2jmobius.gameserver.instancemanager.GrandBossManager;
import org.l2jmobius.gameserver.model.Location;
import org.l2jmobius.gameserver.model.StatSet;
@ -123,8 +124,7 @@ public class Core extends Quest
}
else
{
final String test = loadGlobalQuestVar("Core_Attacked");
if (test.equalsIgnoreCase("true"))
if (GlobalVariablesManager.getInstance().getBoolean("CoreAttacked", false))
{
_firstAttacked = true;
}
@ -140,8 +140,7 @@ public class Core extends Quest
@Override
public void saveGlobalData()
{
final String val = "" + _firstAttacked;
saveGlobalQuestVar("Core_Attacked", val);
GlobalVariablesManager.getInstance().set("CoreAttacked", _firstAttacked);
}
public void spawnBoss(GrandBossInstance npc)

View File

@ -16,6 +16,7 @@
*/
package ai.bosses;
import org.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
import org.l2jmobius.gameserver.instancemanager.GrandBossManager;
import org.l2jmobius.gameserver.model.Party;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
@ -95,14 +96,14 @@ public class Sailren extends Quest
}
case "open":
{
deleteGlobalQuestVar("close");
GlobalVariablesManager.getInstance().remove("SailrenClose");
cancelQuestTimer("open", npc, null);
break;
}
case "vkrovatku":
{
npc.deleteMe();
deleteGlobalQuestVar("close");
GlobalVariablesManager.getInstance().remove("SailrenClose");
cancelQuestTimer("open", npc, null);
cancelQuestTimer("vkrovatku", npc, null);
break;
@ -116,14 +117,13 @@ public class Sailren extends Quest
{
if (player.getInventory().getItemByItemId(STONE) != null)
{
final String close = loadGlobalQuestVar("close");
if (close.equals(""))
if (!GlobalVariablesManager.getInstance().hasVariable("SailrenClose"))
{
final Party party = player.getParty();
if (party != null)
{
player.destroyItemByItemId("Sailren", STONE, 1, player, true);
saveGlobalQuestVar("close", "1");
GlobalVariablesManager.getInstance().set("SailrenClose", true);
final BossZone zone = GrandBossManager.getInstance().getZone(27244, -7026, -1974);
for (PlayerInstance member : party.getPartyMembers())
{
@ -170,7 +170,7 @@ public class Sailren extends Quest
}
else if (npc == _slrnInstance)
{
deleteGlobalQuestVar("close");
GlobalVariablesManager.getInstance().remove("SailrenClose");
cancelQuestTimer("open", npc, null);
}
return super.onKill(npc, killer, isPet);

View File

@ -64,10 +64,7 @@ public class GlobalVariablesManager extends AbstractVariables
LOGGER.warning(getClass().getSimpleName() + ": Couldn't restore global variables.");
return false;
}
finally
{
compareAndSetChanges(true, false);
}
LOGGER.info(getClass().getSimpleName() + ": Loaded " + getSet().size() + " variables.");
return true;
}
@ -75,12 +72,6 @@ public class GlobalVariablesManager extends AbstractVariables
@Override
public boolean storeMe()
{
// No changes, nothing to store.
if (!hasChanges())
{
return false;
}
try (Connection con = DatabaseFactory.getConnection();
Statement del = con.createStatement();
PreparedStatement st = con.prepareStatement(INSERT_QUERY))
@ -102,10 +93,7 @@ public class GlobalVariablesManager extends AbstractVariables
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Couldn't save global variables to database.", e);
return false;
}
finally
{
compareAndSetChanges(true, false);
}
LOGGER.info(getClass().getSimpleName() + ": Stored " + getSet().size() + " variables.");
return true;
}

View File

@ -1121,102 +1121,6 @@ public class Quest extends ManagedScript
}
}
/**
* Insert (or Update) in the database variables that need to stay persistant for this quest after a reboot. This function is for storage of values that do not related to a specific player but are global for all characters. For example, if we need to disable a quest-gatekeeper until a certain
* time (as is done with some grand-boss gatekeepers), we can save that time in the DB.
* @param var : String designating the name of the variable for the quest
* @param value : String designating the value of the variable for the quest
*/
public void saveGlobalQuestVar(String var, String value)
{
try (Connection con = DatabaseFactory.getConnection())
{
PreparedStatement statement;
statement = con.prepareStatement("REPLACE INTO quest_global_data (quest_name,var,value) VALUES (?,?,?)");
statement.setString(1, getName());
statement.setString(2, var);
statement.setString(3, value);
statement.executeUpdate();
statement.close();
}
catch (Exception e)
{
LOGGER.warning("could not insert global quest variable: " + e);
}
}
/**
* Read from the database a previously saved variable for this quest. Due to performance considerations, this function should best be used only when the quest is first loaded. Subclasses of this class can define structures into which these loaded values can be saved. However, on-demand usage of
* this function throughout the script is not prohibited, only not recommended. Values read from this function were entered by calls to "saveGlobalQuestVar"
* @param var : String designating the name of the variable for the quest
* @return String : String representing the loaded value for the passed var, or an empty string if the var was invalid
*/
public String loadGlobalQuestVar(String var)
{
String result = "";
try (Connection con = DatabaseFactory.getConnection())
{
PreparedStatement statement;
statement = con.prepareStatement("SELECT value FROM quest_global_data WHERE quest_name = ? AND var = ?");
statement.setString(1, getName());
statement.setString(2, var);
final ResultSet rs = statement.executeQuery();
if (rs.first())
{
result = rs.getString(1);
}
rs.close();
statement.close();
}
catch (Exception e)
{
LOGGER.warning("could not load global quest variable: " + e);
}
return result;
}
/**
* Permanently delete from the database a global quest variable that was previously saved for this quest.
* @param var : String designating the name of the variable for the quest
*/
public void deleteGlobalQuestVar(String var)
{
try (Connection con = DatabaseFactory.getConnection())
{
PreparedStatement statement;
statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ? AND var = ?");
statement.setString(1, getName());
statement.setString(2, var);
statement.executeUpdate();
statement.close();
}
catch (Exception e)
{
LOGGER.warning("could not delete global quest variable: " + e);
}
}
/**
* Permanently delete from the database all global quest variables that was previously saved for this quest.
*/
public void deleteAllGlobalQuestVars()
{
try (Connection con = DatabaseFactory.getConnection())
{
PreparedStatement statement;
statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ?");
statement.setString(1, getName());
statement.executeUpdate();
statement.close();
}
catch (Exception e)
{
LOGGER.warning("could not delete global quest variables: " + e);
}
}
/**
* Insert in the database the quest for the player.
* @param qs : QuestState pointing out the state of the quest