Skip to content

Commit

Permalink
remove exclusives
Browse files Browse the repository at this point in the history
  • Loading branch information
hatersgit committed Oct 18, 2023
1 parent ef12ed0 commit 6a167ff
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 40 deletions.
73 changes: 63 additions & 10 deletions modules/mod-Forge/src/ForgeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ enum CharacterPointType
LEVEL_10_TAB = 7
};

enum NodeType
{
AURA = 0,
SPELL = 1,
CHOICE = 2
};

enum ForgeSettingIndex
{
FORGE_SETTING_SPEC_SLOTS = 0
Expand Down Expand Up @@ -90,10 +97,17 @@ struct ForgeCharacterSpec
uint32 CharacterSpecTabId; // like holy ret pro
// TabId, Spellid
std::unordered_map<uint32, std::unordered_map<uint32, ForgeCharacterTalent*>> Talents;
std::unordered_map<uint32 /*node id*/, uint32/*spell picked*/> ChoiceNodesChosen;
// tabId
std::unordered_map<uint32, uint8> PointsSpent;
};

struct ForgeTalentChoice
{
uint32 spellId;
bool active;
};

struct ForgeTalent
{
uint32 SpellId;
Expand All @@ -104,10 +118,11 @@ struct ForgeTalent
uint16 TabPointReq;
uint8 RequiredLevel;
CharacterPointType TalentType;
NodeType nodeType;
uint8 NumberOfRanks;
PereqReqirementType PreReqType;
std::list<ForgeTalentPrereq*> Prereqs;
std::list<uint32> ExclusiveWith;
std::list<ForgeTalentChoice*> Choices;
std::list<uint32> UnlearnSpells;
// rank number, spellId
std::unordered_map<uint32, uint32> Ranks;
Expand Down Expand Up @@ -854,6 +869,9 @@ class ForgeCache : public DatabaseScript
// tabId
std::unordered_map<uint32, ForgeTalentTab*> TalentTabs;

// choiceNodeId is the id of the node in forge_talents
std::unordered_map<uint32 /*nodeid*/, std::vector<uint32/*choice spell id*/>> _choiceNodes;

private:
std::unordered_map<ObjectGuid, uint32> CharacterActiveSpecs;
std::unordered_map<std::string, uint32> CONFIG;
Expand Down Expand Up @@ -920,12 +938,13 @@ class ForgeCache : public DatabaseScript
AddTalentTrees();
AddTalentsToTrees();
AddTalentPrereqs();
AddTalentExclusiveness();
AddTalentChoiceNodes();
AddTalentRanks();
AddTalentUnlearn();
AddCharacterSpecs();
AddTalentSpent();
AddCharacterTalents();
AddCharacterChoiceNodes();
LOG_INFO("server.load", "Loading characters points...");
AddCharacterPointsFromDB();
AddCharacterClassSpecs();
Expand Down Expand Up @@ -1206,12 +1225,13 @@ class ForgeCache : public DatabaseScript
newTalent->NumberOfRanks = talentFields[7].Get<uint8>();
newTalent->PreReqType = (PereqReqirementType)talentFields[8].Get<uint8>();
newTalent->TabPointReq = talentFields[9].Get<uint16>();
newTalent->nodeType = NodeType(talentFields[10].Get<uint8>());

auto tabItt = TalentTabs.find(newTalent->TalentTabId);

if (tabItt == TalentTabs.end())
{
LOG_ERROR("FORGE.ForgeCache", "Error loading talents, invaild tab id: " + std::to_string(newTalent->TalentTabId));
LOG_ERROR("FORGE.ForgeCache", "Error loading talents, invalid tab id: " + std::to_string(newTalent->TalentTabId));
}
else
tabItt->second->Talents[newTalent->SpellId] = newTalent;
Expand Down Expand Up @@ -1249,28 +1269,36 @@ class ForgeCache : public DatabaseScript
} while (preReqTalents->NextRow());
}

void AddTalentExclusiveness()
void AddTalentChoiceNodes()
{
QueryResult exclTalents = WorldDatabase.Query("SELECT * FROM forge_talent_exclusive");
QueryResult exclTalents = WorldDatabase.Query("SELECT * FROM forge_talent_choice_nodes");

_choiceNodes.clear();

if (!exclTalents)
return;

do
{
Field* talentFields = exclTalents->Fetch();
uint32 spellId = talentFields[0].Get<uint32>();
uint32 choiceNodeId = talentFields[0].Get<uint32>();
uint32 talentTabId = talentFields[1].Get<uint32>();
uint32 exclusiveSpellId = talentFields[2].Get<uint32>();
uint32 spellChoice = talentFields[2].Get<uint32>();

ForgeTalent* lt = TalentTabs[talentTabId]->Talents[spellId];
ForgeTalentChoice* choice = new ForgeTalentChoice();
choice->active = false;
choice->spellId = spellChoice;

_choiceNodes[choiceNodeId].push_back(spellChoice);

ForgeTalent* lt = TalentTabs[talentTabId]->Talents[choiceNodeId];
if (lt != nullptr)
{
lt->ExclusiveWith.push_back(exclusiveSpellId);
lt->Choices.push_back(choice);
}
else
{
LOG_ERROR("FORGE.ForgeCache", "Error loading AddTalentExclusiveness, invaild exclusiveSpellId id: " + std::to_string(exclusiveSpellId));
LOG_ERROR("FORGE.ForgeCache", "Error loading AddTalentChoiceNodes, invaild choiceNodeId id: " + std::to_string(choiceNodeId));
}

} while (exclTalents->NextRow());
Expand Down Expand Up @@ -1439,6 +1467,31 @@ class ForgeCache : public DatabaseScript
} while (talentsQuery->NextRow());
}

void AddCharacterChoiceNodes() {
QueryResult choiceQuery = CharacterDatabase.Query("SELECT * FROM forge_character_node_choices");

if (!choiceQuery)
return;

do
{
Field* fields = choiceQuery->Fetch();
uint32 id = fields[0].Get<uint32>();
ObjectGuid characterGuid = ObjectGuid::Create<HighGuid::Player>(id);
uint32 specId = fields[1].Get<uint32>();
uint32 TabId = fields[2].Get<uint32>();
uint32 nodeId = fields[3].Get<uint8>();
uint32 chosenSpell = fields[4].Get<uint32>();

ForgeTalent* ft = TalentTabs[TabId]->Talents[nodeId];
if (ft->nodeType == NodeType::CHOICE) {
ForgeCharacterSpec* spec = CharacterSpecs[characterGuid][specId];
spec->ChoiceNodesChosen[nodeId] = chosenSpell;
}

} while (choiceQuery->NextRow());
}

void AddCharacterPointsFromDB()
{
QueryResult pointsQuery = CharacterDatabase.Query("SELECT * FROM forge_character_points");
Expand Down
33 changes: 14 additions & 19 deletions modules/mod-Forge/src/ForgeCommonMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ std::string ForgeCommonMessage::BuildTree(Player* player, CharacterPointType poi

j = 0;

for (auto& preReq : talentKvp.second->ExclusiveWith)
for (auto& preReq : talentKvp.second->Ranks)
{
std::string reqDel = "!";
std::string reqDel = "%";

if (j == 0)
reqDel = "";

msg = msg + reqDel + std::to_string(preReq);
msg = msg + reqDel + std::to_string(preReq.first) + "~" +
std::to_string(preReq.second);

j++;
}
Expand All @@ -110,31 +111,33 @@ std::string ForgeCommonMessage::BuildTree(Player* player, CharacterPointType poi

j = 0;

for (auto& preReq : talentKvp.second->Ranks)
for (auto& preReq : talentKvp.second->UnlearnSpells)
{
std::string reqDel = "%";
std::string reqDel = "`";

if (j == 0)
reqDel = "";

msg = msg + reqDel + std::to_string(preReq.first) + "~" +
std::to_string(preReq.second);
msg = msg + reqDel + std::to_string(preReq);

j++;
}

msg = msg + "&" + std::to_string(talentKvp.second->nodeType);

msg = msg + "&"; // delimit the field

j = 0;

for (auto& preReq : talentKvp.second->UnlearnSpells)
// TODO: SET THIS TO BE CHOICE NODE
for (auto& choice : talentKvp.second->Choices)
{
std::string reqDel = "`";
std::string choiceDel = "!";

if (j == 0)
reqDel = "";
choiceDel = "";

msg = msg + reqDel + std::to_string(preReq);
msg = msg + choiceDel + std::to_string(choice->spellId);

j++;
}
Expand Down Expand Up @@ -313,14 +316,6 @@ bool ForgeCommonMessage::CanLearnTalent(Player* player, uint32 tabId, uint32 spe
}
}

for (auto& exclu : ft->ExclusiveWith)
{
auto typeItt = skillTabs.find(exclu);

if (typeItt != skillTabs.end() && (typeItt->second->CurrentRank > 0))
return false;
}

return true;
}

Expand Down
11 changes: 0 additions & 11 deletions modules/mod-Forge/src/TopicHandlers/LearnTalentHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,6 @@ class LearnTalentHandler : public ForgeTopicHandler
}
}

for (auto& exclu : ft->ExclusiveWith)
{
auto typeItt = skillTabs.find(exclu);

if (typeItt != skillTabs.end() && typeItt->second->CurrentRank > 0)
{
RequirementsNotMet(iam);
return;
}
}

auto spellItter = skillTabs.find(ft->SpellId);
ForgeCharacterTalent* ct = new ForgeCharacterTalent();

Expand Down

0 comments on commit 6a167ff

Please sign in to comment.