diff --git a/megamek/src/megamek/server/commands/ChangeOwnershipCommand.java b/megamek/src/megamek/server/commands/ChangeOwnershipCommand.java new file mode 100644 index 00000000000..48691c02742 --- /dev/null +++ b/megamek/src/megamek/server/commands/ChangeOwnershipCommand.java @@ -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 . + */ +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 " + + "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) { + } + } + +} diff --git a/megamek/src/megamek/server/commands/ChangeWeatherCommand.java b/megamek/src/megamek/server/commands/ChangeWeatherCommand.java index 4eccef2e475..f18c5926e17 100644 --- a/megamek/src/megamek/server/commands/ChangeWeatherCommand.java +++ b/megamek/src/megamek/server/commands/ChangeWeatherCommand.java @@ -1,5 +1,4 @@ /* - * Copyright (C) 2024 Luana Scoppio (luana.coppio@gmail.com) * Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. * * This file is part of MegaMek. diff --git a/megamek/src/megamek/server/commands/DisasterCommand.java b/megamek/src/megamek/server/commands/DisasterCommand.java index acee28bce21..0a7137cd88b 100644 --- a/megamek/src/megamek/server/commands/DisasterCommand.java +++ b/megamek/src/megamek/server/commands/DisasterCommand.java @@ -1,5 +1,4 @@ /* - * Copyright (C) 2024 Luana Scoppio (luana.coppio@gmail.com) * Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. * * This file is part of MegaMek. diff --git a/megamek/src/megamek/server/commands/KillCommand.java b/megamek/src/megamek/server/commands/KillCommand.java index 387dbb855c7..837bcce266e 100644 --- a/megamek/src/megamek/server/commands/KillCommand.java +++ b/megamek/src/megamek/server/commands/KillCommand.java @@ -1,5 +1,4 @@ /* - * Copyright (C) 2024 Luana Scoppio (luana.coppio@gmail.com) * Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. * * This file is part of MegaMek. diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 13065fedbd0..95aabd23203 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -188,6 +188,8 @@ public List 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));