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

Commit

Permalink
Core/Pets: initial work on implementing PetModeFlags::DisableActions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovahlord committed Oct 17, 2023
1 parent 8adfcbf commit 1ad2d96
Show file tree
Hide file tree
Showing 24 changed files with 700 additions and 514 deletions.
7 changes: 4 additions & 3 deletions src/server/game/AI/CoreAI/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "PetAI.h"
#include "AIException.h"
#include "Creature.h"
#include "CharmInfo.h"
#include "Errors.h"
#include "Group.h"
#include "Log.h"
Expand Down Expand Up @@ -436,13 +437,13 @@ void PetAI::HandleReturnMovement()
if (!me->GetCharmInfo()->IsAtStay() && !me->GetCharmInfo()->IsReturning())
{
// Return to previous position where stay was clicked
float x, y, z;
Position stayPosition;

me->GetCharmInfo()->GetStayPosition(x, y, z);
me->GetCharmInfo()->GetStayPosition(stayPosition);
ClearCharmInfoFlags();
me->GetCharmInfo()->SetIsReturning(true);
me->GetMotionMaster()->Clear();
me->GetMotionMaster()->MovePoint(me->GetGUID().GetCounter(), x, y, z);
me->GetMotionMaster()->MovePoint(me->GetGUID().GetCounter(), stayPosition);
}
}
if (me->GetCharmInfo()->HasCommandState(COMMAND_FOLLOW))
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/CreatureAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void CreatureAI::JustAppeared()
NewTemporarySummon* summon = me->ToTemporarySummon();
if (summon->ShouldJoinSummonerSpawnGroupAfterCreation() || summon->ShouldFollowSummonerAfterCreation() && !summon->GetVehicle())
{
if (Unit* summoner = summon->GetSummoner())
if (Unit* summoner = summon->GetInternalSummoner())
{
summon->GetMotionMaster()->Clear();
summon->FollowTarget(summoner); // @todo: ShouldJoinSummonerSpawnGroupAfterCreation should actually make the creature join the target's formation
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Creature.h"
#include "BattlegroundMgr.h"
#include "CellImpl.h"
#include "CharmInfo.h"
#include "Common.h"
#include "CreatureAI.h"
#include "CreatureAISelector.h"
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Creature/CreatureData.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ enum CreatureStaticFlags2
CREATURE_STATIC_FLAG_2_PVP_ENABLING_OOC = 0x00080000,
CREATURE_STATIC_FLAG_2_NO_DEATH_MESSAGE = 0x00100000, // CREATURE_TYPE_FLAG_NO_DEATH_MESSAGE
CREATURE_STATIC_FLAG_2_IGNORE_PATHING_FAILURE = 0x00200000,
CREATURE_STATIC_FLAG_2_FULL_SPELL_LIST = 0x00400000,
CREATURE_STATIC_FLAG_2_FULL_SPELL_LIST = 0x00400000, // Only allows spells being added to the action bar
CREATURE_STATIC_FLAG_2_DOES_NOT_REDUCE_REPUTATION_FOR_RAIDS = 0x00800000,
CREATURE_STATIC_FLAG_2_IGNORE_MISDIRECTION = 0x01000000,
CREATURE_STATIC_FLAG_2_HIDE_BODY = 0x02000000, // UNIT_FLAG2_HIDE_BODY
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Creature/TemporarySummon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "TemporarySummon.h"
#include "CharmInfo.h"
#include "CreatureAI.h"
#include "DBCStructure.h"
#include "Log.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void NewGuardian::InitializeStats()
}

UpdateAllStats();
SetFullHealth();
}

void NewGuardian::HandlePostSummonActions()
Expand Down
39 changes: 39 additions & 0 deletions src/server/game/Entities/Creature/TemporarySummon/NewPet.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include "NewPet.h"
#include "CharmInfo.h"
#include "DBCStores.h"
#include "GameTime.h"
#include "Map.h"
Expand Down Expand Up @@ -412,6 +413,44 @@ void NewPet::ResetTalents()
SendTalentsInfoUpdateToSummoner();
}

void NewPet::DisablePetActions(bool disable)
{
ASSERT(GetCharmInfo());

// Store the original settings before we change them
if (disable)
{
PetDisableActionSettings& settings = _disableActionSettings.emplace();
settings.OriginalReactState = GetReactState();
settings.OriginalCommandState = GetCharmInfo()->GetCommandState();
}
else
{
// Restore the settings
if (_disableActionSettings.has_value())
{
SetReactState(_disableActionSettings->OriginalReactState);
GetCharmInfo()->SetCommandState(_disableActionSettings->OriginalCommandState);
}
}

WorldPackets::Pet::SPetMode packet;
packet.PetGUID = GetGUID();
packet.CommandState = GetCharmInfo()->GetCommandState();
packet.ReactState = GetReactState();
if (disable)
{
packet.Flag = AsUnderlyingType(PetModeFlags::DisableActions);

SetReactState(REACT_PASSIVE);
GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
}

if (Unit const* summoner = GetInternalSummoner())
if (Player const* player = summoner->ToPlayer())
player->SendDirectMessage(packet.Write());
}

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

void NewPet::SendSpellLearnedToSummoner(uint32 spellId)
Expand Down
9 changes: 9 additions & 0 deletions src/server/game/Entities/Creature/TemporarySummon/NewPet.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ struct PetSpell
PetSpellType Type = PETSPELL_NORMAL;
};

struct PetDisableActionSettings
{
CommandStates OriginalCommandState = COMMAND_FOLLOW;
ReactStates OriginalReactState = REACT_PASSIVE;
};

using PetSpellMap = std::unordered_map<uint32 /*spellId*/, PetSpell /*actionBarValues*/>;
using PetTalentMap = std::unordered_map<uint32 /*talentId*/, uint32 /*rank*/>;

Expand Down Expand Up @@ -92,6 +98,8 @@ class TC_GAME_API NewPet final : public NewGuardian
DeclinedName const* GetDeclinedNames() const { return _declinedNames.get(); }
// Resets all talents that the pet has currently learned
void ResetTalents();
// Disables pets actions and toggles the command state to passive/follow
void DisablePetActions(bool disable);

private:
void SendSpellLearnedToSummoner(uint32 spellId);
Expand All @@ -111,6 +119,7 @@ class TC_GAME_API NewPet final : public NewGuardian
bool _isClassPet;
PetSpellMap _spells;
Optional<PlayerPetDataKey> _playerPetDataKey;
Optional<PetDisableActionSettings> _disableActionSettings;
PetTalentMap _talents;
std::unique_ptr<DeclinedName> _declinedNames;
};
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Pet/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "CharmInfo.h"
#include "Common.h"
#include "DatabaseEnv.h"
#include "Log.h"
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "CharacterCache.h"
#include "CharacterDatabaseCleaner.h"
#include "CharacterPackets.h"
#include "CharmInfo.h"
#include "Chat.h"
#include "CinematicMgr.h"
#include "CombatPackets.h"
Expand Down
Loading

0 comments on commit 1ad2d96

Please sign in to comment.