name: Ragnaraika
card_text: Insect, Plant, and Reptile monsters on the field gain 300 ATK/DEF, also all other monsters on the field lose 300 ATK/DEF. During your Main Phase: You can activate 1 of these effects;
  ● Add 1 "Ragnaraika" monster from your Deck to your hand, then discard 1 card.
  ● Special Summon 1 of your "Ragnaraika" monsters from your hand, GY, or banishment, in Defense Position.
  You can only use this effect of "Ragnaraika Bloom" once per turn.
external_ids: local SETCARD_ID_0 = 0x1ab --Ragnaraika
  
lua: local SETCARD_ID_0 = 0x1ab --Ragnaraika
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetValue(s.val)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e3)
  	--
  	local e4 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.val(e, c)
  	local r = c:GetRace()
  	if bit.band(r, RACE_INSECT + RACE_PLANT + RACE_REPTILE) ~= 0 then
  		return 300
  	else
  		return -300
  	end
  end
  function s.filter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.spfilter(c, e, tp)
  	return c:IsFaceupEx() and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local b1 = Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_DECK, 0, 1, nil)
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2), aux.Stringid(id, 3))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 3)) + 1
  	end
  	e:SetLabel(op)
  	if op == 0 then
  		e:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  		Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.filter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g:GetCount() > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) ~= 0 and g:GetFirst():IsLocation(LOCATION_HAND) then
  			Duel.ConfirmCards(1 - tp, g)
  			Duel.ShuffleHand(tp)
  			Duel.BreakEffect()
  			Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD, nil)
  		end
  	else
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, true, false, POS_FACEUP_DEFENSE)
  		end
  	end
  end
  
  
source_text: Ragnaraika
  Insect, Plant, and Reptile monsters on the field gain 300 ATK/DEF, also all other monsters on the field lose 300 ATK/DEF. During your Main Phase: You can activate 1 of these effects;
  ● Add 1 "Ragnaraika" monster from your Deck to your hand, then discard 1 card.
  ● Special Summon 1 of your "Ragnaraika" monsters from your hand, GY, or banishment, in Defense Position.
  You can only use this effect of "Ragnaraika Bloom" once per turn.
target_text: -- Ragnaraika
  local SETCARD_ID_0 = 0x1ab --Ragnaraika
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetValue(s.val)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_UPDATE_DEFENSE)
  	c:RegisterEffect(e3)
  	--
  	local e4 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.val(e, c)
  	local r = c:GetRace()
  	if bit.band(r, RACE_INSECT + RACE_PLANT + RACE_REPTILE) ~= 0 then
  		return 300
  	else
  		return -300
  	end
  end
  function s.filter1(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.spfilter(c, e, tp)
  	return c:IsFaceupEx() and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local b1 = Duel.IsExistingMatchingCard(s.filter1, tp, LOCATION_DECK, 0, 1, nil)
  	local b2 = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil, e, tp)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2), aux.Stringid(id, 3))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 3)) + 1
  	end
  	e:SetLabel(op)
  	if op == 0 then
  		e:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  		Duel.SetOperationInfo(0, CATEGORY_HANDES, nil, 0, tp, 1)
  	else
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, s.filter1, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g:GetCount() > 0 and Duel.SendtoHand(g, nil, REASON_EFFECT) ~= 0 and g:GetFirst():IsLocation(LOCATION_HAND) then
  			Duel.ConfirmCards(1 - tp, g)
  			Duel.ShuffleHand(tp)
  			Duel.BreakEffect()
  			Duel.DiscardHand(tp, nil, 1, 1, REASON_EFFECT + REASON_DISCARD, nil)
  		end
  	else
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, 1, nil, e, tp)
  		if g:GetCount() > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, true, false, POS_FACEUP_DEFENSE)
  		end
  	end
  end
  
  