Preserve suppressed pet buffs across zoning

This commit is contained in:
Vayle
2026-03-09 12:14:37 -04:00
parent ab39e26b52
commit 83ff1a840d
6 changed files with 191 additions and 20 deletions
+34 -9
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++) {
+24 -9
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,7 +3161,7 @@ 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;
}
@@ -3171,18 +3171,22 @@ void ZoneDatabase::SavePetInfo(Client *client)
pet_buffs.reserve(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` = {}",
@@ -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;