mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-02-20 18:10:02 +01:00
243 lines
6.8 KiB
C++
243 lines
6.8 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it
|
|
* and/or modify it under version 2 of the License, or (at your option), any later version.
|
|
*/
|
|
|
|
#include "PaladinActions.h"
|
|
#include "BlessingManager.h"
|
|
|
|
#include "AiFactory.h"
|
|
#include "Event.h"
|
|
#include "PlayerbotAI.h"
|
|
#include "PlayerbotAIConfig.h"
|
|
#include "PlayerbotFactory.h"
|
|
#include "Playerbots.h"
|
|
#include "SharedDefines.h"
|
|
|
|
inline std::string const GetActualBlessingOfMight(Unit* target)
|
|
{
|
|
if (!target->ToPlayer())
|
|
{
|
|
return "blessing of might";
|
|
}
|
|
int tab = AiFactory::GetPlayerSpecTab(target->ToPlayer());
|
|
switch (target->getClass())
|
|
{
|
|
case CLASS_MAGE:
|
|
case CLASS_PRIEST:
|
|
case CLASS_WARLOCK:
|
|
return "blessing of wisdom";
|
|
break;
|
|
case CLASS_SHAMAN:
|
|
if (tab == SHAMAN_TAB_ELEMENTAL || tab == SHAMAN_TAB_RESTORATION)
|
|
{
|
|
return "blessing of wisdom";
|
|
}
|
|
break;
|
|
case CLASS_DRUID:
|
|
if (tab == DRUID_TAB_RESTORATION || tab == DRUID_TAB_BALANCE)
|
|
{
|
|
return "blessing of wisdom";
|
|
}
|
|
break;
|
|
case CLASS_PALADIN:
|
|
if (tab == PALADIN_TAB_HOLY)
|
|
{
|
|
return "blessing of wisdom";
|
|
}
|
|
break;
|
|
}
|
|
|
|
return "blessing of might";
|
|
}
|
|
|
|
inline std::string const GetActualBlessingOfWisdom(Unit* target)
|
|
{
|
|
if (!target->ToPlayer())
|
|
{
|
|
return "blessing of might";
|
|
}
|
|
int tab = AiFactory::GetPlayerSpecTab(target->ToPlayer());
|
|
switch (target->getClass())
|
|
{
|
|
case CLASS_WARRIOR:
|
|
case CLASS_ROGUE:
|
|
case CLASS_DEATH_KNIGHT:
|
|
case CLASS_HUNTER:
|
|
return "blessing of might";
|
|
break;
|
|
case CLASS_SHAMAN:
|
|
if (tab == SHAMAN_TAB_ENHANCEMENT)
|
|
{
|
|
return "blessing of might";
|
|
}
|
|
break;
|
|
case CLASS_DRUID:
|
|
if (tab == DRUID_TAB_FERAL)
|
|
{
|
|
return "blessing of might";
|
|
}
|
|
break;
|
|
case CLASS_PALADIN:
|
|
if (tab == PALADIN_TAB_PROTECTION || tab == PALADIN_TAB_RETRIBUTION)
|
|
{
|
|
return "blessing of might";
|
|
}
|
|
break;
|
|
}
|
|
|
|
return "blessing of wisdom";
|
|
}
|
|
|
|
Value<Unit*>* CastBlessingOnPartyAction::GetTargetValue()
|
|
{
|
|
return context->GetValue<Unit*>("party member without aura", name);
|
|
}
|
|
|
|
bool CastBlessingOfMightAction::Execute(Event event)
|
|
{
|
|
Unit* target = GetTarget();
|
|
if (!target)
|
|
return false;
|
|
|
|
return botAI->CastSpell(GetActualBlessingOfMight(target), target);
|
|
}
|
|
|
|
Value<Unit*>* CastBlessingOfMightOnPartyAction::GetTargetValue()
|
|
{
|
|
return context->GetValue<Unit*>("party member without aura", "blessing of might,blessing of wisdom");
|
|
}
|
|
|
|
bool CastBlessingOfMightOnPartyAction::Execute(Event event)
|
|
{
|
|
Unit* target = GetTarget();
|
|
if (!target)
|
|
return false;
|
|
|
|
return botAI->CastSpell(GetActualBlessingOfMight(target), target);
|
|
}
|
|
|
|
bool CastBlessingOfWisdomAction::Execute(Event event)
|
|
{
|
|
Unit* target = GetTarget();
|
|
if (!target)
|
|
return false;
|
|
|
|
return botAI->CastSpell(GetActualBlessingOfWisdom(target), target);
|
|
}
|
|
|
|
Value<Unit*>* CastBlessingOfWisdomOnPartyAction::GetTargetValue()
|
|
{
|
|
return context->GetValue<Unit*>("party member without aura", "blessing of might,blessing of wisdom");
|
|
}
|
|
|
|
bool CastBlessingOfWisdomOnPartyAction::Execute(Event event)
|
|
{
|
|
Unit* target = GetTarget();
|
|
if (!target)
|
|
return false;
|
|
|
|
return botAI->CastSpell(GetActualBlessingOfWisdom(target), target);
|
|
}
|
|
|
|
bool CastSealSpellAction::isUseful() { return AI_VALUE2(bool, "combat", "self target"); }
|
|
|
|
Value<Unit*>* CastTurnUndeadAction::GetTargetValue() { return context->GetValue<Unit*>("cc target", getName()); }
|
|
|
|
Unit* CastRighteousDefenseAction::GetTarget()
|
|
{
|
|
Unit* current_target = AI_VALUE(Unit*, "current target");
|
|
if (!current_target)
|
|
{
|
|
return NULL;
|
|
}
|
|
return current_target->GetVictim();
|
|
}
|
|
|
|
|
|
bool CastDivineSacrificeAction::isUseful()
|
|
{
|
|
return GetTarget() && (GetTarget() != nullptr) && CastSpellAction::isUseful() &&
|
|
!botAI->HasAura("divine guardian", GetTarget(), false, false, -1, true);
|
|
}
|
|
|
|
bool CastCancelDivineSacrificeAction::Execute(Event event)
|
|
{
|
|
botAI->RemoveAura("divine sacrifice");
|
|
return true;
|
|
}
|
|
|
|
bool CastCancelDivineSacrificeAction::isUseful()
|
|
{
|
|
return botAI->HasAura("divine sacrifice", GetTarget(), false, true, -1, true);
|
|
}
|
|
|
|
bool CastGreaterBlessingAction::Execute(Event event)
|
|
{
|
|
Player* bot = botAI->GetBot();
|
|
if (!bot)
|
|
return false;
|
|
|
|
Group* group = bot->GetGroup();
|
|
if (!group)
|
|
return false;
|
|
|
|
// Gather assignments
|
|
auto assignment = AssignBlessingsForGroup(botAI);
|
|
|
|
// Find what is assigned to *this* Paladin
|
|
auto paladinIt = assignment.find(bot);
|
|
if (paladinIt == assignment.end())
|
|
return false; // No blessings assigned
|
|
|
|
// For each (class -> blessing) assigned, search for a player missing it
|
|
for (auto& kv : paladinIt->second)
|
|
{
|
|
uint8 classId = kv.first;
|
|
GreaterBlessingType gBlessing = kv.second;
|
|
|
|
// Convert the blessing to a spell name
|
|
std::string spellName;
|
|
std::string auraName;
|
|
switch (gBlessing)
|
|
{
|
|
case GREATER_BLESSING_OF_MIGHT:
|
|
spellName = "greater blessing of might";
|
|
auraName = "greater blessing of might";
|
|
break;
|
|
case GREATER_BLESSING_OF_WISDOM:
|
|
spellName = "greater blessing of wisdom";
|
|
auraName = "greater blessing of wisdom";
|
|
break;
|
|
case GREATER_BLESSING_OF_KINGS:
|
|
spellName = "greater blessing of kings";
|
|
auraName = "greater blessing of kings";
|
|
break;
|
|
case GREATER_BLESSING_OF_SANCTUARY:
|
|
spellName = "greater blessing of sanctuary";
|
|
auraName = "greater blessing of sanctuary";
|
|
break;
|
|
}
|
|
|
|
// Find the first raid member of that class who lacks the aura
|
|
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
|
|
{
|
|
Player* member = ref->GetSource();
|
|
if (!member || !member->IsInWorld())
|
|
continue;
|
|
|
|
if (member->getClass() == classId && !botAI->HasAura(auraName, member))
|
|
{
|
|
// Found a target
|
|
botAI->TellMaster("Casting " + spellName + " on " + member->GetName());
|
|
bool casted = botAI->CastSpell(spellName, member);
|
|
// Return true as soon as we cast a single Greater Blessing
|
|
return casted;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If we reach here, we didn't find any missing aura
|
|
return false;
|
|
}
|