magarena/src/magic/model/event/MagicSourceEvent.java

106 lines
2.9 KiB
Java
Raw Permalink Normal View History

package magic.model.event;
2020-01-15 12:02:42 -08:00
import java.util.regex.Matcher;
import magic.model.MagicCopyable;
2020-01-15 12:02:42 -08:00
import magic.model.MagicPlayer;
import magic.model.MagicSource;
import magic.model.choice.MagicChoice;
2020-01-15 12:02:42 -08:00
import magic.model.choice.MagicChoiceFactory;
import magic.model.condition.MagicCondition;
import magic.model.target.MagicTargetPicker;
2014-04-18 14:43:01 -07:00
public class MagicSourceEvent implements MagicCopyable, MagicEventFactory {
private final MagicRuleEventAction rule;
private final Matcher matcher;
private final MagicCondition ifCond;
private final MagicChoiceFactory choiceFact;
private final MagicTargetPicker<?> picker;
private final MagicEventAction action;
private final String text;
public MagicSourceEvent(
final MagicRuleEventAction aRule,
final Matcher aMatcher,
final MagicCondition aIfCond,
final MagicChoiceFactory aChoiceFact,
final MagicTargetPicker<?> aPicker,
final MagicEventAction aAction,
final String aText
) {
rule = aRule;
matcher = aMatcher;
ifCond = aIfCond;
choiceFact = aChoiceFact;
picker = aPicker;
action = aAction;
text = aText;
}
2015-12-31 02:54:52 -08:00
@Override
public MagicEvent getEvent(final MagicSource source, final MagicPlayer player, final MagicCopyable ref) {
return new MagicEvent(
source,
player,
choiceFact.build(source, player, ref),
picker,
ref,
action,
text
);
}
2015-12-31 02:54:52 -08:00
// needed for groovy static checking as it does not find default methods
@Override
public MagicEvent getEvent(final MagicSource source) {
return getEvent(source, source.getController(), MagicEvent.NO_REF);
2015-05-08 18:57:19 -07:00
}
2015-12-31 02:54:52 -08:00
// needed for groovy static checking as it does not find default methods
@Override
public MagicEvent getEvent(final MagicEvent event) {
return getEvent(event.getSource(), event.getPlayer(), MagicEvent.NO_REF);
}
2015-12-31 02:54:52 -08:00
@Override
public boolean accept(final MagicSource source, final MagicEvent ev) {
return ifCond.accept(ev);
}
public MagicCondition[] getConditions() {
return rule.getConditions(matcher);
}
public MagicTiming getTiming() {
return rule.getTiming(matcher);
}
2015-12-31 02:54:52 -08:00
public String getName() {
return rule.getName(matcher);
}
2015-12-31 02:54:52 -08:00
public boolean isIndependent() {
return rule.isIndependent();
}
2015-03-26 04:47:38 -07:00
public MagicEventAction getAction() {
return rule.getAction(matcher);
}
public MagicChoice getChoice() {
return rule.getChoice(matcher);
}
2015-12-31 02:54:52 -08:00
public MagicChoice getEventChoice() {
return choiceFact.build(MagicSource.NONE, MagicPlayer.NONE, MagicEvent.NO_REF);
}
public MagicTargetPicker<?> getPicker() {
return rule.getPicker(matcher);
}
public MagicEventAction getEventAction() {
return action;
}
}