Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make pets behave more accurately to Live #1305

Draft
wants to merge 100 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
8270e0e
Working on pet bouncers
jadebenn Nov 18, 2023
a58ffcc
Merge branch 'DarkflameUniverse:main' into PetDigAnimFix
jadebenn Nov 18, 2023
5734ef8
initial dig functionality; need to clean up kruft
jadebenn Nov 19, 2023
a76ddd9
cleaned up kruft
jadebenn Nov 19, 2023
fc1ff50
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Nov 19, 2023
bd6f9a7
added imagination cost to digs
jadebenn Nov 19, 2023
76d3187
actually check if the player can afford to dig
jadebenn Nov 19, 2023
c8b624c
minor changes
jadebenn Nov 19, 2023
9b9b5bc
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Nov 19, 2023
e835eb3
Fixed pet emotes not playing
jadebenn Nov 19, 2023
81a54e7
Merge branch 'PetFixes' of https://github.com/jadebenn/DarkflameServe…
jadebenn Nov 19, 2023
23664c0
updated pet command functionality
jadebenn Nov 19, 2023
81d8c18
mission fix redo
jadebenn Nov 22, 2023
57a1c05
update loop cleanup
jadebenn Nov 22, 2023
1a6fb89
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Nov 22, 2023
74047bc
Working on pet bouncers
jadebenn Nov 18, 2023
119968a
initial dig functionality; need to clean up kruft
jadebenn Nov 19, 2023
86abbc1
cleaned up kruft
jadebenn Nov 19, 2023
b3762da
added imagination cost to digs
jadebenn Nov 19, 2023
e73b2bf
actually check if the player can afford to dig
jadebenn Nov 19, 2023
3f1f51f
minor changes
jadebenn Nov 19, 2023
1a74ed6
Fixed pet emotes not playing
jadebenn Nov 19, 2023
cb65de6
updated pet command functionality
jadebenn Nov 19, 2023
3f1468e
mission fix redo
jadebenn Nov 22, 2023
e4b3e22
update loop cleanup
jadebenn Nov 22, 2023
c598b57
Merge branch 'PetFixes' of https://github.com/jadebenn/DarkflameServe…
jadebenn Nov 25, 2023
55f857b
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Nov 25, 2023
93592c7
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Dec 10, 2023
1c01219
added some pet debug commands
jadebenn Dec 10, 2023
200d679
redone pet update loop
jadebenn Dec 11, 2023
5b738df
Further redid pet update loop
jadebenn Dec 12, 2023
a99f7a7
Re-implemented treasure dig handling
jadebenn Dec 13, 2023
68df8af
capitalization
jadebenn Dec 13, 2023
fd5ea75
added bone dragon treasure dig handling
jadebenn Dec 13, 2023
291fc83
added bone dragon treasure dig handling
jadebenn Dec 13, 2023
775e4fe
change AND priority
jadebenn Dec 13, 2023
2a4cfe3
function rename
jadebenn Dec 13, 2023
1b8f10f
added treasure dig menu prompts and help messages
jadebenn Dec 14, 2023
9953255
Update GameMessages.h
jadebenn Dec 14, 2023
2db76ae
Update GameMessages.cpp
jadebenn Dec 14, 2023
8f19aa9
minor gm formatting fix
jadebenn Dec 14, 2023
f5ca142
Update PetStatus enum to prep for bitset use
jadebenn Dec 14, 2023
668bebf
adding new pet flags
jadebenn Dec 15, 2023
054371d
added new pet bitflag system
jadebenn Dec 15, 2023
e01fbfc
restored header guards
jadebenn Dec 15, 2023
9add2c9
PetFlag system now functioning correctly
jadebenn Dec 15, 2023
1c7ce6e
updated CDClient pet data handling
jadebenn Dec 16, 2023
cecf065
Changed how pet data is loaded
jadebenn Dec 16, 2023
60e4813
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Dec 17, 2023
8c97271
Update treasure behavior
jadebenn Dec 17, 2023
b8449a1
Merge branch 'PetFixes' of https://github.com/jadebenn/DarkflameServe…
jadebenn Dec 17, 2023
2d3e03a
pet following and flag behavior improvements
jadebenn Dec 17, 2023
c6df078
comment cleanup
jadebenn Dec 17, 2023
60b3f3c
Merge branch 'main' into PetFixes
Dec 27, 2023
d7d5202
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Dec 27, 2023
6edd42d
pet bouncer minimum functionality
Dec 28, 2023
a4f0602
Merge branch 'main' into PetFixes
Dec 28, 2023
5f8f200
pet bouncers now bounce player upon pressing shift
Dec 28, 2023
b83e1bf
some further bouncer refinements
Dec 29, 2023
1ee5b64
Update PetComponent.h
jadebenn Jan 1, 2024
17753c5
Update PetComponent.h
jadebenn Jan 1, 2024
d5a0b71
Update PetComponent.cpp
jadebenn Jan 1, 2024
9a35aad
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Jan 1, 2024
c575fd9
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Jan 5, 2024
384083e
use reference instead of pointer for cdclient data
jadebenn Jan 5, 2024
0f365e0
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Jan 5, 2024
6c3c08c
Added fallback to default values if CDClient data cannot be loaded
jadebenn Jan 5, 2024
20d6820
Merge branch 'main' into PetFixes
jadebenn Jan 6, 2024
06d5a27
Merge branch 'DarkflameUniverse:main' into PetFixes
jadebenn Jan 6, 2024
d6321a6
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Feb 14, 2024
70e0cd6
more merge
jadebenn Feb 14, 2024
a449e53
delete unused functions and update documentation
jadebenn Mar 4, 2024
1c1b733
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Mar 4, 2024
c36bc83
fix pet taming minigame countdown
jadebenn Mar 4, 2024
9ec028b
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Mar 6, 2024
4791b31
use class enums
jadebenn Mar 6, 2024
9a9254b
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Mar 8, 2024
e832dfb
add most pet messages
jadebenn Mar 9, 2024
50b2074
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Mar 24, 2024
657fb35
semi update the unit tests
jadebenn Apr 1, 2024
0b4d7b6
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Apr 1, 2024
36e0dbd
load imagination costs for pet abilities from CDClient
jadebenn Apr 19, 2024
d88b982
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Apr 19, 2024
0b24532
clean up PetComponent
jadebenn Apr 20, 2024
6ddf5b3
remove unneeded tests
jadebenn Apr 20, 2024
5ddf4ce
fix unused expression
jadebenn Apr 20, 2024
f41321e
Use compile-time flag setting
jadebenn Apr 20, 2024
071c022
this commit may be kinda broke but I'm gonna push it to check something
jadebenn Apr 20, 2024
7b223d1
Revert "this commit may be kinda broke but I'm gonna push it to check…
jadebenn Apr 20, 2024
68bb51f
move the pet taming minigame start logic into a separate function
jadebenn Apr 20, 2024
fdd981c
Merge remote-tracking branch 'upstream/main' into PetFixes
jadebenn Apr 25, 2024
efc2cb6
Merge branch 'main' into PetFixes
jadebenn Dec 14, 2024
514732d
formatting & const
jadebenn Dec 15, 2024
43681b4
more formatting & const
jadebenn Dec 15, 2024
96f224c
move semantics
jadebenn Dec 15, 2024
0786986
partially address comments
jadebenn Dec 15, 2024
472f873
further address feedback
jadebenn Dec 15, 2024
f7bcbb0
no longer bad (you know it)
jadebenn Dec 15, 2024
d42351d
formatting nits
jadebenn Dec 15, 2024
79c26d9
misc
jadebenn Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dCommon/dEnums/ePetStatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef __EPETSTATUS__H__
#define __EPETSTATUS__H__

