--トポロジック・ガンブラー・ドラゴン
function c114514008.initial_effect(c)
	--link summon
	aux.AddLinkProcedure(c,aux.FilterBoolFunction(Card.IsLinkType,TYPE_EFFECT),2)
	c:EnableReviveLimit()
	--discard
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(114514008,0))
	e1:SetCategory(CATEGORY_HANDES)
	e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)
	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
	e1:SetRange(LOCATION_MZONE)
	e1:SetCountLimit(1,114514008)
	e1:SetCost(c114514008.cost)
	e1:SetCondition(c114514008.hdcon)
	e1:SetTarget(c114514008.hdtg)
	e1:SetOperation(c114514008.hdop)
	c:RegisterEffect(e1)
	--discard
	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(114514008,1))
	e2:SetCategory(CATEGORY_HANDES+CATEGORY_DAMAGE)
	e2:SetType(EFFECT_TYPE_IGNITION)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCountLimit(1,114514008)
	e2:SetCost(c114514008.cost)
	e2:SetCondition(c114514008.hdcon2)
	e2:SetTarget(c114514008.hdtg2)
	e2:SetOperation(c114514008.hdop2)
	c:RegisterEffect(e2)
	--immune
	local e3=Effect.CreateEffect(c)
	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
	e3:SetType(EFFECT_TYPE_FIELD)
	e3:SetRange(LOCATION_MZONE)
	e3:SetTargetRange(LOCATION_MZONE,0)
	e3:SetCondition(c114514008.hdcon2)
	e3:SetTarget(c114514008.target)
	e3:SetValue(1)
	c:RegisterEffect(e3)
	local e4=e3:Clone()
	e4:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	c:RegisterEffect(e4)
	local e5=Effect.CreateEffect(c)
	e5:SetType(EFFECT_TYPE_SINGLE)
	e5:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e5:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
	e5:SetRange(LOCATION_MZONE,0)
	e5:SetCondition(c114514008.hdcon2)
	e5:SetTarget(c114514008.target)
	e5:SetValue(c114514008.efilter)
	c:RegisterEffect(e5)
	Duel.AddCustomActivityCounter(114514008,ACTIVITY_SPSUMMON,c114514008.counterfilter)
end
function c114514008.counterfilter(c)
	return not c:IsAttribute(ATTRIBUTE_DARK)
end
function c114514008.cost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.GetCustomActivityCount(114514008,tp,ACTIVITY_SPSUMMON)==0 end
	local e1=Effect.CreateEffect(e:GetHandler())
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH)
	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
	e1:SetReset(RESET_PHASE+PHASE_END)
	e1:SetTargetRange(1,0)
	e1:SetTarget(c114514008.splimit)
	Duel.RegisterEffect(e1,tp)
end
function c114514008.splimit(e,c)
	return not c:IsAttribute(ATTRIBUTE_DARK)
end
function c114514008.cfilter(c,zone)
	local seq=c:GetSequence()
	if c:IsControler(1) then seq=seq+16 end
	return bit.extract(zone,seq)~=0
end
function c114514008.hdcon(e,tp,eg,ep,ev,re,r,rp)
	local zone=Duel.GetLinkedZone(0)+Duel.GetLinkedZone(1)*0x10000
	return not eg:IsContains(e:GetHandler()) and eg:IsExists(c114514008.cfilter,1,nil,zone) and Duel.GetLP(e:GetHandlerPlayer())>Duel.GetLP(1-e:GetHandlerPlayer())
end
function c114514008.hdtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	Duel.SetOperationInfo(0,CATEGORY_HANDES,nil,0,tp,1)
	Duel.SetOperationInfo(0,CATEGORY_HANDES,nil,0,1-tp,1)
end
function c114514008.hdop(e,tp,eg,ep,ev,re,r,rp)
	local hg=Duel.GetFieldGroup(tp,LOCATION_HAND,0)
	local ct=math.min(hg:GetCount(),2)
	if ct<=0 then return end
	local ct2=1
	if ct>1 then ct2=Duel.AnnounceNumber(tp,1,2) end
	local g=hg:RandomSelect(tp,ct2)
	local ct3=Duel.SendtoGrave(g,REASON_EFFECT+REASON_DISCARD)
	if ct3<=0 then return end
	Duel.BreakEffect()
	Duel.DiscardHand(1-tp,nil,ct3,ct3,REASON_EFFECT+REASON_DISCARD)
end
function c114514008.hdcon2(e)
	return e:GetHandler():IsExtraLinkState()
end
function c114514008.hdtg2(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.GetFieldGroupCount(1-tp,LOCATION_HAND,0)>0 end
	Duel.SetOperationInfo(0,CATEGORY_HANDES,nil,0,1-tp,2)
end
function c114514008.hdop2(e,tp,eg,ep,ev,re,r,rp)
	if Duel.DiscardHand(1-tp,nil,2,2,REASON_EFFECT+REASON_DISCARD)~=0
		and Duel.GetFieldGroupCount(1-tp,LOCATION_HAND,0)==0 then
		Duel.Damage(1-tp,3000,REASON_EFFECT)
	end
end
function c114514008.target(e,c)
	return c:IsType(TYPE_LINK)
end
function c114514008.efilter(e,re,rp)
	return re:IsActiveType(TYPE_MONSTER)
end