name: Bujingi
card_text: During either player's Damage Step, if a Beast-Warrior-Type "Bujin" monster you control battles an opponent's monster: You can banish this card from your Graveyard; that monster you control gains ATK equal to the current ATK of the opponent's monster it is battling until the end of the Damage Step, and if it does, all battle damage your opponent takes from that battle is halved. You can only use this effect of "Bujingi Sinyou" once per turn.
external_ids: local SETCARD_ID_0 = 0x88 --Bujin
  
lua: local SETCARD_ID_0 = 0x88 --Bujin
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atkup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetRange(LOCATION_GRAVE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.atkcon)
  	e1:SetCost(aux.bfgcost)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local phase = Duel.GetCurrentPhase()
  	if phase ~= PHASE_DAMAGE or Duel.IsDamageCalculated() then
  		return false
  	end
  	local c = Duel.GetAttackTarget()
  	if not c then
  		return false
  	end
  	if c:IsControler(1 - tp) then
  		c = Duel.GetAttacker()
  	end
  	return c and c:IsSetCard(SETCARD_ID_0) and c:IsRace(RACE_BEASTWARRIOR) and c:IsRelateToBattle()
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local d = Duel.GetAttackTarget()
  	if not a:IsRelateToBattle() or a:IsFacedown() or not d:IsRelateToBattle() or d:IsFacedown() then
  		return
  	end
  	if a:IsControler(1 - tp) then
  		a, d = d, a
  	end
  	if a:IsImmuneToEffect(e) then
  		return
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetOwnerPlayer(tp)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  	e1:SetValue(d:GetAttack())
  	a:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(0, 1)
  	e2:SetValue(HALF_DAMAGE)
  	e2:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	Duel.RegisterEffect(e2, tp)
  end
  
  
source_text: Bujingi
  During either player's Damage Step, if a Beast-Warrior-Type "Bujin" monster you control battles an opponent's monster: You can banish this card from your Graveyard; that monster you control gains ATK equal to the current ATK of the opponent's monster it is battling until the end of the Damage Step, and if it does, all battle damage your opponent takes from that battle is halved. You can only use this effect of "Bujingi Sinyou" once per turn.
target_text: -- Bujingi
  local SETCARD_ID_0 = 0x88 --Bujin
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atkup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetRange(LOCATION_GRAVE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.atkcon)
  	e1:SetCost(aux.bfgcost)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local phase = Duel.GetCurrentPhase()
  	if phase ~= PHASE_DAMAGE or Duel.IsDamageCalculated() then
  		return false
  	end
  	local c = Duel.GetAttackTarget()
  	if not c then
  		return false
  	end
  	if c:IsControler(1 - tp) then
  		c = Duel.GetAttacker()
  	end
  	return c and c:IsSetCard(SETCARD_ID_0) and c:IsRace(RACE_BEASTWARRIOR) and c:IsRelateToBattle()
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local d = Duel.GetAttackTarget()
  	if not a:IsRelateToBattle() or a:IsFacedown() or not d:IsRelateToBattle() or d:IsFacedown() then
  		return
  	end
  	if a:IsControler(1 - tp) then
  		a, d = d, a
  	end
  	if a:IsImmuneToEffect(e) then
  		return
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetOwnerPlayer(tp)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_DAMAGE)
  	e1:SetValue(d:GetAttack())
  	a:RegisterEffect(e1)
  	local e2 = Effect.CreateEffect(e:GetHandler())
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(0, 1)
  	e2:SetValue(HALF_DAMAGE)
  	e2:SetReset(RESET_PHASE + PHASE_DAMAGE)
  	Duel.RegisterEffect(e2, tp)
  end
  
  