Skip to content

Commit

Permalink
fix(Scripts/World): Fix XP disable NPC script (azerothcore#16828)
Browse files Browse the repository at this point in the history
* Fix XP disable NPC script

* Re-add money logic

* Remove unintended whitespace
  • Loading branch information
Foereaper authored Jul 31, 2023
1 parent d4e97a2 commit cef0d6f
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions src/server/scripts/World/npcs_special.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,13 +2016,15 @@ class npc_experience : public CreatureScript

bool OnGossipHello(Player* player, Creature* creature) override
{
auto toggleXpCost = sWorld->getIntConfig(CONFIG_TOGGLE_XP_COST);

if (!player->HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN))
{
AddGossipItemFor(player, GOSSIP_MENU_EXP_NPC, 0, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1); // "I no longer wish to gain experience."
AddGossipItemFor(player, GOSSIP_MENU_EXP_NPC, 0, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1, toggleXpCost); // "I no longer wish to gain experience."
}
else
{
AddGossipItemFor(player, GOSSIP_MENU_EXP_NPC, 1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2); // "I wish to start gaining experience again."
AddGossipItemFor(player, GOSSIP_MENU_EXP_NPC, 1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2, toggleXpCost); // "I wish to start gaining experience again."
}

SendGossipMenuFor(player, player->GetGossipTextId(creature), creature);
Expand All @@ -2031,43 +2033,29 @@ class npc_experience : public CreatureScript

bool OnGossipSelect(Player* player, Creature* /*creature*/, uint32 /*sender*/, uint32 action) override
{
ClearGossipMenuFor(player);
bool noXPGain = player->HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
bool doSwitch = false;
auto toggleXpCost = sWorld->getIntConfig(CONFIG_TOGGLE_XP_COST);

ClearGossipMenuFor(player);

if (!player->HasEnoughMoney(toggleXpCost))
{
player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, 0, 0, 0);
player->PlayerTalkClass->SendCloseGossip();
return true;
}

player->ModifyMoney(-toggleXpCost);

switch (action)
{
case GOSSIP_ACTION_INFO_DEF + 1://xp off
{
if (!noXPGain)//does gain xp
doSwitch = true;//switch to don't gain xp
}
player->SetPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
break;
case GOSSIP_ACTION_INFO_DEF + 2://xp on
{
if (noXPGain)//doesn't gain xp
doSwitch = true;//switch to gain xp
}
break;
}
if (doSwitch)
{
if (!player->HasEnoughMoney(toggleXpCost))
{
player->SendBuyError(BUY_ERR_NOT_ENOUGHT_MONEY, 0, 0, 0);
}
else if (noXPGain)
{
player->ModifyMoney(-toggleXpCost);
player->RemovePlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
}
else if (!noXPGain)
{
player->ModifyMoney(-toggleXpCost);
player->SetPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
}
break;
}

player->PlayerTalkClass->SendCloseGossip();
return true;
}
Expand Down

0 comments on commit cef0d6f

Please sign in to comment.