mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
fixed AI targeting cards with Hexproof
This commit is contained in:
parent
5c0adadbc7
commit
39404820de
7 changed files with 21 additions and 19 deletions
|
@ -74,7 +74,7 @@ public interface Permanent extends Card {
|
|||
|
||||
public UUID getControllerId();
|
||||
public boolean changeControllerId(UUID controllerId, Game game);
|
||||
public boolean canBeTargetedBy(MageObject source);
|
||||
public boolean canBeTargetedBy(MageObject source, UUID controllerId, Game game);
|
||||
public boolean hasProtectionFrom(MageObject source);
|
||||
public boolean hasSummoningSickness();
|
||||
public int getDamage();
|
||||
|
|
|
@ -647,11 +647,13 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeTargetedBy(MageObject source) {
|
||||
public boolean canBeTargetedBy(MageObject source, UUID sourceControllerId, Game game) {
|
||||
if (source != null) {
|
||||
if (abilities.containsKey(ShroudAbility.getInstance().getId()))
|
||||
return false;
|
||||
|
||||
if (abilities.containsKey(HexproofAbility.getInstance().getId()))
|
||||
if (game.getOpponents(controllerId).contains(sourceControllerId))
|
||||
return false;
|
||||
if (hasProtectionFrom(source))
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -85,8 +85,8 @@ public class TargetPermanent<T extends TargetPermanent<T>> extends TargetObject<
|
|||
//2. We need to check both source.getId() and source.getSourceId()
|
||||
// first for protection from spells or abilities (e.g. protection from colored spells, r1753)
|
||||
// second for protection from sources (e.g. protection from artifacts + equip ability)
|
||||
return permanent.canBeTargetedBy(game.getObject(source.getId()))
|
||||
&& permanent.canBeTargetedBy(game.getObject(source.getSourceId()))
|
||||
return permanent.canBeTargetedBy(game.getObject(source.getId()), controllerId, game)
|
||||
&& permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game)
|
||||
&& filter.match(permanent, source.getSourceId(), controllerId, game);
|
||||
else
|
||||
return filter.match(permanent, null, controllerId, game);
|
||||
|
@ -124,7 +124,7 @@ public class TargetPermanent<T extends TargetPermanent<T>> extends TargetObject<
|
|||
int count = 0;
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource)) {
|
||||
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= remainingTargets)
|
||||
return true;
|
||||
|
@ -164,7 +164,7 @@ public class TargetPermanent<T extends TargetPermanent<T>> extends TargetObject<
|
|||
Set<UUID> possibleTargets = new HashSet<UUID>();
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource)) {
|
||||
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
|
|||
if (permanent != null) {
|
||||
if (source != null)
|
||||
//TODO: check for replacement effects
|
||||
return permanent.canBeTargetedBy(game.getObject(source.getSourceId())) && filter.match(permanent, source.getSourceId(), controllerId, game);
|
||||
return permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game) && filter.match(permanent, source.getSourceId(), controllerId, game);
|
||||
else
|
||||
return filter.match(permanent, source.getSourceId(), controllerId, game);
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
|
@ -183,7 +183,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
|
|||
MageObject targetSource = game.getObject(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
if (source != null)
|
||||
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
|
||||
return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
|
||||
else
|
||||
return filter.match(permanent);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
|
@ -152,7 +152,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class TargetDefender extends TargetImpl<TargetDefender> {
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
|
@ -133,7 +133,7 @@ public class TargetDefender extends TargetImpl<TargetDefender> {
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class TargetDefender extends TargetImpl<TargetDefender> {
|
|||
}
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent);
|
||||
return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
|
|||
MageObject targetSource = game.getObject(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
if (source != null)
|
||||
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
|
||||
return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game);
|
||||
else
|
||||
return filter.match(permanent);
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
|
@ -193,7 +193,7 @@ public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer>
|
|||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue