name: Appliancer
card_text: 1 "Appliancer" monster
  Cannot be used as Link Material the turn it is Link Summoned. This linked card gains 1000 ATK. Once per turn, during your Battle Phase, if this card is co-linked (except during the Damage Step): You can switch the locations of 2 "Appliancer" monsters in your Main Monster Zones, including this card, and if you do, the other monster can make a second attack during each Battle Phase this turn. Once per turn, when this card that is not co-linked is targeted for an attack: You can negate that attack.
external_ids: local SETCARD_ID_0 = 0x14b --Appliancer
  
lua: local SETCARD_ID_0 = 0x14b --Appliancer
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 1, 1)
  	--cannot link material
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_CANNOT_BE_LINK_MATERIAL)
  	e1:SetValue(s.lmlimit)
  	c:RegisterEffect(e1)
  	--atk
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(1000)
  	e2:SetCondition(s.atkcon)
  	c:RegisterEffect(e2)
  	--change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetHintTiming(TIMING_BATTLE_START)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.chcon)
  	e3:SetTarget(s.chtg)
  	e3:SetOperation(s.chop)
  	c:RegisterEffect(e3)
  	--negate attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BE_BATTLE_TARGET)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.negcon)
  	e4:SetOperation(s.negop)
  	c:RegisterEffect(e4)
  end
  function s.lmlimit(e)
  	local c = e:GetHandler()
  	return c:IsStatus(STATUS_SPSUMMON_TURN) and c:IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.atkcon(e)
  	return e:GetHandler():IsLinkState()
  end
  function s.chcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE and e:GetHandler():GetMutualLinkedGroupCount() > 0 and Duel.GetTurnPlayer() == tp and Duel.GetCurrentChain() == 0
  end
  function s.chfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetSequence() < 5
  end
  function s.fselect(g, c)
  	return g:IsContains(c)
  end
  function s.chtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.chfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.fselect, 2, 2, e:GetHandler())
  	end
  end
  function s.chop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.chfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local sg = g:SelectSubGroup(tp, s.fselect, false, 2, 2, c)
  	if sg and sg:GetCount() == 2 then
  		Duel.HintSelection(sg)
  		local tc1 = sg:GetFirst()
  		local tc2 = sg:GetNext()
  		Duel.SwapSequence(tc1, tc2)
  		local tc = tc1
  		if tc == c then
  			tc = tc2
  		end
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_EXTRA_ATTACK)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetMutualLinkedGroupCount() == 0
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  
source_text: Appliancer
  1 "Appliancer" monster
  Cannot be used as Link Material the turn it is Link Summoned. This linked card gains 1000 ATK. Once per turn, during your Battle Phase, if this card is co-linked (except during the Damage Step): You can switch the locations of 2 "Appliancer" monsters in your Main Monster Zones, including this card, and if you do, the other monster can make a second attack during each Battle Phase this turn. Once per turn, when this card that is not co-linked is targeted for an attack: You can negate that attack.
target_text: -- Appliancer
  local SETCARD_ID_0 = 0x14b --Appliancer
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 1, 1)
  	--cannot link material
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_CANNOT_BE_LINK_MATERIAL)
  	e1:SetValue(s.lmlimit)
  	c:RegisterEffect(e1)
  	--atk
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(1000)
  	e2:SetCondition(s.atkcon)
  	c:RegisterEffect(e2)
  	--change
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetHintTiming(TIMING_BATTLE_START)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.chcon)
  	e3:SetTarget(s.chtg)
  	e3:SetOperation(s.chop)
  	c:RegisterEffect(e3)
  	--negate attack
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_BE_BATTLE_TARGET)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.negcon)
  	e4:SetOperation(s.negop)
  	c:RegisterEffect(e4)
  end
  function s.lmlimit(e)
  	local c = e:GetHandler()
  	return c:IsStatus(STATUS_SPSUMMON_TURN) and c:IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.atkcon(e)
  	return e:GetHandler():IsLinkState()
  end
  function s.chcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE and e:GetHandler():GetMutualLinkedGroupCount() > 0 and Duel.GetTurnPlayer() == tp and Duel.GetCurrentChain() == 0
  end
  function s.chfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:GetSequence() < 5
  end
  function s.fselect(g, c)
  	return g:IsContains(c)
  end
  function s.chtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.chfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.fselect, 2, 2, e:GetHandler())
  	end
  end
  function s.chop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) then
  		return
  	end
  	local g = Duel.GetMatchingGroup(s.chfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local sg = g:SelectSubGroup(tp, s.fselect, false, 2, 2, c)
  	if sg and sg:GetCount() == 2 then
  		Duel.HintSelection(sg)
  		local tc1 = sg:GetFirst()
  		local tc2 = sg:GetNext()
  		Duel.SwapSequence(tc1, tc2)
  		local tc = tc1
  		if tc == c then
  			tc = tc2
  		end
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetCode(EFFECT_EXTRA_ATTACK)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetMutualLinkedGroupCount() == 0
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  