Improve class spell and use trinket

This commit is contained in:
Yunfan Li
2024-08-14 18:18:01 +08:00
parent c778e303df
commit a1cb9dea05
47 changed files with 377 additions and 108 deletions

View File

@@ -154,6 +154,9 @@ public:
creators["give water"] = &ActionContext::give_water;
creators["mount"] = &ActionContext::mount;
creators["war stomp"] = &ActionContext::war_stomp;
creators["blood fury"] = &ActionContext::blood_fury;
creators["berserking"] = &ActionContext::berserking;
creators["use trinket"] = &ActionContext::use_trinket;
creators["auto talents"] = &ActionContext::auto_talents;
creators["auto learn spell"] = &ActionContext::auto_learn_spell;
creators["auto share quest"] = &ActionContext::auto_share_quest;
@@ -324,6 +327,9 @@ private:
static Action* try_emergency(PlayerbotAI* botAI) { return new TryEmergencyAction(botAI); }
static Action* mount(PlayerbotAI* botAI) { return new CastSpellAction(botAI, "mount"); }
static Action* war_stomp(PlayerbotAI* botAI) { return new CastWarStompAction(botAI); }
static Action* blood_fury(PlayerbotAI* botAI) { return new CastBloodFuryAction(botAI); }
static Action* berserking(PlayerbotAI* botAI) { return new CastBerserkingAction(botAI); }
static Action* use_trinket(PlayerbotAI* botAI) { return new UseTrinketAction(botAI); }
static Action* auto_talents(PlayerbotAI* botAI) { return new AutoSetTalentsAction(botAI); }
static Action* auto_learn_spell(PlayerbotAI* botAI) { return new AutoLearnSpellAction(botAI); }
static Action* auto_share_quest(PlayerbotAI* ai) { return new AutoShareQuestAction(ai); }

View File

@@ -36,9 +36,9 @@ bool TogglePetSpellAutoCastAction::Execute(Event event)
continue;
bool shouldApply = true;
// imp's spell, felhunte's intelligence, ghoul's leap, cat stealth
// imp's spell, felhunte's intelligence, cat stealth
if (spellId == 4511 || spellId == 1742 || spellId == 54424 || spellId == 57564 || spellId == 57565 ||
spellId == 57566 || spellId == 57567 || spellId == 47482 || spellId == 24450)
spellId == 57566 || spellId == 57567 || spellId == 24450)
{
shouldApply = false;
}
@@ -72,7 +72,7 @@ bool PetAttackAction::Execute(Event event)
{
return false;
}
// pet->SetReactState(REACT_DEFENSIVE);
pet->SetReactState(REACT_PASSIVE);
pet->ClearUnitState(UNIT_STATE_FOLLOW);
pet->AttackStop();
pet->SetTarget(target->GetGUID());

View File

