name: Eternal
card_text: Monsters you control gain 500 DEF for each "Ancient Fairy Dragon", and monsters that mention it, that you control. Once per Chain: You can target 1 face-up monster your opponent controls; until the end of this turn, its ATK/DEF become halved, also its effects are negated. You can use this effect of "Eternal Sunshine" a number of times per turn, up to the number of "Ancient Fairy Dragon", and monsters that mention it, that you control.
external_ids: local CARD_ID_0 = 25862681 --Ancient Fairy Dragon
  
lua: local CARD_ID_0 = 25862681 --Ancient Fairy Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	c:RegisterEffect(e1)
  	--def up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_DEFENSE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetValue(s.val)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DISABLE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e3:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e3:SetTarget(s.distg)
  	e3:SetOperation(s.disop)
  	c:RegisterEffect(e3)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and (c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0) and c:IsType(TYPE_MONSTER))
  end
  function s.val(e, c)
  	local ct = Duel.GetMatchingGroupCount(s.atkfilter, e:GetHandlerPlayer(), LOCATION_ONFIELD, 0, nil)
  	return ct * 500
  end
  function s.disfilter(c)
  	return c:IsFaceup()
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local ct = Duel.GetMatchingGroupCount(s.atkfilter, tp, LOCATION_ONFIELD, 0, nil)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.disfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.disfilter, tp, 0, LOCATION_MZONE, 1, nil) and Duel.GetFlagEffect(tp, id) < ct
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.disfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, 1, 0, 0)
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and tc:IsType(TYPE_MONSTER) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(math.ceil(tc:GetAttack() / 2))
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  		e2:SetValue(math.ceil(tc:GetDefense() / 2))
  		tc:RegisterEffect(e2)
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_DISABLE)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e3)
  		local e4 = Effect.CreateEffect(c)
  		e4:SetType(EFFECT_TYPE_SINGLE)
  		e4:SetCode(EFFECT_DISABLE_EFFECT)
  		e4:SetValue(RESET_TURN_SET)
  		e4:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e4)
  	end
  end
  
  
source_text: Eternal
  Monsters you control gain 500 DEF for each "Ancient Fairy Dragon", and monsters that mention it, that you control. Once per Chain: You can target 1 face-up monster your opponent controls; until the end of this turn, its ATK/DEF become halved, also its effects are negated. You can use this effect of "Eternal Sunshine" a number of times per turn, up to the number of "Ancient Fairy Dragon", and monsters that mention it, that you control.
target_text: -- Eternal
  local CARD_ID_0 = 25862681 --Ancient Fairy Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	c:RegisterEffect(e1)
  	--def up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_DEFENSE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetValue(s.val)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DISABLE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e3:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e3:SetTarget(s.distg)
  	e3:SetOperation(s.disop)
  	c:RegisterEffect(e3)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and (c:IsCode(CARD_ID_0) or aux.IsCodeListed(c, CARD_ID_0) and c:IsType(TYPE_MONSTER))
  end
  function s.val(e, c)
  	local ct = Duel.GetMatchingGroupCount(s.atkfilter, e:GetHandlerPlayer(), LOCATION_ONFIELD, 0, nil)
  	return ct * 500
  end
  function s.disfilter(c)
  	return c:IsFaceup()
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local ct = Duel.GetMatchingGroupCount(s.atkfilter, tp, LOCATION_ONFIELD, 0, nil)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.disfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.disfilter, tp, 0, LOCATION_MZONE, 1, nil) and Duel.GetFlagEffect(tp, id) < ct
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local g = Duel.SelectTarget(tp, s.disfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, 1, 0, 0)
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and tc:IsType(TYPE_MONSTER) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(math.ceil(tc:GetAttack() / 2))
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_SET_DEFENSE_FINAL)
  		e2:SetValue(math.ceil(tc:GetDefense() / 2))
  		tc:RegisterEffect(e2)
  		local e3 = Effect.CreateEffect(c)
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_DISABLE)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e3)
  		local e4 = Effect.CreateEffect(c)
  		e4:SetType(EFFECT_TYPE_SINGLE)
  		e4:SetCode(EFFECT_DISABLE_EFFECT)
  		e4:SetValue(RESET_TURN_SET)
  		e4:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e4)
  	end
  end
  
  