* Split cards improves:

* Fixed that fused spells can't be played from non hand zone;
 * Fixed double choose spell dialog (#5506, #6549);
This commit is contained in:
Oleg Agafonov 2020-05-19 01:30:46 +04:00
parent 6b5108770c
commit 63dbf5f40b
9 changed files with 1 additions and 190 deletions

View file

@ -1895,27 +1895,6 @@ public class ComputerPlayer extends PlayerImpl implements Player {
return 0; return 0;
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
switch (ability.getSpellAbilityType()) {
case SPLIT:
case SPLIT_FUSED:
case SPLIT_AFTERMATH:
MageObject object = game.getObject(ability.getSourceId());
if (object != null) {
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getSpellAbilities(playerId, object, game.getState().getZone(object.getId()), game);
if (useableAbilities != null && !useableAbilities.isEmpty()) {
// game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(useableAbilities.values()));
// TODO: Improve this
return (SpellAbility) useableAbilities.values().iterator().next();
}
}
return null;
default:
return ability;
}
}
@Override @Override
public Mode chooseMode(Modes modes, Ability source, Game game) { public Mode chooseMode(Modes modes, Ability source, Game game) {
log.debug("chooseMode"); log.debug("chooseMode");

View file

@ -1973,51 +1973,6 @@ public class HumanPlayer extends PlayerImpl {
return true; return true;
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
if (gameInCheckPlayableState(game)) {
return null;
}
// TODO: add canRespond cycle?
if (!canRespond()) {
return null;
}
switch (ability.getSpellAbilityType()) {
case SPLIT:
case SPLIT_FUSED:
case SPLIT_AFTERMATH:
MageObject object = game.getObject(ability.getSourceId());
if (object != null) {
String message = "Choose ability to cast" + (noMana ? " for FREE" : "") + "<br>" + object.getLogName();
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getSpellAbilities(playerId, object, game.getState().getZone(object.getId()), game);
if (useableAbilities != null
&& useableAbilities.size() == 1) {
return (SpellAbility) useableAbilities.values().iterator().next();
} else if (useableAbilities != null
&& !useableAbilities.isEmpty()) {
updateGameStatePriority("chooseSpellAbilityForCast", game);
prepareForResponse(game);
if (!isExecutingMacro()) {
game.fireGetChoiceEvent(playerId, message, object, new ArrayList<>(useableAbilities.values()));
}
waitForResponse(game);
if (response.getUUID() != null) {
if (useableAbilities.containsKey(response.getUUID())) {
return (SpellAbility) useableAbilities.get(response.getUUID());
}
}
}
}
return null;
default:
return ability;
}
}
@Override @Override
public SpellAbility chooseAbilityForCast(Card card, Game game, boolean nonMana) { public SpellAbility chooseAbilityForCast(Card card, Game game, boolean nonMana) {
if (gameInCheckPlayableState(game)) { if (gameInCheckPlayableState(game)) {

View file

@ -29,39 +29,6 @@ public class TestComputerPlayer extends ComputerPlayer {
this.testPlayerLink = testPlayerLink; this.testPlayerLink = testPlayerLink;
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
// copy-paste for TestComputerXXX
// workaround to cast fused cards in tests by it's NAMES (Wear, Tear, Wear // Tear)
// reason: TestPlayer uses outer computerPlayer to cast, not TestPlayer
switch (ability.getSpellAbilityType()) {
case SPLIT:
case SPLIT_FUSED:
case SPLIT_AFTERMATH:
if (!this.testPlayerLink.getChoices().isEmpty()) {
MageObject object = game.getObject(ability.getSourceId());
if (object != null) {
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getSpellAbilities(playerId, object, game.getState().getZone(object.getId()), game);
// left, right or fused cast
for (String choose : this.testPlayerLink.getChoices()) {
for (ActivatedAbility activatedAbility : useableAbilities.values()) {
if (activatedAbility instanceof SpellAbility) {
if (((SpellAbility) activatedAbility).getCardName().equals(choose)) {
return (SpellAbility) activatedAbility;
}
}
}
}
}
}
}
// default implementation by AI
return super.chooseSpellAbilityForCast(ability, game, noMana);
}
@Override @Override
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) { public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
// copy-paste for TestComputerXXX // copy-paste for TestComputerXXX

View file

@ -29,39 +29,6 @@ public class TestComputerPlayer7 extends ComputerPlayer7 {
this.testPlayerLink = testPlayerLink; this.testPlayerLink = testPlayerLink;
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
// copy-paste for TestComputerXXX
// workaround to cast fused cards in tests by it's NAMES (Wear, Tear, Wear // Tear)
// reason: TestPlayer uses outer computerPlayer to cast, not TestPlayer
switch (ability.getSpellAbilityType()) {
case SPLIT:
case SPLIT_FUSED:
case SPLIT_AFTERMATH:
if (!this.testPlayerLink.getChoices().isEmpty()) {
MageObject object = game.getObject(ability.getSourceId());
if (object != null) {
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getSpellAbilities(playerId, object, game.getState().getZone(object.getId()), game);
// left, right or fused cast
for (String choose : this.testPlayerLink.getChoices()) {
for (ActivatedAbility activatedAbility : useableAbilities.values()) {
if (activatedAbility instanceof SpellAbility) {
if (((SpellAbility) activatedAbility).getCardName().equals(choose)) {
return (SpellAbility) activatedAbility;
}
}
}
}
}
}
}
// default implementation by AI
return super.chooseSpellAbilityForCast(ability, game, noMana);
}
@Override @Override
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) { public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
// copy-paste for TestComputerXXX // copy-paste for TestComputerXXX

View file

@ -29,39 +29,6 @@ public class TestComputerPlayerMonteCarlo extends ComputerPlayerMCTS {
this.testPlayerLink = testPlayerLink; this.testPlayerLink = testPlayerLink;
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
// copy-paste for TestComputerXXX
// workaround to cast fused cards in tests by it's NAMES (Wear, Tear, Wear // Tear)
// reason: TestPlayer uses outer computerPlayer to cast, not TestPlayer
switch (ability.getSpellAbilityType()) {
case SPLIT:
case SPLIT_FUSED:
case SPLIT_AFTERMATH:
if (!this.testPlayerLink.getChoices().isEmpty()) {
MageObject object = game.getObject(ability.getSourceId());
if (object != null) {
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getSpellAbilities(playerId, object, game.getState().getZone(object.getId()), game);
// left, right or fused cast
for (String choose : this.testPlayerLink.getChoices()) {
for (ActivatedAbility activatedAbility : useableAbilities.values()) {
if (activatedAbility instanceof SpellAbility) {
if (((SpellAbility) activatedAbility).getCardName().equals(choose)) {
return (SpellAbility) activatedAbility;
}
}
}
}
}
}
}
// default implementation by AI
return super.chooseSpellAbilityForCast(ability, game, noMana);
}
@Override @Override
public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) { public boolean choose(Outcome outcome, Target target, UUID sourceId, Game game) {
// copy-paste for TestComputerXXX // copy-paste for TestComputerXXX

View file

@ -3456,12 +3456,6 @@ public class TestPlayer implements Player {
computerPlayer.cleanUpOnMatchEnd(); computerPlayer.cleanUpOnMatchEnd();
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
Assert.fail("That's method must calls only from computerPlayer->cast(), see TestComputerPlayerXXX");
return computerPlayer.chooseSpellAbilityForCast(ability, game, noMana);
}
@Override @Override
public void skip() { public void skip() {
computerPlayer.skip(); computerPlayer.skip();

View file

@ -543,11 +543,6 @@ public class PlayerStub implements Player {
return false; return false;
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
return null;
}
@Override @Override
public boolean putInHand(Card card, Game game) { public boolean putInHand(Card card, Game game) {
return false; return false;

View file

@ -317,8 +317,6 @@ public interface Player extends MageItem, Copyable<Player> {
boolean cast(SpellAbility ability, Game game, boolean noMana, MageObjectReference reference); boolean cast(SpellAbility ability, Game game, boolean noMana, MageObjectReference reference);
SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana);
SpellAbility chooseAbilityForCast(Card card, Game game, boolean noMana); SpellAbility chooseAbilityForCast(Card card, Game game, boolean noMana);
boolean putInHand(Card card, Game game); boolean putInHand(Card card, Game game);

View file

@ -1120,13 +1120,7 @@ public abstract class PlayerImpl implements Player, Serializable {
SpellAbility ability = originalAbility.copy(); SpellAbility ability = originalAbility.copy();
ability.setControllerId(getId()); ability.setControllerId(getId());
ability.setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(ability.getSourceId())); ability.setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(ability.getSourceId()));
if (ability.getSpellAbilityType() != SpellAbilityType.BASE) {
ability = chooseSpellAbilityForCast(ability, game, noMana);
if (ability == null) {
// No ability could be cast (selected), probably because of no valid targets (happens often if a card can be cast by an effect).
return false;
}
}
//20091005 - 601.2a //20091005 - 601.2a
if (ability.getSourceId() == null) { if (ability.getSourceId() == null) {
logger.error("Ability without sourceId turn " + game.getTurnNum() + ". Ability: " + ability.getRule()); logger.error("Ability without sourceId turn " + game.getTurnNum() + ". Ability: " + ability.getRule());
@ -1189,11 +1183,6 @@ public abstract class PlayerImpl implements Player, Serializable {
return false; return false;
} }
@Override
public SpellAbility chooseSpellAbilityForCast(SpellAbility ability, Game game, boolean noMana) {
return ability;
}
@Override @Override
public boolean playLand(Card card, Game game, boolean ignoreTiming) { public boolean playLand(Card card, Game game, boolean ignoreTiming) {
// Check for alternate casting possibilities: e.g. land with Morph // Check for alternate casting possibilities: e.g. land with Morph