name: 携帯型バッテリー
card_text: 自分の墓地の「電池メン」と名のついたモンスター2体を選択し、表側攻撃表示で特殊召喚する。
  このカードがフィールド上から離れた時、そのモンスターを全て破壊する。
  そのモンスターが全てフィールド上から離れた時、このカードを破壊する。
external_ids: local CARD_ID_0 = 59822133 --青眼の精霊龍
  local SETCARD_ID_0 = 0x28 --電池メン
  
lua: local CARD_ID_0 = 59822133 --青眼の精霊龍
  local SETCARD_ID_0 = 0x28 --電池メン
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetOperation(s.desop)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  	--Destroy2
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetCondition(s.descon2)
  	e3:SetOperation(s.desop2)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 2, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 2, 2, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, 0, 0)
  	if e:GetLabelObject() then
  		e:GetLabelObject():DeleteGroup()
  	end
  	e:SetLabelObject(nil)
  end
  function s.sfilter(c, e, tp)
  	return c:IsRelateToEffect(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(s.sfilter, nil, e, tp)
  	local sct = sg:GetCount()
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if sct == 0 or ft <= 0 or (sct > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) then
  		return
  	end
  	if sct > ft then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		sg = sg:Select(tp, ft, ft, nil)
  		sct = ft
  	end
  	local tc = sg:GetFirst()
  	while tc and Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK) do
  		c:SetCardTarget(tc)
  		tc:CreateRelation(c, RESET_EVENT + 0x1020000)
  		tc = sg:GetNext()
  	end
  	e:SetLabelObject(sg)
  	sg:KeepAlive()
  	Duel.SpecialSummonComplete()
  end
  function s.desfilter1(c, rc)
  	return c:IsRelateToCard(rc) and c:IsLocation(LOCATION_MZONE) and not c:IsStatus(STATUS_DESTROY_CONFIRMED + STATUS_BATTLE_DESTROYED)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = e:GetLabelObject():GetLabelObject()
  	if not sg then
  		return
  	end
  	Duel.Destroy(sg:Filter(s.desfilter1, nil, c), REASON_EFFECT)
  	sg:DeleteGroup()
  	e:SetLabelObject(nil)
  end
  function s.descon2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = e:GetLabelObject():GetLabelObject()
  	if not sg or c:IsStatus(STATUS_DESTROY_CONFIRMED) then
  		return false
  	end
  	local rg = eg:Filter(Card.IsRelateToCard, nil, c)
  	local tc = rg:GetFirst()
  	while tc do
  		sg:RemoveCard(tc)
  		tc = rg:GetNext()
  	end
  	return sg:GetCount() == 0
  end
  function s.desop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  
  
source_text: 携帯型バッテリー
  自分の墓地の「電池メン」と名のついたモンスター2体を選択し、表側攻撃表示で特殊召喚する。
  このカードがフィールド上から離れた時、そのモンスターを全て破壊する。
  そのモンスターが全てフィールド上から離れた時、このカードを破壊する。
target_text: -- 携帯型バッテリー
  local CARD_ID_0 = 59822133 --青眼の精霊龍
  local SETCARD_ID_0 = 0x28 --電池メン
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--Destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e2:SetCode(EVENT_LEAVE_FIELD)
  	e2:SetOperation(s.desop)
  	e2:SetLabelObject(e1)
  	c:RegisterEffect(e2)
  	--Destroy2
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetCondition(s.descon2)
  	e3:SetOperation(s.desop2)
  	e3:SetLabelObject(e1)
  	c:RegisterEffect(e3)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		return not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) and Duel.GetLocationCount(tp, LOCATION_MZONE) > 1 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 2, nil, e, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 2, 2, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 2, 0, 0)
  	if e:GetLabelObject() then
  		e:GetLabelObject():DeleteGroup()
  	end
  	e:SetLabelObject(nil)
  end
  function s.sfilter(c, e, tp)
  	return c:IsRelateToEffect(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local sg = g:Filter(s.sfilter, nil, e, tp)
  	local sct = sg:GetCount()
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if sct == 0 or ft <= 0 or (sct > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) then
  		return
  	end
  	if sct > ft then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		sg = sg:Select(tp, ft, ft, nil)
  		sct = ft
  	end
  	local tc = sg:GetFirst()
  	while tc and Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK) do
  		c:SetCardTarget(tc)
  		tc:CreateRelation(c, RESET_EVENT + 0x1020000)
  		tc = sg:GetNext()
  	end
  	e:SetLabelObject(sg)
  	sg:KeepAlive()
  	Duel.SpecialSummonComplete()
  end
  function s.desfilter1(c, rc)
  	return c:IsRelateToCard(rc) and c:IsLocation(LOCATION_MZONE) and not c:IsStatus(STATUS_DESTROY_CONFIRMED + STATUS_BATTLE_DESTROYED)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = e:GetLabelObject():GetLabelObject()
  	if not sg then
  		return
  	end
  	Duel.Destroy(sg:Filter(s.desfilter1, nil, c), REASON_EFFECT)
  	sg:DeleteGroup()
  	e:SetLabelObject(nil)
  end
  function s.descon2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local sg = e:GetLabelObject():GetLabelObject()
  	if not sg or c:IsStatus(STATUS_DESTROY_CONFIRMED) then
  		return false
  	end
  	local rg = eg:Filter(Card.IsRelateToCard, nil, c)
  	local tc = rg:GetFirst()
  	while tc do
  		sg:RemoveCard(tc)
  		tc = rg:GetNext()
  	end
  	return sg:GetCount() == 0
  end
  function s.desop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT)
  end
  
  