Merge pull request #65 from Valorith/codex/preserve-pet-suppression-zoning

Preserve suppressed pet buffs across zoning
This commit is contained in:
Vayle 2026-03-09 13:41:00 -04:00 committed by GitHub
commit 4b0dab8377
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 193 additions and 22 deletions

View File

@ -7199,6 +7199,18 @@ ALTER TABLE `character_parcels_containers`
.sql = R"(
ALTER TABLE `character_buffs`
ADD COLUMN `suppressed` tinyint(1) unsigned NOT NULL DEFAULT 0 AFTER `instrument_mod`;
)",
.content_schema_update = false
},
ManifestEntry{
.version = 9330,
.description = "2026_03_09_add_suppressed_to_character_pet_buffs.sql",
.check = "SHOW COLUMNS FROM `character_pet_buffs` LIKE 'suppressed'",
.condition = "empty",
.match = "",
.sql = R"(
ALTER TABLE `character_pet_buffs`
ADD COLUMN `suppressed` tinyint(1) unsigned NOT NULL DEFAULT 0 AFTER `instrument_mod`;
)",
.content_schema_update = false
},

View File

@ -7,6 +7,20 @@
class CharacterPetBuffsRepository: public BaseCharacterPetBuffsRepository {
public:
struct CharacterPetBuffsWithSuppressed {
int32_t char_id;
int32_t pet;
int32_t slot;
int32_t spell_id;
int8_t caster_level;
std::string castername;
int32_t ticsremaining;
int32_t counters;
int32_t numhits;
int32_t rune;
uint8_t instrument_mod;
uint8_t suppressed;
};
/**
* This file was auto generated and can be modified and extended upon
@ -41,8 +55,110 @@ public:
* 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
static CharacterPetBuffsWithSuppressed NewEntityWithSuppressed()
{
return CharacterPetBuffsWithSuppressed{
.char_id = 0,
.pet = 0,
.slot = 0,
.spell_id = 0,
.caster_level = 0,
.castername = "",
.ticsremaining = 0,
.counters = 0,
.numhits = 0,
.rune = 0,
.instrument_mod = 10,
.suppressed = 0,
};
}
static std::vector<CharacterPetBuffsWithSuppressed> GetWhereWithSuppressed(
Database& db,
const std::string& where_filter
)
{
std::vector<CharacterPetBuffsWithSuppressed> entries;
auto results = db.QueryDatabase(
fmt::format(
"SELECT {}, `suppressed` FROM {} WHERE {}",
SelectColumnsRaw(),
TableName(),
where_filter
)
);
entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
auto e = NewEntityWithSuppressed();
e.char_id = row[0] ? static_cast<int32_t>(atoi(row[0])) : 0;
e.pet = row[1] ? static_cast<int32_t>(atoi(row[1])) : 0;
e.slot = row[2] ? static_cast<int32_t>(atoi(row[2])) : 0;
e.spell_id = row[3] ? static_cast<int32_t>(atoi(row[3])) : 0;
e.caster_level = row[4] ? static_cast<int8_t>(atoi(row[4])) : 0;
e.castername = row[5] ? row[5] : "";
e.ticsremaining = row[6] ? static_cast<int32_t>(atoi(row[6])) : 0;
e.counters = row[7] ? static_cast<int32_t>(atoi(row[7])) : 0;
e.numhits = row[8] ? static_cast<int32_t>(atoi(row[8])) : 0;
e.rune = row[9] ? static_cast<int32_t>(atoi(row[9])) : 0;
e.instrument_mod = row[10] ? static_cast<uint8_t>(strtoul(row[10], nullptr, 10)) : 10;
e.suppressed = row[11] ? static_cast<uint8_t>(strtoul(row[11], nullptr, 10)) : 0;
entries.emplace_back(e);
}
return entries;
}
static int InsertManyWithSuppressed(
Database& db,
const std::vector<CharacterPetBuffsWithSuppressed>& entries
)
{
if (entries.empty()) {
return 0;
}
std::vector<std::string> insert_chunks;
insert_chunks.reserve(entries.size());
for (const auto& e : entries) {
std::vector<std::string> values;
values.reserve(12);
values.push_back(std::to_string(e.char_id));
values.push_back(std::to_string(e.pet));
values.push_back(std::to_string(e.slot));
values.push_back(std::to_string(e.spell_id));
values.push_back(std::to_string(e.caster_level));
values.push_back("'" + Strings::Escape(e.castername) + "'");
values.push_back(std::to_string(e.ticsremaining));
values.push_back(std::to_string(e.counters));
values.push_back(std::to_string(e.numhits));
values.push_back(std::to_string(e.rune));
values.push_back(std::to_string(e.instrument_mod));
values.push_back(std::to_string(e.suppressed));
insert_chunks.push_back("(" + Strings::Implode(",", values) + ")");
}
auto results = db.QueryDatabase(
fmt::format(
"INSERT INTO {} ({}, `suppressed`) VALUES {}",
TableName(),
ColumnsRaw(),
Strings::Implode(",", insert_chunks)
)
);
return results.Success() ? results.RowsAffected() : 0;
}
};

View File

@ -41,6 +41,6 @@
* Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
*/
#define CURRENT_BINARY_DATABASE_VERSION 9328
#define CURRENT_BINARY_DATABASE_VERSION 9330
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9054
#define CUSTOM_BINARY_DATABASE_VERSION 0

View File

@ -0,0 +1,3 @@
-- Add suppressed column to character_pet_buffs to persist pet buff suppression state across zones
ALTER TABLE `character_pet_buffs`
ADD COLUMN `suppressed` tinyint(1) unsigned NOT NULL DEFAULT 0 AFTER `instrument_mod`;

View File

@ -481,14 +481,17 @@ void NPC::GetPetState(SpellBuff_Struct *pet_buffs, uint32 *items, char *name) {
//save their buffs.
for (int i=EQ::invslot::EQUIPMENT_BEGIN; i < GetPetMaxTotalSlots(); i++) {
if (IsValidSpell(buffs[i].spellid)) {
pet_buffs[i].spellid = buffs[i].spellid;
if (IsValidOrSuppressedSpell(buffs[i].spellid)) {
const bool suppressed = buffs[i].spellid == SPELL_SUPPRESSED;
pet_buffs[i].spellid = suppressed ? SPELL_SUPPRESSED : buffs[i].spellid;
pet_buffs[i].effect_type = i+1;
pet_buffs[i].duration = buffs[i].ticsremaining;
pet_buffs[i].duration = suppressed ? buffs[i].suppressedticsremaining : buffs[i].ticsremaining;
pet_buffs[i].level = buffs[i].casterlevel;
pet_buffs[i].bard_modifier = 10;
pet_buffs[i].counters = buffs[i].counters;
pet_buffs[i].bard_modifier = buffs[i].instrument_mod;
pet_buffs[i].player_id = suppressed ? buffs[i].suppressedid : 0;
}
else {
pet_buffs[i].spellid = SPELL_UNKNOWN;
@ -496,6 +499,7 @@ void NPC::GetPetState(SpellBuff_Struct *pet_buffs, uint32 *items, char *name) {
pet_buffs[i].level = 0;
pet_buffs[i].bard_modifier = 10;
pet_buffs[i].counters = 0;
pet_buffs[i].player_id = 0;
}
}
}
@ -505,32 +509,53 @@ void NPC::SetPetState(SpellBuff_Struct *pet_buffs, uint32 *items) {
int i;
for (i = 0; i < GetPetMaxTotalSlots(); i++) {
const bool suppressed = pet_buffs[i].spellid == SPELL_SUPPRESSED;
uint32 restored_spell_id = suppressed ? pet_buffs[i].player_id : pet_buffs[i].spellid;
for(int z = 0; z < GetPetMaxTotalSlots(); z++) {
// check for duplicates
if(IsValidSpell(buffs[z].spellid) && buffs[z].spellid == pet_buffs[i].spellid) {
// check for duplicates
if (!IsValidOrSuppressedSpell(buffs[z].spellid)) {
continue;
}
const uint32 existing_spell_id = buffs[z].spellid == SPELL_SUPPRESSED ? buffs[z].suppressedid : buffs[z].spellid;
if (existing_spell_id == restored_spell_id) {
buffs[z].spellid = SPELL_UNKNOWN;
buffs[z].suppressedid = 0;
buffs[z].suppressedticsremaining = -1;
pet_buffs[i].spellid = 0xFFFFFFFF;
pet_buffs[i].player_id = 0;
restored_spell_id = 0xFFFFFFFF;
}
}
if (pet_buffs[i].spellid <= (uint32)SPDAT_RECORDS && pet_buffs[i].spellid != 0 && (pet_buffs[i].duration > 0 || pet_buffs[i].duration == -1)) {
if (
IsValidSpell(restored_spell_id) &&
(pet_buffs[i].duration > 0 || pet_buffs[i].duration == -1)
) {
if(pet_buffs[i].level == 0 || pet_buffs[i].level > 100)
pet_buffs[i].level = 1;
buffs[i].spellid = pet_buffs[i].spellid;
buffs[i].ticsremaining = pet_buffs[i].duration;
buffs[i].spellid = suppressed ? SPELL_SUPPRESSED : restored_spell_id;
buffs[i].ticsremaining = suppressed ? 0 : pet_buffs[i].duration;
buffs[i].casterlevel = pet_buffs[i].level;
buffs[i].casterid = 0;
buffs[i].counters = pet_buffs[i].counters;
buffs[i].hit_number = spells[pet_buffs[i].spellid].hit_number;
buffs[i].hit_number = spells[restored_spell_id].hit_number;
buffs[i].instrument_mod = pet_buffs[i].bard_modifier;
buffs[i].suppressedid = suppressed ? restored_spell_id : 0;
buffs[i].suppressedticsremaining = suppressed ? pet_buffs[i].duration : -1;
}
else {
buffs[i].spellid = SPELL_UNKNOWN;
buffs[i].suppressedid = 0;
buffs[i].suppressedticsremaining = -1;
pet_buffs[i].spellid = 0xFFFFFFFF;
pet_buffs[i].effect_type = 0;
pet_buffs[i].level = 0;
pet_buffs[i].duration = 0;
pet_buffs[i].bard_modifier = 0;
pet_buffs[i].player_id = 0;
}
}
for (int j1=0; j1 < GetPetMaxTotalSlots(); j1++) {

View File

@ -3128,8 +3128,8 @@ void ZoneDatabase::SavePetInfo(Client *client)
std::vector<CharacterPetInfoRepository::CharacterPetInfo> pet_infos;
auto pet_info = CharacterPetInfoRepository::NewEntity();
std::vector<CharacterPetBuffsRepository::CharacterPetBuffs> pet_buffs;
auto pet_buff = CharacterPetBuffsRepository::NewEntity();
std::vector<CharacterPetBuffsRepository::CharacterPetBuffsWithSuppressed> pet_buffs;
auto pet_buff = CharacterPetBuffsRepository::NewEntityWithSuppressed();
std::vector<CharacterPetInventoryRepository::CharacterPetInventory> inventory;
auto item = CharacterPetInventoryRepository::NewEntity();
@ -3161,28 +3161,32 @@ void ZoneDatabase::SavePetInfo(Client *client)
);
for (int slot_id = 0; slot_id < max_slots; slot_id++) {
if (!IsValidSpell(p->Buffs[slot_id].spellid)) {
if (!IsValidOrSuppressedSpell(p->Buffs[slot_id].spellid)) {
continue;
}
pet_buff_count++;
}
pet_buffs.reserve(pet_buff_count);
pet_buffs.reserve(pet_buffs.size() + pet_buff_count);
for (int slot_id = 0; slot_id < max_slots; slot_id++) {
if (!IsValidSpell(p->Buffs[slot_id].spellid)) {
if (!IsValidOrSuppressedSpell(p->Buffs[slot_id].spellid)) {
continue;
}
const bool suppressed = p->Buffs[slot_id].spellid == SPELL_SUPPRESSED;
pet_buff.char_id = client->CharacterID();
pet_buff.pet = pet_info_type;
pet_buff.slot = slot_id;
pet_buff.spell_id = p->Buffs[slot_id].spellid;
pet_buff.spell_id = suppressed ? p->Buffs[slot_id].player_id : p->Buffs[slot_id].spellid;
pet_buff.caster_level = p->Buffs[slot_id].level;
pet_buff.ticsremaining = p->Buffs[slot_id].duration;
pet_buff.counters = p->Buffs[slot_id].counters;
pet_buff.numhits = 0;
pet_buff.instrument_mod = p->Buffs[slot_id].bard_modifier;
pet_buff.suppressed = suppressed ? 1 : 0;
pet_buffs.push_back(pet_buff);
}
@ -3242,7 +3246,16 @@ void ZoneDatabase::SavePetInfo(Client *client)
);
if (!pet_buffs.empty()) {
CharacterPetBuffsRepository::InsertMany(database, pet_buffs);
const auto saved_count = CharacterPetBuffsRepository::InsertManyWithSuppressed(database, pet_buffs);
if (saved_count != static_cast<int>(pet_buffs.size())) {
LogError(
"Failed to save all pet buffs for character [{}] [{}]. Expected [{}] rows, saved [{}]. Verify the `character_pet_buffs` schema is up to date.",
client->GetCleanName(),
client->CharacterID(),
pet_buffs.size(),
saved_count
);
}
}
CharacterPetInventoryRepository::DeleteWhere(
@ -3332,7 +3345,7 @@ void ZoneDatabase::LoadPetInfo(Client *client)
p->taunting = e.taunting;
}
const auto& buffs = CharacterPetBuffsRepository::GetWhere(
const auto& buffs = CharacterPetBuffsRepository::GetWhereWithSuppressed(
database,
fmt::format(
"`char_id` = {}",
@ -3350,7 +3363,7 @@ void ZoneDatabase::LoadPetInfo(Client *client)
continue;
}
if (e.slot >= RuleI(Spells, MaxTotalSlotsPET)) {
if (e.slot >= RuleI(Spells, MaxTotalSlotsPET) || e.slot >= PET_BUFF_COUNT) {
continue;
}
@ -3358,9 +3371,11 @@ void ZoneDatabase::LoadPetInfo(Client *client)
continue;
}
p->Buffs[e.slot].spellid = e.spell_id;
const bool suppressed = e.suppressed != 0;
p->Buffs[e.slot].spellid = suppressed ? SPELL_SUPPRESSED : e.spell_id;
p->Buffs[e.slot].level = e.caster_level;
p->Buffs[e.slot].player_id = 0;
p->Buffs[e.slot].player_id = suppressed ? e.spell_id : 0;
p->Buffs[e.slot].effect_type = BuffEffectType::Buff;
p->Buffs[e.slot].duration = e.ticsremaining;
p->Buffs[e.slot].counters = e.counters;