name: Vera
card_text: Once per turn, when a monster effect activated by your opponent resolves, if you control 5 or more EARTH monsters, you can negate that effect, and if you do, destroy that card. You can only use each of the following effects of "Vera the Vernusylph Goddess" once per turn. You can target 1 face-up monster your opponent controls; take control of it, and if you do, it becomes EARTH. During your opponent's turn (Quick Effect): You can target 1 EARTH monster in your GY; Special Summon it.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--control
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_CONTROL)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.cttg)
  	e1:SetOperation(s.ctop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_DISABLE + CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_CHAIN_SOLVING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.discon)
  	e3:SetOperation(s.disop)
  	c:RegisterEffect(e3)
  end
  function s.ctfilter(c)
  	return c:IsControlerCanBeChanged() and c:IsFaceup()
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.ctfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.ctfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, s.ctfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.GetControl(tc, tp) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_ATTRIBUTE)
  		e1:SetValue(ATTRIBUTE_EARTH)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttribute(ATTRIBUTE_EARTH) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) 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, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 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)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.disfilter(c)
  	return c:IsAttribute(ATTRIBUTE_EARTH) and c:IsFaceup()
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp
  		and Duel.IsChainDisablable(ev)
  		and re:IsActiveType(TYPE_MONSTER)
  		and Duel.GetMatchingGroupCount(s.disfilter, tp, LOCATION_MZONE, 0, nil) >= 5
  		and e:GetHandler():GetFlagEffect(id) <= 0
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), aux.Stringid(id, 2)) then
  		Duel.Hint(HINT_CARD, 0, id)
  		local rc = re:GetHandler()
  		if Duel.NegateEffect(ev) and rc:IsRelateToEffect(re) then
  			Duel.Destroy(rc, REASON_EFFECT)
  		end
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 3))
  	end
  end
  
  
source_text: Vera
  Once per turn, when a monster effect activated by your opponent resolves, if you control 5 or more EARTH monsters, you can negate that effect, and if you do, destroy that card. You can only use each of the following effects of "Vera the Vernusylph Goddess" once per turn. You can target 1 face-up monster your opponent controls; take control of it, and if you do, it becomes EARTH. During your opponent's turn (Quick Effect): You can target 1 EARTH monster in your GY; Special Summon it.
target_text: -- Vera
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--control
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_CONTROL)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.cttg)
  	e1:SetOperation(s.ctop)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_DISABLE + CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_CHAIN_SOLVING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.discon)
  	e3:SetOperation(s.disop)
  	c:RegisterEffect(e3)
  end
  function s.ctfilter(c)
  	return c:IsControlerCanBeChanged() and c:IsFaceup()
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.ctfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.ctfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, s.ctfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.GetControl(tc, tp) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_ATTRIBUTE)
  		e1:SetValue(ATTRIBUTE_EARTH)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttribute(ATTRIBUTE_EARTH) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) 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, 0, 1, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.spfilter, tp, LOCATION_GRAVE, 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)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.disfilter(c)
  	return c:IsAttribute(ATTRIBUTE_EARTH) and c:IsFaceup()
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp
  		and Duel.IsChainDisablable(ev)
  		and re:IsActiveType(TYPE_MONSTER)
  		and Duel.GetMatchingGroupCount(s.disfilter, tp, LOCATION_MZONE, 0, nil) >= 5
  		and e:GetHandler():GetFlagEffect(id) <= 0
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), aux.Stringid(id, 2)) then
  		Duel.Hint(HINT_CARD, 0, id)
  		local rc = re:GetHandler()
  		if Duel.NegateEffect(ev) and rc:IsRelateToEffect(re) then
  			Duel.Destroy(rc, REASON_EFFECT)
  		end
  		e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 3))
  	end
  end
  
  