name: Absorb
card_text: Add 1 "Gem-Knight" card from your Deck to your hand, then you can apply this effect.
  ● Fusion Summon 1 "Gem-Knight" Fusion Monster from your Extra Deck, by banishing its materials from your hand or field.
  You can only activate 1 "Absorb Fusion" per turn. You cannot Special Summon the turn you activate this card, except "Gem-Knight" monsters.
external_ids: local SETCARD_ID_0 = 0x1047 --Gem-Knight
  
lua: local SETCARD_ID_0 = 0x1047 --Gem-Knight
  local s, id, o = GetID()
  function s.initial_effect(c)
  	-- fusion
  	local e0 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		matfilter = aux.NecroValleyFilter(),
  		mat_operation_code_map = {
  			{ [LOCATION_REMOVED] = FusionSpell.FUSION_OPERATION_GRAVE },
  			{ [0xff] = FusionSpell.FUSION_OPERATION_BANISH },
  		},
  	})
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	e1:SetLabelObject(e0)
  	c:RegisterEffect(e1)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_SPSUMMON, s.counterfilter)
  end
  
  function s.counterfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetCustomActivityCount(id, tp, ACTIVITY_SPSUMMON) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	Duel.RegisterEffect(e1, tp)
  end
  
  function s.splimit(e, c, sump, sumtype, sumpos, targetp, se)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  
  function s.fusfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		local fusion_effect = e:GetLabelObject()
  		if fusion_effect:GetTarget()(e, tp, eg, ep, ev, re, r, rp, 0) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			fusion_effect:GetOperation()(e, tp, eg, ep, ev, re, r, rp)
  		end
  	end
  end
  
  
source_text: Absorb
  Add 1 "Gem-Knight" card from your Deck to your hand, then you can apply this effect.
  ● Fusion Summon 1 "Gem-Knight" Fusion Monster from your Extra Deck, by banishing its materials from your hand or field.
  You can only activate 1 "Absorb Fusion" per turn. You cannot Special Summon the turn you activate this card, except "Gem-Knight" monsters.
target_text: -- Absorb
  local SETCARD_ID_0 = 0x1047 --Gem-Knight
  local s, id, o = GetID()
  function s.initial_effect(c)
  	-- fusion
  	local e0 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		matfilter = aux.NecroValleyFilter(),
  		mat_operation_code_map = {
  			{ [LOCATION_REMOVED] = FusionSpell.FUSION_OPERATION_GRAVE },
  			{ [0xff] = FusionSpell.FUSION_OPERATION_BANISH },
  		},
  	})
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	e1:SetLabelObject(e0)
  	c:RegisterEffect(e1)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_SPSUMMON, s.counterfilter)
  end
  
  function s.counterfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetCustomActivityCount(id, tp, ACTIVITY_SPSUMMON) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	Duel.RegisterEffect(e1, tp)
  end
  
  function s.splimit(e, c, sump, sumtype, sumpos, targetp, se)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  
  function s.fusfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		local fusion_effect = e:GetLabelObject()
  		if fusion_effect:GetTarget()(e, tp, eg, ep, ev, re, r, rp, 0) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			fusion_effect:GetOperation()(e, tp, eg, ep, ev, re, r, rp)
  		end
  	end
  end
  
  