mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 23:49:25 +02:00
<!--
Thank you for contributing to mod-playerbots, please make sure that
you...
1. Submit your PR to the test-staging branch, not master.
2. Read the guidelines below before submitting.
3. Don't delete parts of this template.
DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND
PREDICTABILITY over behavioral realism.
Every action and decision executes PER BOT AND PER TRIGGER. Small
increases in logic complexity scale
poorly across thousands of bots and negatively affect all. We prioritize
a stable system over a smarter
one. Bots don't need to behave perfectly; believable behavior is the
goal, not human simulation.
Default behavior must be cheap in processing; expensive behavior must be
opt-in.
Before submitting, make sure your changes aligns with these principles.
-->
## Pull Request Description
<!-- Describe what this change does and why it is needed -->
Clean up a bunch of additional unused variable warnings.
## Feature Evaluation
<!--
If your PR is very minimal (comment typo, wrong ID reference, etc), and
it is very obvious it will not have
any impact on performance, you may skip these question. If necessary, a
maintainer may ask you for them later.
-->
<!-- Please answer the following: -->
- Describe the **minimum logic** required to achieve the intended
behavior.
- Describe the **processing cost** when this logic executes across many
bots.
## How to Test the Changes
<!--
- Step-by-step instructions to test the change.
- Any required setup (e.g. multiple players, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->
## Impact Assessment
<!-- As a generic test, before and after measure of pmon (playerbot pmon
tick) can help you here. -->
- Does this change increase per-bot/per-tick processing or risk scaling
poorly with thousands of bots?
- - [x] No, not at all
- - [ ] Minimal impact (**explain below**)
- - [ ] Moderate impact (**explain below**)
- Does this change modify default bot behavior?
- - [x] No
- - [ ] Yes (**explain why**)
- Does this change add new decision branches or increase maintenance
complexity?
- - [x] No
- - [ ] Yes (**explain below**)
## Messages to Translate
<!--
Bot messages have to be translatable, but you don't need to do the
translations here. You only need to make sure
the message is in a translatable format, and list in the table the
message_key and the default English message.
Search for GetBotTextOrDefault in the codebase for examples.
-->
- Does this change add bot messages to translate?
- - [x] No
- - [ ] Yes (**list messages in the table**)
| Message key | Default message |
| --------------- | ------------------ |
| | |
| | |
## AI Assistance
<!--
AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
We expect contributors to be honest about what they do and do not
understand.
-->
- Was AI assistance used while working on this change?
- - [ ] No
- - [x] Yes (**explain below**)
<!--
If yes, please specify:
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation).
- Which parts of the change were influenced or generated, and whether it
was thoroughly reviewed.
-->
Claude reviewed the warnings log from a build and suggested a series of
changes. I focused just on these warnings for now. Every line was
reviewed. Some sections need to be reviewed by author for intent.
## 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 (Conf comments, WiKi commands).
## Notes for Reviewers
<!-- Anything else that's helpful to review or test your pull request.
-->
229 lines
6.3 KiB
C++
229 lines
6.3 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 <memory>
|
|
#include <mutex>
|
|
#include <vector>
|
|
|
|
#include "ReadyCheckAction.h"
|
|
#include "Event.h"
|
|
#include "Playerbots.h"
|
|
|
|
std::string const formatPercent(std::string const name, uint8 value, float percent)
|
|
{
|
|
std::ostringstream out;
|
|
|
|
std::string color;
|
|
if (percent > 75)
|
|
color = "|cff00ff00";
|
|
else if (percent > 50)
|
|
color = "|cffffff00";
|
|
else
|
|
color = "|cffff0000";
|
|
|
|
out << "|cffffffff[" << name << "]" << color << "x" << (int)value;
|
|
return out.str();
|
|
}
|
|
|
|
class ReadyChecker
|
|
{
|
|
public:
|
|
virtual ~ReadyChecker() = default;
|
|
virtual bool Check(PlayerbotAI* botAI, AiObjectContext* context) = 0;
|
|
virtual std::string const getName() = 0;
|
|
virtual bool PrintAlways() { return true; }
|
|
|
|
static std::vector<std::unique_ptr<ReadyChecker>> checkers;
|
|
static std::once_flag initFlag;
|
|
};
|
|
|
|
std::vector<std::unique_ptr<ReadyChecker>> ReadyChecker::checkers;
|
|
std::once_flag ReadyChecker::initFlag;
|
|
|
|
class HealthChecker : public ReadyChecker
|
|
{
|
|
public:
|
|
bool Check(PlayerbotAI* /*botAI*/, AiObjectContext* context) override
|
|
{
|
|
return AI_VALUE2(uint8, "health", "self target") > sPlayerbotAIConfig.almostFullHealth;
|
|
}
|
|
|
|
std::string const getName() override { return "HP"; }
|
|
};
|
|
|
|
class ManaChecker : public ReadyChecker
|
|
{
|
|
public:
|
|
bool Check(PlayerbotAI* /*botAI*/, AiObjectContext* context) override
|
|
{
|
|
return !AI_VALUE2(bool, "has mana", "self target") ||
|
|
AI_VALUE2(uint8, "mana", "self target") > sPlayerbotAIConfig.mediumHealth;
|
|
}
|
|
|
|
std::string const getName() override { return "MP"; }
|
|
};
|
|
|
|
class DistanceChecker : public ReadyChecker
|
|
{
|
|
public:
|
|
bool Check(PlayerbotAI* botAI, AiObjectContext* /*context*/) override
|
|
{
|
|
Player* bot = botAI->GetBot();
|
|
if (Player* master = botAI->GetMaster())
|
|
{
|
|
bool distance = bot->GetDistance(master) <= sPlayerbotAIConfig.sightDistance;
|
|
if (!distance)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool PrintAlways() override { return false; }
|
|
std::string const getName() override { return "Far away"; }
|
|
};
|
|
|
|
class HunterChecker : public ReadyChecker
|
|
{
|
|
public:
|
|
bool Check(PlayerbotAI* botAI, AiObjectContext* /*context*/) override
|
|
{
|
|
Player* bot = botAI->GetBot();
|
|
if (bot->getClass() == CLASS_HUNTER)
|
|
{
|
|
if (!bot->GetUInt32Value(PLAYER_AMMO_ID))
|
|
{
|
|
botAI->TellError("Out of ammo!");
|
|
return false;
|
|
}
|
|
|
|
if (!bot->GetPet())
|
|
{
|
|
botAI->TellError("No pet!");
|
|
return false;
|
|
}
|
|
|
|
if (bot->GetPet()->GetHappinessState() == UNHAPPY)
|
|
{
|
|
botAI->TellError("Pet is unhappy!");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool PrintAlways() override { return false; }
|
|
std::string const getName() override { return "Far away"; }
|
|
};
|
|
|
|
class ItemCountChecker : public ReadyChecker
|
|
{
|
|
public:
|
|
ItemCountChecker(std::string const item, std::string const name) : item(item), name(name) {}
|
|
|
|
bool Check(PlayerbotAI* /*botAI*/, AiObjectContext* context) override
|
|
{
|
|
return AI_VALUE2(uint32, "item count", item) > 0;
|
|
}
|
|
|
|
std::string const getName() override { return name; }
|
|
|
|
private:
|
|
std::string const item;
|
|
std::string const name;
|
|
};
|
|
|
|
class ManaPotionChecker : public ItemCountChecker
|
|
{
|
|
public:
|
|
ManaPotionChecker(std::string const item, std::string const name) : ItemCountChecker(item, name) {}
|
|
|
|
bool Check(PlayerbotAI* botAI, AiObjectContext* context) override
|
|
{
|
|
return !AI_VALUE2(bool, "has mana", "self target") || ItemCountChecker::Check(botAI, context);
|
|
}
|
|
};
|
|
|
|
bool ReadyCheckAction::Execute(Event event)
|
|
{
|
|
WorldPacket& p = event.getPacket();
|
|
ObjectGuid player;
|
|
p.rpos(0);
|
|
if (!p.empty())
|
|
{
|
|
p >> player;
|
|
if (player == bot->GetGUID())
|
|
return false;
|
|
}
|
|
|
|
return ReadyCheck();
|
|
}
|
|
|
|
bool ReadyCheckAction::ReadyCheck()
|
|
{
|
|
std::call_once(
|
|
ReadyChecker::initFlag,
|
|
[]()
|
|
{
|
|
ReadyChecker::checkers.reserve(8);
|
|
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<HealthChecker>());
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<ManaChecker>());
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<DistanceChecker>());
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<HunterChecker>());
|
|
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<ItemCountChecker>("food", "Food"));
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<ManaPotionChecker>("drink", "Water"));
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<ItemCountChecker>("healing potion", "Hpot"));
|
|
ReadyChecker::checkers.emplace_back(std::make_unique<ManaPotionChecker>("mana potion", "Mpot"));
|
|
});
|
|
|
|
bool result = true;
|
|
for (auto const& checkerPtr : ReadyChecker::checkers)
|
|
{
|
|
if (!checkerPtr)
|
|
continue;
|
|
|
|
bool ok = checkerPtr->Check(botAI, context);
|
|
result = result && ok;
|
|
}
|
|
|
|
std::ostringstream out;
|
|
|
|
uint32 hp = AI_VALUE2(uint32, "item count", "healing potion");
|
|
out << formatPercent("Hp", hp, 100.0 * hp / 5);
|
|
|
|
out << ", ";
|
|
uint32 food = AI_VALUE2(uint32, "item count", "food");
|
|
out << formatPercent("Food", food, 100.0 * food / 20);
|
|
|
|
if (AI_VALUE2(bool, "has mana", "self target"))
|
|
{
|
|
out << ", ";
|
|
uint32 mp = AI_VALUE2(uint32, "item count", "mana potion");
|
|
out << formatPercent("Mp", mp, 100.0 * mp / 5);
|
|
|
|
out << ", ";
|
|
uint32 water = AI_VALUE2(uint32, "item count", "water");
|
|
out << formatPercent("Water", water, 100.0 * water / 20);
|
|
}
|
|
|
|
botAI->TellMaster(out);
|
|
|
|
WorldPacket packet(MSG_RAID_READY_CHECK);
|
|
packet << bot->GetGUID();
|
|
packet << uint8(1);
|
|
bot->GetSession()->HandleRaidReadyCheckOpcode(packet);
|
|
|
|
botAI->ChangeStrategy("-ready check", BOT_STATE_NON_COMBAT);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool FinishReadyCheckAction::Execute(Event /*event*/) { return ReadyCheck(); }
|