Removed quest_global_data SQL table.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
DROP TABLE IF EXISTS `global_variables`;
|
||||
CREATE TABLE IF NOT EXISTS `global_variables` (
|
||||
`var` VARCHAR(20) NOT NULL DEFAULT '',
|
||||
`var` VARCHAR(255) NOT NULL DEFAULT '',
|
||||
`value` VARCHAR(255) ,
|
||||
PRIMARY KEY (`var`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
@@ -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.
|
||||
|
||||
DROP TABLE IF EXISTS `quest_global_data`;
|
||||
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=InnoDB DEFAULT CHARSET=utf8;
|
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
import com.l2jmobius.commons.util.CommonUtil;
|
||||
import com.l2jmobius.gameserver.ai.CtrlIntention;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.SkillData;
|
||||
import com.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.Location;
|
||||
@@ -227,18 +228,18 @@ public final class SeedOfAnnihilation extends AbstractNpcAI
|
||||
});
|
||||
|
||||
int buffsNow = 0;
|
||||
final String var = loadGlobalQuestVar("SeedNextStatusChange");
|
||||
final String var = GlobalVariablesManager.getInstance().getString("SeedNextStatusChange");
|
||||
if (var.equalsIgnoreCase("") || (Long.parseLong(var) < System.currentTimeMillis()))
|
||||
{
|
||||
buffsNow = getRandom(ZONE_BUFFS_LIST.length);
|
||||
saveGlobalQuestVar("SeedBuffsList", String.valueOf(buffsNow));
|
||||
GlobalVariablesManager.getInstance().set("SeedBuffsList", String.valueOf(buffsNow));
|
||||
_seedsNextStatusChange = getNextSeedsStatusChangeTime();
|
||||
saveGlobalQuestVar("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
|
||||
GlobalVariablesManager.getInstance().set("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
|
||||
}
|
||||
else
|
||||
{
|
||||
_seedsNextStatusChange = Long.parseLong(var);
|
||||
buffsNow = Integer.parseInt(loadGlobalQuestVar("SeedBuffsList"));
|
||||
buffsNow = Integer.parseInt(GlobalVariablesManager.getInstance().getString("SeedBuffsList"));
|
||||
}
|
||||
for (int i = 0; i < _regionsData.length; i++)
|
||||
{
|
||||
@@ -301,9 +302,9 @@ public final class SeedOfAnnihilation extends AbstractNpcAI
|
||||
if (event.equalsIgnoreCase("ChangeSeedsStatus"))
|
||||
{
|
||||
final int buffsNow = getRandom(ZONE_BUFFS_LIST.length);
|
||||
saveGlobalQuestVar("SeedBuffsList", String.valueOf(buffsNow));
|
||||
GlobalVariablesManager.getInstance().set("SeedBuffsList", String.valueOf(buffsNow));
|
||||
_seedsNextStatusChange = getNextSeedsStatusChangeTime();
|
||||
saveGlobalQuestVar("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
|
||||
GlobalVariablesManager.getInstance().set("SeedNextStatusChange", String.valueOf(_seedsNextStatusChange));
|
||||
for (int i = 0; i < _regionsData.length; i++)
|
||||
{
|
||||
_regionsData[i].activeBuff = ZONE_BUFFS_LIST[buffsNow][i];
|
||||
|
@@ -21,6 +21,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.enums.ChatType;
|
||||
import com.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.GrandBossManager;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Attackable;
|
||||
@@ -82,7 +83,7 @@ public final class Core extends AbstractNpcAI
|
||||
}
|
||||
else
|
||||
{
|
||||
final String test = loadGlobalQuestVar("Core_Attacked");
|
||||
final String test = GlobalVariablesManager.getInstance().getString("Core_Attacked");
|
||||
if (test.equalsIgnoreCase("true"))
|
||||
{
|
||||
_firstAttacked = true;
|
||||
@@ -102,7 +103,7 @@ public final class Core extends AbstractNpcAI
|
||||
@Override
|
||||
public void onSave()
|
||||
{
|
||||
saveGlobalQuestVar("Core_Attacked", Boolean.toString(_firstAttacked));
|
||||
GlobalVariablesManager.getInstance().set("Core_Attacked", Boolean.toString(_firstAttacked));
|
||||
}
|
||||
|
||||
public void spawnBoss(L2GrandBossInstance npc)
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package ai.bosses.QueenShyeed;
|
||||
|
||||
import com.l2jmobius.gameserver.enums.ChatType;
|
||||
import com.l2jmobius.gameserver.instancemanager.GlobalVariablesManager;
|
||||
import com.l2jmobius.gameserver.instancemanager.ZoneManager;
|
||||
import com.l2jmobius.gameserver.model.Location;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
@@ -81,7 +82,7 @@ public final class QueenShyeed extends AbstractNpcAI
|
||||
|
||||
private void spawnShyeed()
|
||||
{
|
||||
final String respawn = loadGlobalQuestVar("Respawn");
|
||||
final String respawn = GlobalVariablesManager.getInstance().getString("QueenShyeedRespawn");
|
||||
final long remain = (!respawn.isEmpty()) ? Long.parseLong(respawn) - System.currentTimeMillis() : 0;
|
||||
if (remain > 0)
|
||||
{
|
||||
@@ -98,7 +99,7 @@ public final class QueenShyeed extends AbstractNpcAI
|
||||
private void startRespawn()
|
||||
{
|
||||
final int respawnTime = RESPAWN - getRandom(RANDOM_RESPAWN);
|
||||
saveGlobalQuestVar("Respawn", Long.toString(System.currentTimeMillis() + respawnTime));
|
||||
GlobalVariablesManager.getInstance().set("QueenShyeedRespawn", Long.toString(System.currentTimeMillis() + respawnTime));
|
||||
startQuestTimer("respawn", respawnTime, null, null);
|
||||
MOB_BUFF_ZONE.setEnabled(false);
|
||||
MOB_BUFF_DISPLAY_ZONE.setEnabled(false);
|
||||
|
@@ -79,14 +79,14 @@ public final class FreyaCelebration extends LongTimeEvent
|
||||
if (getQuestItemsCount(player, Inventory.ADENA_ID) > 1)
|
||||
{
|
||||
final long _curr_time = System.currentTimeMillis();
|
||||
final String value = loadGlobalQuestVar(player.getAccountName());
|
||||
final String value = player.getVariables().getString("FreyaCelebration");
|
||||
final long _reuse_time = value == "" ? 0 : Long.parseLong(value);
|
||||
|
||||
if (_curr_time > _reuse_time)
|
||||
{
|
||||
takeItems(player, Inventory.ADENA_ID, 1);
|
||||
giveItems(player, FREYA_POTION, 1);
|
||||
saveGlobalQuestVar(player.getAccountName(), Long.toString(System.currentTimeMillis() + (HOURS * 3600000)));
|
||||
player.getVariables().set("FreyaCelebration", Long.toString(System.currentTimeMillis() + (HOURS * 3600000)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -92,7 +92,7 @@ public final class MasterOfEnchanting extends LongTimeEvent
|
||||
else if (event.equalsIgnoreCase("buy_scroll_24"))
|
||||
{
|
||||
final long curTime = System.currentTimeMillis();
|
||||
final String value = loadGlobalQuestVar(player.getAccountName());
|
||||
final String value = player.getVariables().getString("MasterOfEnchanting");
|
||||
final long reuse = value == "" ? 0 : Long.parseLong(value);
|
||||
if (player.getCreateDate().after(EVENT_START))
|
||||
{
|
||||
@@ -105,7 +105,7 @@ public final class MasterOfEnchanting extends LongTimeEvent
|
||||
{
|
||||
takeItems(player, Inventory.ADENA_ID, SCROLL_24_PRICE);
|
||||
giveItems(player, MASTER_YOGI_SCROLL, 24);
|
||||
saveGlobalQuestVar(player.getAccountName(), Long.toString(System.currentTimeMillis() + (SCROLL_24_TIME * 3600000)));
|
||||
player.getVariables().set("MasterOfEnchanting", Long.toString(System.currentTimeMillis() + (SCROLL_24_TIME * 3600000)));
|
||||
htmltext = "32599-scroll24.htm";
|
||||
}
|
||||
else
|
||||
@@ -139,7 +139,7 @@ public final class MasterOfEnchanting extends LongTimeEvent
|
||||
{
|
||||
takeItems(player, Inventory.ADENA_ID, SCROLL_24_PRICE);
|
||||
giveItems(player, MASTER_YOGI_SCROLL, 24);
|
||||
saveGlobalQuestVar(player.getAccountName(), Long.toString(System.currentTimeMillis() + (SCROLL_24_TIME * 3600000)));
|
||||
player.getVariables().set("MasterOfEnchanting", Long.toString(System.currentTimeMillis() + (SCROLL_24_TIME * 3600000)));
|
||||
htmltext = "32599-scroll24.htm";
|
||||
}
|
||||
else
|
||||
|
@@ -1655,97 +1655,6 @@ public class Quest extends AbstractScript implements IIdentifiable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert (or update) in the database variables that need to stay persistent for this quest after a reboot.<br>
|
||||
* This function is for storage of values that do not related to a specific player but are global for all characters.<br>
|
||||
* 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 the name of the variable to save
|
||||
* @param value the value of the variable
|
||||
*/
|
||||
public final void saveGlobalQuestVar(String var, String value)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement 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();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "could not insert global quest variable:", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the database a previously saved variable for this quest.<br>
|
||||
* Due to performance considerations, this function should best be used only when the quest is first loaded.<br>
|
||||
* Subclasses of this class can define structures into which these loaded values can be saved.<br>
|
||||
* However, on-demand usage of this function throughout the script is not prohibited, only not recommended.<br>
|
||||
* Values read from this function were entered by calls to "saveGlobalQuestVar".
|
||||
* @param var the name of the variable to load
|
||||
* @return the current value of the specified variable, or an empty string if the variable does not exist
|
||||
*/
|
||||
public final String loadGlobalQuestVar(String var)
|
||||
{
|
||||
String result = "";
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("SELECT value FROM quest_global_data WHERE quest_name = ? AND var = ?"))
|
||||
{
|
||||
statement.setString(1, getName());
|
||||
statement.setString(2, var);
|
||||
try (ResultSet rs = statement.executeQuery())
|
||||
{
|
||||
if (rs.first())
|
||||
{
|
||||
result = rs.getString(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.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 the name of the variable to delete
|
||||
*/
|
||||
public final void deleteGlobalQuestVar(String var)
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ? AND var = ?"))
|
||||
{
|
||||
statement.setString(1, getName());
|
||||
statement.setString(2, var);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "could not delete global quest variable:", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently delete from the database all global quest variables that were previously saved for this quest.
|
||||
*/
|
||||
public final void deleteAllGlobalQuestVars()
|
||||
{
|
||||
try (Connection con = DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement("DELETE FROM quest_global_data WHERE quest_name = ?"))
|
||||
{
|
||||
statement.setString(1, getName());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "could not delete global quest variables:", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert in the database the quest for the player.
|
||||
* @param qs the {@link QuestState} object whose variable to insert
|
||||
|
Reference in New Issue
Block a user