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