name: War
card_text: During the Battle Phase: Target 1 "War Rock" monster in your GY, then activate 1 of these effects;
  ● Special Summon that target in Attack Position, but for the rest of this turn, its effects are negated, also it cannot attack directly.
  ● Special Summon that target in Defense Position, also the first time each "War Rock" monster you control would be destroyed by battle this turn, it is not destroyed.
  You can only activate 1 "War Rock Spirit" per turn.
external_ids: local SETCARD_ID_0 = 0x15f --War
  
lua: local SETCARD_ID_0 = 0x15f --War
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
  end
  function s.afilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.dfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		local op = e:GetLabel()
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and (op == 0 and s.afilter(chkc, e, tp) or op == 1 and s.dfilter(chkc, e, tp))
  	end
  	local b1 = Duel.IsExistingTarget(s.afilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	local b2 = Duel.IsExistingTarget(s.dfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and (b1 or b2)
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	e:SetLabel(op)
  	local filter = s.afilter
  	if op == 1 then
  		filter = s.dfilter
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	local op = e:GetLabel()
  	if tc:IsRelateToEffect(e) then
  		if op == 0 then
  			Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_DISABLE_EFFECT)
  			e2:SetValue(RESET_TURN_SET)
  			tc:RegisterEffect(e2)
  			local e3 = Effect.CreateEffect(c)
  			e3:SetType(EFFECT_TYPE_SINGLE)
  			e3:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  			e3:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e3)
  			Duel.SpecialSummonComplete()
  		else
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		end
  	end
  	if op == 1 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  		e1:SetTargetRange(LOCATION_MZONE, 0)
  		e1:SetTarget(s.indtg)
  		e1:SetValue(s.indct)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.indtg(e, c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.indct(e, re, r, rp)
  	if bit.band(r, REASON_BATTLE) ~= 0 then
  		return 1
  	else
  		return 0
  	end
  end
  
  
source_text: War
  During the Battle Phase: Target 1 "War Rock" monster in your GY, then activate 1 of these effects;
  ● Special Summon that target in Attack Position, but for the rest of this turn, its effects are negated, also it cannot attack directly.
  ● Special Summon that target in Defense Position, also the first time each "War Rock" monster you control would be destroyed by battle this turn, it is not destroyed.
  You can only activate 1 "War Rock Spirit" per turn.
target_text: -- War
  local SETCARD_ID_0 = 0x15f --War
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
  end
  function s.afilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_ATTACK)
  end
  function s.dfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		local op = e:GetLabel()
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and (op == 0 and s.afilter(chkc, e, tp) or op == 1 and s.dfilter(chkc, e, tp))
  	end
  	local b1 = Duel.IsExistingTarget(s.afilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	local b2 = Duel.IsExistingTarget(s.dfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and (b1 or b2)
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0), aux.Stringid(id, 1))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 0))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1)) + 1
  	end
  	e:SetLabel(op)
  	local filter = s.afilter
  	if op == 1 then
  		filter = s.dfilter
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	local op = e:GetLabel()
  	if tc:IsRelateToEffect(e) then
  		if op == 0 then
  			Duel.SpecialSummonStep(tc, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetCode(EFFECT_DISABLE_EFFECT)
  			e2:SetValue(RESET_TURN_SET)
  			tc:RegisterEffect(e2)
  			local e3 = Effect.CreateEffect(c)
  			e3:SetType(EFFECT_TYPE_SINGLE)
  			e3:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  			e3:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc:RegisterEffect(e3)
  			Duel.SpecialSummonComplete()
  		else
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		end
  	end
  	if op == 1 then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetCode(EFFECT_INDESTRUCTABLE_COUNT)
  		e1:SetTargetRange(LOCATION_MZONE, 0)
  		e1:SetTarget(s.indtg)
  		e1:SetValue(s.indct)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.indtg(e, c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.indct(e, re, r, rp)
  	if bit.band(r, REASON_BATTLE) ~= 0 then
  		return 1
  	else
  		return 0
  	end
  end
  
  