name: Breaking
card_text: Once per turn: You can target 1 Ritual Monster you control; show 1 Ritual Monster in your hand, until the end of this turn. The Level of the shown Ritual Monster becomes the targeted monster's Level, until the end of this turn (even if this card leaves the field). Once per turn, if "Ruin, Queen of Oblivion" or "Demise, King of Armageddon" is Ritual Summoned to your field (except during the Damage Step): You can activate 1 of these effects;
  ● Draw 1 card.
  ● Destroy 1 card on the field.
external_ids: local CARD_ID_0 = 46427957 --Ruin, Queen of Oblivion
  local CARD_ID_1 = 72426662 --Demise, King of Armageddon
  
lua: local CARD_ID_0 = 46427957 --Ruin, Queen of Oblivion
  local CARD_ID_1 = 72426662 --Demise, King of Armageddon
  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)
  	c:RegisterEffect(e1)
  	--change level
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.lvtg)
  	e2:SetOperation(s.lvop)
  	c:RegisterEffect(e2)
  	--draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.target)
  	c:RegisterEffect(e3)
  end
  function s.lvfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_RITUAL) and Duel.IsExistingMatchingCard(s.lvcfilter, tp, LOCATION_HAND, 0, 1, nil, c)
  end
  function s.lvcfilter(c, mc)
  	return c:IsType(TYPE_RITUAL) and c:IsType(TYPE_MONSTER) and not c:IsPublic() and not c:IsLevel(mc:GetLevel())
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.lvfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local cg = Duel.SelectMatchingCard(tp, s.lvcfilter, tp, LOCATION_HAND, 0, 1, 1, nil, tc)
  	if cg:GetCount() > 0 then
  		Duel.ConfirmCards(1 - tp, cg)
  		local pc = cg:GetFirst()
  		local e2 = Effect.CreateEffect(c)
  		e2:SetDescription(66)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_PUBLIC)
  		e2:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		pc:RegisterEffect(e2)
  		if tc:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_CHANGE_LEVEL)
  			e1:SetValue(tc:GetLevel())
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			pc:RegisterEffect(e1)
  		end
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsCode(CARD_ID_0, CARD_ID_1) and c:IsControler(tp) and c:IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.IsPlayerCanDraw(tp, 1)
  	local g = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD)
  	local b2 = g:GetCount() > 0
  	if chk == 0 then
  		return b1 or b2
  	end
  	local sel = 0
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EFFECT)
  	if b1 and b2 then
  		sel = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		sel = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		sel = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	if sel == 0 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_PLAYER_TARGET)
  		e:SetOperation(s.drop)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetTargetParam(1)
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	else
  		e:SetCategory(CATEGORY_DESTROY)
  		e:SetOperation(s.desop)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	end
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  
source_text: Breaking
  Once per turn: You can target 1 Ritual Monster you control; show 1 Ritual Monster in your hand, until the end of this turn. The Level of the shown Ritual Monster becomes the targeted monster's Level, until the end of this turn (even if this card leaves the field). Once per turn, if "Ruin, Queen of Oblivion" or "Demise, King of Armageddon" is Ritual Summoned to your field (except during the Damage Step): You can activate 1 of these effects;
  ● Draw 1 card.
  ● Destroy 1 card on the field.
target_text: -- Breaking
  local CARD_ID_0 = 46427957 --Ruin, Queen of Oblivion
  local CARD_ID_1 = 72426662 --Demise, King of Armageddon
  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)
  	c:RegisterEffect(e1)
  	--change level
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1)
  	e2:SetTarget(s.lvtg)
  	e2:SetOperation(s.lvop)
  	c:RegisterEffect(e2)
  	--draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCountLimit(1)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.target)
  	c:RegisterEffect(e3)
  end
  function s.lvfilter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_RITUAL) and Duel.IsExistingMatchingCard(s.lvcfilter, tp, LOCATION_HAND, 0, 1, nil, c)
  end
  function s.lvcfilter(c, mc)
  	return c:IsType(TYPE_RITUAL) and c:IsType(TYPE_MONSTER) and not c:IsPublic() and not c:IsLevel(mc:GetLevel())
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_MZONE) and s.lvfilter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_MZONE, 0, 1, 1, nil, tp)
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local cg = Duel.SelectMatchingCard(tp, s.lvcfilter, tp, LOCATION_HAND, 0, 1, 1, nil, tc)
  	if cg:GetCount() > 0 then
  		Duel.ConfirmCards(1 - tp, cg)
  		local pc = cg:GetFirst()
  		local e2 = Effect.CreateEffect(c)
  		e2:SetDescription(66)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_PUBLIC)
  		e2:SetProperty(EFFECT_FLAG_CLIENT_HINT)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		pc:RegisterEffect(e2)
  		if tc:IsRelateToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_CHANGE_LEVEL)
  			e1:SetValue(tc:GetLevel())
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			pc:RegisterEffect(e1)
  		end
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsCode(CARD_ID_0, CARD_ID_1) and c:IsControler(tp) and c:IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.IsPlayerCanDraw(tp, 1)
  	local g = Duel.GetFieldGroup(tp, LOCATION_ONFIELD, LOCATION_ONFIELD)
  	local b2 = g:GetCount() > 0
  	if chk == 0 then
  		return b1 or b2
  	end
  	local sel = 0
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EFFECT)
  	if b1 and b2 then
  		sel = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		sel = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		sel = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	if sel == 0 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_PLAYER_TARGET)
  		e:SetOperation(s.drop)
  		Duel.SetTargetPlayer(tp)
  		Duel.SetTargetParam(1)
  		Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	else
  		e:SetCategory(CATEGORY_DESTROY)
  		e:SetOperation(s.desop)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	end
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  