[SWS] Implemented Sabacc Game, Fixed A-Wing.

This commit is contained in:
LevelX2 2016-09-27 12:35:22 +02:00
parent 86f2007945
commit 33bc95082c
2 changed files with 144 additions and 9 deletions

View file

@ -32,8 +32,8 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.RequirementEffect;
import mage.abilities.effects.common.RemoveFromCombatSourceEffect;
import mage.abilities.effects.common.combat.AttacksIfAbleSourceEffect;
import mage.abilities.keyword.HasteAbility;
import mage.abilities.keyword.SpaceflightAbility;
import mage.cards.CardImpl;
@ -41,6 +41,8 @@ import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
@ -49,7 +51,7 @@ import mage.constants.Zone;
public class AWing extends CardImpl {
public AWing(UUID ownerId) {
super(ownerId, 96, "A-Wing", Rarity.NA/*UNCOMMON*/, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{2}{R}");
super(ownerId, 96, "A-Wing", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{2}{R}");
this.expansionSetCode = "SWS";
this.subtype.add("Rebel");
this.subtype.add("Starship");
@ -64,8 +66,7 @@ public class AWing extends CardImpl {
// {1}:Remove A-wing from combat. It must attack on your next combat if able.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new RemoveFromCombatSourceEffect(), new GenericManaCost(1));
//ability.addEffect(new AttacksIfAbleSourceEffect(Duration.Custom));
// NEEDS FIX
ability.addEffect(new AWingAttacksNextCombatIfAbleSourceEffect());
this.addAbility(ability);
}
@ -78,3 +79,62 @@ public class AWing extends CardImpl {
return new AWing(this);
}
}
class AWingAttacksNextCombatIfAbleSourceEffect extends RequirementEffect {
int turnNumber;
int phaseCount;
int nextPhaseTurnNumber = 0;
int nextPhasePhaseCount = 0;
public AWingAttacksNextCombatIfAbleSourceEffect() {
super(Duration.Custom);
staticText = "It must attack on your next combat if able";
}
public AWingAttacksNextCombatIfAbleSourceEffect(final AWingAttacksNextCombatIfAbleSourceEffect effect) {
super(effect);
this.turnNumber = effect.turnNumber;
this.phaseCount = effect.phaseCount;
this.nextPhaseTurnNumber = effect.nextPhaseTurnNumber;
this.nextPhasePhaseCount = effect.nextPhasePhaseCount;
}
@Override
public void init(Ability source, Game game) {
turnNumber = game.getTurnNum();
phaseCount = game.getPhase().getCount();
}
@Override
public AWingAttacksNextCombatIfAbleSourceEffect copy() {
return new AWingAttacksNextCombatIfAbleSourceEffect(this);
}
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getSourceId())) {
if (game.getTurnNum() != turnNumber || game.getPhase().getCount() != phaseCount) {
if (nextPhaseTurnNumber == 0) {
nextPhasePhaseCount = game.getPhase().getCount();
nextPhaseTurnNumber = game.getTurnNum();
} else if (game.getTurnNum() != nextPhaseTurnNumber || game.getPhase().getCount() != nextPhasePhaseCount) {
this.discard();
}
return true;
}
}
return false;
}
@Override
public boolean mustAttack(Game game) {
return true;
}
@Override
public boolean mustBlock(Game game) {
return false;
}
}

View file

@ -28,9 +28,24 @@
package mage.sets.starwars;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.GainControlTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.predicate.other.PlayerIdPredicate;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -38,18 +53,26 @@ import mage.constants.Rarity;
*/
public class SabaccGame extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("permanent an opponent controls");
static {
filter.add(new ControllerPredicate(TargetController.OPPONENT));
}
public SabaccGame(UUID ownerId) {
super(ownerId, 54, "Sabacc Game", Rarity.NA/*UNCOMMON*/, new CardType[]{CardType.SORCERY}, "{1}{U}");
super(ownerId, 54, "Sabacc Game", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{1}{U}");
this.expansionSetCode = "SWS";
// Almost the same as unimplemented Mogg Assassin from Exodus
// Not exactly. Because the permanent choosen by opponent does not have the target word in rule text it is chosen during resolution.
/*
* Choose target permanent an opponent controls. That opponent choosers a permanent you control.
* Flip a coin. If you win the flip, gain control of the permanent you chose.
* Choose target permanent an opponent controls. That opponent chooses a permanent you control.
* Flip a coin. If you win the flip, gain control of the permanent you chose.
* If you lose the flip, your opponent gains control of the permanent they chose.
*/
}
this.getSpellAbility().getEffects().add(new SabaccGameEffect());
this.getSpellAbility().getTargets().add(new TargetPermanent(filter));
}
public SabaccGame(final SabaccGame card) {
super(card);
@ -60,3 +83,55 @@ public class SabaccGame extends CardImpl {
return new SabaccGame(this);
}
}
class SabaccGameEffect extends OneShotEffect {
public SabaccGameEffect() {
super(Outcome.Benefit);
this.staticText = "Choose target permanent an opponent controls. That opponent chooses a permanent you control. "
+ "Flip a coin. If you win the flip, gain control of the permanent you chose. "
+ "If you lose the flip, your opponent gains control of the permanent they chose";
}
public SabaccGameEffect(final SabaccGameEffect effect) {
super(effect);
}
@Override
public SabaccGameEffect copy() {
return new SabaccGameEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent targetPermanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) {
Player opponent = game.getPlayer(targetPermanent.getControllerId());
if (opponent != null) {
FilterPermanent filter = new FilterPermanent("permanent controlled by " + controller.getName());
filter.add(new PlayerIdPredicate(controller.getId()));
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
Permanent chosenPermanent = null;
if (target.chooseTarget(outcome, opponent.getId(), source, game)) {
chosenPermanent = game.getPermanent(target.getFirstTarget());
}
boolean flipWin = controller.flipCoin(game);
if (flipWin) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, controller.getId());
effect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(effect, source);
} else if (chosenPermanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
return false;
}
}