Skip to content

Commit 2f9ced6

Browse files
committed
Core/Creatures: moved the initialization of CreatorGUIDs to new summon handling
1 parent ce55b5a commit 2f9ced6

File tree

8 files changed

+72
-42
lines changed

8 files changed

+72
-42
lines changed

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "SpellMgr.h"
5454
#include "SummonInfo.h"
5555
#include "TemporarySummon.h"
56+
#include "TotemPackets.h"
5657
#include "Transport.h"
5758
#include "Util.h"
5859
#include "Vehicle.h"
@@ -317,11 +318,15 @@ void Creature::AddToWorld()
317318
if (IsVehicle())
318319
GetVehicleKit()->Install();
319320

320-
// If the creature has been summoned, register it for the summoner
321321
if (SummonInfo* summonInfo = GetSummonInfo())
322+
{
323+
// If the creature has been summoned, register it for the summoner
322324
if (Unit* summoner = summonInfo->GetUnitSummoner())
323325
summoner->RegisterSummon(summonInfo);
324326

327+
HandlePostSummonActions();
328+
}
329+
325330
if (GetZoneScript())
326331
GetZoneScript()->OnCreatureCreate(this);
327332
}
@@ -2808,6 +2813,45 @@ bool Creature::IsSummon() const
28082813
return _summonInfo != nullptr;
28092814
}
28102815

2816+
void Creature::HandlePostSummonActions()
2817+
{
2818+
SummonInfo* summonInfo = ASSERT_NOTNULL(GetSummonInfo());
2819+
2820+
if (Unit* summoner = summonInfo->GetUnitSummoner())
2821+
{
2822+
SummonPropertiesSlot slot = summonInfo->GetSummonSlot();
2823+
2824+
// Controlled summons always set their creator guid, which is being used to display summoner names in their title
2825+
if (summonInfo->IsControlledBySummoner())
2826+
SetCreatorGUID(summoner->GetGUID());
2827+
2828+
// Totem slot summons always send the TotemCreated packet. Some non-Shaman classes use this
2829+
// to display summon icons that can be canceled (Consecration, DK ghouls, Wild Mushrooms)
2830+
switch (slot)
2831+
{
2832+
case SummonPropertiesSlot::Totem1:
2833+
case SummonPropertiesSlot::Totem2:
2834+
case SummonPropertiesSlot::Totem3:
2835+
case SummonPropertiesSlot::Totem4:
2836+
{
2837+
if (Player* playerSummoner = Object::ToPlayer(summoner))
2838+
{
2839+
WorldPackets::Totem::TotemCreated totemCreated;
2840+
totemCreated.Totem = GetGUID();
2841+
totemCreated.SpellID = GetUInt32Value(UNIT_CREATED_BY_SPELL);
2842+
totemCreated.Duration = summonInfo->GetRemainingDuration().value_or(0ms).count();
2843+
totemCreated.Slot = AsUnderlyingType(summonInfo->GetSummonSlot()) - 1;
2844+
2845+
playerSummoner->SendDirectMessage(totemCreated.Write());
2846+
}
2847+
break;
2848+
}
2849+
default:
2850+
break;
2851+
}
2852+
}
2853+
}
2854+
28112855
void Creature::AllLootRemovedFromCorpse()
28122856
{
28132857
if (loot.loot_type != LOOT_SKINNING && !IsPet() && GetCreatureTemplate()->SkinLootId && hasLootRecipient())

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ 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();
435+
433436
protected:
434437
bool CreateFromProto(ObjectGuid::LowType guidlow, uint32 entry, CreatureData const* data = nullptr, uint32 vehId = 0);
435438
bool InitEntry(uint32 entry, CreatureData const* data = nullptr);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ void SummonInfo::SetUseSummonerFaction(bool set)
154154
else
155155
_flags.RemoveFlag(SummonPropertiesFlags::UseSummonerFaction);
156156
}
157+
157158
bool SummonInfo::IsControlledBySummoner() const
158159
{
159160
return _control > SummonPropertiesControl::None;

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ void TempSummon::InitStats(uint32 duration)
189189

190190
if (m_Properties->Control != SUMMON_CATEGORY_WILD)
191191
{
192-
// Creator guid is always set for allied summons
193-
SetCreatorGUID(owner->GetGUID());
194-
195192
// Summons inherit their player summoner's guild data
196193
if (owner && (owner->IsPlayer() || owner->IsTotem()))
197194
{

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

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
#include "SummonInfo.h"
8383
#include "TemporarySummon.h"
8484
#include "Totem.h"
85-
#include "TotemPackets.h"
8685
#include "Transport.h"
8786
#include "UnitAI.h"
8887
#include "UpdateFieldFlags.h"
@@ -5727,6 +5726,16 @@ void Unit::SetOwnerGUID(ObjectGuid owner)
57275726
RemoveFieldNotifyFlag(UF_FLAG_OWNER);
57285727
}
57295728

5729+
Unit* Unit::GetCreator() const
5730+
{
5731+
return ObjectAccessor::GetUnit(*this, GetCreatorGUID());
5732+
}
5733+
5734+
Creature* Unit::GetCritter() const
5735+
{
5736+
return ObjectAccessor::GetCreature(*this, GetCritterGUID());
5737+
}
5738+
57305739
Player* Unit::GetControllingPlayer() const
57315740
{
57325741
if (ObjectGuid guid = GetCharmerOrOwnerGUID())
@@ -8840,44 +8849,13 @@ void Unit::RegisterSummon(SummonInfo* summon)
88408849
return;
88418850
}
88428851

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-
88508852
uint8 targetSlot = AsUnderlyingType(slot);
88518853

8852-
// Another is occupying the slot. Unsummon that summon first
8854+
// Another summon is occupying the slot. Unsummon that one first
88538855
if (SummonInfo* activeSummon = _slottedSummons[targetSlot])
88548856
activeSummon->GetSummonedCreature()->DespawnOrUnsummon();
88558857

88568858
_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-
}
88818859
}
88828860

