Framework for GM's and helpers for mounts (#651)

* Framework for GM's and helpers for mounts

* docs and spacing

* whitespace
This commit is contained in:
Aaron Kimbrell 2022-07-17 02:35:11 -05:00 committed by GitHub
parent 0d4f86b20b
commit ef8c2a40f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 281 additions and 165 deletions

View File

@ -179,6 +179,18 @@ public:
*/ */
void SetLastRocketItemID(LWOOBJID lastRocketItemID) { m_LastRocketItemID = lastRocketItemID; } void SetLastRocketItemID(LWOOBJID lastRocketItemID) { m_LastRocketItemID = lastRocketItemID; }
/**
* 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; }
/** /**
* Gives the player rewards for the last level that they leveled up from * Gives the player rewards for the last level that they leveled up from
*/ */
@ -579,6 +591,11 @@ private:
* ID of the last rocket used * ID of the last rocket used
*/ */
LWOOBJID m_LastRocketItemID = LWOOBJID_EMPTY; LWOOBJID m_LastRocketItemID = LWOOBJID_EMPTY;
/**
* Mount Item ID
*/
LWOOBJID m_MountItemID = LWOOBJID_EMPTY;
}; };
#endif // CHARACTERCOMPONENT_H #endif // CHARACTERCOMPONENT_H

View File

@ -1,10 +1,13 @@
#include "PossessableComponent.h" #include "PossessableComponent.h"
#include "PossessorComponent.h" #include "PossessorComponent.h"
#include "EntityManager.h" #include "EntityManager.h"
#include "Inventory.h"
#include "Item.h" #include "Item.h"
PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId) : Component(parent){ PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId) : Component(parent){
m_Possessor = LWOOBJID_EMPTY; m_Possessor = LWOOBJID_EMPTY;
CDItemComponent item = Inventory::FindItemComponent(m_Parent->GetLOT());
m_AnimationFlag = static_cast<eAnimationFlags>(item.animationFlag);
// Get the possession Type from the CDClient // Get the possession Type from the CDClient
auto query = CDClientDatabase::CreatePreppedStmt("SELECT possessionType, depossessOnHit FROM PossessableComponent WHERE id = ?;"); auto query = CDClientDatabase::CreatePreppedStmt("SELECT possessionType, depossessOnHit FROM PossessableComponent WHERE id = ?;");

View File

@ -54,6 +54,18 @@ class PossessableComponent : public Component {
*/ */
void ForceDepossess() { m_ImmediatelyDepossess = true; m_DirtyPossessable = true;}; void ForceDepossess() { m_ImmediatelyDepossess = true; m_DirtyPossessable = true;};
/**
* Set if the parent entity was spawned from an item
* @param value if the parent entity was spawned from an item
*/
void SetItemSpawned(bool value) { m_ItemSpawned = value;};
/**
* Returns if the parent entity was spawned from an item
* @return if the parent entity was spawned from an item
*/
LWOOBJID GetItemSpawned() const { return m_ItemSpawned; };
/** /**
* Handles an OnUsed event by some other entity, if said entity has a Possessor it becomes the possessor * Handles an OnUsed event by some other entity, if said entity has a Possessor it becomes the possessor
* of this entity * of this entity
@ -95,4 +107,9 @@ class PossessableComponent : public Component {
*/ */
bool m_ImmediatelyDepossess = false; bool m_ImmediatelyDepossess = false;
/**
* @brief Whether the parent entity was spawned from an item
*
*/
bool m_ItemSpawned = false;
}; };

View File

@ -36,6 +36,18 @@ class PossessorComponent : public Component {
*/ */
LWOOBJID GetPossessable() const { return m_Possessable; } LWOOBJID GetPossessable() const { return m_Possessable; }
/**
* Sets if we are busy mounting or dismounting
* @param value if we are busy mounting or dismounting
*/
void SetIsBusy(bool value) { m_IsBusy = value; }
/**
* Returns if we are busy mounting or dismounting
* @return if we are busy mounting or dismounting
*/
bool GetIsBusy() const { return m_IsBusy; }
/** /**
* Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0 * 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 * @param value the possesible type to set
@ -60,4 +72,10 @@ class PossessorComponent : public Component {
* *
*/ */
bool m_DirtyPossesor = false; bool m_DirtyPossesor = false;
/**
* @brief if the possessor is busy mounting or dismounting
*
*/
bool m_IsBusy = false;
}; };

View File

