Tibalt, Cosmic Impostor - fixed that emblem can't cast not owned cards (#7598)

* Fixed ability.canChooseTarget not using correct playerId

* Fixed Necrotic Plague

* Revert "Fixed Necrotic Plague"

This reverts commit 7659039670.

* Set target controller on Necrotic Plague and add check in canChooseTarget

* Add test for Tibalt + Ephemerate interaction

* Tests improved

Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
This commit is contained in:
Daniel Bomar 2021-02-22 13:06:43 -06:00 committed by GitHub
parent b94af941df
commit bb0a995541
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 84 additions and 31 deletions

View file

@ -901,24 +901,36 @@ public abstract class AbilityImpl implements Ability {
}
@Override
public boolean canChooseTarget(Game game) {
public boolean canChooseTarget(Game game, UUID playerId) {
if (this instanceof SpellAbility) {
if (SpellAbilityType.SPLIT_FUSED.equals(((SpellAbility) this).getSpellAbilityType())) {
Card card = game.getCard(getSourceId());
if (card != null) {
return canChooseTargetAbility(((SplitCard) card).getLeftHalfCard().getSpellAbility(), game, getControllerId())
&& canChooseTargetAbility(((SplitCard) card).getRightHalfCard().getSpellAbility(), game, getControllerId());
return canChooseTargetAbility(((SplitCard) card).getLeftHalfCard().getSpellAbility(), game, playerId)
&& canChooseTargetAbility(((SplitCard) card).getRightHalfCard().getSpellAbility(), game, playerId);
}
return false;
}
}
return canChooseTargetAbility(this, game, getControllerId());
return canChooseTargetAbility(this, game, playerId);
}
private static boolean canChooseTargetAbility(Ability ability, Game game, UUID controllerId) {
int found = 0;
for (Mode mode : ability.getModes().values()) {
if (mode.getTargets().canChoose(ability.getSourceId(), ability.getControllerId(), game)) {
boolean validTargets = true;
for (Target target : mode.getTargets()) {
UUID abilityControllerId = controllerId;
if (target.getTargetController() != null) {
abilityControllerId = target.getTargetController();
}
if (!target.canChoose(ability.getSourceId(), abilityControllerId, game)) {
validTargets = false;
break;
}
}
if (validTargets) {
found++;
if (ability.getModes().isEachModeMoreThanOnce()) {
return true;