mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-09 20:24:16 +00:00
most of gameplay tab works
This commit is contained in:
@@ -4,9 +4,13 @@
|
||||
#include "BehaviorStates.h"
|
||||
#include "ControlBehaviorMsgs.h"
|
||||
#include "tinyxml2.h"
|
||||
#include "ModelComponent.h"
|
||||
|
||||
#include <ranges>
|
||||
|
||||
PropertyBehavior::PropertyBehavior() {
|
||||
m_LastEditedState = BehaviorState::HOME_STATE;
|
||||
m_ActiveState = BehaviorState::HOME_STATE;
|
||||
}
|
||||
|
||||
template<>
|
||||
@@ -84,6 +88,11 @@ void PropertyBehavior::HandleMsg(AddMessage& msg) {
|
||||
isLoot = m_BehaviorId != 7965;
|
||||
};
|
||||
|
||||
template<>
|
||||
void PropertyBehavior::HandleMsg(GameMessages::RequestUse& msg) {
|
||||
m_States[m_ActiveState].HandleMsg(msg);
|
||||
}
|
||||
|
||||
void PropertyBehavior::SendBehaviorListToClient(AMFArrayValue& args) const {
|
||||
args.Insert("id", std::to_string(m_BehaviorId));
|
||||
args.Insert("name", m_Name);
|
||||
@@ -153,3 +162,12 @@ void PropertyBehavior::Deserialize(const tinyxml2::XMLElement& behavior) {
|
||||
m_States[static_cast<BehaviorState>(stateId)].Deserialize(*stateElement);
|
||||
}
|
||||
}
|
||||
|
||||
const State& PropertyBehavior::GetState(const BehaviorState state) {
|
||||
DluAssert(state >= BehaviorState::HOME_STATE && state <= BehaviorState::STAR_STATE);
|
||||
return m_States[state];
|
||||
}
|
||||
|
||||
void PropertyBehavior::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
for (auto& state : m_States | std::views::values) state.Update(deltaTime, modelComponent);
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ namespace tinyxml2 {
|
||||
enum class BehaviorState : uint32_t;
|
||||
|
||||
class AMFArrayValue;
|
||||
class ModelComponent;
|
||||
|
||||
/**
|
||||
* Represents the Entity of a Property Behavior and holds data associated with the behavior
|
||||
@@ -31,8 +32,17 @@ public:
|
||||
|
||||
void Serialize(tinyxml2::XMLElement& behavior) const;
|
||||
void Deserialize(const tinyxml2::XMLElement& behavior);
|
||||
|
||||
const std::map<BehaviorState, State>& GetStates() const { return m_States; }
|
||||
const State& GetState(const BehaviorState state);
|
||||
const State& GetActiveState() const { return m_States.at(m_ActiveState); }
|
||||
State& GetActiveStateMut() { return m_States.at(m_ActiveState); }
|
||||
|
||||
void Update(float deltaTime, ModelComponent& modelComponent);
|
||||
private:
|
||||
|
||||
BehaviorState m_ActiveState;
|
||||
|
||||
// The states this behavior has.
|
||||
std::map<BehaviorState, State> m_States;
|
||||
|
||||
|
@@ -117,6 +117,11 @@ void State::HandleMsg(MigrateActionsMessage& msg) {
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
void State::HandleMsg(GameMessages::RequestUse& msg) {
|
||||
for (auto& strip : m_Strips) strip.HandleMsg(msg);
|
||||
}
|
||||
|
||||
bool State::IsEmpty() const {
|
||||
for (const auto& strip : m_Strips) {
|
||||
if (!strip.IsEmpty()) return false;
|
||||
@@ -152,3 +157,7 @@ void State::Deserialize(const tinyxml2::XMLElement& state) {
|
||||
strip.Deserialize(*stripElement);
|
||||
}
|
||||
}
|
||||
|
||||
void State::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
for (auto& strip : m_Strips) strip.Update(deltaTime, modelComponent);
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ namespace tinyxml2 {
|
||||
}
|
||||
|
||||
class AMFArrayValue;
|
||||
class ModelComponent;
|
||||
|
||||
class State {
|
||||
public:
|
||||
@@ -19,6 +20,11 @@ public:
|
||||
|
||||
void Serialize(tinyxml2::XMLElement& state) const;
|
||||
void Deserialize(const tinyxml2::XMLElement& state);
|
||||
|
||||
const std::vector<Strip>& GetStrips() const { return m_Strips; }
|
||||
std::vector<Strip>& GetStripsMut() { return m_Strips; }
|
||||
|
||||
void Update(float deltaTime, ModelComponent& modelComponent);
|
||||
private:
|
||||
std::vector<Strip> m_Strips;
|
||||
};
|
||||
|
@@ -3,6 +3,9 @@
|
||||
#include "Amf3.h"
|
||||
#include "ControlBehaviorMsgs.h"
|
||||
#include "tinyxml2.h"
|
||||
#include "dEntity/EntityInfo.h"
|
||||
#include "ModelComponent.h"
|
||||
#include "PlayerManager.h"
|
||||
|
||||
template <>
|
||||
void Strip::HandleMsg(AddStripMessage& msg) {
|
||||
@@ -75,7 +78,54 @@ void Strip::HandleMsg(MigrateActionsMessage& msg) {
|
||||
} else {
|
||||
m_Actions.insert(m_Actions.begin() + msg.GetDstActionIndex(), msg.GetMigratedActions().begin(), msg.GetMigratedActions().end());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
void Strip::HandleMsg(GameMessages::RequestUse& msg) {
|
||||
if (m_Actions[m_NextActionIndex].GetType() == "OnInteract") IncrementAction();
|
||||
}
|
||||
|
||||
void Strip::IncrementAction() {
|
||||
if (m_Actions.empty()) return;
|
||||
m_NextActionIndex++;
|
||||
m_NextActionIndex %= m_Actions.size();
|
||||
}
|
||||
|
||||
void Strip::Spawn(LOT lot, Entity& entity) {
|
||||
EntityInfo info{};
|
||||
info.lot = lot; // Dark Ronin property
|
||||
info.pos = entity.GetPosition();
|
||||
info.rot = NiQuaternionConstant::IDENTITY;
|
||||
info.spawnerID = entity.GetObjectID();
|
||||
Game::entityManager->ConstructEntity(Game::entityManager->CreateEntity(info, nullptr, &entity));
|
||||
IncrementAction();
|
||||
}
|
||||
|
||||
// Spawns a specific drop for all
|
||||
void Strip::SpawnDrop(LOT dropLOT, Entity& entity) {
|
||||
for (auto* const player : PlayerManager::GetAllPlayers()) {
|
||||
GameMessages::SendDropClientLoot(player, entity.GetObjectID(), dropLOT, 0, entity.GetPosition());
|
||||
}
|
||||
IncrementAction();
|
||||
}
|
||||
|
||||
void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
auto& entity = *modelComponent.GetParent();
|
||||
auto number = static_cast<int32_t>(GetNextAction().GetValueParameterDouble());
|
||||
if (GetNextAction().GetType() == "SpawnStromling") {
|
||||
Spawn(10495, entity);
|
||||
} else if (GetNextAction().GetType() == "SpawnPirate") {
|
||||
Spawn(10497, entity);
|
||||
} else if (GetNextAction().GetType() == "SpawnRonin") {
|
||||
Spawn(10498, entity);
|
||||
} else if (GetNextAction().GetType() == "DropImagination") {
|
||||
for (; number > 0; number--) SpawnDrop(935, entity);
|
||||
} else if (GetNextAction().GetType() == "DropHealth") {
|
||||
for (; number > 0; number--) SpawnDrop(177, entity);
|
||||
} else if (GetNextAction().GetType() == "DropArmor") {
|
||||
for (; number > 0; number--) SpawnDrop(6431, entity);
|
||||
}
|
||||
}
|
||||
|
||||
void Strip::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
|
||||
m_Position.SendBehaviorBlocksToClient(args);
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include "Action.h"
|
||||
#include "StripUiPosition.h"
|
||||
|
||||
#include "DluAssert.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace tinyxml2 {
|
||||
@@ -11,6 +13,7 @@ namespace tinyxml2 {
|
||||
}
|
||||
|
||||
class AMFArrayValue;
|
||||
class ModelComponent;
|
||||
|
||||
class Strip {
|
||||
public:
|
||||
@@ -22,7 +25,16 @@ public:
|
||||
|
||||
void Serialize(tinyxml2::XMLElement& strip) const;
|
||||
void Deserialize(const tinyxml2::XMLElement& strip);
|
||||
|
||||
const std::vector<Action>& GetActions() const { return m_Actions; }
|
||||
const Action& GetNextAction() const { DluAssert(m_NextActionIndex < m_Actions.size()); return m_Actions[m_NextActionIndex]; }
|
||||
|
||||
void IncrementAction();
|
||||
void Spawn(LOT object, Entity& entity);
|
||||
void Update(float deltaTime, ModelComponent& modelComponent);
|
||||
void SpawnDrop(LOT dropLOT, Entity& entity);
|
||||
private:
|
||||
size_t m_NextActionIndex{ 0 };
|
||||
std::vector<Action> m_Actions;
|
||||
StripUiPosition m_Position;
|
||||
};
|
||||
|
Reference in New Issue
Block a user