Skip to content

Commit ce55b5a

Browse files
committed
Core/Creatures: moved replacement of old summons and sending of SMSG_TOTEM_CREATED to new SummonInfo API and
1 parent ec1ab2a commit ce55b5a

File tree

7 files changed

+82
-27
lines changed

7 files changed

+82
-27
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ void Creature::AddToWorld()
318318
GetVehicleKit()->Install();
319319

320320
// If the creature has been summoned, register it for the summoner
321-
if (IsSummon())
322-
if (Unit* summoner = GetSummonInfo()->GetUnitSummoner())
323-
summoner->RegisterSummon(GetSummonInfo());
321+
if (SummonInfo* summonInfo = GetSummonInfo())
322+
if (Unit* summoner = summonInfo->GetUnitSummoner())
323+
summoner->RegisterSummon(summonInfo);
324324

325325
if (GetZoneScript())
326326
GetZoneScript()->OnCreatureCreate(this);
@@ -332,9 +332,9 @@ void Creature::RemoveFromWorld()
332332
if (IsInWorld())
333333
{
334334
// If the creature about to despawn, unregister it for the summoner
335-
if (IsSummon())
336-
if (Unit* summoner = GetSummonInfo()->GetUnitSummoner())
337-
summoner->UnregisterSummon(GetSummonInfo());
335+
if (SummonInfo* summonInfo = GetSummonInfo())
336+
if (Unit* summoner = summonInfo->GetUnitSummoner())
337+
summoner->UnregisterSummon(summonInfo);
338338

339339
if (GetZoneScript())
340340
GetZoneScript()->OnCreatureRemove(this);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,8 @@ bool SummonInfo::IsControlledBySummoner() const
158158
{
159159
return _control > SummonPropertiesControl::None;
160160
}
161+
162+
SummonPropertiesSlot SummonInfo::GetSummonSlot() const
163+
{
164+
return _summonSlot;
165+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class TC_GAME_API SummonInfo
7777
void SetUseSummonerFaction(bool set);
7878
// Returns true when the summon is either a Guardian, Pet, Vehicle or Possessed summon
7979
bool IsControlledBySummoner() const;
80+
// Returns the summon slot that the summon is going to be stored in
81+
SummonPropertiesSlot GetSummonSlot() const;
8082

8183
private:
8284
Creature* _summonedCreature;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,6 @@ void TempSummon::InitStats(uint32 duration)
184184
int32 slot = m_Properties->Slot;
185185
if (slot > 0)
186186
{
187-
if (owner->m_SummonSlot[slot] && owner->m_SummonSlot[slot] != GetGUID())
188-
{
189-
Creature* oldSummon = GetMap()->GetCreature(owner->m_SummonSlot[slot]);
190-
if (oldSummon && oldSummon->IsSummon())
191-
oldSummon->ToTempSummon()->UnSummon();
192-
}
193187
owner->m_SummonSlot[slot] = GetGUID();
194188
}
195189

src/server/game/Entities/Totem/Totem.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,8 @@ void Totem::Update(uint32 time)
5353
void Totem::InitStats(uint32 duration)
5454
{
5555
// client requires SMSG_TOTEM_CREATED to be sent before adding to world and before removing old totem
56-
if (GetOwner()->GetTypeId() == TYPEID_PLAYER
57-
&& m_Properties->Slot >= SUMMON_SLOT_TOTEM_FIRE
58-
&& m_Properties->Slot < MAX_TOTEM_SLOT)
56+
if (GetOwner()->GetTypeId() == TYPEID_PLAYER && m_Properties->Slot >= SUMMON_SLOT_TOTEM_FIRE && m_Properties->Slot < MAX_TOTEM_SLOT)
5957
{
60-
WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
61-
data << uint8(m_Properties->Slot - 1);
62-
data << uint64(GetGUID());
63-
data << uint32(duration);
64-
data << uint32(GetUInt32Value(UNIT_CREATED_BY_SPELL));
65-
GetOwner()->ToPlayer()->SendDirectMessage(&data);
66-
6758
// set display id depending on caster's race
6859
SetDisplayId(GetOwner()->GetModelForTotem(PlayerTotemType(m_Properties->ID)));
6960
}

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

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include "SummonInfo.h"
8383
#include "TemporarySummon.h"
8484
#include "Totem.h"
85+
#include "TotemPackets.h"
8586
#include "Transport.h"
8687
#include "UnitAI.h"
8788
#include "UpdateFieldFlags.h"
@@ -379,6 +380,8 @@ Unit::Unit(bool isWorldObject) :
379380

380381
_oldFactionId = 0;
381382
_isWalkingBeforeCharm = false;
383+
384+
_slottedSummons.resize(AsUnderlyingType(SummonPropertiesSlot::Max), nullptr);
382385
}
383386

384387
////////////////////////////////////////////////////////////
@@ -8824,16 +8827,73 @@ void Unit::RegisterSummon(SummonInfo* summon)
88248827
if (!summon)
88258828
return;
88268829

8827-
if (!advstd::ranges::contains(_activeSummons, summon))
8828-
_activeSummons.push_back(summon);
8830+
SummonPropertiesSlot slot = summon->GetSummonSlot();
8831+
8832+
// Wild Summons usually don't need any tracking but some do have certain SummonPropertiesFlags which
8833+
// causes them to interact with the summoner in some way (e.g. despawning when the summoner died)
8834+
if (slot == SummonPropertiesSlot::None)
8835+
{
8836+
if (advstd::ranges::contains(_wildSummons, summon))
8837+
return;
8838+
8839+
_wildSummons.push_back(summon);
8840+
return;
8841+
}
8842+
8843+
// Select any available totem slot if empty, otherwise they just replace the oldest summon of the same entry
8844+
if (slot == SummonPropertiesSlot::AnyAvailableTotem)
8845+
{
8846+
// @Todo
8847+
slot = SummonPropertiesSlot::Totem1;
8848+
}
8849+
8850+
uint8 targetSlot = AsUnderlyingType(slot);
8851+
8852+
// Another is occupying the slot. Unsummon that summon first
8853+
if (SummonInfo* activeSummon = _slottedSummons[targetSlot])
8854+
activeSummon->GetSummonedCreature()->DespawnOrUnsummon();
8855+
8856+
_slottedSummons[targetSlot] = summon;
8857+
8858+
switch (slot)
8859+
{
8860+
case SummonPropertiesSlot::Totem1:
8861+
case SummonPropertiesSlot::Totem2:
8862+
case SummonPropertiesSlot::Totem3:
8863+
case SummonPropertiesSlot::Totem4:
8864+
{
8865+
Creature const* summonedCreature = summon->GetSummonedCreature();
8866+
if (Player* playerSummoner = Object::ToPlayer(summon->GetUnitSummoner()))
8867+
{
8868+
WorldPackets::Totem::TotemCreated totemCreated;
8869+
totemCreated.Totem = summonedCreature->GetGUID();
8870+
totemCreated.SpellID = summonedCreature->GetUInt32Value(UNIT_CREATED_BY_SPELL);
8871+
totemCreated.Duration = summon->GetRemainingDuration().value_or(0ms).count();
8872+
totemCreated.Slot = AsUnderlyingType(summon->GetSummonSlot()) - 1;
8873+
8874+
playerSummoner->SendDirectMessage(totemCreated.Write());
8875+
}
8876+
break;
8877+
}
8878+
default:
8879+
break;
8880+
}
88298881
}
88308882

88318883
void Unit::UnregisterSummon(SummonInfo* summon)
88328884
{
88338885
if (!summon)
88348886
return;
88358887

8836-
std::erase(_activeSummons, summon);
8888+
SummonPropertiesSlot slot = summon->GetSummonSlot();
8889+
if (slot == SummonPropertiesSlot::None)
8890+
{
8891+
std::erase(_wildSummons, summon);
8892+
return;
8893+
}
8894+
8895+
uint8 targetSlot = AsUnderlyingType(slot);
8896+
_slottedSummons[targetSlot] = nullptr;
88378897
}
88388898

88398899
void Unit::SetShapeshiftForm(ShapeshiftForm form)
@@ -9626,7 +9686,8 @@ void Unit::RemoveFromWorld()
96269686
}
96279687

96289688
// 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
9629-
_activeSummons.clear();
9689+
_wildSummons.clear();
9690+
_slottedSummons.clear();
96309691

96319692
WorldObject::RemoveFromWorld();
96329693
m_duringRemoveFromWorld = false;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,9 @@ class TC_GAME_API Unit : public WorldObject
18261826

18271827
/* Player Movement fields END*/
18281828

1829-
std::vector<SummonInfo*> _activeSummons;
1829+
// SummonInfo slot handling
1830+
std::vector<SummonInfo*> _wildSummons;
1831+
std::vector<SummonInfo*> _slottedSummons;
18301832
};
18311833

18321834
namespace Trinity

0 commit comments

Comments
 (0)