Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Creatures: re-implement pet/guardian scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovahlord committed Oct 23, 2023
1 parent fd23ca8 commit 23dc2d5
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 528 deletions.
42 changes: 39 additions & 3 deletions src/server/game/Entities/Creature/TemporarySummon/NewGuardian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "DBCStores.h"
#include "ObjectMgr.h"
#include "NewPet.h"
#include "SpellAuras.h"
#include "SpellMgr.h"
#include "SpellInfo.h"

Expand All @@ -20,6 +21,22 @@ void NewGuardian::AddToWorld()
NewTemporarySummon::AddToWorld();
}

void NewGuardian::Update(uint32 diff)
{
if (_scalingAuraUpdateTimer.has_value())
{
if (*_scalingAuraUpdateTimer <= Milliseconds(diff))
{
UpdateScalingAuras();
_scalingAuraUpdateTimer = 1s;
}
else
*_scalingAuraUpdateTimer -= Milliseconds(diff);
}

NewTemporarySummon::Update(diff);
}

bool NewGuardian::HandlePreSummonActions(Unit const* summoner, uint8 creatureLevel, uint8 maxSummons)
{
if (!NewTemporarySummon::HandlePreSummonActions(summoner, creatureLevel, maxSummons))
Expand Down Expand Up @@ -96,10 +113,9 @@ void NewGuardian::InitializeStats()
SetStatFlatModifier(UNIT_MOD_RESISTANCE_FROST, BASE_VALUE, float(creatureInfo->resistance[SPELL_SCHOOL_FROST]));
SetStatFlatModifier(UNIT_MOD_RESISTANCE_SHADOW, BASE_VALUE, float(creatureInfo->resistance[SPELL_SCHOOL_SHADOW]));
SetStatFlatModifier(UNIT_MOD_RESISTANCE_ARCANE, BASE_VALUE, float(creatureInfo->resistance[SPELL_SCHOOL_ARCANE]));

SetCanModifyStats(true);
}

SetCanModifyStats(true);
UpdateAllStats();
SetFullHealth();
}
Expand All @@ -108,9 +124,11 @@ void NewGuardian::HandlePostSummonActions()
{
NewTemporarySummon::HandlePostSummonActions();

//CastPassiveAuras();
CastPassiveAuras();
}

// ------------- private methods

void NewGuardian::CastPassiveAuras()
{
CreatureTemplate const* creatureInfo = GetCreatureTemplate();
Expand All @@ -126,7 +144,25 @@ void NewGuardian::CastPassiveAuras()
return;

for (uint32 spellId : petSpellStore->second)
{
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
{
if (spellInfo->IsPassive())
{
CastSpell(this, spellId);
if (spellInfo->HasAttribute(SPELL_ATTR4_OWNER_POWER_SCALING))
_scalingAuras.push_back(spellId);
}
}
}

if (!_scalingAuras.empty())
_scalingAuraUpdateTimer = 1s;
}

void NewGuardian::UpdateScalingAuras()
{
for (uint32 spellId : _scalingAuras)
if (Aura* aura = GetAura(spellId))
aura->RecalculateAmountOfEffects();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TC_GAME_API NewGuardian : public NewTemporarySummon
explicit NewGuardian(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject);

void AddToWorld() override;
void Update(uint32 diff) override;

// Stats handling
bool UpdateAllStats() override;
Expand All @@ -42,10 +43,13 @@ class TC_GAME_API NewGuardian : public NewTemporarySummon
bool IsUsingRealStats() const { return _isUsingRealStats; }
void InitializeStats();

protected:
private:
void CastPassiveAuras();
void UpdateScalingAuras();

bool _isUsingRealStats;
std::vector<uint32> _scalingAuras;
Optional<Milliseconds> _scalingAuraUpdateTimer;
};

#endif // Guardian_h__
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void NewTemporarySummon::Update(uint32 diff)
// Make sure that the summon is within the summoner's distance when its following the player
if (_summonDistanceCheckTimer.has_value())
{
if (_summonDistanceCheckTimer <= Milliseconds(diff))
if (*_summonDistanceCheckTimer <= Milliseconds(diff))
{
Unit* summoner = GetInternalSummoner();
if (!summoner || GetExactDist(summoner) > MAX_SUMMON_DISTANCE)
Expand Down
4 changes: 4 additions & 0 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class DynamicObject;
class GameClient;
class GameObject;
class Guardian;
class NewGuardian;
class Item;
class Minion;
class MotionMaster;
Expand Down Expand Up @@ -1635,6 +1636,9 @@ class TC_GAME_API Unit : public WorldObject
NewTemporarySummon* ToTemporarySummon() { if (IsSummon()) return reinterpret_cast<NewTemporarySummon*>(this); else return nullptr; }
NewTemporarySummon const* ToTemporarySummon() const { if (IsSummon()) return reinterpret_cast<NewTemporarySummon const*>(this); else return nullptr; }

NewGuardian* ToNewGuardian() { if (IsGuardian()) return reinterpret_cast<NewGuardian*>(this); else return nullptr; }
NewGuardian const* ToNewGuardian() const { if (IsGuardian()) return reinterpret_cast<NewGuardian const*>(this); else return nullptr; }

NewPet* ToNewPet() { if (IsPet()) return reinterpret_cast<NewPet*>(this); else return nullptr; }
NewPet const* ToNewPet() const { if (IsPet()) return reinterpret_cast<NewPet const*>(this); else return nullptr; }

Expand Down
Loading

0 comments on commit 23dc2d5

Please sign in to comment.