@@ -6,8 +6,13 @@
#include "GenericSpellActions.h"
#include "Event.h"
#include "ItemTemplate.h"
#include "ObjectDefines.h"
#include "Opcodes.h"
#include "Player.h"
#include "Playerbots.h"
#include "ServerFacade.h"
#include "WorldPacket.h"
CastSpellAction::CastSpellAction(PlayerbotAI* botAI, std::string const spell)
: Action(botAI, spell), range(botAI->GetRange("spell")), spell(spell)
@@ -124,11 +129,35 @@ bool CastSpellAction::isUseful()
CastMeleeSpellAction::CastMeleeSpellAction(PlayerbotAI* botAI, std::string const spell) : CastSpellAction(botAI, spell)
{
range = ATTACK_DISTANCE;
// Unit* target = AI_VALUE(Unit*, "current target");
// if (target)
// range = bot->GetMeleeRange(target);
}
// range = target->GetCombinedCombatReach();
bool CastMeleeSpellAction::isUseful()
{
Unit* target = GetTarget();
if (!target)
return false;
if (!bot->IsWithinMeleeRange(target))
return false;
return CastSpellAction::isUseful();
}
CastMeleeDebuffSpellAction::CastMeleeDebuffSpellAction(PlayerbotAI* botAI, std::string const spell, bool isOwner, float needLifeTime) : CastDebuffSpellAction(botAI, spell, isOwner, needLifeTime)
{
range = ATTACK_DISTANCE;
}
bool CastMeleeDebuffSpellAction::isUseful()
{
Unit* target = GetTarget();
if (!target)
return false;
if (!bot->IsWithinMeleeRange(target))
return false;
return CastDebuffSpellAction::isUseful();
}
bool CastAuraSpellAction::isUseful()
@@ -209,17 +238,7 @@ CastShootAction::CastShootAction(PlayerbotAI* botAI) : CastSpellAction(botAI, "s
NextAction** CastSpellAction::getPrerequisites()
{
if (spell == "mount")
return nullptr;
if (range > botAI->GetRange("spell"))
return nullptr;
else if (range > ATTACK_DISTANCE)
return NextAction::merge(NextAction::array(0, new NextAction("reach spell"), nullptr),
Action::getPrerequisites());
else
return NextAction::merge(NextAction::array(0, new NextAction("reach melee"), nullptr),
Action::getPrerequisites());
return nullptr;
}
Value<Unit*>* CastDebuffSpellOnAttackerAction::GetTargetValue()
@@ -271,6 +290,70 @@ bool CastVehicleSpellAction::Execute(Event event)
return botAI->CastVehicleSpell(spellId, GetTarget());
}
bool UseTrinketAction::Execute(Event event)
{
Item* trinket1 = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_TRINKET1);
if (trinket1 && UseTrinket(trinket1))
return true;
Item* trinket2 = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_TRINKET2);
if (trinket2 && UseTrinket(trinket2))
return true;
return false;
}
bool UseTrinketAction::UseTrinket(Item* item)
{
if (bot->CanUseItem(item) != EQUIP_ERR_OK)
return false;
if (bot->IsNonMeleeSpellCast(true))
return false;
uint8 bagIndex = item->GetBagSlot();
uint8 slot = item->GetSlot();
uint8 spell_index = 0;
uint8 cast_count = 1;
ObjectGuid item_guid = item->GetGUID();
uint32 glyphIndex = 0;
uint8 castFlags = 0;
uint32 targetFlag = TARGET_FLAG_NONE;
uint32 spellId = 0;
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
{
if (item->GetTemplate()->Spells[i].SpellId > 0 && item->GetTemplate()->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_USE)
{
spellId = item->GetTemplate()->Spells[i].SpellId;
if (!botAI->CanCastSpell(spellId, bot, false))
{
return false;
}
break;
}
}
if (!spellId)
return false;
WorldPacket packet(CMSG_USE_ITEM);
packet << bagIndex << slot << cast_count << spellId << item_guid << glyphIndex << castFlags;
Unit* target = AI_VALUE(Unit*, "current target");
if (target)
{
targetFlag = TARGET_FLAG_UNIT;
packet << targetFlag << target->GetGUID().WriteAsPacked();
}
else
{
targetFlag = TARGET_FLAG_NONE;
packet << targetFlag << bot->GetPackGUID();
}
bot->GetSession()->HandleUseItemOpcode(packet);
return true;
}
Value<Unit*>* BuffOnMainTankAction::GetTargetValue() { return context->GetValue<Unit*>("main tank", spell); }
bool CastDebuffSpellAction::isUseful()

View File

@@ -9,6 +9,7 @@
#include "Action.h"
#include "PlayerbotAI.h"
#include "PlayerbotAIConfig.h"
#include "UseItemAction.h"
#include "Value.h"
class PlayerbotAI;
@@ -52,6 +53,7 @@ class CastMeleeSpellAction : public CastSpellAction
{
public:
CastMeleeSpellAction(PlayerbotAI* botAI, std::string const spell);
bool isUseful() override;
};
class CastDebuffSpellAction : public CastAuraSpellAction
@@ -67,6 +69,13 @@ private:
float needLifeTime;
};
class CastMeleeDebuffSpellAction : public CastDebuffSpellAction
{
public:
CastMeleeDebuffSpellAction(PlayerbotAI* botAI, std::string const spell, bool isOwner = false, float needLifeTime = 8.0f);
bool isUseful() override;
};
class CastDebuffSpellOnAttackerAction : public CastDebuffSpellAction
{
public:
@@ -245,10 +254,31 @@ public:
CastManaTapAction(PlayerbotAI* botAI) : CastBuffSpellAction(botAI, "mana tap") {}
};
class CastWarStompAction : public CastSpellAction
class CastWarStompAction : public CastMeleeSpellAction
{
public:
CastWarStompAction(PlayerbotAI* botAI) : CastSpellAction(botAI, "war stomp") {}
CastWarStompAction(PlayerbotAI* botAI) : CastMeleeSpellAction(botAI, "war stomp") {}
};
class CastBloodFuryAction : public CastBuffSpellAction
{
public:
CastBloodFuryAction(PlayerbotAI* botAI) : CastBuffSpellAction(botAI, "blood fury") {}
};
class CastBerserkingAction : public CastBuffSpellAction
{
public:
CastBerserkingAction(PlayerbotAI* botAI) : CastBuffSpellAction(botAI, "berserking") {}
};
class UseTrinketAction : public Action
{
public:
UseTrinketAction(PlayerbotAI* botAI) : Action(botAI, "use trinket") {}
bool Execute(Event event) override;
protected:
bool UseTrinket(Item* trinket);
};
class CastSpellOnEnemyHealerAction : public CastSpellAction

View File

@@ -143,7 +143,10 @@ std::vector<std::pair<uint32, std::string>> ListSpellsAction::GetSpellList(std::
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(itr->first);
if (!spellInfo)
continue;
if (spellInfo->IsPassive())
continue;
SkillLineAbilityEntry const* skillLine = skillSpells[itr->first];
if (skill != SKILL_NONE && (!skillLine || skillLine->SkillLine != skill))
continue;