name: Beginning
card_text: Reveal 3 Warrior-Type monsters from your Deck, including at least 1 "Black Luster Soldier" monster or "Gaia The Fierce Knight" monster, and have your opponent randomly pick 1. If they picked a "Black Luster Soldier" monster or "Gaia The Fierce Knight" monster, add it to your hand and send the rest to the Graveyard. Otherwise, send them all to the Graveyard. You can only activate 1 "Beginning of Heaven and Earth" per turn.
external_ids: local SETCARD_ID_0 = 0x10cf --Black
  
lua: local SETCARD_ID_0 = 0x10cf --Black
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c)
  	return c:IsRace(RACE_WARRIOR) and c:IsAbleToHand()
  end
  function s.filter2(c)
  	return c:IsSetCard(SETCARD_ID_0, 0xbd)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return g:GetCount() > 2 and g:IsExists(s.filter2, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_DECK, 0, nil)
  	if g:IsExists(s.filter2, 1, nil) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg1 = g:FilterSelect(tp, s.filter2, 1, 1, nil)
  		g:RemoveCard(sg1:GetFirst())
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg2 = g:Select(tp, 2, 2, nil)
  		sg1:Merge(sg2)
  		Duel.ConfirmCards(1 - tp, sg1)
  		Duel.ShuffleDeck(tp)
  		local tg = sg1:Select(1 - tp, 1, 1, nil)
  		local tc = tg:GetFirst()
  		Duel.Hint(HINT_CARD, 0, tc:GetCode())
  		if s.filter2(tc) and tc:IsAbleToHand() then
  			tc:SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			sg1:RemoveCard(tc)
  		end
  		Duel.SendtoGrave(sg1, REASON_EFFECT)
  	end
  end
  
  
source_text: Beginning
  Reveal 3 Warrior-Type monsters from your Deck, including at least 1 "Black Luster Soldier" monster or "Gaia The Fierce Knight" monster, and have your opponent randomly pick 1. If they picked a "Black Luster Soldier" monster or "Gaia The Fierce Knight" monster, add it to your hand and send the rest to the Graveyard. Otherwise, send them all to the Graveyard. You can only activate 1 "Beginning of Heaven and Earth" per turn.
target_text: -- Beginning
  local SETCARD_ID_0 = 0x10cf --Black
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter1(c)
  	return c:IsRace(RACE_WARRIOR) and c:IsAbleToHand()
  end
  function s.filter2(c)
  	return c:IsSetCard(SETCARD_ID_0, 0xbd)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return g:GetCount() > 2 and g:IsExists(s.filter2, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.filter1, tp, LOCATION_DECK, 0, nil)
  	if g:IsExists(s.filter2, 1, nil) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg1 = g:FilterSelect(tp, s.filter2, 1, 1, nil)
  		g:RemoveCard(sg1:GetFirst())
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local sg2 = g:Select(tp, 2, 2, nil)
  		sg1:Merge(sg2)
  		Duel.ConfirmCards(1 - tp, sg1)
  		Duel.ShuffleDeck(tp)
  		local tg = sg1:Select(1 - tp, 1, 1, nil)
  		local tc = tg:GetFirst()
  		Duel.Hint(HINT_CARD, 0, tc:GetCode())
  		if s.filter2(tc) and tc:IsAbleToHand() then
  			tc:SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  			Duel.SendtoHand(tc, nil, REASON_EFFECT)
  			sg1:RemoveCard(tc)
  		end
  		Duel.SendtoGrave(sg1, REASON_EFFECT)
  	end
  end
  
  