name: Ancient
card_text: 1 Tuner + 1+ non-Tuner monsters
  If this card is Synchro Summoned: You can draw 1 card, or if "World of Spirits" is on the field, add 1 LIGHT monster (Beast, Plant, or Fairy) or 1 "Eternal Sunshine" from your Deck to your hand instead. You can only use this effect of "Ancient Fairy Life Dragon" once per turn. Your "Ancient Fairy Dragon" and monsters that mention it can attack while in face-up Defense Position (apply their DEF for damage calculation).
external_ids: local CARD_ID_0 = 5414777 --World of Spirits
  local CARD_ID_1 = 25862681 --Ancient Fairy Dragon
  local CARD_ID_2 = 28903523 --Eternal Sunshine
  
lua: local CARD_ID_0 = 5414777 --World of Spirits
  local CARD_ID_1 = 25862681 --Ancient Fairy Dragon
  local CARD_ID_2 = 28903523 --Eternal Sunshine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0, CARD_ID_2)
  	--Synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--draw or search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DEFENSE_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.atktg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.thfilter(c)
  	return (c:IsCode(CARD_ID_2) or c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsRace(RACE_BEAST + RACE_FAIRY + RACE_PLANT)) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local flag = Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceupEx, Card.IsCode), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil, CARD_ID_0)
  	if chk == 0 then
  		return flag and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil) or not flag and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local flag = Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceupEx, Card.IsCode), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil, CARD_ID_0)
  	if not flag and Duel.IsPlayerCanDraw(tp, 1) then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	elseif flag then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if #g > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.atktg(e, c)
  	return c:IsCode(CARD_ID_1) or aux.IsCodeListed(c, CARD_ID_1)
  end
  
  
source_text: Ancient
  1 Tuner + 1+ non-Tuner monsters
  If this card is Synchro Summoned: You can draw 1 card, or if "World of Spirits" is on the field, add 1 LIGHT monster (Beast, Plant, or Fairy) or 1 "Eternal Sunshine" from your Deck to your hand instead. You can only use this effect of "Ancient Fairy Life Dragon" once per turn. Your "Ancient Fairy Dragon" and monsters that mention it can attack while in face-up Defense Position (apply their DEF for damage calculation).
target_text: -- Ancient
  local CARD_ID_0 = 5414777 --World of Spirits
  local CARD_ID_1 = 25862681 --Ancient Fairy Dragon
  local CARD_ID_2 = 28903523 --Eternal Sunshine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1, CARD_ID_0, CARD_ID_2)
  	--Synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--draw or search
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DEFENSE_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.atktg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.thfilter(c)
  	return (c:IsCode(CARD_ID_2) or c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsRace(RACE_BEAST + RACE_FAIRY + RACE_PLANT)) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local flag = Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceupEx, Card.IsCode), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil, CARD_ID_0)
  	if chk == 0 then
  		return flag and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil) or not flag and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local flag = Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceupEx, Card.IsCode), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil, CARD_ID_0)
  	if not flag and Duel.IsPlayerCanDraw(tp, 1) then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	elseif flag then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if #g > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.atktg(e, c)
  	return c:IsCode(CARD_ID_1) or aux.IsCodeListed(c, CARD_ID_1)
  end
  
  