Merge pull request #110 from Lonaasan/main

[Small Addition] Added respawnInWorld Command
This commit is contained in:
Kae 2024-09-09 20:52:06 +10:00 committed by GitHub
commit 8457c2e954
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 12 deletions

View File

@ -10,6 +10,7 @@
},
"openSbCommands": {
"swap": "Usage /swap <name>. Swaps the current character, case-insensitive, only substring required."
"swap": "Usage /swap <name>. Swaps the current character, case-insensitive, only substring required.",
"respawninworld": "Usage /respawninworld. Sets the respawn flag for the current world until you teleport away."
}
}

View File

@ -51,7 +51,8 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient,
{"maketechavailable", bind(&ClientCommandProcessor::makeTechAvailable, this, _1)},
{"enabletech", bind(&ClientCommandProcessor::enableTech, this, _1)},
{"upgradeship", bind(&ClientCommandProcessor::upgradeShip, this, _1)},
{"swap", bind(&ClientCommandProcessor::swap, this, _1)}
{"swap", bind(&ClientCommandProcessor::swap, this, _1)},
{"respawnInWorld", bind(&ClientCommandProcessor::respawnInWorld, this, _1)}
};
}
@ -186,7 +187,7 @@ String ClientCommandProcessor::setGravity(String const& argumentsString) {
return "You must be an admin to use this command.";
m_universeClient->worldClient()->overrideGravity(lexicalCast<float>(arguments.at(0)));
return strf("Gravity set to {}, the change is LOCAL ONLY", arguments.at(0));
return strf("Gravity set to {} (This is client-side!)", arguments.at(0));
}
String ClientCommandProcessor::resetGravity() {
@ -427,4 +428,16 @@ String ClientCommandProcessor::swap(String const& argumentsString) {
return "Failed to swap player";
}
String ClientCommandProcessor::respawnInWorld(String const& argumentsString) {
auto arguments = m_parser.tokenizeToStringList(argumentsString);
auto worldClient = m_universeClient->worldClient();
if (arguments.size() == 0)
return strf("Respawn in this world is currently {}", worldClient->respawnInWorld() ? "true" : "false");
bool respawnInWorld = Json::parse(arguments.at(0)).toBool();
worldClient->setRespawnInWorld(respawnInWorld);
return strf("Respawn in this world set to {} (This is client-side!)", respawnInWorld ? "true" : "false");
}
}

View File

@ -58,6 +58,7 @@ private:
String enableTech(String const& argumentsString);
String upgradeShip(String const& argumentsString);
String swap(String const& argumentsString);
String respawnInWorld(String const& argumentsString);
UniverseClientPtr m_universeClient;
CinematicPtr m_cinematicOverlay;

View File

@ -142,6 +142,10 @@ bool WorldClient::respawnInWorld() const {
return m_respawnInWorld;
}
void WorldClient::setRespawnInWorld(bool respawnInWorld) {
m_respawnInWorld = respawnInWorld;
}
void WorldClient::removeEntity(EntityId entityId, bool andDie) {
auto entity = m_entityMap->entity(entityId);
if (!entity)

View File

@ -108,6 +108,7 @@ public:
bool mainPlayerDead() const;
void reviveMainPlayer();
bool respawnInWorld() const;
void setRespawnInWorld(bool respawnInWorld);
void removeEntity(EntityId entityId, bool andDie);
@ -175,6 +176,9 @@ public:
typedef std::function<bool(PlayerPtr, StringView)> BroadcastCallback;
BroadcastCallback& broadcastCallback();
private:
static const float DropDist;