--治安战警队 御风者
local s,id,o=GetID()
local m=152220106
function s.initial_effect(c)
	--immune
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_FIELD)
	e3:SetCode(m)
	e3:SetRange(LOCATION_MZONE)
	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e3:SetTargetRange(1,0)
	c:RegisterEffect(e3)
	local e4=Effect.CreateEffect(c)
	e4:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e4:SetCode(EVENT_ADJUST)
	e4:SetRange(LOCATION_MZONE)
	e4:SetOperation(s.op)
	c:RegisterEffect(e4)
	--draw
	local e2=Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id,3))
	e2:SetCategory(CATEGORY_DRAW)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_CHAINING)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCountLimit(1,id)
	e2:SetCost(s.dcost)
	e2:SetCondition(s.dcon)
	e2:SetTarget(s.dtg)
	e2:SetOperation(s.dop)
	c:RegisterEffect(e2)
end
	--immune
function s.etarget(e,c)
	return not c:IsType(TYPE_EFFECT)
end
function s.efilter(e,re)
	return re:IsActiveType(TYPE_SPELL)
end

function s.op(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	--local g=Duel.GetMatchingGroup(Card.IsSetCard,tp,0x04,0,nil,0x156)
	local g=Duel.GetMatchingGroup(aux.TRUE,tp,0x04,0,nil)
	local tc=g:GetFirst()
	while tc do
		local ck=0
		if tc:IsImmuneToEffect(e) then
			tc:ResetFlagEffect(m)
			ck=1
		elseif tc:GetFlagEffect(m)==0 and ck==0 then
			tc:RegisterFlagEffect(m,RESET_EVENT+RESETS_STANDARD,0,1)
			local e1=Effect.CreateEffect(c)
			e1:SetType(EFFECT_TYPE_SINGLE)
			e1:SetCode(EFFECT_IMMUNE_EFFECT)
			e1:SetRange(LOCATION_MZONE)
			e1:SetReset(RESET_EVENT+RESETS_STANDARD)
			e1:SetCondition(s.convfilter)
			e1:SetValue(s.vafilter)
			tc:RegisterEffect(e1)
		end
		tc=g:GetNext()
	end
end

function s.convfilter(e)
	local c=e:GetHandler()
	local tp=c:GetControler()
	--Debug.Message(Duel.IsPlayerAffectedByEffect(tp,m) and c:GetFlagEffect(m)~=0)
	return Duel.IsPlayerAffectedByEffect(tp,m) and c:GetFlagEffect(m)~=0
end

function s.vafilter(e,te)
	local c=e:GetHandler()
	if te:IsActiveType(TYPE_MONSTER) and te:GetHandlerPlayer()~=e:GetHandlerPlayer() then
		if c:GetSequence()==5 then
			return te:GetActivateSequence()==3
		elseif c:GetSequence()==6 then
			return te:GetActivateSequence()==1
		else
			return te:GetActivateSequence()==4-c:GetSequence()
		end
	end
end
	--spsummon
function s.filter(c)
	return c:IsSetCard(0x156) and c:IsAbleToRemoveAsCost()
end
function s.dcon(e,tp,eg,ep,ev,re,r,rp)
	return re:IsActiveType(TYPE_SPELL+TYPE_TRAP) and re:IsHasType(EFFECT_TYPE_ACTIVATE) and ep==1-tp
end
function s.dcost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(s.filter,tp,LOCATION_HAND,0,1,nil) end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)
	local g=Duel.SelectMatchingCard(tp,s.filter,tp,LOCATION_HAND,0,1,1,nil)
	Duel.Remove(g,POS_FACEUP,REASON_COST)
end
function s.dtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsPlayerCanDraw(tp,2) end
	Duel.SetTargetPlayer(tp)
	Duel.SetTargetParam(2)
	Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,2)
end
function s.dop(e,tp,eg,ep,ev,re,r,rp)
	local p,d=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER,CHAININFO_TARGET_PARAM)
	Duel.Draw(p,d,REASON_EFFECT)
end