From 6c97ea820876ce10e4a6197dc1cd3739fef116a5 Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Sat, 6 Aug 2022 09:19:34 +0100 Subject: [PATCH] Implement flying command (#713) * Implement flying command * Add documentation. --- dGame/Character.h | 17 ++++++++++++ dGame/dBehaviors/JetPackBehavior.cpp | 18 +++++++++++++ dGame/dUtilities/SlashCommandHandler.cpp | 34 ++++++++++++++++++++++++ docs/Commands.md | 1 + 4 files changed, 70 insertions(+) diff --git a/dGame/Character.h b/dGame/Character.h index 1a1d4cd0..52bff83d 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -425,6 +425,18 @@ public: */ const std::vector& GetEquippedItems() const { return m_EquippedItems; } + /** + * @brief Get the flying state + * @return value of the flying state + */ + bool GetIsFlying() { return m_IsFlying; } + + /** + * @brief Set the value of the flying state + * @param isFlying the flying state + */ + void SetIsFlying(bool isFlying) { m_IsFlying = isFlying; } + private: /** * The ID of this character. First 32 bits of the ObjectID. @@ -621,6 +633,11 @@ private: */ std::string m_TargetScene; + /** + * Bool that tracks the flying state of the user. + */ + bool m_IsFlying = false; + /** * Queries the character XML and updates all the fields of this object * NOTE: quick as there's no DB lookups diff --git a/dGame/dBehaviors/JetPackBehavior.cpp b/dGame/dBehaviors/JetPackBehavior.cpp index 00900735..e7d76560 100644 --- a/dGame/dBehaviors/JetPackBehavior.cpp +++ b/dGame/dBehaviors/JetPackBehavior.cpp @@ -3,16 +3,34 @@ #include "BehaviorBranchContext.h" #include "GameMessages.h" +#include "Character.h" + void JetPackBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) { auto* entity = EntityManager::Instance()->GetEntity(branch.target); GameMessages::SendSetJetPackMode(entity, true, this->m_BypassChecks, this->m_EnableHover, this->m_effectId, this->m_Airspeed, this->m_MaxAirspeed, this->m_VerticalVelocity, this->m_WarningEffectID); + + if (entity->IsPlayer()) { + auto* character = entity->GetCharacter(); + + if (character) { + character->SetIsFlying(true); + } + } } void JetPackBehavior::UnCast(BehaviorContext* context, BehaviorBranchContext branch) { auto* entity = EntityManager::Instance()->GetEntity(branch.target); GameMessages::SendSetJetPackMode(entity, false); + + if (entity->IsPlayer()) { + auto* character = entity->GetCharacter(); + + if (character) { + character->SetIsFlying(false); + } + } } void JetPackBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bit_stream, const BehaviorBranchContext branch) { diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 0bf37288..b91021de 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -942,6 +942,40 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit } } + if (chatCommand == "fly" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_DEVELOPER) { + auto* character = entity->GetCharacter(); + + if (character) { + bool isFlying = character->GetIsFlying(); + + if (isFlying) { + GameMessages::SendSetJetPackMode(entity, false); + + character->SetIsFlying(false); + } else { + float speedScale = 1.0f; + + if (args.size() >= 1) { + float tempScaleStore; + + if (GeneralUtils::TryParse(args[0], tempScaleStore)) { + speedScale = tempScaleStore; + } else { + ChatPackets::SendSystemMessage(sysAddr, u"Failed to parse speed scale argument."); + } + } + + float airSpeed = 20 * speedScale; + float maxAirSpeed = 30 * speedScale; + float verticalVelocity = 1.5 * speedScale; + + GameMessages::SendSetJetPackMode(entity, true, true, false, 167, airSpeed, maxAirSpeed, verticalVelocity); + + character->SetIsFlying(true); + } + } + } + //------- GM COMMANDS TO ACTUALLY MODERATE -------- if (chatCommand == "mute" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_JUNIOR_DEVELOPER) { diff --git a/docs/Commands.md b/docs/Commands.md index b5588f68..8cefaa14 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -32,6 +32,7 @@ Here is a summary of the commands available in-game. All commands are prefixed b |gminvis|`/gminvis`|Toggles invisibility for the character, though it's currently a bit buggy. Requires nonzero GM Level for the character, but the account must have a GM level of 8.|8| |setname|`/setname `|Sets a temporary name for your player. The name resets when you log out.|8| |title|`/title `|Temporarily appends your player's name with " - <title>". This resets when you log out.|8| +|fly|`/fly <speed>`|This toggles your flying state with an optional parameter for the speed scale.|4| ## Server Operation Commands