Core/Units: moved CharmInfo class to an own file
This commit is contained in:
1 parent
254ebe6cbf
commit
bb6a8ac297
19 files changed
+458
-392
No files matched your search
@@ -24,6 +24,7 @@
|
||||
#include "BattlegroundScore.h"
|
||||
#include "CellImpl.h"
|
||||
#include "CharacterCache.h"
|
||||
#include "CharmInfo.h"
|
||||
#include "Chat.h"
|
||||
#include "ChatTextBuilder.h"
|
||||
#include "ChatPackets.h"
|
||||
@@ -9705,268 +9706,6 @@ void Unit::DeleteCharmInfo()
|
||||
m_charmInfo.reset();
|
||||
}
|
||||
|
||||
CharmInfo::CharmInfo(Unit* unit)
|
||||
: _unit(unit), _CommandState(COMMAND_FOLLOW), _petnumber(0), _oldReactState(REACT_PASSIVE),
|
||||
_isCommandAttack(false), _isCommandFollow(false), _isAtStay(false), _isFollowing(false), _isReturning(false),
|
||||
_stayX(0.0f), _stayY(0.0f), _stayZ(0.0f)
|
||||
{
|
||||
for (uint8 i = 0; i < MAX_SPELL_CHARM; ++i)
|
||||
_charmspells[i].SetActionAndType(0, ACT_DISABLED);
|
||||
|
||||
if (Creature* creature = _unit->ToCreature())
|
||||
{
|
||||
_oldReactState = creature->GetReactState();
|
||||
creature->SetReactState(REACT_PASSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
CharmInfo::~CharmInfo() { }
|
||||
|
||||
void CharmInfo::RestoreState()
|
||||
{
|
||||
if (Creature* creature = _unit->ToCreature())
|
||||
creature->SetReactState(_oldReactState);
|
||||
}
|
||||
|
||||
void CharmInfo::InitPetActionBar()
|
||||
{
|
||||
// the first 3 SpellOrActions are attack, follow and moveTo
|
||||
SetActionBar(ACTION_BAR_INDEX_ATTACK, COMMAND_ATTACK, ACT_COMMAND);
|
||||
SetActionBar(ACTION_BAR_INDEX_FOLLOW, COMMAND_FOLLOW, ACT_COMMAND);
|
||||
SetActionBar(ACTION_BAR_INDEX_MOVE_TO, COMMAND_MOVE_TO, ACT_COMMAND);
|
||||
|
||||
// middle 4 SpellOrActions are spells/special attacks/abilities
|
||||
for (uint32 i = 0; i < ACTION_BAR_INDEX_PET_SPELL_END-ACTION_BAR_INDEX_PET_SPELL_START; ++i)
|
||||
SetActionBar(ACTION_BAR_INDEX_PET_SPELL_START + i, 0, ACT_PASSIVE);
|
||||
|
||||
// last 3 SpellOrActions are reactions
|
||||
SetActionBar(ACTION_BAR_INDEX_ASSIST, REACT_ASSIST, ACT_REACTION);
|
||||
SetActionBar(ACTION_BAR_INDEX_DEFENSIVE, REACT_DEFENSIVE, ACT_REACTION);
|
||||
SetActionBar(ACTION_BAR_INDEX_PASSIVE, REACT_PASSIVE, ACT_REACTION);
|
||||
}
|
||||
|
||||
void CharmInfo::InitEmptyActionBar(bool withAttack)
|
||||
{
|
||||
if (withAttack)
|
||||
SetActionBar(ACTION_BAR_INDEX_START, COMMAND_ATTACK, ACT_COMMAND);
|
||||
else
|
||||
SetActionBar(ACTION_BAR_INDEX_START, 0, ACT_PASSIVE);
|
||||
for (uint32 x = ACTION_BAR_INDEX_START+1; x < ACTION_BAR_INDEX_END; ++x)
|
||||
SetActionBar(x, 0, ACT_PASSIVE);
|
||||
}
|
||||
|
||||
void CharmInfo::InitPossessCreateSpells()
|
||||
{
|
||||
if (_unit->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
// Adding switch until better way is found. Malcrom
|
||||
// Adding entrys to this switch will prevent COMMAND_ATTACK being added to pet bar.
|
||||
switch (_unit->GetEntry())
|
||||
{
|
||||
case 23575: // Mindless Abomination
|
||||
case 24783: // Trained Rock Falcon
|
||||
case 27664: // Crashin' Thrashin' Racer
|
||||
case 40281: // Crashin' Thrashin' Racer
|
||||
case 28511: // Eye of Acherus
|
||||
break;
|
||||
default:
|
||||
InitEmptyActionBar();
|
||||
break;
|
||||
}
|
||||
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
{
|
||||
uint32 spellId = _unit->ToCreature()->m_spells[i];
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
if (spellInfo)
|
||||
{
|
||||
if (spellInfo->HasAttribute(SPELL_ATTR5_NOT_AVAILABLE_WHILE_CHARMED))
|
||||
continue;
|
||||
|
||||
if (spellInfo->IsPassive())
|
||||
_unit->CastSpell(_unit, spellInfo->Id, true);
|
||||
else
|
||||
AddSpellToActionBar(spellInfo, ACT_PASSIVE, i % MAX_UNIT_ACTION_BAR_INDEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
InitEmptyActionBar();
|
||||
}
|
||||
|
||||
void CharmInfo::InitCharmCreateSpells()
|
||||
{
|
||||
if (_unit->GetTypeId() == TYPEID_PLAYER) // charmed players don't have spells
|
||||
{
|
||||
InitEmptyActionBar();
|
||||
return;
|
||||
}
|
||||
|
||||
InitPetActionBar();
|
||||
|
||||
for (uint32 x = 0; x < MAX_SPELL_CHARM; ++x)
|
||||
{
|
||||
uint32 spellId = _unit->ToCreature()->m_spells[x];
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
|
||||
if (!spellInfo)
|
||||
{
|
||||
_charmspells[x].SetActionAndType(spellId, ACT_DISABLED);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (spellInfo->HasAttribute(SPELL_ATTR5_NOT_AVAILABLE_WHILE_CHARMED))
|
||||
continue;
|
||||
|
||||
if (spellInfo->IsPassive())
|
||||
{
|
||||
_unit->CastSpell(_unit, spellInfo->Id, true);
|
||||
_charmspells[x].SetActionAndType(spellId, ACT_PASSIVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
_charmspells[x].SetActionAndType(spellId, ACT_DISABLED);
|
||||
|
||||
ActiveStates newstate = ACT_PASSIVE;
|
||||
|
||||
if (!spellInfo->IsAutocastable())
|
||||
newstate = ACT_PASSIVE;
|
||||
else
|
||||
{
|
||||
if (spellInfo->NeedsExplicitUnitTarget())
|
||||
{
|
||||
newstate = ACT_ENABLED;
|
||||
ToggleCreatureAutocast(spellInfo, true);
|
||||
}
|
||||
else
|
||||
newstate = ACT_DISABLED;
|
||||
}
|
||||
|
||||
AddSpellToActionBar(spellInfo, newstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CharmInfo::AddSpellToActionBar(SpellInfo const* spellInfo, ActiveStates newstate, uint8 preferredSlot)
|
||||
{
|
||||
uint32 spell_id = spellInfo->Id;
|
||||
uint32 first_id = spellInfo->GetFirstRankSpell()->Id;
|
||||
|
||||
ASSERT(preferredSlot < MAX_UNIT_ACTION_BAR_INDEX);
|
||||
// new spell rank can be already listed
|
||||
for (uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
|
||||
{
|
||||
if (uint32 action = PetActionBar[i].GetAction())
|
||||
{
|
||||
if (PetActionBar[i].IsActionBarForSpell() && sSpellMgr->GetFirstSpellInChain(action) == first_id)
|
||||
{
|
||||
PetActionBar[i].SetAction(spell_id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// or use empty slot in other case
|
||||
for (uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
|
||||
{
|
||||
uint8 j = (preferredSlot + i) % MAX_UNIT_ACTION_BAR_INDEX;
|
||||
if (!PetActionBar[j].GetAction() && PetActionBar[j].IsActionBarForSpell())
|
||||
{
|
||||
SetActionBar(j, spell_id, newstate == ACT_DECIDE ? spellInfo->IsAutocastable() ? ACT_ENABLED : ACT_PASSIVE : newstate);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id)
|
||||
{
|
||||
uint32 first_id = sSpellMgr->GetFirstSpellInChain(spell_id);
|
||||
|
||||
for (uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
|
||||
{
|
||||
if (uint32 action = PetActionBar[i].GetAction())
|
||||
{
|
||||
if (PetActionBar[i].IsActionBarForSpell() && sSpellMgr->GetFirstSpellInChain(action) == first_id)
|
||||
{
|
||||
SetActionBar(i, 0, ACT_PASSIVE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CharmInfo::ToggleCreatureAutocast(SpellInfo const* spellInfo, bool apply)
|
||||
{
|
||||
if (spellInfo->IsPassive())
|
||||
return;
|
||||
|
||||
for (uint32 x = 0; x < MAX_SPELL_CHARM; ++x)
|
||||
if (spellInfo->Id == _charmspells[x].GetAction())
|
||||
_charmspells[x].SetType(apply ? ACT_ENABLED : ACT_DISABLED);
|
||||
}
|
||||
|
||||
void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow)
|
||||
{
|
||||
_petnumber = petnumber;
|
||||
if (statwindow)
|
||||
_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, _petnumber);
|
||||
else
|
||||
_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0);
|
||||
}
|
||||
|
||||
void CharmInfo::LoadPetActionBar(const std::string& data)
|
||||
{
|
||||
InitPetActionBar();
|
||||
|
||||
Tokenizer tokens(data, ' ');
|
||||
|
||||
if (tokens.size() != (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START) * 2)
|
||||
return; // non critical, will reset to default
|
||||
|
||||
uint8 index = ACTION_BAR_INDEX_START;
|
||||
Tokenizer::const_iterator iter = tokens.begin();
|
||||
for (; index < ACTION_BAR_INDEX_END; ++iter, ++index)
|
||||
{
|
||||
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
|
||||
ActiveStates type = ActiveStates(atol(*iter));
|
||||
++iter;
|
||||
uint32 action = atoul(*iter);
|
||||
|
||||
PetActionBar[index].SetActionAndType(action, type);
|
||||
|
||||
// check correctness
|
||||
if (PetActionBar[index].IsActionBarForSpell())
|
||||
{
|
||||
SpellInfo const* spelInfo = sSpellMgr->GetSpellInfo(PetActionBar[index].GetAction());
|
||||
if (!spelInfo)
|
||||
SetActionBar(index, 0, ACT_PASSIVE);
|
||||
else if (!spelInfo->IsAutocastable())
|
||||
SetActionBar(index, PetActionBar[index].GetAction(), ACT_PASSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CharmInfo::BuildActionBar(WorldPacket* data)
|
||||
{
|
||||
for (uint32 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
|
||||
*data << uint32(PetActionBar[i].packedData);
|
||||
}
|
||||
|
||||
void CharmInfo::SetSpellAutocast(SpellInfo const* spellInfo, bool state)
|
||||
{
|
||||
for (uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
|
||||
{
|
||||
if (spellInfo->Id == PetActionBar[i].GetAction() && PetActionBar[i].IsActionBarForSpell())
|
||||
{
|
||||
PetActionBar[i].SetType(state ? ACT_ENABLED : ACT_DISABLED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Unit::isFrozen() const
|
||||
{
|
||||
return HasAuraState(AURA_STATE_FROZEN);
|
||||
|
||||
Reference in new issue
Block a user