2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "MovementAIComponent.h"
|
|
|
|
#include "Component.h"
|
|
|
|
#include "Preconditions.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
enum class PetAbilityType
|
|
|
|
{
|
|
|
|
Invalid,
|
|
|
|
GoToObject,
|
|
|
|
JumpOnObject,
|
|
|
|
DigAtPosition
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an entity that is a pet. This pet can be tamed and consequently follows the tamer around, allowing it
|
|
|
|
* to dig for treasure and activate pet bouncers.
|
|
|
|
*/
|
|
|
|
class PetComponent : public Component
|
|
|
|
{
|
|
|
|
public:
|
2023-06-09 08:22:45 +00:00
|
|
|
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::PET;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
explicit PetComponent(Entity* parentEntity, uint32_t componentId);
|
|
|
|
~PetComponent() override;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
|
|
|
void Update(float deltaTime) override;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Handles an OnUse event from another entity, initializing the pet taming minigame if this pet is untamed.
|
|
|
|
* @param originator the entity that triggered the event
|
|
|
|
*/
|
|
|
|
void OnUse(Entity* originator) override;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Attempts to complete the pet minigame by passing a list of bricks to build the minigame model.
|
|
|
|
* @param bricks the bricks to try to complete the minigame with
|
|
|
|
* @param clientFailed unused
|
|
|
|
*/
|
2022-04-07 05:21:29 +00:00
|
|
|
void TryBuild(uint32_t numBricks, bool clientFailed);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Handles a notification from the client regarding the completion of the pet minigame, adding the pet to their
|
|
|
|
* inventory.
|
|
|
|
* @param position the position to spawn the completed model at
|
|
|
|
*/
|
|
|
|
void NotifyTamingBuildSuccess(NiPoint3 position);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Handles the notification of the client to set the name of the pet (indicating that minigame was completed
|
|
|
|
* successfully).
|
|
|
|
* @param name the name of the pet to set
|
|
|
|
*/
|
|
|
|
void RequestSetPetName(std::u16string name);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Handles a notification of the client that the taming entity is leaving the minigame, either voluntary or because
|
|
|
|
* time ran out.
|
|
|
|
* @param voluntaryExit whether the client voluntarily exited the minigame
|
|
|
|
*/
|
|
|
|
void ClientExitTamingMinigame(bool voluntaryExit);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Starts the internal timer for the build limit for building the minigame model
|
|
|
|
*/
|
|
|
|
void StartTimer();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Notifies the client that they failed the minigame because time ran out
|
|
|
|
*/
|
|
|
|
void ClientFailTamingMinigame();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Makes the pet wander around
|
|
|
|
*/
|
|
|
|
void Wander();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Spawns a pet from an item in the inventory of an owner
|
|
|
|
* @param item the item to create the pet from
|
|
|
|
* @param registerPet notifies the client that the pet was spawned, not necessary if this pet is being tamed
|
|
|
|
*/
|
2022-06-18 07:14:24 +00:00
|
|
|
void Activate(Item* item, bool registerPet = true, bool fromTaming = false);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Despawns the pet
|
|
|
|
*/
|
|
|
|
void Deactivate();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Removes the pet from the inventory
|
|
|
|
*/
|
|
|
|
void Release();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Commands the pet to do an action, actions are still a relative mystery, next to playing emotes
|
|
|
|
* @param position a position to execute the command at, currently unused
|
|
|
|
* @param source the source object that triggered the command
|
|
|
|
* @param commandType the type of the command (see function body for types)
|
|
|
|
* @param typeId extra information about the command, e.g. the emote to play
|
|
|
|
* @param overrideObey unused
|
|
|
|
*/
|
|
|
|
void Command(NiPoint3 position, LWOOBJID source, int32_t commandType, int32_t typeId, bool overrideObey);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the ID of the owner of this pet (if any)
|
|
|
|
* @return the ID of the owner of this pet
|
|
|
|
*/
|
|
|
|
LWOOBJID GetOwnerId() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the entity that owns this pet (if any)
|
|
|
|
* @return the entity that owns this pet
|
|
|
|
*/
|
|
|
|
Entity* GetOwner() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the ID that is stored in the database with regards to this pet, only set for pets that are tamed
|
|
|
|
* @return the ID that is stored in the database with regards to this pet
|
|
|
|
*/
|
|
|
|
LWOOBJID GetDatabaseId() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the ID of the object that the pet is currently interacting with, could be a treasure chest or a switch
|
|
|
|
* @return the ID of the object that the pet is currently interacting with
|
|
|
|
*/
|
|
|
|
LWOOBJID GetInteraction() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Sets the ID that the pet is interacting with
|
|
|
|
* @param value the ID that the pet is interacting with
|
|
|
|
*/
|
|
|
|
void SetInteraction(LWOOBJID value);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the ID that this pet was spawned from, only set for tamed pets
|
|
|
|
* @return the ID that this pet was spawned from
|
|
|
|
*/
|
|
|
|
LWOOBJID GetItemId() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the status of this pet, e.g. tamable or tamed. The values here are still a bit of mystery and likely a
|
|
|
|
* bit map
|
|
|
|
* @return the status of this pet
|
|
|
|
*/
|
|
|
|
uint32_t GetStatus() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Sets the current status of the pet
|
|
|
|
* @param value the current status of the pet to set
|
|
|
|
*/
|
|
|
|
void SetStatus(uint32_t value);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns an ability the pet may perform, currently unused
|
|
|
|
* @return an ability the pet may perform
|
|
|
|
*/
|
|
|
|
PetAbilityType GetAbility() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Sets the ability of the pet, currently unused
|
|
|
|
* @param value the ability to set
|
|
|
|
*/
|
|
|
|
void SetAbility(PetAbilityType value);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Sets preconditions for the pet that need to be met before it can be tamed
|
|
|
|
* @param conditions the preconditions to set
|
|
|
|
*/
|
|
|
|
void SetPreconditions(std::string& conditions);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the entity that this component belongs to
|
|
|
|
* @return the entity that this component belongs to
|
|
|
|
*/
|
|
|
|
Entity* GetParentEntity() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Sets the name of the pet to be moderated
|
|
|
|
* @param petName the name of the pet to set
|
|
|
|
*/
|
|
|
|
void SetPetNameForModeration(const std::string& petName);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Loads the pet name up for moderation along with the moderation status from the database and sets them for this
|
|
|
|
* pet.
|
|
|
|
*/
|
|
|
|
void LoadPetNameFromModeration();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the component of the pet some entity is currently taming (if any)
|
|
|
|
* @param tamer the entity that's currently taming
|
|
|
|
* @return the pet component of the entity that's being tamed
|
|
|
|
*/
|
2023-06-09 08:04:42 +00:00
|
|
|
static PetComponent* GetTamingPet(LWOOBJID tamer);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the pet that's currently spawned for some entity (if any)
|
|
|
|
* @param owner the owner of the pet that's spawned
|
|
|
|
* @return the pet component of the entity that was spawned by the owner
|
|
|
|
*/
|
2023-06-09 08:04:42 +00:00
|
|
|
static PetComponent* GetActivePet(LWOOBJID owner);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-06-18 06:53:09 +00:00
|
|
|
/**
|
|
|
|
* Adds the timer to the owner of this pet to drain imagination at the rate
|
|
|
|
* specified by the parameter imaginationDrainRate
|
|
|
|
*
|
|
|
|
* @param item The item that represents this pet in the inventory.
|
|
|
|
*/
|
2022-06-18 07:14:24 +00:00
|
|
|
void AddDrainImaginationTimer(Item* item, bool fromTaming = false);
|
2022-06-18 06:53:09 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Information for the minigame to be completed
|
|
|
|
*/
|
|
|
|
struct PetPuzzleData
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The LOT of the object that is to be created
|
|
|
|
*/
|
|
|
|
LOT puzzleModelLot;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* That file that contains the bricks required to build the model
|
|
|
|
*/
|
|
|
|
std::string buildFile;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The time limit to complete the build
|
|
|
|
*/
|
|
|
|
int32_t timeLimit;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The imagination cost for the tamer to start the minigame
|
|
|
|
*/
|
|
|
|
int32_t imaginationCost;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The number of pieces required to complete the minigame
|
|
|
|
*/
|
|
|
|
int32_t numValidPieces;
|
|
|
|
};
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Cache of all the pets that are currently spawned, indexed by tamer
|
|
|
|
*/
|
|
|
|
static std::unordered_map<LWOOBJID, LWOOBJID> activePets;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Cache of all the pets that are currently being tamed, indexed by tamer
|
|
|
|
*/
|
|
|
|
static std::unordered_map<LWOOBJID, LWOOBJID> currentActivities;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Cache of all the minigames and their information from the database
|
|
|
|
*/
|
|
|
|
static std::unordered_map<LOT, PetComponent::PetPuzzleData> buildCache;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Flags that indicate that a player has tamed a pet, indexed by the LOT of the pet
|
|
|
|
*/
|
2023-05-02 22:39:21 +00:00
|
|
|
static std::map<LOT, int32_t> petFlags;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the component in the pet component table
|
|
|
|
*/
|
|
|
|
uint32_t m_ComponentId;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the model that was built to complete the taming minigame for this pet
|
|
|
|
*/
|
|
|
|
LWOOBJID m_ModelId;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the object that the pet is currently interacting with (e.g. a treasure chest or switch)
|
|
|
|
*/
|
|
|
|
LWOOBJID m_Interaction;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the entity that owns this pet
|
|
|
|
*/
|
|
|
|
LWOOBJID m_Owner;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the entity that is currently taming this pet
|
|
|
|
*/
|
|
|
|
LWOOBJID m_Tamer;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID under which this pet is stored in the database (if it's tamed)
|
|
|
|
*/
|
|
|
|
LWOOBJID m_DatabaseId;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The ID of the item from which this pet was created
|
|
|
|
*/
|
|
|
|
LWOOBJID m_ItemId;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The moderation status for the name of this pet
|
|
|
|
*/
|
|
|
|
uint32_t m_ModerationStatus;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The name of this pet
|
|
|
|
*/
|
|
|
|
std::string m_Name;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The name of the owner of this pet
|
|
|
|
*/
|
|
|
|
std::string m_OwnerName;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The current state of the pet (e.g. tamable, tamed, etc).
|
|
|
|
*/
|
|
|
|
uint32_t m_Status;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* A currently active ability, mostly unused
|
|
|
|
*/
|
|
|
|
PetAbilityType m_Ability;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The time an entity has left to complete the minigame
|
|
|
|
*/
|
|
|
|
float m_Timer;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* A timer that tracks how long a tamed pet has been to far away from its owner, triggering a teleport after timeout
|
|
|
|
*/
|
|
|
|
float m_TimerAway;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Timer that tracks how long a pet has been digging up some treasure, required to spawn the treasure contents
|
|
|
|
* on time
|
|
|
|
*/
|
|
|
|
float m_TresureTime;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The position that this pet was spawned at
|
|
|
|
*/
|
|
|
|
NiPoint3 m_StartPosition;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* The movement AI component that is related to this pet, required to move it around
|
|
|
|
*/
|
2023-06-09 08:22:45 +00:00
|
|
|
MovementAIComponent* m_MovementAI;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
/**
|
|
|
|
* Preconditions that need to be met before an entity can tame this pet
|
|
|
|
*/
|
|
|
|
PreconditionExpression* m_Preconditions;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-06-18 06:53:09 +00:00
|
|
|
/**
|
|
|
|
* The rate at which imagination is drained from the user for having the pet out.
|
|
|
|
*/
|
|
|
|
float imaginationDrainRate;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|