Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Pets: added methods for resummoning active class pets and use it…
Browse files Browse the repository at this point in the history
… when relogging
  • Loading branch information
Ovahlord committed Sep 30, 2023
1 parent 417667e commit 7232ead
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 264 deletions.
8 changes: 2 additions & 6 deletions src/server/game/AI/CoreAI/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@

int32 PetAI::Permissible(Creature const* creature)
{
if (creature->HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
{
if (reinterpret_cast<Guardian const*>(creature)->GetOwner()->GetTypeId() == TYPEID_PLAYER)
return PERMIT_BASE_PROACTIVE;
return PERMIT_BASE_REACTIVE;
}
if (creature->IsPet())
return PERMIT_BASE_PROACTIVE;

return PERMIT_BASE_NO;
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/AI/CreatureAISelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ namespace FactorySelector
CreatureAI* SelectAI(Creature* creature)
{
// special pet case, if a tamed creature uses AIName (example SmartAI) we need to override it
//if (creature->IsPet())
// return ASSERT_NOTNULL(sCreatureAIRegistry->GetRegistryItem("PetAI"))->Create(creature);
if (creature->IsPet())
return ASSERT_NOTNULL(sCreatureAIRegistry->GetRegistryItem("PetAI"))->Create(creature);

// scriptname in db
try
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Creature/TemporarySummon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void TempSummon::UnSummon(uint32 msTime)
//ASSERT(!IsPet());
if (IsPet())
{
((Pet*)this)->Remove(PET_SAVE_DISMISS);
//((Pet*)this)->Remove(PET_SAVE_DISMISS);
ASSERT(!IsInWorld());
return;
}
Expand Down
16 changes: 13 additions & 3 deletions src/server/game/Entities/Creature/TemporarySummon/NewPet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ void NewPet::HandlePostSummonActions()
NewGuardian::HandlePostSummonActions();

if (IsHunterPet())
{
SendTalentsInfoUpdateToSummoner();
CastSpell(nullptr, SPELL_PET_ENERGIZE);
}
else
CastSpell(nullptr, SPELL_SUMMON_HEAL);
}

bool NewPet::CanBeDismissed() const
Expand All @@ -138,8 +143,13 @@ void NewPet::Dismiss(bool permanent /*= true*/)
UpdatePlayerPetData(player->GetPlayerPetData(_playerPetDataKey->first, _playerPetDataKey->second));

// If the pet has been despawned while dead, we will mark the pet as inactive
if (permanent && !IsAlive())
player->SetActiveClassPetDataKey(std::nullopt);
if (IsClassPet())
{
if (permanent)
player->SetActiveClassPetDataKey(std::nullopt);
else
player->SetActiveClassPetDataKey(_playerPetDataKey);
}

if (IsClassPet())
{
Expand All @@ -151,7 +161,7 @@ void NewPet::Dismiss(bool permanent /*= true*/)
WorldPackets::Pet::PetDismissSound dismissSound;
dismissSound.ModelID = creatureDisplay->ModelID;
dismissSound.ModelPosition = GetPosition();
SendMessageToSet(dismissSound.Write(), false);
player->SendDirectMessage(dismissSound.Write());
}
}
}
Expand Down
139 changes: 3 additions & 136 deletions src/server/game/Entities/Pet/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,134 +349,6 @@ bool Pet::LoadPetData(Player* owner, uint32 petEntry, uint32 petnumber, bool cur
return true;
}

void Pet::SavePetToDB(PetSaveMode mode)
{
return;

if (!GetEntry())
return;

// save only fully controlled creature
if (!isControlled())
return;

// not save not player pets
if (!GetOwnerOrCreatorGUID().IsPlayer())
return;

uint32 curhealth = GetHealth();
uint32 curmana = GetPower(POWER_MANA);

CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
// save auras before possibly removing them
_SaveAuras(trans);

_SaveSpells(trans);
GetSpellHistory()->SaveToDB<Pet>(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<uint8> slot = IsHunterPet() ? GetOwner()->GetFirstUnusedActivePetSlot() : GetOwner()->GetFirstUnusedPetSlot();
if (slot)
{
SetSlot(*slot);
//playerPetData = new PlayerPetData();
}
else
mode = PET_SAVE_AS_DELETED;
}
*/

if (mode == PET_SAVE_DISMISS || mode == PET_SAVE_LOGOUT)
RemoveAllAuras();

/*
// whole pet is saved to DB
if (mode >= PET_SAVE_CURRENT_STATE)
{
ObjectGuid::LowType ownerLowGUID = GetOwnerOrCreatorGUID().GetCounter();
std::string name = m_name;
CharacterDatabase.EscapeString(name);
trans = CharacterDatabase.BeginTransaction();
// remove current data
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_PET_BY_ID);
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, petId);
stmt->setUInt32(1, GetEntry());
stmt->setUInt64(2, ownerLowGUID);
stmt->setUInt32(3, GetNativeDisplayId());
stmt->setUInt8(4, getLevel());
stmt->setUInt32(5, GetUInt32Value(UNIT_FIELD_PETEXPERIENCE));
stmt->setUInt8(6, GetReactState());
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, mode == PET_SAVE_DISMISS ? 0 : 1);
stmt->setUInt32(11, curhealth);
stmt->setUInt32(12, curmana);
stmt->setString(13, GenerateActionBarData());
stmt->setUInt32(14, GameTime::GetGameTime()); // unsure about this
stmt->setUInt32(15, GetUInt32Value(UNIT_CREATED_BY_SPELL));
stmt->setUInt8(16, getPetType());
trans->Append(stmt);
CharacterDatabase.CommitTransaction(trans);
if (m_petSlot > PET_SLOT_LAST)
TC_LOG_ERROR("sql.sql", "Pet::SavePetToDB: bad slot %u for pet %u!", m_petSlot, petId);
playerPetData->PetId = petId;
playerPetData->CreatureId = GetEntry();
playerPetData->Owner = ownerLowGUID;
playerPetData->DisplayId = GetNativeDisplayId();
playerPetData->Petlevel = getLevel();
playerPetData->PetExp = GetUInt32Value(UNIT_FIELD_PETEXPERIENCE);
playerPetData->Reactstate = GetReactState();
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 = mode == PET_SAVE_DISMISS ? 0 : 1;
playerPetData->SavedHealth = curhealth;
playerPetData->SavedMana = curmana;
playerPetData->Actionbar = GenerateActionBarData();
playerPetData->Timediff = GameTime::GetGameTime();
playerPetData->SummonSpellId = GetUInt32Value(UNIT_CREATED_BY_SPELL);
playerPetData->Type = getPetType();
if (mode == PET_SAVE_NEW_PET)
GetOwner()->AddToPlayerPetDataStore(playerPetData);
}
// delete
else
{
RemoveAllAuras();
DeleteFromDB(m_charmInfo->GetPetNumber());
GetOwner()->DeleteFromPlayerPetDataStore(m_charmInfo->GetPetNumber());
GetOwner()->GetSession()->SendStablePet(ObjectGuid::Empty);
}
*/
}

