Skip to content

Commit

Permalink
NPCBots: Implement Blizzlike money sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
trickerer committed Nov 26, 2024
1 parent 46854ca commit df76640
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12091,7 +12091,28 @@ void bot_ai::_autoLootCreatureGold(Creature* creature) const
players.push_back(p);
}

uint32 goldPerPlayer = uint32(loot->gold / uint32(players.size()));
uint32 bots_count = 0;
if (BotMgr::GetNpcBotMoneyShareEnabled())
{
for (GroupReference const* itr = gr->GetFirstMember(); itr != nullptr; itr = itr->next())
{
Player const* member = itr->GetSource();
if (!member || !member->IsInMap(creature) || !member->HaveBot())
continue;

BotMap const* botMap = member->GetBotMgr()->GetBotMap();
for (auto const& kv : *botMap)
{
Creature const* bot = kv.second;
if (bot && bot->IsAlive() && bot->IsInMap(creature) && (gr->IsMember(kv.first) || !BotMgr::GetNpcBotMoneyShareGroupOnly()) &&
(member->GetMap()->IsDungeon() || creature->GetDistance(bot) <= sWorld->getFloatConfig(CONFIG_GROUP_XP_DISTANCE)))
++bots_count;
}
}
}

uint32 sharers_count = uint32(players.size()) + bots_count;
uint32 goldPerPlayer = uint32(loot->gold / sharers_count);

for (std::vector<Player*>::const_iterator i = players.begin(); i != players.end(); ++i)
{
Expand All @@ -12100,7 +12121,7 @@ void bot_ai::_autoLootCreatureGold(Creature* creature) const

WorldPacket data(SMSG_LOOT_MONEY_NOTIFY, 4 + 1);
data << uint32(goldPerPlayer);
data << uint8(players.size() <= 1); // Controls the text displayed in chat. 0 is "Your share is..." and 1 is "You loot..."
data << uint8(sharers_count <= 1); // Controls the text displayed in chat. 0 is "Your share is..." and 1 is "You loot..."
(*i)->SendDirectMessage(&data);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/server/game/AI/NpcBots/botmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ bool _enableNpcBots;
bool _logToDB;
bool _xpReductionBlizzlikeEnable;
bool _xpReductionBlizzlikeGroupOnly;
bool _moneyLootShareEnable;
bool _moneyLootShareGroupOnly;
bool _enableNpcBotsDungeons;
bool _enableNpcBotsRaids;
bool _enableNpcBotsBGs;
Expand Down Expand Up @@ -335,6 +337,8 @@ void BotMgr::LoadConfig(bool reload)
_xpReductionStartingNumber = sConfigMgr->GetIntDefault("NpcBot.XpReduction.StartingNumber", 2);
_xpReductionBlizzlikeEnable = sConfigMgr->GetBoolDefault("NpcBot.XpReduction.Blizzlike.Enable", true);
_xpReductionBlizzlikeGroupOnly = sConfigMgr->GetBoolDefault("NpcBot.XpReduction.Blizzlike.GroupOnly", false);
_moneyLootShareEnable = sConfigMgr->GetBoolDefault("NpcBot.MoneyShare.Enable", false);
_moneyLootShareGroupOnly = sConfigMgr->GetBoolDefault("NpcBot.MoneyShare.GroupOnly", false);
_mountLevel60 = sConfigMgr->GetIntDefault("NpcBot.MountLevel.60", 20);
_mountLevel100 = sConfigMgr->GetIntDefault("NpcBot.MountLevel.100", 40);
_healTargetIconFlags = sConfigMgr->GetIntDefault("NpcBot.HealTargetIconMask", 0);
Expand Down Expand Up @@ -1117,6 +1121,15 @@ bool BotMgr::GetNpcBotXpReductionBlizzlikeGroupOnly()
return _xpReductionBlizzlikeGroupOnly;
}

bool BotMgr::GetNpcBotMoneyShareEnabled()
{
return _moneyLootShareEnable;
}
bool BotMgr::GetNpcBotMoneyShareGroupOnly()
{
return _moneyLootShareGroupOnly;
}

