name: Battle
card_text: At the end of the Battle Phase: You can add 1 card from your GY to your hand, except "Battle Survivor", that was sent there during this Battle Phase while you controlled this face-up card. You can only use this effect of "Battle Survivor" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	local ng = Group.CreateGroup()
  	ng:KeepAlive()
  	e1:SetLabelObject(ng)
  	e2:SetLabelObject(ng)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() >= PHASE_BATTLE_START and Duel.GetCurrentPhase() <= PHASE_BATTLE
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = e:GetLabelObject()
  	if c:GetFlagEffect(id) == 0 then
  		sg:Clear()
  		c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  	end
  	local g = eg:Filter(Card.IsControler, nil, tp)
  	local tc = g:GetFirst()
  	while tc do
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  		sg:AddCard(tc)
  		tc = g:GetNext()
  	end
  end
  function s.thfilter(c)
  	return c:GetFlagEffect(id) ~= 0 and c:IsAbleToHand() and not c:IsCode(id) and c:IsLocation(LOCATION_GRAVE)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ng = e:GetLabelObject()
  	if chk == 0 then
  		return ng and ng:GetCount() > 0 and ng:IsExists(s.thfilter, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local ng = e:GetLabelObject()
  	if not ng or ng:GetCount() == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = ng:FilterSelect(tp, aux.NecroValleyFilter(s.thfilter), 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Battle
  At the end of the Battle Phase: You can add 1 card from your GY to your hand, except "Battle Survivor", that was sent there during this Battle Phase while you controlled this face-up card. You can only use this effect of "Battle Survivor" once per turn.
target_text: -- Battle
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_PHASE + PHASE_BATTLE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.regcon)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	local ng = Group.CreateGroup()
  	ng:KeepAlive()
  	e1:SetLabelObject(ng)
  	e2:SetLabelObject(ng)
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() >= PHASE_BATTLE_START and Duel.GetCurrentPhase() <= PHASE_BATTLE
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = e:GetLabelObject()
  	if c:GetFlagEffect(id) == 0 then
  		sg:Clear()
  		c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  	end
  	local g = eg:Filter(Card.IsControler, nil, tp)
  	local tc = g:GetFirst()
  	while tc do
  		tc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_BATTLE, 0, 1)
  		sg:AddCard(tc)
  		tc = g:GetNext()
  	end
  end
  function s.thfilter(c)
  	return c:GetFlagEffect(id) ~= 0 and c:IsAbleToHand() and not c:IsCode(id) and c:IsLocation(LOCATION_GRAVE)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ng = e:GetLabelObject()
  	if chk == 0 then
  		return ng and ng:GetCount() > 0 and ng:IsExists(s.thfilter, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local ng = e:GetLabelObject()
  	if not ng or ng:GetCount() == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = ng:FilterSelect(tp, aux.NecroValleyFilter(s.thfilter), 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  