local m=120253004
local cm=_G["c"..m]
cm.name="暗冥穿越侍·危机"
function cm.initial_effect(c)
	--Summon Procedure
	cm.sumproc(c,aux.Stringid(m,2),ATTRIBUTE_LIGHT)
	cm.sumproc(c,aux.Stringid(m,3),ATTRIBUTE_DARK)
	cm.sumproc(c,aux.Stringid(m,4),ATTRIBUTE_FIRE)
	cm.sumproc(c,aux.Stringid(m,5),ATTRIBUTE_WATER)
	cm.sumproc(c,aux.Stringid(m,6),ATTRIBUTE_EARTH)
	cm.sumproc(c,aux.Stringid(m,7),ATTRIBUTE_WIND)
	cm.sumproc(c,aux.Stringid(m,8),ATTRIBUTE_DIVINE)
	local mat=RD.CreateAdvanceCount(c,3)
	--Destroy
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(m,0))
	e1:SetCategory(CATEGORY_DESTROY+CATEGORY_ATKCHANGE)
	e1:SetType(EFFECT_TYPE_IGNITION)
	e1:SetRange(LOCATION_MZONE)
	e1:SetLabelObject(mat)
	e1:SetCondition(cm.condition)
	e1:SetTarget(cm.target)
	e1:SetOperation(cm.operation)
	c:RegisterEffect(e1)
end
--Summon Procedure
function cm.sumproc(c,desc,attr)
	RD.AddSummonProcedure(c,desc,cm.sumcon(attr),cm.sumop(attr),SUMMON_TYPE_ADVANCE+SUMMON_VALUE_SELF)
end
function cm.sumcon(attr)
	return function(e,c,minc)
		if c==nil then return true end
		local mg=Duel.GetTributeGroup(c):Filter(Card.IsAttribute,nil,attr)
		return minc<=3 and Duel.CheckTribute(c,3,3,mg)
	end
end
function cm.sumop(attr)
	return function(e,tp,eg,ep,ev,re,r,rp,c)
		local mg=Duel.GetTributeGroup(c):Filter(Card.IsAttribute,nil,attr)
		Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_RELEASE)
		local g=Duel.SelectTribute(tp,c,3,3,mg)
		c:SetMaterial(g)
		Duel.Release(g,REASON_SUMMON+REASON_MATERIAL)
	end
end
--Destroy
function cm.condition(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	return RD.IsSummonTurn(c) and e:GetLabelObject():GetLabel()==3
end
function cm.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(nil,tp,0,LOCATION_ONFIELD,1,nil) end
	local g=Duel.GetMatchingGroup(nil,tp,0,LOCATION_ONFIELD,nil)
	Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0)
end
function cm.operation(e,tp,eg,ep,ev,re,r,rp)
	RD.SelectAndDoAction(HINTMSG_DESTROY,nil,tp,0,LOCATION_ONFIELD,1,1,nil,function(g)
		local c=e:GetHandler()
		local tc=g:GetFirst()
		if Duel.Destroy(tc,REASON_EFFECT)~=0 and tc:IsLevelAbove(1)
			and c:IsFaceup() and c:IsRelateToEffect(e) and Duel.SelectYesNo(tp,aux.Stringid(m,1)) then
			Duel.BreakEffect()
			local atk=tc:GetOriginalLevel()*200
			RD.AttachAtkDef(e,c,atk,0,RESET_EVENT+RESETS_STANDARD+RESET_DISABLE+RESET_PHASE+PHASE_END)
		end
	end)
end