name: 光の封札剣
card_text: 1:相手の手札をランダムに1枚選んで裏側表示で除外する。
  このカードの発動後、相手ターンで数えて4ターン目の相手スタンバイフェイズに、そのカードを相手の手札に戻す。
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, 0, LOCATION_HAND, 1, nil, tp, POS_FACEDOWN)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, 1 - tp, LOCATION_HAND)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(1 - tp, LOCATION_HAND, 0)
  	local rs = g:RandomSelect(1 - tp, 1)
  	local card = rs:GetFirst()
  	if card == nil then
  		return
  	end
  	if Duel.Remove(card, POS_FACEDOWN, REASON_EFFECT) > 0 and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local ph = Duel.GetCurrentPhase()
  		local cp = Duel.GetTurnPlayer()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetRange(LOCATION_REMOVED)
  		e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  		e1:SetCountLimit(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 4)
  		e1:SetCondition(s.thcon)
  		e1:SetOperation(s.thop)
  		e1:SetLabel(1)
  		card:RegisterEffect(e1)
  		e:GetHandler():RegisterFlagEffect(1082946, RESET_PHASE + PHASE_END + RESET_SELF_TURN, 0, 3)
  		s[e:GetHandler()] = e1
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = e:GetLabel()
  	e:GetOwner():SetTurnCounter(ct)
  	if ct == 4 then
  		Duel.SendtoHand(e:GetHandler(), nil, REASON_EFFECT)
  		e:GetOwner():ResetFlagEffect(1082946)
  	else
  		e:SetLabel(ct + 1)
  	end
  end
  
  
source_text: 光の封札剣
  1:相手の手札をランダムに1枚選んで裏側表示で除外する。
  このカードの発動後、相手ターンで数えて4ターン目の相手スタンバイフェイズに、そのカードを相手の手札に戻す。
target_text: -- 光の封札剣
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, 0, LOCATION_HAND, 1, nil, tp, POS_FACEDOWN)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, 1 - tp, LOCATION_HAND)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetFieldGroup(1 - tp, LOCATION_HAND, 0)
  	local rs = g:RandomSelect(1 - tp, 1)
  	local card = rs:GetFirst()
  	if card == nil then
  		return
  	end
  	if Duel.Remove(card, POS_FACEDOWN, REASON_EFFECT) > 0 and e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local ph = Duel.GetCurrentPhase()
  		local cp = Duel.GetTurnPlayer()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetRange(LOCATION_REMOVED)
  		e1:SetCode(EVENT_PHASE + PHASE_STANDBY)
  		e1:SetCountLimit(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_STANDBY + RESET_SELF_TURN, 4)
  		e1:SetCondition(s.thcon)
  		e1:SetOperation(s.thop)
  		e1:SetLabel(1)
  		card:RegisterEffect(e1)
  		e:GetHandler():RegisterFlagEffect(1082946, RESET_PHASE + PHASE_END + RESET_SELF_TURN, 0, 3)
  		s[e:GetHandler()] = e1
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = e:GetLabel()
  	e:GetOwner():SetTurnCounter(ct)
  	if ct == 4 then
  		Duel.SendtoHand(e:GetHandler(), nil, REASON_EFFECT)
  		e:GetOwner():ResetFlagEffect(1082946)
  	else
  		e:SetLabel(ct + 1)
  	end
  end
  
  