Skip to content

Commit

Permalink
feat: spectate command
Browse files Browse the repository at this point in the history
  • Loading branch information
aronwk-aaron committed Jun 4, 2024
1 parent a54600b commit b56d077
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dGame/dGameMessages/GameMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6212,3 +6212,17 @@ void GameMessages::SendSlashCommandFeedbackText(Entity* entity, std::u16string t
auto sysAddr = entity->GetSystemAddress();
SEND_PACKET;
}

void GameMessages::SendForceCameraTargetCycle(Entity* entity, bool bForceCycling, eCameraTargetCyclingMode cyclingMode, LWOOBJID optionalTargetID) {
CBITSTREAM;
CMSGHEADER;

bitStream.Write(entity->GetObjectID());
bitStream.Write(eGameMessageType::FORCE_CAMERA_TARGET_CYCLE);
bitStream.Write(bForceCycling);
bitStream.Write(cyclingMode);
bitStream.Write(optionalTargetID);

auto sysAddr = entity->GetSystemAddress();
SEND_PACKET;
}
6 changes: 6 additions & 0 deletions dGame/dGameMessages/GameMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ enum class eQuickBuildState : uint32_t;
enum class BehaviorSlot : int32_t;
enum class eVendorTransactionResult : uint32_t;

enum class eCameraTargetCyclingMode : int32_t {
ALLOW_CYCLE_TEAMMATES,
DISALLOW_CYCLING
};

namespace GameMessages {
class PropertyDataMessage;
void SendFireEventClientSide(const LWOOBJID& objectID, const SystemAddress& sysAddr, std::u16string args, const LWOOBJID& object, int64_t param1, int param2, const LWOOBJID& sender);
Expand Down Expand Up @@ -666,6 +671,7 @@ namespace GameMessages {
void HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);

void SendSlashCommandFeedbackText(Entity* entity, std::u16string text);
void SendForceCameraTargetCycle(Entity* entity, bool bForceCycling, eCameraTargetCyclingMode cyclingMode, LWOOBJID optionalTargetID);
};

#endif // GAMEMESSAGES_H
9 changes: 9 additions & 0 deletions dGame/dUtilities/SlashCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,15 @@ void SlashCommandHandler::Startup() {
};
RegisterCommand(FindPlayerCommand);

Command SpectateCommand{
.help = "Spectate a player",
.info = "Specify a player name to spectate. They must be in the same world as you",
.aliases = { "spectate", "follow" },
.handle = GMGreaterThanZeroCommands::Spectate,
.requiredLevel = eGameMasterLevel::JUNIOR_MODERATOR
};
RegisterCommand(SpectateCommand);

// Register GM Zero Commands

Command HelpCommand{
Expand Down
8 changes: 8 additions & 0 deletions dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,12 @@ namespace GMGreaterThanZeroCommands {
request.Serialize(bitStream);
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
}

void Spectate(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
if (args.length() <= 0) GameMessages::SendSlashCommandFeedbackText(entity, u"No player Given");
auto player = PlayerManager::GetPlayer(args);
if (!player) GameMessages::SendSlashCommandFeedbackText(entity, u"Player not found");
GameMessages::SendSlashCommandFeedbackText(entity, u"Spectating Player");
GameMessages::SendForceCameraTargetCycle(entity, false, eCameraTargetCyclingMode::DISALLOW_CYCLING, player->GetObjectID());
}
}
1 change: 1 addition & 0 deletions dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace GMGreaterThanZeroCommands {
void Title(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ShowAll(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void FindPlayer(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Spectate(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}

#endif //!GMGREATERTHANZEROCOMMANDS_H

0 comments on commit b56d077

Please sign in to comment.