Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,54 @@ bool CheckMountStateAction::Execute(Event event)
return false;
}

class FindMountItemVisitor : public IterateItemsVisitor
{
public:
explicit FindMountItemVisitor(int32 minSpeed) : IterateItemsVisitor(), minSpeed(minSpeed), best(nullptr), bestSpeed(-1) {}

virtual bool Visit(Item* item)
{
for (int s = 0; s < MAX_ITEM_PROTO_SPELLS; ++s)
{
uint32 spellId = item->GetProto()->Spells[s].SpellId;
if (!spellId)
{
continue;
}

SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo || spellInfo->EffectAura[0] != SPELL_AURA_MOUNTED)
{
continue;
}

int32 speed = max(spellInfo->EffectBasePoints[1], spellInfo->EffectBasePoints[2]);
if (speed >= minSpeed && speed > bestSpeed)
{
bestSpeed = speed;
best = item;
}
}
return true;
}

Item* GetResult() { return best; }

private:
int32 minSpeed;
Item* best;
int32 bestSpeed;
};

bool CheckMountStateAction::Mount()
{
Player* master = GetMaster();

if (bot->IsNonMeleeSpellCasted(true))
{
return false;
}

ai->RemoveShapeshift();
Unit::AuraList const& auras = master->GetAurasByType(SPELL_AURA_MOUNTED);
if (auras.empty())
Expand Down Expand Up @@ -82,8 +127,22 @@ bool CheckMountStateAction::Mount()
}

ai->CastSpell(ids[index], bot);
ai->SetNextCheckDelay(4000);
return true;
}

return false;
FindMountItemVisitor visitor(masterSpeed);
IterateItems(&visitor);
Item* mountItem = visitor.GetResult();
if (!mountItem)
{
return false;
}

SpellCastTargets targets;
targets.m_targetMask = TARGET_FLAG_SELF;
targets.setUnitTarget(bot);
bot->CastItemUseSpell(mountItem, targets);
ai->SetNextCheckDelay(4000);
return true;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include "../Action.h"
#include "InventoryAction.h"
#include "MovementActions.h"
#include "../values/LastMovementValue.h"

namespace ai
{
class CheckMountStateAction : public Action {
class CheckMountStateAction : public InventoryAction {
public:
CheckMountStateAction(PlayerbotAI* ai) : Action(ai, "check mount state") {}
CheckMountStateAction(PlayerbotAI* ai) : InventoryAction(ai, "check mount state") {}

virtual bool Execute(Event event);

Expand Down
Loading