@ -3986,6 +3986,47 @@ void GameMessages::SendDisplayChatBubble(LWOOBJID objectId, const std::u16string
SEND_PACKET; SEND_PACKET;
} }
// Mounts
void GameMessages::SendSetMountInventoryID(Entity* entity, const LWOOBJID& objectID, const SystemAddress& sysAddr){
CBITSTREAM;
CMSGHEADER;
bitStream.Write(entity->GetObjectID());
bitStream.Write(GAME_MSG::GAME_MSG_SET_MOUNT_INVENTORY_ID);
bitStream.Write(objectID);
SEND_PACKET_BROADCAST;
}
void GameMessages::HandleDismountComplete(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr){
LWOOBJID objectId{};
inStream->Read(objectId);
auto* mount = EntityManager::Instance()->GetEntity(objectId);
if (objectId != LWOOBJID_EMPTY) {
PossessorComponent* possessor;
if (entity->TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessor)) {
if (mount) {
possessor->SetIsBusy(false);
possessor->SetPossessable(LWOOBJID_EMPTY);
possessor->SetPossessableType(ePossessionType::NO_POSSESSION);
GameMessages::SendSetStunned(entity->GetObjectID(), eStunState::POP, UNASSIGNED_SYSTEM_ADDRESS, LWOOBJID_EMPTY, true, false, true, false, false, false, false, true, true, true, true, true, true, true, true, true);
EntityManager::Instance()->SerializeEntity(entity);
}
}
}
}
void GameMessages::HandleAcknowledgePossession(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {
Game::logger->Log("HandleAcknowledgePossession", "Got AcknowledgePossession from %i\n", entity->GetLOT());
EntityManager::Instance()->SerializeEntity(entity);
}
//Racing //Racing
void GameMessages::HandleModuleAssemblyQueryData(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) void GameMessages::HandleModuleAssemblyQueryData(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr)
@ -4042,14 +4083,6 @@ void GameMessages::HandleRacingClientReady(RakNet::BitStream* inStream, Entity*
} }
void GameMessages::HandleAcknowledgePossession(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr)
{
Game::logger->Log("HandleAcknowledgePossession", "Got AcknowledgePossession from %i\n", entity->GetLOT());
EntityManager::Instance()->SerializeEntity(entity);
}
void GameMessages::HandleRequestDie(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) void GameMessages::HandleRequestDie(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr)
{ {
bool bClientDeath; bool bClientDeath;

View File

@ -328,6 +328,34 @@ namespace GameMessages {
void SendDisplayChatBubble(LWOOBJID objectId, const std::u16string& text, const SystemAddress& sysAddr); void SendDisplayChatBubble(LWOOBJID objectId, const std::u16string& text, const SystemAddress& sysAddr);
// Mounts
/**
* @brief Set the Inventory LWOOBJID of the mount
*
* @param entity The entity that is mounting
* @param sysAddr the system address to send game message responses to
* @param objectID LWOOBJID of the item in inventory that is being used
*/
void SendSetMountInventoryID(Entity* entity, const LWOOBJID& objectID, const SystemAddress& sysAddr);
/**
* @brief Handle client dismounting mount
*
* @param inStream Raknet BitStream of incoming data
* @param entity The Entity that is dismounting
* @param sysAddr the system address to send game message responses to
*/
void HandleDismountComplete(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr);
/**
* @brief Handle acknowledging that the client possessed something
*
* @param inStream Raknet BitStream of incoming data
* @param entity The Entity that is possessing
* @param sysAddr the system address to send game message responses to
*/
void HandleAcknowledgePossession(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr);
//Racing: //Racing:
void HandleModuleAssemblyQueryData(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr); void HandleModuleAssemblyQueryData(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr);
@ -337,8 +365,6 @@ namespace GameMessages {
void HandleRacingClientReady(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr); void HandleRacingClientReady(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr);
void HandleAcknowledgePossession(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr);
void HandleRequestDie(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr); void HandleRequestDie(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr);
void HandleVehicleNotifyServerAddPassiveBoostAction(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr); void HandleVehicleNotifyServerAddPassiveBoostAction(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr);

View File

@ -535,8 +535,10 @@ enum GAME_MSG : unsigned short {
GAME_MSG_REQUEST_MOVE_ITEM_BETWEEN_INVENTORY_TYPES = 1666, GAME_MSG_REQUEST_MOVE_ITEM_BETWEEN_INVENTORY_TYPES = 1666,
GAME_MSG_RESPONSE_MOVE_ITEM_BETWEEN_INVENTORY_TYPES = 1667, GAME_MSG_RESPONSE_MOVE_ITEM_BETWEEN_INVENTORY_TYPES = 1667,
GAME_MSG_PLAYER_SET_CAMERA_CYCLING_MODE = 1676, GAME_MSG_PLAYER_SET_CAMERA_CYCLING_MODE = 1676,
GAME_MSG_SET_MOUNT_INVENTORY_ID = 1726,
GAME_MSG_NOTIFY_SERVER_LEVEL_PROCESSING_COMPLETE = 1734, GAME_MSG_NOTIFY_SERVER_LEVEL_PROCESSING_COMPLETE = 1734,
GAME_MSG_NOTIFY_LEVEL_REWARDS = 1735, GAME_MSG_NOTIFY_LEVEL_REWARDS = 1735,
GAME_MSG_DISMOUNT_COMPLETE = 1756,
GAME_MSG_MARK_INVENTORY_ITEM_AS_ACTIVE = 1767, GAME_MSG_MARK_INVENTORY_ITEM_AS_ACTIVE = 1767,
END END
}; };