[Command] Enable to cancel self command

This commit is contained in:
Yunfan Li
2024-07-19 13:43:18 +08:00
parent 3716de4c96
commit fce0f431e1
4 changed files with 39 additions and 26 deletions

View File

@@ -125,12 +125,12 @@ AiPlayerbot.BotAutologin = 0
# Default: 0 (disabled)
AiPlayerbot.AllowPlayerBots = 0
# Bots will be summoned to player when accept group invitation
AiPlayerbot.SummonWhenGroup = 1
# Allow/deny bots from your guild
AiPlayerbot.AllowGuildBots = 1
# Bots will be summoned to player when accept group invitation
AiPlayerbot.SummonWhenGroup = 1
# Added following config
# Selfbot permission level (0 = disabled, 1 = gm only (default), 2 = all players, 3 = activate on login)
AiPlayerbot.SelfBotLevel = 1
@@ -541,7 +541,7 @@ AiPlayerbot.EquipmentPersistence = 0
# default: 80
AiPlayerbot.EquipmentPersistenceLevel = 80
# Bot automatically upgrade equipments on levelup
# Randombots automatically upgrade equipments on levelup
# Default: 1 (enabled)
AiPlayerbot.AutoUpgradeEquip = 1
@@ -578,15 +578,15 @@ AiPlayerbot.RandomBotQuestItems = "6948,5175,5176,5177,5178,16309,12382,13704,11
#
#
# Bots automatically learn classquest reward spells on levelup
# Randombots automatically learn classquest reward spells on levelup
# Default: 0 (disabled)
AiPlayerbot.AutoLearnQuestSpells = 0
# Bots automatically learn trainable spells on levelup
# Randombots automatically learn trainable spells on levelup
# Default: 1 (enabled)
AiPlayerbot.AutoLearnTrainerSpells = 1
# Bot automatically picks talent points on levelup
# Randombots automatically picks talent points on levelup
# Default: 1 (enabled)
AiPlayerbot.AutoPickTalents = 1
@@ -635,7 +635,6 @@ AiPlayerbot.RandomBotTeleLowerLevel = 3
AiPlayerbot.RandomBotTeleHigherLevel = 1
# Bots automatically teleport to another place for leveling on levelup
# Only for random bots
# Default: 1 (enabled)
AiPlayerbot.AutoTeleportForLevel = 1

View File

@@ -191,7 +191,7 @@ PlayerbotAI::~PlayerbotAI()
delete aiObjectContext;
if (bot)
sPlayerbotsMgr->RemovePlayerBotData(bot->GetGUID());
sPlayerbotsMgr->RemovePlayerBotData(bot->GetGUID(), true);
}
void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)

View File

@@ -1214,7 +1214,7 @@ PlayerbotMgr::PlayerbotMgr(Player* const master) : PlayerbotHolder(), master(ma
PlayerbotMgr::~PlayerbotMgr()
{
if (master)
sPlayerbotsMgr->RemovePlayerBotData(master->GetGUID());
sPlayerbotsMgr->RemovePlayerBotData(master->GetGUID(), false);
}
void PlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/)
@@ -1427,31 +1427,44 @@ void PlayerbotsMgr::AddPlayerbotData(Player* player, bool isBotAI)
return;
}
// If the guid already exists in the map, remove it
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsMap.find(player->GetGUID());
if (itr != _playerbotsMap.end())
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsAIMap.find(player->GetGUID());
if (itr != _playerbotsAIMap.end())
{
_playerbotsMap.erase(itr);
_playerbotsAIMap.erase(itr);
}
itr = _playerbotsMgrMap.find(player->GetGUID());
if (itr != _playerbotsMgrMap.end())
{
_playerbotsMgrMap.erase(itr);
}
if (!isBotAI)
{
PlayerbotMgr* playerbotMgr = new PlayerbotMgr(player);
ASSERT(_playerbotsMap.emplace(player->GetGUID(), playerbotMgr).second);
ASSERT(_playerbotsAIMap.emplace(player->GetGUID(), playerbotMgr).second);
playerbotMgr->OnPlayerLogin(player);
}
else
{
PlayerbotAI* botAI = new PlayerbotAI(player);
ASSERT(_playerbotsMap.emplace(player->GetGUID(), botAI).second);
ASSERT(_playerbotsMgrMap.emplace(player->GetGUID(), botAI).second);
}
}
void PlayerbotsMgr::RemovePlayerBotData(ObjectGuid const& guid)
void PlayerbotsMgr::RemovePlayerBotData(ObjectGuid const& guid, bool is_AI)
{
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsMap.find(guid);
if (itr != _playerbotsMap.end())
{
_playerbotsMap.erase(itr);
if (is_AI) {
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsAIMap.find(guid);
if (itr != _playerbotsAIMap.end())
{
_playerbotsAIMap.erase(itr);
}
} else {
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsMgrMap.find(guid);
if (itr != _playerbotsMgrMap.end())
{
_playerbotsMgrMap.erase(itr);
}
}
}
@@ -1464,8 +1477,8 @@ PlayerbotAI* PlayerbotsMgr::GetPlayerbotAI(Player* player)
// if (player->GetSession()->isLogingOut() || player->IsDuringRemoveFromWorld()) {
// return nullptr;
// }
auto itr = _playerbotsMap.find(player->GetGUID());
if (itr != _playerbotsMap.end())
auto itr = _playerbotsAIMap.find(player->GetGUID());
if (itr != _playerbotsAIMap.end())
{
if (itr->second->IsBotAI())
return reinterpret_cast<PlayerbotAI*>(itr->second);
@@ -1480,8 +1493,8 @@ PlayerbotMgr* PlayerbotsMgr::GetPlayerbotMgr(Player* player)
{
return nullptr;
}
auto itr = _playerbotsMap.find(player->GetGUID());
if (itr != _playerbotsMap.end())
auto itr = _playerbotsMgrMap.find(player->GetGUID());
if (itr != _playerbotsMgrMap.end())
{
if (!itr->second->IsBotAI())
return reinterpret_cast<PlayerbotMgr*>(itr->second);

View File

@@ -99,13 +99,14 @@ class PlayerbotsMgr
}
void AddPlayerbotData(Player* player, bool isBotAI);
void RemovePlayerBotData(ObjectGuid const& guid);
void RemovePlayerBotData(ObjectGuid const& guid, bool is_AI);
PlayerbotAI* GetPlayerbotAI(Player* player);
PlayerbotMgr* GetPlayerbotMgr(Player* player);
private:
std::unordered_map<ObjectGuid, PlayerbotAIBase*> _playerbotsMap;
std::unordered_map<ObjectGuid, PlayerbotAIBase*> _playerbotsAIMap;
std::unordered_map<ObjectGuid, PlayerbotAIBase*> _playerbotsMgrMap;
};
#define sPlayerbotsMgr PlayerbotsMgr::instance()