name: Lucky
card_text: During the End Phase, if you Summoned 2 or more "Cloudian" monsters with the same name this turn, draw 2 cards.
external_ids: local SETCARD_ID_0 = 0x18 --Cloudian
  
lua: local SETCARD_ID_0 = 0x18 --Cloudian
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	if not s.global_check then
  		s.global_check = true
  		s[0] = false
  		s[1] = Group.CreateGroup()
  		s[1]:KeepAlive()
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_SUMMON_SUCCESS)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  		local ge2 = Effect.CreateEffect(c)
  		ge2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge2:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  		ge2:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge2, 0)
  		local ge3 = Effect.CreateEffect(c)
  		ge3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge3:SetCode(EVENT_SPSUMMON_SUCCESS)
  		ge3:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge3, 0)
  		local ge4 = Effect.CreateEffect(c)
  		ge4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge4:SetCode(EVENT_PHASE_START + PHASE_DRAW)
  		ge4:SetOperation(s.clear)
  		Duel.RegisterEffect(ge4, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	while tc do
  		if not s[0] and tc:IsFaceup() and tc:IsSetCard(SETCARD_ID_0) then
  			if s[1]:IsContains(tc) then
  				s[0] = true
  			else
  				s[1]:AddCard(tc)
  			end
  		end
  		tc = eg:GetNext()
  	end
  end
  function s.clear(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = false
  	s[1]:Clear()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.drcon)
  	e1:SetOperation(s.drop)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.filter(c, g)
  	return g:IsExists(Card.IsCode, 1, c, c:GetCode())
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return s[0] or s[1]:IsExists(s.filter, 1, nil, s[1])
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Draw(tp, 2, REASON_EFFECT)
  end
  
  
source_text: Lucky
  During the End Phase, if you Summoned 2 or more "Cloudian" monsters with the same name this turn, draw 2 cards.
target_text: -- Lucky
  local SETCARD_ID_0 = 0x18 --Cloudian
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DRAW)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	if not s.global_check then
  		s.global_check = true
  		s[0] = false
  		s[1] = Group.CreateGroup()
  		s[1]:KeepAlive()
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_SUMMON_SUCCESS)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  		local ge2 = Effect.CreateEffect(c)
  		ge2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge2:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  		ge2:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge2, 0)
  		local ge3 = Effect.CreateEffect(c)
  		ge3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge3:SetCode(EVENT_SPSUMMON_SUCCESS)
  		ge3:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge3, 0)
  		local ge4 = Effect.CreateEffect(c)
  		ge4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge4:SetCode(EVENT_PHASE_START + PHASE_DRAW)
  		ge4:SetOperation(s.clear)
  		Duel.RegisterEffect(ge4, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	while tc do
  		if not s[0] and tc:IsFaceup() and tc:IsSetCard(SETCARD_ID_0) then
  			if s[1]:IsContains(tc) then
  				s[0] = true
  			else
  				s[1]:AddCard(tc)
  			end
  		end
  		tc = eg:GetNext()
  	end
  end
  function s.clear(e, tp, eg, ep, ev, re, r, rp)
  	s[0] = false
  	s[1]:Clear()
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.drcon)
  	e1:SetOperation(s.drop)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.filter(c, g)
  	return g:IsExists(Card.IsCode, 1, c, c:GetCode())
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return s[0] or s[1]:IsExists(s.filter, 1, nil, s[1])
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Draw(tp, 2, REASON_EFFECT)
  end
  
  