def graft(value): txt = "Graft %d" % value def enterBattlefieldWith(self): self.add_counters(PowerToughnessCounter(1, 1), number=value) def graft_1(source): yield CiP(source, enterBattlefieldWith, txt=txt) graft_CiP = CiPAbility(graft_1, txt=txt, keyword='graft') def condition(source, card): return isCreature( card) and not source == card and source.num_counters("+1+1") > 0 def graft_2(controller, source, card): yield NoTarget() if source.num_counters("+1+1") > 0: if controller.you_may("move a +1/+1 counter from %s to %s" % (source, card)): source.remove_counters(PowerToughnessCounter(1, 1)) card.add_counters(PowerToughnessCounter(1, 1)) yield graft_Triggered = TriggeredAbility(EnterTrigger("battlefield", condition, player="any"), effects=graft_2, txt=txt) return graft_CiP, graft_Triggered
def __init__(self, effects, condition, events=[], tracking="battlefield", zone="battlefield", txt=''): super(CardTrackingAbility, self).__init__(effects, zone, txt) self.enter_trigger = EnterTrigger(tracking, condition, player="any") self.leave_trigger = LeaveTrigger(tracking, player="any") self.control_changed = Trigger( ControllerChanged(), sender="source") # card with ability changed controller if isinstance(events, tuple): events = list(events) elif not isinstance(events, list): events = [events] self.other_triggers = [ Trigger(event) for event in [ControllerChanged()] + events ] # triggers for tracked cards if not condition: condition = all_match self.condition = condition self.tracking = tracking self.events = events