name: Sunavalon
card_text: When this card is activated: If you control a Link-4 or higher Plant monster when this effect resolves, negate the effects of all face-up monsters your opponent currently controls. During damage calculation, if your Plant Link Monster battles: You can activate this effect; it gains ATK equal to the combined ATK of monsters it currently points to, until the end of this turn. (These effects remain even if this card leaves the field.) You can only use this effect of "Sunavalon Bloom" once per turn. You can only activate 1 "Sunavalon Bloom" per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.acttg)
  	e1:SetOperation(s.actop)
  	c:RegisterEffect(e1)
  	--atk
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.atkcon)
  	e2:SetTarget(s.atktg)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.lkfilter(c)
  	return c:IsRace(RACE_PLANT) and c:IsType(TYPE_LINK) and c:IsLinkAbove(4)
  end
  function s.acttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	if Duel.IsExistingMatchingCard(s.lkfilter, tp, LOCATION_MZONE, 0, 1, nil) then
  		local g = Duel.GetMatchingGroup(aux.NegateMonsterFilter, tp, 0, LOCATION_MZONE, nil)
  		Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, g:GetCount(), 0, 0)
  	end
  end
  function s.actop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsExistingMatchingCard(s.lkfilter, tp, LOCATION_MZONE, 0, 1, nil) then
  		local g = Duel.GetMatchingGroup(aux.NegateMonsterFilter, tp, 0, LOCATION_MZONE, nil)
  		local tc = g:GetFirst()
  		while tc do
  			Duel.NegateRelatedChain(tc, RESET_TURN_SET)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(e:GetHandler())
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_DISABLE_EFFECT)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e2)
  			tc = g:GetNext()
  		end
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetBattleMonster(tp)
  	return tc and tc:IsRace(RACE_PLANT) and tc:IsType(TYPE_LINK)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tc = Duel.GetBattleMonster(tp)
  	local lg = tc:GetLinkedGroup():Filter(Card.IsFaceup, nil)
  	if chk == 0 then
  		return #lg > 0 and lg:GetSum(Card.GetAttack) > 0
  	end
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetBattleMonster(tp)
  	if not tc:IsRelateToBattle() then
  		return
  	end
  	local lg = tc:GetLinkedGroup():Filter(Card.IsFaceup, nil)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(lg:GetSum(Card.GetAttack))
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	tc:RegisterEffect(e1)
  end
  
  
source_text: Sunavalon
  When this card is activated: If you control a Link-4 or higher Plant monster when this effect resolves, negate the effects of all face-up monsters your opponent currently controls. During damage calculation, if your Plant Link Monster battles: You can activate this effect; it gains ATK equal to the combined ATK of monsters it currently points to, until the end of this turn. (These effects remain even if this card leaves the field.) You can only use this effect of "Sunavalon Bloom" once per turn. You can only activate 1 "Sunavalon Bloom" per turn.
target_text: -- Sunavalon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.acttg)
  	e1:SetOperation(s.actop)
  	c:RegisterEffect(e1)
  	--atk
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_PRE_DAMAGE_CALCULATE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.atkcon)
  	e2:SetTarget(s.atktg)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.lkfilter(c)
  	return c:IsRace(RACE_PLANT) and c:IsType(TYPE_LINK) and c:IsLinkAbove(4)
  end
  function s.acttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	if Duel.IsExistingMatchingCard(s.lkfilter, tp, LOCATION_MZONE, 0, 1, nil) then
  		local g = Duel.GetMatchingGroup(aux.NegateMonsterFilter, tp, 0, LOCATION_MZONE, nil)
  		Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, g:GetCount(), 0, 0)
  	end
  end
  function s.actop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsExistingMatchingCard(s.lkfilter, tp, LOCATION_MZONE, 0, 1, nil) then
  		local g = Duel.GetMatchingGroup(aux.NegateMonsterFilter, tp, 0, LOCATION_MZONE, nil)
  		local tc = g:GetFirst()
  		while tc do
  			Duel.NegateRelatedChain(tc, RESET_TURN_SET)
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  			local e2 = Effect.CreateEffect(e:GetHandler())
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_DISABLE_EFFECT)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e2)
  			tc = g:GetNext()
  		end
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetBattleMonster(tp)
  	return tc and tc:IsRace(RACE_PLANT) and tc:IsType(TYPE_LINK)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local tc = Duel.GetBattleMonster(tp)
  	local lg = tc:GetLinkedGroup():Filter(Card.IsFaceup, nil)
  	if chk == 0 then
  		return #lg > 0 and lg:GetSum(Card.GetAttack) > 0
  	end
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetBattleMonster(tp)
  	if not tc:IsRelateToBattle() then
  		return
  	end
  	local lg = tc:GetLinkedGroup():Filter(Card.IsFaceup, nil)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(lg:GetSum(Card.GetAttack))
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  	tc:RegisterEffect(e1)
  end
  
  