name: Shining
card_text: Cannot be destroyed by battle. At the end of the Damage Step, if this card battled an opponent's monster: You can place 1 Piece Counter on this card (max. 4), then you can apply the following effect, based on the number of Piece Counters on it.
  ● 1: Place 1 monster from your Deck on top of your Deck.
  ● 2: Draw 1 card.
  ● 3: Add 1 monster from your Deck to your hand.
  ● 4: Add 1 card from your Deck to your hand.
external_ids: local COUNTER_ID_0 = 0x5f --Piece
  
lua: local COUNTER_ID_0 = 0x5f --Piece
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5f)
  	c:SetCounterLimit(0x5f, 4)
  	--battle indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--add counter
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_COUNTER + CATEGORY_DRAW + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DAMAGE_STEP_END)
  	e2:SetTarget(s.cttg)
  	e2:SetOperation(s.ctop)
  	c:RegisterEffect(e2)
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tc = e:GetHandler():GetBattleTarget()
  	if chk == 0 then
  		return tc and e:GetHandler():IsCanAddCounter(COUNTER_ID_0, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 1, 0, 0x5f)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and c:IsFaceup() then
  		c:AddCounter(COUNTER_ID_0, 1)
  		local ct = c:GetCounter(COUNTER_ID_0)
  		local dg = Duel.GetMatchingGroup(Card.IsType, tp, LOCATION_DECK, 0, nil, TYPE_MONSTER)
  		if ct == 1 and dg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 4))
  			local g = dg:Select(tp, 1, 1, nil)
  			local tc = g:GetFirst()
  			if tc then
  				Duel.ShuffleDeck(tp)
  				Duel.MoveSequence(tc, SEQ_DECKTOP)
  				Duel.ConfirmDecktop(tp, 1)
  			end
  		end
  		if ct == 2 and Duel.IsPlayerCanDraw(tp, 1) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.BreakEffect()
  			Duel.Draw(tp, 1, REASON_EFFECT)
  		end
  		local mg = Duel.GetMatchingGroup(s.mfilter, tp, LOCATION_DECK, 0, nil)
  		if ct == 3 and mg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local g = mg:Select(tp, 1, 1, nil)
  			if g:GetCount() > 0 then
  				Duel.SendtoHand(g, nil, REASON_EFFECT)
  				Duel.ConfirmCards(1 - tp, g)
  			end
  		end
  		local cg = Duel.GetMatchingGroup(Card.IsAbleToHand, tp, LOCATION_DECK, 0, nil)
  		if ct == 4 and cg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 3)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local g = cg:Select(tp, 1, 1, nil)
  			if g:GetCount() > 0 then
  				g:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  				Duel.SendtoHand(g, nil, REASON_EFFECT)
  			end
  		end
  	end
  end
  function s.mfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  
  
source_text: Shining
  Cannot be destroyed by battle. At the end of the Damage Step, if this card battled an opponent's monster: You can place 1 Piece Counter on this card (max. 4), then you can apply the following effect, based on the number of Piece Counters on it.
  ● 1: Place 1 monster from your Deck on top of your Deck.
  ● 2: Draw 1 card.
  ● 3: Add 1 monster from your Deck to your hand.
  ● 4: Add 1 card from your Deck to your hand.
target_text: -- Shining
  local COUNTER_ID_0 = 0x5f --Piece
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5f)
  	c:SetCounterLimit(0x5f, 4)
  	--battle indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--add counter
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_COUNTER + CATEGORY_DRAW + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DAMAGE_STEP_END)
  	e2:SetTarget(s.cttg)
  	e2:SetOperation(s.ctop)
  	c:RegisterEffect(e2)
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tc = e:GetHandler():GetBattleTarget()
  	if chk == 0 then
  		return tc and e:GetHandler():IsCanAddCounter(COUNTER_ID_0, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 1, 0, 0x5f)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and c:IsFaceup() then
  		c:AddCounter(COUNTER_ID_0, 1)
  		local ct = c:GetCounter(COUNTER_ID_0)
  		local dg = Duel.GetMatchingGroup(Card.IsType, tp, LOCATION_DECK, 0, nil, TYPE_MONSTER)
  		if ct == 1 and dg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 4))
  			local g = dg:Select(tp, 1, 1, nil)
  			local tc = g:GetFirst()
  			if tc then
  				Duel.ShuffleDeck(tp)
  				Duel.MoveSequence(tc, SEQ_DECKTOP)
  				Duel.ConfirmDecktop(tp, 1)
  			end
  		end
  		if ct == 2 and Duel.IsPlayerCanDraw(tp, 1) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.BreakEffect()
  			Duel.Draw(tp, 1, REASON_EFFECT)
  		end
  		local mg = Duel.GetMatchingGroup(s.mfilter, tp, LOCATION_DECK, 0, nil)
  		if ct == 3 and mg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local g = mg:Select(tp, 1, 1, nil)
  			if g:GetCount() > 0 then
  				Duel.SendtoHand(g, nil, REASON_EFFECT)
  				Duel.ConfirmCards(1 - tp, g)
  			end
  		end
  		local cg = Duel.GetMatchingGroup(Card.IsAbleToHand, tp, LOCATION_DECK, 0, nil)
  		if ct == 4 and cg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 3)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local g = cg:Select(tp, 1, 1, nil)
  			if g:GetCount() > 0 then
  				g:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  				Duel.SendtoHand(g, nil, REASON_EFFECT)
  			end
  		end
  	end
  end
  function s.mfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  
  