[Zone] Implement Zone State Saving on Shutdown (#4715)

* Save spawns

* Update base_zone_state_spawns_repository.h

* Zone state save work

* Code cleanup

* More cleanup

* Database migration

* Update database_update_manifest.cpp

* Revert decay at storage model

* Code cleanup

* More cleanup

* More cleanup

* More cleanup

* Entity variables

* Add entity variables to the schema

* Post rebase

* Checkpoint

* Serialize / deserialize buffs

* Current hp / mana / end save / load

* Save / load current_waypoint

* Add zone spawn protection

* Finishing touches

* Cleanup

* Update zone_save_state.cpp

* Cleanup

* Update zone_save_state.cpp

* Update npc.cpp

* Update npc.cpp

* More

* Update perl_npc.cpp

* Update zone_loot.cpp
This commit is contained in:
Chris Miles
2025-02-28 15:31:06 -06:00
committed by GitHub
parent 425d24c1f4
commit 2f7ca2cdc8
26 changed files with 1637 additions and 59 deletions
@@ -6868,6 +6868,47 @@ CREATE UNIQUE INDEX `keys` ON data_buckets (`key`, character_id, npc_id, bot_id,
-- Create indexes for just instance_id (instance deletion)
CREATE INDEX idx_instance_id ON data_buckets (instance_id);
)",
.content_schema_update = false
},
ManifestEntry{
.version = 9307,
.description = "2025_02_17_zone_state_spawns.sql",
.check = "SHOW TABLES LIKE 'zone_state_spawns'",
.condition = "empty",
.match = "",
.sql = R"(
CREATE TABLE `zone_state_spawns` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`zone_id` int(11) unsigned DEFAULT NULL,
`instance_id` int(11) unsigned DEFAULT NULL,
`is_corpse` tinyint(11) DEFAULT 0,
`decay_in_seconds` int(11) DEFAULT 0,
`npc_id` int(10) unsigned DEFAULT NULL,
`spawn2_id` int(10) unsigned NOT NULL,
`spawngroup_id` int(10) unsigned NOT NULL,
`x` float NOT NULL,
`y` float NOT NULL,
`z` float NOT NULL,
`heading` float NOT NULL,
`respawn_time` int(10) unsigned NOT NULL,
`variance` int(10) unsigned NOT NULL,
`grid` int(10) unsigned DEFAULT 0,
`current_waypoint` int(11) DEFAULT 0,
`path_when_zone_idle` smallint(6) DEFAULT 0,
`condition_id` smallint(5) unsigned DEFAULT 0,
`condition_min_value` smallint(6) DEFAULT 0,
`enabled` smallint(6) DEFAULT 1,
`anim` smallint(5) unsigned DEFAULT 0,
`loot_data` text DEFAULT NULL,
`entity_variables` text DEFAULT NULL,
`buffs` text DEFAULT NULL,
`hp` bigint(20) DEFAULT 0,
`mana` bigint(20) DEFAULT 0,
`endurance` bigint(20) DEFAULT 0,
`created_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4
)",
.content_schema_update = false
},
+1
View File
@@ -350,6 +350,7 @@ namespace DatabaseSchema {
"shared_task_dynamic_zones",
"shared_task_members",
"shared_tasks",
"zone_state_spawns",
};
}
+3 -1
View File
@@ -149,6 +149,7 @@ namespace Logs {
BotSpellChecks,
BotSpellTypeChecks,
NpcHandin,
ZoneState,
MaxCategoryID /* Don't Remove this */
};
@@ -256,7 +257,8 @@ namespace Logs {
"Bot Settings",
"Bot Spell Checks",
"Bot Spell Type Checks",
"NpcHandin"
"NpcHandin",
"ZoneState"
};
}
+10
View File
@@ -914,6 +914,16 @@
OutF(LogSys, Logs::Detail, Logs::NpcHandin, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogZoneState(message, ...) do {\
if (LogSys.IsLogEnabled(Logs::General, Logs::ZoneState))\
OutF(LogSys, Logs::General, Logs::ZoneState, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define LogZoneStateDetail(message, ...) do {\
if (LogSys.IsLogEnabled(Logs::Detail, Logs::ZoneState))\
OutF(LogSys, Logs::Detail, Logs::ZoneState, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)
#define Log(debug_level, log_category, message, ...) do {\
if (LogSys.IsLogEnabled(debug_level, log_category))\
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
+1
View File
@@ -25,6 +25,7 @@ struct LootItem {
uint16 trivial_max_level;
uint16 npc_min_level;
uint16 npc_max_level;
uint32 lootdrop_id; // required for zone state referencing
};
typedef std::list<LootItem*> LootItems;
@@ -0,0 +1,703 @@
/**
* DO NOT MODIFY THIS FILE
*
* This repository was automatically generated and is NOT to be modified directly.
* Any repository modifications are meant to be made to the repository extending the base.
* Any modifications to base repositories are to be made by the generator only
*
* @generator ./utils/scripts/generators/repository-generator.pl
* @docs https://docs.eqemu.io/developer/repositories
*/
#ifndef EQEMU_BASE_ZONE_STATE_SPAWNS_REPOSITORY_H
#define EQEMU_BASE_ZONE_STATE_SPAWNS_REPOSITORY_H
#include "../../database.h"
#include "../../strings.h"
#include <ctime>
class BaseZoneStateSpawnsRepository {
public:
struct ZoneStateSpawns {
int64_t id;
uint32_t zone_id;
uint32_t instance_id;
int8_t is_corpse;
int32_t decay_in_seconds;
uint32_t npc_id;
uint32_t spawn2_id;
uint32_t spawngroup_id;
float x;
float y;
float z;
float heading;
uint32_t respawn_time;
uint32_t variance;
uint32_t grid;
int32_t current_waypoint;
int16_t path_when_zone_idle;
uint16_t condition_id;
int16_t condition_min_value;
int16_t enabled;
uint16_t anim;
std::string loot_data;
std::string entity_variables;
std::string buffs;
int64_t hp;
int64_t mana;
int64_t endurance;
time_t created_at;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zone_id",
"instance_id",
"is_corpse",
"decay_in_seconds",
"npc_id",
"spawn2_id",
"spawngroup_id",
"x",
"y",
"z",
"heading",
"respawn_time",
"variance",
"grid",
"current_waypoint",
"path_when_zone_idle",
"condition_id",
"condition_min_value",
"enabled",
"anim",
"loot_data",
"entity_variables",
"buffs",
"hp",
"mana",
"endurance",
"created_at",
};
}
static std::vector<std::string> SelectColumns()
{
return {
"id",
"zone_id",
"instance_id",
"is_corpse",
"decay_in_seconds",
"npc_id",
"spawn2_id",
"spawngroup_id",
"x",
"y",
"z",
"heading",
"respawn_time",
"variance",
"grid",
"current_waypoint",
"path_when_zone_idle",
"condition_id",
"condition_min_value",
"enabled",
"anim",
"loot_data",
"entity_variables",
"buffs",
"hp",
"mana",
"endurance",
"UNIX_TIMESTAMP(created_at)",
};
}
static std::string ColumnsRaw()
{
return std::string(Strings::Implode(", ", Columns()));
}
static std::string SelectColumnsRaw()
{
return std::string(Strings::Implode(", ", SelectColumns()));
}
static std::string TableName()
{
return std::string("zone_state_spawns");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
SelectColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
ColumnsRaw()
);
}
static ZoneStateSpawns NewEntity()
{
ZoneStateSpawns e{};
e.id = 0;
e.zone_id = 0;
e.instance_id = 0;
e.is_corpse = 0;
e.decay_in_seconds = 0;
e.npc_id = 0;
e.spawn2_id = 0;
e.spawngroup_id = 0;
e.x = 0;
e.y = 0;
e.z = 0;
e.heading = 0;
e.respawn_time = 0;
e.variance = 0;
e.grid = 0;
e.current_waypoint = 0;
e.path_when_zone_idle = 0;
e.condition_id = 0;
e.condition_min_value = 0;
e.enabled = 1;
e.anim = 0;
e.loot_data = "";
e.entity_variables = "";
e.buffs = "";
e.hp = 0;
e.mana = 0;
e.endurance = 0;
e.created_at = 0;
return e;
}
static ZoneStateSpawns GetZoneStateSpawns(
const std::vector<ZoneStateSpawns> &zone_state_spawnss,
int zone_state_spawns_id
)
{
for (auto &zone_state_spawns : zone_state_spawnss) {
if (zone_state_spawns.id == zone_state_spawns_id) {
return zone_state_spawns;
}
}
return NewEntity();
}
static ZoneStateSpawns FindOne(
Database& db,
int zone_state_spawns_id
)
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
zone_state_spawns_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
ZoneStateSpawns e{};
e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0;
e.zone_id = row[1] ? static_cast<uint32_t>(strtoul(row[1], nullptr, 10)) : 0;
e.instance_id = row[2] ? static_cast<uint32_t>(strtoul(row[2], nullptr, 10)) : 0;
e.is_corpse = row[3] ? static_cast<int8_t>(atoi(row[3])) : 0;
e.decay_in_seconds = row[4] ? static_cast<int32_t>(atoi(row[4])) : 0;
e.npc_id = row[5] ? static_cast<uint32_t>(strtoul(row[5], nullptr, 10)) : 0;
e.spawn2_id = row[6] ? static_cast<uint32_t>(strtoul(row[6], nullptr, 10)) : 0;
e.spawngroup_id = row[7] ? static_cast<uint32_t>(strtoul(row[7], nullptr, 10)) : 0;
e.x = row[8] ? strtof(row[8], nullptr) : 0;
e.y = row[9] ? strtof(row[9], nullptr) : 0;
e.z = row[10] ? strtof(row[10], nullptr) : 0;
e.heading = row[11] ? strtof(row[11], nullptr) : 0;
e.respawn_time = row[12] ? static_cast<uint32_t>(strtoul(row[12], nullptr, 10)) : 0;
e.variance = row[13] ? static_cast<uint32_t>(strtoul(row[13], nullptr, 10)) : 0;
e.grid = row[14] ? static_cast<uint32_t>(strtoul(row[14], nullptr, 10)) : 0;
e.current_waypoint = row[15] ? static_cast<int32_t>(atoi(row[15])) : 0;
e.path_when_zone_idle = row[16] ? static_cast<int16_t>(atoi(row[16])) : 0;
e.condition_id = row[17] ? static_cast<uint16_t>(strtoul(row[17], nullptr, 10)) : 0;
e.condition_min_value = row[18] ? static_cast<int16_t>(atoi(row[18])) : 0;
e.enabled = row[19] ? static_cast<int16_t>(atoi(row[19])) : 1;
e.anim = row[20] ? static_cast<uint16_t>(strtoul(row[20], nullptr, 10)) : 0;
e.loot_data = row[21] ? row[21] : "";
e.entity_variables = row[22] ? row[22] : "";
e.buffs = row[23] ? row[23] : "";
e.hp = row[24] ? strtoll(row[24], nullptr, 10) : 0;
e.mana = row[25] ? strtoll(row[25], nullptr, 10) : 0;
e.endurance = row[26] ? strtoll(row[26], nullptr, 10) : 0;
e.created_at = strtoll(row[27] ? row[27] : "-1", nullptr, 10);
return e;
}
return NewEntity();
}
static int DeleteOne(
Database& db,
int zone_state_spawns_id
)
{
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
zone_state_spawns_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Database& db,
const ZoneStateSpawns &e
)
{
std::vector<std::string> v;
auto columns = Columns();
v.push_back(columns[1] + " = " + std::to_string(e.zone_id));
v.push_back(columns[2] + " = " + std::to_string(e.instance_id));
v.push_back(columns[3] + " = " + std::to_string(e.is_corpse));
v.push_back(columns[4] + " = " + std::to_string(e.decay_in_seconds));
v.push_back(columns[5] + " = " + std::to_string(e.npc_id));
v.push_back(columns[6] + " = " + std::to_string(e.spawn2_id));
v.push_back(columns[7] + " = " + std::to_string(e.spawngroup_id));
v.push_back(columns[8] + " = " + std::to_string(e.x));
v.push_back(columns[9] + " = " + std::to_string(e.y));
v.push_back(columns[10] + " = " + std::to_string(e.z));
v.push_back(columns[11] + " = " + std::to_string(e.heading));
v.push_back(columns[12] + " = " + std::to_string(e.respawn_time));
v.push_back(columns[13] + " = " + std::to_string(e.variance));
v.push_back(columns[14] + " = " + std::to_string(e.grid));
v.push_back(columns[15] + " = " + std::to_string(e.current_waypoint));
v.push_back(columns[16] + " = " + std::to_string(e.path_when_zone_idle));
v.push_back(columns[17] + " = " + std::to_string(e.condition_id));
v.push_back(columns[18] + " = " + std::to_string(e.condition_min_value));
v.push_back(columns[19] + " = " + std::to_string(e.enabled));
v.push_back(columns[20] + " = " + std::to_string(e.anim));
v.push_back(columns[21] + " = '" + Strings::Escape(e.loot_data) + "'");
v.push_back(columns[22] + " = '" + Strings::Escape(e.entity_variables) + "'");
v.push_back(columns[23] + " = '" + Strings::Escape(e.buffs) + "'");
v.push_back(columns[24] + " = " + std::to_string(e.hp));
v.push_back(columns[25] + " = " + std::to_string(e.mana));
v.push_back(columns[26] + " = " + std::to_string(e.endurance));
v.push_back(columns[27] + " = FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")");
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", v),
PrimaryKey(),
e.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static ZoneStateSpawns InsertOne(
Database& db,
ZoneStateSpawns e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.zone_id));
v.push_back(std::to_string(e.instance_id));
v.push_back(std::to_string(e.is_corpse));
v.push_back(std::to_string(e.decay_in_seconds));
v.push_back(std::to_string(e.npc_id));
v.push_back(std::to_string(e.spawn2_id));
v.push_back(std::to_string(e.spawngroup_id));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.respawn_time));
v.push_back(std::to_string(e.variance));
v.push_back(std::to_string(e.grid));
v.push_back(std::to_string(e.current_waypoint));
v.push_back(std::to_string(e.path_when_zone_idle));
v.push_back(std::to_string(e.condition_id));
v.push_back(std::to_string(e.condition_min_value));
v.push_back(std::to_string(e.enabled));
v.push_back(std::to_string(e.anim));
v.push_back("'" + Strings::Escape(e.loot_data) + "'");
v.push_back("'" + Strings::Escape(e.entity_variables) + "'");
v.push_back("'" + Strings::Escape(e.buffs) + "'");
v.push_back(std::to_string(e.hp));
v.push_back(std::to_string(e.mana));
v.push_back(std::to_string(e.endurance));
v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")");
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", v)
)
);
if (results.Success()) {
e.id = results.LastInsertedID();
return e;
}
e = NewEntity();
return e;
}
static int InsertMany(
Database& db,
const std::vector<ZoneStateSpawns> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.zone_id));
v.push_back(std::to_string(e.instance_id));
v.push_back(std::to_string(e.is_corpse));
v.push_back(std::to_string(e.decay_in_seconds));
v.push_back(std::to_string(e.npc_id));
v.push_back(std::to_string(e.spawn2_id));
v.push_back(std::to_string(e.spawngroup_id));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.respawn_time));
v.push_back(std::to_string(e.variance));
v.push_back(std::to_string(e.grid));
v.push_back(std::to_string(e.current_waypoint));
v.push_back(std::to_string(e.path_when_zone_idle));
v.push_back(std::to_string(e.condition_id));
v.push_back(std::to_string(e.condition_min_value));
v.push_back(std::to_string(e.enabled));
v.push_back(std::to_string(e.anim));
v.push_back("'" + Strings::Escape(e.loot_data) + "'");
v.push_back("'" + Strings::Escape(e.entity_variables) + "'");
v.push_back("'" + Strings::Escape(e.buffs) + "'");
v.push_back(std::to_string(e.hp));
v.push_back(std::to_string(e.mana));
v.push_back(std::to_string(e.endurance));
v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")");
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
}
std::vector<std::string> v;
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
Strings::Implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<ZoneStateSpawns> All(Database& db)
{
std::vector<ZoneStateSpawns> all_entries;
auto results = db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
ZoneStateSpawns e{};
e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0;
e.zone_id = row[1] ? static_cast<uint32_t>(strtoul(row[1], nullptr, 10)) : 0;
e.instance_id = row[2] ? static_cast<uint32_t>(strtoul(row[2], nullptr, 10)) : 0;
e.is_corpse = row[3] ? static_cast<int8_t>(atoi(row[3])) : 0;
e.decay_in_seconds = row[4] ? static_cast<int32_t>(atoi(row[4])) : 0;
e.npc_id = row[5] ? static_cast<uint32_t>(strtoul(row[5], nullptr, 10)) : 0;
e.spawn2_id = row[6] ? static_cast<uint32_t>(strtoul(row[6], nullptr, 10)) : 0;
e.spawngroup_id = row[7] ? static_cast<uint32_t>(strtoul(row[7], nullptr, 10)) : 0;
e.x = row[8] ? strtof(row[8], nullptr) : 0;
e.y = row[9] ? strtof(row[9], nullptr) : 0;
e.z = row[10] ? strtof(row[10], nullptr) : 0;
e.heading = row[11] ? strtof(row[11], nullptr) : 0;
e.respawn_time = row[12] ? static_cast<uint32_t>(strtoul(row[12], nullptr, 10)) : 0;
e.variance = row[13] ? static_cast<uint32_t>(strtoul(row[13], nullptr, 10)) : 0;
e.grid = row[14] ? static_cast<uint32_t>(strtoul(row[14], nullptr, 10)) : 0;
e.current_waypoint = row[15] ? static_cast<int32_t>(atoi(row[15])) : 0;
e.path_when_zone_idle = row[16] ? static_cast<int16_t>(atoi(row[16])) : 0;
e.condition_id = row[17] ? static_cast<uint16_t>(strtoul(row[17], nullptr, 10)) : 0;
e.condition_min_value = row[18] ? static_cast<int16_t>(atoi(row[18])) : 0;
e.enabled = row[19] ? static_cast<int16_t>(atoi(row[19])) : 1;
e.anim = row[20] ? static_cast<uint16_t>(strtoul(row[20], nullptr, 10)) : 0;
e.loot_data = row[21] ? row[21] : "";
e.entity_variables = row[22] ? row[22] : "";
e.buffs = row[23] ? row[23] : "";
e.hp = row[24] ? strtoll(row[24], nullptr, 10) : 0;
e.mana = row[25] ? strtoll(row[25], nullptr, 10) : 0;
e.endurance = row[26] ? strtoll(row[26], nullptr, 10) : 0;
e.created_at = strtoll(row[27] ? row[27] : "-1", nullptr, 10);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<ZoneStateSpawns> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<ZoneStateSpawns> all_entries;
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE {}",
BaseSelect(),
where_filter
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
ZoneStateSpawns e{};
e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0;
e.zone_id = row[1] ? static_cast<uint32_t>(strtoul(row[1], nullptr, 10)) : 0;
e.instance_id = row[2] ? static_cast<uint32_t>(strtoul(row[2], nullptr, 10)) : 0;
e.is_corpse = row[3] ? static_cast<int8_t>(atoi(row[3])) : 0;
e.decay_in_seconds = row[4] ? static_cast<int32_t>(atoi(row[4])) : 0;
e.npc_id = row[5] ? static_cast<uint32_t>(strtoul(row[5], nullptr, 10)) : 0;
e.spawn2_id = row[6] ? static_cast<uint32_t>(strtoul(row[6], nullptr, 10)) : 0;
e.spawngroup_id = row[7] ? static_cast<uint32_t>(strtoul(row[7], nullptr, 10)) : 0;
e.x = row[8] ? strtof(row[8], nullptr) : 0;
e.y = row[9] ? strtof(row[9], nullptr) : 0;
e.z = row[10] ? strtof(row[10], nullptr) : 0;
e.heading = row[11] ? strtof(row[11], nullptr) : 0;
e.respawn_time = row[12] ? static_cast<uint32_t>(strtoul(row[12], nullptr, 10)) : 0;
e.variance = row[13] ? static_cast<uint32_t>(strtoul(row[13], nullptr, 10)) : 0;
e.grid = row[14] ? static_cast<uint32_t>(strtoul(row[14], nullptr, 10)) : 0;
e.current_waypoint = row[15] ? static_cast<int32_t>(atoi(row[15])) : 0;
e.path_when_zone_idle = row[16] ? static_cast<int16_t>(atoi(row[16])) : 0;
e.condition_id = row[17] ? static_cast<uint16_t>(strtoul(row[17], nullptr, 10)) : 0;
e.condition_min_value = row[18] ? static_cast<int16_t>(atoi(row[18])) : 0;
e.enabled = row[19] ? static_cast<int16_t>(atoi(row[19])) : 1;
e.anim = row[20] ? static_cast<uint16_t>(strtoul(row[20], nullptr, 10)) : 0;
e.loot_data = row[21] ? row[21] : "";
e.entity_variables = row[22] ? row[22] : "";
e.buffs = row[23] ? row[23] : "";
e.hp = row[24] ? strtoll(row[24], nullptr, 10) : 0;
e.mana = row[25] ? strtoll(row[25], nullptr, 10) : 0;
e.endurance = row[26] ? strtoll(row[26], nullptr, 10) : 0;
e.created_at = strtoll(row[27] ? row[27] : "-1", nullptr, 10);
all_entries.push_back(e);
}
return all_entries;
}
static int DeleteWhere(Database& db, const std::string &where_filter)
{
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {}",
TableName(),
where_filter
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int Truncate(Database& db)
{
auto results = db.QueryDatabase(
fmt::format(
"TRUNCATE TABLE {}",
TableName()
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int64 GetMaxId(Database& db)
{
auto results = db.QueryDatabase(
fmt::format(
"SELECT COALESCE(MAX({}), 0) FROM {}",
PrimaryKey(),
TableName()
)
);
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
}
static int64 Count(Database& db, const std::string &where_filter = "")
{
auto results = db.QueryDatabase(
fmt::format(
"SELECT COUNT(*) FROM {} {}",
TableName(),
(where_filter.empty() ? "" : "WHERE " + where_filter)
)
);
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
}
static std::string BaseReplace()
{
return fmt::format(
"REPLACE INTO {} ({}) ",
TableName(),
ColumnsRaw()
);
}
static int ReplaceOne(
Database& db,
const ZoneStateSpawns &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.zone_id));
v.push_back(std::to_string(e.instance_id));
v.push_back(std::to_string(e.is_corpse));
v.push_back(std::to_string(e.decay_in_seconds));
v.push_back(std::to_string(e.npc_id));
v.push_back(std::to_string(e.spawn2_id));
v.push_back(std::to_string(e.spawngroup_id));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.respawn_time));
v.push_back(std::to_string(e.variance));
v.push_back(std::to_string(e.grid));
v.push_back(std::to_string(e.current_waypoint));
v.push_back(std::to_string(e.path_when_zone_idle));
v.push_back(std::to_string(e.condition_id));
v.push_back(std::to_string(e.condition_min_value));
v.push_back(std::to_string(e.enabled));
v.push_back(std::to_string(e.anim));
v.push_back("'" + Strings::Escape(e.loot_data) + "'");
v.push_back("'" + Strings::Escape(e.entity_variables) + "'");
v.push_back("'" + Strings::Escape(e.buffs) + "'");
v.push_back(std::to_string(e.hp));
v.push_back(std::to_string(e.mana));
v.push_back(std::to_string(e.endurance));
v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")");
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseReplace(),
Strings::Implode(",", v)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int ReplaceMany(
Database& db,
const std::vector<ZoneStateSpawns> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &e: entries) {
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.zone_id));
v.push_back(std::to_string(e.instance_id));
v.push_back(std::to_string(e.is_corpse));
v.push_back(std::to_string(e.decay_in_seconds));
v.push_back(std::to_string(e.npc_id));
v.push_back(std::to_string(e.spawn2_id));
v.push_back(std::to_string(e.spawngroup_id));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.respawn_time));
v.push_back(std::to_string(e.variance));
v.push_back(std::to_string(e.grid));
v.push_back(std::to_string(e.current_waypoint));
v.push_back(std::to_string(e.path_when_zone_idle));
v.push_back(std::to_string(e.condition_id));
v.push_back(std::to_string(e.condition_min_value));
v.push_back(std::to_string(e.enabled));
v.push_back(std::to_string(e.anim));
v.push_back("'" + Strings::Escape(e.loot_data) + "'");
v.push_back("'" + Strings::Escape(e.entity_variables) + "'");
v.push_back("'" + Strings::Escape(e.buffs) + "'");
v.push_back(std::to_string(e.hp));
v.push_back(std::to_string(e.mana));
v.push_back(std::to_string(e.endurance));
v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")");
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
}
std::vector<std::string> v;
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseReplace(),
Strings::Implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
};
#endif //EQEMU_BASE_ZONE_STATE_SPAWNS_REPOSITORY_H
@@ -0,0 +1,14 @@
#ifndef EQEMU_ZONE_STATE_SPAWNS_REPOSITORY_H
#define EQEMU_ZONE_STATE_SPAWNS_REPOSITORY_H
#include "../database.h"
#include "../strings.h"
#include "base/base_zone_state_spawns_repository.h"
class ZoneStateSpawnsRepository: public BaseZoneStateSpawnsRepository {
public:
// Custom extended repository methods here
};
#endif //EQEMU_ZONE_STATE_SPAWNS_REPOSITORY_H
+1
View File
@@ -374,6 +374,7 @@ RULE_BOOL(Zone, AllowCrossZoneSpellsOnBots, false, "Set to true to allow cross z
RULE_BOOL(Zone, AllowCrossZoneSpellsOnMercs, false, "Set to true to allow cross zone spells (cast/remove) to affect mercenaries")
RULE_BOOL(Zone, AllowCrossZoneSpellsOnPets, false, "Set to true to allow cross zone spells (cast/remove) to affect pets")
RULE_BOOL(Zone, ZoneShardQuestMenuOnly, false, "Set to true if you only want quests to show the zone shard menu")
RULE_BOOL(Zone, StateSavingOnShutdown, true, "Set to true if you want zones to save state on shutdown (npcs, corpses, loot, entity variables, buffs etc.)")
RULE_CATEGORY_END()
RULE_CATEGORY(Map)
+1 -1
View File
@@ -42,7 +42,7 @@
* Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
*/
#define CURRENT_BINARY_DATABASE_VERSION 9306
#define CURRENT_BINARY_DATABASE_VERSION 9307
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9054
#endif