mirror of
https://github.com/Squareville/wonderland-server.git
synced 2025-12-16 20:34:54 -06:00
Merge branch 'DarkflameUniverse:main' into main
This commit is contained in:
@@ -114,7 +114,6 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitS
|
||||
context->FilterTargets(validTargets, this->m_ignoreFactionList, this->m_includeFactionList, this->m_targetSelf, this->m_targetEnemy, this->m_targetFriend, this->m_targetTeam);
|
||||
|
||||
for (auto validTarget : validTargets) {
|
||||
if (targets.size() >= this->m_maxTargets) break;
|
||||
if (std::find(targets.begin(), targets.end(), validTarget) != targets.end()) continue;
|
||||
if (validTarget->GetIsDead()) continue;
|
||||
|
||||
@@ -147,13 +146,28 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitS
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(targets.begin(), targets.end(), [reference](Entity* a, Entity* b) {
|
||||
std::sort(targets.begin(), targets.end(), [this, reference, combatAi](Entity* a, Entity* b) {
|
||||
const auto aDistance = Vector3::DistanceSquared(reference, a->GetPosition());
|
||||
const auto bDistance = Vector3::DistanceSquared(reference, b->GetPosition());
|
||||
|
||||
return aDistance > bDistance;
|
||||
return aDistance < bDistance;
|
||||
});
|
||||
|
||||
|
||||
if (m_useAttackPriority) {
|
||||
// this should be using the attack priority column on the destroyable component
|
||||
// We want targets with no threat level to remain the same order as above
|
||||
// std::stable_sort(targets.begin(), targets.end(), [combatAi](Entity* a, Entity* b) {
|
||||
// const auto aThreat = combatAi->GetThreat(a->GetObjectID());
|
||||
// const auto bThreat = combatAi->GetThreat(b->GetObjectID());
|
||||
|
||||
// If enabled for this behavior, prioritize threat over distance
|
||||
// return aThreat > bThreat;
|
||||
// });
|
||||
}
|
||||
|
||||
// After we've sorted and found our closest targets, size the vector down in case there are too many
|
||||
if (m_maxTargets > 0 && targets.size() > m_maxTargets) targets.resize(m_maxTargets);
|
||||
const auto hit = !targets.empty();
|
||||
bitStream.Write(hit);
|
||||
|
||||
|
||||
@@ -27,8 +27,13 @@
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDPhysicsComponentTable.h"
|
||||
#include "dNavMesh.h"
|
||||
#include "Amf3.h"
|
||||
|
||||
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
||||
{
|
||||
using namespace GameMessages;
|
||||
RegisterMsg<GetObjectReportInfo>(this, &BaseCombatAIComponent::MsgGetObjectReportInfo);
|
||||
}
|
||||
m_Target = LWOOBJID_EMPTY;
|
||||
m_DirtyStateOrTarget = true;
|
||||
m_State = AiState::spawn;
|
||||
@@ -839,3 +844,73 @@ void BaseCombatAIComponent::IgnoreThreat(const LWOOBJID threat, const float valu
|
||||
SetThreat(threat, 0.0f);
|
||||
m_Target = LWOOBJID_EMPTY;
|
||||
}
|
||||
|
||||
bool BaseCombatAIComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
using enum AiState;
|
||||
auto& reportMsg = static_cast<GameMessages::GetObjectReportInfo&>(msg);
|
||||
auto& cmptType = reportMsg.info->PushDebug("Base Combat AI");
|
||||
cmptType.PushDebug<AMFIntValue>("Component ID") = GetComponentID();
|
||||
auto& targetInfo = cmptType.PushDebug("Current Target Info");
|
||||
targetInfo.PushDebug<AMFStringValue>("Current Target ID") = std::to_string(m_Target);
|
||||
// if (m_Target != LWOOBJID_EMPTY) {
|
||||
// LWOGameMessages::ObjGetName nameMsg(m_CurrentTarget);
|
||||
// SEND_GAMEOBJ_MSG(nameMsg);
|
||||
// if (!nameMsg.msg.name.empty()) targetInfo.PushDebug("Name") = nameMsg.msg.name;
|
||||
// }
|
||||
|
||||
auto& roundInfo = cmptType.PushDebug("Round Info");
|
||||
// roundInfo.PushDebug<AMFDoubleValue>("Combat Round Time") = m_CombatRoundLength;
|
||||
// roundInfo.PushDebug<AMFDoubleValue>("Minimum Time") = m_MinRoundLength;
|
||||
// roundInfo.PushDebug<AMFDoubleValue>("Maximum Time") = m_MaxRoundLength;
|
||||
// roundInfo.PushDebug<AMFDoubleValue>("Selected Time") = m_SelectedTime;
|
||||
// roundInfo.PushDebug<AMFDoubleValue>("Combat Start Delay") = m_CombatStartDelay;
|
||||
std::string curState;
|
||||
switch (m_State) {
|
||||
case idle: curState = "Idling"; break;
|
||||
case aggro: curState = "Aggroed"; break;
|
||||
case tether: curState = "Returning to Tether"; break;
|
||||
case spawn: curState = "Spawn"; break;
|
||||
case dead: curState = "Dead"; break;
|
||||
default: curState = "Unknown or Undefined"; break;
|
||||
}
|
||||
cmptType.PushDebug<AMFStringValue>("Current Combat State") = curState;
|
||||
|
||||
//switch (m_CombatBehaviorType) {
|
||||
// case 0: curState = "Passive"; break;
|
||||
// case 1: curState = "Aggressive"; break;
|
||||
// case 2: curState = "Passive (Turret)"; break;
|
||||
// case 3: curState = "Aggressive (Turret)"; break;
|
||||
// default: curState = "Unknown or Undefined"; break;
|
||||
//}
|
||||
//cmptType.PushDebug("Current Combat Behavior State") = curState;
|
||||
|
||||
//switch (m_CombatRole) {
|
||||
// case 0: curState = "Melee"; break;
|
||||
// case 1: curState = "Ranged"; break;
|
||||
// case 2: curState = "Support"; break;
|
||||
// default: curState = "Unknown or Undefined"; break;
|
||||
//}
|
||||
//cmptType.PushDebug("Current Combat Role") = curState;
|
||||
|
||||
auto& tetherPoint = cmptType.PushDebug("Tether Point");
|
||||
tetherPoint.PushDebug<AMFDoubleValue>("X") = m_StartPosition.x;
|
||||
tetherPoint.PushDebug<AMFDoubleValue>("Y") = m_StartPosition.y;
|
||||
tetherPoint.PushDebug<AMFDoubleValue>("Z") = m_StartPosition.z;
|
||||
cmptType.PushDebug<AMFDoubleValue>("Hard Tether Radius") = m_HardTetherRadius;
|
||||
cmptType.PushDebug<AMFDoubleValue>("Soft Tether Radius") = m_SoftTetherRadius;
|
||||
cmptType.PushDebug<AMFDoubleValue>("Aggro Radius") = m_AggroRadius;
|
||||
cmptType.PushDebug<AMFDoubleValue>("Tether Speed") = m_TetherSpeed;
|
||||
cmptType.PushDebug<AMFDoubleValue>("Aggro Speed") = m_TetherSpeed;
|
||||
// cmptType.PushDebug<AMFDoubleValue>("Specified Min Range") = m_SpecificMinRange;
|
||||
// cmptType.PushDebug<AMFDoubleValue>("Specified Max Range") = m_SpecificMaxRange;
|
||||
auto& threats = cmptType.PushDebug("Target Threats");
|
||||
for (const auto& [id, threat] : m_ThreatEntries) {
|
||||
threats.PushDebug<AMFDoubleValue>(std::to_string(id)) = threat;
|
||||
}
|
||||
|
||||
auto& ignoredThreats = cmptType.PushDebug("Temp Ignored Threats");
|
||||
for (const auto& [id, threat] : m_ThreatEntries) {
|
||||
ignoredThreats.PushDebug<AMFDoubleValue>(std::to_string(id) + " - Time") = threat;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -234,6 +234,8 @@ public:
|
||||
// Ignore a threat for a certain amount of time
|
||||
void IgnoreThreat(const LWOOBJID target, const float time);
|
||||
|
||||
bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Returns the current target or the target that currently is the largest threat to this entity
|
||||
|
||||
@@ -8,15 +8,33 @@
|
||||
#include "GameMessages.h"
|
||||
#include "BitStream.h"
|
||||
#include "eTriggerEventType.h"
|
||||
#include "Amf3.h"
|
||||
|
||||
BouncerComponent::BouncerComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
||||
m_PetEnabled = false;
|
||||
m_PetBouncerEnabled = false;
|
||||
m_PetSwitchLoaded = false;
|
||||
m_Destination = GeneralUtils::TryParse<NiPoint3>(
|
||||
GeneralUtils::SplitString(m_Parent->GetVarAsString(u"bouncer_destination"), '\x1f'))
|
||||
.value_or(NiPoint3Constant::ZERO);
|
||||
m_Speed = GeneralUtils::TryParse<float>(m_Parent->GetVarAsString(u"bouncer_speed")).value_or(-1.0f);
|
||||
m_UsesHighArc = GeneralUtils::TryParse<bool>(m_Parent->GetVarAsString(u"bouncer_uses_high_arc")).value_or(false);
|
||||
m_LockControls = GeneralUtils::TryParse<bool>(m_Parent->GetVarAsString(u"lock_controls")).value_or(false);
|
||||
m_IgnoreCollision = !GeneralUtils::TryParse<bool>(m_Parent->GetVarAsString(u"ignore_collision")).value_or(true);
|
||||
m_StickLanding = GeneralUtils::TryParse<bool>(m_Parent->GetVarAsString(u"stickLanding")).value_or(false);
|
||||
m_UsesGroupName = GeneralUtils::TryParse<bool>(m_Parent->GetVarAsString(u"uses_group_name")).value_or(false);
|
||||
m_GroupName = m_Parent->GetVarAsString(u"grp_name");
|
||||
m_MinNumTargets = GeneralUtils::TryParse<int32_t>(m_Parent->GetVarAsString(u"num_targets_to_activate")).value_or(1);
|
||||
m_CinematicPath = m_Parent->GetVarAsString(u"attached_cinematic_path");
|
||||
|
||||
if (parent->GetLOT() == 7625) {
|
||||
LookupPetSwitch();
|
||||
}
|
||||
|
||||
{
|
||||
using namespace GameMessages;
|
||||
RegisterMsg<GetObjectReportInfo>(this, &BouncerComponent::MsgGetObjectReportInfo);
|
||||
}
|
||||
}
|
||||
|
||||
BouncerComponent::~BouncerComponent() {
|
||||
@@ -94,3 +112,54 @@ void BouncerComponent::LookupPetSwitch() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool BouncerComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
auto& reportMsg = static_cast<GameMessages::GetObjectReportInfo&>(msg);
|
||||
auto& cmptType = reportMsg.info->PushDebug("Bouncer");
|
||||
cmptType.PushDebug<AMFIntValue>("Component ID") = GetComponentID();
|
||||
auto& destPos = cmptType.PushDebug("Destination Position");
|
||||
if (m_Destination != NiPoint3Constant::ZERO) {
|
||||
destPos.PushDebug(m_Destination);
|
||||
} else {
|
||||
destPos.PushDebug("<font color=\'#FF0000\'>WARNING:</font> Bouncer has no target position, is likely missing config data");
|
||||
}
|
||||
|
||||
|
||||
if (m_Speed == -1.0f) {
|
||||
cmptType.PushDebug("<font color=\'#FF0000\'>WARNING:</font> Bouncer has no speed value, is likely missing config data");
|
||||
} else {
|
||||
cmptType.PushDebug<AMFDoubleValue>("Bounce Speed") = m_Speed;
|
||||
}
|
||||
cmptType.PushDebug<AMFStringValue>("Bounce trajectory arc") = m_UsesHighArc ? "High Arc" : "Low Arc";
|
||||
cmptType.PushDebug<AMFBoolValue>("Collision Enabled") = m_IgnoreCollision;
|
||||
cmptType.PushDebug<AMFBoolValue>("Stick Landing") = m_StickLanding;
|
||||
cmptType.PushDebug<AMFBoolValue>("Locks character's controls") = m_LockControls;
|
||||
if (!m_CinematicPath.empty()) cmptType.PushDebug<AMFStringValue>("Cinematic Camera Path (plays during bounce)") = m_CinematicPath;
|
||||
|
||||
auto* switchComponent = m_Parent->GetComponent<SwitchComponent>();
|
||||
auto& respondsToFactions = cmptType.PushDebug("Responds to Factions");
|
||||
if (!switchComponent || switchComponent->GetFactionsToRespondTo().empty()) respondsToFactions.PushDebug("Faction 1");
|
||||
else {
|
||||
for (const auto faction : switchComponent->GetFactionsToRespondTo()) {
|
||||
respondsToFactions.PushDebug(("Faction " + std::to_string(faction)));
|
||||
}
|
||||
}
|
||||
|
||||
cmptType.PushDebug<AMFBoolValue>("Uses a group name for interactions") = m_UsesGroupName;
|
||||
if (!m_UsesGroupName) {
|
||||
if (m_MinNumTargets > 1) {
|
||||
cmptType.PushDebug("<font color=\'#FF0000\'>WARNING:</font> Bouncer has a required number of objects to activate, but no group for interactions.");
|
||||
}
|
||||
|
||||
if (!m_GroupName.empty()) {
|
||||
cmptType.PushDebug("<font color=\'#FF0000\'>WARNING:</font> Has a group name for interactions , but is marked to not use that name.");
|
||||
}
|
||||
} else {
|
||||
if (m_GroupName.empty()) {
|
||||
cmptType.PushDebug("<font color=\'#FF0000\'>WARNING:</font> Set to use a group name for inter actions, but no group name is assigned");
|
||||
}
|
||||
cmptType.PushDebug<AMFIntValue>("Number of interactions to activate bouncer") = m_MinNumTargets;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ public:
|
||||
*/
|
||||
void LookupPetSwitch();
|
||||
|
||||
bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Whether this bouncer needs to be activated by a pet
|
||||
@@ -66,6 +68,36 @@ private:
|
||||
* Whether the pet switch for this bouncer has been located
|
||||
*/
|
||||
bool m_PetSwitchLoaded;
|
||||
|
||||
// The bouncer destination
|
||||
NiPoint3 m_Destination;
|
||||
|
||||
// The speed at which the player is bounced
|
||||
float m_Speed{};
|
||||
|
||||
// Whether to use a high arc for the bounce trajectory
|
||||
bool m_UsesHighArc{};
|
||||
|
||||
// Lock controls when bouncing
|
||||
bool m_LockControls{};
|
||||
|
||||
// Ignore collision when bouncing
|
||||
bool m_IgnoreCollision{};
|
||||
|
||||
// Stick the landing afterwards or let the player slide
|
||||
bool m_StickLanding{};
|
||||
|
||||
// Whether or not there is a group name
|
||||
bool m_UsesGroupName{};
|
||||
|
||||
// The group name for targets
|
||||
std::string m_GroupName{};
|
||||
|
||||
// The number of targets to activate the bouncer
|
||||
int32_t m_MinNumTargets{};
|
||||
|
||||
// The cinematic path to play during the bounce
|
||||
std::string m_CinematicPath{};
|
||||
};
|
||||
|
||||
#endif // BOUNCERCOMPONENT_H
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
#include "CollectibleComponent.h"
|
||||
|
||||
#include "MissionComponent.h"
|
||||
#include "dServer.h"
|
||||
#include "Amf3.h"
|
||||
|
||||
CollectibleComponent::CollectibleComponent(Entity* parentEntity, const int32_t componentID, const int32_t collectibleId) :
|
||||
Component(parentEntity, componentID), m_CollectibleId(collectibleId) {
|
||||
using namespace GameMessages;
|
||||
RegisterMsg<GetObjectReportInfo>(this, &CollectibleComponent::MsgGetObjectReportInfo);
|
||||
}
|
||||
|
||||
void CollectibleComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
|
||||
outBitStream.Write(GetCollectibleId());
|
||||
}
|
||||
|
||||
bool CollectibleComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
auto& reportMsg = static_cast<GameMessages::GetObjectReportInfo&>(msg);
|
||||
auto& cmptType = reportMsg.info->PushDebug("Collectible");
|
||||
auto collectibleID = static_cast<uint32_t>(m_CollectibleId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);
|
||||
|
||||
cmptType.PushDebug<AMFIntValue>("Component ID") = GetComponentID();
|
||||
|
||||
cmptType.PushDebug<AMFIntValue>("Collectible ID") = GetCollectibleId();
|
||||
cmptType.PushDebug<AMFIntValue>("Mission Tracking ID (for save data)") = collectibleID;
|
||||
|
||||
auto* localCharEntity = Game::entityManager->GetEntity(reportMsg.clientID);
|
||||
bool collected = false;
|
||||
if (localCharEntity) {
|
||||
auto* missionComponent = localCharEntity->GetComponent<MissionComponent>();
|
||||
|
||||
if (m_CollectibleId != 0) {
|
||||
collected = missionComponent->HasCollectible(collectibleID);
|
||||
}
|
||||
}
|
||||
|
||||
cmptType.PushDebug<AMFBoolValue>("Has been collected") = collected;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
class CollectibleComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::COLLECTIBLE;
|
||||
CollectibleComponent(Entity* parentEntity, const int32_t componentID, const int32_t collectibleId) : Component(parentEntity, componentID), m_CollectibleId(collectibleId) {}
|
||||
CollectibleComponent(Entity* parentEntity, const int32_t componentID, const int32_t collectibleId);
|
||||
|
||||
int16_t GetCollectibleId() const { return m_CollectibleId; }
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) override;
|
||||
|
||||
bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg);
|
||||
private:
|
||||
int16_t m_CollectibleId = 0;
|
||||
};
|
||||
|
||||
@@ -1122,8 +1122,8 @@ bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
stats.PushDebug<AMFIntValue>("Imagination") = m_iImagination;
|
||||
stats.PushDebug<AMFDoubleValue>("Maximum Imagination") = m_fMaxImagination;
|
||||
stats.PushDebug<AMFIntValue>("Damage Absorption Points") = m_DamageToAbsorb;
|
||||
destroyableInfo.PushDebug<AMFBoolValue>("Is GM Immune") = m_IsGMImmune;
|
||||
destroyableInfo.PushDebug<AMFBoolValue>("Is Shielded") = m_IsShielded;
|
||||
stats.PushDebug<AMFBoolValue>("Is GM Immune") = m_IsGMImmune;
|
||||
stats.PushDebug<AMFBoolValue>("Is Shielded") = m_IsShielded;
|
||||
destroyableInfo.PushDebug<AMFIntValue>("Attacks To Block") = m_AttacksToBlock;
|
||||
destroyableInfo.PushDebug<AMFIntValue>("Damage Reduction") = m_DamageReduction;
|
||||
std::stringstream factionsStream;
|
||||
@@ -1140,7 +1140,7 @@ bool DestroyableComponent::OnGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
|
||||
destroyableInfo.PushDebug<AMFStringValue>("Enemy Factions") = factionsStream.str();
|
||||
|
||||
destroyableInfo.PushDebug<AMFBoolValue>("Is Smashable") = m_IsSmashable;
|
||||
destroyableInfo.PushDebug<AMFBoolValue>("Is A Smashable") = m_IsSmashable;
|
||||
destroyableInfo.PushDebug<AMFBoolValue>("Is Smashed") = m_IsSmashed;
|
||||
destroyableInfo.PushDebug<AMFBoolValue>("Is Module Assembly") = m_IsModuleAssembly;
|
||||
destroyableInfo.PushDebug<AMFDoubleValue>("Explode Factor") = m_ExplodeFactor;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#include "GhostComponent.h"
|
||||
|
||||
#include "Amf3.h"
|
||||
#include "GameMessages.h"
|
||||
|
||||
GhostComponent::GhostComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
||||
m_GhostReferencePoint = NiPoint3Constant::ZERO;
|
||||
m_GhostOverridePoint = NiPoint3Constant::ZERO;
|
||||
m_GhostOverride = false;
|
||||
|
||||
RegisterMsg<GameMessages::GetObjectReportInfo>(this, &GhostComponent::MsgGetObjectReportInfo);
|
||||
}
|
||||
|
||||
GhostComponent::~GhostComponent() {
|
||||
@@ -55,3 +60,12 @@ bool GhostComponent::IsObserved(LWOOBJID id) {
|
||||
void GhostComponent::GhostEntity(LWOOBJID id) {
|
||||
m_ObservedEntities.erase(id);
|
||||
}
|
||||
|
||||
bool GhostComponent::MsgGetObjectReportInfo(GameMessages::GameMsg& msg) {
|
||||
auto& reportMsg = static_cast<GameMessages::GetObjectReportInfo&>(msg);
|
||||
auto& cmptType = reportMsg.info->PushDebug("Ghost");
|
||||
cmptType.PushDebug<AMFIntValue>("Component ID") = GetComponentID();
|
||||
cmptType.PushDebug<AMFBoolValue>("Is GM Invis") = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ public:
|
||||
|
||||
void GhostEntity(const LWOOBJID id);
|
||||
|
||||
bool MsgGetObjectReportInfo(GameMessages::GameMsg& msg);
|
||||
|
||||
private:
|
||||
NiPoint3 m_GhostReferencePoint;
|
||||
|
||||
|
||||
@@ -29,19 +29,22 @@ ModelComponent::ModelComponent(Entity* parent, const int32_t componentID) : Comp
|
||||
|
||||
bool ModelComponent::OnResetModelToDefaults(GameMessages::GameMsg& msg) {
|
||||
auto& reset = static_cast<GameMessages::ResetModelToDefaults&>(msg);
|
||||
for (auto& behavior : m_Behaviors) behavior.HandleMsg(reset);
|
||||
GameMessages::UnSmash unsmash;
|
||||
unsmash.target = GetParent()->GetObjectID();
|
||||
unsmash.duration = 0.0f;
|
||||
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
if (reset.bResetBehaviors) for (auto& behavior : m_Behaviors) behavior.HandleMsg(reset);
|
||||
|
||||
m_Parent->SetPosition(m_OriginalPosition);
|
||||
m_Parent->SetRotation(m_OriginalRotation);
|
||||
if (reset.bUnSmash) {
|
||||
GameMessages::UnSmash unsmash;
|
||||
unsmash.target = GetParent()->GetObjectID();
|
||||
unsmash.duration = 0.0f;
|
||||
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
m_NumActiveUnSmash = 0;
|
||||
}
|
||||
|
||||
if (reset.bResetPos) m_Parent->SetPosition(m_OriginalPosition);
|
||||
if (reset.bResetRot) m_Parent->SetRotation(m_OriginalRotation);
|
||||
m_Parent->SetVelocity(NiPoint3Constant::ZERO);
|
||||
|
||||
m_Speed = 3.0f;
|
||||
m_NumListeningInteract = 0;
|
||||
m_NumActiveUnSmash = 0;
|
||||
|
||||
m_NumActiveAttack = 0;
|
||||
GameMessages::SetFaction set{};
|
||||
|
||||
@@ -67,6 +67,10 @@ public:
|
||||
*/
|
||||
static SwitchComponent* GetClosestSwitch(NiPoint3 position);
|
||||
|
||||
const std::vector<int32_t>& GetFactionsToRespondTo() const {
|
||||
return m_FactionsToRespondTo;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* A list of all pet switches.
|
||||
|
||||
@@ -848,6 +848,11 @@ namespace GameMessages {
|
||||
|
||||
struct ResetModelToDefaults : public GameMsg {
|
||||
ResetModelToDefaults() : GameMsg(MessageType::Game::RESET_MODEL_TO_DEFAULTS) {}
|
||||
|
||||
bool bResetPos{ true };
|
||||
bool bResetRot{ true };
|
||||
bool bUnSmash{ true };
|
||||
bool bResetBehaviors{ true };
|
||||
};
|
||||
|
||||
struct EmotePlayed : public GameMsg {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "ControlBehaviorMsgs.h"
|
||||
#include "tinyxml2.h"
|
||||
#include "ModelComponent.h"
|
||||
#include "StringifiedEnum.h"
|
||||
|
||||
#include <ranges>
|
||||
|
||||
@@ -178,13 +179,33 @@ void PropertyBehavior::Deserialize(const tinyxml2::XMLElement& behavior) {
|
||||
}
|
||||
|
||||
void PropertyBehavior::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
for (auto& state : m_States | std::views::values) state.Update(deltaTime, modelComponent);
|
||||
auto& activeState = GetActiveState();
|
||||
UpdateResult updateResult{};
|
||||
activeState.Update(deltaTime, modelComponent, updateResult);
|
||||
if (updateResult.newState.has_value() && updateResult.newState.value() != m_ActiveState) {
|
||||
LOG("Behavior %llu is changing from state %s to %s", StringifiedEnum::ToString(m_ActiveState).data(), StringifiedEnum::ToString(updateResult.newState.value()).data());
|
||||
GameMessages::ResetModelToDefaults resetMsg{};
|
||||
resetMsg.bResetPos = false;
|
||||
resetMsg.bResetRot = false;
|
||||
resetMsg.bUnSmash = false;
|
||||
resetMsg.bResetBehaviors = false;
|
||||
modelComponent.OnResetModelToDefaults(resetMsg);
|
||||
HandleMsg(resetMsg);
|
||||
m_ActiveState = updateResult.newState.value();
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyBehavior::OnChatMessageReceived(const std::string& sMessage) {
|
||||
for (auto& state : m_States | std::views::values) state.OnChatMessageReceived(sMessage);
|
||||
auto& activeState = GetActiveState();
|
||||
activeState.OnChatMessageReceived(sMessage);
|
||||
}
|
||||
|
||||
void PropertyBehavior::OnHit() {
|
||||
for (auto& state : m_States | std::views::values) state.OnHit();
|
||||
auto& activeState = GetActiveState();
|
||||
activeState.OnHit();
|
||||
}
|
||||
|
||||
State& PropertyBehavior::GetActiveState() {
|
||||
DluAssert(m_States.contains(m_ActiveState));
|
||||
return m_States[m_ActiveState];
|
||||
}
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
#ifndef __PROPERTYBEHAVIOR__H__
|
||||
#define __PROPERTYBEHAVIOR__H__
|
||||
|
||||
#include "BehaviorStates.h"
|
||||
#include "State.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace tinyxml2 {
|
||||
class XMLElement;
|
||||
}
|
||||
|
||||
enum class BehaviorState : uint32_t;
|
||||
|
||||
class AMFArrayValue;
|
||||
class BehaviorMessageBase;
|
||||
class ModelComponent;
|
||||
|
||||
struct UpdateResult {
|
||||
std::optional<BehaviorState> newState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents the Entity of a Property Behavior and holds data associated with the behavior
|
||||
*/
|
||||
@@ -45,6 +50,7 @@ public:
|
||||
void OnHit();
|
||||
|
||||
private:
|
||||
State& GetActiveState();
|
||||
// The current active behavior state. Behaviors can only be in ONE state at a time.
|
||||
BehaviorState m_ActiveState;
|
||||
|
||||
|
||||
@@ -163,8 +163,8 @@ void State::Deserialize(const tinyxml2::XMLElement& state) {
|
||||
}
|
||||
}
|
||||
|
||||
void State::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
for (auto& strip : m_Strips) strip.Update(deltaTime, modelComponent);
|
||||
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) {
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace tinyxml2 {
|
||||
|
||||
class AMFArrayValue;
|
||||
class ModelComponent;
|
||||
struct UpdateResult;
|
||||
|
||||
class State {
|
||||
public:
|
||||
@@ -21,7 +22,7 @@ public:
|
||||
void Serialize(tinyxml2::XMLElement& state) const;
|
||||
void Deserialize(const tinyxml2::XMLElement& state);
|
||||
|
||||
void Update(float deltaTime, ModelComponent& modelComponent);
|
||||
void Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
|
||||
|
||||
void OnChatMessageReceived(const std::string& sMessage);
|
||||
void OnHit();
|
||||
|
||||
@@ -160,13 +160,14 @@ void Strip::SpawnDrop(LOT dropLOT, Entity& entity) {
|
||||
}
|
||||
}
|
||||
|
||||
void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
|
||||
void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
|
||||
auto& entity = *modelComponent.GetParent();
|
||||
auto& nextAction = GetNextAction();
|
||||
auto number = nextAction.GetValueParameterDouble();
|
||||
auto valueStr = nextAction.GetValueParameterString();
|
||||
auto numberAsInt = static_cast<int32_t>(number);
|
||||
auto nextActionType = GetNextAction().GetType();
|
||||
LOG_DEBUG("Processing Strip Action: %s with number %.2f and string %s", nextActionType.data(), number, valueStr.data());
|
||||
|
||||
// TODO replace with switch case and nextActionType with enum
|
||||
/* BEGIN Move */
|
||||
@@ -223,7 +224,8 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
|
||||
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
|
||||
modelComponent.AddUnSmash();
|
||||
|
||||
m_PausedTime = number;
|
||||
// since it may take time for the message to relay to clients
|
||||
m_PausedTime = number + 0.5f;
|
||||
} else if (nextActionType == "Wait") {
|
||||
m_PausedTime = number;
|
||||
} else if (nextActionType == "Chat") {
|
||||
@@ -258,6 +260,21 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
|
||||
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup
|
||||
}
|
||||
/* END Gameplay */
|
||||
/* BEGIN StateMachine */
|
||||
else if (nextActionType == "ChangeStateHome") {
|
||||
updateResult.newState = BehaviorState::HOME_STATE;
|
||||
} else if (nextActionType == "ChangeStateCircle") {
|
||||
updateResult.newState = BehaviorState::CIRCLE_STATE;
|
||||
} else if (nextActionType == "ChangeStateSquare") {
|
||||
updateResult.newState = BehaviorState::SQUARE_STATE;
|
||||
} else if (nextActionType == "ChangeStateDiamond") {
|
||||
updateResult.newState = BehaviorState::DIAMOND_STATE;
|
||||
} else if (nextActionType == "ChangeStateTriangle") {
|
||||
updateResult.newState = BehaviorState::TRIANGLE_STATE;
|
||||
} else if (nextActionType == "ChangeStateStar") {
|
||||
updateResult.newState = BehaviorState::STAR_STATE;
|
||||
}
|
||||
/* END StateMachine*/
|
||||
else {
|
||||
static std::set<std::string> g_WarnedActions;
|
||||
if (!g_WarnedActions.contains(nextActionType.data())) {
|
||||
@@ -330,7 +347,7 @@ bool Strip::CheckMovement(float deltaTime, ModelComponent& modelComponent) {
|
||||
return moveFinished;
|
||||
}
|
||||
|
||||
void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
|
||||
// No point in running a strip with only one action.
|
||||
// Strips are also designed to have 2 actions or more to run.
|
||||
if (!HasMinimumActions()) return;
|
||||
@@ -354,9 +371,9 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
|
||||
// Check for trigger blocks and if not a trigger block proc this blocks action
|
||||
if (m_NextActionIndex == 0) {
|
||||
LOG("Behavior strip started %s", nextAction.GetType().data());
|
||||
if (nextAction.GetType() == "OnInteract") {
|
||||
modelComponent.AddInteract();
|
||||
|
||||
} else if (nextAction.GetType() == "OnChat") {
|
||||
// logic here if needed
|
||||
} else if (nextAction.GetType() == "OnAttack") {
|
||||
@@ -365,7 +382,7 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
m_WaitingForAction = true;
|
||||
} else { // should be a normal block
|
||||
ProcNormalAction(deltaTime, modelComponent);
|
||||
ProcNormalAction(deltaTime, modelComponent, updateResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace tinyxml2 {
|
||||
|
||||
class AMFArrayValue;
|
||||
class ModelComponent;
|
||||
struct UpdateResult;
|
||||
|
||||
class Strip {
|
||||
public:
|
||||
@@ -33,9 +34,9 @@ public:
|
||||
// Checks the movement logic for whether or not to proceed
|
||||
// Returns true if the movement can continue, false if it needs to wait more.
|
||||
bool CheckMovement(float deltaTime, ModelComponent& modelComponent);
|
||||
void Update(float deltaTime, ModelComponent& modelComponent);
|
||||
void Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
|
||||
void SpawnDrop(LOT dropLOT, Entity& entity);
|
||||
void ProcNormalAction(float deltaTime, ModelComponent& modelComponent);
|
||||
void ProcNormalAction(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult);
|
||||
void RemoveStates(ModelComponent& modelComponent) const;
|
||||
|
||||
// 2 actions are required for strips to work
|
||||
|
||||
@@ -365,6 +365,7 @@ void DropLoot(Entity* player, const LWOOBJID source, const std::map<LOT, LootDro
|
||||
lootMsg.spawnPos = spawnPosition;
|
||||
lootMsg.sourceID = source;
|
||||
lootMsg.item = LOT_NULL;
|
||||
CalcFinalDropPos(lootMsg);
|
||||
lootMsg.Send();
|
||||
const auto* const memberEntity = Game::entityManager->GetEntity(member);
|
||||
if (memberEntity) lootMsg.Send(memberEntity->GetSystemAddress());
|
||||
@@ -377,6 +378,7 @@ void DropLoot(Entity* player, const LWOOBJID source, const std::map<LOT, LootDro
|
||||
lootMsg.spawnPos = spawnPosition;
|
||||
lootMsg.sourceID = source;
|
||||
lootMsg.item = LOT_NULL;
|
||||
CalcFinalDropPos(lootMsg);
|
||||
lootMsg.Send();
|
||||
lootMsg.Send(player->GetSystemAddress());
|
||||
}
|
||||
|
||||
@@ -1053,7 +1053,7 @@ void SlashCommandHandler::Startup() {
|
||||
.info = "Resurrects the player",
|
||||
.aliases = { "resurrect" },
|
||||
.handle = GMZeroCommands::Resurrect,
|
||||
.requiredLevel = eGameMasterLevel::CIVILIAN
|
||||
.requiredLevel = eGameMasterLevel::DEVELOPER
|
||||
};
|
||||
RegisterCommand(ResurrectCommand);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user