Skip to content

Commit

Permalink
Merge pull request liyunfan1223#245 from liyunfan1223/attack_target
Browse files Browse the repository at this point in the history
Attack target
  • Loading branch information
liyunfan1223 authored Jun 6, 2024
2 parents 5d7a1aa + 7d1e17f commit e16e659
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 78 deletions.
4 changes: 4 additions & 0 deletions src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3090,6 +3090,10 @@ bool PlayerbotAI::IsInterruptableSpellCasting(Unit* target, std::string const sp

bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
{
if (!target->IsInWorld())
{
return false;
}
bool isFriend = bot->IsFriendlyTo(target);
for (uint32 type = SPELL_AURA_NONE; type < TOTAL_AURAS; ++type)
{
Expand Down
42 changes: 21 additions & 21 deletions src/PlayerbotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ void PlayerbotFactory::Randomize(bool incremental)
// {
// return;
// }

LOG_INFO("playerbots", "Preparing to {} randomize...", (incremental ? "incremental" : "full"));
LOG_INFO("playerbots", "{} randomizing {} (level {} class = {})...", (incremental ? "Incremental" : "Full"), bot->GetName().c_str(), bot->GetLevel(), bot->getClass());
// LOG_DEBUG("playerbots", "Preparing to {} randomize...", (incremental ? "incremental" : "full"));
Prepare();
LOG_INFO("playerbots", "Resetting player...");
LOG_DEBUG("playerbots", "Resetting player...");
PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Reset");
bot->resetTalents(true);
// bot->SaveToDB(false, false);
Expand Down Expand Up @@ -221,14 +221,14 @@ void PlayerbotFactory::Randomize(bool incremental)
}

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1");
LOG_INFO("playerbots", "Initializing spells (step 1)...");
LOG_DEBUG("playerbots", "Initializing spells (step 1)...");
// bot->LearnDefaultSkills();
InitClassSpells();
InitAvailableSpells();
if (pmo)
pmo->finish();

LOG_INFO("playerbots", "Initializing skills (step 1)...");
LOG_DEBUG("playerbots", "Initializing skills (step 1)...");
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills1");
InitSkills();
InitSpecialSpells();
Expand All @@ -238,7 +238,7 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Talents");
LOG_INFO("playerbots", "Initializing talents...");
LOG_DEBUG("playerbots", "Initializing talents...");
if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) {
InitTalentsTree();
}
Expand All @@ -252,13 +252,13 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells2");
LOG_INFO("playerbots", "Initializing spells (step 2)...");
LOG_DEBUG("playerbots", "Initializing spells (step 2)...");
InitAvailableSpells();
if (pmo)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Mounts");
LOG_INFO("playerbots", "Initializing mounts...");
LOG_DEBUG("playerbots", "Initializing mounts...");
InitMounts();
bot->SaveToDB(false, false);
if (pmo)
Expand All @@ -271,7 +271,7 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Equip");
LOG_INFO("playerbots", "Initializing equipmemt...");
LOG_DEBUG("playerbots", "Initializing equipmemt...");
if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) {
InitEquipment(incremental);
}
Expand All @@ -289,38 +289,38 @@ void PlayerbotFactory::Randomize(bool incremental)
// }

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Bags");
LOG_INFO("playerbots", "Initializing bags...");
LOG_DEBUG("playerbots", "Initializing bags...");
InitBags();
// bot->SaveToDB(false, false);
if (pmo)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Ammo");
LOG_INFO("playerbots", "Initializing ammo...");
LOG_DEBUG("playerbots", "Initializing ammo...");
InitAmmo();
if (pmo)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Food");
LOG_INFO("playerbots", "Initializing food...");
LOG_DEBUG("playerbots", "Initializing food...");
InitFood();
if (pmo)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Potions");
LOG_INFO("playerbots", "Initializing potions...");
LOG_DEBUG("playerbots", "Initializing potions...");
InitPotions();
if (pmo)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Reagents");
LOG_INFO("playerbots", "Initializing reagents...");
LOG_DEBUG("playerbots", "Initializing reagents...");
InitReagents();
if (pmo)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_EqSets");
LOG_INFO("playerbots", "Initializing second equipment set...");
LOG_DEBUG("playerbots", "Initializing second equipment set...");
// InitSecondEquipmentSet();
if (pmo)
pmo->finish();
Expand All @@ -337,18 +337,18 @@ void PlayerbotFactory::Randomize(bool incremental)
// }

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Inventory");
LOG_INFO("playerbots", "Initializing inventory...");
LOG_DEBUG("playerbots", "Initializing inventory...");
// InitInventory();
if (pmo)
pmo->finish();

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Consumable");
LOG_INFO("playerbots", "Initializing consumables...");
LOG_DEBUG("playerbots", "Initializing consumables...");
AddConsumables();
if (pmo)
pmo->finish();

