-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
181 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program 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 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program 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. | ||
*/ | ||
package megamek.server.commands; | ||
|
||
import megamek.client.ui.Messages; | ||
import megamek.common.Coords; | ||
import megamek.common.Hex; | ||
import megamek.server.Server; | ||
import megamek.server.commands.arguments.Argument; | ||
import megamek.server.commands.arguments.IntegerArgument; | ||
import megamek.server.totalwarfare.TWGameManager; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* The Server Command "/firefight" that will put one hex on fire. | ||
* | ||
* @author Luana Coppio | ||
*/ | ||
public class FirefightCommand extends GamemasterServerCommand { | ||
|
||
private static final String FIRESTARTER = "firefight"; | ||
private static final String X = "x"; | ||
private static final String Y = "y"; | ||
private static final String TYPE = "type"; | ||
|
||
public FirefightCommand(Server server, TWGameManager gameManager) { | ||
super(server, | ||
gameManager, | ||
FIRESTARTER, | ||
Messages.getString("Gamemaster.cmd.firefight.help"), | ||
Messages.getString("Gamemaster.cmd.firefight.longName")); | ||
} | ||
|
||
@Override | ||
public List<Argument<?>> defineArguments() { | ||
return List.of( | ||
new IntegerArgument(X, Messages.getString("Gamemaster.cmd.x")), | ||
new IntegerArgument(Y, Messages.getString("Gamemaster.cmd.y")) | ||
); | ||
} | ||
|
||
/** | ||
* Run this command with the arguments supplied | ||
* | ||
* @see ServerCommand#run(int, String[]) | ||
*/ | ||
@Override | ||
protected void runAsGM(int connId, Map<String, Argument<?>> args) { | ||
int xArg = (int) args.get(X).getValue() - 1; | ||
int yArg = (int) args.get(Y).getValue() - 1; | ||
firefight(new Coords(xArg, yArg)); | ||
} | ||
|
||
private void firefight(Coords coords) { | ||
try { | ||
Hex hex = gameManager.getGame().getBoard().getHex(coords); | ||
Objects.requireNonNull(hex, "Hex not found."); | ||
gameManager.removeFire(coords, Messages.getString("Gamemaster.cmd.firefight.reason")); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Failed to ignite hex: " + e.getMessage()); | ||
} | ||
} | ||
} |
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,87 @@ | ||
/* | ||
* MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This program 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 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program 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. | ||
*/ | ||
package megamek.server.commands; | ||
|
||
import megamek.client.ui.Messages; | ||
import megamek.common.Coords; | ||
import megamek.common.Hex; | ||
import megamek.server.Server; | ||
import megamek.server.commands.arguments.Argument; | ||
import megamek.server.commands.arguments.IntegerArgument; | ||
import megamek.server.totalwarfare.TWGameManager; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* The Server Command "/nofires" removes all fires on the board. | ||
* | ||
* @author Luana Coppio | ||
*/ | ||
public class NoFiresCommand extends GamemasterServerCommand { | ||
|
||
private final String reason; | ||
|
||
public NoFiresCommand(Server server, TWGameManager gameManager) { | ||
super(server, | ||
gameManager, | ||
"nofires", | ||
Messages.getString("Gamemaster.cmd.nofire.help"), | ||
Messages.getString("Gamemaster.cmd.nofire.longName")); | ||
this.reason = Messages.getString("Gamemaster.cmd.firefight.reason"); | ||
} | ||
|
||
@Override | ||
public List<Argument<?>> defineArguments() { | ||
return List.of(); | ||
} | ||
|
||
/** | ||
* Run this command with the arguments supplied | ||
* | ||
* @see ServerCommand#run(int, String[]) | ||
*/ | ||
@Override | ||
protected void runAsGM(int connId, Map<String, Argument<?>> args) { | ||
try { | ||
getAllCoords().forEach(this::firefight); | ||
} catch (Exception e) { | ||
logger.error(Messages.getString("Gamemaster.cmd.fire.failed"), e); | ||
server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.fire.failed")); | ||
} | ||
} | ||
|
||
private HashSet<Coords> getAllCoords() { | ||
var boardHeight = gameManager.getGame().getBoard().getHeight(); | ||
var boardWidth = gameManager.getGame().getBoard().getWidth(); | ||
var coordsSet = new HashSet<Coords>(); | ||
for (int x = 0; x < boardWidth; x++) { | ||
for (int y = 0; y < boardHeight; y++) { | ||
coordsSet.add(new Coords(x, y)); | ||
} | ||
} | ||
return coordsSet; | ||
} | ||
|
||
private void firefight(Coords coords) { | ||
Hex hex = gameManager.getGame().getBoard().getHex(coords); | ||
if (null == hex) { | ||
// Just ignore null hexes... | ||
// they should not happen, but I don't want to crash the command | ||
return; | ||
} | ||
gameManager.removeFire(coords, reason); | ||
} | ||
} |
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