mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
- Fixed loading WorldPosition from string to fix RTSC points loading (#965)
- Restored loading from playerbots_db_store - Added deletion before saving to playerbots_db_store
This commit is contained in:
@@ -17,11 +17,6 @@ void PlayerbotDbStore::Load(PlayerbotAI* botAI)
|
||||
stmt->SetData(0, guid);
|
||||
if (PreparedQueryResult result = PlayerbotsDatabase.Query(stmt))
|
||||
{
|
||||
botAI->ClearStrategies(BOT_STATE_COMBAT);
|
||||
botAI->ClearStrategies(BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy("+chat", BOT_STATE_COMBAT);
|
||||
botAI->ChangeStrategy("+chat", BOT_STATE_NON_COMBAT);
|
||||
|
||||
std::vector<std::string> values;
|
||||
do
|
||||
{
|
||||
@@ -32,9 +27,17 @@ void PlayerbotDbStore::Load(PlayerbotAI* botAI)
|
||||
if (key == "value")
|
||||
values.push_back(value);
|
||||
else if (key == "co")
|
||||
{
|
||||
botAI->ClearStrategies(BOT_STATE_COMBAT);
|
||||
botAI->ChangeStrategy("+chat", BOT_STATE_COMBAT);
|
||||
botAI->ChangeStrategy(value, BOT_STATE_COMBAT);
|
||||
}
|
||||
else if (key == "nc")
|
||||
{
|
||||
botAI->ClearStrategies(BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy("+chat", BOT_STATE_NON_COMBAT);
|
||||
botAI->ChangeStrategy(value, BOT_STATE_NON_COMBAT);
|
||||
}
|
||||
else if (key == "dead")
|
||||
botAI->ChangeStrategy(value, BOT_STATE_DEAD);
|
||||
} while (result->NextRow());
|
||||
@@ -49,6 +52,11 @@ void PlayerbotDbStore::Save(PlayerbotAI* botAI)
|
||||
|
||||
Reset(botAI);
|
||||
|
||||
PlayerbotsDatabasePreparedStatement* deleteStatement =
|
||||
PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_DEL_DB_STORE);
|
||||
deleteStatement->SetData(0, guid);
|
||||
PlayerbotsDatabase.Execute(deleteStatement);
|
||||
|
||||
std::vector<std::string> data = botAI->GetAiObjectContext()->Save();
|
||||
for (std::vector<std::string>::iterator i = data.begin(); i != data.end(); ++i)
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "WorldSession.h"
|
||||
#include "ChannelMgr.h"
|
||||
#include "BroadcastHelper.h"
|
||||
#include "PlayerbotDbStore.h"
|
||||
|
||||
PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) {}
|
||||
class PlayerbotLoginQueryHolder : public LoginQueryHolder
|
||||
@@ -487,9 +488,9 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
|
||||
}
|
||||
else
|
||||
{
|
||||
// botAI->ResetStrategies(!sRandomPlayerbotMgr->IsRandomBot(bot));
|
||||
botAI->ResetStrategies();
|
||||
botAI->ResetStrategies(!sRandomPlayerbotMgr->IsRandomBot(bot));
|
||||
}
|
||||
sPlayerbotDbStore->Load(botAI);
|
||||
|
||||
if (master && !master->HasUnitState(UNIT_STATE_IN_FLIGHT))
|
||||
{
|
||||
|
||||
@@ -22,12 +22,15 @@
|
||||
|
||||
WorldPosition::WorldPosition(std::string const str)
|
||||
{
|
||||
std::stringstream out(str);
|
||||
out >> this->m_mapId;
|
||||
out >> this->m_positionX;
|
||||
out >> this->m_positionY;
|
||||
out >> this->m_positionZ;
|
||||
out >> this->m_orientation;
|
||||
std::vector<std::string> tokens = split(str, '|');
|
||||
if (tokens.size() == 5)
|
||||
{
|
||||
m_mapId = std::stoi(tokens[0]);
|
||||
m_positionX = std::stof(tokens[1]);
|
||||
m_positionY = std::stof(tokens[2]);
|
||||
m_positionZ = std::stof(tokens[3]);
|
||||
m_orientation = std::stof(tokens[4]);
|
||||
}
|
||||
}
|
||||
|
||||
WorldPosition::WorldPosition(uint32 mapId, const Position& pos)
|
||||
@@ -361,13 +364,25 @@ std::string const WorldPosition::print()
|
||||
std::string const WorldPosition::to_string()
|
||||
{
|
||||
std::stringstream out;
|
||||
out << GetMapId();
|
||||
out << GetPositionX();
|
||||
out << GetPositionY();
|
||||
out << GetPositionZ();
|
||||
out << GetOrientation();
|
||||
out << m_mapId << '|';
|
||||
out << m_positionX << '|';
|
||||
out << m_positionY << '|';
|
||||
out << m_positionZ << '|';
|
||||
out << m_orientation;
|
||||
return out.str();
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<std::string> WorldPosition::split(const std::string& s, char delimiter)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::string token;
|
||||
std::istringstream tokenStream(s);
|
||||
while (std::getline(tokenStream, token, delimiter))
|
||||
{
|
||||
tokens.push_back(token);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
void WorldPosition::printWKT(std::vector<WorldPosition> points, std::ostringstream& out, uint32 dim, bool loop)
|
||||
{
|
||||
|
||||
@@ -131,6 +131,7 @@ public:
|
||||
std::string const print();
|
||||
|
||||
std::string const to_string();
|
||||
std::vector<std::string> split(const std::string& s, char delimiter);
|
||||
|
||||
void printWKT(std::vector<WorldPosition> points, std::ostringstream& out, uint32 dim = 0, bool loop = false);
|
||||
void printWKT(std::ostringstream& out) { printWKT({*this}, out); }
|
||||
|
||||
Reference in New Issue
Block a user