#include <cstdint>

enum ePetStatus : uint32_t {
NONE,
UNKNOWN1 = 0x1,
UNKNOWN2 = 0x2,
UNKNOWN3 = 0x4,
UNKNOWN4 = 0x8,
BEING_TAMED = 0x10,
IS_NOT_WAITING = 0x20, // Right name? - used to be decimal 20
PLAY_SPAWN_ANIM = 0x80,
TAMEABLE = 0x4000000
};

#endif //!__EPETSTATUS__H__
jadebenn marked this conversation as resolved.
Show resolved Hide resolved
95 changes: 66 additions & 29 deletions dGame/dComponents/PetComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "ePetTamingNotifyType.h"
#include "eUseItemResponse.h"
#include "ePlayerFlag.h"
#include "ePetStatus.h"

#include "Game.h"
#include "dConfig.h"
Expand Down Expand Up @@ -80,13 +81,16 @@ PetComponent::PetComponent(Entity* parent, uint32_t componentId): Component(pare
m_Timer = 0;
m_TimerAway = 0;
m_DatabaseId = LWOOBJID_EMPTY;
m_Status = 67108866; // Tamable
m_Status = ePetStatus::TAMEABLE; // Tameable
m_Ability = PetAbilityType::Invalid;
m_StartPosition = NiPoint3::ZERO;
m_MovementAI = nullptr;
m_TresureTime = 0;
m_Preconditions = nullptr;

m_ReadyToDig = false;
m_InInteract = false;

std::string checkPreconditions = GeneralUtils::UTF16ToWTF8(parent->GetVar<std::u16string>(u"CheckPrecondition"));

if (!checkPreconditions.empty()) {
Expand Down Expand Up @@ -150,6 +154,15 @@ void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpd
}

void PetComponent::OnUse(Entity* originator) {
LOG("PET USE!");

if(m_ReadyToDig) {
LOG("Dig initiated!");
m_TresureTime = 2.0f;
//m_ReadyToDig = false;
SetAbility(PetAbilityType::DigAtPosition);
}

if (m_Owner != LWOOBJID_EMPTY) {
return;
}
Expand Down Expand Up @@ -369,29 +382,8 @@ void PetComponent::Update(float deltaTime) {
return;
}

if (m_TresureTime > 0) {
auto* tresure = Game::entityManager->GetEntity(m_Interaction);

if (tresure == nullptr) {
m_TresureTime = 0;

return;
}

m_TresureTime -= deltaTime;

m_MovementAI->Stop();

if (m_TresureTime <= 0) {
m_Parent->SetOwnerOverride(m_Owner);

tresure->Smash(m_Parent->GetObjectID());

m_Interaction = LWOOBJID_EMPTY;

m_TresureTime = 0;
}

if (m_TresureTime > 0.0f) {
InteractDig(deltaTime);
return;
}

Expand Down Expand Up @@ -440,10 +432,9 @@ void PetComponent::Update(float deltaTime) {
}
}

// Determine if the "Lost Tags" mission has been completed and digging has been unlocked
auto* missionComponent = owner->GetComponent<MissionComponent>();
if (!missionComponent) return;

// Determine if the "Lost Tags" mission has been completed and digging has been unlocked
const bool digUnlocked = missionComponent->GetMissionState(842) == eMissionState::COMPLETE;

Entity* closestTresure = PetDigServer::GetClosestTresure(position);
Expand All @@ -461,11 +452,14 @@ void PetComponent::Update(float deltaTime) {

Command(NiPoint3::ZERO, LWOOBJID_EMPTY, 1, 202, true);

m_TresureTime = 2;
SetIsReadyToDig(true);

} else if (distance < 10 * 10) {
haltDistance = 1;

destination = tresurePosition;

SetIsReadyToDig(false);
}
}

Expand All @@ -480,6 +474,49 @@ void PetComponent::Update(float deltaTime) {
m_Timer = 1;
}

void PetComponent::SetIsReadyToDig(bool isReady) {
if (isReady) {
LOG("Dig state reached!");
//m_Interaction = closestTresure->GetObjectID();
SetAbility(PetAbilityType::JumpOnObject);
SetStatus(ePetStatus::IS_NOT_WAITING); // Treasure dig status
m_ReadyToDig = true;
}
else {
LOG("Dig state ended!");
//m_Interaction = LWOOBJID_EMPTY;
SetAbility(PetAbilityType::Invalid);
SetStatus(0); // TODO: Check status
m_ReadyToDig = false;
}
}

void PetComponent::InteractDig(float deltaTime) { //Should I rename to InteractDig?
LOG("Pet digging!");

auto* tresure = Game::entityManager->GetEntity(m_Interaction);

if (tresure == nullptr) {
m_TresureTime = 0.0f;
return;
}

m_TresureTime -= deltaTime;

m_MovementAI->Stop();

if (m_TresureTime <= 0.0f) {
m_Parent->SetOwnerOverride(m_Owner);

tresure->Smash(m_Parent->GetObjectID());

LOG("Pet dig completed!");
m_Interaction = LWOOBJID_EMPTY;
m_TresureTime = 0.0f;
SetIsReadyToDig(false);
}
}

void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
if (m_Tamer == LWOOBJID_EMPTY) return;

Expand Down Expand Up @@ -736,7 +773,7 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {

currentActivities.erase(m_Tamer);

SetStatus(67108866);
SetStatus(ePetStatus::TAMEABLE);
m_Tamer = LWOOBJID_EMPTY;
m_Timer = 0;

Expand Down Expand Up @@ -787,7 +824,7 @@ void PetComponent::ClientFailTamingMinigame() {

currentActivities.erase(m_Tamer);

SetStatus(67108866);
SetStatus(ePetStatus::TAMEABLE);
m_Tamer = LWOOBJID_EMPTY;
m_Timer = 0;

Expand Down
33 changes: 33 additions & 0 deletions dGame/dComponents/PetComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class PetComponent : public Component
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;

/**
* Handles the pet dig interaction
* @param deltaTime time elapsed
*/
void InteractDig(float deltaTime);

/**
* 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
Expand Down Expand Up @@ -172,6 +178,23 @@ class PetComponent : public Component
*/
void SetPreconditions(std::string& conditions);

/**
* Sets if the pet is ready to dig
* @param isReady whether the pet is ready to dig (true) or not (false)
*/
void SetIsReadyToDig(bool isReady);

/**
* @return is pet ready to dig
*/
bool GetIsReadyToDig() { return m_ReadyToDig; };

/**
* Sets pet's treasure timer
* @param digTime float representing the treasure dig time in seconds
*/
void SetTreasureTime(float digTime) { m_TresureTime = digTime; };

/**
* Returns the entity that this component belongs to
* @return the entity that this component belongs to
Expand Down Expand Up @@ -341,6 +364,16 @@ class PetComponent : public Component
*/
float m_TresureTime;

/**
* Boolean that sets if a pet is ready to dig and display the interact prompt
*/
bool m_ReadyToDig;

/**
* Boolean that sets if a pet is in an interaction
*/
float m_InInteract;

/**
* The position that this pet was spawned at
*/
Expand Down
27 changes: 27 additions & 0 deletions dGame/dUtilities/SlashCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "dServer.h"
#include "MissionComponent.h"
#include "Mail.h"
#include "PetComponent.h"
#include "dpWorld.h"
#include "Item.h"
#include "PropertyManagementComponent.h"
Expand Down Expand Up @@ -679,6 +680,32 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
entity->GetCharacter()->SetPlayerFlag(flagId, false);
}

if (chatCommand == "setpetstatus" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
if (args.size() == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Too few arguments!");
return;
}

uint32_t petStatus;
if (!GeneralUtils::TryParse(args[0], petStatus)) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid pet status!");
return;
}

// Determine if player has a pet summoned
auto* petComponent = PetComponent::GetActivePet(entity->GetObjectID());
if (!petComponent) {
ChatPackets::SendSystemMessage(sysAddr, u"No active pet found!");
return;
}

petComponent->SetStatus(petStatus);
//Game::entityManager->SerializeEntity(petComponent->GetParentEntity());

std::u16string msg = u"Set pet status to " + (GeneralUtils::to_u16string(petStatus));
ChatPackets::SendSystemMessage(sysAddr, msg);
}

if (chatCommand == "resetmission" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
if (args.size() == 0) return;

Expand Down
11 changes: 11 additions & 0 deletions dScripts/02_server/Map/General/PetDigServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ void PetDigServer::OnDie(Entity* self, Entity* killer) {
}
}

void PetDigServer::OnUse(Entity* self, Entity* user) {
LOG("Treasure used!");

auto* petComponent = PetComponent::GetActivePet(user->GetObjectID());
if (!petComponent) return;

if(petComponent->GetIsReadyToDig()) {
petComponent->SetTreasureTime(2.0f);
}
}

void PetDigServer::HandleXBuildDig(const Entity* self, Entity* owner, Entity* pet) {
auto playerID = self->GetVar<LWOOBJID>(u"builder");
if (playerID == LWOOBJID_EMPTY || playerID != owner->GetObjectID())
Expand Down
7 changes: 7 additions & 0 deletions dScripts/02_server/Map/General/PetDigServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class PetDigServer : public CppScripts::Script
void OnStartup(Entity* self) override;
void OnDie(Entity* self, Entity* killer) override;

/**
* Invoked when a player interacts with treasure.
* @param self the entity the script belongs to
* @param user the entity that used the treasure
*/
void OnUse(Entity* self, Entity* user) override;

static Entity* GetClosestTresure(NiPoint3 position);

private:
Expand Down