name: Kiwi
card_text: During either player's turn: You can discard this card; "Magician Girl" monsters you currently control gain 300 ATK and DEF for each "Magician Girl" monster with different names on the field and in the Graveyards, until the end of this turn. Spellcaster-Type monsters you control cannot be destroyed by card effects, and your opponent cannot target them with card effects.
external_ids: local SETCARD_ID_0 = 0x20a2 --Magician
  
lua: local SETCARD_ID_0 = 0x20a2 --Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_SPELLCASTER))
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--cannot be target
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable()
  	end
  	Duel.SendtoGrave(c, REASON_COST + REASON_DISCARD)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  end
  function s.ctfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil)
  	local g = Duel.GetMatchingGroup(s.ctfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, LOCATION_MZONE + LOCATION_GRAVE, nil)
  	if tg:GetCount() > 0 and g:GetCount() > 0 then
  		local d = g:GetClassCount(Card.GetCode) * 300
  		local sc = tg:GetFirst()
  		while sc do
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			e1:SetValue(d)
  			sc:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_UPDATE_DEFENSE)
  			sc:RegisterEffect(e2)
  			sc = tg:GetNext()
  		end
  	end
  end
  
  
source_text: Kiwi
  During either player's turn: You can discard this card; "Magician Girl" monsters you currently control gain 300 ATK and DEF for each "Magician Girl" monster with different names on the field and in the Graveyards, until the end of this turn. Spellcaster-Type monsters you control cannot be destroyed by card effects, and your opponent cannot target them with card effects.
target_text: -- Kiwi
  local SETCARD_ID_0 = 0x20a2 --Magician
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk up
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_SPELLCASTER))
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--cannot be target
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsDiscardable()
  	end
  	Duel.SendtoGrave(c, REASON_COST + REASON_DISCARD)
  end
  function s.atkfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.atkfilter, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  end
  function s.ctfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil)
  	local g = Duel.GetMatchingGroup(s.ctfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, LOCATION_MZONE + LOCATION_GRAVE, nil)
  	if tg:GetCount() > 0 and g:GetCount() > 0 then
  		local d = g:GetClassCount(Card.GetCode) * 300
  		local sc = tg:GetFirst()
  		while sc do
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			e1:SetValue(d)
  			sc:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_UPDATE_DEFENSE)
  			sc:RegisterEffect(e2)
  			sc = tg:GetNext()
  		end
  	end
  end
  
  