name: Knightmare
card_text: 2 monsters with different names
  If this card is Link Summoned during your turn: You can discard 1 card; if this card was co-linked when this effect was activated, you can draw 1 card, also, during your Main Phase this turn, you can Normal Summon 1 monster from your hand to your zone this card points to, in addition to your Normal Summon/Set. You can only apply this effect of "Knightmare Goblin" once per turn. Neither player can target co-linked monsters you control with card effects.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--extra summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.sumcon)
  	e1:SetCost(s.sumcost)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--cannot target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.tgtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.sumcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK) and Duel.GetTurnPlayer() == tp
  end
  function s.sumcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanSummon(tp) and Duel.IsPlayerCanAdditionalSummon(tp) and Duel.GetFlagEffect(tp, id) == 0
  	end
  	if e:GetHandler():GetMutualLinkedGroupCount() > 0 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetLabel(1)
  	else
  		e:SetCategory(0)
  		e:SetLabel(0)
  	end
  end
  function s.sumop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 1 and Duel.IsPlayerCanDraw(tp, 1) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local fid = c:GetFieldID()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 2))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetTargetRange(LOCATION_HAND, 0)
  	e1:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e1:SetLabel(fid)
  	e1:SetCondition(s.sumcon2)
  	e1:SetValue(s.sumval)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.sumcon2(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFieldID() == e:GetLabel()
  end
  function s.sumval(e, c)
  	local c = e:GetHandler()
  	local sumzone = c:GetLinkedZone()
  	local relzone = -bit.lshift(1, c:GetSequence())
  	return 0, sumzone, relzone
  end
  function s.tgtg(e, c)
  	return c:GetMutualLinkedGroupCount() > 0
  end
  
  
source_text: Knightmare
  2 monsters with different names
  If this card is Link Summoned during your turn: You can discard 1 card; if this card was co-linked when this effect was activated, you can draw 1 card, also, during your Main Phase this turn, you can Normal Summon 1 monster from your hand to your zone this card points to, in addition to your Normal Summon/Set. You can only apply this effect of "Knightmare Goblin" once per turn. Neither player can target co-linked monsters you control with card effects.
target_text: -- Knightmare
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, nil, 2, 2, s.lcheck)
  	c:EnableReviveLimit()
  	--extra summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.sumcon)
  	e1:SetCost(s.sumcost)
  	e1:SetTarget(s.sumtg)
  	e1:SetOperation(s.sumop)
  	c:RegisterEffect(e1)
  	--cannot target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.tgtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:GetClassCount(Card.GetLinkCode) == g:GetCount()
  end
  function s.sumcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK) and Duel.GetTurnPlayer() == tp
  end
  function s.sumcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.sumtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanSummon(tp) and Duel.IsPlayerCanAdditionalSummon(tp) and Duel.GetFlagEffect(tp, id) == 0
  	end
  	if e:GetHandler():GetMutualLinkedGroupCount() > 0 then
  		e:SetCategory(CATEGORY_DRAW)
  		e:SetLabel(1)
  	else
  		e:SetCategory(0)
  		e:SetLabel(0)
  	end
  end
  function s.sumop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 1 and Duel.IsPlayerCanDraw(tp, 1) and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  	if Duel.GetFlagEffect(tp, id) ~= 0 then
  		return
  	end
  	local c = e:GetHandler()
  	local fid = c:GetFieldID()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 2))
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetTargetRange(LOCATION_HAND, 0)
  	e1:SetCode(EFFECT_EXTRA_SUMMON_COUNT)
  	e1:SetLabel(fid)
  	e1:SetCondition(s.sumcon2)
  	e1:SetValue(s.sumval)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.sumcon2(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFieldID() == e:GetLabel()
  end
  function s.sumval(e, c)
  	local c = e:GetHandler()
  	local sumzone = c:GetLinkedZone()
  	local relzone = -bit.lshift(1, c:GetSequence())
  	return 0, sumzone, relzone
  end
  function s.tgtg(e, c)
  	return c:GetMutualLinkedGroupCount() > 0
  end
  
  