--凶导的弔唱
function c114514397.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c) 
	e1:SetType(EFFECT_TYPE_ACTIVATE) 
	e1:SetCode(EVENT_FREE_CHAIN) 
	c:RegisterEffect(e1) 
	--to grave 
	local e1=Effect.CreateEffect(c) 
	e1:SetCategory(CATEGORY_TOGRAVE)
	e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O) 
	e1:SetCode(EVENT_SPSUMMON_SUCCESS) 
	e1:SetProperty(EFFECT_FLAG_DELAY+EFFECT_FLAG_CARD_TARGET) 
	e1:SetCountLimit(1,114514397) 
	e1:SetCondition(c114514397.con)
	e1:SetTarget(c114514397.actg) 
	e1:SetOperation(c114514397.acop) 
	c:RegisterEffect(e1) 
	--destroy replace
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_DESTROY_REPLACE)
	e2:SetRange(LOCATION_SZONE)
	e2:SetCountLimit(1,214514397) 
	e2:SetTarget(c114514397.desreptg)
	e2:SetValue(c114514397.desrepval)
	e2:SetOperation(c114514397.desrepop)
	c:RegisterEffect(e2)
end
function c114514397.cfilter(c,tp) 
	return c:IsSummonLocation(LOCATION_EXTRA) and c:IsFaceup() and c:IsSummonPlayer(tp) and Duel.IsExistingMatchingCard(c114514397.tgfil,tp,LOCATION_EXTRA,LOCATION_EXTRA,1,nil,c) 
end
function c114514397.con(e,tp,eg,ep,ev,re,r,rp)
	return eg:IsExists(c114514397.cfilter,1,nil,1-tp)
end
function c114514397.tgfil(c,sc) 
	local flag=0 
	if sc:IsType(TYPE_FUSION) then flag=bit.bor(flag,TYPE_FUSION) end
	if sc:IsType(TYPE_SYNCHRO) then flag=bit.bor(flag,TYPE_SYNCHRO) end
	if sc:IsType(TYPE_XYZ) then flag=bit.bor(flag,TYPE_XYZ) end 
	if sc:IsType(TYPE_LINK) then flag=bit.bor(flag,TYPE_LINK) end
	return c:IsType(flag) and c:IsAbleToGrave() 
end 
function c114514397.actg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return eg:IsExists(c114514397.tarfil,1,nil,e,tp) end 
	local g=eg:Filter(c114514397.tarfil,nil,e,tp):Select(tp,1,1,nil)
	Duel.SetTargetCard(g) 
	Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,PLAYER_ALL,LOCATION_EXTRA)
end 
function c114514397.acop(e,tp,eg,ep,ev,re,r,rp) 
	local c=e:GetHandler() 
	local tc=Duel.GetFirstTarget() 
	local g=Duel.GetMatchingGroup(c114514397.tgfil,tp,LOCATION_EXTRA,LOCATION_EXTRA,nil,tc)
	if g:GetCount()>0 then 
		Duel.SendtoGrave(g,REASON_EFFECT) 
	end 
end 
function c114514397.repfilter(c,tp)
	return c:IsControler(tp) and c:IsOnField() and c:IsSetCard(0x145) and c:IsType(TYPE_MONSTER) and c:IsType(TYPE_RITUAL) and c:IsReason(REASON_BATTLE+REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
end
function c114514397.desreptg(e,tp,eg,ep,ev,re,r,rp,chk)
	local c=e:GetHandler()
	if chk==0 then return eg:IsExists(c114514397.repfilter,1,nil,tp) and Duel.IsExistingMatchingCard(function(c) return c:IsAbleToRemove() and c:IsType(TYPE_FUSION+TYPE_SYNCHRO+TYPE_XYZ+TYPE_LINK) end,tp,LOCATION_GRAVE,LOCATION_GRAVE,1,nil) end
	return Duel.SelectEffectYesNo(tp,c,96)
end
function c114514397.desrepval(e,c)
	return c114514397.repfilter(c,e:GetHandlerPlayer())
end
function c114514397.desrepop(e,tp,eg,ep,ev,re,r,rp)
	local rg=Duel.SelectMatchingCard(tp,function(c) return c:IsAbleToRemove() and c:IsType(TYPE_FUSION+TYPE_SYNCHRO+TYPE_XYZ+TYPE_LINK) end,tp,LOCATION_GRAVE,LOCATION_GRAVE,1,1,nil) 
	Duel.Remove(rg,POS_FACEUP,REASON_EFFECT) 
	Duel.Hint(HINT_CARD,0,114514397)
end




