mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-03 21:56:36 +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 64b58bfc52.
* Update database_instances.cpp
This commit is contained in:
+11
-8
@@ -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);
|
||||
}
|
||||
|
||||
+54
-47
@@ -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);
|
||||
|
||||
+11
-12
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
+20
-3
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user