--甲虫装机 盖诺赛克特
function c114514816.initial_effect(c)
	--xyz summon
	aux.AddXyzProcedure(c,aux.FilterBoolFunction(Card.IsRace,RACE_INSECT),7,2)
	c:EnableReviveLimit()   
	--lv change
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetCode(EFFECT_XYZ_LEVEL)
	e1:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
	e1:SetRange(LOCATION_EXTRA)
	e1:SetTargetRange(LOCATION_MZONE,0)
	e1:SetTarget(c114514816.lvtg)
	e1:SetValue(c114514816.lvval)
	c:RegisterEffect(e1) 
	--equip
	local e1=Effect.CreateEffect(c) 
	e1:SetDescription(aux.Stringid(114514816,0))
	e1:SetCategory(CATEGORY_EQUIP)
	e1:SetType(EFFECT_TYPE_IGNITION) 
	e1:SetRange(LOCATION_MZONE)   
	e1:SetCost(function(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) 
	e1:SetTarget(c114514816.eqtg)
	e1:SetOperation(c114514816.eqop)
	c:RegisterEffect(e1) 
	--sp 
	local e2=Effect.CreateEffect(c) 
	e2:SetDescription(aux.Stringid(114514816,1))
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_FREE_CHAIN) 
	e2:SetHintTiming(0,TIMINGS_CHECK_MONSTER)
	e2:SetRange(LOCATION_MZONE)   
	e2:SetCountLimit(1,114514816)
	e2:SetCost(c114514816.spcost) 
	e2:SetTarget(c114514816.sptg)
	e2:SetOperation(c114514816.spop)
	c:RegisterEffect(e2)  
	--negate
	local e3=Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(114514816,2))
	e3:SetCategory(CATEGORY_DISABLE+CATEGORY_DESTROY)
	e3:SetType(EFFECT_TYPE_QUICK_O)
	e3:SetCode(EVENT_CHAINING)
	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL)
	e3:SetRange(LOCATION_MZONE)
	e3:SetCountLimit(1,114514816) 
	e3:SetCondition(c114514816.discon)
	e3:SetTarget(c114514816.distg)
	e3:SetOperation(c114514816.disop)
	c:RegisterEffect(e3)
	local e5=Effect.CreateEffect(c)
	e5:SetType(EFFECT_TYPE_SINGLE)
	e5:SetCode(EFFECT_UPDATE_ATTACK)
	e5:SetRange(LOCATION_MZONE)
	e5:SetCondition(c114514816.atkcon)
	e5:SetValue(1000)
	c:RegisterEffect(e5)
end
function c114514816.lvtg(e,c)
	return c:IsLevelAbove(1) and c:GetEquipCount()>0 
end
function c114514816.lvval(e,c,rc)
	local lv=c:GetLevel()
	if rc==e:GetHandler() then return 7
	else return lv end
end
function c114514816.filter(c)
	return c:IsSetCard(0x56) and not c:IsForbidden()
end
function c114514816.eqtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.GetLocationCount(tp,LOCATION_SZONE)>0
		and Duel.IsExistingMatchingCard(c114514816.filter,tp,LOCATION_GRAVE+LOCATION_HAND+LOCATION_DECK,0,1,nil) end
	Duel.SetOperationInfo(0,CATEGORY_LEAVE_GRAVE,nil,1,tp,LOCATION_GRAVE+LOCATION_HAND+LOCATION_DECK)
end
function c114514816.eqop(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	if Duel.GetLocationCount(tp,LOCATION_SZONE)<=0 then return end
	if c:IsFacedown() or not c:IsRelateToEffect(e) then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_EQUIP)
	local g=Duel.SelectMatchingCard(tp,aux.NecroValleyFilter(c114514816.filter),tp,LOCATION_GRAVE+LOCATION_HAND+LOCATION_DECK,0,1,1,nil)
	local tc=g:GetFirst()
	if tc then
		if not Duel.Equip(tp,tc,c) then return end
		local e1=Effect.CreateEffect(c)
		e1:SetProperty(EFFECT_FLAG_COPY_INHERIT+EFFECT_FLAG_OWNER_RELATE)
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetCode(EFFECT_EQUIP_LIMIT)
		e1:SetReset(RESET_EVENT+RESETS_STANDARD)
		e1:SetValue(c114514816.eqlimit)
		tc:RegisterEffect(e1)
	end
