Skip to content

Commit

Permalink
Implement talent template system
Browse files Browse the repository at this point in the history
  • Loading branch information
LilleCarl committed Feb 21, 2014
1 parent df34774 commit 289f979
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 3 deletions.
8 changes: 8 additions & 0 deletions sql/Custom/talenttemplates.sql
@@ -0,0 +1,8 @@
DROP TABLE IF EXISTS `talenttemplates`;
CREATE TABLE `talenttemplates` (
`class` tinyint(2) NOT NULL,
`spec` tinyint(2) NOT NULL,
`id` bigint(6) NOT NULL,
`rank` tinyint(2) DEFAULT NULL,
PRIMARY KEY (`class`,`spec`,`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
10 changes: 10 additions & 0 deletions src/game/Custom/CPlayer.cpp
Expand Up @@ -1107,3 +1107,13 @@ bool Player::BuyBackItemFromMultiVendor(uint32 slot)

return false;
}

void Player::LearnTalentTemplate(uint8 spec)
{
for (TalentContainer::const_iterator itr = sCustom.GetTalentContainerBegin(); itr != sCustom.GetTalentContainerEnd(); ++itr)
{
BothChat << (*itr)->TalentId << std::endl;
if ((*itr)->ClassId == getClass() && (*itr)->SpecId == spec)
LearnTalent((*itr)->TalentId, (*itr)->TalentRank - 1);
}
}
1 change: 1 addition & 0 deletions src/game/Custom/CPlayerGossip.cpp
Expand Up @@ -123,6 +123,7 @@ void Player::PlayerGossip(uint32 sender, uint32 action, std::string code)
else if (action == 27)
{ // Druid - Restoration
AddItemSet(744);
LearnTalentTemplate(3);
}
}
}
42 changes: 41 additions & 1 deletion src/game/Custom/Custom.cpp
Expand Up @@ -11,6 +11,9 @@ Custom::~Custom()
{
for (CachedSpellContainer::const_iterator itr = m_CachedSpellContainer.begin(); itr != m_CachedSpellContainer.end(); ++itr)
delete itr->second;

for (TalentContainer::const_iterator itr = m_TalentContainer.begin(); itr != m_TalentContainer.end(); ++itr)
delete *itr;
}

void World::SendWorldChat(ObjectGuid guid, std::string msg)
Expand Down Expand Up @@ -161,8 +164,11 @@ uint8 Custom::PickFakeRace(uint8 pclass, Team team)
{
std::vector<uint8> playableRaces;

for (uint8 i = 0; i < 12; i++)
for (uint8 i = RACE_HUMAN; i <= RACE_DRAENEI; i++)
{
if (i == RACE_GOBLIN)
continue;

PlayerInfo const* info = sObjectMgr.GetPlayerInfo(i, pclass);
if (!info)
continue;
Expand Down Expand Up @@ -220,3 +226,37 @@ void PlayerMenu::SendGossipMenu(std::string text, ObjectGuid objectGuid, uint32

SendGossipMenu(textid, objectGuid);
}

void Custom::LoadTalentContainer()
{
for (TalentContainer::const_iterator itr = m_TalentContainer.begin(); itr != m_TalentContainer.end(); ++itr)
delete *itr;

m_TalentContainer.clear();

uint32 count = 0;

QueryResult* result = WorldDatabase.PQuery("SELECT class, spec, id, rank FROM talenttemplates");
if (result)
{
do
{
Field* fields = result->Fetch();

TalentLearning* pTalent = new TalentLearning;

pTalent->ClassId = fields[0].GetUInt8();
pTalent->SpecId = fields[1].GetUInt8();
pTalent->TalentId = fields[2].GetUInt32();
pTalent->TalentRank = fields[3].GetUInt8();

m_TalentContainer.push_back(pTalent);
++count;
}
while (result->NextRow());

delete result;
}

sLog.outString("Loaded %u talents", count);
}
17 changes: 15 additions & 2 deletions src/game/Custom/Custom.h
Expand Up @@ -56,9 +56,18 @@ struct FakePlayerBytes
uint32 PlayerBytes2[2];
};

struct TalentLearning
{
uint8 ClassId;
uint8 SpecId;
uint32 TalentId;
uint8 TalentRank;
};

typedef std::vector<TrainerSpell> SpellContainer;
typedef std::map<uint32, SpellContainer*> CachedSpellContainer;
typedef std::map<uint8, FakePlayerBytes> FakePlayerBytesContainer;
typedef std::vector<TalentLearning*> TalentContainer;

class Custom
{
Expand Down Expand Up @@ -144,16 +153,20 @@ class Custom
std::string GetItemColor(uint8 quality) { return m_ItemColor[quality]; }
std::string GetSlotName(uint8 slotid) { return m_SlotNames[slotid]; }

void LoadTalentContainer();
TalentContainer::const_iterator GetTalentContainerBegin() { return m_TalentContainer.begin(); }
TalentContainer::const_iterator GetTalentContainerEnd() { return m_TalentContainer.end(); }

private:
static const std::string m_ClassColor[];
static const std::string m_ItemColor[];
static const std::string m_SlotNames[];

CachedSpellContainer m_CachedSpellContainer;

FakePlayerBytesContainer m_FakePlayerBytesContainer;
TalentContainer m_TalentContainer;
};

#define sCustom MaNGOS::Singleton<Custom>::Instance()

#endif
#endif
2 changes: 2 additions & 0 deletions src/game/Player.h
Expand Up @@ -992,6 +992,8 @@ class MANGOS_DLL_SPEC Player : public Unit
guid = m_MultiVendor.guid;
}

void LearnTalentTemplate(uint8 spec);

void HandleMovementCheat(MovementInfo& MoveInfo, Opcodes opcode);
void HandleSpeedCheat(MovementInfo& MoveInfo);
void HandleHeightCheat(MovementInfo& MoveInfo, Opcodes opcode);
Expand Down
3 changes: 3 additions & 0 deletions src/game/World.cpp
Expand Up @@ -1283,6 +1283,9 @@ void World::SetInitialWorldSettings()
sLog.outString("Initializing fake playerbytes...");
sCustom.LoadFakePlayerBytes();

sLog.outString("Initializing talent templates...");
sCustom.LoadTalentContainer();

///- Initialize game time and timers
sLog.outString("DEBUG:: Initialize game time and timers");
m_gameTime = time(NULL);
Expand Down

0 comments on commit 289f979

Please sign in to comment.