name: Madolche
card_text: 2 "Madolche" monsters
  While this card points to a "Madolche" monster, "Madolche" Spells/Traps you control cannot be destroyed by card effects, also neither player can target them with card effects. If this card on the field would be destroyed by battle or card effect, you can shuffle 1 "Madolche" monster from your GY into the Deck instead.
external_ids: local SETCARD_ID_0 = 0x71 --Madolche
  
lua: local SETCARD_ID_0 = 0x71 --Madolche
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 2, 2)
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_ONFIELD, 0)
  	e1:SetCondition(s.indescon)
  	e1:SetTarget(s.indestg)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.desreptg)
  	e3:SetOperation(s.desrepop)
  	c:RegisterEffect(e3)
  end
  function s.indesfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.indescon(e)
  	return e:GetHandler():GetLinkedGroup():IsExists(s.indesfilter, 1, nil)
  end
  function s.indestg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.desrepfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToDeck() and not c:IsHasEffect(EFFECT_NECRO_VALLEY)
  end
  function s.desreptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE) and Duel.IsExistingMatchingCard(s.desrepfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	return Duel.SelectEffectYesNo(tp, c, 96)
  end
  function s.desrepop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.desrepfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.HintSelection(g)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT + REASON_REPLACE)
  end
  
  
source_text: Madolche
  2 "Madolche" monsters
  While this card points to a "Madolche" monster, "Madolche" Spells/Traps you control cannot be destroyed by card effects, also neither player can target them with card effects. If this card on the field would be destroyed by battle or card effect, you can shuffle 1 "Madolche" monster from your GY into the Deck instead.
target_text: -- Madolche
  local SETCARD_ID_0 = 0x71 --Madolche
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 2, 2)
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_ONFIELD, 0)
  	e1:SetCondition(s.indescon)
  	e1:SetTarget(s.indestg)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTarget(s.desreptg)
  	e3:SetOperation(s.desrepop)
  	c:RegisterEffect(e3)
  end
  function s.indesfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.indescon(e)
  	return e:GetHandler():GetLinkedGroup():IsExists(s.indesfilter, 1, nil)
  end
  function s.indestg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.desrepfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToDeck() and not c:IsHasEffect(EFFECT_NECRO_VALLEY)
  end
  function s.desreptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE) and Duel.IsExistingMatchingCard(s.desrepfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	return Duel.SelectEffectYesNo(tp, c, 96)
  end
  function s.desrepop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.desrepfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.HintSelection(g)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT + REASON_REPLACE)
  end
  
  