name: Contract
card_text: Destroy as many "Dark Contract" cards in your Spell & Trap Zone as possible, and if you do, draw the same number of cards you destroyed, then gain 1000 LP for each card you drew with this effect.
external_ids: local SETCARD_ID_0 = 0xae --Dark
  
lua: local SETCARD_ID_0 = 0xae --Dark
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DRAW + CATEGORY_RECOVER)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetSequence() < 5
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_SZONE, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_SZONE, 0, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, g:GetCount())
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, g:GetCount() * 1000)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_SZONE, 0, nil)
  	local ct1 = Duel.Destroy(g, REASON_EFFECT)
  	if ct1 == 0 then
  		return
  	end
  	local ct2 = Duel.Draw(tp, ct1, REASON_EFFECT)
  	Duel.BreakEffect()
  	Duel.Recover(tp, ct2 * 1000, REASON_EFFECT)
  end
  
  
source_text: Contract
  Destroy as many "Dark Contract" cards in your Spell & Trap Zone as possible, and if you do, draw the same number of cards you destroyed, then gain 1000 LP for each card you drew with this effect.
target_text: -- Contract
  local SETCARD_ID_0 = 0xae --Dark
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DRAW + CATEGORY_RECOVER)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetSequence() < 5
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_SZONE, 0, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_SZONE, 0, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, g:GetCount())
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 0, tp, g:GetCount() * 1000)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_SZONE, 0, nil)
  	local ct1 = Duel.Destroy(g, REASON_EFFECT)
  	if ct1 == 0 then
  		return
  	end
  	local ct2 = Duel.Draw(tp, ct1, REASON_EFFECT)
  	Duel.BreakEffect()
  	Duel.Recover(tp, ct2 * 1000, REASON_EFFECT)
  end
  
  