88838861
void Unit::UnregisterSummon(SummonInfo* summon)

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,14 +1078,21 @@ class TC_GAME_API Unit : public WorldObject
10781078

10791079
ObjectGuid GetOwnerGUID() const override { return GetGuidValue(UNIT_FIELD_SUMMONEDBY); }
10801080
void SetOwnerGUID(ObjectGuid owner);
1081+
10811082
ObjectGuid GetCreatorGUID() const { return GetGuidValue(UNIT_FIELD_CREATEDBY); }
10821083
void SetCreatorGUID(ObjectGuid creator) { SetGuidValue(UNIT_FIELD_CREATEDBY, creator); }
1084+
Unit* GetCreator() const;
1085+
10831086
ObjectGuid GetMinionGUID() const { return GetGuidValue(UNIT_FIELD_SUMMON); }
10841087
void SetMinionGUID(ObjectGuid guid) { SetGuidValue(UNIT_FIELD_SUMMON, guid); }
1085-
void SetPetGUID(ObjectGuid guid) { m_SummonSlot[SUMMON_SLOT_PET] = guid; }
1088+
10861089
ObjectGuid GetPetGUID() const { return m_SummonSlot[SUMMON_SLOT_PET]; }
1087-
void SetCritterGUID(ObjectGuid guid) { SetGuidValue(UNIT_FIELD_CRITTER, guid); }
1090+
void SetPetGUID(ObjectGuid guid) { m_SummonSlot[SUMMON_SLOT_PET] = guid; }
1091+
10881092
ObjectGuid GetCritterGUID() const { return GetGuidValue(UNIT_FIELD_CRITTER); }
1093+
void SetCritterGUID(ObjectGuid guid) { SetGuidValue(UNIT_FIELD_CRITTER, guid); }
1094+
Creature* GetCritter() const;
1095+
10891096
ObjectGuid GetOwnerOrCreatorGUID() const { return GetOwnerGUID() ? GetOwnerGUID() : GetCreatorGUID(); }
10901097

10911098
ObjectGuid GetCharmerGUID() const { return GetGuidValue(UNIT_FIELD_CHARMEDBY); }
@@ -1324,7 +1331,7 @@ class TC_GAME_API Unit : public WorldObject
13241331
std::array<ObjectGuid, MAX_SUMMON_SLOT> m_SummonSlot;
13251332
std::array<ObjectGuid, MAX_GAMEOBJECT_SLOT> m_ObjectSlot;
13261333

1327-
// Registers the SummonInfo API of a summoned creature to allow safely accessing it
1334+
// Registers the SummonInfo API of a summoned creature to allow to safely access it
13281335
void RegisterSummon(SummonInfo* summon);
13291336
// Unregisters the SummonInfo API of a summoned creature so it can no longer be accessed
13301337
void UnregisterSummon(SummonInfo* summon);

src/server/scripts/Commands/cs_pet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class pet_commandscript : public CommandScript
103103
creatureTarget->DespawnOrUnsummon();
104104
creatureTarget->SetHealth(0); // just for nice GM-mode view
105105

106-
pet->SetGuidValue(UNIT_FIELD_CREATEDBY, player->GetGUID());
106+
pet->SetCreatorGUID(player->GetGUID());
107107
pet->SetFaction(player->GetFaction());
108108

109109
if (!pet->InitStatsForLevel(creatureTarget->getLevel()))

src/server/scripts/Spells/spell_quest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ class spell_q28813_get_our_boys_back_dummy : public SpellScriptLoader
24762476
if (Creature* injuredStormwindInfantry = caster->FindNearestCreature(NPC_INJURED_STORMWIND_INFANTRY, 5.0f, true))
24772477
{
24782478
injuredStormwindInfantry->SetCreatorGUID(caster->GetGUID());
2479-
injuredStormwindInfantry->CastSpell(injuredStormwindInfantry, SPELL_RENEWED_LIFE, true);
2479+
injuredStormwindInfantry->CastSpell(injuredStormwindInfantry, SPELL_RENEWED_LIFE);
24802480
}
24812481
}
24822482

0 commit comments

Comments
 (0)