Skip to content

Commit

Permalink
Added player settings to gossip npc.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnchyDev committed Oct 6, 2023
1 parent 96f0336 commit 80fa444
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 11 deletions.
12 changes: 12 additions & 0 deletions data/sql/db-characters/base/base.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE IF NOT EXISTS `attriboost_attributes` (
`guid` int unsigned NOT NULL,
`unallocated` int DEFAULT NULL,
`stamina` int unsigned DEFAULT NULL,
`strength` int unsigned DEFAULT NULL,
`agility` int unsigned DEFAULT NULL,
`intellect` int unsigned DEFAULT NULL,
`spirit` int unsigned DEFAULT NULL,
`settings` int DEFAULT NULL,
`comment` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
PRIMARY KEY (`guid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
113 changes: 103 additions & 10 deletions src/Attriboost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,17 @@ Attriboosts* GetAttriboosts(uint64 guid)
if (attri == attriboostsMap.end())
{
Attriboosts attriboosts;

attriboosts.Unallocated = 0;

attriboosts.Stamina = 0;
attriboosts.Strength = 0;
attriboosts.Agility = 0;
attriboosts.Intellect = 0;
attriboosts.Spirit = 0;

attriboosts.Settings = ATTR_SETTING_PROMPT;

auto result = attriboostsMap.emplace(guid, attriboosts);
attri = result.first;
}
Expand Down Expand Up @@ -169,13 +173,17 @@ void LoadAttriboosts()
uint64 guid = fields[0].Get<uint64>();

Attriboosts attriboosts;

attriboosts.Unallocated = fields[1].Get<uint32>();

attriboosts.Stamina = fields[2].Get<uint32>();
attriboosts.Strength = fields[3].Get<uint32>();
attriboosts.Agility = fields[4].Get<uint32>();
attriboosts.Intellect = fields[5].Get<uint32>();
attriboosts.Spirit = fields[6].Get<uint32>();

attriboosts.Settings = fields[7].Get<uint32>();

attriboostsMap.emplace(guid, attriboosts);

count++;
Expand All @@ -191,16 +199,19 @@ void SaveAttriboosts()
auto guid = it->first;

auto unallocated = it->second.Unallocated;

auto stamina = it->second.Stamina;
auto strength = it->second.Strength;
auto agility = it->second.Agility;
auto intellect = it->second.Intellect;
auto spirit = it->second.Spirit;

CharacterDatabase.Execute("INSERT INTO `attriboost_attributes` (guid, unallocated, stamina, strength, agility, intellect, spirit) VALUES ({}, {}, {}, {}, {}, {}, {}) ON DUPLICATE KEY UPDATE unallocated={}, stamina={}, strength={}, agility={}, intellect={}, spirit={}",
auto settings = it->second.Settings;

CharacterDatabase.Execute("INSERT INTO `attriboost_attributes` (guid, unallocated, stamina, strength, agility, intellect, spirit, settings) VALUES ({}, {}, {}, {}, {}, {}, {}, {}) ON DUPLICATE KEY UPDATE unallocated={}, stamina={}, strength={}, agility={}, intellect={}, spirit={}, settings={}",
guid,
unallocated, stamina, strength, agility, intellect, spirit,
unallocated, stamina, strength, agility, intellect, spirit);
unallocated, stamina, strength, agility, intellect, spirit, settings,
unallocated, stamina, strength, agility, intellect, spirit, settings);
}
}

Expand Down Expand Up @@ -373,6 +384,44 @@ uint32 GetAttributesToSpend(Player* player)
return attributes->Unallocated;
}

bool HasSetting(Player* player, uint32 setting)
{
if (!player)
{
return false;
}

auto attributes = GetAttriboosts(player->GetGUID().GetRawValue());
if (!attributes)
{
return false;
}

return (attributes->Settings & setting) == setting;
}
void ToggleSetting(Player* player, uint32 setting)
{
if (!player)
{
return;
}

auto attributes = GetAttriboosts(player->GetGUID().GetRawValue());
if (!attributes)
{
return;
}

if (HasSetting(player, setting))
{
attributes->Settings -= setting;
}
else
{
attributes->Settings += setting;
}
}

void AttriboostWorldScript::OnAfterConfigLoad(bool reload)
{
if (reload)
Expand All @@ -392,19 +441,33 @@ bool AttriboostCreatureScript::OnGossipHello(Player* player, Creature* creature)

if (HasAttributesToSpend(player))
{
AddGossipItemFor(player, GOSSIP_ICON_DOT, Acore::StringFormatFmt("|cff00FF00{} |rAttributes to spend.", GetAttributesToSpend(player)), GOSSIP_SENDER_MAIN, 0);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Stamina", GOSSIP_SENDER_MAIN, ATTR_SPELL_STAMINA);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Strength", GOSSIP_SENDER_MAIN, ATTR_SPELL_STRENGTH);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Agility", GOSSIP_SENDER_MAIN, ATTR_SPELL_AGILITY);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Intellect", GOSSIP_SENDER_MAIN, ATTR_SPELL_INTELLECT);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Spirit", GOSSIP_SENDER_MAIN, ATTR_SPELL_SPIRIT);
AddGossipItemFor(player, GOSSIP_ICON_DOT, Acore::StringFormatFmt("|TInterface\\GossipFrame\\TrainerGossipIcon:16|t |cffFF0000{} |rAttributes to spend.", GetAttributesToSpend(player)), GOSSIP_SENDER_MAIN, 0);

if (HasSetting(player, ATTR_SETTING_PROMPT))
{
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Stamina", GOSSIP_SENDER_MAIN, ATTR_SPELL_STAMINA, "Are you sure you want to spend your points in stamina?", 0, false);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Strength", GOSSIP_SENDER_MAIN, ATTR_SPELL_STRENGTH, "Are you sure you want to spend your points in strength?", 0, false);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Agility", GOSSIP_SENDER_MAIN, ATTR_SPELL_AGILITY, "Are you sure you want to spend your points in agility?", 0, false);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Intellect", GOSSIP_SENDER_MAIN, ATTR_SPELL_INTELLECT, "Are you sure you want to spend your points in intellect?", 0, false);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Spirit", GOSSIP_SENDER_MAIN, ATTR_SPELL_SPIRIT, "Are you sure you want to spend your points in spirit?", 0, false);
}
else
{
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Stamina", GOSSIP_SENDER_MAIN, ATTR_SPELL_STAMINA);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Strength", GOSSIP_SENDER_MAIN, ATTR_SPELL_STRENGTH);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Agility", GOSSIP_SENDER_MAIN, ATTR_SPELL_AGILITY);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Intellect", GOSSIP_SENDER_MAIN, ATTR_SPELL_INTELLECT);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\MINIMAP\\UI-Minimap-ZoomInButton-Up:16|t Spirit", GOSSIP_SENDER_MAIN, ATTR_SPELL_SPIRIT);
}
}

if (HasAttributes(player))
{
AddGossipItemFor(player, GOSSIP_ICON_DOT, "Reset Attributes|n|TInterface\\Icons\\INV_Misc_Coin_01:16|t 250", GOSSIP_SENDER_MAIN, 1000, "Are you sure you want to reset your attributes?", 2500000, false);
AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\GossipFrame\\UnlearnGossipIcon:16|t Reset Attributes", GOSSIP_SENDER_MAIN, 1000, "Are you sure you want to reset your attributes?", 2500000, false);
}

AddGossipItemFor(player, GOSSIP_ICON_DOT, "|TInterface\\GossipFrame\\HealerGossipIcon:16|t Settings", GOSSIP_SENDER_MAIN, 2000);

if (HasAttributesToSpend(player))
{
SendGossipMenuFor(player, 441191, creature);
Expand Down Expand Up @@ -436,9 +499,39 @@ bool AttriboostCreatureScript::OnGossipSelect(Player* player, Creature* creature
OnGossipHello(player, creature);
}

if (action >= 2000 && action < 3000)
{
HandleSettings(player, creature, action);
}

return true;
}

void AttriboostCreatureScript::HandleSettings(Player* player, Creature* creature, uint32 action)
{
if (action == 2000)
{
ClearGossipMenuFor(player);

player->PrepareQuestMenu(creature->GetGUID());

auto hasPromptSetting = HasSetting(player, ATTR_SETTING_PROMPT);
AddGossipItemFor(player, GOSSIP_ICON_DOT, Acore::StringFormatFmt("|TInterface\\GossipFrame\\HealerGossipIcon:16|t Prompt 'Are you sure': {}", hasPromptSetting ? "|cff00FF00Enabled|r" : "|cffFF0000Disabled"), GOSSIP_SENDER_MAIN, 2001);

AddGossipItemFor(player, GOSSIP_ICON_DOT, "Back", GOSSIP_SENDER_MAIN, 0);

SendGossipMenuFor(player, 441190, creature);

return;
}

if (action == 2001)
{
ToggleSetting(player, ATTR_SETTING_PROMPT);
HandleSettings(player, creature, 2000);
}
}

void AttriboostCreatureScript::HandleAttributeAllocation(Player* player, uint32 attribute, bool reset)
{
if (!player)
Expand Down
10 changes: 9 additions & 1 deletion src/Attriboost.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ enum AttriboostConstants
{
ATTR_ITEM = 16073,
ATTR_SPELL = 18282,
ATTR_QUEST = 441153
ATTR_QUEST = 441153,

ATTR_SETTING_PROMPT = 1
};

enum AttriboostStats
Expand All @@ -25,11 +27,14 @@ enum AttriboostStats
struct Attriboosts
{
uint32 Unallocated;

uint32 Stamina;
uint32 Strength;
uint32 Agility;
uint32 Intellect;
uint32 Spirit;

uint32 Settings;
};

std::unordered_map<uint64, Attriboosts> attriboostsMap;
Expand All @@ -43,6 +48,8 @@ void ResetAttributes(Attriboosts* /*attributes*/);
bool HasAttributesToSpend(Player* /*player*/);
bool HasAttributes(Player* /*player*/);
uint32 GetAttributesToSpend(Player* /*player*/);
bool HasSetting(Player* player, uint32 /*setting*/);
void ToggleSetting(Player* player, uint32 /*setting*/);

class AttriboostPlayerScript : public PlayerScript
{
Expand All @@ -64,6 +71,7 @@ class AttriboostCreatureScript : public CreatureScript
virtual bool OnGossipHello(Player* /*player*/, Creature* /*creature*/) override;
virtual bool OnGossipSelect(Player* /*player*/, Creature* /*creature*/, uint32 /*sender*/, uint32 /*action*/) override;

void HandleSettings(Player* /*player*/, Creature* /*creature*/, uint32 /*action*/);
void HandleAttributeAllocation(Player* /*player*/, uint32 /*attribute*/, bool /*reset*/);
};

Expand Down

0 comments on commit 80fa444

Please sign in to comment.