diff --git a/src/server/database/Database/Implementation/CharacterDatabase.cpp b/src/server/database/Database/Implementation/CharacterDatabase.cpp index cae83c0a2e..f99bc60e1f 100644 --- a/src/server/database/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/database/Database/Implementation/CharacterDatabase.cpp @@ -634,8 +634,6 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_DEL_CHAR_PET_BY_ID, "DELETE FROM character_pet WHERE id = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_PET, "INSERT INTO character_pet (id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, active, curhealth, curmana, abdata, savetime, CreatedBySpell, PetType) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); - PrepareStatement(CHAR_SEL_PET_ID_BY_SLOT, "SELECT id, owner, slot FROM character_pet WHERE owner = ? AND slot = ?", CONNECTION_SYNCH); - PrepareStatement(CHAR_SEL_UNUSED_ACTIVE_PET_SLOT, "SELECT cp.slot+1 FROM character_pet cp LEFT JOIN character_pet cpa ON cp.slot+1 = cpa.slot WHERE cpa.slot IS NULL AND cp.slot + 1 <= 4 ORDER BY cp.slot LIMIT 1", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_CHAR_ALL_PETS_DETAIL, "SELECT id, entry, owner, modelid, level, exp, Reactstate, slot, name, renamed, active, curhealth, curmana, abdata, savetime, CreatedBySpell, PetType FROM character_pet WHERE owner = ? ORDER BY slot", CONNECTION_ASYNC); // PvPstats diff --git a/src/server/database/Database/Implementation/CharacterDatabase.h b/src/server/database/Database/Implementation/CharacterDatabase.h index 8cc5d0584e..714d85e404 100644 --- a/src/server/database/Database/Implementation/CharacterDatabase.h +++ b/src/server/database/Database/Implementation/CharacterDatabase.h @@ -528,8 +528,6 @@ enum CharacterDatabaseStatements : uint32 CHAR_DEL_CHAR_PET_BY_OWNER, CHAR_DEL_CHAR_PET_DECLINEDNAME_BY_OWNER, CHAR_SEL_PET_SLOTS, - CHAR_SEL_PET_ID_BY_SLOT, - CHAR_SEL_UNUSED_ACTIVE_PET_SLOT, CHAR_SEL_PET_SLOTS_DETAIL, CHAR_SEL_PET_ENTRY, CHAR_SEL_PET_SLOT_BY_ID, diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index 60a014b6b2..2301f55b6c 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -140,7 +140,13 @@ bool Pet::LoadPetData(Player* owner, uint32 petEntry, uint32 petnumber, bool cur if (petType == HUNTER_PET) { CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petEntry); - if (!creatureInfo || !creatureInfo->IsTameable(owner->CanTameExoticPets())) + if (!creatureInfo) + { + owner->GetSession()->SendStableResult(STABLE_ERR_STABLE); + return false; + } + + if (!creatureInfo->IsTameable(owner->CanTameExoticPets())) { owner->GetSession()->SendStableResult(STABLE_ERR_EXOTIC); return false; @@ -333,8 +339,6 @@ bool Pet::LoadPetData(Player* owner, uint32 petEntry, uint32 petnumber, bool cur LoadTemplateImmunities(); m_loading = false; - SetActive(true); - return true; } @@ -362,29 +366,27 @@ void Pet::SavePetToDB(PetSaveMode mode) GetSpellHistory()->SaveToDB(trans); CharacterDatabase.CommitTransaction(trans); + PlayerPetData* playerPetData = GetOwner()->GetPlayerPetDataById(m_charmInfo->GetPetNumber()); + + // save as new if no data for Pet in PlayerPetDataStore + if (mode < PET_SAVE_NEW_PET && !playerPetData) + mode = PET_SAVE_NEW_PET; + if (mode == PET_SAVE_NEW_PET) { Optional slot = IsHunterPet() ? GetOwner()->GetFirstUnusedActivePetSlot() : GetOwner()->GetFirstUnusedPetSlot(); if (slot) { - SetActive(true); SetSlot(*slot); + playerPetData = new PlayerPetData(); } else mode = PET_SAVE_AS_DELETED; } - if (mode == PET_SAVE_DISMISS) - { + if (mode == PET_SAVE_DISMISS || mode == PET_SAVE_LOGOUT) RemoveAllAuras(); - SetActive(false); - } - - if (mode == PET_SAVE_LOGOUT) - { - RemoveAllAuras(); - } // whole pet is saved to DB if (mode >= PET_SAVE_CURRENT_STATE) @@ -399,9 +401,11 @@ void Pet::SavePetToDB(PetSaveMode mode) stmt->setUInt32(0, m_charmInfo->GetPetNumber()); trans->Append(stmt); + uint32 petId = m_charmInfo->GetPetNumber(); + // save pet stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PET); - stmt->setUInt32(0, m_charmInfo->GetPetNumber()); + stmt->setUInt32(0, petId); stmt->setUInt32(1, GetEntry()); stmt->setUInt64(2, ownerLowGUID); stmt->setUInt32(3, GetNativeDisplayId()); @@ -411,7 +415,7 @@ void Pet::SavePetToDB(PetSaveMode mode) stmt->setInt16(7, m_petSlot); stmt->setString(8, m_name); stmt->setUInt8(9, HasByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, UNIT_CAN_BE_RENAMED) ? 0 : 1); - stmt->setUInt8(10, IsActive() ? 1 : 0); + stmt->setUInt8(10, mode == PET_SAVE_DISMISS ? 0 : 1); stmt->setUInt32(11, curhealth); stmt->setUInt32(12, curmana); @@ -424,21 +428,8 @@ void Pet::SavePetToDB(PetSaveMode mode) CharacterDatabase.CommitTransaction(trans); - PlayerPetData* playerPetData = (mode < PET_SAVE_NEW_PET) ? GetOwner()->GetPlayerPetDataById(m_charmInfo->GetPetNumber()) : new PlayerPetData(); - - // save as new if no data for Pet in PlayerPetDataStore - if (mode < PET_SAVE_NEW_PET && !playerPetData) - { - mode = PET_SAVE_NEW_PET; - playerPetData = new PlayerPetData(); - } - - uint32 petId = m_charmInfo->GetPetNumber(); - if (m_petSlot > PET_SLOT_LAST) - { - TC_LOG_ERROR("sql.sql", "Player::LoadPetsFromDB: bad slot %u for pet %u!", m_petSlot, petId); - } + TC_LOG_ERROR("sql.sql", "Pet::SavePetToDB: bad slot %u for pet %u!", m_petSlot, petId); playerPetData->PetId = petId; playerPetData->CreatureId = GetEntry(); @@ -450,7 +441,7 @@ void Pet::SavePetToDB(PetSaveMode mode) playerPetData->Slot = m_petSlot; playerPetData->Name = m_name; playerPetData->Renamed = HasByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, UNIT_CAN_BE_RENAMED) ? 0 : 1; - playerPetData->Active = IsActive() ? 1 : 0; + playerPetData->Active = mode == PET_SAVE_DISMISS ? 0 : 1; playerPetData->SavedHealth = curhealth; playerPetData->SavedMana = curmana; playerPetData->Actionbar = GenerateActionBarData(); diff --git a/src/server/game/Entities/Pet/Pet.h b/src/server/game/Entities/Pet/Pet.h index 94572df765..8396dde595 100644 --- a/src/server/game/Entities/Pet/Pet.h +++ b/src/server/game/Entities/Pet/Pet.h @@ -165,9 +165,6 @@ class TC_GAME_API Pet : public Guardian uint32 GetSlot() { return m_petSlot; } void SetSlot(uint32 newPetSlot) { m_petSlot = newPetSlot; } // use only together with DB update - bool IsActive() { return m_petActive; } - void SetActive(bool active) { m_petActive = active; } - protected: PetType m_petType; int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets) @@ -175,9 +172,8 @@ class TC_GAME_API Pet : public Guardian bool m_loading; uint32 m_focusRegenTimer; - DeclinedName *m_declinedname; + DeclinedName* m_declinedname; uint32 m_petSlot; - bool m_petActive = false; private: void SaveToDB(uint32, uint8, uint32) override // override of Creature::SaveToDB - must not be called diff --git a/src/server/game/Entities/Pet/PetDefines.h b/src/server/game/Entities/Pet/PetDefines.h index 42b248dcf7..892d895410 100644 --- a/src/server/game/Entities/Pet/PetDefines.h +++ b/src/server/game/Entities/Pet/PetDefines.h @@ -31,12 +31,13 @@ enum PetType // stored in character_pet.slot enum PetSaveMode { - PET_SAVE_AS_DELETED = -1, // not saved in fact + PET_SAVE_AS_DELETED = -1, // removes pet from DB and erases from playerPetDataStore PET_SAVE_UPADTE_SLOT = 0, // not used yet - PET_SAVE_CURRENT_STATE = 1, // Saves everything like it is atm - PET_SAVE_DISMISS = 2, // Saves everything like it is atm, but removes auras and sets unactive - PET_SAVE_LOGOUT = 3, // Saves everything like it is atm, but removes auras - PET_SAVE_NEW_PET = 4 + PET_SAVE_CURRENT_STATE = 1, // Saves everything like it is atm, current = true + PET_SAVE_DISMISS = 2, // Saves everything like it is atm, removes auras and current = false + PET_SAVE_LOGOUT = 3, // Saves everything like it is atm, removes auras and current = true + PET_SAVE_NEW_PET = 4, // Saves everything like it is atm, current = true and pushes new into playerPetDataStore + PET_SAVE_TEMP_UNSUMMON = PET_SAVE_LOGOUT }; enum PetStableSlot diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 13e88f6a49..5f73cf4983 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -26470,7 +26470,7 @@ void Player::UnsummonPetTemporaryIfAny() m_oldpetspell = pet->GetUInt32Value(UNIT_CREATED_BY_SPELL); } - RemovePet(pet, PET_SAVE_DISMISS); + RemovePet(pet, PET_SAVE_TEMP_UNSUMMON); } void Player::ResummonPetTemporaryUnSummonedIfAny()