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);
|
stmt->SetData(0, guid);
|
||||||
if (PreparedQueryResult result = PlayerbotsDatabase.Query(stmt))
|
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;
|
std::vector<std::string> values;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -32,9 +27,17 @@ void PlayerbotDbStore::Load(PlayerbotAI* botAI)
|
|||||||
if (key == "value")
|
if (key == "value")
|
||||||
values.push_back(value);
|
values.push_back(value);
|
||||||
else if (key == "co")
|
else if (key == "co")
|
||||||
|
{
|
||||||
|
botAI->ClearStrategies(BOT_STATE_COMBAT);
|
||||||
|
botAI->ChangeStrategy("+chat", BOT_STATE_COMBAT);
|
||||||
botAI->ChangeStrategy(value, BOT_STATE_COMBAT);
|
botAI->ChangeStrategy(value, BOT_STATE_COMBAT);
|
||||||
|
}
|
||||||
else if (key == "nc")
|
else if (key == "nc")
|
||||||
|
{
|
||||||
|
botAI->ClearStrategies(BOT_STATE_NON_COMBAT);
|
||||||
|
botAI->ChangeStrategy("+chat", BOT_STATE_NON_COMBAT);
|
||||||
botAI->ChangeStrategy(value, BOT_STATE_NON_COMBAT);
|
botAI->ChangeStrategy(value, BOT_STATE_NON_COMBAT);
|
||||||
|
}
|
||||||
else if (key == "dead")
|
else if (key == "dead")
|
||||||
botAI->ChangeStrategy(value, BOT_STATE_DEAD);
|
botAI->ChangeStrategy(value, BOT_STATE_DEAD);
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
@@ -49,6 +52,11 @@ void PlayerbotDbStore::Save(PlayerbotAI* botAI)
|
|||||||
|
|
||||||
Reset(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();
|
std::vector<std::string> data = botAI->GetAiObjectContext()->Save();
|
||||||
for (std::vector<std::string>::iterator i = data.begin(); i != data.end(); ++i)
|
for (std::vector<std::string>::iterator i = data.begin(); i != data.end(); ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "WorldSession.h"
|
#include "WorldSession.h"
|
||||||
#include "ChannelMgr.h"
|
#include "ChannelMgr.h"
|
||||||
#include "BroadcastHelper.h"
|
#include "BroadcastHelper.h"
|
||||||
|
#include "PlayerbotDbStore.h"
|
||||||
|
|
||||||
PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) {}
|
PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) {}
|
||||||
class PlayerbotLoginQueryHolder : public LoginQueryHolder
|
class PlayerbotLoginQueryHolder : public LoginQueryHolder
|
||||||
@@ -487,9 +488,9 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// botAI->ResetStrategies(!sRandomPlayerbotMgr->IsRandomBot(bot));
|
botAI->ResetStrategies(!sRandomPlayerbotMgr->IsRandomBot(bot));
|
||||||
botAI->ResetStrategies();
|
|
||||||
}
|
}
|
||||||
|
sPlayerbotDbStore->Load(botAI);
|
||||||
|
|
||||||
if (master && !master->HasUnitState(UNIT_STATE_IN_FLIGHT))
|
if (master && !master->HasUnitState(UNIT_STATE_IN_FLIGHT))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,12 +22,15 @@
|
|||||||
|
|
||||||
WorldPosition::WorldPosition(std::string const str)
|
WorldPosition::WorldPosition(std::string const str)
|
||||||
{
|
{
|
||||||
std::stringstream out(str);
|
std::vector<std::string> tokens = split(str, '|');
|
||||||
out >> this->m_mapId;
|
if (tokens.size() == 5)
|
||||||
out >> this->m_positionX;
|
{
|
||||||
out >> this->m_positionY;
|
m_mapId = std::stoi(tokens[0]);
|
||||||
out >> this->m_positionZ;
|
m_positionX = std::stof(tokens[1]);
|
||||||
out >> this->m_orientation;
|
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)
|
WorldPosition::WorldPosition(uint32 mapId, const Position& pos)
|
||||||
@@ -361,13 +364,25 @@ std::string const WorldPosition::print()
|
|||||||
std::string const WorldPosition::to_string()
|
std::string const WorldPosition::to_string()
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << GetMapId();
|
out << m_mapId << '|';
|
||||||
out << GetPositionX();
|
out << m_positionX << '|';
|
||||||
out << GetPositionY();
|
out << m_positionY << '|';
|
||||||
out << GetPositionZ();
|
out << m_positionZ << '|';
|
||||||
out << GetOrientation();
|
out << m_orientation;
|
||||||
return out.str();
|
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)
|
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 print();
|
||||||
|
|
||||||
std::string const to_string();
|
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::vector<WorldPosition> points, std::ostringstream& out, uint32 dim = 0, bool loop = false);
|
||||||
void printWKT(std::ostringstream& out) { printWKT({*this}, out); }
|
void printWKT(std::ostringstream& out) { printWKT({*this}, out); }
|
||||||
|
|||||||
Reference in New Issue
Block a user