name: Minerva,
card_text: 2 Level 4 monsters
  You can detach 1 material from this card; send the top 3 cards of your Deck to the GY, then draw cards equal to the number of "Lightsworn" cards sent to the GY by this effect. If this card is destroyed by battle, or if this card in its owner's possession is destroyed by an opponent's card effect: You can send the top 3 cards of your Deck to the GY, then you can destroy cards on the field up to the number of "Lightsworn" cards sent to the GY by this effect. You can only use each effect of "Minerva, the Exalted Lightsworn" once per turn.
external_ids: local SETCARD_ID_0 = 0x38 --Lightsworn
  
lua: local SETCARD_ID_0 = 0x38 --Lightsworn
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2)
  	c:EnableReviveLimit()
  	--discard deck & draw
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_DECKDES + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.drcost)
  	e1:SetTarget(s.distg)
  	e1:SetOperation(s.drop)
  	c:RegisterEffect(e1)
  	--discard deck & destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetCategory(CATEGORY_DECKDES + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.drcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 3)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(3)
  	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, 3)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLocation(LOCATION_GRAVE)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.DiscardDeck(p, d, REASON_EFFECT)
  	local g = Duel.GetOperatedGroup()
  	local ct = g:FilterCount(s.cfilter, nil)
  	if ct > 0 then
  		Duel.BreakEffect()
  		Duel.Draw(tp, ct, REASON_EFFECT)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_BATTLE) or (rp == 1 - tp and c:IsReason(REASON_EFFECT) and c:IsPreviousControler(tp))
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.DiscardDeck(p, d, REASON_EFFECT)
  	local g = Duel.GetOperatedGroup()
  	local ct = g:FilterCount(s.cfilter, nil)
  	local dg = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if ct ~= 0 and dg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sdg = dg:Select(tp, 1, ct, nil)
  		Duel.HintSelection(sdg)
  		Duel.Destroy(sdg, REASON_EFFECT)
  	end
  end
  
  
source_text: Minerva,
  2 Level 4 monsters
  You can detach 1 material from this card; send the top 3 cards of your Deck to the GY, then draw cards equal to the number of "Lightsworn" cards sent to the GY by this effect. If this card is destroyed by battle, or if this card in its owner's possession is destroyed by an opponent's card effect: You can send the top 3 cards of your Deck to the GY, then you can destroy cards on the field up to the number of "Lightsworn" cards sent to the GY by this effect. You can only use each effect of "Minerva, the Exalted Lightsworn" once per turn.
target_text: -- Minerva,
  local SETCARD_ID_0 = 0x38 --Lightsworn
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 4, 2)
  	c:EnableReviveLimit()
  	--discard deck & draw
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_DECKDES + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.drcost)
  	e1:SetTarget(s.distg)
  	e1:SetOperation(s.drop)
  	c:RegisterEffect(e1)
  	--discard deck & destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetCategory(CATEGORY_DECKDES + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.drcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeck(tp, 3)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(3)
  	Duel.SetOperationInfo(0, CATEGORY_DECKDES, nil, 0, tp, 3)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsLocation(LOCATION_GRAVE)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.DiscardDeck(p, d, REASON_EFFECT)
  	local g = Duel.GetOperatedGroup()
  	local ct = g:FilterCount(s.cfilter, nil)
  	if ct > 0 then
  		Duel.BreakEffect()
  		Duel.Draw(tp, ct, REASON_EFFECT)
  	end
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_BATTLE) or (rp == 1 - tp and c:IsReason(REASON_EFFECT) and c:IsPreviousControler(tp))
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.DiscardDeck(p, d, REASON_EFFECT)
  	local g = Duel.GetOperatedGroup()
  	local ct = g:FilterCount(s.cfilter, nil)
  	local dg = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	if ct ~= 0 and dg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sdg = dg:Select(tp, 1, ct, nil)
  		Duel.HintSelection(sdg)
  		Duel.Destroy(sdg, REASON_EFFECT)
  	end
  end
  
  