name: Performapal
card_text: When an opponent's monster declares a direct attack: You can Special Summon this card from your hand, and if you do, change the attack target to this card, and proceed to damage calculation. If you would take battle damage from that battle, you gain that much LP instead.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.hspcon)
  	e1:SetTarget(s.hsptg)
  	e1:SetOperation(s.hspop)
  	c:RegisterEffect(e1)
  end
  function s.hspcon(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttacker()
  	return at:IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.hsptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.hspop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		local a = Duel.GetAttacker()
  		if a:IsAttackable() and not a:IsImmuneToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_FIELD)
  			e1:SetCode(EFFECT_REVERSE_DAMAGE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_PLAYER_TARGET)
  			e1:SetRange(LOCATION_MZONE)
  			e1:SetTargetRange(1, 0)
  			e1:SetValue(s.rev)
  			e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  			c:RegisterEffect(e1)
  			Duel.CalculateDamage(a, c)
  		end
  	end
  end
  function s.rev(e, re, r, rp, rc)
  	return bit.band(r, REASON_BATTLE) ~= 0 and e:GetHandler() == Duel.GetAttackTarget()
  end
  
  
source_text: Performapal
  When an opponent's monster declares a direct attack: You can Special Summon this card from your hand, and if you do, change the attack target to this card, and proceed to damage calculation. If you would take battle damage from that battle, you gain that much LP instead.
target_text: -- Performapal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.hspcon)
  	e1:SetTarget(s.hsptg)
  	e1:SetOperation(s.hspop)
  	c:RegisterEffect(e1)
  end
  function s.hspcon(e, tp, eg, ep, ev, re, r, rp)
  	local at = Duel.GetAttacker()
  	return at:IsControler(1 - tp) and Duel.GetAttackTarget() == nil
  end
  function s.hsptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, c, 1, 0, 0)
  end
  function s.hspop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		local a = Duel.GetAttacker()
  		if a:IsAttackable() and not a:IsImmuneToEffect(e) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_FIELD)
  			e1:SetCode(EFFECT_REVERSE_DAMAGE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_PLAYER_TARGET)
  			e1:SetRange(LOCATION_MZONE)
  			e1:SetTargetRange(1, 0)
  			e1:SetValue(s.rev)
  			e1:SetReset(RESET_PHASE + PHASE_DAMAGE)
  			c:RegisterEffect(e1)
  			Duel.CalculateDamage(a, c)
  		end
  	end
  end
  function s.rev(e, re, r, rp, rc)
  	return bit.band(r, REASON_BATTLE) ~= 0 and e:GetHandler() == Duel.GetAttackTarget()
  end
  
  