|
|
@@ -0,0 +1,83 @@
|
|
|
+#include "ModeCommand.h"
|
|
|
+
|
|
|
+#include "Chat.h"
|
|
|
+#include "Game.h"
|
|
|
+#include "Player.h"
|
|
|
+
|
|
|
+ModeCommand::ModeCommand()
|
|
|
+ : ChatCommand(
|
|
|
+ "gamemode", "sets the gamemode to 0 (normal) or 1 (cheats)", 10)
|
|
|
+{
|
|
|
+ addParam(new PlayerNameParameter(true));
|
|
|
+ addParam(new IntegerParameter("mode",
|
|
|
+ "0 (normal) or 1 (cheats)",
|
|
|
+ false,
|
|
|
+ [](Entity* actor) {
|
|
|
+ if (actor) return dynamic_cast<Player*>(actor)->getGameMode();
|
|
|
+ return 0;
|
|
|
+ }));
|
|
|
+}
|
|
|
+
|
|
|
+bool ModeCommand::execute(
|
|
|
+ Framework::RCArray<Framework::Text>& params, Entity* zActor) const
|
|
|
+{
|
|
|
+ if (zActor && params.getEntryCount() == 1)
|
|
|
+ {
|
|
|
+ Player* p = dynamic_cast<Player*>(zActor);
|
|
|
+ int mode = (int)*params.z(0);
|
|
|
+ if (mode < 0 || mode > 1)
|
|
|
+ {
|
|
|
+ Framework::Text message = "Usage: gamemode [<playerName>] <0/1>";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ message = "gamemode must be 0 or 1";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ p->setGameMode(mode);
|
|
|
+ Framework::Text message = "gamemode for player ";
|
|
|
+ message.append() << p->getName() << " is now set to " << mode;
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ }
|
|
|
+ else if (params.getEntryCount() == 2)
|
|
|
+ {
|
|
|
+ Player* p = Game::INSTANCE->zPlayerByName(*params.z(0));
|
|
|
+ if (!p)
|
|
|
+ {
|
|
|
+ Framework::Text message = "Usage: gamemode [<playerName>] <0/1>";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ message = "";
|
|
|
+ message.append() << "Player " << *params.z(0) << " not found";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int mode = (int)*params.z(1);
|
|
|
+ if (mode < 0 || mode > 1)
|
|
|
+ {
|
|
|
+ Framework::Text message = "Usage: gamemode [<playerName>] <0/1>";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ message = "gamemode must be 0 or 1";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ p->setGameMode(mode);
|
|
|
+ Framework::Text message = "gamemode for player ";
|
|
|
+ message.append() << p->getName() << " is now set to " << mode;
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Framework::Text message = "Usage: gamemode [<playerName>] <0/1>";
|
|
|
+ Game::INSTANCE->zChat()->sendMessageTo(
|
|
|
+ message, zActor, Chat::CHANNEL_INFO);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|