Skip to content

Commit

Permalink
Merge pull request #549 from liyunfan1223/combat_formation
Browse files Browse the repository at this point in the history
[WIP] Tank face and dps behind
  • Loading branch information
liyunfan1223 committed Sep 26, 2024
2 parents c710345 + 4df77e6 commit b69d3bd
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 106 deletions.
12 changes: 9 additions & 3 deletions src/AiFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa
}
if (sPlayerbotAIConfig->autoSaveMana)
{
engine->addStrategy("smana", false);
engine->addStrategy("save mana", false);
}
if (sPlayerbotAIConfig->autoAvoidAoe && facade->HasRealPlayerMaster())
{
engine->addStrategy("aaoe", false);
engine->addStrategy("avoid aoe", false);
}
engine->addStrategy("formation", false);
switch (player->getClass())
Expand Down Expand Up @@ -388,6 +388,12 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa

break;
}
if (PlayerbotAI::IsTank(player, true)) {
engine->addStrategy("tank face", false);
}
if (PlayerbotAI::IsMelee(player, true) && PlayerbotAI::IsDps(player, true)) {
engine->addStrategy("behind", false);
}

if (facade->IsRealPlayer() || sRandomPlayerbotMgr->IsRandomBot(player))
{
Expand Down Expand Up @@ -599,7 +605,7 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const

if (sPlayerbotAIConfig->autoSaveMana)
{
nonCombatEngine->addStrategy("smana", false);
nonCombatEngine->addStrategy("save mana", false);
}
if ((sRandomPlayerbotMgr->IsRandomBot(player)) && !player->InBattleground())
{
Expand Down
35 changes: 29 additions & 6 deletions src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
AllowActivity();

Spell* currentSpell = bot->GetCurrentSpell(CURRENT_GENERIC_SPELL);
if (!currentSpell)
currentSpell = bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL);
if (currentSpell && currentSpell->getState() == SPELL_STATE_PREPARING)
{
if (currentSpell->m_targets.GetUnitTarget() && !currentSpell->m_targets.GetUnitTarget()->IsAlive() &&
Expand All @@ -326,9 +328,9 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
}

if (nextTransportCheck > elapsed)
nextTransportCheck -= elapsed;
else
nextTransportCheck = 0;
nextTransportCheck -= elapsed;
else
nextTransportCheck = 0;

if (!nextTransportCheck)
{
Expand Down Expand Up @@ -1093,7 +1095,9 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
horizontalSpeed = 0.11f;
}
verticalSpeed = -verticalSpeed;

// high vertical may result in stuck as bot can not handle gravity
if (verticalSpeed > 35.0f)
break;
// stop casting
InterruptSpell();

Expand All @@ -1102,7 +1106,7 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
bot->GetMotionMaster()->Clear();

Unit* currentTarget = GetAiObjectContext()->GetValue<Unit*>("current target")->Get();
bot->GetMotionMaster()->MoveKnockbackFromForPlayer(bot->GetPositionX() + vcos, bot->GetPositionY() + vsin,
bot->GetMotionMaster()->MoveKnockbackFromForPlayer(bot->GetPositionX() - vcos, bot->GetPositionY() - vsin,
horizontalSpeed, verticalSpeed);

// bot->AddUnitMovementFlag(MOVEMENTFLAG_FALLING);
Expand Down Expand Up @@ -2023,7 +2027,7 @@ bool PlayerbotAI::IsDps(Player* player, bool bySpec)
{
return true;
}
if (tab == DRUID_TAB_FERAL && !IsTank(player))
if (tab == DRUID_TAB_FERAL && !IsTank(player, bySpec))
{
return true;
}
Expand Down Expand Up @@ -2088,6 +2092,25 @@ bool PlayerbotAI::IsMainTank(Player* player)
return false;
}

uint32 PlayerbotAI::GetGroupTankNum(Player* player)
{
Group* group = player->GetGroup();
if (!group)
{
return 0;
}
uint32 result = 0;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (IsTank(member) && member->IsAlive())
{
result++;
}
}
return result;
}

bool PlayerbotAI::IsAssistTank(Player* player) { return IsTank(player) && !IsMainTank(player); }

bool PlayerbotAI::IsAssistTankOfIndex(Player* player, int index)
Expand Down
1 change: 1 addition & 0 deletions src/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class PlayerbotAI : public PlayerbotAIBase
static bool IsCombo(Player* player, bool bySpec = false);
static bool IsRangedDps(Player* player, bool bySpec = false);
static bool IsMainTank(Player* player);
static uint32 GetGroupTankNum(Player* player);
bool IsAssistTank(Player* player);
bool IsAssistTankOfIndex(Player* player, int index);
bool IsHealAssistantOfIndex(Player* player, int index);
Expand Down
5 changes: 4 additions & 1 deletion src/PlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,10 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
sGroupMgr->AddGroup(newGroup);
newGroup->AddMember(bot);
}

