* Game: tiny leaders game mode improves (fixed AI games errors, fixed commander dupes on game restart with Karn Liberated, #6113);

This commit is contained in:
Oleg Agafonov 2021-07-24 14:24:17 +04:00
parent c1db466d05
commit ac8d3de474
8 changed files with 75 additions and 33 deletions

View file

@ -15,6 +15,7 @@ import mage.constants.*;
import mage.game.mulligan.Mulligan;
import mage.game.turn.TurnMod;
import mage.players.Player;
import mage.util.CardUtil;
import mage.watchers.common.CommanderInfoWatcher;
import mage.watchers.common.CommanderPlaysCountWatcher;
@ -50,27 +51,36 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId);
if (player != null) {
Card commander = getCommanderCard(player.getMatchPlayer().getDeck().getName(), player.getId());
String commanderName = player.getMatchPlayer().getDeck().getName();
Card commander = findCommander(this, player, commanderName);
if (commander != null) {
Set<Card> cards = new HashSet<>();
cards.add(commander);
this.loadCards(cards, playerId);
player.addCommanderId(commander.getId());
// already exists - just move to zone (example: game restart by Karn Liberated)
commander.moveToZone(Zone.COMMAND, null, this, true);
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary, false, "Commander"));
ability.addEffect(new CommanderCostModification(commander));
// Commander rule #4 was removed Jan. 18, 2016
// ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
CommanderInfoWatcher watcher = new CommanderInfoWatcher("Commander", commander.getId(), false);
getState().addWatcher(watcher);
watcher.addCardInfoToCommander(this);
this.getState().addAbility(ability, null);
} else {
throw new UnknownError("Commander card could not be created. Name: [" + player.getMatchPlayer().getDeck().getName() + ']');
// create new commander
commander = getCommanderCard(commanderName, player.getId());
if (commander != null) {
Set<Card> cards = new HashSet<>();
cards.add(commander);
this.loadCards(cards, playerId);
player.addCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true);
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary, false, "Commander"));
ability.addEffect(new CommanderCostModification(commander));
// Commander rule #4 was removed Jan. 18, 2016
// ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
CommanderInfoWatcher watcher = new CommanderInfoWatcher("Commander", commander.getId(), false);
getState().addWatcher(watcher);
watcher.addCardInfoToCommander(this);
this.getState().addAbility(ability, null);
} else {
// TODO: can't see that error in game logs at all, wtf? See GameWorker.call
// Test use case: create tiny game with random generated deck - game freezes with empty battlefield
throw new IllegalStateException("Commander card could not be created. Name: [" + player.getMatchPlayer().getDeck().getName() + ']');
}
}
}
}
super.init(choosingPlayerId);
if (startingPlayerSkipsDraw) {
@ -78,6 +88,14 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
}
}
private Card findCommander(Game game, Player player, String commanderName) {
return game.getCommanderCardsFromAnyZones(player, CommanderCardType.ANY, Zone.ALL)
.stream()
.filter(c -> CardUtil.haveSameNames(c, commanderName, game))
.findFirst()
.orElse(null);
}
/**
* Name of Tiny Leader comes from the deck name (it's not in the sideboard)
* Additionally, it was taken into account that WOTC had missed a few color

View file

@ -12,18 +12,15 @@ import java.io.Serializable;
*/
public class MatchPlayer implements Serializable {
private static final long serialVersionUID = 42L;
private int wins;
private int winsNeeded;
private boolean matchWinner;
private Deck deck;
private Player player;
private final String name;
private String name;
private boolean quit;
//private final boolean timerTimeout;
private boolean doneSideboarding;
private int priorityTimeLeft;
@ -34,11 +31,29 @@ public class MatchPlayer implements Serializable {
this.winsNeeded = match.getWinsNeeded();
this.doneSideboarding = true;
this.quit = false;
//this.timerTimeout = false;
this.name = player.getName();
this.matchWinner = false;
}
/**
* Create match player's copy for simulated/ai games,
* so game and cards can get access to player's deck
*
* @param newPlayer
* @return
*/
public MatchPlayer(final MatchPlayer source, Player newPlayer) {
this.wins = source.wins;
this.winsNeeded = source.winsNeeded;
this.matchWinner = source.matchWinner;
this.deck = source.deck;
this.player = newPlayer; // new
this.name = newPlayer.getName(); // new
this.quit = source.quit;
this.doneSideboarding = source.doneSideboarding;
this.priorityTimeLeft = source.priorityTimeLeft;
}
public int getPriorityTimeLeft() {
return priorityTimeLeft;
}

View file

@ -245,6 +245,8 @@ public abstract class PlayerImpl implements Player, Serializable {
this.inRange.addAll(player.inRange);
this.userData = player.userData;
this.matchPlayer = player.matchPlayer;
this.canPayLifeCost = player.canPayLifeCost;
this.sacrificeCostFilter = player.sacrificeCostFilter;
this.alternativeSourceCosts.addAll(player.alternativeSourceCosts);