void Pet::DeleteFromDB(ObjectGuid::LowType guidlow)
{
/*
Expand Down Expand Up @@ -541,7 +413,7 @@ void Pet::Update(uint32 diff)
{
//if (!IsHunterPet() || m_corpseRemoveTime <= GameTime::GetGameTime())
{
Remove(PET_SAVE_DISMISS); //hunters' pets never get removed because of death, NEVER!
//Remove(PET_SAVE_DISMISS); //hunters' pets never get removed because of death, NEVER!
return;
}
break;
Expand All @@ -553,7 +425,7 @@ void Pet::Update(uint32 diff)
if ((!IsWithinDistInMap(owner, GetMap()->GetVisibilityRange()) && !isPossessed()) || (isControlled() && !owner->GetSummonGUID()))
//if (!owner || (!IsWithinDistInMap(owner, GetMap()->GetVisibilityDistance()) && (owner->GetCharmGUID() && (owner->GetCharmGUID() != GetGUID()))) || (isControlled() && !owner->GetPetGUID()))
{
Remove(PET_SAVE_DISMISS, true);
//Remove(PET_SAVE_DISMISS, true);
return;
}

Expand All @@ -573,7 +445,7 @@ void Pet::Update(uint32 diff)
m_duration -= diff;
else
{
Remove(getPetType() != SUMMON_PET ? PET_SAVE_AS_DELETED : PET_SAVE_DISMISS);
//Remove(getPetType() != SUMMON_PET ? PET_SAVE_AS_DELETED : PET_SAVE_DISMISS);
return;
}
}
Expand All @@ -586,11 +458,6 @@ void Pet::Update(uint32 diff)
Creature::Update(diff);
}

void Pet::Remove(PetSaveMode mode, bool returnreagent)
{
//GetOwner()->RemovePet(this, mode, returnreagent);
}

void Pet::GivePetXP(uint32 xp)
{
//if (!IsHunterPet())
Expand Down
2 changes: 0 additions & 2 deletions src/server/game/Entities/Pet/Pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class TC_GAME_API Pet : public Guardian
bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map);
bool LoadPetData(Player* owner, uint32 petentry = 0, uint32 petnumber = 0, bool current = false);
bool IsLoading() const override { return m_loading;}
void SavePetToDB(PetSaveMode mode);
void Remove(PetSaveMode mode, bool returnreagent = false);
static void DeleteFromDB(ObjectGuid::LowType guidlow);

void setDeathState(DeathState s) override; // overwrite virtual Creature::setDeathState and Unit::setDeathState
Expand Down
20 changes: 6 additions & 14 deletions src/server/game/Entities/Pet/PetDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,7 @@ enum PetType
MAX_PET_TYPE = 4
};

#define MAX_PET_STABLES 20

// stored in character_pet.slot
enum PetSaveMode
{
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, 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
};
static constexpr uint8 MAX_PET_STABLES = 20;

enum PetCallSpells
{
Expand Down Expand Up @@ -105,8 +93,12 @@ enum StableResultCode : uint8
enum PetSummonSpellIds
{
// Hunter Pets
SPELL_PET_ENERGIZE = 99289
SPELL_PET_ENERGIZE = 99289,

// Pets
SPELL_SUMMON_HEAL = 36492 // serverside Spell
};

// Used by companions (minipets) and quest slot summons
constexpr float DEFAULT_FOLLOW_DISTANCE = 2.5f;
constexpr float DEFAULT_FOLLOW_DISTANCE_PET = 3.f;
Expand Down
Loading

0 comments on commit 7232ead

Please sign in to comment.