--高速决斗技能-传说之骑士
Duel.LoadScript("speed_duel_common.lua")
function c100730014.initial_effect(c)
	aux.SpeedDuelAtMainPhase(c,c100730014.skill,c100730014.con,aux.Stringid(100730014,0))
	aux.SpeedDuelBeforeDraw(c,c100730014.skill2)
	aux.RegisterSpeedDuelSkillCardCommon()
end
function c100730014.con(e,tp)
	tp=e:GetLabelObject():GetOwner()
	return aux.SpeedDuelAtMainPhaseCondition(e,tp)
		and Duel.IsExistingMatchingCard(Card.IsCode,tp,LOCATION_HAND,0,1,nil,6368038)
		and Duel.GetMZoneCount(tp)>0
end

function c100730014.skill(e,tp,eg,ep,ev,re,r,rp)
	tp=e:GetLabelObject():GetOwner()
	local g=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_HAND,0,1,nil,6368038)
	local c=g:Select(tp,1,1,nil)
	if c then
	   Duel.Hint(HINT_CARD,1-tp,100730014)
	   Duel.ConfirmCards(1-tp,c)
		local e1=Effect.CreateEffect(e:GetHandler(c))
		e1:SetDescription(aux.Stringid(100730014,0))
		e1:SetType(EFFECT_TYPE_FIELD)
		e1:SetTargetRange(LOCATION_HAND,0)
		e1:SetCode(EFFECT_SUMMON_PROC)
		e1:SetTarget(c100730014.nttg)
		e1:SetReset(RESET_PHASE+PHASE_END)
		Duel.RegisterEffect(e1,tp)
	end 
	Duel.ShuffleHand(tp)
end
function c100730014.nttg(e,c)
	return c:IsCode(6368038)
end
function c100730014.skill2(e,tp)
	tp=e:GetLabelObject():GetOwner()
	local c=e:GetHandler()
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD)
	e2:SetCode(EFFECT_PIERCE)
	e2:SetTargetRange(LOCATION_MZONE,0)
	e2:SetTarget(c100730014.pietg)
	Duel.RegisterEffect(e2,tp)
	local e3=Effect.CreateEffect(c)
	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e3:SetTargetRange(1,0)
	e3:SetCategory(CATEGORY_DRAW)
	e3:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e3:SetCode(EVENT_BATTLE_DAMAGE)
	e3:SetValue(c100730014.abdcon)
	e3:SetCondition(c100730014.condition)
	e3:SetOperation(c100730014.op)
	Duel.RegisterEffect(e3,tp)
	local e4=Effect.CreateEffect(c)
	e4:SetType(EFFECT_TYPE_FIELD)
	e4:SetCode(EFFECT_CANNOT_TRIGGER)
	e4:SetProperty(EFFECT_FLAG_SET_AVAILABLE)
	e4:SetTargetRange(LOCATION_SZONE,0)
	e4:SetTarget(c100730014.distg)
	e4:SetCondition(c100730014.effcon)
	Duel.RegisterEffect(e4,tp)
	e:Reset()
end
function c100730014.effcon(e)
	return Duel.IsExistingMatchingCard(Card.IsFacedown,tp,LOCATION_SZONE,0,1,nil)
		and Duel.IsExistingMatchingCard(Card.IsCode,tp,LOCATION_MZONE,0,1,nil,6368038,16589042,66889139)
end
function c100730014.distg(e,c)
	return c:IsFacedown()
end
function c100730014.pietg(e,c)
	return c:IsCode(6368038,16589042,66889139)
end
function c100730014.condition(e,tp,eg,ep,ev,re,r,rp)
	local tc=eg:GetFirst()
	local bc=tc:GetBattleTarget()
	return tc:IsControler(tp) and bc and bc:IsDefensePos() and tc:IsCode(6368038,16589042,66889139)
end
function c100730014.abdcon(e)
	return Duel.GetTurnPlayer()==e:GetHandlerPlayer()
end
function c100730014.op(e,tp,eg,ep,ev,re,r,rp)
	local tc=e:GetLabelObject()
	local c=e:GetHandler()
	Duel.Hint(HINT_CARD,0,100730014)
	Duel.Draw(tp,2,REASON_RULE)
	Duel.ShuffleHand(tp)
	Duel.BreakEffect()
	Duel.DiscardHand(tp,nil,1,1,REASON_EFFECT+REASON_DISCARD)
end