--トゥーン・ワールド
function c30795251.initial_effect(c)
	--maintain
	local e4=Effect.CreateEffect(c)
	e4:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e4:SetProperty(EFFECT_FLAG_CANNOT_DISABLE+EFFECT_FLAG_UNCOPYABLE)
	e4:SetCode(EVENT_PHASE+PHASE_STANDBY)
	e4:SetRange(LOCATION_SZONE)
	e4:SetCountLimit(1)
	e4:SetOperation(c30795251.mtcond)
	e4:SetOperation(c30795251.mtop)
	c:RegisterEffect(e4)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCost(c30795251.cost)
	c:RegisterEffect(e1)
	--recover
	e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(30795251,0))
	e1:SetCategory(CATEGORY_RECOVER)
	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_F)
	e1:SetCode(EVENT_TO_GRAVE)
	e1:SetCondition(c30795251.reccon)
	e1:SetTarget(c30795251.target)
	e1:SetOperation(c30795251.operation)
	c:RegisterEffect(e1)
	local ge1=Effect.CreateEffect(c)
	ge1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	ge1:SetCode(EVENT_PAY_LPCOST)
	ge1:SetOperation(c30795251.checkop)
	Duel.RegisterEffect(ge1,0)
	if not c30795251.costcounter then c30795251.costcounter={} end
	c30795251.costcounter[e:GetHandler()]=0
end
function c30795251.reccon(e,tp,eg,ep,ev,re,r,rp)
	return e:GetHandler():IsPreviousLocation(LOCATION_SZONE)
		and e:GetHandler():IsPreviousPosition(POS_FACEUP)
end
function c30795251.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	Duel.SetTargetPlayer(tp)
	Duel.SetTargetParam(c30795251.costcounter[e:GetHandler()])
	Duel.SetOperationInfo(0,CATEGORY_RECOVER,nil,0,tp,c30795251.costcounter[e:GetHandler()])
end
function c30795251.operation(e,tp,eg,ep,ev,re,r,rp)
	local p,d=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER,CHAININFO_TARGET_PARAM)
	Duel.Recover(p,c30795251.costcounter[e:GetHandler()],REASON_EFFECT)
	c30795251.costcounter[e:GetHandler()]=0
end

function c30795251.checkop(e,tp,eg,ep,ev,re,r,rp)
	if re and re:GetHandler()==e:GetHandler() then
		c30795251.costcounter[e:GetHandler()]=c30795251.costcounter[e:GetHandler()] + val
	end
end
function c30795251.cost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.CheckLPCost(tp,1000) end
	c30795251.costcounter[e:GetHandler()]=0
	Duel.PayLPCost(tp,1000)
end

function c30795251.mtcond(e,tp,eg,ep,ev,re,r,rp)
	return Duel.GetTurnPlayer() == tp
end
function c30795251.mtop(e,tp,eg,ep,ev,re,r,rp)
	if Duel.CheckLPCost(tp,500) and Duel.SelectYesNo(tp,aux.Stringid(30795251,0)) then
		Duel.PayLPCost(tp,500)
	else
		Duel.Destroy(e:GetHandler(),REASON_COST)
	end
end