Improved Word of Command turn control handling

This commit is contained in:
L_J 2018-06-04 01:32:17 +02:00 committed by GitHub
parent b7c6afc66d
commit 492c5ab63e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 57 deletions

View file

@ -33,10 +33,6 @@ public class LoseControlOnOtherPlayersControllerEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.resetOtherTurnsControlled();
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
targetPlayer.setGameUnderYourControl(true);
}
return true;
}
return false;

View file

@ -393,6 +393,8 @@ public interface Game extends MageItem, Serializable {
boolean checkStateAndTriggered();
void playPriority(UUID activePlayerId, boolean resuming);
void resetControlAfterSpellResolve(Spell spell);
boolean endTurn(Ability source);

View file

@ -1395,7 +1395,13 @@ public abstract class GameImpl implements Game, Serializable {
StackObject top = null;
try {
top = state.getStack().peek();
top.resolve(this);
Spell topSpell = getSpell(top.getId());
if (topSpell != null) {
top.resolve(this);
resetControlAfterSpellResolve(topSpell);
} else {
top.resolve(this);
}
} finally {
if (top != null) {
state.getStack().remove(top, this); // seems partly redundant because move card from stack to grave is already done and the stack removed
@ -1409,6 +1415,31 @@ public abstract class GameImpl implements Game, Serializable {
}
}
}
@Override
public void resetControlAfterSpellResolve(Spell spell) {
// for Word of Command
if (spell.getCommandedBy() != null) {
UUID commandedBy = spell.getCommandedBy();
UUID spellControllerId = null;
if (commandedBy.equals(spell.getControllerId())) {
spellControllerId = spell.getSpellAbility().getFirstTarget(); // i.e. resolved spell is Word of Command
} else {
spellControllerId = spell.getControllerId(); // i.e. resolved spell is the target opponent's spell
}
if (commandedBy != null && spellControllerId != null) {
Player turnController = getPlayer(commandedBy);
if (turnController != null) {
Player targetPlayer = getPlayer(spellControllerId);
if (targetPlayer != null) {
informPlayers(turnController.getLogName() + " lost control over " + targetPlayer.getLogName());
turnController.resetOtherTurnsControlled();
targetPlayer.setGameUnderYourControl(true);
}
}
}
}
}
/**
* This checks if the stack gets filled iterated, without ever getting empty

View file

@ -36,7 +36,13 @@ public class SpellStack extends ArrayDeque<StackObject> {
StackObject top = null;
try {
top = this.peek();
top.resolve(game);
Spell topSpell = getSpell(top.getId());
if (topSpell != null) {
top.resolve(game);
game.resetControlAfterSpellResolve(topSpell);
} else {
top.resolve(game);
}
} finally {
if (top != null) {
if (contains(top)) {