Skip to content

Commit

Permalink
[9349] Add posssibility for one action button set per talent spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
hunuza committed Feb 10, 2010
1 parent 4db904b commit 1f8f516
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 45 deletions.
3 changes: 2 additions & 1 deletion sql/characters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

DROP TABLE IF EXISTS `character_db_version`;
CREATE TABLE `character_db_version` (
`required_9339_01_characters_group` bit(1) default NULL
`required_9349_01_characters_character_action` bit(1) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Last applied sql update to DB';

--
Expand Down Expand Up @@ -337,6 +337,7 @@ UNLOCK TABLES;
DROP TABLE IF EXISTS `character_action`;
CREATE TABLE `character_action` (
`guid` int(11) unsigned NOT NULL default '0' COMMENT 'Global Unique Identifier',
`spec` tinyint(3) unsigned NOT NULL default '0',
`button` tinyint(3) unsigned NOT NULL default '0',
`action` int(11) unsigned NOT NULL default '0',
`type` tinyint(3) unsigned NOT NULL default '0',
Expand Down
2 changes: 2 additions & 0 deletions sql/updates/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pkgdata_DATA = \
9329_01_mangos_spell_chain.sql \
9331_01_mangos_quest_template.sql \
9339_01_characters_group.sql \
9349_01_characters_character_action.sql \
README

## Additional files to include when running 'make dist'
Expand Down Expand Up @@ -106,4 +107,5 @@ EXTRA_DIST = \
9329_01_mangos_spell_chain.sql \
9331_01_mangos_quest_template.sql \
9339_01_characters_group.sql \
9349_01_characters_character_action.sql \
README
2 changes: 1 addition & 1 deletion src/game/CharacterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool LoginQueryHolder::Initialize()
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADREPUTATION, "SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADINVENTORY, "SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS, "SELECT button,action,type FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACTIONS, "SELECT spec,button,action,type FROM character_action WHERE guid = '%u' ORDER BY button", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILCOUNT, "SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD "'", GUID_LOPART(m_guid), (uint64)time(NULL));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILDATE, "SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSOCIALLIST, "SELECT friend,flags,note FROM character_social WHERE guid = '%u' LIMIT 255", GUID_LOPART(m_guid));
Expand Down
2 changes: 1 addition & 1 deletion src/game/MiscHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ void WorldSession::HandleSetActionButtonOpcode(WorldPacket& recv_data)
sLog.outError( "MISC: Unknown action button type %u for action %u into button %u", type, action, button );
return;
}
GetPlayer()->addActionButton(button, action, type);
GetPlayer()->addActionButton(GetPlayer()->m_activeSpec, button, action, type);
}
}

Expand Down
84 changes: 46 additions & 38 deletions src/game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ bool Player::Create( uint32 guidlow, const std::string& name, uint8 race, uint8

// original action bar
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);
addActionButton(0, action_itr->button,action_itr->action,action_itr->type);

// original items
CharStartOutfitEntry const* oEntry = NULL;
Expand Down Expand Up @@ -5635,10 +5635,11 @@ void Player::SendInitialActionButtons() const

