--時の女神の悪戯
--Mischief of the Time Goddess
local s,id=GetID()
function s.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id,0))
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(TIMING_BATTLE_END)
	e1:SetCondition(s.condition)
	e1:SetTarget(s.target)
	e1:SetOperation(s.operation)
	c:RegisterEffect(e1)
end
s.listed_series={SET_VALKYRIE}
s.listed_names={92182447}
function s.condition(e,tp,eg,ep,ev,re,r,rp)
	if Duel.IsTurnPlayer(1-tp) or Duel.GetCurrentPhase()~=PHASE_BATTLE or Duel.GetCurrentChain(true)>0 then
		return false
	end
	local g=Duel.GetFieldGroup(tp,LOCATION_MZONE,0)
	return #g>0 and g:FilterCount(aux.FaceupFilter(Card.IsSetCard,SET_VALKYRIE),nil)==#g
end
function s.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return true end
	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
		Duel.SetChainLimit(aux.FALSE)
	end
end
function s.operation(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	if c:IsRelateToEffect(e) then
		Duel.SendtoGrave(c,REASON_EFFECT)
	end
	--skip phases until Battle Phase
	Duel.SkipPhase(tp,PHASE_BATTLE,RESET_PHASE|PHASE_END,1)
	--prevent activations for the rest of that battle phase
	local e0=Effect.CreateEffect(c)
	e0:SetType(EFFECT_TYPE_FIELD)
	e0:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e0:SetCode(EFFECT_CANNOT_ACTIVATE)
	e0:SetTargetRange(0,1)
	e0:SetValue(1)
	e0:SetReset(RESET_PHASE|PHASE_BATTLE|PHASE_END)
	Duel.RegisterEffect(e0,tp)
	Duel.SkipPhase(tp,PHASE_MAIN2,RESET_PHASE|PHASE_END,1)
	Duel.SkipPhase(tp,PHASE_END,RESET_PHASE|PHASE_END,1)
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_FIELD)
	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e1:SetCode(EFFECT_SKIP_TURN)
	e1:SetTargetRange(0,1)
	e1:SetReset(RESET_PHASE|PHASE_END|RESET_OPPO_TURN)
	Duel.RegisterEffect(e1,tp)
	Duel.SkipPhase(tp,PHASE_DRAW,RESET_PHASE|PHASE_END,2)
	Duel.SkipPhase(tp,PHASE_STANDBY,RESET_PHASE|PHASE_END,2)
	Duel.SkipPhase(tp,PHASE_MAIN1,RESET_PHASE|PHASE_END,2)
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e2:SetCode(EFFECT_CANNOT_EP)
	e2:SetTargetRange(1,0)
	e2:SetReset(RESET_PHASE|PHASE_MAIN1|RESET_SELF_TURN)
	Duel.RegisterEffect(e2,tp)
	--prevent activation of "Mischief of the Time Goddess"
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_FIELD)
	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET+EFFECT_FLAG_OATH+EFFECT_FLAG_CLIENT_HINT)
	e3:SetDescription(aux.Stringid(id,1))
	e3:SetCode(EFFECT_CANNOT_ACTIVATE)
	e3:SetTargetRange(1,0)
	e3:SetValue(s.limit)
	e3:SetReset(RESET_PHASE|PHASE_END,3)
	Duel.RegisterEffect(e3,tp)
end
function s.limit(e,re,tp)
	return re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:GetHandler():IsCode(92182447)
end