convert all gain rules to use MagicAbilityList

master
melvin 2014-02-01 11:58:32 +08:00
parent e6f7e8a860
commit 495786686d
3 changed files with 18 additions and 10 deletions

View File

@ -7,6 +7,6 @@ type=Legendary,Creature
subtype=Human,Artificer subtype=Human,Artificer
cost={W}{U}{B} cost={W}{U}{B}
pt=2/2 pt=2/2
ability=pay {W}{B}:Target artifact creature gains deathtouch and lifelink until end of turn. ability=pay {W}{B}:Target artifact creature gains deathtouch, lifelink until end of turn.
timing=main timing=main
requires_groovy_code requires_groovy_code

View File

@ -18,12 +18,20 @@ public class MagicGainAbilityAction extends MagicAction {
private final MagicAbilityList abilityList; private final MagicAbilityList abilityList;
private final boolean duration; private final boolean duration;
public MagicGainAbilityAction(final MagicPermanent permanent,final Set<MagicAbility> abilities, final boolean duration) { public MagicGainAbilityAction(final MagicPermanent permanent,final MagicAbilityList abilityList, final boolean duration) {
this.permanent=permanent; this.permanent=permanent;
this.abilityList=MagicAbility.getAbilityList(abilities); this.abilityList=abilityList;
this.duration=duration; this.duration=duration;
} }
public MagicGainAbilityAction(final MagicPermanent permanent,final Set<MagicAbility> abilities, final boolean duration) {
this(permanent,MagicAbility.getAbilityList(abilities), duration);
}
public MagicGainAbilityAction(final MagicPermanent permanent,final MagicAbilityList abilityList) {
this(permanent,abilityList,MagicStatic.UntilEOT);
}
public MagicGainAbilityAction(final MagicPermanent permanent,final List<MagicAbility> abilities) { public MagicGainAbilityAction(final MagicPermanent permanent,final List<MagicAbility> abilities) {
this(permanent,EnumSet.copyOf(abilities),MagicStatic.UntilEOT); this(permanent,EnumSet.copyOf(abilities),MagicStatic.UntilEOT);
} }

View File

@ -530,7 +530,7 @@ public enum MagicRuleEventAction {
) { ) {
public MagicEventAction getAction(final String rule) { public MagicEventAction getAction(final String rule) {
final Matcher matcher = matched(rule); final Matcher matcher = matched(rule);
final MagicAbility ability = MagicAbility.getAbility(matcher.group("ability")); final MagicAbilityList abilityList = MagicAbility.getAbilityList(matcher.group("ability"));
final String[] pt = matcher.group("pt").replace("+","").split("/"); final String[] pt = matcher.group("pt").replace("+","").split("/");
final int power = Integer.parseInt(pt[0]); final int power = Integer.parseInt(pt[0]);
final int toughness = Integer.parseInt(pt[1]); final int toughness = Integer.parseInt(pt[1]);
@ -540,7 +540,7 @@ public enum MagicRuleEventAction {
event.processTargetPermanent(game,new MagicPermanentAction() { event.processTargetPermanent(game,new MagicPermanentAction() {
public void doAction(final MagicPermanent creature) { public void doAction(final MagicPermanent creature) {
game.doAction(new MagicChangeTurnPTAction(creature,power,toughness)); game.doAction(new MagicChangeTurnPTAction(creature,power,toughness));
game.doAction(new MagicGainAbilityAction(creature,ability)); game.doAction(new MagicGainAbilityAction(creature,abilityList));
} }
}); });
} }
@ -671,7 +671,7 @@ public enum MagicRuleEventAction {
) { ) {
public MagicEventAction getAction(final String rule) { public MagicEventAction getAction(final String rule) {
final Matcher matcher = matched(rule); final Matcher matcher = matched(rule);
final MagicAbility ability = MagicAbility.getAbility(matcher.group("ability")); final MagicAbilityList abilityList = MagicAbility.getAbilityList(matcher.group("ability"));
final String[] pt = matcher.group("pt").replace("+","").split("/"); final String[] pt = matcher.group("pt").replace("+","").split("/");
final int power = Integer.parseInt(pt[0]); final int power = Integer.parseInt(pt[0]);
final int toughness = Integer.parseInt(pt[1]); final int toughness = Integer.parseInt(pt[1]);
@ -681,7 +681,7 @@ public enum MagicRuleEventAction {
event.processTargetPermanent(game,new MagicPermanentAction() { event.processTargetPermanent(game,new MagicPermanentAction() {
public void doAction(final MagicPermanent creature) { public void doAction(final MagicPermanent creature) {
game.doAction(new MagicChangeTurnPTAction(creature,power,toughness)); game.doAction(new MagicChangeTurnPTAction(creature,power,toughness));
game.doAction(new MagicGainAbilityAction(creature,ability)); game.doAction(new MagicGainAbilityAction(creature,abilityList));
} }
}); });
} }
@ -737,13 +737,13 @@ public enum MagicRuleEventAction {
) { ) {
public MagicEventAction getAction(final String rule) { public MagicEventAction getAction(final String rule) {
final Matcher matcher = matched(rule); final Matcher matcher = matched(rule);
final MagicAbility ability = MagicAbility.getAbility(matcher.group("ability")); final MagicAbilityList abilityList = MagicAbility.getAbilityList(matcher.group("ability"));
return new MagicEventAction() { return new MagicEventAction() {
@Override @Override
public void executeEvent(final MagicGame game, final MagicEvent event) { public void executeEvent(final MagicGame game, final MagicEvent event) {
event.processTargetPermanent(game,new MagicPermanentAction() { event.processTargetPermanent(game,new MagicPermanentAction() {
public void doAction(final MagicPermanent creature) { public void doAction(final MagicPermanent creature) {
game.doAction(new MagicGainAbilityAction(creature,ability)); game.doAction(new MagicGainAbilityAction(creature,abilityList));
} }
}); });
} }