mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 21:01:29 +00:00
[Spawn] Split spawn2 enabled into its own state table (#3664)
* [Spawn] Split spawn2 enabled into its own state table * Update spawn2.cpp * Update repo * Make spawn2 enabled/disabled instance aware * Update questmgr.cpp * Make sure packet stuff is aware of instance_id * Update questmgr.cpp * Update database_update_manifest.cpp * Cleanup * Revert "Cleanup" This reverts commit 64b58bfc5273dac13bb88f92522e31773bb80ffc. * Update database_instances.cpp
This commit is contained in:
parent
fad9599642
commit
0811a899d1
@ -4995,6 +4995,26 @@ ADD COLUMN `id` int(11) NOT NULL AUTO_INCREMENT FIRST,
|
||||
DROP PRIMARY KEY,
|
||||
ADD PRIMARY KEY (`id`) USING BTREE,
|
||||
ADD UNIQUE INDEX(`varname`);
|
||||
)"
|
||||
},
|
||||
ManifestEntry{
|
||||
.version = 9241,
|
||||
.description = "2023_10_29_split_spawn2_enabled.sql",
|
||||
.check = "SHOW TABLES LIKE 'spawn2_disabled'",
|
||||
.condition = "empty",
|
||||
.match = "",
|
||||
.sql = R"(
|
||||
CREATE TABLE `spawn2_backup_2023_10_29` LIKE `spawn2`;
|
||||
CREATE TABLE `spawn2_disabled` (
|
||||
`id` bigint(11) NOT NULL AUTO_INCREMENT,
|
||||
`spawn2_id` int(11) DEFAULT NULL,
|
||||
`instance_id` int(11) DEFAULT 0,
|
||||
`disabled` smallint(11) DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `spawn2_id` (`spawn2_id`,`instance_id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
|
||||
INSERT INTO spawn2_disabled (spawn2_id, disabled) SELECT id, 1 FROM spawn2 WHERE enabled = 0;
|
||||
ALTER TABLE `spawn2` DROP COLUMN `enabled`;
|
||||
)"
|
||||
},
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "../common/repositories/raid_members_repository.h"
|
||||
#include "../common/repositories/respawn_times_repository.h"
|
||||
#include "../common/repositories/spawn_condition_values_repository.h"
|
||||
#include "repositories/spawn2_disabled_repository.h"
|
||||
|
||||
|
||||
#include "database.h"
|
||||
@ -49,6 +50,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
|
||||
bool Database::AddClientToInstance(uint16 instance_id, uint32 character_id)
|
||||
{
|
||||
auto e = InstanceListPlayerRepository::NewEntity();
|
||||
@ -553,6 +555,7 @@ void Database::PurgeExpiredInstances()
|
||||
CharacterCorpsesRepository::BuryInstances(*this, imploded_instance_ids);
|
||||
DynamicZoneMembersRepository::DeleteByManyInstances(*this, imploded_instance_ids);
|
||||
DynamicZonesRepository::DeleteWhere(*this, fmt::format("instance_id IN ({})", imploded_instance_ids));
|
||||
Spawn2DisabledRepository::DeleteWhere(*this, fmt::format("instance_id IN ({})", imploded_instance_ids));
|
||||
}
|
||||
|
||||
void Database::SetInstanceDuration(uint16 instance_id, uint32 new_duration)
|
||||
|
||||
@ -345,6 +345,7 @@ namespace DatabaseSchema {
|
||||
"respawn_times",
|
||||
"saylink",
|
||||
"server_scheduled_events",
|
||||
"spawn2_disabled",
|
||||
"player_event_log_settings",
|
||||
"player_event_logs",
|
||||
"shared_task_activity_state",
|
||||
|
||||
354
common/repositories/base/base_spawn2_disabled_repository.h
Normal file
354
common/repositories/base/base_spawn2_disabled_repository.h
Normal file
@ -0,0 +1,354 @@
|
||||
/**
|
||||
* 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://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_SPAWN2_DISABLED_REPOSITORY_H
|
||||
#define EQEMU_BASE_SPAWN2_DISABLED_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseSpawn2DisabledRepository {
|
||||
public:
|
||||
struct Spawn2Disabled {
|
||||
int64_t id;
|
||||
int32_t spawn2_id;
|
||||
int32_t instance_id;
|
||||
int16_t disabled;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"spawn2_id",
|
||||
"instance_id",
|
||||
"disabled",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"spawn2_id",
|
||||
"instance_id",
|
||||
"disabled",
|
||||
};
|
||||
}
|
||||
|
||||
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("spawn2_disabled");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static Spawn2Disabled NewEntity()
|
||||
{
|
||||
Spawn2Disabled e{};
|
||||
|
||||
e.id = 0;
|
||||
e.spawn2_id = 0;
|
||||
e.instance_id = 0;
|
||||
e.disabled = 0;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
static Spawn2Disabled GetSpawn2Disabled(
|
||||
const std::vector<Spawn2Disabled> &spawn2_disableds,
|
||||
int spawn2_disabled_id
|
||||
)
|
||||
{
|
||||
for (auto &spawn2_disabled : spawn2_disableds) {
|
||||
if (spawn2_disabled.id == spawn2_disabled_id) {
|
||||
return spawn2_disabled;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static Spawn2Disabled FindOne(
|
||||
Database& db,
|
||||
int spawn2_disabled_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
spawn2_disabled_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
Spawn2Disabled e{};
|
||||
|
||||
e.id = strtoll(row[0], nullptr, 10);
|
||||
e.spawn2_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.instance_id = static_cast<int32_t>(atoi(row[2]));
|
||||
e.disabled = static_cast<int16_t>(atoi(row[3]));
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int spawn2_disabled_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
spawn2_disabled_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
const Spawn2Disabled &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.spawn2_id));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.instance_id));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.disabled));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static Spawn2Disabled InsertOne(
|
||||
Database& db,
|
||||
Spawn2Disabled e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.spawn2_id));
|
||||
v.push_back(std::to_string(e.instance_id));
|
||||
v.push_back(std::to_string(e.disabled));
|
||||
|
||||
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<Spawn2Disabled> &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.spawn2_id));
|
||||
v.push_back(std::to_string(e.instance_id));
|
||||
v.push_back(std::to_string(e.disabled));
|
||||
|
||||
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<Spawn2Disabled> All(Database& db)
|
||||
{
|
||||
std::vector<Spawn2Disabled> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Spawn2Disabled e{};
|
||||
|
||||
e.id = strtoll(row[0], nullptr, 10);
|
||||
e.spawn2_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.instance_id = static_cast<int32_t>(atoi(row[2]));
|
||||
e.disabled = static_cast<int16_t>(atoi(row[3]));
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<Spawn2Disabled> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<Spawn2Disabled> 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) {
|
||||
Spawn2Disabled e{};
|
||||
|
||||
e.id = strtoll(row[0], nullptr, 10);
|
||||
e.spawn2_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.instance_id = static_cast<int32_t>(atoi(row[2]));
|
||||
e.disabled = static_cast<int16_t>(atoi(row[3]));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_SPAWN2_DISABLED_REPOSITORY_H
|
||||
@ -16,6 +16,7 @@
|
||||
#include "../../strings.h"
|
||||
#include <ctime>
|
||||
|
||||
|
||||
class BaseSpawn2Repository {
|
||||
public:
|
||||
struct Spawn2 {
|
||||
@ -33,7 +34,6 @@ public:
|
||||
int8_t path_when_zone_idle;
|
||||
uint32_t _condition;
|
||||
int32_t cond_value;
|
||||
uint8_t enabled;
|
||||
uint8_t animation;
|
||||
int8_t min_expansion;
|
||||
int8_t max_expansion;
|
||||
@ -63,7 +63,6 @@ public:
|
||||
"path_when_zone_idle",
|
||||
"_condition",
|
||||
"cond_value",
|
||||
"enabled",
|
||||
"animation",
|
||||
"min_expansion",
|
||||
"max_expansion",
|
||||
@ -89,7 +88,6 @@ public:
|
||||
"path_when_zone_idle",
|
||||
"_condition",
|
||||
"cond_value",
|
||||
"enabled",
|
||||
"animation",
|
||||
"min_expansion",
|
||||
"max_expansion",
|
||||
@ -149,7 +147,6 @@ public:
|
||||
e.path_when_zone_idle = 0;
|
||||
e._condition = 0;
|
||||
e.cond_value = 1;
|
||||
e.enabled = 1;
|
||||
e.animation = 0;
|
||||
e.min_expansion = -1;
|
||||
e.max_expansion = -1;
|
||||
@ -180,8 +177,9 @@ public:
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
spawn2_id
|
||||
)
|
||||
);
|
||||
@ -204,12 +202,11 @@ public:
|
||||
e.path_when_zone_idle = static_cast<int8_t>(atoi(row[11]));
|
||||
e._condition = static_cast<uint32_t>(strtoul(row[12], nullptr, 10));
|
||||
e.cond_value = static_cast<int32_t>(atoi(row[13]));
|
||||
e.enabled = static_cast<uint8_t>(strtoul(row[14], nullptr, 10));
|
||||
e.animation = static_cast<uint8_t>(strtoul(row[15], nullptr, 10));
|
||||
e.min_expansion = static_cast<int8_t>(atoi(row[16]));
|
||||
e.max_expansion = static_cast<int8_t>(atoi(row[17]));
|
||||
e.content_flags = row[18] ? row[18] : "";
|
||||
e.content_flags_disabled = row[19] ? row[19] : "";
|
||||
e.animation = static_cast<uint8_t>(strtoul(row[14], nullptr, 10));
|
||||
e.min_expansion = static_cast<int8_t>(atoi(row[15]));
|
||||
e.max_expansion = static_cast<int8_t>(atoi(row[16]));
|
||||
e.content_flags = row[17] ? row[17] : "";
|
||||
e.content_flags_disabled = row[18] ? row[18] : "";
|
||||
|
||||
return e;
|
||||
}
|
||||
@ -256,12 +253,11 @@ public:
|
||||
v.push_back(columns[11] + " = " + std::to_string(e.path_when_zone_idle));
|
||||
v.push_back(columns[12] + " = " + std::to_string(e._condition));
|
||||
v.push_back(columns[13] + " = " + std::to_string(e.cond_value));
|
||||
v.push_back(columns[14] + " = " + std::to_string(e.enabled));
|
||||
v.push_back(columns[15] + " = " + std::to_string(e.animation));
|
||||
v.push_back(columns[16] + " = " + std::to_string(e.min_expansion));
|
||||
v.push_back(columns[17] + " = " + std::to_string(e.max_expansion));
|
||||
v.push_back(columns[18] + " = '" + Strings::Escape(e.content_flags) + "'");
|
||||
v.push_back(columns[19] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
|
||||
v.push_back(columns[14] + " = " + std::to_string(e.animation));
|
||||
v.push_back(columns[15] + " = " + std::to_string(e.min_expansion));
|
||||
v.push_back(columns[16] + " = " + std::to_string(e.max_expansion));
|
||||
v.push_back(columns[17] + " = '" + Strings::Escape(e.content_flags) + "'");
|
||||
v.push_back(columns[18] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@ -297,7 +293,6 @@ public:
|
||||
v.push_back(std::to_string(e.path_when_zone_idle));
|
||||
v.push_back(std::to_string(e._condition));
|
||||
v.push_back(std::to_string(e.cond_value));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
v.push_back(std::to_string(e.animation));
|
||||
v.push_back(std::to_string(e.min_expansion));
|
||||
v.push_back(std::to_string(e.max_expansion));
|
||||
@ -346,7 +341,6 @@ public:
|
||||
v.push_back(std::to_string(e.path_when_zone_idle));
|
||||
v.push_back(std::to_string(e._condition));
|
||||
v.push_back(std::to_string(e.cond_value));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
v.push_back(std::to_string(e.animation));
|
||||
v.push_back(std::to_string(e.min_expansion));
|
||||
v.push_back(std::to_string(e.max_expansion));
|
||||
@ -399,12 +393,11 @@ public:
|
||||
e.path_when_zone_idle = static_cast<int8_t>(atoi(row[11]));
|
||||
e._condition = static_cast<uint32_t>(strtoul(row[12], nullptr, 10));
|
||||
e.cond_value = static_cast<int32_t>(atoi(row[13]));
|
||||
e.enabled = static_cast<uint8_t>(strtoul(row[14], nullptr, 10));
|
||||
e.animation = static_cast<uint8_t>(strtoul(row[15], nullptr, 10));
|
||||
e.min_expansion = static_cast<int8_t>(atoi(row[16]));
|
||||
e.max_expansion = static_cast<int8_t>(atoi(row[17]));
|
||||
e.content_flags = row[18] ? row[18] : "";
|
||||
e.content_flags_disabled = row[19] ? row[19] : "";
|
||||
e.animation = static_cast<uint8_t>(strtoul(row[14], nullptr, 10));
|
||||
e.min_expansion = static_cast<int8_t>(atoi(row[15]));
|
||||
e.max_expansion = static_cast<int8_t>(atoi(row[16]));
|
||||
e.content_flags = row[17] ? row[17] : "";
|
||||
e.content_flags_disabled = row[18] ? row[18] : "";
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
@ -443,12 +436,11 @@ public:
|
||||
e.path_when_zone_idle = static_cast<int8_t>(atoi(row[11]));
|
||||
e._condition = static_cast<uint32_t>(strtoul(row[12], nullptr, 10));
|
||||
e.cond_value = static_cast<int32_t>(atoi(row[13]));
|
||||
e.enabled = static_cast<uint8_t>(strtoul(row[14], nullptr, 10));
|
||||
e.animation = static_cast<uint8_t>(strtoul(row[15], nullptr, 10));
|
||||
e.min_expansion = static_cast<int8_t>(atoi(row[16]));
|
||||
e.max_expansion = static_cast<int8_t>(atoi(row[17]));
|
||||
e.content_flags = row[18] ? row[18] : "";
|
||||
e.content_flags_disabled = row[19] ? row[19] : "";
|
||||
e.animation = static_cast<uint8_t>(strtoul(row[14], nullptr, 10));
|
||||
e.min_expansion = static_cast<int8_t>(atoi(row[15]));
|
||||
e.max_expansion = static_cast<int8_t>(atoi(row[16]));
|
||||
e.content_flags = row[17] ? row[17] : "";
|
||||
e.content_flags_disabled = row[18] ? row[18] : "";
|
||||
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
50
common/repositories/spawn2_disabled_repository.h
Normal file
50
common/repositories/spawn2_disabled_repository.h
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef EQEMU_SPAWN2_DISABLED_REPOSITORY_H
|
||||
#define EQEMU_SPAWN2_DISABLED_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../strings.h"
|
||||
#include "base/base_spawn2_disabled_repository.h"
|
||||
|
||||
class Spawn2DisabledRepository: public BaseSpawn2DisabledRepository {
|
||||
public:
|
||||
|
||||
/**
|
||||
* This file was auto generated and can be modified and extended upon
|
||||
*
|
||||
* Base repository methods are automatically
|
||||
* generated in the "base" version of this repository. The base repository
|
||||
* is immutable and to be left untouched, while methods in this class
|
||||
* are used as extension methods for more specific persistence-layer
|
||||
* accessors or mutators.
|
||||
*
|
||||
* Base Methods (Subject to be expanded upon in time)
|
||||
*
|
||||
* Note: Not all tables are designed appropriately to fit functionality with all base methods
|
||||
*
|
||||
* InsertOne
|
||||
* UpdateOne
|
||||
* DeleteOne
|
||||
* FindOne
|
||||
* GetWhere(std::string where_filter)
|
||||
* DeleteWhere(std::string where_filter)
|
||||
* InsertMany
|
||||
* All
|
||||
*
|
||||
* Example custom methods in a repository
|
||||
*
|
||||
* Spawn2DisabledRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* Spawn2DisabledRepository::GetWhereNeverExpires()
|
||||
* Spawn2DisabledRepository::GetWhereXAndY()
|
||||
* Spawn2DisabledRepository::DeleteWhereXAndY()
|
||||
*
|
||||
* Most of the above could be covered by base methods, but if you as a developer
|
||||
* find yourself re-using logic for other parts of the code, its best to just make a
|
||||
* method that can be re-used easily elsewhere especially if it can use a base repository
|
||||
* method and encapsulate filters there
|
||||
*/
|
||||
|
||||
// Custom extended repository methods here
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_SPAWN2_DISABLED_REPOSITORY_H
|
||||
@ -1142,10 +1142,10 @@ struct ServerInstanceUpdateTime_Struct
|
||||
uint32 new_duration;
|
||||
};
|
||||
|
||||
struct ServerSpawnStatusChange_Struct
|
||||
{
|
||||
struct ServerSpawnStatusChange_Struct {
|
||||
uint32 id;
|
||||
bool new_status;
|
||||
bool new_status;
|
||||
uint32 instance_id;
|
||||
};
|
||||
|
||||
struct ServerQGlobalUpdate_Struct
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
* Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
|
||||
*/
|
||||
|
||||
#define CURRENT_BINARY_DATABASE_VERSION 9240
|
||||
#define CURRENT_BINARY_DATABASE_VERSION 9241
|
||||
|
||||
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9040
|
||||
|
||||
|
||||
@ -359,22 +359,25 @@ Mob *QuestManager::spawn_from_spawn2(uint32 spawn2_id)
|
||||
|
||||
void QuestManager::enable_spawn2(uint32 spawn2_id)
|
||||
{
|
||||
database.UpdateSpawn2Status(spawn2_id, 1);
|
||||
database.UpdateSpawn2Status(spawn2_id, 1, zone->GetInstanceID());
|
||||
auto pack = new ServerPacket(ServerOP_SpawnStatusChange, sizeof(ServerSpawnStatusChange_Struct));
|
||||
ServerSpawnStatusChange_Struct* ssc = (ServerSpawnStatusChange_Struct*) pack->pBuffer;
|
||||
ssc->id = spawn2_id;
|
||||
ssc->new_status = 1;
|
||||
auto *ssc = (ServerSpawnStatusChange_Struct *) pack->pBuffer;
|
||||
ssc->id = spawn2_id;
|
||||
ssc->new_status = true;
|
||||
ssc->instance_id = zone->GetInstanceID();
|
||||
worldserver.SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
}
|
||||
|
||||
void QuestManager::disable_spawn2(uint32 spawn2_id)
|
||||
{
|
||||
database.UpdateSpawn2Status(spawn2_id, 0);
|
||||
database.UpdateSpawn2Status(spawn2_id, 0, zone->GetInstanceID());
|
||||
auto pack = new ServerPacket(ServerOP_SpawnStatusChange, sizeof(ServerSpawnStatusChange_Struct));
|
||||
ServerSpawnStatusChange_Struct* ssc = (ServerSpawnStatusChange_Struct*) pack->pBuffer;
|
||||
ssc->id = spawn2_id;
|
||||
ssc->new_status = 0;
|
||||
auto *ssc = (ServerSpawnStatusChange_Struct *) pack->pBuffer;
|
||||
ssc->id = spawn2_id;
|
||||
ssc->new_status = false;
|
||||
ssc->instance_id = zone->GetInstanceID();
|
||||
|
||||
worldserver.SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
}
|
||||
|
||||
101
zone/spawn2.cpp
101
zone/spawn2.cpp
@ -27,6 +27,8 @@
|
||||
#include "zone.h"
|
||||
#include "zonedb.h"
|
||||
#include "../common/repositories/criteria/content_filter_criteria.h"
|
||||
#include "../common/repositories/spawn2_repository.h"
|
||||
#include "../common/repositories/spawn2_disabled_repository.h"
|
||||
|
||||
extern EntityList entity_list;
|
||||
extern Zone* zone;
|
||||
@ -468,60 +470,65 @@ bool ZoneDatabase::PopulateZoneSpawnList(uint32 zoneid, LinkedList<Spawn2*> &spa
|
||||
LogInfo("Loaded [{}] respawn timer(s)", Strings::Commify(results.RowCount()));
|
||||
|
||||
const char *zone_name = ZoneName(zoneid);
|
||||
std::string query = fmt::format(
|
||||
"SELECT "
|
||||
"id, "
|
||||
"spawngroupID, "
|
||||
"x, "
|
||||
"y, "
|
||||
"z, "
|
||||
"heading, "
|
||||
"respawntime, "
|
||||
"variance, "
|
||||
"pathgrid, "
|
||||
"path_when_zone_idle, "
|
||||
"_condition, "
|
||||
"cond_value, "
|
||||
"enabled, "
|
||||
"animation "
|
||||
"FROM "
|
||||
"spawn2 "
|
||||
"WHERE TRUE {} AND zone = '{}' AND (version = {} OR version = -1) ",
|
||||
ContentFilterCriteria::apply(),
|
||||
zone_name,
|
||||
version
|
||||
);
|
||||
results = QueryDatabase(query);
|
||||
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
auto spawns = Spawn2Repository::GetWhere(
|
||||
content_db, fmt::format(
|
||||
"TRUE {} AND zone = '{}' AND (version = {} OR version = -1) ",
|
||||
ContentFilterCriteria::apply(),
|
||||
zone_name,
|
||||
version
|
||||
)
|
||||
);
|
||||
|
||||
std::vector<uint32> spawn2_ids;
|
||||
for (auto &s: spawns) {
|
||||
spawn2_ids.push_back(s.id);
|
||||
}
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
std::vector<Spawn2DisabledRepository::Spawn2Disabled> disabled_spawns = {};
|
||||
if (!spawn2_ids.empty()) {
|
||||
disabled_spawns = Spawn2DisabledRepository::GetWhere(
|
||||
database,
|
||||
fmt::format(
|
||||
"spawn2_id IN ({}) and instance_id = {}",
|
||||
Strings::Join(spawn2_ids, ","),
|
||||
zone->GetInstanceID()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
for (auto &s: spawns) {
|
||||
uint32 spawn_time_left = 0;
|
||||
Spawn2* new_spawn = 0;
|
||||
bool perl_enabled = Strings::ToInt(row[12]) == 1 ? true : false;
|
||||
if (spawn_times.count(s.id) != 0) {
|
||||
spawn_time_left = spawn_times[s.id];
|
||||
}
|
||||
|
||||
if (spawn_times.count(Strings::ToInt(row[0])) != 0)
|
||||
spawn_time_left = spawn_times[Strings::ToInt(row[0])];
|
||||
// load from spawn2_disabled
|
||||
bool spawn_enabled = true;
|
||||
// check if spawn is disabled
|
||||
for (auto &ds: disabled_spawns) {
|
||||
if (ds.spawn2_id == s.id) {
|
||||
spawn_enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
new_spawn = new Spawn2(
|
||||
Strings::ToInt(row[0]), // uint32 in_spawn2_id
|
||||
Strings::ToInt(row[1]), // uint32 spawngroup_id
|
||||
Strings::ToFloat(row[2]), // float in_x
|
||||
Strings::ToFloat(row[3]), // float in_y
|
||||
Strings::ToFloat(row[4]), // float in_z
|
||||
Strings::ToFloat(row[5]), // float in_heading
|
||||
Strings::ToInt(row[6]), // uint32 respawn
|
||||
Strings::ToInt(row[7]), // uint32 variance
|
||||
spawn_time_left, // uint32 timeleft
|
||||
Strings::ToInt(row[8]), // uint32 grid
|
||||
(bool)Strings::ToInt(row[9]), // bool path_when_zone_idle
|
||||
Strings::ToInt(row[10]), // uint16 in_cond_id
|
||||
Strings::ToInt(row[11]), // int16 in_min_value
|
||||
perl_enabled, // bool in_enabled
|
||||
(EmuAppearance)Strings::ToInt(row[13]) // EmuAppearance anim
|
||||
auto new_spawn = new Spawn2(
|
||||
s.id,
|
||||
s.spawngroupID,
|
||||
s.x,
|
||||
s.y,
|
||||
s.z,
|
||||
s.heading,
|
||||
s.respawntime,
|
||||
s.variance,
|
||||
spawn_time_left,
|
||||
s.pathgrid,
|
||||
(bool) s.path_when_zone_idle,
|
||||
s._condition,
|
||||
(int16) s.cond_value,
|
||||
spawn_enabled,
|
||||
(EmuAppearance) s.animation
|
||||
);
|
||||
|
||||
spawn2_list.Insert(new_spawn);
|
||||
|
||||
@ -1729,28 +1729,27 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
|
||||
if (zone)
|
||||
{
|
||||
ServerSpawnStatusChange_Struct *ssc = (ServerSpawnStatusChange_Struct*)pack->pBuffer;
|
||||
LinkedListIterator<Spawn2*> iterator(zone->spawn2_list);
|
||||
if (ssc->instance_id != zone->GetInstanceID()) {
|
||||
break;
|
||||
}
|
||||
|
||||
LinkedListIterator<Spawn2 *> iterator(zone->spawn2_list);
|
||||
iterator.Reset();
|
||||
Spawn2 *found_spawn = nullptr;
|
||||
while (iterator.MoreElements())
|
||||
{
|
||||
Spawn2* cur = iterator.GetData();
|
||||
if (cur->GetID() == ssc->id)
|
||||
{
|
||||
while (iterator.MoreElements()) {
|
||||
Spawn2 *cur = iterator.GetData();
|
||||
if (cur->GetID() == ssc->id) {
|
||||
found_spawn = cur;
|
||||
break;
|
||||
}
|
||||
iterator.Advance();
|
||||
}
|
||||
|
||||
if (found_spawn)
|
||||
{
|
||||
if (ssc->new_status == 0)
|
||||
{
|
||||
if (found_spawn) {
|
||||
if (ssc->new_status == 0) {
|
||||
found_spawn->Disable();
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
found_spawn->Enable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "../common/repositories/character_pet_info_repository.h"
|
||||
#include "../common/repositories/character_buffs_repository.h"
|
||||
#include "../common/repositories/criteria/content_filter_criteria.h"
|
||||
#include "../common/repositories/spawn2_disabled_repository.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
@ -171,10 +172,26 @@ uint32 ZoneDatabase::GetSpawnTimeLeft(uint32 id, uint16 instance_id)
|
||||
|
||||
}
|
||||
|
||||
void ZoneDatabase::UpdateSpawn2Status(uint32 id, uint8 new_status)
|
||||
void ZoneDatabase::UpdateSpawn2Status(uint32 id, uint8 new_status, uint32 instance_id)
|
||||
{
|
||||
std::string query = StringFormat("UPDATE spawn2 SET enabled = %i WHERE id = %lu", new_status, (unsigned long)id);
|
||||
QueryDatabase(query);
|
||||
auto spawns = Spawn2DisabledRepository::GetWhere(
|
||||
*this,
|
||||
fmt::format("spawn2_id = {} and instance_id = {}", id, instance_id)
|
||||
);
|
||||
if (!spawns.empty()) {
|
||||
auto spawn = spawns[0];
|
||||
// 1 = enabled 0 = disabled
|
||||
spawn.disabled = new_status ? 0 : 1;
|
||||
spawn.instance_id = instance_id;
|
||||
Spawn2DisabledRepository::UpdateOne(*this, spawn);
|
||||
return;
|
||||
}
|
||||
|
||||
auto spawn = Spawn2DisabledRepository::NewEntity();
|
||||
spawn.spawn2_id = id;
|
||||
spawn.instance_id = instance_id;
|
||||
spawn.disabled = new_status ? 0 : 1;
|
||||
Spawn2DisabledRepository::InsertOne(*this, spawn);
|
||||
}
|
||||
|
||||
bool ZoneDatabase::SetSpecialAttkFlag(uint8 id, const char* flag) {
|
||||
|
||||
@ -529,7 +529,7 @@ public:
|
||||
bool CreateSpawn2(Client *c, uint32 spawngroup, const char* zone, const glm::vec4& position, uint32 respawn, uint32 variance, uint16 condition, int16 cond_value);
|
||||
void UpdateRespawnTime(uint32 id, uint16 instance_id,uint32 timeleft);
|
||||
uint32 GetSpawnTimeLeft(uint32 id, uint16 instance_id);
|
||||
void UpdateSpawn2Status(uint32 id, uint8 new_status);
|
||||
void UpdateSpawn2Status(uint32 id, uint8 new_status, uint32 instance_id);
|
||||
|
||||
/* Grids/Paths */
|
||||
uint32 GetFreeGrid(uint16 zoneid);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user