-
Notifications
You must be signed in to change notification settings - Fork 287
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
feat: adds a couple of new commands for GMs on games. #6183
Draft
Scoppio
wants to merge
5
commits into
MegaMek:master
Choose a base branch
from
Scoppio:feature/kill-command
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+798
−29
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7c4ab9b
feat: adds slash kill command for GMs
Scoppio f614557
feat: added nosmoke and change weather commands, disaster is currentl…
Scoppio f7d8a48
feat: added change ownership command, disaster is still WIP
Scoppio b797123
feat: added multiple GM commands, including kill, change planetary co…
Scoppio ffe5736
Merge branch 'master' into feature/kill-command
Scoppio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
megamek/src/megamek/server/commands/ChangeOwnershipCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This file is part of MegaMek. | ||
* | ||
* MegaMek is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MegaMek is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package megamek.server.commands; | ||
|
||
import megamek.common.Entity; | ||
import megamek.common.Player; | ||
import megamek.server.Server; | ||
import megamek.server.totalwarfare.TWGameManager; | ||
|
||
/** | ||
* The Server Command "/changeOwner" that will switch an entity's owner to another player. | ||
* | ||
* @author Luana Scoppio | ||
*/ | ||
public class ChangeOwnershipCommand extends ServerCommand implements IsGM { | ||
|
||
private final TWGameManager gameManager; | ||
|
||
public ChangeOwnershipCommand(Server server, TWGameManager gameManager) { | ||
super(server, | ||
"changeOwner", | ||
"Switches ownership of a player's entity to another player during the end phase. " | ||
+ "Usage: /changeOwner <Unit ID> <Player ID> " | ||
+ "The following is an example of changing unit ID 7 to player ID 2: /changeOwner 7 2 "); | ||
this.gameManager = gameManager; | ||
} | ||
|
||
/** | ||
* Run this command with the arguments supplied | ||
* | ||
* @see ServerCommand#run(int, String[]) | ||
*/ | ||
@Override | ||
public void run(int connId, String[] args) { | ||
try { | ||
if (!isGM(connId)) { | ||
server.sendServerChat(connId, "You are not a Game Master."); | ||
return; | ||
} | ||
|
||
int eid = Integer.parseInt(args[1]); | ||
Entity ent = gameManager.getGame().getEntity(eid); | ||
int pid = Integer.parseInt(args[2]); | ||
Player player = server.getGame().getPlayer(pid); | ||
if (null == ent) { | ||
server.sendServerChat(connId, "No such entity."); | ||
} else if (null == player) { | ||
server.sendServerChat(connId, "No such player."); | ||
} else if (player.getTeam() == Player.TEAM_UNASSIGNED) { | ||
server.sendServerChat(connId, "Player must be assigned a team."); | ||
} else { | ||
server.sendServerChat(connId, ent.getDisplayName() + " will switch to " + player.getName() + "'s side at the end of this turn."); | ||
ent.setTraitorId(pid); | ||
} | ||
} catch (NumberFormatException ignored) { | ||
} | ||
} | ||
|
||
@Override | ||
public TWGameManager getGameManager() { | ||
return gameManager; | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
megamek/src/megamek/server/commands/ChangeWeatherCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This file is part of MegaMek. | ||
* | ||
* MegaMek is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MegaMek is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package megamek.server.commands; | ||
|
||
import megamek.common.planetaryconditions.*; | ||
import megamek.server.Server; | ||
import megamek.server.totalwarfare.TWGameManager; | ||
|
||
|
||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* @author Luana Scoppio | ||
*/ | ||
public class ChangeWeatherCommand extends ServerCommand { | ||
|
||
private final TWGameManager gameManager; | ||
|
||
private static final String HELP_TEXT = "GM changes (weather) planetary conditions. The parameters are optional and unordered " + | ||
"and the effects are applied at the beginning of the next turn. The square brackets means that argument is optional. " + | ||
"Usage format: /weather [fog=0-2] [wind=0-6] [winddir=0-6] [light=0-6] [atmo=0-5] [blowsand=0-1] [weather=0-14] " + | ||
"light= 0: daylight, 1: dusk, 2: full moon, 3: glare, 4: moonless night, 5: solar flare, 6: pitch black " + | ||
"fog= 0: none, 1: light, 2: heavy " + | ||
"wind= 0: calm, 1: light gale, 2: moderate gale, 3: strong gale, 4: storm, 5: tornado F1-F3, 6: tornado F4 " + | ||
"winddir= 0: south, 1: southwest, 2: northwest, 3: north, 4: northeast, 5: southeast, 6: random " + | ||
"atmo= 0: vacuum, 1: trace, 2: thin, 3: standard, 4: high, 5: very high " + | ||
"blowsand= 0: no, 1: yes " + | ||
"weather= 0: clear, 1: light rain, 2: moderate rain, 3: heavy rain, 4: gusting rain, 5: downpour, 6: light snow " + | ||
"7: moderate snow, 8: snow flurries, 9: heavy snow, 10: sleet, 11: ice storm, 12: light hail, 13: heavy hail " + | ||
"14: lightning storm"; | ||
|
||
/** Creates new ChangeWeatherCommand */ | ||
public ChangeWeatherCommand(Server server, TWGameManager gameManager) { | ||
super(server, "weather", HELP_TEXT); | ||
this.gameManager = gameManager; | ||
} | ||
|
||
private void updatePlanetaryCondition(String arg, String prefix, int connId, int maxLength, Consumer<Integer> setter, | ||
Function<Integer, String> successMessage, Function<Integer, String> errorMessage) { | ||
var value = Integer.parseInt(arg.substring(prefix.length())); | ||
Check notice Code scanning / CodeQL Missing catch of NumberFormatException Note
Potential uncaught 'java.lang.NumberFormatException'.
|
||
if (value >= 0 && value < maxLength) { | ||
setter.accept(value); | ||
server.sendServerChat(connId, successMessage.apply(value)); | ||
} else { | ||
server.sendServerChat(connId, errorMessage.apply(maxLength)); | ||
} | ||
} | ||
|
||
private record Condition(int maxLength, Consumer<Integer> setter, Function<Integer, String> successMessage, Function<Integer, String> errorMessage) {} | ||
|
||
/** | ||
* Run this command with the arguments supplied | ||
*/ | ||
@Override | ||
public void run(int connId, String[] args) { | ||
if (!server.getPlayer(connId).getGameMaster()) { | ||
server.sendServerChat(connId, "You are not a Game Master."); | ||
return; | ||
} | ||
|
||
var planetaryConditions = gameManager.getGame().getPlanetaryConditions(); | ||
|
||
if (args.length > 1) { | ||
|
||
Map<String, Condition> conditions = Map.of( | ||
"fog=", new Condition(Fog.values().length, value -> planetaryConditions.setFog(Fog.values()[value]), | ||
value -> "The fog has changed.", maxLength -> "Invalid fog value. Must be between 0 and " + (maxLength - 1)), | ||
"wind=", new Condition(Wind.values().length, value -> planetaryConditions.setWind(Wind.values()[value]), | ||
value -> "The wind strength has changed.", maxLength -> "Invalid wind value. Must be between 0 and " + (maxLength - 1)), | ||
"winddir=", new Condition(WindDirection.values().length, value -> planetaryConditions.setWindDirection(WindDirection.values()[value]), | ||
value -> "The wind direction has changed.", maxLength -> "Invalid wind direction value. Must be between 0 and " + (maxLength - 1)), | ||
"light=", new Condition(Light.values().length, value -> planetaryConditions.setLight(Light.values()[value]), | ||
value -> "The light has changed.", maxLength -> "Invalid light value. Must be between 0 and " + (maxLength - 1)), | ||
"atmo=", new Condition(Atmosphere.values().length, value -> planetaryConditions.setAtmosphere(Atmosphere.values()[value]), | ||
value -> value == 0 ? "The air has vanished, put your vac suits!" : "The air is changing.", maxLength -> "Invalid atmosphere value. Must be between 0 and " + (maxLength - 1)), | ||
"blowsand=", new Condition(BlowingSand.values().length, value -> planetaryConditions.setBlowingSand(BlowingSand.values()[value]), | ||
value -> value == 1 ? "Sand started blowing." : "The sand has settled.", maxLength -> "Invalid blowsand value. Must be between 0 and " + (maxLength - 1)), | ||
"weather=", new Condition(Weather.values().length, value -> planetaryConditions.setWeather(Weather.values()[value]), | ||
value -> "The weather has changed.", maxLength -> "Invalid weather value. Must be between 0 and " + (maxLength - 1)) | ||
); | ||
|
||
Stream.of(args) | ||
.forEach(arg -> conditions.forEach((prefix, condition) -> { | ||
if (arg.startsWith(prefix)) { | ||
updatePlanetaryCondition(arg, prefix, connId, condition.maxLength, condition.setter, condition.successMessage, condition.errorMessage); | ||
} | ||
})); | ||
|
||
gameManager.getGame().setPlanetaryConditions(planetaryConditions); | ||
} else { | ||
// Error out; it's not a valid call. | ||
server.sendServerChat(connId, "weather command failed. " + HELP_TEXT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This file is part of MegaMek. | ||
* | ||
* MegaMek is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MegaMek is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package megamek.server.commands; | ||
|
||
import megamek.server.Server; | ||
import megamek.server.totalwarfare.TWGameManager; | ||
|
||
/** | ||
* @author Luana Scoppio | ||
*/ | ||
public class DisasterCommand extends ServerCommand { | ||
|
||
private final TWGameManager gameManager; | ||
|
||
/** Creates new DisasterCommand */ | ||
public DisasterCommand(Server server, TWGameManager gameManager) { | ||
super(server, "disaster", "GM calls a disaster at random, arguments in square brackets are optional. Usage: /disaster [type] " + | ||
"if not type is passed, one is chosen at random. " + | ||
"type= 0: hurricane, 1: lightning storm, 2: meteor shower, 3: orbital bombardment, 4: wildfire, 5: sandstorm, 6: hailstorm, " + | ||
"7: heatwave"); | ||
this.gameManager = gameManager; | ||
} | ||
|
||
/** | ||
* Run this command with the arguments supplied | ||
*/ | ||
@Override | ||
public void run(int connId, String[] args) { | ||
if (!server.getPlayer(connId).getGameMaster()) { | ||
server.sendServerChat(connId, "You are not a Game Master."); | ||
return; | ||
} | ||
|
||
// Check argument integrity. | ||
if (args.length == 1) { | ||
// Check command | ||
// NOT IMPLEMENTED | ||
server.sendServerChat(connId, "Oh no..."); | ||
} else if (args.length == 2) { | ||
// Error out; it's not a valid call. | ||
server.sendServerChat(connId, "Oh no..."); | ||
} else { | ||
server.sendServerChat(connId, "disaster command failed (1)."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package megamek.server.commands; | ||
|
||
import megamek.server.totalwarfare.TWGameManager; | ||
|
||
public interface IsGM { | ||
|
||
TWGameManager getGameManager(); | ||
|
||
default boolean isGM(int connId) { | ||
return getGameManager().getGame().getPlayer(connId).getGameMaster(); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest lumping this together with command line nukes. I doubt the distinction is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe one new specifically to enable/disable GM commands in game? Because now I have created 4 new GM-only commands, or maybe just not add the option at all, since you are turning yourself into a GM, requesting the blessing of the other players, maybe having access to all commands should be a given instead of having multiple flags blocking you from doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would go with "GM gets access to all GM commands by default". Nominally, the point is to give them access to various tools that let them arbitrarily alter the scenario as needed. The GM status itself already has some safeguards applied to prevent abuse (can't just activate it midgame without the players voting to allow it, etc.).