--[[message
卡数：11
规则：大师3
Inspired by this page (http://roadoftheking.com/dd-advance-combo).
]]
Debug.SetAIName("Naim")
Debug.ReloadFieldBegin(DUEL_ATTACK_FIRST_TURN+DUEL_SIMPLE_AI+DUEL_PSEUDO_SHUFFLE,3)
Debug.SetPlayerInfo(0,100,0,0)
Debug.SetPlayerInfo(1,11000,0,0)

local e0=Effect.GlobalEffect()
e0:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
e0:SetCode(EVENT_ADJUST)
e0:SetCountLimit(1)
e0:SetCondition(function(e,tp,eg,ep,ev,re,r,rp) return Duel.GetLP(0)>0 end)
e0:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
local g=Duel.SelectMatchingCard(tp,Card.IsAbleToHand,tp,LOCATION_DECK,0,4,4,nil)
if g:GetCount()>0 then
  Duel.SendtoHand(g,nil,REASON_RULE)
end end)
Duel.RegisterEffect(e0,0)

--your hand
Debug.AddCard(74069667,0,0,LOCATION_DECK,0,POS_FACEUP_ATTACK)		--ragnarok
--~ Debug.AddCard(45206713,0,0,LOCATION_DECK,0,POS_FACEUP_ATTACK)		--swirl
--~ Debug.AddCard(46372010,0,0,LOCATION_DECK,0,POS_FACEUP_ATTACK)		--gate
Debug.AddCard(11609969,0,0,LOCATION_DECK,0,POS_FACEUP_ATTACK)		--kepler

--your deck
Debug.AddCard(73360025,0,0,LOCATION_DECK,0,POS_FACEDOWN)			--swamp
Debug.AddCard(45206713,0,0,LOCATION_DECK,0,POS_FACEUP_ATTACK)		--swirl
Debug.AddCard(46372010,0,0,LOCATION_DECK,0,POS_FACEUP_ATTACK)		--gate
Debug.AddCard(19580308,0,0,LOCATION_DECK,0,POS_FACEDOWN)			--lamia

--your extra deck
Debug.AddCard(8463720,0,0,LOCATION_EXTRA,0,POS_FACEDOWN)		--beowulf
Debug.AddCard(74583607,0,0,LOCATION_EXTRA,0,POS_FACEDOWN)		--genghis
Debug.AddCard(50954680,0,0,LOCATION_EXTRA,0,POS_FACEDOWN)		--crystal
Debug.AddCard(44852429,0,0,LOCATION_EXTRA,0,POS_FACEDOWN)		--sieg
Debug.AddCard(987311,0,0,LOCATION_EXTRA,0,POS_FACEDOWN)		--alex

--opponent's
Debug.AddCard(89631139,1,1,LOCATION_MZONE,2,POS_FACEUP_ATTACK)		--graydle dragon


--Insert any message here
--insert additional message here
Debug.ReloadFieldEnd()

Debug.ShowHint("从卡组中选择四张卡加入手卡！")
aux.BeginPuzzle()
local e999=Effect.GlobalEffect()
e999:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
e999:SetCode(EVENT_DAMAGE)
e999:SetCondition(function(e,tp,eg,ep,ev,re,r,rp) return Duel.GetLP(1)<=0 end)
e999:SetOperation(function(e,tp,eg,ep,ev,re,r,rp)
Debug.ShowHint("残局群181175613") end)
Duel.RegisterEffect(e999,0)

--~ Debug.ShowHint("Win this turn!!")