name: Water
card_text: You can Ritual Summon this card with "A.I.'s Ritual". If this card is Ritual Summoned: You can return all monsters your opponent control with 2300 or less ATK to the hand. You can target 1 face-up monster your opponent controls; return all Link Monsters from your GY to the Extra Deck, and if you do, change that targeted monster's ATK to 0. You can only use this effect of "Water Leviathan @Ignister" once per turn. Once per battle, during damage calculation, if this card battles an opponent's monster (Quick Effect): You can halve the ATK of that opponent's monster, during that damage calculation only.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--to extra
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOEXTRA + CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tetg)
  	e2:SetOperation(s.teop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.atkcon)
  	e3:SetCost(s.atkcost)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsAttackBelow(2300) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, g:GetCount(), 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, 0, LOCATION_MZONE, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  	end
  end
  function s.tefilter(c)
  	return c:IsType(TYPE_LINK) and c:IsAbleToExtra()
  end
  function s.tetg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and aux.nzatk(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tefilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingTarget(aux.nzatk, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, aux.nzatk, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	local g = Duel.GetMatchingGroup(s.tefilter, tp, LOCATION_GRAVE, 0, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, g:GetCount(), 0, 0)
  end
  function s.teop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.tefilter, tp, LOCATION_GRAVE, 0, nil)
  	if aux.NecroValleyNegateCheck(g) then
  		return
  	end
  	if g:GetCount() > 0 and Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(0)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	return bc and aux.nzatk(bc) and bc:IsControler(1 - tp)
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:GetFlagEffect(id) == 0
  	end
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE_CAL, 0, 1)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	if bc and bc:IsFaceup() and bc:IsRelateToBattle() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(math.ceil(bc:GetAttack() / 2))
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE_CAL)
  		bc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Water
  You can Ritual Summon this card with "A.I.'s Ritual". If this card is Ritual Summoned: You can return all monsters your opponent control with 2300 or less ATK to the hand. You can target 1 face-up monster your opponent controls; return all Link Monsters from your GY to the Extra Deck, and if you do, change that targeted monster's ATK to 0. You can only use this effect of "Water Leviathan @Ignister" once per turn. Once per battle, during damage calculation, if this card battles an opponent's monster (Quick Effect): You can halve the ATK of that opponent's monster, during that damage calculation only.
target_text: -- Water
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.thcon)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--to extra
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOEXTRA + CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tetg)
  	e2:SetOperation(s.teop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.atkcon)
  	e3:SetCost(s.atkcost)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.thfilter(c)
  	return c:IsFaceup() and c:IsAttackBelow(2300) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, g:GetCount(), 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, 0, LOCATION_MZONE, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  	end
  end
  function s.tefilter(c)
  	return c:IsType(TYPE_LINK) and c:IsAbleToExtra()
  end
  function s.tetg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and aux.nzatk(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tefilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingTarget(aux.nzatk, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, aux.nzatk, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	local g = Duel.GetMatchingGroup(s.tefilter, tp, LOCATION_GRAVE, 0, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, g:GetCount(), 0, 0)
  end
  function s.teop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.tefilter, tp, LOCATION_GRAVE, 0, nil)
  	if aux.NecroValleyNegateCheck(g) then
  		return
  	end
  	if g:GetCount() > 0 and Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsFaceup() and tc:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(0)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	return bc and aux.nzatk(bc) and bc:IsControler(1 - tp)
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:GetFlagEffect(id) == 0
  	end
  	c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE_CAL, 0, 1)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	if bc and bc:IsFaceup() and bc:IsRelateToBattle() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetValue(math.ceil(bc:GetAttack() / 2))
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE_CAL)
  		bc:RegisterEffect(e1)
  	end
  end
  
  