end
function c114514816.eqlimit(e,c)
	return e:GetOwner()==c
end 
function c114514816.spcost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return e:GetHandler():IsAbleToExtraAsCost() end 
	Duel.SendtoDeck(e:GetHandler(),nil,2,REASON_COST) 
end 
function c114514816.spfilter(c,e,tp) 
	if not (c:IsSetCard(0x56) and not c:IsCode(114514816) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)) then return false end 
	if c:IsLocation(LOCATION_EXTRA) then 
		return Duel.GetLocationCountFromEx(tp,tp,e:GetHandler(),c)>0 
	else 
		return Duel.GetMZoneCount(tp,e:GetHandler())>0  
	end  
end
function c114514816.sptg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(c114514816.spfilter,tp,LOCATION_DECK+LOCATION_EXTRA,0,1,nil,e,tp) end
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_DECK+LOCATION_EXTRA)
end
function c114514816.spop(e,tp,eg,ep,ev,re,r,rp) 
	local c=e:GetHandler()
	if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
	local tc=Duel.SelectMatchingCard(tp,c114514816.spfilter,tp,LOCATION_DECK+LOCATION_EXTRA,0,1,1,nil,e,tp):GetFirst()
	if tc and Duel.SpecialSummon(tc,0,tp,tp,false,false,POS_FACEUP)~=0 and tc:IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(function(c) return c:IsCanOverlay() and c:IsType(TYPE_MONSTER) and c:IsSetCard(0x56) end,tp,LOCATION_GRAVE,0,1,nil) and Duel.SelectYesNo(tp,aux.Stringid(114514816,3)) then
		local og=Duel.SelectMatchingCard(tp,function(c) return c:IsCanOverlay() and c:IsType(TYPE_MONSTER) and c:IsSetCard(0x56) end,tp,LOCATION_GRAVE,0,1,1,nil) 
		Duel.Overlay(tc,og)  
	end
end 
function c114514816.discon(e,tp,eg,ep,ev,re,r,rp) 
	local c=e:GetHandler() 
	local mg=c:GetEquipGroup() 
	local flag=0 
	if mg:IsExists(function(c) return bit.band(c:GetOriginalType(),TYPE_MONSTER)~=0 end,1,nil) then flag=bit.bor(flag,TYPE_MONSTER) end 
	if mg:IsExists(function(c) return bit.band(c:GetOriginalType(),TYPE_SPELL)~=0 end,1,nil) then flag=bit.bor(flag,TYPE_SPELL) end 
	if mg:IsExists(function(c) return bit.band(c:GetOriginalType(),TYPE_TRAP)~=0 end,1,nil) then flag=bit.bor(flag,TYPE_TRAP) end 
	return rp==1-tp and re:IsActiveType(flag) and Duel.IsChainDisablable(ev) and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED)  
end
function c114514816.distg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	Duel.SetOperationInfo(0,CATEGORY_DISABLE,eg,1,0,0)
	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
		Duel.SetOperationInfo(0,CATEGORY_DESTROY,eg,1,0,0)
	end
end
function c114514816.disop(e,tp,eg,ep,ev,re,r,rp)
	if Duel.NegateEffect(ev) and re:GetHandler():IsRelateToEffect(re) then
		Duel.Destroy(eg,REASON_EFFECT)
	end
end
function c114514816.atkcon(e)
	return Duel.GetTurnPlayer()==e:GetHandlerPlayer()
end