local cm,m,o=GetID()
function cm.initial_effect(c)
	vgf.VgCard(c)
	vgd.EffectTypeIgnition(c,m,LOCATION_MZONE,cm.op,vgf.DamageCost(1),vgf.VMonsterCondition)
	vgd.EffectTypeTrigger(c,m,LOCATION_MZONE,EFFECT_TYPE_SINGLE,EVENT_ATTACK_ANNOUNCE,cm.op2,nil,cm.con2)
end
function cm.op(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	local g=vgf.SelectMatchingCard(HINTMSG_FACEUP,e,tp,cm.filter,tp,LOCATION_ORDER,0,1,1,nil)
	Duel.RaiseEvent(g,EVENT_CUSTOM+EVENT_SING,e,0,tp,tp,0)
end
function cm.filter(c)
	return c:IsSetCard(0xa040) and c:IsPosition(POS_FACEUP)
end
function cm.con2(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	return vgf.RMonsterFilter(c) and vgf.IsExistingMatchingCard(Card.IsPosition,tp,LOCATION_ORDER,0,2,nil,POS_FACEDOWN)
end
function cm.op2(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	local g=vgf.SelectMatchingCard(HINTMSG_FACEUP,e,tp,cm.filter,tp,LOCATION_ORDER,0,1,1,nil)
	Duel.RaiseEvent(g,EVENT_CUSTOM+EVENT_SING,e,0,tp,tp,0)
    local e1=Effect.CreateEffect(c)
    e1:SetType(EFFECT_TYPE_FIELD)
    e1:SetCode(EFFECT_CANNOT_ACTIVATE)
    e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
    e1:SetTargetRange(0,1)
    e1:SetValue(cm.actlimit)
    Duel.RegisterEffect(e1,tp)
	vgf.EffectReset(c,e1,EVENT_BATTLED)
end
function cm.actlimit(e,te,tp)
	local tc=te:GetHandler()
    return te:IsHasCategory(CATEGORY_DEFENDER) and tc:IsType(TYPE_MONSTER) and tc:GetBaseDefense()==0 and tc:IsLocation(LOCATION_HAND)
end