name: Sunavalon
card_text: 2+ Plant monsters
  This card cannot be targeted for attacks, but does not prevent your opponent from attacking you directly. Three times per turn, if you take battle or effect damage: You can gain that much LP, and if you do, Special Summon 1 "Sunvine" monster from your Extra Deck. Once per turn, when a monster this card points to is targeted for an attack: You can negate the attack, and if you do, move that monster you control to another of your Main Monster Zones.
external_ids: local SETCARD_ID_0 = 0x1158 --Sunvine
  
lua: local SETCARD_ID_0 = 0x1158 --Sunvine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, s.mfilter, 2, 99)
  	c:EnableReviveLimit()
  	--cannot be battle traget
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCode(EFFECT_IGNORE_BATTLE_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_RECOVER)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(3)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--negate attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BE_BATTLE_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.mvcon)
  	e4:SetTarget(s.mvtg)
  	e4:SetOperation(s.mvop)
  	c:RegisterEffect(e4)
  end
  function s.mfilter(c)
  	return c:IsLinkRace(RACE_PLANT)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp and bit.band(r, REASON_BATTLE + REASON_EFFECT) ~= 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 1, tp, ev)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.Recover(tp, ev, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  		if #g > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.mvcon(e, tp, eg, ep, ev, re, r, rp)
  	local d = Duel.GetAttackTarget()
  	return d and d:IsControler(tp) and e:GetHandler():GetLinkedGroup():IsContains(d)
  end
  function s.mvtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0) > 0
  	end
  end
  function s.mvop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttackTarget()
  	if Duel.NegateAttack() and Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOZONE)
  		local s = Duel.SelectDisableField(tp, 1, LOCATION_MZONE, 0, 0)
  		local nseq = math.log(s, 2)
  		Duel.MoveSequence(tc, nseq)
  	end
  end
  
  
source_text: Sunavalon
  2+ Plant monsters
  This card cannot be targeted for attacks, but does not prevent your opponent from attacking you directly. Three times per turn, if you take battle or effect damage: You can gain that much LP, and if you do, Special Summon 1 "Sunvine" monster from your Extra Deck. Once per turn, when a monster this card points to is targeted for an attack: You can negate the attack, and if you do, move that monster you control to another of your Main Monster Zones.
target_text: -- Sunavalon
  local SETCARD_ID_0 = 0x1158 --Sunvine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, s.mfilter, 2, 99)
  	c:EnableReviveLimit()
  	--cannot be battle traget
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetCode(EFFECT_IGNORE_BATTLE_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--spsummon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_RECOVER)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(3)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--negate attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BE_BATTLE_TARGET)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.mvcon)
  	e4:SetTarget(s.mvtg)
  	e4:SetOperation(s.mvop)
  	c:RegisterEffect(e4)
  end
  function s.mfilter(c)
  	return c:IsLinkRace(RACE_PLANT)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp and bit.band(r, REASON_BATTLE + REASON_EFFECT) ~= 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  	Duel.SetOperationInfo(0, CATEGORY_RECOVER, nil, 1, tp, ev)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.Recover(tp, ev, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  		if #g > 0 then
  			Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  		end
  	end
  end
  function s.mvcon(e, tp, eg, ep, ev, re, r, rp)
  	local d = Duel.GetAttackTarget()
  	return d and d:IsControler(tp) and e:GetHandler():GetLinkedGroup():IsContains(d)
  end
  function s.mvtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0) > 0
  	end
  end
  function s.mvop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetAttackTarget()
  	if Duel.NegateAttack() and Duel.GetLocationCount(tp, LOCATION_MZONE, PLAYER_NONE, 0) > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOZONE)
  		local s = Duel.SelectDisableField(tp, 1, LOCATION_MZONE, 0, 0)
  		local nseq = math.log(s, 2)
  		Duel.MoveSequence(tc, nseq)
  	end
  end
  
  