grind, teleport, move random for rndbot

This commit is contained in:
Yunfan Li
2023-07-31 12:49:27 +08:00
parent 366867d773
commit 0cd1fa4db3
12 changed files with 145 additions and 99 deletions

View File

@@ -110,6 +110,7 @@ class StrategyContext : public NamedObjectContext<Strategy>
creators["guild"] = &StrategyContext::guild;
creators["grind"] = &StrategyContext::grind;
creators["avoid aoe"] = &StrategyContext::avoid_aoe;
creators["move random"] = &StrategyContext::move_random;
}
private:
@@ -169,6 +170,7 @@ class StrategyContext : public NamedObjectContext<Strategy>
static Strategy* guild (PlayerbotAI* botAI) { return new GuildStrategy(botAI); }
static Strategy* grind(PlayerbotAI* botAI) { return new GrindingStrategy(botAI); }
static Strategy* avoid_aoe(PlayerbotAI* botAI) { return new AvoidAoeStrategy(botAI); }
static Strategy* move_random(PlayerbotAI* ai) { return new MoveRandomStrategy(ai); }
};
class MovementStrategyContext : public NamedObjectContext<Strategy>

View File

@@ -1399,7 +1399,7 @@ bool MoveRandomAction::Execute(Event event)
bool MoveRandomAction::isUseful()
{
return !botAI->HasRealPlayerMaster() && botAI->GetAiObjectContext()->GetValue<GuidVector>("nearest friendly players")->Get().size() > urand(25, 100);
return !botAI->HasRealPlayerMaster();
}
bool MoveInsideAction::Execute(Event event)

View File

@@ -15,3 +15,9 @@ void GrindingStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)
triggers.push_back(new TriggerNode("no target", NextAction::array(0, new NextAction("attack anything", 5.0f), nullptr)));
}
void MoveRandomStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)
{
triggers.push_back(new TriggerNode(
"often",
NextAction::array(0, new NextAction("move random", 1.5f), NULL)));
}

View File

@@ -20,4 +20,11 @@ class GrindingStrategy : public NonCombatStrategy
void InitTriggers(std::vector<TriggerNode*>& triggers) override;
};
class MoveRandomStrategy : public NonCombatStrategy
{
public:
MoveRandomStrategy(PlayerbotAI* ai) : NonCombatStrategy(botAI) {}
std::string const getName() override { return "move random"; }
void InitTriggers(std::vector<TriggerNode*>& triggers) override;
};
#endif

View File

@@ -7,6 +7,7 @@
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Playerbots.h"
#include "ReputationMgr.h"
#include "ServerFacade.h"
GuidVector AttackersValue::Calculate()
@@ -126,7 +127,7 @@ bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float range)
rti = bot->GetGroup()->GetTargetIcon(7) == attacker->GetGUID();
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
bool leaderHasThreat = false;
if (attacker && bot->GetGroup() && botAI->GetMaster())
leaderHasThreat = attacker->GetThreatMgr().GetThreat(botAI->GetMaster());
@@ -141,6 +142,7 @@ bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float range)
// bool inCannon = botAI->IsInVehicle(false, true);
// bool enemy = botAI->GetAiObjectContext()->GetValue<Unit*>("enemy player target")->Get();
return attacker &&
attacker->IsInWorld() &&
attacker->GetMapId() == bot->GetMapId() &&
@@ -155,7 +157,8 @@ bool AttackersValue::IsPossibleTarget(Unit* attacker, Player* bot, float range)
!(attacker->GetCreatureType() == CREATURE_TYPE_CRITTER && !attacker->IsInCombat()) &&
!attacker->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_PC) &&
!attacker->HasUnitFlag(UNIT_FLAG_NOT_SELECTABLE) &&
!(sPlayerbotAIConfig->IsInPvpProhibitedZone(attacker->GetAreaId()) && bot->CanSeeOrDetect(attacker) && (attacker->GetGUID().IsPlayer() || attacker->GetGUID().IsPet())) &&
bot->CanSeeOrDetect(attacker) &&
!(sPlayerbotAIConfig->IsInPvpProhibitedZone(attacker->GetZoneId()) && (attacker->GetGUID().IsPlayer() || attacker->GetGUID().IsPet())) &&
(!c || (!c->IsInEvadeMode() && ((!isMemberBotGroup && botAI->HasStrategy("attack tagged", BOT_STATE_NON_COMBAT)) ||
leaderHasThreat || (!c->hasLootRecipient() && (!c->GetVictim() || (c->GetVictim() && ((!c->GetVictim()->IsPlayer() || bot->IsInSameGroupWith(c->GetVictim()->ToPlayer())) ||
(botAI->GetMaster() && c->GetVictim() == botAI->GetMaster()))))) || c->isTappedBy(bot))));

View File

@@ -4,6 +4,8 @@
#include "GrindTargetValue.h"
#include "Playerbots.h"
#include "ReputationMgr.h"
#include "SharedDefines.h"
Unit* GrindTargetValue::Calculate()
{
@@ -54,14 +56,19 @@ Unit* GrindTargetValue::FindTargetForGrinding(uint32 assistCount)
if (!unit)
continue;
// if (unit->HasUnitFlag(UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_NOT_SELECTABLE)) {
// continue;
// }
auto &rep = bot->ToPlayer()->GetReputationMgr();
if (unit->ToCreature() && !unit->ToCreature()->GetCreatureTemplate()->lootid && bot->GetReactionTo(unit) >= REP_NEUTRAL) {
continue;
}
if (!bot->IsHostileTo(unit) && unit->GetNpcFlags() != UNIT_NPC_FLAG_NONE) {
continue;
}
if (!bot->isHonorOrXPTarget(unit)) {
continue;
}
if (abs(bot->GetPositionZ() - unit->GetPositionZ()) > sPlayerbotAIConfig->spellDistance)
continue;