Skip to content

Commit 7f4c7a4

Browse files
committed
Core/Units: Added new accessor methods to select Summons either by slot, spellId or creatureId
1 parent 2f9ced6 commit 7f4c7a4

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8874,6 +8874,57 @@ void Unit::UnregisterSummon(SummonInfo* summon)
88748874
_slottedSummons[targetSlot] = nullptr;
88758875
}
88768876

8877+
SummonInfo* Unit::GetSummonInSlot(SummonPropertiesSlot slot) const
8878+
{
8879+
if (slot == SummonPropertiesSlot::None ||
8880+
slot == SummonPropertiesSlot::Max ||
8881+
slot == SummonPropertiesSlot::AnyAvailableTotem)
8882+
return nullptr;
8883+
8884+
return _slottedSummons[AsUnderlyingType(slot)];
8885+
}
8886+
8887+
std::vector<SummonInfo*> Unit::GetSummonsByCreatureId(uint32 creatureId)
8888+
{
8889+
if (creatureId == 0)
8890+
return {};
8891+
8892+
std::vector<SummonInfo*> summons;
8893+
8894+
8895+
std::ranges::copy_if(_wildSummons, std::back_inserter(summons), [creatureId](SummonInfo const* summon)
8896+
{
8897+
return summon->GetSummonedCreature()->GetEntry() == creatureId;
8898+
});
8899+
8900+
std::ranges::copy_if(_slottedSummons, std::back_inserter(summons), [creatureId](SummonInfo const* summon)
8901+
{
8902+
return summon->GetSummonedCreature()->GetEntry() == creatureId;
8903+
});
8904+
8905+
return summons;
8906+
}
8907+
8908+
std::vector<SummonInfo*> Unit::GetSummonsBySpellId(uint32 spellId)
8909+
{
8910+
if (spellId == 0)
8911+
return {};
8912+
8913+
std::vector<SummonInfo*> summons;
8914+
8915+
std::ranges::copy_if(_wildSummons, std::back_inserter(summons), [spellId](SummonInfo const* summon)
8916+
{
8917+
return summon->GetSummonedCreature()->GetUInt32Value(UNIT_CREATED_BY_SPELL) == spellId;
8918+
});
8919+
8920+
std::ranges::copy_if(_slottedSummons, std::back_inserter(summons), [spellId](SummonInfo const* summon)
8921+
{
8922+
return summon->GetSummonedCreature()->GetUInt32Value(UNIT_CREATED_BY_SPELL) == spellId;
8923+
});
8924+
8925+
return summons;
8926+
}
8927+
88778928
void Unit::SetShapeshiftForm(ShapeshiftForm form)
88788929
{
88798930
SetByteValue(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_SHAPESHIFT_FORM, form);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ enum ProcFlagsSpellType : uint32;
103103
enum ZLiquidStatus : uint32;
104104
enum CharmType : uint8;
105105

106+
enum class SummonPropertiesSlot: int8;
107+
106108
namespace Movement
107109
{
108110
class ExtraMovementStatusElement;
@@ -1336,6 +1338,13 @@ class TC_GAME_API Unit : public WorldObject
13361338
// Unregisters the SummonInfo API of a summoned creature so it can no longer be accessed
13371339
void UnregisterSummon(SummonInfo* summon);
13381340

1341+
// Returns the currently active summon that is the summoner's specified summon slot
1342+
SummonInfo* GetSummonInSlot(SummonPropertiesSlot slot) const;
1343+
// Returns a vector with all currently active summons with the specified creature Id
1344+
std::vector<SummonInfo*> GetSummonsByCreatureId(uint32 creatureId);
1345+
// Returns a vector with all currently active summons which have been created by the specified spell Id
1346+
std::vector<SummonInfo*> GetSummonsBySpellId(uint32 spellId);
1347+
13391348
ShapeshiftForm GetShapeshiftForm() const { return ShapeshiftForm(GetByteValue(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_SHAPESHIFT_FORM)); }
13401349
void SetShapeshiftForm(ShapeshiftForm form);
13411350

0 commit comments

Comments
 (0)