name: War
card_text: You can only control 1 "War Rock Ordeal". When this card is activated: Place 3 counters on it. When your "War Rock" monster destroys an opponent's monster by battle and sends it to their GY: You can remove 1 counter from this card, and if you do, draw 1 card. If the last counter has been removed by this effect, send this card to the GY.
external_ids: local SETCARD_ID_0 = 0x15f --War
  local COUNTER_ID_0 = 0x5a --Counter(War
  
lua: local SETCARD_ID_0 = 0x15f --War
  local COUNTER_ID_0 = 0x5a --Counter(War
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5a, LOCATION_SZONE)
  	c:SetUniqueOnField(1, 0, id)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.drcon)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsCanAddCounter(tp, COUNTER_ID_0, 3, e:GetHandler())
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 3)
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	local at = tc:GetBattleTarget()
  	return eg:GetCount() == 1 and tc:IsLocation(LOCATION_GRAVE) and tc:IsReason(REASON_BATTLE) and at:IsRelateToBattle() and at:IsControler(tp) and at:IsSetCard(SETCARD_ID_0)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 1, REASON_EFFECT) and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and c:RemoveCounter(tp, COUNTER_ID_0, 1, REASON_EFFECT) then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		if Duel.Draw(p, d, REASON_EFFECT) ~= 0 and c:GetCounter(COUNTER_ID_0) == 0 then
  			Duel.SendtoGrave(c, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: War
  You can only control 1 "War Rock Ordeal". When this card is activated: Place 3 counters on it. When your "War Rock" monster destroys an opponent's monster by battle and sends it to their GY: You can remove 1 counter from this card, and if you do, draw 1 card. If the last counter has been removed by this effect, send this card to the GY.
target_text: -- War
  local SETCARD_ID_0 = 0x15f --War
  local COUNTER_ID_0 = 0x5a --Counter(War
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5a, LOCATION_SZONE)
  	c:SetUniqueOnField(1, 0, id)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.drcon)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsCanAddCounter(tp, COUNTER_ID_0, 3, e:GetHandler())
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 3)
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local tc = eg:GetFirst()
  	local at = tc:GetBattleTarget()
  	return eg:GetCount() == 1 and tc:IsLocation(LOCATION_GRAVE) and tc:IsReason(REASON_BATTLE) and at:IsRelateToBattle() and at:IsControler(tp) and at:IsSetCard(SETCARD_ID_0)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 1, REASON_EFFECT) and Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and c:RemoveCounter(tp, COUNTER_ID_0, 1, REASON_EFFECT) then
  		local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  		if Duel.Draw(p, d, REASON_EFFECT) ~= 0 and c:GetCounter(COUNTER_ID_0) == 0 then
  			Duel.SendtoGrave(c, REASON_EFFECT)
  		end
  	end
  end
  
  