name: Gouki
card_text: 3+ "Gouki" monsters
  Cannot be destroyed by battle, and is unaffected by the activated effects of your opponent's monsters with ATK less than or equal to this card. When your opponent activates a card or effect that targets this card, and/or a monster(s) this card points to (Quick Effect): You can make this card lose exactly 500 ATK, and if you do, negate the activation. Once per turn, if this card's current ATK is different from its original ATK (Quick Effect): You can make this card gain 1000 ATK until the end of this turn.
external_ids: local SETCARD_ID_0 = 0xfc --Gouki
  
lua: local SETCARD_ID_0 = 0xfc --Gouki
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 3)
  	c:EnableReviveLimit()
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--immune
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_IMMUNE_EFFECT)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(s.immval)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_NEGATE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e3:SetCondition(s.negcon)
  	e3:SetTarget(s.negtg)
  	e3:SetOperation(s.negop)
  	c:RegisterEffect(e3)
  	--atk up
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_ATKCHANGE)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.atkcon)
  	e4:SetOperation(s.atkop)
  	c:RegisterEffect(e4)
  end
  function s.immval(e, te)
  	return te:GetOwner() ~= e:GetHandler()
  		and te:IsActiveType(TYPE_MONSTER)
  		and te:GetOwnerPlayer() ~= e:GetHandlerPlayer()
  		and te:GetOwner():GetAttack() <= e:GetHandler():GetAttack()
  		and te:IsActivated()
  end
  function s.negfilter(c, g)
  	return g:IsContains(c)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if rp == tp or c:IsStatus(STATUS_BATTLE_DESTROYED) then
  		return false
  	end
  	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return false
  	end
  	local lg = e:GetHandler():GetLinkedGroup()
  	lg:AddCard(c)
  	local tg = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	return tg and lg:IsExists(s.negfilter, 1, nil, tg) and Duel.IsChainNegatable(ev)
  end
  function s.negtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFacedown() or c:GetAttack() < 500 or not c:IsRelateToEffect(e) or Duel.GetCurrentChain() ~= ev + 1 or c:IsStatus(STATUS_BATTLE_DESTROYED) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(-500)
  	c:RegisterEffect(e1)
  	if not c:IsImmuneToEffect(e1) and not c:IsHasEffect(EFFECT_REVERSE_UPDATE) then
  		Duel.NegateActivation(ev)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return not c:IsAttack(c:GetBaseAttack()) and aux.dscon(e, tp, eg, ep, ev, re, r, rp)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(1000)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END)
  	c:RegisterEffect(e1)
  end
  
  
source_text: Gouki
  3+ "Gouki" monsters
  Cannot be destroyed by battle, and is unaffected by the activated effects of your opponent's monsters with ATK less than or equal to this card. When your opponent activates a card or effect that targets this card, and/or a monster(s) this card points to (Quick Effect): You can make this card lose exactly 500 ATK, and if you do, negate the activation. Once per turn, if this card's current ATK is different from its original ATK (Quick Effect): You can make this card gain 1000 ATK until the end of this turn.
target_text: -- Gouki
  local SETCARD_ID_0 = 0xfc --Gouki
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkSetCard, SETCARD_ID_0), 3)
  	c:EnableReviveLimit()
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--immune
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_IMMUNE_EFFECT)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(s.immval)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_NEGATE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e3:SetCondition(s.negcon)
  	e3:SetTarget(s.negtg)
  	e3:SetOperation(s.negop)
  	c:RegisterEffect(e3)
  	--atk up
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_ATKCHANGE)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.atkcon)
  	e4:SetOperation(s.atkop)
  	c:RegisterEffect(e4)
  end
  function s.immval(e, te)
  	return te:GetOwner() ~= e:GetHandler()
  		and te:IsActiveType(TYPE_MONSTER)
  		and te:GetOwnerPlayer() ~= e:GetHandlerPlayer()
  		and te:GetOwner():GetAttack() <= e:GetHandler():GetAttack()
  		and te:IsActivated()
  end
  function s.negfilter(c, g)
  	return g:IsContains(c)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if rp == tp or c:IsStatus(STATUS_BATTLE_DESTROYED) then
  		return false
  	end
  	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return false
  	end
  	local lg = e:GetHandler():GetLinkedGroup()
  	lg:AddCard(c)
  	local tg = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	return tg and lg:IsExists(s.negfilter, 1, nil, tg) and Duel.IsChainNegatable(ev)
  end
  function s.negtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFacedown() or c:GetAttack() < 500 or not c:IsRelateToEffect(e) or Duel.GetCurrentChain() ~= ev + 1 or c:IsStatus(STATUS_BATTLE_DESTROYED) then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(-500)
  	c:RegisterEffect(e1)
  	if not c:IsImmuneToEffect(e1) and not c:IsHasEffect(EFFECT_REVERSE_UPDATE) then
  		Duel.NegateActivation(ev)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return not c:IsAttack(c:GetBaseAttack()) and aux.dscon(e, tp, eg, ep, ev, re, r, rp)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:IsRelateToEffect(e) or c:IsFacedown() then
  		return
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetValue(1000)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END)
  	c:RegisterEffect(e1)
  end
  
  