--大泽夜语
local s,id,o=GetID()
function s.initial_effect(c)
	-- activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCondition(s.condition)
	c:RegisterEffect(e1)
	-- remove setcode
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetCode(id)
	e2:SetRange(LOCATION_SZONE)
	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e2:SetTargetRange(1,1)
	c:RegisterEffect(e2)
	-- revolution!
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_IGNITION)
	e3:SetRange(LOCATION_SZONE)
	e3:SetCondition(s.condition)
	e3:SetCost(s.cost)
	e3:SetOperation(s.op)
	c:RegisterEffect(e3)

	if not s.gf then
		s.originIsSetCard = Card.IsSetCard
		Card.IsSetCard = s.IsSetCard
		s.originIsCodeListed = aux.IsCodeListed
		aux.IsCodeListed = s.IsCodeListed
		s.gf=true
	end
end

function s.condition(e,tp,eg,ep,ev,re,r,rp)
	return Duel.GetCurrentPhase()==PHASE_MAIN1 and not Duel.CheckPhaseActivity()
end

function s.cost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return e:GetHandler():IsAbleToGraveAsCost() end
	Duel.SendtoGrave(e:GetHandler(),REASON_COST)
end
function s.op(e,tp,eg,ep,ev,re,r,rp)
	local ge=Effect.CreateEffect(e:GetHandler())
	ge:SetType(EFFECT_TYPE_FIELD)
	ge:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	ge:SetCode(id)
	ge:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	ge:SetTargetRange(1,1)
	Duel.RegisterEffect(ge,tp)
end

function s.IsSetCard(c,set)
	if Duel.IsPlayerAffectedByEffect(c:GetControler(),id) then
		return false
	end
	return s.originIsSetCard(c,set)
end

function s.IsCodeListed(c,code)
	if Duel.IsPlayerAffectedByEffect(c:GetControler(),id) then
		return false
	end
	return s.originIsCodeListed(c,code)
end

