* Fixed some problems with blocking requirements (fixes #355).

This commit is contained in:
LevelX2 2013-10-08 17:12:04 +02:00
parent 2dd26a9075
commit db1521d30c
8 changed files with 24 additions and 12 deletions

View file

@ -91,7 +91,7 @@ class RevengeOfTheHuntedEffect extends RequirementEffect<RevengeOfTheHuntedEffec
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
return true;
return permanent.canBlock(source.getFirstTarget(), game);
}
@Override

View file

@ -92,10 +92,9 @@ class FeralContestEffect extends RequirementEffect<FeralContestEffect> {
}
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (creature != null) {
return true;
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getTargets().get(1).getFirstTarget())) {
return permanent.canBlock(source.getFirstTarget(), game);
}
return false;
}

View file

@ -96,7 +96,10 @@ class GrapplingHookEffect extends RequirementEffect<GrapplingHookEffect> {
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getFirstTarget())) {
return true;
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
return permanent.canBlock(equipment.getAttachedTo(), game);
}
}
return false;
}

View file

@ -60,6 +60,10 @@ public class MustBeBlockedByAllAttachedEffect extends RequirementEffect<MustBeBl
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment != null && attachment.getAttachedTo() != null) {
return permanent.canBlock(attachment.getAttachedTo(), game);
}
return true;
}

View file

@ -56,7 +56,7 @@ public class MustBeBlockedByAllSourceEffect extends RequirementEffect<MustBeBloc
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
return true;
return permanent.canBlock(source.getSourceId(), game);
}
@Override

View file

@ -56,9 +56,11 @@ public class MustBeBlockedByTargetSourceEffect extends RequirementEffect<MustBeB
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
Permanent creature = game.getPermanent(source.getFirstTarget());
if (creature != null && creature.getId().equals(permanent.getId())) {
return true;
if (permanent.getId().equals(source.getFirstTarget())) {
Permanent blocker = game.getPermanent(source.getFirstTarget());
if (blocker != null && blocker.canBlock(source.getSourceId(), game)) {
return true;
}
}
return false;
}

View file

@ -374,7 +374,7 @@ public class Combat implements Serializable, Copyable<Combat> {
* and the requirement, so that's the only option.
*/
for (Permanent creature : game.getBattlefield().getActivePermanents(filterBlockers, player.getId(), game)) {
if (game.getOpponents(attackerId).contains(creature.getControllerId())) {
if (game.getOpponents(attackerId).contains(creature.getControllerId())) {
for (Map.Entry entry : game.getContinuousEffects().getApplicableRequirementEffects(creature, game).entrySet()) {
RequirementEffect effect = (RequirementEffect)entry.getKey();
if (effect.mustBlock(game)) {
@ -400,7 +400,7 @@ public class Combat implements Serializable, Copyable<Combat> {
}
public boolean checkBlockRequirementsAfter(Player player, Player controller, Game game) {
// Get one time a list of all opponents in range
// Get once a list of all opponents in range
Set<UUID> opponents = game.getOpponents(attackerId);
//20101001 - 509.1c
// map with attackers (UUID) that must be blocked by at least one blocker and a set of all creatures that can block it and don't block yet

View file

@ -869,6 +869,10 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
return false;
}
Permanent attacker = game.getPermanent(attackerId);
// controller of attacking permanent must be an opponent
if (!game.getOpponents(this.getControllerId()).contains(attacker.getControllerId())) {
return false;
}
//20101001 - 509.1b
for (Map.Entry entry: game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
RestrictionEffect effect = (RestrictionEffect)entry.getKey();