LOG_INFO("playerbots", "Initializing glyphs...");
LOG_DEBUG("playerbots", "Initializing glyphs...");
bot->SaveToDB(false, false);
InitGlyphs();

Expand Down Expand Up @@ -385,12 +385,12 @@ void PlayerbotFactory::Randomize(bool incremental)
}

pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Save");
LOG_INFO("playerbots", "Saving to DB...");
LOG_DEBUG("playerbots", "Saving to DB...");
bot->SetMoney(urand(level * 100000, level * 5 * 100000));
bot->SetHealth(bot->GetMaxHealth());
bot->SetPower(POWER_MANA, bot->GetMaxPower(POWER_MANA));
bot->SaveToDB(false, false);
LOG_INFO("playerbots", "Done.");
LOG_INFO("playerbots", "Initialization Done.");
if (pmo)
pmo->finish();
}
Expand Down Expand Up @@ -587,7 +587,7 @@ void PlayerbotFactory::InitPetTalents()
// LOG_INFO("playerbots", "{} init pet talents failed with petTalentType < 0({})", bot->GetName().c_str(), pet_family->petTalentType);
return;
}
pet->resetTalents();
// pet->resetTalents();
std::unordered_map<uint32, std::vector<TalentEntry const*> > spells;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
Expand Down
12 changes: 6 additions & 6 deletions src/RandomPlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,8 +1196,8 @@ void RandomPlayerbotMgr::RandomTeleport(Player* bot, std::vector<WorldLocation>&

z = 0.05f + ground;

LOG_INFO("playerbots", "Random teleporting bot {} to {} {},{},{} ({}/{} locations)",
bot->GetName().c_str(), zone->area_name[0], x, y, z, attemtps, tlocs.size());
LOG_INFO("playerbots", "Random teleporting bot {} (level {}) to {} {},{},{} ({}/{} locations)",
bot->GetName().c_str(), bot->GetLevel(), zone->area_name[0], x, y, z, attemtps, tlocs.size());

if (hearth)
{
Expand Down Expand Up @@ -1387,7 +1387,7 @@ void RandomPlayerbotMgr::RandomTeleportForLevel(Player* bot)

uint32 level = bot->getLevel();
uint8 race = bot->getRace();
LOG_INFO("playerbots", "Random teleporting bot {} for level {} ({} locations available)", bot->GetName().c_str(), bot->GetLevel(), locsPerLevelCache[level].size());
LOG_DEBUG("playerbots", "Random teleporting bot {} for level {} ({} locations available)", bot->GetName().c_str(), bot->GetLevel(), locsPerLevelCache[level].size());
if (urand(0, 100) < sPlayerbotAIConfig->probTeleToBankers * 100) {
RandomTeleport(bot, bankerLocsPerLevelCache[level], true);
} else {
Expand All @@ -1402,7 +1402,7 @@ void RandomPlayerbotMgr::RandomTeleportGrindForLevel(Player* bot)

uint32 level = bot->getLevel();
uint8 race = bot->getRace();
LOG_INFO("playerbots", "Random teleporting bot {} for level {} ({} locations available)", bot->GetName().c_str(), bot->GetLevel(), locsPerLevelCache[level].size());
LOG_DEBUG("playerbots", "Random teleporting bot {} for level {} ({} locations available)", bot->GetName().c_str(), bot->GetLevel(), locsPerLevelCache[level].size());

RandomTeleport(bot, locsPerLevelCache[level]);
}
Expand Down Expand Up @@ -1642,7 +1642,7 @@ void RandomPlayerbotMgr::Refresh(Player* bot)
if (bot->InBattleground())
return;

LOG_INFO("playerbots", "Refreshing bot {} <{}>", bot->GetGUID().ToString().c_str(), bot->GetName().c_str());
LOG_DEBUG("playerbots", "Refreshing bot {} <{}>", bot->GetGUID().ToString().c_str(), bot->GetName().c_str());

PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "Refresh");

Expand Down Expand Up @@ -2482,7 +2482,7 @@ void RandomPlayerbotMgr::RandomTeleportForRpg(Player* bot)
{
uint32 race = bot->getRace();
uint32 level = bot->GetLevel();
LOG_INFO("playerbots", "Random teleporting bot {} for RPG ({} locations available)", bot->GetName().c_str(), rpgLocsCacheLevel[race].size());
LOG_DEBUG("playerbots", "Random teleporting bot {} for RPG ({} locations available)", bot->GetName().c_str(), rpgLocsCacheLevel[race].size());
RandomTeleport(bot, rpgLocsCacheLevel[race][level], true);
}

Expand Down
2 changes: 2 additions & 0 deletions src/strategy/StrategyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class StrategyContext : public NamedObjectContext<Strategy>
creators["potions"] = &StrategyContext::potions;
creators["cast time"] = &StrategyContext::cast_time;
creators["threat"] = &StrategyContext::threat;
creators["focus"] = &StrategyContext::focus;
creators["tell target"] = &StrategyContext::tell_target;
creators["pvp"] = &StrategyContext::pvp;
creators["return"] = &StrategyContext::_return;
Expand Down Expand Up @@ -120,6 +121,7 @@ class StrategyContext : public NamedObjectContext<Strategy>
static Strategy* mark_rti(PlayerbotAI* botAI) { return new MarkRtiStrategy(botAI); }
static Strategy* tell_target(PlayerbotAI* botAI) { return new TellTargetStrategy(botAI); }
static Strategy* threat(PlayerbotAI* botAI) { return new ThreatStrategy(botAI); }
static Strategy* focus(PlayerbotAI* botAI) { return new FocusStrategy(botAI); }
static Strategy* cast_time(PlayerbotAI* botAI) { return new CastTimeStrategy(botAI); }
static Strategy* potions(PlayerbotAI* botAI) { return new UsePotionsStrategy(botAI); }
static Strategy* kite(PlayerbotAI* botAI) { return new KiteStrategy(botAI); }
Expand Down
8 changes: 8 additions & 0 deletions src/strategy/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ Unit* UnitCalculatedValue::Get()
if (value && value->IsInWorld())
return value;
return nullptr;
}

Unit* UnitManualSetValue::Get()
{
// Prevent crashing by InWorld check
if (value && value->IsInWorld())
return value;
return nullptr;
}
1 change: 1 addition & 0 deletions src/strategy/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class UnitManualSetValue : public ManualSetValue<Unit*>
ManualSetValue<Unit*>(botAI, defaultValue, name) { }

std::string const Format() override;
Unit* Get() override;
};

#endif
7 changes: 6 additions & 1 deletion src/strategy/actions/AttackAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ bool AttackMyTargetAction::Execute(Event event)

return false;
}


botAI->GetAiObjectContext()->GetValue<GuidVector>("prioritized targets")->Set({guid});
bool result = Attack(botAI->GetUnit(guid));
if (result)
context->GetValue<ObjectGuid>("pull target")->Set(guid);
Expand All @@ -62,6 +63,10 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
return false;
}

if (!target->IsInWorld())
{
return false;
}
std::ostringstream msg;
msg << target->GetName();

Expand Down
4 changes: 2 additions & 2 deletions src/strategy/actions/ChangeTalentsAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ bool ChangeTalentsAction::Execute(Event event)
if (param.find("help") != std::string::npos) {
out << TalentsHelp();
} else if (param.find("switch") != std::string::npos) {
if (param == "1") {
if (param.find("switch 1")) {
bot->ActivateSpec(0);
out << "Active first talent";
} else if (param == "2") {
} else if (param.find("switch 2")) {
bot->ActivateSpec(1);
out << "Active second talent";
}
Expand Down
2 changes: 1 addition & 1 deletion src/strategy/actions/MovementActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ bool MovementAction::Follow(Unit* target, float distance)

void MovementAction::UpdateMovementState()
{
if (bot->Unit::IsInWater() || bot->Unit::IsUnderWater())
if (bot->Unit::IsUnderWater())
{
bot->SetSwim(true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/strategy/actions/ReviveFromCorpseAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ bool SpiritHealerAction::Execute(Event event)
Unit* unit = botAI->GetUnit(*i);
if (unit && unit->HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER))
{
LOG_INFO("playerbots", "Bot {} {}:{} <{}> revives at spirit healer",
LOG_DEBUG("playerbots", "Bot {} {}:{} <{}> revives at spirit healer",
bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->getLevel(), bot->GetName());
PlayerbotChatHandler ch(bot);
bot->ResurrectPlayer(0.5f);
Expand Down
2 changes: 2 additions & 0 deletions src/strategy/deathknight/DKActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ class CastDeathAndDecayAction : public CastSpellAction
{
public:
CastDeathAndDecayAction(PlayerbotAI* botAI) : CastSpellAction(botAI, "death and decay") { }

ActionThreatType getThreatType() override { return ActionThreatType::Aoe; }
};

class CastHornOfWinterAction : public CastSpellAction
Expand Down
20 changes: 20 additions & 0 deletions src/strategy/generic/ThreatStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ThreatStrategy.h"
#include "GenericSpellActions.h"
#include "Map.h"
#include "Playerbots.h"

float ThreatMultiplier::GetValue(Action* action)
Expand Down Expand Up @@ -36,3 +37,22 @@ void ThreatStrategy::InitMultipliers(std::vector<Multiplier*>& multipliers)
{
multipliers.push_back(new ThreatMultiplier(botAI));
}

float FocusMultiplier::GetValue(Action* action)
{
if (!action) {
return 1.0f;
}
if (action->getThreatType() == Action::ActionThreatType::Aoe && !dynamic_cast<CastHealingSpellAction*>(action)) {
return 0.0f;
}
if (dynamic_cast<CastDebuffSpellOnAttackerAction*>(action)) {
return 0.0f;
}
return 1.0f;
}

void FocusStrategy::InitMultipliers(std::vector<Multiplier*>& multipliers)
{
multipliers.push_back(new FocusMultiplier(botAI));
}
17 changes: 17 additions & 0 deletions src/strategy/generic/ThreatStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,21 @@ class ThreatStrategy : public Strategy
std::string const getName() override { return "threat"; }
};

class FocusMultiplier : public Multiplier
{
public:
FocusMultiplier(PlayerbotAI* botAI) : Multiplier(botAI, "focus") { }

float GetValue(Action* action) override;
};

class FocusStrategy : public Strategy
{
public:
FocusStrategy(PlayerbotAI* botAI) : Strategy(botAI) { }

void InitMultipliers(std::vector<Multiplier*>& multipliers) override;
std::string const getName() override { return "focus"; }
};

#endif
12 changes: 12 additions & 0 deletions src/strategy/raids/naxxramas/RaidNaxxMultipliers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
#include "WarriorActions.h"
#include "DruidBearActions.h"

float GrobbulusMultiplier::GetValue(Action* action)
{
Unit* boss = AI_VALUE2(Unit*, "find target", "grobbulus");
if (!boss) {
return 1.0f;
}
if (dynamic_cast<AvoidAoeAction*>(action)) {
return 0.0f;
}
return 1.0f;
}

float HeiganDanceMultiplier::GetValue(Action* action)
{
Unit* boss = AI_VALUE2(Unit*, "find target", "heigan the unclean");
Expand Down
Loading

0 comments on commit e16e659

Please sign in to comment.