Skip to content

Commit 860f6b1

Browse files
committed
Core/Creatures: implement SummonPropertiesFlags::DespawnOnSummonerLogout and fixed replacing totems when summoning new ones
1 parent 4e2ac8f commit 860f6b1

File tree

10 files changed

+33
-44
lines changed

10 files changed

+33
-44
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,6 @@ void Creature::AddToWorld()
323323
// If the creature has been summoned, register it for the summoner
324324
if (Unit* summoner = summonInfo->GetUnitSummoner())
325325
summoner->RegisterSummon(summonInfo);
326-
327-
HandlePostSummonActions();
328326
}
329327

330328
if (GetZoneScript())
@@ -2813,7 +2811,7 @@ bool Creature::IsSummon() const
28132811
return _summonInfo != nullptr;
28142812
}
28152813

2816-
void Creature::HandlePostSummonActions()
2814+
void Creature::HandlePreSummonActions()
28172815
{
28182816
SummonInfo* summonInfo = ASSERT_NOTNULL(GetSummonInfo());
28192817

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
430430

431431
bool IsSummon() const override;
432432

433-
// Handles all summon relation actions, such as setting guid values, casting passives and initializing the control status
434-
void HandlePostSummonActions();
433+
// Handles all summon based actions which happen before the creature is being added to the world
434+
void HandlePreSummonActions();
435435

436436
protected:
437437
bool CreateFromProto(ObjectGuid::LowType guidlow, uint32 entry, CreatureData const* data = nullptr, uint32 vehId = 0);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void SummonInfo::SetUseSummonerFaction(bool set)
157157

158158
bool SummonInfo::IsControlledBySummoner() const
159159
{
160-
return _control > SummonPropertiesControl::None;
160+
return _control > SummonPropertiesControl::None && _control < SummonPropertiesControl::Vehicle;
161161
}
162162

163163
SummonPropertiesSlot SummonInfo::GetSummonSlot() const

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class TC_GAME_API SummonInfo
4343

4444
// Initializes additional settings based on the provided SummonProperties ID.
4545
void InitializeSummonProperties(uint32 summonPropertiesId, Unit const* summoner);
46-
// Returns the creature that is tied to this SummonInfo instance.
46+
// Returns the creature that is tied to this SummonInfo instance. This pointer can never be null.
4747
Creature* GetSummonedCreature() const;
48-
// Returns the Unit summoner, or nullptr if no summoner has been provided or if the summoner is not an Unit.
48+
// Returns the Unit summoner that has summoned the creature, or nullptr if no summoner has been provided or if the summoner is not an Unit.
4949
Unit* GetUnitSummoner() const;
50-
// Returns the GameObject summoner, or nullptr if no summoner has been provided or if the summoner is not a GameObject.
50+
// Returns the GameObject summoner that has summoned the creature, or nullptr if no summoner has been provided or if the summoner is not a GameObject.
5151
GameObject* GetGameObjectSummoner() const;
5252

5353
// Returns the remaining time until the summon expires. Nullopt when no duration was set which implies that the summon is permanent.

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ void TempSummon::InitStats(uint32 duration)
181181

182182
if (owner)
183183
{
184-
int32 slot = m_Properties->Slot;
185-
if (slot > 0)
186-
{
187-
owner->m_SummonSlot[slot] = GetGUID();
188-
}
189-
190184
if (m_Properties->Control != SUMMON_CATEGORY_WILD)
191185
{
192186
// Summons inherit their player summoner's guild data
@@ -200,9 +194,6 @@ void TempSummon::InitStats(uint32 duration)
200194
}
201195
}
202196
}
203-
204-
if (owner->IsTotem())
205-
owner->m_Controlled.insert(this);
206197
}
207198
}
208199

@@ -266,15 +257,6 @@ void TempSummon::RemoveFromWorld()
266257
if (!IsInWorld())
267258
return;
268259

269-
if (m_Properties)
270-
{
271-
int32 slot = m_Properties->Slot;
272-
if (slot > 0)
273-
if (Unit* owner = GetSummoner())
274-
if (owner->m_SummonSlot[slot] == GetGUID())
275-
owner->m_SummonSlot[slot].Clear();
276-
}
277-
278260
//if (GetOwnerGUID())
279261
// TC_LOG_ERROR("entities.unit", "Unit %u has owner guid when removed from world", GetEntry());
280262

src/server/game/Entities/Object/Object.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
#include "ObjectAccessor.h"
3939
#include "ObjectMgr.h"
4040
#include "OutdoorPvPMgr.h"
41-
#include "PhasingHandler.h"
4241
#include "PathGenerator.h"
42+
#include "PhasingHandler.h"
4343
#include "Player.h"
4444
#include "ReputationMgr.h"
4545
#include "SpellAuraEffects.h"
4646
#include "SpellDefines.h"
4747
#include "SpellMgr.h"
4848
#include "StringConvert.h"
49+
#include "SummonInfo.h"
4950
#include "SummonInfoArgs.h"
5051
#include "TemporarySummon.h"
5152
#include "Totem.h"
@@ -55,9 +56,9 @@
5556
#include "UpdateFieldFlags.h"
5657
#include "UpdateMask.h"
5758
#include "Util.h"
58-
#include "Vehicle.h"
5959
#include "VMapFactory.h"
6060
#include "VMapManager2.h"
61+
#include "Vehicle.h"
6162
#include "WaypointMovementGenerator.h"
6263
#include "World.h"
6364
#include "WorldPacket.h"
@@ -2118,6 +2119,7 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonCreatur
21182119
}
21192120

