mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-14 15:57:13 +00:00
Main's model behaviors (every rotation, DoDamage, OnTimer, OnStartup, MoveBackToStart, moves along the model's local axes), raw terrain reading with scene lookups and scene tools, property model and brick by brick fixes and the chat server's player count fix, merged onto this branch's structures: - game messages stay structs; the angular velocity messages join them and the handler sets a message's target - strips own their speed again and the block names, moves and rotations stay in the shared action table (PropertyBehaviorActions, which the dashboard's behavior player reads; it now lists rotations too) - the zone keeps reading its file through ZoneFile and takes the boundaries from it, then loads the raw terrain as main does; the old dNavigation terrain reader is gone - the show all response stays a struct and logs a player count mismatch as main does - the property management component tells models who sent a chat message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
178 lines
4.8 KiB
C++
178 lines
4.8 KiB
C++
#include "State.h"
|
|
|
|
#include "Amf3.h"
|
|
#include "ControlBehaviorMsgs.h"
|
|
#include "tinyxml2.h"
|
|
#include "ObjectMessages.h"
|
|
|
|
template <>
|
|
void State::HandleMsg(AddStripMessage& msg) {
|
|
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
|
|
m_Strips.resize(msg.GetActionContext().GetStripId() + 1);
|
|
}
|
|
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(AddActionMessage& msg) {
|
|
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(UpdateStripUiMessage& msg) {
|
|
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(RemoveActionsMessage& msg) {
|
|
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(RearrangeStripMessage& msg) {
|
|
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(UpdateActionMessage& msg) {
|
|
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(RemoveStripMessage& msg) {
|
|
if (m_Strips.size() <= msg.GetActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetActionContext().GetStripId()).HandleMsg(msg);
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(SplitStripMessage& msg) {
|
|
if (msg.GetTransferredActions().empty()) {
|
|
if (m_Strips.size() <= msg.GetSourceActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetSourceActionContext().GetStripId()).HandleMsg(msg);
|
|
} else {
|
|
if (m_Strips.size() <= msg.GetDestinationActionContext().GetStripId()) {
|
|
m_Strips.resize(msg.GetDestinationActionContext().GetStripId() + 1);
|
|
}
|
|
|
|
m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg);
|
|
}
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(MergeStripsMessage& msg) {
|
|
if (msg.GetMigratedActions().empty()) {
|
|
if (m_Strips.size() <= msg.GetSourceActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetSourceActionContext().GetStripId()).HandleMsg(msg);
|
|
} else {
|
|
if (m_Strips.size() <= msg.GetDestinationActionContext().GetStripId()) {
|
|
m_Strips.resize(msg.GetDestinationActionContext().GetStripId() + 1);
|
|
}
|
|
|
|
m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg);
|
|
}
|
|
};
|
|
|
|
template <>
|
|
void State::HandleMsg(MigrateActionsMessage& msg) {
|
|
if (msg.GetMigratedActions().empty()) {
|
|
if (m_Strips.size() <= msg.GetSourceActionContext().GetStripId()) {
|
|
return;
|
|
}
|
|
|
|
m_Strips.at(msg.GetSourceActionContext().GetStripId()).HandleMsg(msg);
|
|
} else {
|
|
if (m_Strips.size() <= msg.GetDestinationActionContext().GetStripId()) {
|
|
m_Strips.resize(msg.GetDestinationActionContext().GetStripId() + 1);
|
|
}
|
|
|
|
m_Strips.at(msg.GetDestinationActionContext().GetStripId()).HandleMsg(msg);
|
|
}
|
|
};
|
|
|
|
template<>
|
|
void State::HandleMsg(GameMessages::RequestUse& msg) {
|
|
for (auto& strip : m_Strips) strip.HandleMsg(msg);
|
|
}
|
|
|
|
template<>
|
|
void State::HandleMsg(GameMessages::ResetModelToDefaults& msg) {
|
|
for (auto& strip : m_Strips) strip.HandleMsg(msg);
|
|
}
|
|
|
|
bool State::IsEmpty() const {
|
|
for (const auto& strip : m_Strips) {
|
|
if (!strip.IsEmpty()) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void State::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
|
|
auto* const strips = args.InsertArray("strips");
|
|
for (size_t stripId = 0; stripId < m_Strips.size(); ++stripId) {
|
|
const auto& strip = m_Strips.at(stripId);
|
|
if (strip.IsEmpty()) continue;
|
|
|
|
auto* const stripArgs = strips->PushArray();
|
|
stripArgs->Insert("id", static_cast<double>(stripId));
|
|
|
|
strip.SendBehaviorBlocksToClient(*stripArgs);
|
|
}
|
|
}
|
|
|
|
void State::Serialize(tinyxml2::XMLElement& state) const {
|
|
for (const auto& strip : m_Strips) {
|
|
if (strip.IsEmpty()) continue;
|
|
|
|
auto* const stripElement = state.InsertNewChildElement("Strip");
|
|
strip.Serialize(*stripElement);
|
|
}
|
|
}
|
|
|
|
void State::Deserialize(const tinyxml2::XMLElement& state) {
|
|
for (const auto* stripElement = state.FirstChildElement("Strip"); stripElement; stripElement = stripElement->NextSiblingElement("Strip")) {
|
|
auto& strip = m_Strips.emplace_back();
|
|
strip.Deserialize(*stripElement);
|
|
}
|
|
}
|
|
|
|
void State::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
|
|
for (auto& strip : m_Strips) strip.Update(deltaTime, modelComponent, updateResult);
|
|
}
|
|
|
|
void State::OnChatMessageReceived(const std::string& sMessage, const LWOOBJID sender) {
|
|
for (auto& strip : m_Strips) strip.OnChatMessageReceived(sMessage, sender);
|
|
}
|
|
|
|
void State::OnHit(const LWOOBJID attacker) {
|
|
for (auto& strip : m_Strips) strip.OnHit(attacker);
|
|
}
|