name: Cherubini,
card_text: 2 Level 3 monsters
  Monsters this card points to cannot be destroyed by card effects. If this card would be destroyed by battle or an opponent's card effect, you can send 1 other card you control to the GY instead. You can send 1 Level 3 monster from your Deck to the GY, then target 1 "Burning Abyss" monster on the field; it gains ATK/DEF equal to the ATK/DEF of the monster sent to the GY, until the end of this turn. You can only use this effect of "Cherubini, Ebon Angel of the Burning Abyss" once per turn.
external_ids: local SETCARD_ID_0 = 0xb1 --Burning
  
lua: local SETCARD_ID_0 = 0xb1 --Burning
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLevel, 3), 2, 2)
  	--indestructable
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e1:SetTarget(s.indtg)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetTarget(s.desreptg)
  	c:RegisterEffect(e2)
  	--boost
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetLabel(0)
  	e3:SetCountLimit(1, id)
  	e3:SetCost(s.atkcost)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.indtg(e, c)
  	return e:GetHandler():GetLinkedGroup():IsContains(c)
  end
  function s.repfilter(c, e)
  	return not c:IsStatus(STATUS_DESTROY_CONFIRMED) and not c:IsImmuneToEffect(e)
  end
  function s.desreptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return not c:IsReason(REASON_REPLACE) and (c:IsReason(REASON_BATTLE) or rp == 1 - tp) and Duel.IsExistingMatchingCard(s.repfilter, tp, LOCATION_ONFIELD, 0, 1, c, e)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = Duel.SelectMatchingCard(tp, s.repfilter, tp, LOCATION_ONFIELD, 0, 1, 1, c, e)
  		Duel.SendtoGrave(g, REASON_EFFECT + REASON_REPLACE)
  		return true
  	else
  		return false
  	end
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.cfilter(c)
  	return c:IsLevel(3) and (c:GetBaseAttack() > 0 or c:GetBaseDefense() > 0) and c:IsAbleToGraveAsCost()
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 1 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_DECK, 0, 1, nil) and Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetLabelObject(g:GetFirst())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local sc = e:GetLabelObject()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and sc then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(sc:GetAttack())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_DEFENSE)
  		e2:SetValue(sc:GetDefense())
  		tc:RegisterEffect(e2)
  	end
  end
  
  
source_text: Cherubini,
  2 Level 3 monsters
  Monsters this card points to cannot be destroyed by card effects. If this card would be destroyed by battle or an opponent's card effect, you can send 1 other card you control to the GY instead. You can send 1 Level 3 monster from your Deck to the GY, then target 1 "Burning Abyss" monster on the field; it gains ATK/DEF equal to the ATK/DEF of the monster sent to the GY, until the end of this turn. You can only use this effect of "Cherubini, Ebon Angel of the Burning Abyss" once per turn.
target_text: -- Cherubini,
  local SETCARD_ID_0 = 0xb1 --Burning
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLevel, 3), 2, 2)
  	--indestructable
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e1:SetTarget(s.indtg)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetTarget(s.desreptg)
  	c:RegisterEffect(e2)
  	--boost
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetLabel(0)
  	e3:SetCountLimit(1, id)
  	e3:SetCost(s.atkcost)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.indtg(e, c)
  	return e:GetHandler():GetLinkedGroup():IsContains(c)
  end
  function s.repfilter(c, e)
  	return not c:IsStatus(STATUS_DESTROY_CONFIRMED) and not c:IsImmuneToEffect(e)
  end
  function s.desreptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return not c:IsReason(REASON_REPLACE) and (c:IsReason(REASON_BATTLE) or rp == 1 - tp) and Duel.IsExistingMatchingCard(s.repfilter, tp, LOCATION_ONFIELD, 0, 1, c, e)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = Duel.SelectMatchingCard(tp, s.repfilter, tp, LOCATION_ONFIELD, 0, 1, 1, c, e)
  		Duel.SendtoGrave(g, REASON_EFFECT + REASON_REPLACE)
  		return true
  	else
  		return false
  	end
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.cfilter(c)
  	return c:IsLevel(3) and (c:GetBaseAttack() > 0 or c:GetBaseDefense() > 0) and c:IsAbleToGraveAsCost()
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		if e:GetLabel() ~= 1 then
  			return false
  		end
  		e:SetLabel(0)
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_DECK, 0, 1, nil) and Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  	e:SetLabelObject(g:GetFirst())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local sc = e:GetLabelObject()
  	if tc:IsFaceup() and tc:IsRelateToEffect(e) and sc then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(sc:GetAttack())
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_DEFENSE)
  		e2:SetValue(sc:GetDefense())
  		tc:RegisterEffect(e2)
  	end
  end
  
  