mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
pet attack and bot target selection
This commit is contained in:
@@ -1718,7 +1718,6 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
|
||||
}
|
||||
|
||||
ObjectGuid oldSel = bot->GetTarget();
|
||||
bot->SetTarget(target->GetGUID());
|
||||
Spell* spell = new Spell(bot, spellInfo, TRIGGERED_NONE);
|
||||
|
||||
spell->m_targets.SetUnitTarget(target);
|
||||
@@ -1933,7 +1932,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
||||
}
|
||||
|
||||
ObjectGuid oldSel = bot->GetTarget();
|
||||
bot->SetTarget(target->GetGUID());
|
||||
bot->SetSelection(target->GetGUID());
|
||||
|
||||
WorldObject* faceTo = target;
|
||||
if (!bot->HasInArc(CAST_ANGLE_IN_FRONT, faceTo))
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Playerbots.h"
|
||||
#include "ServerFacade.h"
|
||||
#include "CreatureAI.h"
|
||||
#include "Unit.h"
|
||||
|
||||
bool AttackAction::Execute(Event event)
|
||||
{
|
||||
@@ -40,7 +41,7 @@ bool AttackMyTargetAction::Execute(Event event)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AttackAction::Attack(Unit* target)
|
||||
bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
|
||||
{
|
||||
if (bot->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE || bot->HasUnitState(UNIT_STATE_IN_FLIGHT))
|
||||
{
|
||||
@@ -93,21 +94,25 @@ bool AttackAction::Attack(Unit* target)
|
||||
}
|
||||
|
||||
ObjectGuid guid = target->GetGUID();
|
||||
bot->SetTarget(target->GetGUID());
|
||||
bot->SetSelection(target->GetGUID());
|
||||
|
||||
Unit* oldTarget = context->GetValue<Unit*>("current target")->Get();
|
||||
context->GetValue<Unit*>("old target")->Set(oldTarget);
|
||||
|
||||
context->GetValue<Unit*>("current target")->Set(target);
|
||||
context->GetValue<LootObjectStack*>("available loot")->Get()->Add(guid);
|
||||
|
||||
|
||||
if (Pet* pet = bot->GetPet())
|
||||
{
|
||||
if (CreatureAI* creatureAI = ((Creature*)pet)->AI())
|
||||
{
|
||||
pet->SetReactState(REACT_PASSIVE);
|
||||
pet->SetReactState(REACT_PASSIVE);
|
||||
if (with_pet) {
|
||||
pet->SetTarget(target->GetGUID());
|
||||
pet->GetCharmInfo()->SetCommandState(COMMAND_ATTACK);
|
||||
creatureAI->AttackStart(target);
|
||||
pet->GetCharmInfo()->SetIsCommandAttack(true);
|
||||
pet->AI()->AttackStart(target);
|
||||
} else {
|
||||
pet->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
|
||||
pet->GetCharmInfo()->SetIsCommandFollow(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class AttackAction : public MovementAction
|
||||
bool Execute(Event event) override;
|
||||
|
||||
protected:
|
||||
bool Attack(Unit* target);
|
||||
bool Attack(Unit* target, bool with_pet = true);
|
||||
};
|
||||
|
||||
class AttackMyTargetAction : public AttackAction
|
||||
|
||||
@@ -82,6 +82,7 @@ bool DropTargetAction::Execute(Event event)
|
||||
{
|
||||
pet->SetReactState(REACT_PASSIVE);
|
||||
pet->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
|
||||
pet->GetCharmInfo()->SetIsCommandFollow(true);
|
||||
pet->AttackStop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ bool EmoteActionBase::Emote(Unit* target, uint32 type, bool textEmote)
|
||||
ObjectGuid oldSelection = bot->GetTarget();
|
||||
if (target)
|
||||
{
|
||||
bot->SetTarget(target->GetGUID());
|
||||
bot->SetSelection(target->GetGUID());
|
||||
|
||||
Player* player = dynamic_cast<Player*>(target);
|
||||
if (player)
|
||||
|
||||
@@ -636,7 +636,6 @@ bool MovementAction::MoveTo(Unit* target, float distance)
|
||||
float distanceToTarget = sServerFacade->GetDistance2d(bot, tx, ty);
|
||||
if (sServerFacade->IsDistanceGreaterThan(distanceToTarget, sPlayerbotAIConfig->targetPosRecalcDistance))
|
||||
{
|
||||
/*
|
||||
float angle = bot->GetAngle(tx, ty);
|
||||
float needToGo = distanceToTarget - distance;
|
||||
|
||||
@@ -649,15 +648,10 @@ bool MovementAction::MoveTo(Unit* target, float distance)
|
||||
float dx = cos(angle) * needToGo + bx;
|
||||
float dy = sin(angle) * needToGo + by;
|
||||
float dz = bz + (tz - bz) * needToGo / distanceToTarget;
|
||||
*/
|
||||
|
||||
float dx = tx;
|
||||
float dy = ty;
|
||||
float dz = tz;
|
||||
return MoveTo(target->GetMapId(), dx, dy, dz);
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
float MovementAction::GetFollowAngle()
|
||||
@@ -991,7 +985,7 @@ bool MovementAction::ChaseTo(WorldObject* obj, float distance, float angle)
|
||||
return false;
|
||||
|
||||
//vehicle->GetMotionMaster()->Clear();
|
||||
vehicle->GetBase()->GetMotionMaster()->MoveChase((Unit*)obj, 30.0f, angle);
|
||||
vehicle->GetBase()->GetMotionMaster()->MoveChase((Unit*)obj, 30.0f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1007,7 +1001,7 @@ bool MovementAction::ChaseTo(WorldObject* obj, float distance, float angle)
|
||||
}
|
||||
|
||||
// bot->GetMotionMaster()->Clear();
|
||||
bot->GetMotionMaster()->MoveChase((Unit*) obj, distance, angle);
|
||||
bot->GetMotionMaster()->MoveChase((Unit*) obj, distance);
|
||||
WaitForReach(bot->GetExactDist2d(obj) - distance);
|
||||
return true;
|
||||
}
|
||||
@@ -1224,15 +1218,15 @@ bool FleeAction::Execute(Event event)
|
||||
|
||||
bool FleeWithPetAction::Execute(Event event)
|
||||
{
|
||||
if (Pet* pet = bot->GetPet())
|
||||
{
|
||||
if (CreatureAI* creatureAI = ((Creature*)pet)->AI())
|
||||
{
|
||||
pet->SetReactState(REACT_PASSIVE);
|
||||
pet->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
|
||||
pet->AttackStop();
|
||||
}
|
||||
}
|
||||
// if (Pet* pet = bot->GetPet())
|
||||
// {
|
||||
// if (CreatureAI* creatureAI = ((Creature*)pet)->AI())
|
||||
// {
|
||||
// pet->SetReactState(REACT_PASSIVE);
|
||||
// pet->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
|
||||
// pet->AttackStop();
|
||||
// }
|
||||
// }
|
||||
|
||||
return Flee(AI_VALUE(Unit*, "current target"));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "ReachTargetActions.h"
|
||||
#include "Event.h"
|
||||
#include "PlayerbotAIConfig.h"
|
||||
#include "Playerbots.h"
|
||||
#include "ServerFacade.h"
|
||||
|
||||
@@ -18,7 +19,8 @@ bool ReachTargetAction::Execute(Event event)
|
||||
float combatReach = bot->GetCombatReach() + target->GetCombatReach() + 4.0f / 3.0f;
|
||||
if (distance < std::max(5.0f, combatReach))
|
||||
{
|
||||
return ChaseTo(target, 0.0f, GetFollowAngle());
|
||||
// return MoveTo(target, 0.0f);
|
||||
return ChaseTo(target, 0.0f, bot->GetAngle(target));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -27,6 +29,7 @@ bool ReachTargetAction::Execute(Event event)
|
||||
bool isFriend = bot->IsFriendlyTo(target);
|
||||
float chaseDist = inLos ? distance : isFriend ? distance / 2 : distance;
|
||||
return ChaseTo(target, chaseDist - sPlayerbotAIConfig->contactDistance, bot->GetAngle(target));
|
||||
// return MoveTo(target, chaseDist - sPlayerbotAIConfig->contactDistance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ class GenericPaladinStrategyActionNodeFactory : public NamedObjectFactory<Action
|
||||
{
|
||||
return new ActionNode ("lay on hands on party",
|
||||
/*P*/ nullptr,
|
||||
/*A*/ NextAction::array(0, new NextAction("flash of light"), nullptr),
|
||||
/*A*/ NextAction::array(0, new NextAction("flash of light on party"), nullptr),
|
||||
/*C*/ nullptr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user