WorldPacket data(SMSG_ACTION_BUTTONS, 1+(MAX_ACTION_BUTTONS*4));
data << uint8(0); // can be 0, 1, 2 (talent spec)
ActionButtonList const& currentActionButtonList = m_actionButtons[m_activeSpec];
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)
ActionButtonList::const_iterator itr = currentActionButtonList.find(button);
if(itr != currentActionButtonList.end() && itr->second.uState != ACTIONBUTTON_DELETED)
data << uint32(itr->second.packedData);
else
data << uint32(0);
Expand Down Expand Up @@ -5703,14 +5704,14 @@ bool Player::IsActionButtonDataValid(uint8 button, uint32 action, uint8 type, Pl
return true;
}

ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type)
ActionButton* Player::addActionButton(uint8 spec, uint8 button, uint32 action, uint8 type)
{

if (!IsActionButtonDataValid(button,action,type,this))
return NULL;

// it create new button (NEW state) if need or return existed
ActionButton& ab = m_actionButtons[button];
ActionButton& ab = m_actionButtons[spec][button];

// set data and update to CHANGED if not NEW
ab.SetActionAndType(action,ActionButtonType(type));
Expand All @@ -5721,12 +5722,13 @@ ActionButton* Player::addActionButton(uint8 button, uint32 action, uint8 type)

void Player::removeActionButton(uint8 button)
{
ActionButtonList::iterator buttonItr = m_actionButtons.find(button);
if (buttonItr==m_actionButtons.end())
ActionButtonList& currentActionButtonList = m_actionButtons[m_activeSpec];
ActionButtonList::iterator buttonItr = currentActionButtonList.find(button);
if (buttonItr==currentActionButtonList.end())
return;

if(buttonItr->second.uState==ACTIONBUTTON_NEW)
m_actionButtons.erase(buttonItr); // new and not saved
currentActionButtonList.erase(buttonItr); // new and not saved
else
buttonItr->second.uState = ACTIONBUTTON_DELETED; // saved, will deleted at next save

Expand All @@ -5735,8 +5737,9 @@ void Player::removeActionButton(uint8 button)

ActionButton const* Player::GetActionButton(uint8 button)
{
ActionButtonList::iterator buttonItr = m_actionButtons.find(button);
if (buttonItr==m_actionButtons.end() || buttonItr->second.uState == ACTIONBUTTON_DELETED)
ActionButtonList& currentActionButtonList = m_actionButtons[m_activeSpec];
ActionButtonList::iterator buttonItr = currentActionButtonList.find(button);
if (buttonItr==currentActionButtonList.end() || buttonItr->second.uState == ACTIONBUTTON_DELETED)
return NULL;

return &buttonItr->second;
Expand Down Expand Up @@ -15208,28 +15211,30 @@ bool Player::isAllowedToLoot(Creature* creature)

void Player::_LoadActions(QueryResult *result)
{
m_actionButtons.clear();
for(int i = 0; i < MAX_TALENT_SPEC_COUNT; ++i)
m_actionButtons[i].clear();

//QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());
//QueryResult *result = CharacterDatabase.PQuery("SELECT spec, button,action,type FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());

if(result)
{
do
{
Field *fields = result->Fetch();

uint8 button = fields[0].GetUInt8();
uint32 action = fields[1].GetUInt32();
uint8 type = fields[2].GetUInt8();
uint8 spec = fields[0].GetUInt8();
uint8 button = fields[1].GetUInt8();
uint32 action = fields[2].GetUInt32();
uint8 type = fields[3].GetUInt8();

if(ActionButton* ab = addActionButton(button, action, type))
if(ActionButton* ab = addActionButton(spec, button, action, type))
ab->uState = ACTIONBUTTON_UNCHANGED;
else
{
sLog.outError( " ...at loading, and will deleted in DB also");

// Will deleted in DB at next save (it can create data until save but marked as deleted)
m_actionButtons[button].uState = ACTIONBUTTON_DELETED;
m_actionButtons[spec][button].uState = ACTIONBUTTON_DELETED;
}
}
while( result->NextRow() );
Expand Down Expand Up @@ -16312,29 +16317,32 @@ void Player::SaveGoldToDB()

void Player::_SaveActions()
{
for(ActionButtonList::iterator itr = m_actionButtons.begin(); itr != m_actionButtons.end(); )
for(int i = 0; i < MAX_TALENT_SPEC_COUNT; ++i)
{
switch (itr->second.uState)
for(ActionButtonList::iterator itr = m_actionButtons[i].begin(); itr != m_actionButtons[i].end(); )
{
case ACTIONBUTTON_NEW:
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' 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;
case ACTIONBUTTON_DELETED:
CharacterDatabase.PExecute("DELETE FROM character_action WHERE guid = '%u' and button = '%u'", GetGUIDLow(), (uint32)itr->first );
m_actionButtons.erase(itr++);
break;
default:
++itr;
break;
switch (itr->second.uState)
{
case ACTIONBUTTON_NEW:
CharacterDatabase.PExecute("INSERT INTO character_action (guid,spec, button,action,type) VALUES ('%u', '%u', '%u', '%u', '%u')",
GetGUIDLow(), i, (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' WHERE guid= '%u' AND button= '%u' AND spec = '%u'",
(uint32)itr->second.GetAction(), (uint32)itr->second.GetType(), GetGUIDLow(), (uint32)itr->first, i );
itr->second.uState = ACTIONBUTTON_UNCHANGED;
++itr;
break;
case ACTIONBUTTON_DELETED:
CharacterDatabase.PExecute("DELETE FROM character_action WHERE guid = '%u' AND button = '%u' AND spec = '%u'", GetGUIDLow(), (uint32)itr->first, i);
m_actionButtons[i].erase(itr++);
break;
default:
++itr;
break;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ class MANGOS_DLL_SPEC Player : public Unit
}

static bool IsActionButtonDataValid(uint8 button, uint32 action, uint8 type, Player* player);
ActionButton* addActionButton(uint8 button, uint32 action, uint8 type);
ActionButton* addActionButton(uint8 spec, uint8 button, uint32 action, uint8 type);
void removeActionButton(uint8 button);
void SendInitialActionButtons() const;
ActionButton const* GetActionButton(uint8 button);
Expand Down Expand Up @@ -2360,7 +2360,7 @@ class MANGOS_DLL_SPEC Player : public Unit
uint32 m_activeSpec;
uint32 m_specsCount;

ActionButtonList m_actionButtons;
ActionButtonList m_actionButtons[MAX_TALENT_SPEC_COUNT];

float m_auraBaseMod[BASEMOD_END][MOD_END];
int16 m_baseRatingValue[MAX_COMBAT_RATING];
Expand Down
1 change: 1 addition & 0 deletions src/game/SharedDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ const uint32 ItemQualityColors[MAX_ITEM_QUALITY] = {
#define SPELL_ATTR_EX6_UNK30 0x40000000 // 30 not set in 3.0.3
#define SPELL_ATTR_EX6_UNK31 0x80000000 // 31 not set in 3.0.3

#define MAX_TALENT_SPEC_COUNT 2
#define MAX_GLYPH_SLOT_INDEX 6

enum SheathTypes
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9348"
#define REVISION_NR "9349"
#endif // __REVISION_NR_H__
2 changes: 1 addition & 1 deletion src/shared/revision_sql.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef __REVISION_SQL_H__
#define __REVISION_SQL_H__
#define REVISION_DB_CHARACTERS "required_9339_01_characters_group"
#define REVISION_DB_CHARACTERS "required_9349_01_characters_character_action"
#define REVISION_DB_MANGOS "required_9331_01_mangos_quest_template"
#define REVISION_DB_REALMD "required_9010_01_realmd_realmlist"
#endif // __REVISION_SQL_H__

0 comments on commit 1f8f516

Please sign in to comment.