-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added change ownership command, disaster is still WIP
- Loading branch information
Showing
5 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
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,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) { | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -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. | ||
|
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 |
---|---|---|
@@ -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. | ||
|
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 |
---|---|---|
@@ -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. | ||
|
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