Name:Cocoon
ManaCost:G
Types:Enchantment Aura
K:Enchant:Creature.YouCtrl:creature you control
SVar:AttachAILogic:Pump
T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Execute$ TrigTap | TriggerDescription$ When this Aura enters, tap enchanted creature and put three pupa counters on this Aura.
SVar:TrigTap:DB$ Tap | Defined$ Enchanted | SubAbility$ DBPutCounter
SVar:DBPutCounter:DB$ PutCounter | CounterType$ PUPA | CounterNum$ 3
R:Event$ Untap | ActiveZones$ Battlefield | ValidCard$ Creature.AttachedBy | ValidStepTurnToController$ You | Layer$ CantHappen | IsPresent$ Card.Self+counters_GE1_PUPA | Description$ Enchanted creature doesn't untap during your untap step if this Aura has a pupa counter on it.
T:Mode$ Phase | Phase$ Upkeep | ValidPlayer$ You | TriggerZones$ Battlefield | Execute$ TrigRemoveCounter | TriggerDescription$ At the beginning of your upkeep, remove a pupa counter from this Aura. If you can't, sacrifice it, put a +1/+1 counter on enchanted creature, and that creature gains flying. (This effect lasts indefinitely.)
SVar:TrigRemoveCounter:DB$ RemoveCounter | Defined$ Self | CounterType$ PUPA | CounterNum$ 1 | RememberRemoved$ True | SubAbility$ TrigPutCounter
# TODO: need EnchantedLKI because it isn't enchanted anymore if this is sacrificed
SVar:TrigPutCounter:DB$ PutCounter | Defined$ Enchanted | CounterType$ P1P1 | CounterNum$ 1 | ConditionCheckSVar$ X | ConditionSVarCompare$ LE0 | SubAbility$ TrigPump
SVar:TrigPump:DB$ Pump | Defined$ Enchanted | KW$ Flying | Duration$ Permanent | ConditionCheckSVar$ X | ConditionSVarCompare$ LE0 | SubAbility$ TrigSac
SVar:TrigSac:DB$ Sacrifice | ConditionCheckSVar$ X | ConditionSVarCompare$ LE0 | SubAbility$ DBCleanup
SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True
SVar:X:Count$RememberedSize
AI:RemoveDeck:Random
DeckHas:Ability$Counters
Oracle:Enchant creature you control\nWhen this Aura enters, tap enchanted creature and put three pupa counters on this Aura.\nEnchanted creature doesn't untap during your untap step if this Aura has a pupa counter on it.\nAt the beginning of your upkeep, remove a pupa counter from this Aura. If you can't, sacrifice it, put a +1/+1 counter on enchanted creature, and that creature gains flying.
