name: Generaider
card_text: When your opponent activates a card or effect in response to the activation of your "Generaider" card or effect: You can discard 1 card; your opponent's activated effect becomes "each player draws 1 card". You can only use this effect of "Generaider Boss Room" once per turn.
external_ids: local SETCARD_ID_0 = 0x134 --Generaider
  
lua: local SETCARD_ID_0 = 0x134 --Generaider
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_ACTIVATE)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.chcon)
  	e2:SetCost(s.chcost)
  	e2:SetOperation(s.chop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetRange(LOCATION_SZONE)
  	c:RegisterEffect(e3)
  end
  function s.chcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetCurrentChain()
  	if ct < 2 then
  		return
  	end
  	if not Duel.IsPlayerCanDraw(tp, 1) or not Duel.IsPlayerCanDraw(1 - tp, 1) then
  		return false
  	end
  	local te, p = Duel.GetChainInfo(ct - 1, CHAININFO_TRIGGERING_EFFECT, CHAININFO_TRIGGERING_PLAYER)
  	return te and te:GetHandler():IsSetCard(SETCARD_ID_0) and p == tp and rp == 1 - tp
  end
  function s.chcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD, nil)
  end
  function s.chop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Group.CreateGroup()
  	Duel.ChangeTargetCard(ev, g)
  	Duel.ChangeChainOperation(ev, s.repop)
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Draw(tp, 1, REASON_EFFECT)
  	Duel.Draw(1 - tp, 1, REASON_EFFECT)
  end
  
  
source_text: Generaider
  When your opponent activates a card or effect in response to the activation of your "Generaider" card or effect: You can discard 1 card; your opponent's activated effect becomes "each player draws 1 card". You can only use this effect of "Generaider Boss Room" once per turn.
target_text: -- Generaider
  local SETCARD_ID_0 = 0x134 --Generaider
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--change effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_ACTIVATE)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.chcon)
  	e2:SetCost(s.chcost)
  	e2:SetOperation(s.chop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetRange(LOCATION_SZONE)
  	c:RegisterEffect(e3)
  end
  function s.chcon(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetCurrentChain()
  	if ct < 2 then
  		return
  	end
  	if not Duel.IsPlayerCanDraw(tp, 1) or not Duel.IsPlayerCanDraw(1 - tp, 1) then
  		return false
  	end
  	local te, p = Duel.GetChainInfo(ct - 1, CHAININFO_TRIGGERING_EFFECT, CHAININFO_TRIGGERING_PLAYER)
  	return te and te:GetHandler():IsSetCard(SETCARD_ID_0) and p == tp and rp == 1 - tp
  end
  function s.chcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD, nil)
  end
  function s.chop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Group.CreateGroup()
  	Duel.ChangeTargetCard(ev, g)
  	Duel.ChangeChainOperation(ev, s.repop)
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Draw(tp, 1, REASON_EFFECT)
  	Duel.Draw(1 - tp, 1, REASON_EFFECT)
  end
  
  