Files
mod-playerbots/src/Ai/Base/Actions/XpGainAction.cpp
bashermens 13fff46fa0 Improper singletons migration to clean Meyer's singletons (cherry-pick) (#2082)
# Pull Request

- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )

Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---

## Complexity & Impact

- Does this change add new decision branches?
    - [x] No
    - [ ] Yes (**explain below**)

- Does this change increase per-bot or per-tick processing?
    - [x] No
    - [ ] Yes (**describe and justify impact**)

- Could this logic scale poorly under load?
    - [x] No
    - [ ] Yes (**explain why**)

---

## Defaults & Configuration

- Does this change modify default bot behavior?
    - [x] No
    - [ ] Yes (**explain why**)

---

## AI Assistance

- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
    - [x] No
    - [ ] Yes (**explain below**)
---

## Final Checklist

- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed

---

## Notes for Reviewers

Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.

---------

Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
2026-01-30 21:49:37 +01:00

100 lines
2.6 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "XpGainAction.h"
#include "Event.h"
#include "GuildMgr.h"
#include "PlayerbotAIConfig.h"
#include "Playerbots.h"
#include "BroadcastHelper.h"
bool XpGainAction::Execute(Event event)
{
context->GetValue<uint32>("death count")->Set(0);
WorldPacket p(event.getPacket()); // (8+4+1+4+8)
ObjectGuid guid;
// uint32 xpgain;
// uint8 type = 0; // 00-kill_xp type, 01-non_kill_xp type
// uint32 givenXp = 0;
// float groupBonus = 0;
p.rpos(0);
p >> guid; // 8 victim
// p >> xpgain; // 1 given experience
// p >> type; // 1 00-kill_xp type, 01-non_kill_xp type
// if (!type)
// {
// p >> givenXp; // 4 experience without rested bonus
// p >> groupBonus; // 8 group bonus
// }
Creature* creature = botAI->GetCreature(guid);
if (creature && !creature->GetMap()->IsDungeon())
{
BroadcastHelper::BroadcastKill(botAI, bot, creature);
}
// randomBotXPRate is now implemented in OnPlayerGiveXP script
// if (!sRandomPlayerbotMgr.IsRandomBot(bot) || sPlayerbotAIConfig.randomBotXPRate == 1)
// return true;
// Unit* victim = nullptr;
// if (guid)
// victim = botAI->GetUnit(guid);
// xpgain = xpgain * (sPlayerbotAIConfig.randomBotXPRate - 1);
// GiveXP(xpgain, victim);
return true;
}
void XpGainAction::GiveXP(uint32 xp, Unit* victim)
{
if (xp < 1)
{
return;
}
if (!bot->IsAlive())
{
return;
}
uint32 level = bot->GetLevel();
// XP to money conversion processed in Player::RewardQuest
if (level >= sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
return;
}
// XP resting bonus for kill
uint32 rested_bonus_xp = victim ? bot->GetXPRestBonus(xp) : 0;
// SendLogXPGain(xp, victim, rested_bonus_xp);
uint32 curXP = bot->GetUInt32Value(PLAYER_XP);
uint32 nextLvlXP = bot->GetUInt32Value(PLAYER_NEXT_LEVEL_XP);
uint32 newXP = curXP + xp + rested_bonus_xp;
while (newXP >= nextLvlXP && level < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
newXP -= nextLvlXP;
if (level < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
{
bot->GiveLevel(level + 1);
}
level = bot->GetLevel();
nextLvlXP = bot->GetUInt32Value(PLAYER_NEXT_LEVEL_XP);
}
bot->SetUInt32Value(PLAYER_XP, newXP);
}