2022-08-06 03:01:59 +00:00
|
|
|
#include "SwitchMultipleBehavior.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "BehaviorBranchContext.h"
|
|
|
|
#include "CDActivitiesTable.h"
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void SwitchMultipleBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2022-12-16 21:23:02 +00:00
|
|
|
float value{};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
if (!bitStream.Read(value)) {
|
|
|
|
LOG("Unable to read value from bitStream, aborting Handle! %i", bitStream.GetNumberOfUnreadBits());
|
2022-12-18 14:49:13 +00:00
|
|
|
return;
|
2022-12-16 21:23:02 +00:00
|
|
|
};
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
uint32_t trigger = 0;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < this->m_behaviors.size(); i++) {
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const double data = this->m_behaviors.at(i).first;
|
2023-04-03 11:11:02 +00:00
|
|
|
trigger = i;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-04-03 11:11:02 +00:00
|
|
|
if (value <= data) break;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* behavior = this->m_behaviors.at(trigger).second;
|
|
|
|
|
2022-12-16 21:23:02 +00:00
|
|
|
behavior->Handle(context, bitStream, branch);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-27 07:25:44 +00:00
|
|
|
void SwitchMultipleBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) {
|
2021-12-05 17:54:36 +00:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2022-01-07 02:12:47 +00:00
|
|
|
void SwitchMultipleBehavior::Load() {
|
2022-01-13 03:48:27 +00:00
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt(
|
2022-01-07 02:12:47 +00:00
|
|
|
"SELECT replace(bP1.parameterID, 'behavior ', '') as key, bP1.value as behavior, "
|
2022-01-13 03:48:27 +00:00
|
|
|
"(select bP2.value FROM BehaviorParameter bP2 WHERE bP2.behaviorID = ?1 AND bP2.parameterID LIKE 'value %' "
|
2022-01-07 02:12:47 +00:00
|
|
|
"AND replace(bP1.parameterID, 'behavior ', '') = replace(bP2.parameterID, 'value ', '')) as value "
|
2022-01-13 03:48:27 +00:00
|
|
|
"FROM BehaviorParameter bP1 WHERE bP1.behaviorID = ?1 AND bP1.parameterID LIKE 'behavior %';");
|
2023-12-28 04:18:20 +00:00
|
|
|
query.bind(1, static_cast<int>(this->m_behaviorId));
|
2022-01-13 03:48:27 +00:00
|
|
|
|
|
|
|
auto result = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
while (!result.eof()) {
|
|
|
|
const auto behavior_id = static_cast<uint32_t>(result.getFloatField(1));
|
|
|
|
|
|
|
|
auto* behavior = CreateBehavior(behavior_id);
|
|
|
|
|
|
|
|
auto value = result.getFloatField(2);
|
|
|
|
|
|
|
|
this->m_behaviors.emplace_back(value, behavior);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
result.nextRow();
|
|
|
|
}
|
|
|
|
}
|