--時の女神の悪戯 (Anime)
--Mischief of the Time Goddess (Anime)
--Scripted by Larry126
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:SetOperation(s.activate)
	c:RegisterEffect(e1)
end
function s.condition(e,tp,eg,ep,ev,re,r,rp)
	return Duel.GetCurrentChain(true)==0
end
function s.activate(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	if c:IsRelateToEffect(e) then
		Duel.SendtoGrave(c,REASON_EFFECT)
	end
	--prevent activations for the rest of that phase
	local e0=Effect.CreateEffect(c)
	e0:SetType(EFFECT_TYPE_FIELD)
	e0:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e0:SetCode(EFFECT_CANNOT_ACTIVATE)
	e0:SetTargetRange(1,1)
	e0:SetValue(1)
	e0:SetReset(RESET_PHASE+PHASE_END)
	Duel.RegisterEffect(e0,tp)
	--skip phases until Battle Phase
	local p=Duel.GetTurnPlayer()
	Duel.SkipPhase(p,PHASE_DRAW,RESET_PHASE|PHASE_END,1)
	Duel.SkipPhase(p,PHASE_STANDBY,RESET_PHASE|PHASE_END,1)
	Duel.SkipPhase(p,PHASE_MAIN1,RESET_PHASE|PHASE_END,1)
	Duel.SkipPhase(p,PHASE_BATTLE,RESET_PHASE|PHASE_END,1)
	Duel.SkipPhase(p,PHASE_MAIN2,RESET_PHASE|PHASE_END,1)
	Duel.SkipPhase(p,PHASE_END,RESET_PHASE|PHASE_END,1)
	Duel.SkipPhase(tp,PHASE_DRAW,RESET_PHASE|PHASE_END,p==tp and 2 or 1)
	Duel.SkipPhase(tp,PHASE_STANDBY,RESET_PHASE|PHASE_END,p==tp and 2 or 1)
	Duel.SkipPhase(tp,PHASE_MAIN1,RESET_PHASE|PHASE_END,p==tp and 2 or 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)
	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,Duel.GetCurrentPhase()<=PHASE_MAIN1 and 2 or 1)
	Duel.RegisterEffect(e2,tp)
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_FIELD)
	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e3:SetCode(EFFECT_CANNOT_EP)
	e3:SetTargetRange(0,1)
	e3:SetReset(RESET_PHASE+PHASE_END)
	Duel.RegisterEffect(e3,tp)
end