diff --git a/src/PlayerbotDbStore.cpp b/src/PlayerbotDbStore.cpp index c644eb4e..42331ffe 100644 --- a/src/PlayerbotDbStore.cpp +++ b/src/PlayerbotDbStore.cpp @@ -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 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 data = botAI->GetAiObjectContext()->Save(); for (std::vector::iterator i = data.begin(); i != data.end(); ++i) { diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 4d9aa06f..5f0b521c 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -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)) { diff --git a/src/TravelMgr.cpp b/src/TravelMgr.cpp index 301802b6..68a54fa5 100644 --- a/src/TravelMgr.cpp +++ b/src/TravelMgr.cpp @@ -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 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 WorldPosition::split(const std::string& s, char delimiter) +{ + std::vector 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 points, std::ostringstream& out, uint32 dim, bool loop) { diff --git a/src/TravelMgr.h b/src/TravelMgr.h index af7d0717..46d76665 100644 --- a/src/TravelMgr.h +++ b/src/TravelMgr.h @@ -131,6 +131,7 @@ public: std::string const print(); std::string const to_string(); + std::vector split(const std::string& s, char delimiter); void printWKT(std::vector points, std::ostringstream& out, uint32 dim = 0, bool loop = false); void printWKT(std::ostringstream& out) { printWKT({*this}, out); }