mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Levelup maintenance
This commit is contained in:
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* 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 "AutoLearnSpellAction.h"
|
||||
|
||||
#include "Event.h"
|
||||
#include "GuildMgr.h"
|
||||
#include "PlayerbotFactory.h"
|
||||
#include "Playerbots.h"
|
||||
#include "BroadcastHelper.h"
|
||||
|
||||
bool AutoLearnSpellAction::Execute(Event event)
|
||||
{
|
||||
std::string const param = event.getParam();
|
||||
|
||||
std::ostringstream out;
|
||||
LearnSpells(&out);
|
||||
|
||||
if (!out.str().empty())
|
||||
{
|
||||
std::string const temp = out.str();
|
||||
out.seekp(0);
|
||||
out << "Learned spells: ";
|
||||
out << temp;
|
||||
out.seekp(-2, out.cur);
|
||||
out << ".";
|
||||
botAI->TellMaster(out);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AutoLearnSpellAction::LearnSpells(std::ostringstream* out)
|
||||
{
|
||||
BroadcastHelper::BroadcastLevelup(botAI, bot);
|
||||
if (sPlayerbotAIConfig->autoLearnTrainerSpells &&
|
||||
sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||
LearnTrainerSpells(out);
|
||||
|
||||
if (sPlayerbotAIConfig->autoLearnQuestSpells &&
|
||||
sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||
LearnQuestSpells(out);
|
||||
}
|
||||
|
||||
void AutoLearnSpellAction::LearnTrainerSpells(std::ostringstream* out)
|
||||
{
|
||||
PlayerbotFactory factory(bot, bot->GetLevel());
|
||||
factory.InitClassSpells();
|
||||
factory.InitAvailableSpells();
|
||||
factory.InitSkills();
|
||||
factory.InitPet();
|
||||
// bot->LearnDefaultSkills();
|
||||
|
||||
// CreatureTemplateContainer const* creatureTemplateContainer = sObjectMgr->GetCreatureTemplates();
|
||||
// for (CreatureTemplateContainer::const_iterator i = creatureTemplateContainer->begin(); i !=
|
||||
// creatureTemplateContainer->end(); ++i)
|
||||
// {
|
||||
// CreatureTemplate const& co = i->second;
|
||||
// if (co.trainer_type != TRAINER_TYPE_TRADESKILLS && co.trainer_type != TRAINER_TYPE_CLASS)
|
||||
// continue;
|
||||
|
||||
// if (co.trainer_type == TRAINER_TYPE_CLASS && co.trainer_class != bot->getClass())
|
||||
// continue;
|
||||
|
||||
// uint32 trainerId = co.Entry;
|
||||
|
||||
// TrainerSpellData const* trainer_spells = sObjectMgr->GetNpcTrainerSpells(trainerId);
|
||||
// if (!trainer_spells)
|
||||
// trainer_spells = sObjectMgr->GetNpcTrainerSpells(trainerId);
|
||||
|
||||
// if (!trainer_spells)
|
||||
// continue;
|
||||
|
||||
// for (TrainerSpellMap::const_iterator itr = trainer_spells->spellList.begin(); itr !=
|
||||
// trainer_spells->spellList.end(); ++itr)
|
||||
// {
|
||||
// TrainerSpell const* tSpell = &itr->second;
|
||||
|
||||
// if (!tSpell)
|
||||
// continue;
|
||||
|
||||
// if (!tSpell->learnedSpell[0] && !bot->IsSpellFitByClassAndRace(tSpell->learnedSpell[0]))
|
||||
// continue;
|
||||
|
||||
// TrainerSpellState state = bot->GetTrainerSpellState(tSpell);
|
||||
// if (state != TRAINER_SPELL_GREEN)
|
||||
// continue;
|
||||
|
||||
// SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(tSpell->spell);
|
||||
// bool learn = true;
|
||||
// for (uint8 j = 0; j < 3; ++j)
|
||||
// {
|
||||
// if (!tSpell->learnedSpell[j] && !bot->IsSpellFitByClassAndRace(tSpell->learnedSpell[j]))
|
||||
// continue;
|
||||
|
||||
// if (spellInfo->Effects[j].Effect == SPELL_EFFECT_PROFICIENCY ||
|
||||
// spellInfo->Effects[j].Effect == SPELL_EFFECT_SKILL_STEP ||
|
||||
// spellInfo->Effects[j].Effect == SPELL_EFFECT_DUAL_WIELD)
|
||||
// {
|
||||
// learn = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!learn) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if (tSpell->learnedSpell[0]) {
|
||||
// bot->learnSpell(tSpell->learnedSpell[0], false);
|
||||
// }
|
||||
// else {
|
||||
// LOG_INFO("playerbots", "!tSpell->learnedSpell[0] {}", tSpell->spell);
|
||||
// botAI->CastSpell(tSpell->spell, bot);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void AutoLearnSpellAction::LearnQuestSpells(std::ostringstream* out)
|
||||
{
|
||||
// CreatureTemplate const* co = sCreatureStorage.LookupEntry<CreatureTemplate>(id);
|
||||
ObjectMgr::QuestMap const& questTemplates = sObjectMgr->GetQuestTemplates();
|
||||
for (ObjectMgr::QuestMap::const_iterator i = questTemplates.begin(); i != questTemplates.end(); ++i)
|
||||
{
|
||||
uint32 questId = i->first;
|
||||
Quest const* quest = i->second;
|
||||
|
||||
if (!quest->GetRequiredClasses() || quest->IsRepeatable() || quest->GetMinLevel() < 10)
|
||||
continue;
|
||||
|
||||
if (!bot->SatisfyQuestClass(quest, false) || quest->GetMinLevel() > bot->GetLevel() ||
|
||||
!bot->SatisfyQuestRace(quest, false))
|
||||
continue;
|
||||
|
||||
if (quest->GetRewSpellCast() > 0)
|
||||
{
|
||||
LearnSpell(quest->GetRewSpellCast(), out);
|
||||
}
|
||||
else if (quest->GetRewSpell() > 0)
|
||||
{
|
||||
LearnSpell(quest->GetRewSpell(), out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string const FormatSpell(SpellInfo const* sInfo)
|
||||
{
|
||||
std::ostringstream out;
|
||||
std::string const rank = sInfo->Rank[0];
|
||||
|
||||
if (rank.empty())
|
||||
out << "|cffffffff|Hspell:" << sInfo->Id << "|h[" << sInfo->SpellName[LOCALE_enUS] << "]|h|r";
|
||||
else
|
||||
out << "|cffffffff|Hspell:" << sInfo->Id << "|h[" << sInfo->SpellName[LOCALE_enUS] << " " << rank << "]|h|r";
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
void AutoLearnSpellAction::LearnSpell(uint32 spellId, std::ostringstream* out)
|
||||
{
|
||||
SpellInfo const* proto = sSpellMgr->GetSpellInfo(spellId);
|
||||
if (!proto)
|
||||
return;
|
||||
|
||||
bool learned = false;
|
||||
for (uint8 j = 0; j < 3; ++j)
|
||||
{
|
||||
if (proto->Effects[j].Effect == SPELL_EFFECT_LEARN_SPELL)
|
||||
{
|
||||
uint32 learnedSpell = proto->Effects[j].TriggerSpell;
|
||||
|
||||
if (!bot->HasSpell(learnedSpell))
|
||||
{
|
||||
bot->learnSpell(learnedSpell);
|
||||
*out << FormatSpell(sSpellMgr->GetSpellInfo(learnedSpell)) << ", ";
|
||||
}
|
||||
|
||||
learned = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!learned)
|
||||
{
|
||||
if (!bot->HasSpell(spellId))
|
||||
{
|
||||
bot->learnSpell(spellId);
|
||||
*out << FormatSpell(proto) << ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AutoUpgradeEquipAction::Execute(Event event)
|
||||
{
|
||||
if (!sPlayerbotAIConfig->autoUpgradeEquip || !sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
PlayerbotFactory factory(bot, bot->GetLevel());
|
||||
if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel)
|
||||
{
|
||||
factory.InitEquipment(true);
|
||||
}
|
||||
factory.InitAmmo();
|
||||
return true;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _PLAYERBOT_AUTOLEARNSPELLACTION_H
|
||||
#define _PLAYERBOT_AUTOLEARNSPELLACTION_H
|
||||
|
||||
#include "Action.h"
|
||||
|
||||
class PlayerbotAI;
|
||||
|
||||
class AutoLearnSpellAction : public Action
|
||||
{
|
||||
public:
|
||||
AutoLearnSpellAction(PlayerbotAI* botAI, std::string const name = "auto learn spell") : Action(botAI, name) {}
|
||||
|
||||
bool Execute(Event event);
|
||||
|
||||
private:
|
||||
void LearnSpells(std::ostringstream* out);
|
||||
void LearnTrainerSpells(std::ostringstream* out);
|
||||
void LearnQuestSpells(std::ostringstream* out);
|
||||
void LearnSpell(uint32 spellId, std::ostringstream* out);
|
||||
};
|
||||
|
||||
class AutoUpgradeEquipAction : public Action
|
||||
{
|
||||
public:
|
||||
AutoUpgradeEquipAction(PlayerbotAI* botAI, std::string const name = "auto upgrade equip") : Action(botAI, name) {}
|
||||
|
||||
bool Execute(Event event);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,21 +1,171 @@
|
||||
#include "AutoTeleportForLevelAction.h"
|
||||
|
||||
#include "GuildMgr.h"
|
||||
#include "PlayerbotAIConfig.h"
|
||||
#include "PlayerbotFactory.h"
|
||||
#include "Playerbots.h"
|
||||
#include "RandomPlayerbotMgr.h"
|
||||
#include "SharedDefines.h"
|
||||
#include "BroadcastHelper.h"
|
||||
|
||||
bool AutoTeleportForLevelAction::Execute(Event event)
|
||||
bool AutoMaintenanceOnLevelupAction::Execute(Event event)
|
||||
{
|
||||
AutoPickTalents();
|
||||
AutoLearnSpell();
|
||||
AutoUpgradeEquip();
|
||||
AutoTeleportForLevel();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::AutoTeleportForLevel()
|
||||
{
|
||||
if (!sPlayerbotAIConfig->autoTeleportForLevel || !sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||
{
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (botAI->HasRealPlayerMaster())
|
||||
{
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
sRandomPlayerbotMgr->RandomTeleportForLevel(bot);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::AutoPickTalents()
|
||||
{
|
||||
if (!sPlayerbotAIConfig->autoPickTalents || !sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||
return;
|
||||
|
||||
if (bot->GetFreeTalentPoints() <= 0)
|
||||
return;
|
||||
|
||||
PlayerbotFactory factory(bot, bot->GetLevel());
|
||||
factory.InitTalentsTree(true, true, true);
|
||||
factory.InitPetTalents();
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::AutoLearnSpell()
|
||||
{
|
||||
std::ostringstream out;
|
||||
LearnSpells(&out);
|
||||
|
||||
if (!out.str().empty())
|
||||
{
|
||||
std::string const temp = out.str();
|
||||
out.seekp(0);
|
||||
out << "Learned spells: ";
|
||||
out << temp;
|
||||
out.seekp(-2, out.cur);
|
||||
out << ".";
|
||||
botAI->TellMaster(out);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::LearnSpells(std::ostringstream* out)
|
||||
{
|
||||
BroadcastHelper::BroadcastLevelup(botAI, bot);
|
||||
if (sPlayerbotAIConfig->autoLearnTrainerSpells)
|
||||
LearnTrainerSpells(out);
|
||||
|
||||
if (sPlayerbotAIConfig->autoLearnQuestSpells)
|
||||
LearnQuestSpells(out);
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::LearnTrainerSpells(std::ostringstream* out)
|
||||
{
|
||||
PlayerbotFactory factory(bot, bot->GetLevel());
|
||||
factory.InitClassSpells();
|
||||
factory.InitAvailableSpells();
|
||||
factory.InitSkills();
|
||||
factory.InitPet();
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::LearnQuestSpells(std::ostringstream* out)
|
||||
{
|
||||
// CreatureTemplate const* co = sCreatureStorage.LookupEntry<CreatureTemplate>(id);
|
||||
ObjectMgr::QuestMap const& questTemplates = sObjectMgr->GetQuestTemplates();
|
||||
for (ObjectMgr::QuestMap::const_iterator i = questTemplates.begin(); i != questTemplates.end(); ++i)
|
||||
{
|
||||
uint32 questId = i->first;
|
||||
Quest const* quest = i->second;
|
||||
|
||||
if (!quest->GetRequiredClasses() || quest->IsRepeatable() || quest->GetMinLevel() < 10)
|
||||
continue;
|
||||
|
||||
if (!bot->SatisfyQuestClass(quest, false) || quest->GetMinLevel() > bot->GetLevel() ||
|
||||
!bot->SatisfyQuestRace(quest, false))
|
||||
continue;
|
||||
|
||||
if (quest->GetRewSpellCast() > 0)
|
||||
{
|
||||
LearnSpell(quest->GetRewSpellCast(), out);
|
||||
}
|
||||
else if (quest->GetRewSpell() > 0)
|
||||
{
|
||||
LearnSpell(quest->GetRewSpell(), out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string const AutoMaintenanceOnLevelupAction::FormatSpell(SpellInfo const* sInfo)
|
||||
{
|
||||
std::ostringstream out;
|
||||
std::string const rank = sInfo->Rank[0];
|
||||
|
||||
if (rank.empty())
|
||||
out << "|cffffffff|Hspell:" << sInfo->Id << "|h[" << sInfo->SpellName[LOCALE_enUS] << "]|h|r";
|
||||
else
|
||||
out << "|cffffffff|Hspell:" << sInfo->Id << "|h[" << sInfo->SpellName[LOCALE_enUS] << " " << rank << "]|h|r";
|
||||
|
||||
return out.str();
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::LearnSpell(uint32 spellId, std::ostringstream* out)
|
||||
{
|
||||
SpellInfo const* proto = sSpellMgr->GetSpellInfo(spellId);
|
||||
if (!proto)
|
||||
return;
|
||||
|
||||
bool learned = false;
|
||||
for (uint8 j = 0; j < 3; ++j)
|
||||
{
|
||||
if (proto->Effects[j].Effect == SPELL_EFFECT_LEARN_SPELL)
|
||||
{
|
||||
uint32 learnedSpell = proto->Effects[j].TriggerSpell;
|
||||
|
||||
if (!bot->HasSpell(learnedSpell))
|
||||
{
|
||||
bot->learnSpell(learnedSpell);
|
||||
*out << FormatSpell(sSpellMgr->GetSpellInfo(learnedSpell)) << ", ";
|
||||
}
|
||||
|
||||
learned = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!learned)
|
||||
{
|
||||
if (!bot->HasSpell(spellId))
|
||||
{
|
||||
bot->learnSpell(spellId);
|
||||
*out << FormatSpell(proto) << ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AutoMaintenanceOnLevelupAction::AutoUpgradeEquip()
|
||||
{
|
||||
if (!sPlayerbotAIConfig->autoUpgradeEquip || !sRandomPlayerbotMgr->IsRandomBot(bot))
|
||||
{
|
||||
return;
|
||||
}
|
||||
PlayerbotFactory factory(bot, bot->GetLevel());
|
||||
if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel)
|
||||
{
|
||||
factory.InitEquipment(true);
|
||||
}
|
||||
factory.InitAmmo();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,26 @@
|
||||
|
||||
class PlayerbotAI;
|
||||
|
||||
class AutoTeleportForLevelAction : public Action
|
||||
class AutoMaintenanceOnLevelupAction : public Action
|
||||
{
|
||||
public:
|
||||
AutoTeleportForLevelAction(PlayerbotAI* botAI, std::string const name = "auto teleport for level")
|
||||
AutoMaintenanceOnLevelupAction(PlayerbotAI* botAI, std::string const name = "auto maintenance on levelup")
|
||||
: Action(botAI, name)
|
||||
{
|
||||
}
|
||||
|
||||
bool Execute(Event event);
|
||||
|
||||
protected:
|
||||
void AutoTeleportForLevel();
|
||||
void AutoPickTalents();
|
||||
void AutoLearnSpell();
|
||||
void AutoUpgradeEquip();
|
||||
void LearnSpells(std::ostringstream* out);
|
||||
void LearnTrainerSpells(std::ostringstream* out);
|
||||
void LearnQuestSpells(std::ostringstream* out);
|
||||
void LearnSpell(uint32 spellId, std::ostringstream* out);
|
||||
std::string const FormatSpell(SpellInfo const* sInfo);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -49,14 +49,10 @@ void WorldPacketHandlerStrategy::InitTriggers(std::vector<TriggerNode*>& trigger
|
||||
//triggers.push_back(new TriggerNode("no non bot players around", NextAction::array(0, new NextAction("delay", relevance), nullptr)));
|
||||
triggers.push_back(new TriggerNode("bg status", NextAction::array(0, new NextAction("bg status", relevance), nullptr)));
|
||||
triggers.push_back(new TriggerNode("xpgain", NextAction::array(0, new NextAction("xp gain", relevance), nullptr)));
|
||||
triggers.push_back(new TriggerNode("levelup", NextAction::array(0,
|
||||
new NextAction("auto teleport for level", relevance + 3),
|
||||
new NextAction("auto talents", relevance + 2),
|
||||
new NextAction("auto learn spell", relevance + 1),
|
||||
new NextAction("auto upgrade equip", relevance),
|
||||
nullptr)));
|
||||
// triggers.push_back(new TriggerNode("group destroyed", NextAction::array(0, new NextAction("reset botAI", relevance), nullptr)));
|
||||
|
||||
triggers.push_back(
|
||||
new TriggerNode("levelup", NextAction::array(0, new NextAction("auto maintenance on levelup", relevance + 3), nullptr)));
|
||||
// triggers.push_back(new TriggerNode("group destroyed", NextAction::array(0, new NextAction("reset botAI",
|
||||
// relevance), nullptr)));
|
||||
triggers.push_back(new TriggerNode("group list", NextAction::array(0, new NextAction("reset botAI", relevance), nullptr)));
|
||||
triggers.push_back(new TriggerNode("see spell", NextAction::array(0, new NextAction("see spell", relevance), nullptr)));
|
||||
triggers.push_back(new TriggerNode("release spirit", NextAction::array(0, new NextAction("release", relevance), nullptr)));
|
||||
|
||||
Reference in New Issue
Block a user