--D－HERO ディファレンシャルガイ
function c114514920.initial_effect(c)
	c:EnableReviveLimit()
	aux.AddFusionProcFun2(c,c114514920.matfilter1,c114514920.matfilter2,true)
	--spsummon condition
	local e0=Effect.CreateEffect(c)
	e0:SetType(EFFECT_TYPE_SINGLE)
	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
	e0:SetCode(EFFECT_SPSUMMON_CONDITION)
	e0:SetValue(aux.fuslimit)
	c:RegisterEffect(e0)
    --disable
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e2:SetCode(EVENT_CHAIN_SOLVING)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCondition(c114514920.discon)
	e2:SetOperation(c114514920.disop)
	c:RegisterEffect(e2)
    --spsummon
	local e3=Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(114514920,1))
--[[ 	e3:SetCategory(CATEGORY_SPECIAL_SUMMON) ]]
	e3:SetType(EFFECT_TYPE_QUICK_O)
	e3:SetCode(EVENT_FREE_CHAIN)
	e3:SetRange(LOCATION_MZONE)
	e3:SetHintTiming(0,TIMINGS_CHECK_MONSTER+TIMING_END_PHASE)
    e3:SetCountLimit(1,114514920)
	e3:SetCost(c114514920.spcost)
	e3:SetTarget(c114514920.sptg)
	e3:SetOperation(c114514920.spop)
	c:RegisterEffect(e3)
end
c114514920.material_setcode=0xc008
function c114514920.matfilter1(c)
	return c:IsFusionSetCard(0xc008) and c:IsFusionType(TYPE_FUSION)
end
function c114514920.matfilter2(c)
	return c:IsFusionSetCard(0x8) and c:IsLevelAbove(8) and c:IsFusionAttribute(ATTRIBUTE_DARK)
end
function c114514920.discon(e,tp,eg,ep,ev,re,r,rp)
    local disatk=Duel.GetChainInfo(ev,CHAININFO_TRIGGERING_ATTACK)
	return (re:IsActiveType(TYPE_MONSTER) and disatk<=3200) or (re:IsActiveType(TYPE_QUICKPLAY))
end
function c114514920.disop(e,tp,eg,ep,ev,re,r,rp)
	if rp==1-tp then
		Duel.NegateEffect(ev)
	end
end
function c114514920.spcost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToGraveAsCost,tp,LOCATION_HAND+LOCATION_ONFIELD,0,1,nil) end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)
	local g=Duel.SelectMatchingCard(tp,Card.IsAbleToGraveAsCost,tp,LOCATION_HAND+LOCATION_ONFIELD,0,1,1,nil)
	Duel.SendtoGrave(g,REASON_COST)
end
function c114514920.spfilter(c,e,tp)
	return c:IsSetCard(0xc008) and (c:IsCanBeSpecialSummoned(e,0,tp,false,false)
		or c:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP,1-tp))
end
function c114514920.sptg(e,tp,eg,ep,ev,re,r,rp,chk)
--[[ 	if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and c114514920.spfilter(chkc,e,tp) end ]]
	if chk==0 then return --[[ (Duel.GetLocationCount(tp,LOCATION_MZONE)>0 or Duel.GetLocationCount(1-tp,LOCATION_MZONE)>0)
		and Duel.IsExistingTarget(c114514920.spfilter,tp,LOCATION_GRAVE,0,1,nil,e,tp) and  ]] Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)>0 end
--[[ 	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
	local g=Duel.SelectTarget(tp,c114514920.spfilter,tp,LOCATION_GRAVE,0,1,1,nil,e,tp)
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,g,1,0,0)  ]]
end
function c114514920.spop(e,tp,eg,ep,ev,re,r,rp)
--[[ 	local tc=Duel.GetFirstTarget()
	if not tc:IsRelateToEffect(e) then return end
	local s1=Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and tc:IsCanBeSpecialSummoned(e,0,tp,false,false)
	local s2=Duel.GetLocationCount(1-tp,LOCATION_MZONE)>0 and tc:IsCanBeSpecialSummoned(e,0,tp,false,false,POS_FACEUP,1-tp)
	local op=0
	Duel.Hint(HINT_SELECTMSG,tp,0)
	if s1 and s2 then op=Duel.SelectOption(tp,aux.Stringid(114514920,3),aux.Stringid(114514920,4))
	elseif s1 then op=Duel.SelectOption(tp,aux.Stringid(114514920,3))
	elseif s2 then op=Duel.SelectOption(tp,aux.Stringid(114514920,4))+1
	else return end
	if op==0 then Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP) ]]
    if Duel.GetFieldGroupCount(tp,LOCATION_DECK,0)<1 then return end
    Duel.Hint(HINT_SELECTMSG,tp,aux.Stringid(114514920,2))
    local tc=Duel.SelectMatchingCard(tp,nil,tp,LOCATION_DECK,0,1,1,nil):GetFirst()
	op=Duel.SelectOption(tp,aux.Stringid(114514920,5),aux.Stringid(114514920,6))
	if op==0 then Duel.ShuffleDeck(tp)
		Duel.MoveSequence(tc,SEQ_DECKTOP)
		Duel.ConfirmDecktop(tp,1)
	else Duel.SendtoDeck(tc,1-tp,SEQ_DECKTOP,REASON_EFFECT)
		Duel.ShuffleDeck(tp)
	end
end