name: Fiendsmith
card_text: This turn, your LIGHT Fiend monsters cannot be destroyed by battle, also any battle damage you take becomes halved. You can banish this card from your GY; Fusion Summon 1 "Fiendsmith" Fusion Monster from your Extra Deck, using monsters you control, and/or monsters in your Spell & Trap Zones that are equipped to a "Fiendsmith" monster as an Equip Spell, as material. You can only use this effect of "Fiendsmith Kyrie" once per turn.
external_ids: local SETCARD_ID_0 = 0x1b0 --Fiendsmith
  
lua: local SETCARD_ID_0 = 0x1b0 --Fiendsmith
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(aux.bpcon)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--fusion summon
  	local e2 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = LOCATION_MZONE | LOCATION_SZONE,
  		fusion_spell_matfilter = s.fusion_spell_matfilter,
  	})
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(aux.bfgcost)
  	c:RegisterEffect(e2)
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTarget(s.ptfilter)
  	e1:SetValue(1)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 0)
  	e2:SetValue(HALF_DAMAGE)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  
  function s.ptfilter(e, c)
  	return c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsRace(RACE_FIEND)
  end
  
  function s.fusfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.fusion_spell_matfilter(c)
  	if c:IsLocation(LOCATION_SZONE) then
  		if not c:IsAllTypes(TYPE_SPELL | TYPE_EQUIP) then
  			return false
  		end
  		local tc = c:GetEquipTarget()
  		if tc == nil or tc:IsFacedown() or not tc:IsSetCard(SETCARD_ID_0) then
  			return false
  		end
  	end
  	return true
  end
  
  
source_text: Fiendsmith
  This turn, your LIGHT Fiend monsters cannot be destroyed by battle, also any battle damage you take becomes halved. You can banish this card from your GY; Fusion Summon 1 "Fiendsmith" Fusion Monster from your Extra Deck, using monsters you control, and/or monsters in your Spell & Trap Zones that are equipped to a "Fiendsmith" monster as an Equip Spell, as material. You can only use this effect of "Fiendsmith Kyrie" once per turn.
target_text: -- Fiendsmith
  local SETCARD_ID_0 = 0x1b0 --Fiendsmith
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(aux.bpcon)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--fusion summon
  	local e2 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = LOCATION_MZONE | LOCATION_SZONE,
  		fusion_spell_matfilter = s.fusion_spell_matfilter,
  	})
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(aux.bfgcost)
  	c:RegisterEffect(e2)
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) == 0
  	end
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetTarget(s.ptfilter)
  	e1:SetValue(1)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 0)
  	e2:SetValue(HALF_DAMAGE)
  	e2:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e2, tp)
  	Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  end
  
  function s.ptfilter(e, c)
  	return c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsRace(RACE_FIEND)
  end
  
  function s.fusfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  
  function s.fusion_spell_matfilter(c)
  	if c:IsLocation(LOCATION_SZONE) then
  		if not c:IsAllTypes(TYPE_SPELL | TYPE_EQUIP) then
  			return false
  		end
  		local tc = c:GetEquipTarget()
  		if tc == nil or tc:IsFacedown() or not tc:IsSetCard(SETCARD_ID_0) then
  			return false
  		end
  	end
  	return true
  end
  
  