Skip to content

Commit 857f79b

Browse files
committed
Core/Creatures: converted CMSG_PET_ACTION to packet class and moved most parts of it to the SummonInfo API
1 parent cf8bbd6 commit 857f79b

File tree

10 files changed

+221
-172
lines changed

10 files changed

+221
-172
lines changed

src/server/game/Entities/Creature/SummonInfo/SummonInfo.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SummonInfo::SummonInfo(Creature* summonedCreature, SummonInfoArgs const& args) :
3333
_summonedCreature(ASSERT_NOTNULL(summonedCreature)), _summonerGUID(args.Summoner ? args.Summoner->GetGUID() : ObjectGuid::Empty),
3434
_remainingDuration(args.Duration), _maxHealth(args.MaxHealth), _creatureLevel(args.CreatureLevel),
3535
_flags(SummonPropertiesFlags::None), _control(SummonPropertiesControl::None), _summonSlot(SummonPropertiesSlot::None),
36-
_hasBeenSummonedByCreature(args.Summoner ? args.Summoner->IsCreature() : false)
36+
_hasBeenSummonedByPlayer(args.Summoner ? args.Summoner->IsPlayer() : false)
3737
{
3838
if (args.SummonPropertiesId.has_value())
3939
InitializeSummonProperties(*args.SummonPropertiesId, Object::ToUnit(args.Summoner));
@@ -247,7 +247,7 @@ bool SummonInfo::DespawnsOnSummonerLogout() const
247247
if (IsControlledBySummoner())
248248
{
249249
// Controlled creatures summoned by a creature will only despawn when not engaged
250-
if (_hasBeenSummonedByCreature)
250+
if (!_hasBeenSummonedByPlayer)
251251
return !_summonedCreature->IsEngaged();
252252

253253
// Player controlled summons, however, always despawn
@@ -273,7 +273,7 @@ bool SummonInfo::DespawnsOnSummonerDeath() const
273273
if (IsControlledBySummoner())
274274
{
275275
// Controlled creatures summoned by a creature will only despawn when not engaged (they will despawn when reaching home)
276-
if (_hasBeenSummonedByCreature)
276+
if (!_hasBeenSummonedByPlayer)
277277
return !_summonedCreature->IsEngaged();
278278

279279
// Player controlled summons, however, always despawn
@@ -332,6 +332,11 @@ SummonPropertiesControl SummonInfo::GetControl() const
332332
return _control;
333333
}
334334

335+
bool SummonInfo::IsClassPet() const
336+
{
337+
return _isClassPet;
338+
}
339+
335340
void SummonInfo::castPassiveSpells()
336341
{
337342
CreatureTemplate const* creatureInfo = _summonedCreature->GetCreatureTemplate();
@@ -371,7 +376,7 @@ void SummonInfo::initializeReactState()
371376
break;
372377
case SummonPropertiesControl::Pet:
373378
// Player pets default to assist while creature summons retain their original state
374-
if (!_hasBeenSummonedByCreature)
379+
if (_hasBeenSummonedByPlayer)
375380
_summonedCreature->SetReactState(REACT_ASSIST);
376381
else if (CharmInfo* charmInfo = _summonedCreature->GetCharmInfo())
377382
charmInfo->RestoreState();

src/server/game/Entities/Creature/SummonInfo/SummonInfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class TC_GAME_API SummonInfo
100100
SummonPropertiesSlot GetSummonSlot() const;
101101
// Returns the summon control type which determines how the summon can be controlled by the summoner
102102
SummonPropertiesControl GetControl() const;
103+
// Returns true when the summon is a class pet (Hunter Pet, Warlock Minion or Death Knight Ghoul)
104+
bool IsClassPet() const;
103105

104106
private:
105107
// Looks up and casts all passive spells of the creature summon. Often used for scaling auras.
@@ -116,7 +118,8 @@ class TC_GAME_API SummonInfo
116118
EnumFlag<SummonPropertiesFlags> _flags;
117119
SummonPropertiesControl _control;
118120
SummonPropertiesSlot _summonSlot;
119-
bool _hasBeenSummonedByCreature;
121+
bool _hasBeenSummonedByPlayer;
122+
bool _isClassPet; // Placeholder for class pet interface
120123
};
121124

122125
#endif // _SummonInfo_h__

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8843,10 +8843,10 @@ void Unit::RegisterSummon(SummonInfo* summon)
88438843
// causes them to interact with the summoner in some way (e.g. despawning when the summoner died)
88448844
if (slot == SummonPropertiesSlot::None)
88458845
{
8846-
if (advstd::ranges::contains(_wildSummons, summon))
8846+
if (advstd::ranges::contains(_unslottedSummons, summon))
88478847
return;
88488848

8849-
_wildSummons.push_back(summon);
8849+
_unslottedSummons.push_back(summon);
88508850
return;
88518851
}
88528852

@@ -8867,7 +8867,7 @@ void Unit::UnregisterSummon(SummonInfo* summon)
88678867
SummonPropertiesSlot slot = summon->GetSummonSlot();
88688868
if (slot == SummonPropertiesSlot::None)
88698869
{
8870-
std::erase(_wildSummons, summon);
8870+
std::erase(_unslottedSummons, summon);
88718871
return;
88728872
}
88738873

@@ -8877,30 +8877,38 @@ void Unit::UnregisterSummon(SummonInfo* summon)
88778877

88788878
void Unit::DespawnSummonsOnSummonerLogout()
88798879
{
8880-
// Summons which are stored in a summon slot will always despawn
8881-
std::vector<SummonInfo*> slottedSummons = _slottedSummons;
8882-
for (SummonInfo* summon : slottedSummons)
8883-
if (summon)
8880+
std::vector<SummonInfo*> unslottedSummons = _unslottedSummons;
8881+
for (SummonInfo* summon : unslottedSummons)
8882+
if (summon->DespawnsOnSummonerLogout())
88848883
summon->GetSummonedCreature()->DespawnOrUnsummon();
88858884

8886-
// Wild summons on the other hand only despawn when the according flag is set
8887-
std::vector<SummonInfo*> wildSummons = _wildSummons;
8888-
for (SummonInfo* summon : wildSummons)
8889-
if (summon->DespawnsOnSummonerLogout())
8885+
std::vector<SummonInfo*> slottedSummons = _slottedSummons;
8886+
for (SummonInfo* summon : slottedSummons)
8887+
if (summon && summon->DespawnsOnSummonerLogout())
88908888
summon->GetSummonedCreature()->DespawnOrUnsummon();
88918889
}
88928890

88938891
void Unit::DespawnSummonsOnSummonerDeath()
88948892
{
8893+
std::vector<SummonInfo*> unslottedSummons = _unslottedSummons;
8894+
for (SummonInfo* summon : unslottedSummons)
8895+
if (summon->DespawnsOnSummonerDeath())
8896+
summon->GetSummonedCreature()->DespawnOrUnsummon();
8897+
88958898
std::vector<SummonInfo*> slottedSummons = _slottedSummons;
88968899
for (SummonInfo* summon : slottedSummons)
88978900
if (summon && summon->DespawnsOnSummonerDeath())
88988901
summon->GetSummonedCreature()->DespawnOrUnsummon();
88998902

8900-
std::vector<SummonInfo*> wildSummons = _wildSummons;
8901-
for (SummonInfo* summon : wildSummons)
8902-
if (summon->DespawnsOnSummonerDeath())
8903-
summon->GetSummonedCreature()->DespawnOrUnsummon();
8903+
}
8904+
8905+
void Unit::DismissPet()
8906+
{
8907+
if (!GetMinionGUID())
8908+
return;
8909+
8910+
for (SummonInfo* summonInfo : GetSummonsByControlType(SummonPropertiesControl::Pet))
8911+
summonInfo->GetSummonedCreature()->DespawnOrUnsummon();
89048912
}
89058913

89068914
SummonInfo* Unit::GetSummonInSlot(SummonPropertiesSlot slot) const
@@ -8921,14 +8929,14 @@ std::vector<SummonInfo*> Unit::GetSummonsByCreatureId(uint32 creatureId)
89218929
std::vector<SummonInfo*> summons;
89228930

89238931

8924-
std::ranges::copy_if(_wildSummons, std::back_inserter(summons), [creatureId](SummonInfo const* summon)
8932+
std::ranges::copy_if(_unslottedSummons, std::back_inserter(summons), [creatureId](SummonInfo const* summon)
89258933
{
89268934
return summon->GetSummonedCreature()->GetEntry() == creatureId;
89278935
});
89288936

89298937
std::ranges::copy_if(_slottedSummons, std::back_inserter(summons), [creatureId](SummonInfo const* summon)
89308938
{
8931-
return summon->GetSummonedCreature()->GetEntry() == creatureId;
8939+
return summon && summon->GetSummonedCreature()->GetEntry() == creatureId;
89328940
});
89338941

89348942
return summons;
@@ -8941,14 +8949,31 @@ std::vector<SummonInfo*> Unit::GetSummonsBySpellId(uint32 spellId)
89418949

89428950
std::vector<SummonInfo*> summons;
89438951

8944-
std::ranges::copy_if(_wildSummons, std::back_inserter(summons), [spellId](SummonInfo const* summon)
8952+
std::ranges::copy_if(_unslottedSummons, std::back_inserter(summons), [spellId](SummonInfo const* summon)
89458953
{
89468954
return summon->GetSummonedCreature()->GetUInt32Value(UNIT_CREATED_BY_SPELL) == spellId;
89478955
});
89488956

89498957
std::ranges::copy_if(_slottedSummons, std::back_inserter(summons), [spellId](SummonInfo const* summon)
89508958
{
8951-
return summon->GetSummonedCreature()->GetUInt32Value(UNIT_CREATED_BY_SPELL) == spellId;
8959+
return summon && summon->GetSummonedCreature()->GetUInt32Value(UNIT_CREATED_BY_SPELL) == spellId;
8960+
});
8961+
8962+
return summons;
8963+
}
8964+
8965+
std::vector<SummonInfo*> Unit::GetSummonsByControlType(SummonPropertiesControl control)
8966+
{
8967+
std::vector<SummonInfo*> summons;
8968+
8969+
std::ranges::copy_if(_unslottedSummons, std::back_inserter(summons), [control](SummonInfo const* summon)
8970+
{
8971+
return summon->GetControl() == control;
8972+
});
8973+
8974+
std::ranges::copy_if(_slottedSummons, std::back_inserter(summons), [control](SummonInfo const* summon)
8975+
{
8976+
return summon && summon->GetControl() == control;
89528977
});
89538978

89548979
return summons;
@@ -9744,7 +9769,7 @@ void Unit::RemoveFromWorld()
97449769
}
97459770

97469771
// Clear all active summon references. If we are about to switch map instances, we want to make sure that we leave all summons behind so we won't do threadunsafe operations
9747-
_wildSummons.clear();
9772+
_unslottedSummons.clear();
97489773
_slottedSummons.clear();
97499774

97509775
WorldObject::RemoveFromWorld();

src/server/game/Entities/Unit/Unit.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ enum ProcFlagsSpellType : uint32;
103103
enum ZLiquidStatus : uint32;
104104
enum CharmType : uint8;
105105

106+
enum class SummonPropertiesControl : uint8;
106107
enum class SummonPropertiesSlot: int8;
107108

108109
namespace Movement
@@ -1341,13 +1342,17 @@ class TC_GAME_API Unit : public WorldObject
13411342
void DespawnSummonsOnSummonerLogout();
13421343
// Despawns all summons that should despawn when the summoner dies
13431344
void DespawnSummonsOnSummonerDeath();
1345+
// Dismisses the currently active pet summon(s) (class pets and summons which are considered pets)
1346+
void DismissPet();
13441347

13451348
// Returns the currently active summon that is the summoner's specified summon slot
13461349
SummonInfo* GetSummonInSlot(SummonPropertiesSlot slot) const;
13471350
// Returns a vector with all currently active summons with the specified creature Id
13481351
std::vector<SummonInfo*> GetSummonsByCreatureId(uint32 creatureId);
13491352
// Returns a vector with all currently active summons which have been created by the specified spell Id
13501353
std::vector<SummonInfo*> GetSummonsBySpellId(uint32 spellId);
1354+
// Returns a vector with all currently active summons which are being controlled in a specific way
1355+
std::vector<SummonInfo*> GetSummonsByControlType(SummonPropertiesControl control);
13511356

13521357
ShapeshiftForm GetShapeshiftForm() const { return ShapeshiftForm(GetByteValue(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_SHAPESHIFT_FORM)); }
13531358
void SetShapeshiftForm(ShapeshiftForm form);
@@ -1847,7 +1852,7 @@ class TC_GAME_API Unit : public WorldObject
18471852
/* Player Movement fields END*/
18481853

18491854
// SummonInfo slot handling
1850-
std::vector<SummonInfo*> _wildSummons;
1855+
std::vector<SummonInfo*> _unslottedSummons;
18511856
std::vector<SummonInfo*> _slottedSummons;
18521857
};
18531858

0 commit comments

Comments
 (0)