name: Rain
card_text: Target 1 "Cloudian" monster you control; reduce its ATK by exactly 1000 or 2000, and if you do, apply the appropriate effect.
  ● 1000: Destroy 1 Spell/Trap your opponent controls.
  ● 2000: Destroy 2 cards your opponent controls.
external_ids: local SETCARD_ID_0 = 0x18 --Cloudian
  
lua: local SETCARD_ID_0 = 0x18 --Cloudian
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsAttackAbove(1000)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.cfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.filter1(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local atk = tc:GetAttack()
  		local g1 = Duel.GetMatchingGroup(s.filter1, tp, 0, LOCATION_ONFIELD, nil)
  		local g2 = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
  		local opt = 0
  		local b1 = atk >= 1000 and g1:GetCount() > 0
  		local b2 = atk >= 2000 and g2:GetCount() > 1
  		if b1 and b2 then
  			opt = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  		elseif b1 then
  			opt = Duel.SelectOption(tp, aux.Stringid(id, 0))
  		elseif b2 then
  			opt = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  		else
  			opt = 2
  		end
  		if opt == 0 then
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(-1000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = g1:Select(tp, 1, 1, nil)
  			Duel.Destroy(dg, REASON_EFFECT)
  		elseif opt == 1 then
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(-2000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = g2:Select(tp, 2, 2, nil)
  			Duel.Destroy(dg, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Rain
  Target 1 "Cloudian" monster you control; reduce its ATK by exactly 1000 or 2000, and if you do, apply the appropriate effect.
  ● 1000: Destroy 1 Spell/Trap your opponent controls.
  ● 2000: Destroy 2 cards your opponent controls.
target_text: -- Rain
  local SETCARD_ID_0 = 0x18 --Cloudian
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsAttackAbove(1000)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.cfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.cfilter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.filter1(c)
  	return c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local atk = tc:GetAttack()
  		local g1 = Duel.GetMatchingGroup(s.filter1, tp, 0, LOCATION_ONFIELD, nil)
  		local g2 = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
  		local opt = 0
  		local b1 = atk >= 1000 and g1:GetCount() > 0
  		local b2 = atk >= 2000 and g2:GetCount() > 1
  		if b1 and b2 then
  			opt = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  		elseif b1 then
  			opt = Duel.SelectOption(tp, aux.Stringid(id, 0))
  		elseif b2 then
  			opt = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  		else
  			opt = 2
  		end
  		if opt == 0 then
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(-1000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = g1:Select(tp, 1, 1, nil)
  			Duel.Destroy(dg, REASON_EFFECT)
  		elseif opt == 1 then
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(-2000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = g2:Select(tp, 2, 2, nil)
  			Duel.Destroy(dg, REASON_EFFECT)
  		end
  	end
  end
  
  