name: Reanimation
card_text: Activate only when your opponent's monster declares a direct attack. Select 1 Synchro Monster in your Graveyard with a Level less than or equal to the attacking monster's. The Battle Damage you take from that attack is halved. At the end of the Damage Step, Special Summon the selected Synchro Monster from the Graveyard.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp and Duel.GetAttackTarget() == nil and eg:GetFirst():IsLocation(LOCATION_MZONE)
  end
  function s.filter(c, lv)
  	return c:IsLevelBelow(lv) and c:IsType(TYPE_SYNCHRO) and c:IsSpecialSummonableCard()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, eg:GetFirst():GetLevel())
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, eg:GetFirst():GetLevel())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, eg:GetFirst():GetLevel())
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(HALF_DAMAGE)
  	Duel.RegisterEffect(e1, tp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e2:SetCode(EVENT_DAMAGE_STEP_END)
  		e2:SetOperation(s.spop)
  		e2:SetLabelObject(tc)
  		e2:SetReset(RESET_PHASE + PHASE_DAMAGE)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = e:GetLabelObject()
  	if tc:IsLocation(LOCATION_GRAVE) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Reanimation
  Activate only when your opponent's monster declares a direct attack. Select 1 Synchro Monster in your Graveyard with a Level less than or equal to the attacking monster's. The Battle Damage you take from that attack is halved. At the end of the Damage Step, Special Summon the selected Synchro Monster from the Graveyard.
target_text: -- Reanimation
  local s, id, o = GetID()
  function s.initial_effect(c)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp and Duel.GetAttackTarget() == nil and eg:GetFirst():IsLocation(LOCATION_MZONE)
  end
  function s.filter(c, lv)
  	return c:IsLevelBelow(lv) and c:IsType(TYPE_SYNCHRO) and c:IsSpecialSummonableCard()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, eg:GetFirst():GetLevel())
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, eg:GetFirst():GetLevel())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, eg:GetFirst():GetLevel())
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(HALF_DAMAGE)
  	Duel.RegisterEffect(e1, tp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		local e2 = Effect.CreateEffect(e:GetHandler())
  		e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e2:SetCode(EVENT_DAMAGE_STEP_END)
  		e2:SetOperation(s.spop)
  		e2:SetLabelObject(tc)
  		e2:SetReset(RESET_PHASE + PHASE_DAMAGE)
  		Duel.RegisterEffect(e2, tp)
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	local tc = e:GetLabelObject()
  	if tc:IsLocation(LOCATION_GRAVE) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  