Files
DarkflameServer/dGame/dComponents/PossessorComponent.h
Aaron Kimbrell b2a1e9e0b8 refactor: remaining game messages as structs, switch removed
Every game message still written or read by hand is now a NetGameMsg with
Serialize and Deserialize, in per-domain files:
- MovementMessages: teleport, platforms (resync and its request), orient to
  angle, node rotation lock, gravity scale, jetpack mode, control scheme,
  respawn checkpoint, rails (set/start, ready, cancel, arrived), mount
  inventory ID, dismount complete, possession ack, ghost reference override
  and position, camera cycling (eCameraTargetCyclingMode moves here).
- ZoneMessages: player loaded (the old PLAYER_LOADED case), ready for
  updates, player ready, restore to post load stats, server done loading,
  invalid zone transfer list, zone summary display/dismissed, level
  processing complete, object world state, and the localized announcement
  WorldMigration wrote by hand.
- PlayerMessages: chat mode, GM level, LEGO score, currency, reputation,
  GM invis, pickup currency, zone and player statistics, chat commands, bug
  reports, verify ack.
- ObjectMessages: fire event client/server side, notify client
  (zone) object, notify object, script network vars, failed preconditions,
  terminate interaction, set name, request use, request server object info.
- QuickBuildMessages: notify state, enable, cancel.
- ActivityMessages gains match response/update/request, leaderboard request
  and data, shooting gallery score/rotation/fire, activity state change.
- MissionMessages gains MissionDialogueCancelled (a no-op, as before).
The wire structs left in GameMessages.h move to their domains (tooltip and
emote to Effects, loot and item use to Inventory, model build to Building,
behavior sound to Property, skill sets to Skill) and gain the missing
direction. The dismount logic moves to PossessorComponent::OnDismountComplete.

Every inbound message is registered in the GameMessageHandler map; the
switch is gone, and GameMessages.cpp only holds the GameMsg/NetGameMsg base
code. Call sites build the structs (NotifyClientObject, TerminateInteraction,
Teleport, PlatformResync, FireEventClientSide, NotifyObject and
NotifyClientZoneObject get convenience constructors like PlayFXEffect).
Dead senders are dropped: SendSetShootingGalleryParams (no callers, field
order was a guess), SendTeamPickupItem (the struct already existed),
SendRequestActivitySummaryLeaderboardData (the struct covers it).

Verified with RemainingMessagesTests: every old Send* function is frozen
verbatim in Legacy/RemainingMessagesLegacy.h and compared byte for byte
(same bits, destination and broadcast flag) over grids of inputs; every old
Handle* read sequence is frozen as a Read* oracle and compared with the
struct's Deserialize; round trips, truncation and a golden packet.
PlayerLoaded (0x00dc36f0), SetGMLevel (0x00dd6230), MissionDialogueCancelled
(0x00d9cc10) and LocalizedAnnouncementServerToSingleClient (0x00f23c50)
were checked against the client. Behaviour notes: an inbound message that
fails to deserialize is dropped, so ParseChatMessage over MAX_MESSAGE_LENGTH
is dropped instead of truncated, and PLAYER_LOADED / READY_FOR_UPDATES /
MISSION_DIALOGUE_CANCELLED now read their (unused) client fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:56 -05:00

123 lines
3.1 KiB
C++

#pragma once
#include "BitStream.h"
#include "Entity.h"
#include "Component.h"
#include "eReplicaComponentType.h"
// possession types
enum class ePossessionType : uint8_t {
NO_POSSESSION = 0,
ATTACHED_VISIBLE,
NOT_ATTACHED_VISIBLE,
NOT_ATTACHED_NOT_VISIBLE,
};
/**
* Represents an entity that can posess other entities. Generally used by players to drive a car.
*/
class PossessorComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::POSSESSOR;
PossessorComponent(Entity* parent, const int32_t componentID);
~PossessorComponent() override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* @brief Mounts the entity
*
* @param mount Entity to be mounted
*/
void Mount(Entity* mount);
/**
* @brief Dismounts the entity
*
* @param mount Entity to be dismounted
* @param forceDismount Should we forcibly dismount the entity
*/
void Dismount(Entity* mount, bool forceDismount = false);
/**
* @brief Handles the client's DismountComplete: finishes a dismount started by Dismount
*
* @param mountId The object ID of the mount the client finished dismounting
*/
void OnDismountComplete(const LWOOBJID mountId);
/**
* Sets the ID that this entity is possessing
* @param value The ID that this entity is possessing
*/
void SetPossessable(LWOOBJID value) { m_Possessable = value; m_DirtyPossesor = true; }
/**
* Returns the entity that this entity is currently posessing
* @return The entity that this entity is currently posessing
*/
LWOOBJID GetPossessable() const { return m_Possessable; }
/**
* Sets if we are busy dismounting
* @param value If we are busy dismounting
*/
void SetIsDismounting(bool value) { m_IsDismounting = value; }
/**
* Returns if we are busy dismounting
* @return If we are busy dismounting
*/
bool GetIsDismounting() const { return m_IsDismounting; }
/**
* Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0
* @param value The possesible type to set
*/
void SetPossessableType(ePossessionType value) { m_PossessableType = value; m_DirtyPossesor = true; }
/**
* Gets the object ID of the mount item that is being used
* @return The object ID of the mount item that is being used
*/
LWOOBJID GetMountItemID() const { return m_MountItemID; }
/**
* Sets the object ID of the mount item that is being used
* @param m_MountItemID The object ID of the mount item that is being used
*/
void SetMountItemID(LWOOBJID mountItemID) { m_MountItemID = mountItemID; }
private:
/**
* The ID of the entity this entity is possessing (e.g. the ID of a car)
*/
LWOOBJID m_Possessable = LWOOBJID_EMPTY;
/**
* @brief possessable type
*
*/
ePossessionType m_PossessableType = ePossessionType::NO_POSSESSION;
/**
* @brief If the possessor is dirty
*
*/
bool m_DirtyPossesor = false;
/**
* @brief If the possessor is busy dismounting
*
*/
bool m_IsDismounting = false;
/**
* Mount Item ID
*/
LWOOBJID m_MountItemID = LWOOBJID_EMPTY;
};