--├宁静的行程┤
function c60151196.initial_effect(c)
	--Activate
    local e1=Effect.CreateEffect(c)
    e1:SetCategory(CATEGORY_TOGRAVE)
    e1:SetType(EFFECT_TYPE_ACTIVATE)
    e1:SetCode(EVENT_FREE_CHAIN)
    e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
    e1:SetCountLimit(1,60151196)
    e1:SetTarget(c60151196.target)
    e1:SetOperation(c60151196.activate)
    c:RegisterEffect(e1)
	--to hand
	local e2=Effect.CreateEffect(c)
	e2:SetCategory(CATEGORY_TOHAND)
	e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DELAY)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetCountLimit(1,60151196)
	e2:SetCondition(c60151196.drcon)
	e2:SetTarget(c60151196.drtg)
	e2:SetOperation(c60151196.drop)
	c:RegisterEffect(e2)
end
function c60151196.tgfilter(c)
    return c:IsSetCard(0x9b23) and c:IsAbleToGrave()
end
function c60151196.target(e,tp,eg,ep,ev,re,r,rp,chk)
    if chk==0 then return Duel.IsExistingMatchingCard(c60151196.tgfilter,tp,LOCATION_HAND,0,1,e:GetHandler()) 
		and Duel.IsPlayerCanDraw(tp,1) end
    Duel.SetOperationInfo(0,CATEGORY_TOGRAVE,nil,1,tp,LOCATION_HAND)
	Duel.SetTargetPlayer(tp)
    Duel.SetTargetParam(1)
    Duel.SetOperationInfo(0,CATEGORY_DRAW,nil,0,tp,1)
end
function c60151196.tgfilter2(c,ttype)
    return c:IsType(ttype) and c:IsFaceup() and c:IsAbleToDeck()
end
function c60151196.activate(e,tp,eg,ep,ev,re,r,rp)
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)
    local g=Duel.SelectMatchingCard(tp,c60151196.tgfilter,tp,LOCATION_HAND,0,1,1,e:GetHandler())
    local tc=g:GetFirst()
    if tc and Duel.SendtoGrave(tc,REASON_EFFECT)~=0 and tc:IsLocation(LOCATION_GRAVE) then
		local p,d=Duel.GetChainInfo(0,CHAININFO_TARGET_PLAYER,CHAININFO_TARGET_PARAM)
		Duel.Draw(p,d,REASON_EFFECT)
		local ttype=bit.band(tc:GetType(),0x7)
        local g2=Duel.GetMatchingGroup(c60151196.tgfilter2,tp,0,LOCATION_ONFIELD,nil,ttype)
        if g2:GetCount()>0 and Duel.SelectYesNo(tp,aux.Stringid(60151196,0)) then
            Duel.BreakEffect()
            Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK)
            local sg=g2:Select(tp,1,1,nil)
			Duel.HintSelection(sg)
            Duel.SendtoDeck(sg,nil,2,REASON_EFFECT)
        end
    end
end
function c60151196.drcon(e,tp,eg,ep,ev,re,r,rp)
	return e:GetHandler():IsReason(REASON_EFFECT)
end
function c60151196.thfilter(c)
    return c:IsSetCard(0x9b23) and c:IsAbleToHand()
end
function c60151196.drtg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(c60151196.thfilter,tp,LOCATION_GRAVE,0,1,e:GetHandler()) end
    Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_GRAVE)
end
function c60151196.drop(e,tp,eg,ep,ev,re,r,rp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
    local g=Duel.SelectMatchingCard(tp,c60151196.thfilter,tp,LOCATION_GRAVE,0,1,1,e:GetHandler())
    if g:GetCount()>0 then
        Duel.HintSelection(g)
        if Duel.SendtoHand(g,nil,REASON_EFFECT)~=0 then
			Duel.ConfirmCards(1-tp,g)
			local g2=Duel.GetMatchingGroup(Card.IsAbleToGrave,tp,LOCATION_HAND+LOCATION_ONFIELD,0,nil)
			if g2:GetCount()>0 and Duel.SelectYesNo(tp,aux.Stringid(60151101,0)) then
				Duel.BreakEffect()
				Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)
				local sg=g2:Select(tp,1,1,nil)
				Duel.SendtoGrave(sg,REASON_EFFECT)
			end
		end
    end
end