name: Gouki
card_text: 2+ "Gouki" monsters
  Once per turn (Quick Effect): You can return to the hand any number of "Gouki" monsters you control that this card points to, then target the same number of face-up cards your opponent controls; they have their effects negated until the end of this turn. This card can attack all monsters your opponent controls, once each. If your opponent controls a face-up monster(s), this card can only target their monster with the highest ATK for attacks (your choice, if tied).
external_ids: local SETCARD_ID_0 = 0xfc --Gouki
  
lua: local SETCARD_ID_0 = 0xfc --Gouki
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 2)
  	c:EnableReviveLimit()
  	--disable
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.discost)
  	e1:SetTarget(s.distg)
  	e1:SetOperation(s.disop)
  	c:RegisterEffect(e1)
  	--attack all
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_ATTACK_ALL)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--attack limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e3:SetCondition(s.atcon)
  	e3:SetValue(s.atlimit)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e4:SetCondition(s.atcon)
  	c:RegisterEffect(e4)
  end
  function s.discost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.costfilter(c, g)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and g:IsContains(c) and c:IsAbleToHandAsCost()
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local lg = e:GetHandler():GetLinkedGroup()
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and aux.NegateAnyFilter(chkc)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 1 then
  			e:SetLabel(0)
  			return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_MZONE, 0, 1, nil, lg) and Duel.IsExistingTarget(aux.NegateAnyFilter, tp, 0, LOCATION_ONFIELD, 1, nil)
  		else
  			return false
  		end
  	end
  	e:SetLabel(0)
  	local rt = Duel.GetTargetCount(aux.NegateAnyFilter, tp, 0, LOCATION_ONFIELD, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local cg = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_MZONE, 0, 1, rt, nil, lg)
  	local ct = cg:GetCount()
  	Duel.SendtoHand(cg, nil, REASON_COST)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
  	local g = Duel.SelectTarget(tp, aux.NegateAnyFilter, tp, 0, LOCATION_ONFIELD, ct, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, g:GetCount(), 0, 0)
  end
  function s.disfilter(c, e)
  	return aux.NegateAnyFilter(c) and c:IsRelateToEffect(e)
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(s.disfilter, nil, e)
  	local tc = g:GetFirst()
  	while tc do
  		Duel.NegateRelatedChain(tc, RESET_TURN_SET)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetValue(RESET_TURN_SET)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e2)
  		if tc:IsType(TYPE_TRAPMONSTER) then
  			local e3 = Effect.CreateEffect(c)
  			e3:SetType(EFFECT_TYPE_SINGLE)
  			e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e3:SetCode(EFFECT_DISABLE_TRAPMONSTER)
  			e3:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e3)
  		end
  		tc = g:GetNext()
  	end
  end
  function s.atcon(e)
  	return Duel.IsExistingMatchingCard(Card.IsFaceup, e:GetHandlerPlayer(), 0, LOCATION_MZONE, 1, nil)
  end
  function s.atlimit(e, c)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, e:GetHandlerPlayer(), 0, LOCATION_MZONE, nil)
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	return not tg:IsContains(c) or c:IsFacedown()
  end
  
  
source_text: Gouki
  2+ "Gouki" monsters
  Once per turn (Quick Effect): You can return to the hand any number of "Gouki" monsters you control that this card points to, then target the same number of face-up cards your opponent controls; they have their effects negated until the end of this turn. This card can attack all monsters your opponent controls, once each. If your opponent controls a face-up monster(s), this card can only target their monster with the highest ATK for attacks (your choice, if tied).
target_text: -- Gouki
  local SETCARD_ID_0 = 0xfc --Gouki
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 2)
  	c:EnableReviveLimit()
  	--disable
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetCountLimit(1)
  	e1:SetCost(s.discost)
  	e1:SetTarget(s.distg)
  	e1:SetOperation(s.disop)
  	c:RegisterEffect(e1)
  	--attack all
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_ATTACK_ALL)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--attack limit
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e3:SetCondition(s.atcon)
  	e3:SetValue(s.atlimit)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	e4:SetCondition(s.atcon)
  	c:RegisterEffect(e4)
  end
  function s.discost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	return true
  end
  function s.costfilter(c, g)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and g:IsContains(c) and c:IsAbleToHandAsCost()
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local lg = e:GetHandler():GetLinkedGroup()
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp) and aux.NegateAnyFilter(chkc)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 1 then
  			e:SetLabel(0)
  			return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_MZONE, 0, 1, nil, lg) and Duel.IsExistingTarget(aux.NegateAnyFilter, tp, 0, LOCATION_ONFIELD, 1, nil)
  		else
  			return false
  		end
  	end
  	e:SetLabel(0)
  	local rt = Duel.GetTargetCount(aux.NegateAnyFilter, tp, 0, LOCATION_ONFIELD, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local cg = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_MZONE, 0, 1, rt, nil, lg)
  	local ct = cg:GetCount()
  	Duel.SendtoHand(cg, nil, REASON_COST)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
  	local g = Duel.SelectTarget(tp, aux.NegateAnyFilter, tp, 0, LOCATION_ONFIELD, ct, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE, g, g:GetCount(), 0, 0)
  end
  function s.disfilter(c, e)
  	return aux.NegateAnyFilter(c) and c:IsRelateToEffect(e)
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(s.disfilter, nil, e)
  	local tc = g:GetFirst()
  	while tc do
  		Duel.NegateRelatedChain(tc, RESET_TURN_SET)
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetValue(RESET_TURN_SET)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e2)
  		if tc:IsType(TYPE_TRAPMONSTER) then
  			local e3 = Effect.CreateEffect(c)
  			e3:SetType(EFFECT_TYPE_SINGLE)
  			e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e3:SetCode(EFFECT_DISABLE_TRAPMONSTER)
  			e3:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e3)
  		end
  		tc = g:GetNext()
  	end
  end
  function s.atcon(e)
  	return Duel.IsExistingMatchingCard(Card.IsFaceup, e:GetHandlerPlayer(), 0, LOCATION_MZONE, 1, nil)
  end
  function s.atlimit(e, c)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, e:GetHandlerPlayer(), 0, LOCATION_MZONE, nil)
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	return not tg:IsContains(c) or c:IsFacedown()
  end
  
  