name: Ad
card_text: During your Main Phase: You can make all monsters currently on the field gain ATK equal to their own Level x 100, until the end of the opponent's turn. If this card in your hand or field is used as Fusion Material, and sent to the GY or banished: You can target 1 of your "Despia" monsters or Level 8 or higher Fusion Monsters, that is banished or in your GY, except "Ad Libitum of Despia"; Special Summon it. You can only use each effect of "Ad Libitum of Despia" once per turn.
external_ids: local SETCARD_ID_0 = 0x164 --Despia
  
lua: local SETCARD_ID_0 = 0x164 --Despia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk change
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--special summon itself
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_BE_MATERIAL)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsLevelAbove(0)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	local tc = g:GetFirst()
  	for tc in aux.Next(g) do
  		local lv = tc:GetLevel()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(lv * 100)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_HAND + LOCATION_ONFIELD) and c:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and r == REASON_FUSION
  end
  function s.spfilter(c, e, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE))
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and (not c:IsCode(id) and c:IsSetCard(SETCARD_ID_0) or c:IsLevelAbove(8) and c:IsType(TYPE_FUSION))
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Ad
  During your Main Phase: You can make all monsters currently on the field gain ATK equal to their own Level x 100, until the end of the opponent's turn. If this card in your hand or field is used as Fusion Material, and sent to the GY or banished: You can target 1 of your "Despia" monsters or Level 8 or higher Fusion Monsters, that is banished or in your GY, except "Ad Libitum of Despia"; Special Summon it. You can only use each effect of "Ad Libitum of Despia" once per turn.
target_text: -- Ad
  local SETCARD_ID_0 = 0x164 --Despia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk change
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--special summon itself
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_BE_MATERIAL)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsLevelAbove(0)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	local tc = g:GetFirst()
  	for tc in aux.Next(g) do
  		local lv = tc:GetLevel()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(lv * 100)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END + RESET_OPPO_TURN)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousLocation(LOCATION_HAND + LOCATION_ONFIELD) and c:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and r == REASON_FUSION
  end
  function s.spfilter(c, e, tp)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE))
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and (not c:IsCode(id) and c:IsSetCard(SETCARD_ID_0) or c:IsLevelAbove(8) and c:IsType(TYPE_FUSION))
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE + LOCATION_REMOVED) and s.spfilter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  