--恶魔真名-阿斯莫德
function c114514297.initial_effect(c)
	c:EnableReviveLimit()
	--change name
	aux.EnableChangeCode(c,70781052,LOCATION_MZONE+LOCATION_GRAVE)
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_SPSUMMON_PROC)
	e2:SetRange(LOCATION_HAND)
	e2:SetProperty(EFFECT_FLAG_UNCOPYABLE)
	e2:SetCondition(c114514297.spcon2)
	c:RegisterEffect(e2)	
	--spsummon
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(114514297,0))
	e1:SetCategory(CATEGORY_DESTROY+CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_IGNITION)
	e1:SetRange(LOCATION_HAND)
	e1:SetCountLimit(1,114514297)
	e1:SetCost(c114514297.spcost)
	e1:SetTarget(c114514297.sptg)
	e1:SetOperation(c114514297.spop)
	c:RegisterEffect(e1)
	--burial
	local e3=Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(114514297,1))
	e3:SetCategory(CATEGORY_TOGRAVE)
	e3:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
	e3:SetCode(EVENT_TO_GRAVE)
	e3:SetProperty(EFFECT_FLAG_DELAY)
	e3:SetCountLimit(1,114514297)
	e3:SetTarget(c114514297.tgtg)
	e3:SetOperation(c114514297.tgop)
	c:RegisterEffect(e3)
	--to graveyard
	local e31=Effect.CreateEffect(c)
	e31:SetDescription(aux.Stringid(114514297,1))
	e31:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_F)
	e31:SetCode(EVENT_SUMMON_SUCCESS)
	e31:SetRange(LOCATION_MZONE)
	e31:SetCondition(c114514297.tgcon1)
	e31:SetTarget(c114514297.tgtg1)
	e31:SetOperation(c114514297.tgop1)
	c:RegisterEffect(e31)
	local e4=e31:Clone()
	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
	c:RegisterEffect(e4)
end
function c114514297.cfilter(c)
	return c:IsFaceup() and c:IsCode(70781052)
end
function c114514297.spcon2(e,c)
	if c==nil then return true end
	local tp=c:GetControler()
	return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
		and Duel.IsExistingMatchingCard(c114514297.cfilter,tp,LOCATION_MZONE,0,5,nil)
end
function c114514297.spcost(e,tp,eg,ep,ev,re,r,rp,chk)
	local c=e:GetHandler()
	if chk==0 then return c:IsDiscardable() end
	Duel.SendtoGrave(c,REASON_COST+REASON_DISCARD)
end
function c114514297.spfilter(c,e,tp)
	return c:IsSetCard(0x45) and c:IsLevelBelow(8) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
end
function c114514297.sptg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
		and Duel.IsExistingMatchingCard(c114514297.spfilter,tp,LOCATION_DECK,0,1,nil,e,tp) end
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_DECK)
	local g=Duel.GetFieldGroup(tp,LOCATION_ONFIELD,0)
	if g:GetCount()>0 then
		Duel.SetOperationInfo(0,CATEGORY_DESTROY,g,1,0,0)
	end
end
function c114514297.spop(e,tp,eg,ep,ev,re,r,rp)
	if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
	local g=Duel.SelectMatchingCard(tp,c114514297.spfilter,tp,LOCATION_DECK,0,1,1,nil,e,tp)
	if Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP_DEFENSE)~=0 then
		Duel.BreakEffect()
		Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_DESTROY)
		local g=Duel.SelectMatchingCard(tp,nil,tp,LOCATION_ONFIELD,0,1,1,nil)
		if g:GetCount()>0 then
			Duel.Destroy(g,REASON_EFFECT)
		end
	end
end
function c114514297.tgfilter(c)
	return c:IsSetCard(0x45) and c:IsAbleToGrave()
end
function c114514297.tgtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(c114514297.tgfilter,tp,LOCATION_DECK,0,1,nil) end
	Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_DECK)
end
function c114514297.tgop(e,tp,eg,ep,ev,re,r,rp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)
	local g=Duel.SelectMatchingCard(tp,c114514297.tgfilter,tp,LOCATION_DECK,0,1,1,nil)
	if g:GetCount()>0 then
		Duel.SendtoGrave(g,REASON_EFFECT)
	end
end
function c114514297.tkcfilter(c,tp)
	return c:IsControler(tp)
end
function c114514297.tgcon1(e,tp,eg,ep,ev,re,r,rp)
	return eg:IsExists(c114514297.tkcfilter,1,nil,1-tp)
end
function c114514297.tgtg1(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return eg:IsExists(c114514297.tkcfilter,1,nil,1-tp) end
	local g=eg:Filter(c114514297.tkcfilter,nil,1-tp)
	Duel.SetTargetCard(g)
end
function c114514297.tgfilter1(c,e)
	return c:IsRelateToEffect(e) and not c:IsImmuneToEffect(e)
end
function c114514297.tgop1(e,tp,eg,ep,ev,re,r,rp)
	local g=Duel.GetTargetsRelateToChain():Filter(Card.IsControler,nil,1-tp)
	local dg=Group.CreateGroup()
	local c=e:GetHandler()
	local tc=g:GetFirst()
	while tc do
			c:SetCardTarget(tc)
			local e1=Effect.CreateEffect(c)
			e1:SetType(EFFECT_TYPE_SINGLE)
			e1:SetCode(EFFECT_SET_CONTROL)
			e1:SetValue(tp)
			e1:SetReset(RESET_EVENT+RESETS_STANDARD)
			e1:SetCondition(c114514297.ctcon)
			tc:RegisterEffect(e1)
	end
end
function c114514297.ctcon(e)
	local c=e:GetOwner()
	local h=e:GetHandler()
	return c:IsHasCardTarget(h)
end