// if (master)
// {
// // bot->TeleportTo(master);
// }
uint32 accountId = bot->GetSession()->GetAccountId();
bool isRandomAccount = sPlayerbotAIConfig->IsInRandomAccountList(accountId);

Expand Down
7 changes: 4 additions & 3 deletions src/strategy/StrategyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ class StrategyContext : public NamedObjectContext<Strategy>
creators["gather"] = &StrategyContext::gather;
creators["emote"] = &StrategyContext::emote;
creators["passive"] = &StrategyContext::passive;
// creators["conserve mana"] = &StrategyContext::conserve_mana;
creators["smana"] = &StrategyContext::auto_save_mana;
creators["save mana"] = &StrategyContext::auto_save_mana;
creators["food"] = &StrategyContext::food;
creators["chat"] = &StrategyContext::chat;
creators["default"] = &StrategyContext::world_packet;
Expand Down Expand Up @@ -113,7 +112,8 @@ class StrategyContext : public NamedObjectContext<Strategy>
creators["group"] = &StrategyContext::group;
creators["guild"] = &StrategyContext::guild;
creators["grind"] = &StrategyContext::grind;
creators["aaoe"] = &StrategyContext::avoid_aoe;
creators["avoid aoe"] = &StrategyContext::avoid_aoe;
creators["tank face"] = &StrategyContext::tank_face;
creators["move random"] = &StrategyContext::move_random;
creators["formation"] = &StrategyContext::combat_formation;
creators["move from group"] = &StrategyContext::move_from_group;
Expand Down Expand Up @@ -179,6 +179,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* tank_face(PlayerbotAI* botAI) { return new TankFaceStrategy(botAI); }
static Strategy* move_random(PlayerbotAI* ai) { return new MoveRandomStrategy(ai); }
static Strategy* combat_formation(PlayerbotAI* ai) { return new CombatFormationStrategy(ai); }
static Strategy* move_from_group(PlayerbotAI* botAI) { return new MoveFromGroupStrategy(botAI); }
Expand Down
4 changes: 3 additions & 1 deletion src/strategy/actions/ActionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ class ActionContext : public NamedObjectContext<Action>
creators["reach party member to resurrect"] = &ActionContext::reach_party_member_to_resurrect;
creators["flee"] = &ActionContext::flee;
creators["flee with pet"] = &ActionContext::flee_with_pet;
creators["aaoe"] = &ActionContext::avoid_aoe;
creators["avoid aoe"] = &ActionContext::avoid_aoe;
creators["combat formation move"] = &ActionContext::combat_formation_move;
creators["tank face"] = &ActionContext::tank_face;
creators["disperse set"] = &ActionContext::disperse_set;
creators["gift of the naaru"] = &ActionContext::gift_of_the_naaru;
creators["shoot"] = &ActionContext::shoot;
Expand Down Expand Up @@ -276,6 +277,7 @@ class ActionContext : public NamedObjectContext<Action>
static Action* flee_with_pet(PlayerbotAI* botAI) { return new FleeWithPetAction(botAI); }
static Action* avoid_aoe(PlayerbotAI* botAI) { return new AvoidAoeAction(botAI); }
static Action* combat_formation_move(PlayerbotAI* botAI) { return new CombatFormationMoveAction(botAI); }
static Action* tank_face(PlayerbotAI* botAI) { return new TankFaceAction(botAI); }
static Action* disperse_set(PlayerbotAI* botAI) { return new DisperseSetAction(botAI); }
static Action* gift_of_the_naaru(PlayerbotAI* botAI) { return new CastGiftOfTheNaaruAction(botAI); }
static Action* lifeblood(PlayerbotAI* botAI) { return new CastLifeBloodAction(botAI); }
Expand Down
Loading

0 comments on commit b69d3bd

Please sign in to comment.