21202121
summon->SetHomePosition(pos);
2122+
summon->HandlePreSummonActions();
21212123
summon->InitStats(summonArgs.SummonDuration);
21222124
summon->SetPrivateObjectOwner(summonArgs.PrivateObjectOwner);
21232125

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,6 @@ void Totem::UnSummon(uint32 msTime)
9595
CombatStop();
9696
RemoveAurasDueToSpell(GetSpell(), GetGUID());
9797

98-
// clear owner's totem slot
99-
for (uint8 i = SUMMON_SLOT_TOTEM_FIRE; i < MAX_TOTEM_SLOT; ++i)
100-
{
101-
if (GetOwner()->m_SummonSlot[i] == GetGUID())
102-
{
103-
GetOwner()->m_SummonSlot[i].Clear();
104-
break;
105-
}
106-
}
107-
10898
GetOwner()->RemoveAurasDueToSpell(GetSpell(), GetGUID());
10999

110100
// remove aura all party members too

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6117,10 +6117,10 @@ void Unit::RemoveAllControlled()
61176117
m_Controlled.erase(m_Controlled.begin());
61186118
if (target->GetCharmerGUID() == GetGUID())
61196119
target->RemoveCharmAuras();
6120-
else if (target->GetOwnerOrCreatorGUID() == GetGUID() && target->IsSummon())
6120+
else if (target->GetOwnerGUID() == GetGUID() && target->IsSummon())
61216121
target->ToTempSummon()->UnSummon();
6122-
else
6123-
TC_LOG_ERROR("entities.unit", "Unit %u is trying to release unit %u which is neither charmed nor owned by it", GetEntry(), target->GetEntry());
6122+
//else
6123+
// TC_LOG_ERROR("entities.unit", "Unit %u is trying to release unit %u which is neither charmed nor owned by it", GetEntry(), target->GetEntry());
61246124
}
61256125
if (GetPetGUID())
61266126
TC_LOG_FATAL("entities.unit", "Unit %u is not able to release its pet %s", GetEntry(), GetPetGUID().ToString().c_str());
@@ -8874,6 +8874,21 @@ void Unit::UnregisterSummon(SummonInfo* summon)
88748874
_slottedSummons[targetSlot] = nullptr;
88758875
}
88768876

8877+
void Unit::DespawnSummonsOnSummonerLogout()
8878+
{
8879+
// Summons which are stored in a summon slot will always despawn
8880+
std::vector<SummonInfo*> slottedSummons = _slottedSummons;
8881+
for (SummonInfo* summon : slottedSummons)
8882+
if (summon)
8883+
summon->GetSummonedCreature()->DespawnOrUnsummon();
8884+
8885+
// Wild summons on the other hand only despawn when the according flag is set
8886+
std::vector<SummonInfo*> wildSummons = _wildSummons;
8887+
for (SummonInfo* summon : wildSummons)
8888+
if (summon->DespawnsOnSummonerLogout())
8889+
summon->GetSummonedCreature()->DespawnOrUnsummon();
8890+
}
8891+
88778892
SummonInfo* Unit::GetSummonInSlot(SummonPropertiesSlot slot) const
88788893
{
88798894
if (slot == SummonPropertiesSlot::None ||
@@ -9690,7 +9705,7 @@ void Unit::RemoveFromWorld()
96909705
RemoveAllDynObjects();
96919706

96929707
ExitVehicle(); // Remove applied auras with SPELL_AURA_CONTROL_VEHICLE
9693-
UnsummonAllTotems();
9708+
DespawnSummonsOnSummonerLogout();
96949709
RemoveAllControlled();
96959710

96969711
RemoveAreaAurasDueToLeaveWorld();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,8 @@ class TC_GAME_API Unit : public WorldObject
13371337
void RegisterSummon(SummonInfo* summon);
13381338
// Unregisters the SummonInfo API of a summoned creature so it can no longer be accessed
13391339
void UnregisterSummon(SummonInfo* summon);
1340+
// Despawns all summons that should despawn when the summoner logs out or despawns
1341+
void DespawnSummonsOnSummonerLogout();
13401342

13411343
// Returns the currently active summon that is the summoner's specified summon slot
13421344
SummonInfo* GetSummonInSlot(SummonPropertiesSlot slot) const;

src/server/game/Handlers/SpellHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ void WorldSession::HandleTotemDestroyed(WorldPackets::Totem::TotemDestroyed& pac
429429
return;
430430

431431
SummonInfo* summonInfo = _player->GetSummonInSlot(slot);
432-
if (!summonInfo)
432+
if (!summonInfo || summonInfo->GetSummonedCreature()->GetGUID() != packet.TotemGUID)
433433
return;
434434

435435
summonInfo->GetSummonedCreature()->DespawnOrUnsummon();

0 commit comments

Comments
 (0)