--神心一刀流·樱华盛舞
function c66914012.initial_effect(c)
	--Activate
	local e12=Effect.CreateEffect(c)
	e12:SetType(EFFECT_TYPE_ACTIVATE)
	e12:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e12)
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e2:SetRange(LOCATION_FZONE)
	e2:SetCode(EVENT_CHAINING)
	e2:SetOperation(c66914012.adop)
	c:RegisterEffect(e2)
	--salvage
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_TOHAND)
	e1:SetType(EFFECT_TYPE_IGNITION)
	e1:SetCountLimit(1,66914013)
	e1:SetRange(LOCATION_FZONE)
	e1:SetCost(c66914012.thcost)
	e1:SetTarget(c66914012.thtg)
	e1:SetOperation(c66914012.thop)
	c:RegisterEffect(e1)	
end
function c66914012.adop(e,tp,eg,ep,ev,re,r,rp)
	local c=e:GetHandler()
	local ct=Duel.GetCurrentChain()
	if ct<2 then return end
	local te,p=Duel.GetChainInfo(ct-1,CHAININFO_TRIGGERING_EFFECT,CHAININFO_TRIGGERING_PLAYER)
	if te and p==tp then
		if  rp==tp  then
			Duel.RegisterFlagEffect(tp,66914013,RESET_CHAIN,0,1)
		end
		if  rp==1-tp  then
			Duel.RegisterFlagEffect(tp,66914014,RESET_CHAIN,0,1)
		end
	end
	if Duel.GetFlagEffect(tp,66914013)>=4 and Duel.GetFlagEffect(tp,66914011)==0 and Duel.IsExistingMatchingCard(c66914012.filter,tp,LOCATION_GRAVE,0,1,nil) and Duel.SelectYesNo(tp,aux.Stringid(66914012,0)) then
		Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
		local g=Duel.SelectMatchingCard(tp,c66914012.filter,tp,LOCATION_GRAVE,0,1,1,nil)
		if g:GetCount()>0 then
			Duel.SendtoHand(g,nil,REASON_EFFECT)
			Duel.ConfirmCards(1-tp,g)
		end
		Duel.RegisterFlagEffect(tp,66914011,0,0,1)
	end
	if Duel.GetFlagEffect(tp,66914014)>=2 and Duel.GetFlagEffect(tp,66914012)==0 and Duel.SelectYesNo(tp,aux.Stringid(66914012,1)) then
		local tg=Duel.GetMatchingGroup(c66914012.rmfilter,tp,0,LOCATION_ONFIELD+LOCATION_GRAVE,nil,tp)
		if tg:GetCount()>0 then
			Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_REMOVE)
			local sg=tg:Select(tp,1,1,nil)
			Duel.HintSelection(sg)
			Duel.Remove(sg,POS_FACEDOWN,REASON_EFFECT)
		end
		Duel.RegisterFlagEffect(tp,66914012,0,0,1)
	end
end
function c66914012.rmfilter(c,tp)
	return c:IsAbleToRemove(tp,POS_FACEDOWN)
end
function c66914012.thcost(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(Card.IsDiscardable,tp,LOCATION_HAND,0,1,e:GetHandler()) end
	Duel.DiscardHand(tp,Card.IsDiscardable,1,1,REASON_COST+REASON_DISCARD)
end
function c66914012.filter(c)
	return c:IsSetCard(0x373) and c:IsAbleToHand()
end
function c66914012.thtg(e,tp,eg,ep,ev,re,r,rp,chk,chkc)
	if chk==0 then return Duel.IsExistingMatchingCard(c66914012.filter,tp,LOCATION_GRAVE,0,1,nil) end
	Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_GRAVE)
end
function c66914012.thop(e,tp,eg,ep,ev,re,r,rp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
	local g=Duel.SelectMatchingCard(tp,c66914012.filter,tp,LOCATION_GRAVE,0,1,1,nil)
	if g:GetCount()>0 then
		Duel.SendtoHand(g,nil,REASON_EFFECT)
		Duel.ConfirmCards(1-tp,g)
	end
end