mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Rewrote a lot of code
...to handle multiple conflicting instances of Master Warcraft (still yet to rewrite the blocker effect)
This commit is contained in:
parent
6400a401d4
commit
e65eefe5ab
1 changed files with 60 additions and 26 deletions
|
@ -32,6 +32,7 @@ import mage.abilities.Ability;
|
||||||
import mage.abilities.Mode;
|
import mage.abilities.Mode;
|
||||||
import mage.abilities.common.CastOnlyDuringPhaseStepSourceAbility;
|
import mage.abilities.common.CastOnlyDuringPhaseStepSourceAbility;
|
||||||
import mage.abilities.condition.common.BeforeAttackersAreDeclaredCondition;
|
import mage.abilities.condition.common.BeforeAttackersAreDeclaredCondition;
|
||||||
|
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.effects.ReplacementEffectImpl;
|
import mage.abilities.effects.ReplacementEffectImpl;
|
||||||
import mage.abilities.effects.RequirementEffect;
|
import mage.abilities.effects.RequirementEffect;
|
||||||
|
@ -80,11 +81,11 @@ public class MasterWarcraft extends CardImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MasterWarcraftChooseAttackersEffect extends ReplacementEffectImpl {
|
class MasterWarcraftChooseAttackersEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
|
|
||||||
public MasterWarcraftChooseAttackersEffect() {
|
public MasterWarcraftChooseAttackersEffect() {
|
||||||
super(Duration.EndOfTurn, Outcome.Benefit);
|
super(Duration.EndOfTurn, Outcome.Benefit, false, false);
|
||||||
this.staticText = "You choose which creatures attack this turn";
|
staticText = "You choose which creatures attack this turn";
|
||||||
}
|
}
|
||||||
|
|
||||||
public MasterWarcraftChooseAttackersEffect(final MasterWarcraftChooseAttackersEffect effect) {
|
public MasterWarcraftChooseAttackersEffect(final MasterWarcraftChooseAttackersEffect effect) {
|
||||||
|
@ -101,15 +102,6 @@ class MasterWarcraftChooseAttackersEffect extends ReplacementEffectImpl {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
|
||||||
Player chooser = game.getPlayer(source.getControllerId());
|
|
||||||
if (chooser != null) {
|
|
||||||
new MasterWarcraftAttackEffect().apply(game, source); // Master Warcraft imposes its effect right before the attackers being declared...
|
|
||||||
}
|
|
||||||
return false; // ...and then resumes the attack declaration
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checksEventType(GameEvent event, Game game) {
|
public boolean checksEventType(GameEvent event, Game game) {
|
||||||
return event.getType() == GameEvent.EventType.DECLARING_ATTACKERS;
|
return event.getType() == GameEvent.EventType.DECLARING_ATTACKERS;
|
||||||
|
@ -120,9 +112,19 @@ class MasterWarcraftChooseAttackersEffect extends ReplacementEffectImpl {
|
||||||
Player chooser = game.getPlayer(source.getControllerId());
|
Player chooser = game.getPlayer(source.getControllerId());
|
||||||
Player attackingPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
|
Player attackingPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
|
||||||
if (chooser != null && attackingPlayer != null && !attackingPlayer.getAvailableAttackers(game).isEmpty()) {
|
if (chooser != null && attackingPlayer != null && !attackingPlayer.getAvailableAttackers(game).isEmpty()) {
|
||||||
return true;
|
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) {
|
||||||
|
// Clears previous instances of "should attack" effects
|
||||||
|
// ("shouldn't attack" effects don't need cleaning because MasterWarcraftMustAttackRequirementEffect overrides them)
|
||||||
|
for (Map.Entry<RequirementEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRequirementEffects(permanent, false, game).entrySet()) {
|
||||||
|
RequirementEffect effect = entry.getKey();
|
||||||
|
if (effect instanceof MasterWarcraftMustAttackRequirementEffect) {
|
||||||
|
effect.discard();
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
|
}
|
||||||
|
new MasterWarcraftAttackEffect().apply(game, source); // Master Warcraft imposes its effect right before the attackers being declared...
|
||||||
|
}
|
||||||
|
return false; // ...and then resumes the attack declaration for the active player as normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,20 +147,28 @@ class MasterWarcraftAttackEffect extends OneShotEffect {
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
|
// TODO: find a way to undo creature selection
|
||||||
Target target = new TargetCreaturePermanent(0, Integer.MAX_VALUE, new FilterCreaturePermanent("creatures that will attack this combat (creatures not chosen won't attack this combat)"), true);
|
Target target = new TargetCreaturePermanent(0, Integer.MAX_VALUE, new FilterCreaturePermanent("creatures that will attack this combat (creatures not chosen won't attack this combat)"), true);
|
||||||
if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
|
if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
|
||||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) {
|
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) {
|
||||||
|
|
||||||
|
// Choose creatures that will be attacking this combat
|
||||||
if (target.getTargets().contains(permanent.getId())) {
|
if (target.getTargets().contains(permanent.getId())) {
|
||||||
RequirementEffect effect = new AttacksIfAbleTargetEffect(Duration.EndOfCombat);
|
RequirementEffect effect = new MasterWarcraftMustAttackRequirementEffect();
|
||||||
effect.setText("");
|
effect.setText("");
|
||||||
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
||||||
game.addEffect(effect, source);
|
game.addEffect(effect, source);
|
||||||
|
// TODO: find a better way to report attackers to game log
|
||||||
|
// game.informPlayers(controller.getLogName() + " has decided that " + permanent.getLogName() + " should attack this combat if able");
|
||||||
|
|
||||||
|
// All other creatures can't attack
|
||||||
} else {
|
} else {
|
||||||
RestrictionEffect effect = new MasterWarcraftCantAttackRestrictionEffect();
|
RestrictionEffect effect = new MasterWarcraftCantAttackRestrictionEffect();
|
||||||
effect.setText("");
|
effect.setText("");
|
||||||
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
||||||
game.addEffect(effect, source);
|
game.addEffect(effect, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -167,6 +177,30 @@ class MasterWarcraftAttackEffect extends OneShotEffect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MasterWarcraftMustAttackRequirementEffect extends AttacksIfAbleTargetEffect {
|
||||||
|
|
||||||
|
MasterWarcraftMustAttackRequirementEffect() {
|
||||||
|
super(Duration.EndOfCombat);
|
||||||
|
}
|
||||||
|
|
||||||
|
MasterWarcraftMustAttackRequirementEffect(final MasterWarcraftMustAttackRequirementEffect effect) {
|
||||||
|
super(effect);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MasterWarcraftMustAttackRequirementEffect copy() {
|
||||||
|
return new MasterWarcraftMustAttackRequirementEffect(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean applies(Permanent permanent, Ability source, Game game) {
|
||||||
|
if (discarded) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.getTargetPointer().getTargets(game, source).contains(permanent.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MasterWarcraftCantAttackRestrictionEffect extends RestrictionEffect {
|
class MasterWarcraftCantAttackRestrictionEffect extends RestrictionEffect {
|
||||||
|
|
||||||
MasterWarcraftCantAttackRestrictionEffect() {
|
MasterWarcraftCantAttackRestrictionEffect() {
|
||||||
|
@ -183,18 +217,18 @@ class MasterWarcraftCantAttackRestrictionEffect extends RestrictionEffect {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(Permanent creature, Ability source, Game game) {
|
public boolean applies(Permanent permanent, Ability source, Game game) {
|
||||||
for (Map.Entry<RequirementEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRequirementEffects(creature, false, game).entrySet()) {
|
return this.getTargetPointer().getFirst(game, source).equals(permanent.getId());
|
||||||
RequirementEffect effect = entry.getKey();
|
|
||||||
if (effect.mustAttack(game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.getTargetPointer().getFirst(game, source).equals(creature.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAttack(Game game) {
|
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) {
|
||||||
|
for (Map.Entry<RequirementEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRequirementEffects(attacker, false, game).entrySet()) {
|
||||||
|
RequirementEffect effect = entry.getKey();
|
||||||
|
if (effect.mustAttack(game)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +238,7 @@ class MasterWarcraftCantAttackRestrictionEffect extends RestrictionEffect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MasterWarcraftChooseBlockersEffect extends ReplacementEffectImpl {
|
class MasterWarcraftChooseBlockersEffect extends ReplacementEffectImpl { // TODO: replace this with ContinuousRuleModifyingEffectImpl
|
||||||
|
|
||||||
public MasterWarcraftChooseBlockersEffect() {
|
public MasterWarcraftChooseBlockersEffect() {
|
||||||
super(Duration.EndOfTurn, Outcome.Benefit);
|
super(Duration.EndOfTurn, Outcome.Benefit);
|
||||||
|
|
Loading…
Reference in a new issue