Skip to content

Commit

Permalink
feat: added change ownership command, disaster is still WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Nov 6, 2024
1 parent f614557 commit f7d8a48
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
76 changes: 76 additions & 0 deletions megamek/src/megamek/server/commands/ChangeOwnershipCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 {

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 {
var currentPlayer = server.getGame().getPlayer(connId);
if (!currentPlayer.isGameMaster()) {
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) {
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright (C) 2024 Luana Scoppio ([email protected])
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
Expand Down
1 change: 0 additions & 1 deletion megamek/src/megamek/server/commands/DisasterCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright (C) 2024 Luana Scoppio ([email protected])
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
Expand Down
1 change: 0 additions & 1 deletion megamek/src/megamek/server/commands/KillCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* Copyright (C) 2024 Luana Scoppio ([email protected])
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
Expand Down
2 changes: 2 additions & 0 deletions megamek/src/megamek/server/totalwarfare/TWGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ public List<ServerCommand> getCommandList(Server server) {
commands.add(new CheckBVTeamCommand(server));
commands.add(new NukeCommand(server, this));
commands.add(new KillCommand(server, this));
commands.add(new ChangeOwnershipCommand(server, this));
commands.add(new DisasterCommand(server, this));
commands.add(new RemoveSmokeCommand(server, this));
commands.add(new ChangeWeatherCommand(server, this));
commands.add(new TraitorCommand(server, this));
Expand Down

0 comments on commit f7d8a48

Please sign in to comment.