name: Lib
card_text: 2 monsters
  Can only be Link Summoned while you have a "World Legacy" card in your GY. You can only use each of the following effects of "Lib the World Key Blademaster" once per turn.
  ● During your Main Phase: You can Set 1 "World Legacy" Spell/Trap from your Deck, but it cannot be activated this turn while you have no "World Legacy" monster in your GY.
  ● If this Link Summoned card is sent to the GY as Link Material: You can shuffle 1 card on the field into the Deck.
external_ids: local SETCARD_ID_0 = 0xfe --World
  
lua: local SETCARD_ID_0 = 0xfe --World
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, nil, 2, 2)
  	--spsummon condition
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_SINGLE)
  	e0:SetCode(EFFECT_SPSUMMON_COST)
  	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e0:SetCost(s.spcost)
  	c:RegisterEffect(e0)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sttg)
  	e1:SetOperation(s.stop)
  	c:RegisterEffect(e1)
  	--to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BE_MATERIAL)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.tdcon)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  function s.spcost(e, c, tp, st)
  	if bit.band(st, SUMMON_TYPE_LINK) ~= SUMMON_TYPE_LINK then
  		return true
  	end
  	return Duel.IsExistingMatchingCard(Card.IsSetCard, tp, LOCATION_GRAVE, 0, 1, nil, 0xfe)
  end
  function s.stfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsSSetable() and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.sttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.stfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.stop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.stfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc and Duel.SSet(tp, tc) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_TRIGGER)
  		e1:SetCondition(s.aclimit)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.actfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.aclimit(e)
  	return not e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED) and not Duel.IsExistingMatchingCard(s.actfilter, e:GetHandlerPlayer(), LOCATION_GRAVE, 0, 1, nil)
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsSummonType(SUMMON_TYPE_LINK) and r == REASON_LINK and c:IsLocation(LOCATION_GRAVE)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  
source_text: Lib
  2 monsters
  Can only be Link Summoned while you have a "World Legacy" card in your GY. You can only use each of the following effects of "Lib the World Key Blademaster" once per turn.
  ● During your Main Phase: You can Set 1 "World Legacy" Spell/Trap from your Deck, but it cannot be activated this turn while you have no "World Legacy" monster in your GY.
  ● If this Link Summoned card is sent to the GY as Link Material: You can shuffle 1 card on the field into the Deck.
target_text: -- Lib
  local SETCARD_ID_0 = 0xfe --World
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, nil, 2, 2)
  	--spsummon condition
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_SINGLE)
  	e0:SetCode(EFFECT_SPSUMMON_COST)
  	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e0:SetCost(s.spcost)
  	c:RegisterEffect(e0)
  	--set
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sttg)
  	e1:SetOperation(s.stop)
  	c:RegisterEffect(e1)
  	--to deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BE_MATERIAL)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.tdcon)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  function s.spcost(e, c, tp, st)
  	if bit.band(st, SUMMON_TYPE_LINK) ~= SUMMON_TYPE_LINK then
  		return true
  	end
  	return Duel.IsExistingMatchingCard(Card.IsSetCard, tp, LOCATION_GRAVE, 0, 1, nil, 0xfe)
  end
  function s.stfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsSSetable() and c:IsType(TYPE_SPELL + TYPE_TRAP)
  end
  function s.sttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.stfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.stop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.stfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc and Duel.SSet(tp, tc) ~= 0 then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CANNOT_TRIGGER)
  		e1:SetCondition(s.aclimit)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.actfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER)
  end
  function s.aclimit(e)
  	return not e:GetHandler():IsStatus(STATUS_EFFECT_ENABLED) and not Duel.IsExistingMatchingCard(s.actfilter, e:GetHandlerPlayer(), LOCATION_GRAVE, 0, 1, nil)
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsSummonType(SUMMON_TYPE_LINK) and r == REASON_LINK and c:IsLocation(LOCATION_GRAVE)
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, Card.IsAbleToDeck, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  