--闪光No.37 希望织龙 蜘蛛鲨龙
local s,id,o=GetID()
function c114514968.initial_effect(c)
	--xyz summon
	c:EnableReviveLimit()
	aux.AddXyzProcedure(c,aux.FilterBoolFunction(Card.IsAttribute,ATTRIBUTE_WATER),5,3,s.ovfilter,aux.Stringid(id,1))
    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_ONFIELD,0)
    e1:SetTarget(s.indtg)
    e1:SetValue(aux.indoval)
	c:RegisterEffect(e1)
	--disable
	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id,2))
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_CHAINING)
	e2:SetRange(LOCATION_MZONE)
    e2:SetCountLimit(1)
	e2:SetCondition(s.discon)
	e2:SetCost(s.cost)
	e2:SetTarget(s.distg)
	e2:SetOperation(s.disop)
	c:RegisterEffect(e2)
end
aux.xyz_number[114514968]=37
function s.ovfilter(c)
	return c:IsFaceup() and c:IsCode(37279508)
end
function s.indtg(e,c)
	return c:IsType(TYPE_SPELL+TYPE_TRAP)
end
--remove
function s.discon(e,tp,eg,ep,ev,re,r,rp)
	return re:IsActiveType(TYPE_MONSTER) and e:GetHandler():GetOverlayGroup():IsExists(Card.IsCode,1,nil,37279508)
end
function s.cost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return e:GetHandler():CheckRemoveOverlayCard(tp,1,REASON_COST) end
	e:GetHandler():RemoveOverlayCard(tp,1,1,REASON_COST)
end
function s.distg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	if re:GetHandler():IsLocation(LOCATION_ONFIELD) then
		Duel.SetOperationInfo(0,CATEGORY_REMOVE,eg,1,0,0)
	end
end
function s.filter(e,c)
	return c:IsType(TYPE_XYZ) and c:IsFaceup()
end
function s.disop(e,tp,eg,ep,ev,re,r,rp)
	if re:GetHandler():IsRelateToEffect(re) then
		local e1=Effect.CreateEffect(e:GetHandler())
		e1:SetType(EFFECT_TYPE_FIELD)
		e1:SetCode(EFFECT_IMMUNE_EFFECT)
		e1:SetTargetRange(LOCATION_MZONE,0)
		e1:SetTarget(s.filter)
		e1:SetValue(s.efilter)
		e1:SetReset(RESET_PHASE+PHASE_END)
		Duel.RegisterEffect(e1,tp)
		local ag=re:GetHandler()
		    if ag and ag:IsLocation(LOCATION_ONFIELD) and Duel.Remove(ag,POS_FACEUP,REASON_EFFECT+REASON_TEMPORARY)~=0 then
			    ag:RegisterFlagEffect(id,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,2)
			    local e1=Effect.CreateEffect(e:GetHandler())
			    e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
			    e1:SetCode(EVENT_PHASE+PHASE_END)
			    e1:SetReset(RESET_PHASE+PHASE_END,2)
			    e1:SetLabelObject(ag)
			    e1:SetCountLimit(1)
			    e1:SetCondition(s.retcon)
			    e1:SetOperation(s.retop)
			    e1:SetLabel(Duel.GetTurnCount())
			    Duel.RegisterEffect(e1,tp)
		    
		    end
	end
end
function s.efilter(e,re)
	return e:GetOwnerPlayer()~=re:GetOwnerPlayer() and re:IsActiveType(TYPE_MONSTER)
end
function s.retcon(e,tp,eg,ep,ev,re,r,rp)
	local tc=e:GetLabelObject()
	return Duel.GetTurnCount()~=e:GetLabel() and tc:GetFlagEffect(id)~=0
end
function s.retop(e,tp,eg,ep,ev,re,r,rp)
	Duel.ReturnToField(e:GetLabelObject())
end