public AnotherCreatureEntersTheBattlefield(GameState state) { super( state, "Whenever another creature enters the battlefield under your control, if you control both that creature and this one and both are unpaired, you may pair that creature with this creature for as long as both remain creatures on the battlefield under your control."); SetGenerator thisCreature = ABILITY_SOURCE_OF_THIS; SetGenerator otherCreatures = RelativeComplement.instance(CreaturePermanents.instance(), thisCreature); this.addPattern( new SimpleZoneChangePattern( null, Battlefield.instance(), otherCreatures, You.instance(), false)); SetGenerator thatCreature = NewObjectOf.instance(TriggerZoneChange.instance(This.instance())); SetGenerator youControl = ControlledBy.instance(You.instance()); SetGenerator youControlUnpairedThis = Intersect.instance(youControl, Unpaired.instance(), thisCreature); SetGenerator youControlUnpairedThat = Intersect.instance(youControl, Unpaired.instance(), thatCreature); this.interveningIf = Both.instance(youControlUnpairedThis, youControlUnpairedThat); ContinuousEffect.Part part = new ContinuousEffect.Part(ContinuousEffectType.PAIR); part.parameters.put( ContinuousEffectType.Parameter.OBJECT, Union.instance(thisCreature, thatCreature)); SetGenerator youControlCreatureThis = Intersect.instance(CREATURES_YOU_CONTROL, thisCreature); SetGenerator youControlCreatureThat = Intersect.instance(CREATURES_YOU_CONTROL, thatCreature); SetGenerator expires = Not.instance(Both.instance(youControlCreatureThis, youControlCreatureThat)); EventFactory floatingEffect = createFloatingEffect(expires, "Pair this creature with that creature", part); this.addEffect(youMay(floatingEffect)); }
@Override public boolean perform(Game game, Event event, Map<Parameter, MagicSet> parameters) { Event damageEvent = createEvent(game, event.getName(), EventType.DEAL_DAMAGE_EVENLY, parameters); boolean ret = damageEvent.perform(event, false); SetPattern affectedCreatures = new SimpleSetPattern( Intersect.instance( TakerOfDamage.instance(EventDamage.instance(Identity.instance(event))), CreaturePermanents.instance())); SimpleEventPattern regenerate = new SimpleEventPattern(EventType.REGENERATE); regenerate.put(EventType.Parameter.OBJECT, affectedCreatures); EventReplacementEffectStopper stopRegen = new EventReplacementEffectStopper( parameters.get(Parameter.SOURCE).getOne(GameObject.class), null, regenerate); ContinuousEffect.Part part = new ContinuousEffect.Part(ContinuousEffectType.STOP_REPLACEMENT_EFFECT); part.parameters.put(ContinuousEffectType.Parameter.PROHIBITION, Identity.instance(stopRegen)); Map<EventType.Parameter, MagicSet> stopRegenParameters = new HashMap<EventType.Parameter, MagicSet>(); stopRegenParameters.put(EventType.Parameter.CAUSE, parameters.get(Parameter.SOURCE)); stopRegenParameters.put(EventType.Parameter.EFFECT, new MagicSet(part)); Event regenStopper = createEvent( game, "A creature dealt damage this way can't be regenerated this turn.", EventType.CREATE_FLOATING_CONTINUOUS_EFFECT, stopRegenParameters); ret = regenStopper.perform(event, false) && ret; event.setResult(Empty.set); return ret; }