name: 幻銃士
card_text: 1:このカードが召喚・反転召喚に成功した時に発動できる。
  自分フィールドのモンスターの数まで、自分フィールドに「銃士トークン」(悪魔族・闇・星4・攻/守500)を特殊召喚する。
  2:自分スタンバイフェイズに発動できる。
  自分フィールドの「銃士」モンスターの数×300ダメージを相手に与える。
  この効果を発動するターン、自分の「銃士」モンスターは攻撃宣言できない。
external_ids: local CARD_ID_0 = 59822133 --青眼の精霊龍
  local CARD_ID_1 = 12958920 --銃士トークン
  local SETCARD_ID_0 = 0x49 --銃士
  
lua: local CARD_ID_0 = 59822133 --青眼の精霊龍
  local CARD_ID_1 = 12958920 --銃士トークン
  local SETCARD_ID_0 = 0x49 --銃士
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--token
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.damcon)
  	e2:SetCost(s.damcost)
  	e2:SetTarget(s.damtg)
  	e2:SetOperation(s.damop)
  	c:RegisterEffect(e2)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_ATTACK_ANNOUNCE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	if tc:IsSetCard(SETCARD_ID_0) then
  		Duel.RegisterFlagEffect(tc:GetControler(), id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 500, 500, 4, RACE_FIEND, ATTRIBUTE_DARK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local ct = Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0)
  	if ft > ct then
  		ft = ct
  	end
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 500, 500, 4, RACE_FIEND, ATTRIBUTE_DARK) then
  		return
  	end
  	local ctn = true
  	while ft > 0 and ctn do
  		local token = Duel.CreateToken(tp, id + 1)
  		Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP)
  		ft = ft - 1
  		if ft <= 0 or not Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			ctn = false
  		end
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp == Duel.GetTurnPlayer()
  end
  function s.damcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ATTACK_ANNOUNCE)
  	e1:SetProperty(EFFECT_FLAG_OATH)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.damfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local ct = Duel.GetMatchingGroupCount(s.damfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, ct * 300)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local ct = Duel.GetMatchingGroupCount(s.damfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Damage(p, ct * 300, REASON_EFFECT)
  end
  
  
source_text: 幻銃士
  1:このカードが召喚・反転召喚に成功した時に発動できる。
  自分フィールドのモンスターの数まで、自分フィールドに「銃士トークン」(悪魔族・闇・星4・攻/守500)を特殊召喚する。
  2:自分スタンバイフェイズに発動できる。
  自分フィールドの「銃士」モンスターの数×300ダメージを相手に与える。
  この効果を発動するターン、自分の「銃士」モンスターは攻撃宣言できない。
target_text: -- 幻銃士
  local CARD_ID_0 = 59822133 --青眼の精霊龍
  local CARD_ID_1 = 12958920 --銃士トークン
  local SETCARD_ID_0 = 0x49 --銃士
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--token
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_TOKEN)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.damcon)
  	e2:SetCost(s.damcost)
  	e2:SetTarget(s.damtg)
  	e2:SetOperation(s.damop)
  	c:RegisterEffect(e2)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.CreateEffect(c)
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_ATTACK_ANNOUNCE)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	if tc:IsSetCard(SETCARD_ID_0) then
  		Duel.RegisterFlagEffect(tc:GetControler(), id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 500, 500, 4, RACE_FIEND, ATTRIBUTE_DARK)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOKEN, nil, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local ct = Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0)
  	if ft > ct then
  		ft = ct
  	end
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	if not Duel.IsPlayerCanSpecialSummonMonster(tp, id + 1, SETCARD_ID_0, TYPES_TOKEN_MONSTER, 500, 500, 4, RACE_FIEND, ATTRIBUTE_DARK) then
  		return
  	end
  	local ctn = true
  	while ft > 0 and ctn do
  		local token = Duel.CreateToken(tp, id + 1)
  		Duel.SpecialSummonStep(token, 0, tp, tp, false, false, POS_FACEUP)
  		ft = ft - 1
  		if ft <= 0 or not Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			ctn = false
  		end
  	end
  	Duel.SpecialSummonComplete()
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp == Duel.GetTurnPlayer()
  end
  function s.damcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ATTACK_ANNOUNCE)
  	e1:SetProperty(EFFECT_FLAG_OATH)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.damfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local ct = Duel.GetMatchingGroupCount(s.damfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, ct * 300)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local ct = Duel.GetMatchingGroupCount(s.damfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Damage(p, ct * 300, REASON_EFFECT)
  end
  
  