mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-04-26 16:46:31 +00:00
most of gameplay tab works
This commit is contained in:
parent
c490d45fe0
commit
0278123a0c
@ -4,7 +4,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
# define DluAssert(expression) assert(expression)
|
# define DluAssert(expression) do { assert(expression) } while(0)
|
||||||
#else
|
#else
|
||||||
# define DluAssert(expression)
|
# define DluAssert(expression)
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,12 +10,26 @@
|
|||||||
#include "SimplePhysicsComponent.h"
|
#include "SimplePhysicsComponent.h"
|
||||||
|
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
|
#include "EntityInfo.h"
|
||||||
|
|
||||||
ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
|
ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
|
||||||
m_OriginalPosition = m_Parent->GetDefaultPosition();
|
m_OriginalPosition = m_Parent->GetDefaultPosition();
|
||||||
m_OriginalRotation = m_Parent->GetDefaultRotation();
|
m_OriginalRotation = m_Parent->GetDefaultRotation();
|
||||||
|
|
||||||
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
|
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
|
||||||
|
RegisterMsg(MessageType::Game::REQUEST_USE, this, &ModelComponent::OnRequestUse);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModelComponent::OnRequestUse(GameMessages::GameMsg& msg) {
|
||||||
|
auto& requestUse = static_cast<GameMessages::RequestUse&>(msg);
|
||||||
|
for (auto& behavior : m_Behaviors) behavior.HandleMsg(requestUse);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelComponent::Update(float deltaTime) {
|
||||||
|
for (auto& behavior : m_Behaviors) {
|
||||||
|
behavior.Update(deltaTime, *this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelComponent::LoadBehaviors() {
|
void ModelComponent::LoadBehaviors() {
|
||||||
@ -29,9 +43,9 @@ void ModelComponent::LoadBehaviors() {
|
|||||||
LOG_DEBUG("Loading behavior %d", behaviorId.value());
|
LOG_DEBUG("Loading behavior %d", behaviorId.value());
|
||||||
auto& inserted = m_Behaviors.emplace_back();
|
auto& inserted = m_Behaviors.emplace_back();
|
||||||
inserted.SetBehaviorId(*behaviorId);
|
inserted.SetBehaviorId(*behaviorId);
|
||||||
|
|
||||||
const auto behaviorStr = Database::Get()->GetBehavior(behaviorId.value());
|
const auto behaviorStr = Database::Get()->GetBehavior(behaviorId.value());
|
||||||
|
|
||||||
tinyxml2::XMLDocument behaviorXml;
|
tinyxml2::XMLDocument behaviorXml;
|
||||||
auto res = behaviorXml.Parse(behaviorStr.c_str(), behaviorStr.size());
|
auto res = behaviorXml.Parse(behaviorStr.c_str(), behaviorStr.size());
|
||||||
LOG_DEBUG("Behavior %i %d: %s", res, behaviorId.value(), behaviorStr.c_str());
|
LOG_DEBUG("Behavior %i %d: %s", res, behaviorId.value(), behaviorStr.c_str());
|
||||||
@ -56,14 +70,14 @@ void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialU
|
|||||||
|
|
||||||
//actual model component:
|
//actual model component:
|
||||||
outBitStream.Write1(); // Yes we are writing model info
|
outBitStream.Write1(); // Yes we are writing model info
|
||||||
outBitStream.Write0(); // Is pickable
|
outBitStream.Write1(); // Is pickable
|
||||||
outBitStream.Write<uint32_t>(2); // Physics type
|
outBitStream.Write<uint32_t>(2); // Physics type
|
||||||
outBitStream.Write(m_OriginalPosition); // Original position
|
outBitStream.Write(m_OriginalPosition); // Original position
|
||||||
outBitStream.Write(m_OriginalRotation); // Original rotation
|
outBitStream.Write(m_OriginalRotation); // Original rotation
|
||||||
|
|
||||||
outBitStream.Write1(); // We are writing behavior info
|
outBitStream.Write1(); // We are writing behavior info
|
||||||
outBitStream.Write<uint32_t>(0); // Number of behaviors
|
outBitStream.Write<uint32_t>(m_Behaviors.size()); // Number of behaviors
|
||||||
outBitStream.Write1(); // Is this model paused
|
outBitStream.Write0(); // Is this model paused
|
||||||
if (bIsInitialUpdate) outBitStream.Write0(); // We are not writing model editing info
|
if (bIsInitialUpdate) outBitStream.Write0(); // We are not writing model editing info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ public:
|
|||||||
ModelComponent(Entity* parent);
|
ModelComponent(Entity* parent);
|
||||||
|
|
||||||
void LoadBehaviors();
|
void LoadBehaviors();
|
||||||
|
void Update(float deltaTime) override;
|
||||||
|
|
||||||
|
bool OnRequestUse(GameMessages::GameMsg& msg);
|
||||||
|
|
||||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||||
|
|
||||||
@ -114,6 +117,8 @@ public:
|
|||||||
|
|
||||||
std::array<std::pair<int32_t, std::string>, 5> GetBehaviorsForSave() const;
|
std::array<std::pair<int32_t, std::string>, 5> GetBehaviorsForSave() const;
|
||||||
|
|
||||||
|
const std::vector<PropertyBehavior>& GetBehaviors() const { return m_Behaviors; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* The behaviors of the model
|
* The behaviors of the model
|
||||||
|
@ -45,6 +45,7 @@ namespace {
|
|||||||
using namespace GameMessages;
|
using namespace GameMessages;
|
||||||
using MessageCreator = std::function<std::unique_ptr<GameMessages::GameMsg>()>;
|
using MessageCreator = std::function<std::unique_ptr<GameMessages::GameMsg>()>;
|
||||||
std::map<MessageType::Game, MessageCreator> g_MessageHandlers = {
|
std::map<MessageType::Game, MessageCreator> g_MessageHandlers = {
|
||||||
|
{ REQUEST_USE, []() { return std::make_unique<RequestUse>(); }},
|
||||||
{ REQUEST_SERVER_OBJECT_INFO, []() { return std::make_unique<RequestServerObjectInfo>(); } },
|
{ REQUEST_SERVER_OBJECT_INFO, []() { return std::make_unique<RequestServerObjectInfo>(); } },
|
||||||
{ SHOOTING_GALLERY_FIRE, []() { return std::make_unique<ShootingGalleryFire>(); } },
|
{ SHOOTING_GALLERY_FIRE, []() { return std::make_unique<ShootingGalleryFire>(); } },
|
||||||
};
|
};
|
||||||
@ -118,11 +119,6 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MessageType::Game::REQUEST_USE: {
|
|
||||||
GameMessages::HandleRequestUse(inStream, entity, sysAddr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case MessageType::Game::SET_FLAG: {
|
case MessageType::Game::SET_FLAG: {
|
||||||
GameMessages::HandleSetFlag(inStream, entity);
|
GameMessages::HandleSetFlag(inStream, entity);
|
||||||
break;
|
break;
|
||||||
|
@ -4954,54 +4954,6 @@ void GameMessages::HandleQuickBuildCancel(RakNet::BitStream& inStream, Entity* e
|
|||||||
quickBuildComponent->CancelQuickBuild(Game::entityManager->GetEntity(userID), eQuickBuildFailReason::CANCELED_EARLY);
|
quickBuildComponent->CancelQuickBuild(Game::entityManager->GetEntity(userID), eQuickBuildFailReason::CANCELED_EARLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameMessages::HandleRequestUse(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) {
|
|
||||||
bool bIsMultiInteractUse = false;
|
|
||||||
unsigned int multiInteractID;
|
|
||||||
int multiInteractType;
|
|
||||||
bool secondary;
|
|
||||||
LWOOBJID objectID;
|
|
||||||
|
|
||||||
inStream.Read(bIsMultiInteractUse);
|
|
||||||
inStream.Read(multiInteractID);
|
|
||||||
inStream.Read(multiInteractType);
|
|
||||||
inStream.Read(objectID);
|
|
||||||
inStream.Read(secondary);
|
|
||||||
|
|
||||||
Entity* interactedObject = Game::entityManager->GetEntity(objectID);
|
|
||||||
|
|
||||||
if (interactedObject == nullptr) {
|
|
||||||
LOG("Object %llu tried to interact, but doesn't exist!", objectID);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (interactedObject->GetLOT() == 9524) {
|
|
||||||
entity->GetCharacter()->SetBuildMode(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bIsMultiInteractUse) {
|
|
||||||
if (multiInteractType == 0) {
|
|
||||||
auto* missionOfferComponent = static_cast<MissionOfferComponent*>(interactedObject->GetComponent(eReplicaComponentType::MISSION_OFFER));
|
|
||||||
|
|
||||||
if (missionOfferComponent != nullptr) {
|
|
||||||
missionOfferComponent->OfferMissions(entity, multiInteractID);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
interactedObject->OnUse(entity);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
interactedObject->OnUse(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Perform use task if possible:
|
|
||||||
auto missionComponent = static_cast<MissionComponent*>(entity->GetComponent(eReplicaComponentType::MISSION));
|
|
||||||
|
|
||||||
if (missionComponent == nullptr) return;
|
|
||||||
|
|
||||||
missionComponent->Progress(eMissionTaskType::TALK_TO_NPC, interactedObject->GetLOT(), interactedObject->GetObjectID());
|
|
||||||
missionComponent->Progress(eMissionTaskType::INTERACT, interactedObject->GetLOT(), interactedObject->GetObjectID());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameMessages::HandlePlayEmote(RakNet::BitStream& inStream, Entity* entity) {
|
void GameMessages::HandlePlayEmote(RakNet::BitStream& inStream, Entity* entity) {
|
||||||
int emoteID;
|
int emoteID;
|
||||||
LWOOBJID targetID;
|
LWOOBJID targetID;
|
||||||
@ -6443,4 +6395,51 @@ namespace GameMessages {
|
|||||||
auto* handlingEntity = Game::entityManager->GetEntity(targetForReport);
|
auto* handlingEntity = Game::entityManager->GetEntity(targetForReport);
|
||||||
if (handlingEntity) handlingEntity->HandleMsg(*this);
|
if (handlingEntity) handlingEntity->HandleMsg(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RequestUse::Deserialize(RakNet::BitStream& stream) {
|
||||||
|
if (!stream.Read(bIsMultiInteractUse)) return false;
|
||||||
|
if (!stream.Read(multiInteractID)) return false;
|
||||||
|
if (!stream.Read(multiInteractType)) return false;
|
||||||
|
if (!stream.Read(object)) return false;
|
||||||
|
if (!stream.Read(secondary)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RequestUse::Handle(Entity& entity, const SystemAddress& sysAddr) {
|
||||||
|
Entity* interactedObject = Game::entityManager->GetEntity(object);
|
||||||
|
|
||||||
|
if (interactedObject == nullptr) {
|
||||||
|
LOG("Object %llu tried to interact, but doesn't exist!", object);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interactedObject->GetLOT() == 9524) {
|
||||||
|
entity.GetCharacter()->SetBuildMode(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bIsMultiInteractUse) {
|
||||||
|
if (multiInteractType == 0) {
|
||||||
|
auto* missionOfferComponent = static_cast<MissionOfferComponent*>(interactedObject->GetComponent(eReplicaComponentType::MISSION_OFFER));
|
||||||
|
|
||||||
|
if (missionOfferComponent != nullptr) {
|
||||||
|
missionOfferComponent->OfferMissions(&entity, multiInteractID);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
interactedObject->OnUse(&entity);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
interactedObject->OnUse(&entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
interactedObject->HandleMsg(*this);
|
||||||
|
|
||||||
|
//Perform use task if possible:
|
||||||
|
auto missionComponent = entity.GetComponent<MissionComponent>();
|
||||||
|
|
||||||
|
if (!missionComponent) return;
|
||||||
|
|
||||||
|
missionComponent->Progress(eMissionTaskType::TALK_TO_NPC, interactedObject->GetLOT(), interactedObject->GetObjectID());
|
||||||
|
missionComponent->Progress(eMissionTaskType::INTERACT, interactedObject->GetLOT(), interactedObject->GetObjectID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,7 +631,6 @@ namespace GameMessages {
|
|||||||
void HandleFireEventServerSide(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
void HandleFireEventServerSide(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
||||||
void HandleRequestPlatformResync(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
void HandleRequestPlatformResync(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
||||||
void HandleQuickBuildCancel(RakNet::BitStream& inStream, Entity* entity);
|
void HandleQuickBuildCancel(RakNet::BitStream& inStream, Entity* entity);
|
||||||
void HandleRequestUse(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
|
||||||
void HandlePlayEmote(RakNet::BitStream& inStream, Entity* entity);
|
void HandlePlayEmote(RakNet::BitStream& inStream, Entity* entity);
|
||||||
void HandleModularBuildConvertModel(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
void HandleModularBuildConvertModel(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
||||||
void HandleSetFlag(RakNet::BitStream& inStream, Entity* entity);
|
void HandleSetFlag(RakNet::BitStream& inStream, Entity* entity);
|
||||||
@ -782,6 +781,26 @@ namespace GameMessages {
|
|||||||
bool Deserialize(RakNet::BitStream& bitStream) override;
|
bool Deserialize(RakNet::BitStream& bitStream) override;
|
||||||
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
|
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RequestUse : public GameMsg {
|
||||||
|
RequestUse() : GameMsg(MessageType::Game::REQUEST_USE) {}
|
||||||
|
|
||||||
|
bool Deserialize(RakNet::BitStream& stream) override;
|
||||||
|
void Handle(Entity& entity, const SystemAddress& sysAddr) override;
|
||||||
|
|
||||||
|
LWOOBJID object{};
|
||||||
|
|
||||||
|
bool secondary{ false };
|
||||||
|
|
||||||
|
// Set to true if this coming from a multi-interaction UI on the client.
|
||||||
|
bool bIsMultiInteractUse{};
|
||||||
|
|
||||||
|
// Used only for multi-interaction
|
||||||
|
unsigned int multiInteractID{};
|
||||||
|
|
||||||
|
// Used only for multi-interaction, is of the enum type InteractionType
|
||||||
|
int multiInteractType{};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GAMEMESSAGES_H
|
#endif // GAMEMESSAGES_H
|
||||||
|
@ -4,9 +4,13 @@
|
|||||||
#include "BehaviorStates.h"
|
#include "BehaviorStates.h"
|
||||||
#include "ControlBehaviorMsgs.h"
|
#include "ControlBehaviorMsgs.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
#include "ModelComponent.h"
|
||||||
|
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
PropertyBehavior::PropertyBehavior() {
|
PropertyBehavior::PropertyBehavior() {
|
||||||
m_LastEditedState = BehaviorState::HOME_STATE;
|
m_LastEditedState = BehaviorState::HOME_STATE;
|
||||||
|
m_ActiveState = BehaviorState::HOME_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
@ -84,6 +88,11 @@ void PropertyBehavior::HandleMsg(AddMessage& msg) {
|
|||||||
isLoot = m_BehaviorId != 7965;
|
isLoot = m_BehaviorId != 7965;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
void PropertyBehavior::HandleMsg(GameMessages::RequestUse& msg) {
|
||||||
|
m_States[m_ActiveState].HandleMsg(msg);
|
||||||
|
}
|
||||||
|
|
||||||
void PropertyBehavior::SendBehaviorListToClient(AMFArrayValue& args) const {
|
void PropertyBehavior::SendBehaviorListToClient(AMFArrayValue& args) const {
|
||||||
args.Insert("id", std::to_string(m_BehaviorId));
|
args.Insert("id", std::to_string(m_BehaviorId));
|
||||||
args.Insert("name", m_Name);
|
args.Insert("name", m_Name);
|
||||||
@ -153,3 +162,12 @@ void PropertyBehavior::Deserialize(const tinyxml2::XMLElement& behavior) {
|
|||||||
m_States[static_cast<BehaviorState>(stateId)].Deserialize(*stateElement);
|
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;
|
enum class BehaviorState : uint32_t;
|
||||||
|
|
||||||
class AMFArrayValue;
|
class AMFArrayValue;
|
||||||
|
class ModelComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the Entity of a Property Behavior and holds data associated with the behavior
|
* 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 Serialize(tinyxml2::XMLElement& behavior) const;
|
||||||
void Deserialize(const tinyxml2::XMLElement& behavior);
|
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:
|
private:
|
||||||
|
|
||||||
|
BehaviorState m_ActiveState;
|
||||||
|
|
||||||
// The states this behavior has.
|
// The states this behavior has.
|
||||||
std::map<BehaviorState, State> m_States;
|
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 {
|
bool State::IsEmpty() const {
|
||||||
for (const auto& strip : m_Strips) {
|
for (const auto& strip : m_Strips) {
|
||||||
if (!strip.IsEmpty()) return false;
|
if (!strip.IsEmpty()) return false;
|
||||||
@ -152,3 +157,7 @@ void State::Deserialize(const tinyxml2::XMLElement& state) {
|
|||||||
strip.Deserialize(*stripElement);
|
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 AMFArrayValue;
|
||||||
|
class ModelComponent;
|
||||||
|
|
||||||
class State {
|
class State {
|
||||||
public:
|
public:
|
||||||
@ -19,6 +20,11 @@ public:
|
|||||||
|
|
||||||
void Serialize(tinyxml2::XMLElement& state) const;
|
void Serialize(tinyxml2::XMLElement& state) const;
|
||||||
void Deserialize(const tinyxml2::XMLElement& state);
|
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:
|
private:
|
||||||
std::vector<Strip> m_Strips;
|
std::vector<Strip> m_Strips;
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
#include "Amf3.h"
|
#include "Amf3.h"
|
||||||
#include "ControlBehaviorMsgs.h"
|
#include "ControlBehaviorMsgs.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
|
#include "dEntity/EntityInfo.h"
|
||||||
|
#include "ModelComponent.h"
|
||||||
|
#include "PlayerManager.h"
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void Strip::HandleMsg(AddStripMessage& msg) {
|
void Strip::HandleMsg(AddStripMessage& msg) {
|
||||||
@ -75,7 +78,54 @@ void Strip::HandleMsg(MigrateActionsMessage& msg) {
|
|||||||
} else {
|
} else {
|
||||||
m_Actions.insert(m_Actions.begin() + msg.GetDstActionIndex(), msg.GetMigratedActions().begin(), msg.GetMigratedActions().end());
|
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 {
|
void Strip::SendBehaviorBlocksToClient(AMFArrayValue& args) const {
|
||||||
m_Position.SendBehaviorBlocksToClient(args);
|
m_Position.SendBehaviorBlocksToClient(args);
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "Action.h"
|
#include "Action.h"
|
||||||
#include "StripUiPosition.h"
|
#include "StripUiPosition.h"
|
||||||
|
|
||||||
|
#include "DluAssert.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace tinyxml2 {
|
namespace tinyxml2 {
|
||||||
@ -11,6 +13,7 @@ namespace tinyxml2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AMFArrayValue;
|
class AMFArrayValue;
|
||||||
|
class ModelComponent;
|
||||||
|
|
||||||
class Strip {
|
class Strip {
|
||||||
public:
|
public:
|
||||||
@ -22,7 +25,16 @@ public:
|
|||||||
|
|
||||||
void Serialize(tinyxml2::XMLElement& strip) const;
|
void Serialize(tinyxml2::XMLElement& strip) const;
|
||||||
void Deserialize(const tinyxml2::XMLElement& strip);
|
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:
|
private:
|
||||||
|
size_t m_NextActionIndex{ 0 };
|
||||||
std::vector<Action> m_Actions;
|
std::vector<Action> m_Actions;
|
||||||
StripUiPosition m_Position;
|
StripUiPosition m_Position;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user