name: Offering
card_text: When your opponent's monster declares a direct attack while you have 3000 or less LP: Negate the attack, and if you do, Special Summon 2 "Ceremonial Tokens" (Rock/EARTH/Level 1/ATK 0/DEF 0), and if you do that, add 1 "Earthbound Immortal" card from your Deck to your hand. "Ceremonial Tokens" cannot be Tributed, except for a Tribute Summon of an "Earthbound Immortal" monster, and cannot be used as Synchro Material.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 82340057 --Ceremonial Token
  local SETCARD_ID_0 = 0x1021 --Earthbound
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 82340057 --Ceremonial Token
  local SETCARD_ID_0 = 0x1021 --Earthbound
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) <= 3000 and Duel.GetTurnPlayer() ~= tp and Duel.GetAttackTarget() == nil
  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 not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 0, 0, 1, RACE_ROCK, ATTRIBUTE_EARTH)
  			and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 2, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.NegateAttack() then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 or not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 0, 0, 1, RACE_ROCK, ATTRIBUTE_EARTH) then
  		return
  	end
  	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
  		return
  	end
  	Duel.SendtoHand(g, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, g)
  	Duel.ShuffleHand(tp)
  	for i = 1, 2 do
  		local token = Duel.CreateToken(tp, id + 1)
  		Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UNRELEASABLE_NONSUM)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(1)
  		token:RegisterEffect(e1, true)
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_UNRELEASABLE_SUM)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e2:SetValue(s.sumlimit)
  		token:RegisterEffect(e2, true)
  		local e3 = Effect.CreateEffect(e:GetHandler())
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_CANNOT_BE_SYNCHRO_MATERIAL)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e3:SetValue(1)
  		token:RegisterEffect(e3, true)
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.sumlimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  
  
source_text: Offering
  When your opponent's monster declares a direct attack while you have 3000 or less LP: Negate the attack, and if you do, Special Summon 2 "Ceremonial Tokens" (Rock/EARTH/Level 1/ATK 0/DEF 0), and if you do that, add 1 "Earthbound Immortal" card from your Deck to your hand. "Ceremonial Tokens" cannot be Tributed, except for a Tribute Summon of an "Earthbound Immortal" monster, and cannot be used as Synchro Material.
target_text: -- Offering
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 82340057 --Ceremonial Token
  local SETCARD_ID_0 = 0x1021 --Earthbound
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetLP(tp) <= 3000 and Duel.GetTurnPlayer() ~= tp and Duel.GetAttackTarget() == nil
  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 not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1
  			and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 0, 0, 1, RACE_ROCK, ATTRIBUTE_EARTH)
  			and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 2, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 2, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if not Duel.NegateAttack() then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		return
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 2 or not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, 0, TYPES_TOKEN_MONSTER, 0, 0, 1, RACE_ROCK, ATTRIBUTE_EARTH) then
  		return
  	end
  	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
  		return
  	end
  	Duel.SendtoHand(g, nil, REASON_EFFECT)
  	Duel.ConfirmCards(1 - tp, g)
  	Duel.ShuffleHand(tp)
  	for i = 1, 2 do
  		local token = Duel.CreateToken(tp, id + 1)
  		Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UNRELEASABLE_NONSUM)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e1:SetValue(1)
  		token:RegisterEffect(e1, true)
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_UNRELEASABLE_SUM)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e2:SetValue(s.sumlimit)
  		token:RegisterEffect(e2, true)
  		local e3 = Effect.CreateEffect(e:GetHandler())
  		e3:SetType(EFFECT_TYPE_SINGLE)
  		e3:SetCode(EFFECT_CANNOT_BE_SYNCHRO_MATERIAL)
  		e3:SetReset(RESET_EVENT + RESETS_STANDARD)
  		e3:SetValue(1)
  		token:RegisterEffect(e3, true)
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.sumlimit(e, c)
  	return not c:IsSetCard(SETCARD_ID_0)
  end
  
  