name: Magikey
card_text: 1 "Magikey" Tuner + 1+ non-Tuner Normal Monsters
  This card can make up to 2 attacks on monsters during each Battle Phase. You can only use each of the following effects of "Magikey Fiend - Transfurlmine" once per turn. If you control this card that was Synchro Summoned using at least 2 Attributes of monsters: You can Set 1 "Magikey" Spell/Trap directly from your Deck to your Spell & Trap Zone. If your opponent Normal or Special Summons a monster(s) with the same Attribute as a monster in your GY (except during the Damage Step): You can destroy that monster(s).
external_ids: local SETCARD_ID_0 = 0x165 --Magikey
  
lua: local SETCARD_ID_0 = 0x165 --Magikey
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), aux.NonTuner(aux.FilterBoolFunction(Card.IsType, TYPE_NORMAL)), 1)
  	c:EnableReviveLimit()
  	--mass register
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.matcon)
  	e1:SetOperation(s.matop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_MATERIAL_CHECK)
  	e2:SetLabelObject(e1)
  	e2:SetValue(s.valcheck)
  	c:RegisterEffect(e2)
  	--attack twice
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_EXTRA_ATTACK_MONSTER)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--set
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.setcon)
  	e4:SetTarget(s.settg)
  	e4:SetOperation(s.setop)
  	c:RegisterEffect(e4)
  	--destroy
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_DESTROY)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_SUMMON_SUCCESS)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1, id + 1)
  	e5:SetCondition(s.descon)
  	e5:SetTarget(s.destg)
  	e5:SetOperation(s.desop)
  	c:RegisterEffect(e5)
  	local e6 = e5:Clone()
  	e6:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e6)
  end
  function s.matcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO) and e:GetLabel() == 1
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 2))
  end
  function s.attfilter(c, rc)
  	return c:GetAttribute() > 0
  end
  function s.valcheck(e, c)
  	local mg = c:GetMaterial()
  	local fg = mg:Filter(s.attfilter, nil, c)
  	if fg:GetClassCount(Card.GetAttribute) >= 2 then
  		e:GetLabelObject():SetLabel(1)
  	else
  		e:GetLabelObject():SetLabel(0)
  	end
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.setfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and not c:IsType(TYPE_FIELD) and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SSet(tp, g:GetFirst())
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsSummonPlayer(1 - tp) and Duel.IsExistingMatchingCard(Card.IsAttribute, tp, LOCATION_GRAVE, 0, 1, nil, c:GetAttribute())
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = eg:Filter(s.cfilter, nil, tp)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 then
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  
source_text: Magikey
  1 "Magikey" Tuner + 1+ non-Tuner Normal Monsters
  This card can make up to 2 attacks on monsters during each Battle Phase. You can only use each of the following effects of "Magikey Fiend - Transfurlmine" once per turn. If you control this card that was Synchro Summoned using at least 2 Attributes of monsters: You can Set 1 "Magikey" Spell/Trap directly from your Deck to your Spell & Trap Zone. If your opponent Normal or Special Summons a monster(s) with the same Attribute as a monster in your GY (except during the Damage Step): You can destroy that monster(s).
target_text: -- Magikey
  local SETCARD_ID_0 = 0x165 --Magikey
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSetCard, SETCARD_ID_0), aux.NonTuner(aux.FilterBoolFunction(Card.IsType, TYPE_NORMAL)), 1)
  	c:EnableReviveLimit()
  	--mass register
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.matcon)
  	e1:SetOperation(s.matop)
  	c:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_MATERIAL_CHECK)
  	e2:SetLabelObject(e1)
  	e2:SetValue(s.valcheck)
  	c:RegisterEffect(e2)
  	--attack twice
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EFFECT_EXTRA_ATTACK_MONSTER)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--set
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.setcon)
  	e4:SetTarget(s.settg)
  	e4:SetOperation(s.setop)
  	c:RegisterEffect(e4)
  	--destroy
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_DESTROY)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_SUMMON_SUCCESS)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1, id + 1)
  	e5:SetCondition(s.descon)
  	e5:SetTarget(s.destg)
  	e5:SetOperation(s.desop)
  	c:RegisterEffect(e5)
  	local e6 = e5:Clone()
  	e6:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e6)
  end
  function s.matcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO) and e:GetLabel() == 1
  end
  function s.matop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD, EFFECT_FLAG_CLIENT_HINT, 1, 0, aux.Stringid(id, 2))
  end
  function s.attfilter(c, rc)
  	return c:GetAttribute() > 0
  end
  function s.valcheck(e, c)
  	local mg = c:GetMaterial()
  	local fg = mg:Filter(s.attfilter, nil, c)
  	if fg:GetClassCount(Card.GetAttribute) >= 2 then
  		e:GetLabelObject():SetLabel(1)
  	else
  		e:GetLabelObject():SetLabel(0)
  	end
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.setfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and not c:IsType(TYPE_FIELD) and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SSet(tp, g:GetFirst())
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsSummonPlayer(1 - tp) and Duel.IsExistingMatchingCard(Card.IsAttribute, tp, LOCATION_GRAVE, 0, 1, nil, c:GetAttribute())
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = eg:Filter(s.cfilter, nil, tp)
  	Duel.SetTargetCard(g)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 then
  		Duel.Destroy(g, REASON_EFFECT)
  	end
  end
  
  