--『诗人』
Duel.LoadScript("c60010000.lua")
local cm,m,o=GetID()
function cm.initial_effect(c)
	--xyz summon
	c:EnableReviveLimit()
	aux.AddXyzProcedureLevelFree(c,cm.mfilter,cm.xyzcheck,2,2)
	--to grave
	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(m,1))
	e2:SetCategory(CATEGORY_TOGRAVE)
	e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)
	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
	e2:SetCountLimit(1,m)
	e2:SetProperty(EFFECT_FLAG_DELAY)
	e2:SetCondition(cm.con)
	e2:SetTarget(cm.tg)
	e2:SetOperation(cm.op)
	c:RegisterEffect(e2)
	--spsummon
	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(12744567,1))
	e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetCountLimit(1,m+10000000)
	e2:SetProperty(EFFECT_FLAG_DELAY)
	e2:SetCondition(cm.spcon)
	e2:SetTarget(cm.sptg)
	e2:SetOperation(cm.spop)
	c:RegisterEffect(e2)
end
MTC.CheckEffectSetCode(Poet,CheckPoet,m,EVENT_SPSUMMON_SUCCESS)
MTC.CheckEffectSetCode(Poet2,CheckPoet2,m,EVENT_TO_GRAVE,EVENT_BE_MATERIAL,EVENT_BATTLE_DESTROYED)
function cm.mfilter(c,xyzc)
	return c:IsType(TYPE_MONSTER)
end
function cm.xyzcheck(g)
	return g:GetClassCount(Card.GetLevel)==1
end
function cm.con(e,tp,eg,ep,ev,re,r,rp)
	return e:GetHandler():IsSummonType(SUMMON_TYPE_XYZ)
end
function cm.tg(e,tp,eg,ep,ev,re,r,rp,chk)
	local g=e:GetHandler():GetOverlayGroup()
	local ac=g:GetFirst()
	for i=1,#g do   
		if not Poet[ac:GetCode()][1] then
			g:RemoveCard(ac)
			ac=g:GetNext()
		end
	end
	if chk==0 then return #g>0 end
end
function cm.op(e,tp,eg,ep,ev,re,r,rp)
	local g=e:GetHandler():GetOverlayGroup()
	local ac=g:GetFirst()
	for i=1,#g do   
		if not Poet[ac:GetCode()][1] then
			g:RemoveCard(ac)
			ac=g:GetNext()
		end
	end
	if #g==0 then return end
	MTC.CycleApplyOp(g,cm.apply,e,tp,c,Poet)
end
function cm.apply(e,tp,c,tablename)
	MTC.ApplyEffectSetCode(e,tp,c,tablename)
end

function cm.spcon(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	return c:IsPreviousLocation(LOCATION_MZONE) and c:GetOverlayCount()>0
end
function cm.sptg(e,tp,eg,ep,ev,re,r,rp,chk)
	local g=e:GetHandler():GetOverlayGroup():Filter(MTC.filterEffectSetCode,nil,Poet2)
	if chk==0 then return #g>0 end
end
function cm.spop(e,tp,eg,ep,ev,re,r,rp)
	local g=e:GetHandler():GetOverlayGroup():Filter(MTC.filterEffectSetCode,nil,Poet2)
	if #g==0 then return end
	MTC.CycleApplyOp(g,cm.apply,e,tp,c,Poet2)
end

