[8098] Support uint32 spell ids in code.

* 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.
This commit is contained in:
VladimirMangos 2009-06-30 07:37:36 +04:00
parent c24e041794
commit 1baec77845
21 changed files with 638 additions and 565 deletions

View file

@ -650,21 +650,8 @@ bool Player::Create( uint32 guidlow, const std::string& name, uint8 race, uint8
learnDefaultSpells();
// original action bar
std::list<uint16>::const_iterator action_itr[4];
for(int i=0; i<4; ++i)
action_itr[i] = info->action[i].begin();
for (; action_itr[0]!=info->action[0].end() && action_itr[1]!=info->action[1].end();)
{
uint16 taction[4];
for(int i=0; i<4 ;++i)
taction[i] = (*action_itr[i]);
addActionButton((uint8)taction[0], taction[1], (uint8)taction[2], (uint8)taction[3]);
for(int i=0; i<4 ;++i)
++action_itr[i];
}
for (PlayerCreateInfoActions::const_iterator action_itr = info->action.begin(); action_itr != info->action.end(); ++action_itr)
addActionButton(action_itr->button,action_itr->action,action_itr->type);
// original items
CharStartOutfitEntry const* oEntry = NULL;
@ -5425,65 +5412,69 @@ void Player::SendInitialActionButtons() const
sLog.outDetail( "Initializing Action Buttons for '%u'", GetGUIDLow() );
WorldPacket data(SMSG_ACTION_BUTTONS, 1+(MAX_ACTION_BUTTONS*4));
data << uint8(0); // can be 0, 1, 2
data << uint8(0); // can be 0, 1, 2 (talent spec)
for(int button = 0; button < MAX_ACTION_BUTTONS; ++button)
{
ActionButtonList::const_iterator itr = m_actionButtons.find(button);
if(itr != m_actionButtons.end() && itr->second.uState != ACTIONBUTTON_DELETED)
{
data << uint16(itr->second.action);
data << uint8(itr->second.misc);
data << uint8(itr->second.type);
}
data << uint32(itr->second.packedData);
else
{
data << uint32(0);
}
}
GetSession()->SendPacket( &data );
sLog.outDetail( "Action Buttons for '%u' Initialized", GetGUIDLow() );
}
bool Player::addActionButton(const uint8 button, const uint16 action, const uint8 type, const uint8 misc)
ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type)
{
if(button >= MAX_ACTION_BUTTONS)
{
sLog.outError( "Action %u not added into button %u for player %s: button must be < 132", action, button, GetName() );
return false;
return NULL;
}
// check cheating with adding non-known spells to action bar
if(type==ACTION_BUTTON_SPELL)
if(action >= MAX_ACTION_BUTTON_ACTION_VALUE)
{
if(!sSpellStore.LookupEntry(action))
{
sLog.outError( "Action %u not added into button %u for player %s: spell not exist", action, button, GetName() );
return false;
}
if(!HasSpell(action))
{
sLog.outError( "Action %u not added into button %u for player %s: player don't known this spell", action, button, GetName() );
return false;
}
sLog.outError( "Action %u not added into button %u for player %s: action must be < %u", action, button, GetName(), MAX_ACTION_BUTTON_ACTION_VALUE );
return NULL;
}
ActionButtonList::iterator buttonItr = m_actionButtons.find(button);
switch(type)
{
case ACTION_BUTTON_SPELL:
if(!sSpellStore.LookupEntry(action))
{
sLog.outError( "Action %u not added into button %u for player %s: spell not exist", action, button, GetName() );
return NULL;
}
if (buttonItr==m_actionButtons.end())
{ // just add new button
m_actionButtons[button] = ActionButton(action,type,misc);
if(!HasSpell(action))
{
sLog.outError( "Action %u not added into button %u for player %s: player don't known this spell", action, button, GetName() );
return NULL;
}
break;
case ACTION_BUTTON_ITEM:
if(!objmgr.GetItemPrototype(action))
{
sLog.outError( "Action %u not added into button %u for player %s: item not exist", action, button, GetName() );
return NULL;
}
break;
default:
break; // pther cases not checked at this moment
}
else
{ // change state of current button
ActionButtonUpdateState uState = buttonItr->second.uState;
buttonItr->second = ActionButton(action,type,misc);
if (uState != ACTIONBUTTON_NEW) buttonItr->second.uState = ACTIONBUTTON_CHANGED;
};
sLog.outDetail( "Player '%u' Added Action '%u' to Button '%u'", GetGUIDLow(), action, button );
return true;
// it create new button (NEW state) if need or return existed
ActionButton& ab = m_actionButtons[button];
// set data and update to CHANGED if not NEW
ab.SetActionAndType(action,ActionButtonType(type));
sLog.outDetail( "Player '%u' Added Action '%u' (type %u) to Button '%u'", GetGUIDLow(), action, uint32(type), button );
return &ab;
}
void Player::removeActionButton(uint8 button)
@ -14494,7 +14485,7 @@ void Player::_LoadActions(QueryResult *result)
{
m_actionButtons.clear();
//QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type,misc FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());
//QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());
if(result)
{
@ -14503,9 +14494,11 @@ void Player::_LoadActions(QueryResult *result)
Field *fields = result->Fetch();
uint8 button = fields[0].GetUInt8();
uint32 action = fields[1].GetUInt32();
uint8 type = fields[2].GetUInt8();
if(addActionButton(button, fields[1].GetUInt16(), fields[2].GetUInt8(), fields[3].GetUInt8()))
m_actionButtons[button].uState = ACTIONBUTTON_UNCHANGED;
if(ActionButton* ab = addActionButton(button, action, type))
ab->uState = ACTIONBUTTON_UNCHANGED;
else
{
sLog.outError( " ...at loading, and will deleted in DB also");
@ -15080,7 +15073,7 @@ void Player::_LoadSpells(QueryResult *result)
{
Field *fields = result->Fetch();
addSpell(fields[0].GetUInt16(), fields[1].GetBool(), false, false, fields[2].GetBool());
addSpell(fields[0].GetUInt32(), fields[1].GetBool(), false, false, fields[2].GetBool());
}
while( result->NextRow() );
@ -15579,14 +15572,14 @@ void Player::_SaveActions()
switch (itr->second.uState)
{
case ACTIONBUTTON_NEW:
CharacterDatabase.PExecute("INSERT INTO character_action (guid,button,action,type,misc) VALUES ('%u', '%u', '%u', '%u', '%u')",
GetGUIDLow(), (uint32)itr->first, (uint32)itr->second.action, (uint32)itr->second.type, (uint32)itr->second.misc );
CharacterDatabase.PExecute("INSERT INTO character_action (guid,button,action,type) VALUES ('%u', '%u', '%u', '%u')",
GetGUIDLow(), (uint32)itr->first, (uint32)itr->second.GetAction(), (uint32)itr->second.GetType() );
itr->second.uState = ACTIONBUTTON_UNCHANGED;
++itr;
break;
case ACTIONBUTTON_CHANGED:
CharacterDatabase.PExecute("UPDATE character_action SET action = '%u', type = '%u', misc= '%u' WHERE guid= '%u' AND button= '%u' ",
(uint32)itr->second.action, (uint32)itr->second.type, (uint32)itr->second.misc, GetGUIDLow(), (uint32)itr->first );
CharacterDatabase.PExecute("UPDATE character_action SET action = '%u', type = '%u' WHERE guid= '%u' AND button= '%u' ",
(uint32)itr->second.GetAction(), (uint32)itr->second.GetType(), GetGUIDLow(), (uint32)itr->first );
itr->second.uState = ACTIONBUTTON_UNCHANGED;
++itr;
break;
@ -15597,7 +15590,7 @@ void Player::_SaveActions()
default:
++itr;
break;
};
}
}
}
@ -16401,8 +16394,7 @@ void Player::PetSpellInitialize()
if(itr->second.state == PETSPELL_REMOVED)
continue;
data << uint16(itr->first);
data << uint16(itr->second.active); // pet spell active state isn't boolean
data << uint32(MAKE_UNIT_ACTION_BUTTON(itr->first,itr->second.active));
++addlist;
}
}
@ -16490,7 +16482,7 @@ void Player::CharmSpellInitialize()
{
for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
{
if(charmInfo->GetCharmSpell(i)->spellId)
if(charmInfo->GetCharmSpell(i)->GetAction())
++addlist;
}
}
@ -16515,11 +16507,8 @@ void Player::CharmSpellInitialize()
for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
{
CharmSpellEntry *cspell = charmInfo->GetCharmSpell(i);
if(cspell->spellId)
{
data << uint16(cspell->spellId);
data << uint16(cspell->active);
}
if(cspell->GetAction())
data << uint32(cspell->packedData);
}
}