--[决斗编年史]化为暗道化师的MASAHIRO
function c20010001.initial_effect(c)
	--flip
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(20010001,0))
	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
	e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_FLIP)
	e1:SetTarget(c20010001.target)
	e1:SetOperation(c20010001.operation)
	c:RegisterEffect(e1)
end
function c20010001.ceget(c,tp)
	c20010001.card_effect_cache={}
	local code=c:GetOriginalCode()
	if not c20010001.card_effect_cache[code] then
		c20010001.card_effect_cache[code]={}
		local orig = Card.RegisterEffect
		Duel.RegisterEffect = function(c,e,f)
			local ccode=c:GetOriginalCode()
			local typ = e:GetType()
			if (typ & EFFECT_TYPE_ACTIONS)>0 then
				table.insert(c20010001.card_effect_cache[code],e:Clone())
			end
		end
		Duel.DisableActionCheck(true)
		Duel.CreateToken(tp,code)
		Duel.DisableActionCheck(false)
		Card.RegisterEffect = orig
		return 
	end
	return c20010001.card_effect_cache[code]
end
function c20010001.cfilter(c,tp)
	local effects=c20010001.ceget(c,tp)
	local canUse = false
	for i,ev in ipairs(effects) do
		c:RegisterEffect(ev)
		local f = ev:GetTarget()
		if f(ev,tp,nil,tp,0,nil,0,tp,0) then canUse = true end
		ev:Reset()
	end
	return c:IsType(TYPE_FLIP) and canUse
end
function c20010001.target(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
	local c=e:GetHandler()
	if chkc then return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and chkc:IsType(TYPE_FLIP) end
	if chk==0 then return Duel.IsExistingMatchingCard(c20010001.cfilter,tp,LOCATION_GRAVE,0,1,nil,TYPE_FLIP) end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_EFFECT)
	Duel.SelectTarget(tp,Card.IsType,tp,LOCATION_GRAVE,0,1,1,nil,TYPE_FLIP)
end
function c20010001.operation(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	local tc=Duel.GetFirstTarget()
	if tc:IsRelateToEffect(e) then
		local effects=c20010001.ceget(tc,tp)
		for i,ev in ipairs(effects) do
			if ev:IsHasType(EFFECT_TYPE_ACTIONS) then
				local f = ev:GetTarget()
				if f == nil or f(ev,tp,nil,tp,0,nil,0,tp,0) then
					Duel.RaiseEvent(tc,EVENT_CHAIN_ACTIVATING,ev,REASON_EFFECT,tp,tp,ev)
					if not f == nil then f(ev,tp,nil,tp,0,nil,0,tp,1) end
					Duel.RaiseEvent(tc,EVENT_CHAIN_SOLVING,ev,REASON_EFFECT,tp,tp,ev)
					f = ev:GetOperation()
					if not f == nil then f(ev,tp,nil,tp,nil,0,tp) end
					Duel.RaiseEvent(tc,EVENT_CHAIN_SOLVED,ev,REASON_EFFECT,tp,tp,ev)
					Duel.RaiseEvent(tc,EVENT_CHAIN_END,ev,REASON_EFFECT,tp,tp,ev)
				end
			end
		end
	end
end
