name: Altergeist
card_text: If an "Altergeist" monster you control would be used as Link Material for an "Altergeist" monster, this card in your hand can also be used as material. You can only use this effect of "Altergeist Pookuery" once per turn. If an "Altergeist" Link Monster is Link Summoned to your field, while this card is in your GY (except during the Damage Step): You can add this card to your hand. You can only use this effect of "Altergeist Pookuery" once per Duel.
external_ids: local SETCARD_ID_0 = 0x103 --Altergeist
  
lua: local SETCARD_ID_0 = 0x103 --Altergeist
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--hand link
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCode(EFFECT_EXTRA_LINK_MATERIAL)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetValue(s.matval)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1 + EFFECT_COUNT_CODE_DUEL)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.mfilter(c, tp)
  	return c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp)
  end
  function s.exmfilter(c)
  	return c:IsLocation(LOCATION_HAND) and c:IsCode(id)
  end
  function s.matval(e, lc, mg, c, tp)
  	if not lc:IsSetCard(SETCARD_ID_0) then
  		return false, nil
  	end
  	return true, not mg or mg:IsExists(s.mfilter, 1, nil, tp) and not mg:IsExists(s.exmfilter, 1, nil)
  end
  function s.cfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_LINK) and c:IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoHand(c, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Altergeist
  If an "Altergeist" monster you control would be used as Link Material for an "Altergeist" monster, this card in your hand can also be used as material. You can only use this effect of "Altergeist Pookuery" once per turn. If an "Altergeist" Link Monster is Link Summoned to your field, while this card is in your GY (except during the Damage Step): You can add this card to your hand. You can only use this effect of "Altergeist Pookuery" once per Duel.
target_text: -- Altergeist
  local SETCARD_ID_0 = 0x103 --Altergeist
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--hand link
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCode(EFFECT_EXTRA_LINK_MATERIAL)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetValue(s.matval)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1 + EFFECT_COUNT_CODE_DUEL)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.mfilter(c, tp)
  	return c:IsLocation(LOCATION_MZONE) and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp)
  end
  function s.exmfilter(c)
  	return c:IsLocation(LOCATION_HAND) and c:IsCode(id)
  end
  function s.matval(e, lc, mg, c, tp)
  	if not lc:IsSetCard(SETCARD_ID_0) then
  		return false, nil
  	end
  	return true, not mg or mg:IsExists(s.mfilter, 1, nil, tp) and not mg:IsExists(s.exmfilter, 1, nil)
  end
  function s.cfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_LINK) and c:IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToHand()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, e:GetHandler(), 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SendtoHand(c, nil, REASON_EFFECT)
  	end
  end
  
  