*Backup your DB!

[8098] Support uint32 spell ids in code. Author: VladimirMangos

    * Propertly work with uint32 spell ids in player action bar
    * Fix in same time bug with not save equipment set button with id==0
    * Merge misc field in character_action and playercreateinfo_action to action field as 3 byte
    * Propertly load uint32 spell ids from character_spell
    * Fixed types for some pet/creature related structure for spell id storing.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-07-01 18:07:20 -05:00
parent 8122a15f46
commit e1d93bd00f
16 changed files with 635 additions and 571 deletions

View File

@@ -12193,11 +12193,9 @@ void Unit::DeleteCharmInfo()
CharmInfo::CharmInfo(Unit* unit)
: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_petnumber(0), m_barInit(false)
{
for(uint8 i =0; i<MAX_SPELL_CHARM; ++i)
{
m_charmspells[i].spellId = 0;
m_charmspells[i].active = ACT_DISABLED;
}
for(uint8 i = 0; i < MAX_SPELL_CHARM; ++i)
m_charmspells[i].SetActionAndType(0,ACT_DISABLED);
if(m_unit->GetTypeId() == TYPEID_UNIT)
{
m_oldReactState = ((Creature*)m_unit)->GetReactState();
@@ -12274,18 +12272,21 @@ void CharmInfo::InitCharmCreateSpells()
if(spellInfo && spellInfo->Attributes & SPELL_ATTR_CASTABLE_WHILE_DEAD)
spellId = 0;
m_charmspells[x].spellId = spellId;
if(!spellId)
{
m_charmspells[x].SetActionAndType(spellId,ACT_DISABLED);
continue;
}
if (IsPassiveSpell(spellId))
{
m_unit->CastSpell(m_unit, spellId, true);
m_charmspells[x].active = ACT_PASSIVE;
m_charmspells[x].SetActionAndType(spellId,ACT_PASSIVE);
}
else
{
m_charmspells[x].SetActionAndType(spellId,ACT_DISABLED);
ActiveStates newstate;
if(spellInfo)
{
@@ -12320,11 +12321,11 @@ bool CharmInfo::AddSpellToActionBar(uint32 spell_id, ActiveStates newstate)
// new spell rank can be already listed
for(uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if (PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
if (uint32 action = PetActionBar[i].GetAction())
{
if (spellmgr.GetFirstSpellInChain(PetActionBar[i].SpellOrAction) == first_id)
if (PetActionBar[i].IsActionBarForSpell() && spellmgr.GetFirstSpellInChain(action) == first_id)
{
PetActionBar[i].SpellOrAction = spell_id;
PetActionBar[i].SetAction(spell_id);
return true;
}
}
@@ -12333,7 +12334,7 @@ bool CharmInfo::AddSpellToActionBar(uint32 spell_id, ActiveStates newstate)
// or use empty slot in other case
for(uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if (!PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
if (!PetActionBar[i].GetAction() && PetActionBar[i].IsActionBarForSpell())
{
SetActionBar(i,spell_id,newstate == ACT_DECIDE ? IsAutocastableSpell(spell_id) ? ACT_DISABLED : ACT_PASSIVE : newstate);
return true;
@@ -12348,9 +12349,9 @@ bool CharmInfo::RemoveSpellFromActionBar(uint32 spell_id)
for(uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if (PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
if (uint32 action = PetActionBar[i].GetAction())
{
if (spellmgr.GetFirstSpellInChain(PetActionBar[i].SpellOrAction) == first_id)
if (PetActionBar[i].IsActionBarForSpell() && spellmgr.GetFirstSpellInChain(action) == first_id)
{
SetActionBar(i,0,ACT_PASSIVE);
return true;
@@ -12367,12 +12368,8 @@ void CharmInfo::ToggleCreatureAutocast(uint32 spellid, bool apply)
return;
for(uint32 x = 0; x < MAX_SPELL_CHARM; ++x)
{
if(spellid == m_charmspells[x].spellId)
{
m_charmspells[x].active = apply ? ACT_ENABLED : ACT_DISABLED;
}
}
if(spellid == m_charmspells[x].GetAction())
m_charmspells[x].SetType(apply ? ACT_ENABLED : ACT_DISABLED);
}
void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow)
@@ -12398,17 +12395,19 @@ void CharmInfo::LoadPetActionBar(const std::string& data )
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());
uint8 type = atol((*iter).c_str());
++iter;
PetActionBar[index].SpellOrAction = atol((*iter).c_str());
uint32 action = atol((*iter).c_str());
PetActionBar[index].SetActionAndType(action,ActiveStates(type));
// check correctness
if(PetActionBar[index].IsActionBarForSpell())
{
if(!sSpellStore.LookupEntry(PetActionBar[index].SpellOrAction))
if(!sSpellStore.LookupEntry(PetActionBar[index].GetAction()))
SetActionBar(index,0,ACT_PASSIVE);
else if(!IsAutocastableSpell(PetActionBar[index].SpellOrAction))
SetActionBar(index,PetActionBar[index].SpellOrAction,ACT_PASSIVE);
else if(!IsAutocastableSpell(PetActionBar[index].GetAction()))
SetActionBar(index,PetActionBar[index].GetAction(),ACT_PASSIVE);
}
}
}
@@ -12416,19 +12415,16 @@ void CharmInfo::LoadPetActionBar(const std::string& data )
void CharmInfo::BuildActionBar( WorldPacket* data )
{
for(uint32 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
*data << uint16(PetActionBar[i].SpellOrAction);
*data << uint16(PetActionBar[i].Type);
}
*data << uint32(PetActionBar[i].packedData);
}
void CharmInfo::SetSpellAutocast( uint32 spell_id, bool state )
{
for(uint8 i = 0; i < MAX_UNIT_ACTION_BAR_INDEX; ++i)
{
if(spell_id == PetActionBar[i].SpellOrAction && PetActionBar[i].IsActionBarForSpell())
if(spell_id == PetActionBar[i].GetAction() && PetActionBar[i].IsActionBarForSpell())
{
PetActionBar[i].Type = state ? ACT_ENABLED : ACT_DISABLED;
PetActionBar[i].SetType(state ? ACT_ENABLED : ACT_DISABLED);
break;
}
}