uint8 BotMgr::GetNpcBotMountLevel60()
{
return _mountLevel60;
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/NpcBots/botmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class TC_GAME_API BotMgr
static uint8 GetNpcBotXpReductionStartingNumber();
static bool GetNpcBotXpReductionBlizzlikeEnabled();
static bool GetNpcBotXpReductionBlizzlikeGroupOnly();
static bool GetNpcBotMoneyShareEnabled();
static bool GetNpcBotMoneyShareGroupOnly();
static uint8 GetNpcBotMountLevel60();
static uint8 GetNpcBotMountLevel100();
static int32 GetBotInfoPacketsLimit();
Expand Down
48 changes: 48 additions & 0 deletions src/server/game/Handlers/LootHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "Player.h"
#include "WorldPacket.h"

//npcbot
#include "botmgr.h"
//end npcbot

void WorldSession::HandleAutostoreLootItemOpcode(WorldPacket& recvData)
{
TC_LOG_DEBUG("network", "WORLD: CMSG_AUTOSTORE_LOOT_ITEM");
Expand Down Expand Up @@ -165,6 +169,50 @@ void WorldSession::HandleLootMoneyOpcode(WorldPacket& /*recvData*/)
if (loot)
{
loot->NotifyMoneyRemoved();
//npcbot
if (shareMoney && player->GetGroup() && BotMgr::GetNpcBotMoneyShareEnabled())
{
Group* group = player->GetGroup();
std::vector<Player*> playersNear;
uint32 bots_count = 0;
for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
{
Player* member = itr->GetSource();
if (!member)
continue;

if (player->IsAtGroupRewardDistance(member))
playersNear.push_back(member);

if (!member->HaveBot())
continue;

BotMap const* botMap = member->GetBotMgr()->GetBotMap();
for (auto const& kv : *botMap)
{
Creature const* bot = kv.second;
if (bot && bot->IsAlive() && bot->IsInMap(player) && (group->IsMember(kv.first) || !BotMgr::GetNpcBotMoneyShareGroupOnly()) &&
(member->GetMap()->IsDungeon() || player->GetDistance(bot) <= sWorld->getFloatConfig(CONFIG_GROUP_XP_DISTANCE)))
++bots_count;
}
}

uint32 sharers_count = uint32(playersNear.size()) + bots_count;
uint32 goldPerPlayer = uint32(loot->gold / sharers_count);

for (std::vector<Player*>::const_iterator i = playersNear.begin(); i != playersNear.end(); ++i)
{
(*i)->ModifyMoney(goldPerPlayer);
(*i)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY, goldPerPlayer);

WorldPacket data(SMSG_LOOT_MONEY_NOTIFY, 4 + 1);
data << uint32(goldPerPlayer);
data << uint8(sharers_count <= 1); // Controls the text displayed in chat. 0 is "Your share is..." and 1 is "You loot..."
(*i)->SendDirectMessage(&data);
}
}
else
//end npcbot
if (shareMoney && player->GetGroup()) //item, pickpocket and players can be looted only single player
{
Group* group = player->GetGroup();
Expand Down
11 changes: 11 additions & 0 deletions src/server/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4231,6 +4231,17 @@ NpcBot.XpReduction.StartingNumber = 2
NpcBot.XpReduction.Blizzlike.Enable = 1
NpcBot.XpReduction.Blizzlike.GroupOnly = 0

#
# NpcBot.MoneyShare.Enable
# NpcBot.MoneyShare.GroupOnly
# Description: Share money loot with bots, effectively reducing money amount players receive.
# Example: Group of 5, 3 bots, looting 100 copper, players receive 20 copper each.
# Default: 0 - (NpcBot.MoneyShare.Enable)
# 0 - (NpcBot.MoneyShare.GroupOnly)

NpcBot.MoneyShare.Enable = 0
NpcBot.MoneyShare.GroupOnly = 0

#
# NpcBot.MountLevel.60
# NpcBot.MountLevel.100
Expand Down

0 comments on commit df76640

Please sign in to comment.