aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-06-01 21:49:42 -0500
committermegamage <none@none>2009-06-01 21:49:42 -0500
commit4e31ec051d9d55327a617aba6d8841d2f1e4b8d1 (patch)
treef1b7d2133ceed9bad76d47cac32c12e3b8fb6df2 /src
parent2c350bcb803ab386a3680227aa6e641e3ae8ad03 (diff)
[7932] Store in DB only spell part of pet action bar, set other to default state (reaction saved). Author: VladimirMangos
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Pet.cpp11
-rw-r--r--src/game/Unit.cpp35
-rw-r--r--src/game/Unit.h12
3 files changed, 34 insertions, 24 deletions
diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp
index d2bef6ddba7..c204717668f 100644
--- a/src/game/Pet.cpp
+++ b/src/game/Pet.cpp
@@ -268,14 +268,10 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
}
else
{
- // Load action bar data
+ // load action bar, if data broken will fill later by default spells.
if (!is_temporary_summoned)
{
- if(!m_charmInfo->LoadActionBar(fields[13].GetCppString()))
- {
- delete result;
- return false;
- }
+ m_charmInfo->LoadPetActionBar(fields[13].GetCppString());
_LoadSpells();
_LoadSpellCooldowns();
@@ -398,7 +394,8 @@ void Pet::SavePetToDB(PetSaveMode mode)
<< curmana << ", "
<< GetPower(POWER_HAPPINESS) << ", '";
- for(uint32 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
+ // save only spell slots from action bar
+ for(uint32 i = ACTION_BAR_INDEX_PET_SPELL_START; i < ACTION_BAR_INDEX_PET_SPELL_END; ++i)
{
ss << uint32(m_charmInfo->GetActionBarEntry(i)->Type) << " "
<< uint32(m_charmInfo->GetActionBarEntry(i)->SpellOrAction) << " ";
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 7c38b3348a6..9bef10368d8 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -11752,21 +11752,25 @@ CharmInfo::~CharmInfo()
void CharmInfo::InitPetActionBar()
{
// the first 3 SpellOrActions are attack, follow and stay
- for(uint32 i = 0; i < 3; i++)
- {
- SetActionBar(i,COMMAND_ATTACK - i,ACT_COMMAND);
- SetActionBar(i + 7,COMMAND_ATTACK - i,ACT_REACTION);
- }
- for(uint32 i = 3; i < 7; ++i)
- SetActionBar(i,0,ACT_PASSIVE);
+ for(uint32 i = 0; i < ACTION_BAR_INDEX_PET_SPELL_START - ACTION_BAR_INDEX_START; ++i)
+ SetActionBar(ACTION_BAR_INDEX_START + i,COMMAND_ATTACK - i,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
+ for(uint32 i = 0; i < ACTION_BAR_INDEX_END - ACTION_BAR_INDEX_PET_SPELL_END; ++i)
+ SetActionBar(ACTION_BAR_INDEX_PET_SPELL_END + i,COMMAND_ATTACK - i,ACT_REACTION);
}
void CharmInfo::InitEmptyActionBar(bool withAttack)
{
if(withAttack)
- SetActionBar(0,COMMAND_ATTACK,ACT_COMMAND);
-
- for(uint32 x = withAttack ? 1 : 0; x < MAX_UNIT_ACTION_BAR_INDEX; ++x)
+ 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);
}
@@ -11916,16 +11920,18 @@ void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow)
m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0);
}
-bool CharmInfo::LoadActionBar( std::string data )
+void CharmInfo::LoadPetActionBar( std::string data )
{
+ InitPetActionBar();
+
Tokens tokens = StrSplit(data, " ");
- if (tokens.size() != MAX_UNIT_ACTION_BAR_INDEX*2)
- return false;
+ if (tokens.size() != (ACTION_BAR_INDEX_PET_SPELL_END-ACTION_BAR_INDEX_PET_SPELL_START)*2)
+ return; // non critical, will reset to default
int index;
Tokens::iterator iter;
- for(iter = tokens.begin(), index = 0; index < MAX_UNIT_ACTION_BAR_INDEX; ++iter, ++index )
+ for(iter = tokens.begin(), index = ACTION_BAR_INDEX_PET_SPELL_START; index < ACTION_BAR_INDEX_PET_SPELL_END; ++iter, ++index )
{
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
PetActionBar[index].Type = atol((*iter).c_str());
@@ -11941,7 +11947,6 @@ bool CharmInfo::LoadActionBar( std::string data )
SetActionBar(index,PetActionBar[index].SpellOrAction,ACT_PASSIVE);
}
}
- return true;
}
void CharmInfo::BuildActionBar( WorldPacket* data )
diff --git a/src/game/Unit.h b/src/game/Unit.h
index 26c8fc39a97..d788a9ad4f6 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -885,7 +885,15 @@ struct CharmSpellEntry
typedef std::list<Player*> SharedVisionList;
-#define MAX_UNIT_ACTION_BAR_INDEX 10
+enum ActionBarIndex
+{
+ ACTION_BAR_INDEX_START = 0,
+ ACTION_BAR_INDEX_PET_SPELL_START = 3,
+ ACTION_BAR_INDEX_PET_SPELL_END = 7,
+ ACTION_BAR_INDEX_END = 10,
+};
+
+#define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
struct CharmInfo
{
@@ -910,7 +918,7 @@ struct CharmInfo
//return true if successful
bool AddSpellToActionBar(uint32 spellid, ActiveStates newstate = ACT_DECIDE);
bool RemoveSpellFromActionBar(uint32 spell_id);
- bool LoadActionBar(std::string data);
+ void LoadPetActionBar(std::string data);
void BuildActionBar(WorldPacket* data);
void SetSpellAutocast(uint32 spell_id, bool state);
void SetActionBar(uint8 index, uint32 spellOrAction,ActiveStates type)