name: Gathering
card_text: You can banish 1 monster you control, and 1 Synchro Monster in your GY that is a "Power Tool" monster or Level 7 or 8 Dragon monster, then target 1 card your opponent controls; destroy it. Level 7 or higher Synchro Monsters you control gain 400 ATK for each of your banished Level 7 or higher Synchro Monsters. Once per turn, when an opponent's monster declares an attack while you have a banished Synchro Monster: You can negate the attack.
external_ids: local SETCARD_ID_0 = 0xc2 --Power
  
lua: local SETCARD_ID_0 = 0xc2 --Power
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--atk up
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetTarget(aux.TargetBoolFunction(s.filter))
  	e3:SetValue(s.val)
  	c:RegisterEffect(e3)
  	--negate
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.negcon)
  	e4:SetOperation(s.negop)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsLevel(7, 8) and c:IsRace(RACE_DRAGON)) and c:IsType(TYPE_SYNCHRO) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemoveAsCost, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g1 = Duel.SelectMatchingCard(tp, Card.IsAbleToRemoveAsCost, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	local g2 = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	g1:Merge(g2)
  	Duel.Remove(g1, POS_FACEUP, REASON_COST)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(nil, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, nil, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and c:IsType(TYPE_MONSTER) and c:IsLevelAbove(7)
  end
  function s.val(e, c)
  	return Duel.GetMatchingGroupCount(s.filter, e:GetHandlerPlayer(), LOCATION_REMOVED, 0, nil) * 400
  end
  function s.negfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and c:IsType(TYPE_MONSTER)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.IsExistingMatchingCard(s.negfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  
source_text: Gathering
  You can banish 1 monster you control, and 1 Synchro Monster in your GY that is a "Power Tool" monster or Level 7 or 8 Dragon monster, then target 1 card your opponent controls; destroy it. Level 7 or higher Synchro Monsters you control gain 400 ATK for each of your banished Level 7 or higher Synchro Monsters. Once per turn, when an opponent's monster declares an attack while you have a banished Synchro Monster: You can negate the attack.
target_text: -- Gathering
  local SETCARD_ID_0 = 0xc2 --Power
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--atk up
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_UPDATE_ATTACK)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetTarget(aux.TargetBoolFunction(s.filter))
  	e3:SetValue(s.val)
  	c:RegisterEffect(e3)
  	--negate
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.negcon)
  	e4:SetOperation(s.negop)
  	c:RegisterEffect(e4)
  end
  function s.cfilter(c)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsLevel(7, 8) and c:IsRace(RACE_DRAGON)) and c:IsType(TYPE_SYNCHRO) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemoveAsCost, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g1 = Duel.SelectMatchingCard(tp, Card.IsAbleToRemoveAsCost, tp, LOCATION_MZONE, 0, 1, 1, nil)
  	local g2 = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	g1:Merge(g2)
  	Duel.Remove(g1, POS_FACEUP, REASON_COST)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(nil, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, nil, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and c:IsType(TYPE_MONSTER) and c:IsLevelAbove(7)
  end
  function s.val(e, c)
  	return Duel.GetMatchingGroupCount(s.filter, e:GetHandlerPlayer(), LOCATION_REMOVED, 0, nil) * 400
  end
  function s.negfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SYNCHRO) and c:IsType(TYPE_MONSTER)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp) and Duel.IsExistingMatchingCard(s.negfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  