name: Ashened
card_text: During the Main Phase: You can Fusion Summon 1 Pyro Fusion Monster from your Extra Deck using monsters from either field as material, including "Veidos the Eruption Dragon of Extinction", and if you do, it gains 500 ATK for each material used. You can banish this card and 1 DARK Pyro monster from your GY; all monsters your opponent currently controls become Pyro until the end of this turn. You can only use each effect of "Ashened to Endlessness" once per turn.
external_ids: local CARD_ID_0 = 78783557 --Veidos the Eruption Dragon of Extinction
  
lua: local CARD_ID_0 = 78783557 --Veidos the Eruption Dragon of Extinction
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	-- activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	-- fusion summon
  	local e2 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = LOCATION_MZONE,
  		pre_select_mat_opponent_location = LOCATION_MZONE,
  		additional_fcheck = s.fcheck,
  		extra_target = s.extra_target,
  		stage_x_operation = s.stage_x_operation,
  	})
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCondition(s.fscon)
  	c:RegisterEffect(e2)
  	-- change race
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + o)
  	e3:SetCost(s.attcost)
  	e3:SetTarget(s.atttg)
  	e3:SetOperation(s.attop)
  	c:RegisterEffect(e3)
  end
  
  function s.fscon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  
  function s.fusfilter(c)
  	return c:IsRace(RACE_PYRO)
  end
  
  function s.fcheck(tp, mg, fc, mg_all)
  	--- Must include a 滅亡龍 ヴェイドス as fusion material
  	if not mg_all:IsExists(function(c)
  		return c:IsFusionCode(CARD_ID_0)
  	end, 1, nil) then
  		return false
  	end
  	return true
  end
  
  function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  
  function s.stage_x_operation(e, tc, tp, stage)
  	if stage == FusionSpell.STAGE_BEFORE_SUMMON_COMPLETE then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(tc:GetMaterialCount() * 500)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  
  function s.costfilter(c)
  	return c:IsRace(RACE_PYRO) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsAbleToRemoveAsCost()
  end
  
  function s.crfilter(c)
  	return c:IsFaceup() and not c:IsRace(RACE_PYRO)
  end
  
  function s.attcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, c) and c:IsAbleToRemoveAsCost()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, c)
  	g:AddCard(c)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  
  function s.atttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.crfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  end
  
  function s.attop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	for tc in aux.Next(g) do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_RACE)
  		e1:SetValue(RACE_PYRO)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Ashened
  During the Main Phase: You can Fusion Summon 1 Pyro Fusion Monster from your Extra Deck using monsters from either field as material, including "Veidos the Eruption Dragon of Extinction", and if you do, it gains 500 ATK for each material used. You can banish this card and 1 DARK Pyro monster from your GY; all monsters your opponent currently controls become Pyro until the end of this turn. You can only use each effect of "Ashened to Endlessness" once per turn.
target_text: -- Ashened
  local CARD_ID_0 = 78783557 --Veidos the Eruption Dragon of Extinction
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	-- activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	-- fusion summon
  	local e2 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  		pre_select_mat_location = LOCATION_MZONE,
  		pre_select_mat_opponent_location = LOCATION_MZONE,
  		additional_fcheck = s.fcheck,
  		extra_target = s.extra_target,
  		stage_x_operation = s.stage_x_operation,
  	})
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_MAIN_END)
  	e2:SetCondition(s.fscon)
  	c:RegisterEffect(e2)
  	-- change race
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + o)
  	e3:SetCost(s.attcost)
  	e3:SetTarget(s.atttg)
  	e3:SetOperation(s.attop)
  	c:RegisterEffect(e3)
  end
  
  function s.fscon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetCurrentPhase() == PHASE_MAIN1 or Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  
  function s.fusfilter(c)
  	return c:IsRace(RACE_PYRO)
  end
  
  function s.fcheck(tp, mg, fc, mg_all)
  	--- Must include a 滅亡龍 ヴェイドス as fusion material
  	if not mg_all:IsExists(function(c)
  		return c:IsFusionCode(CARD_ID_0)
  	end, 1, nil) then
  		return false
  	end
  	return true
  end
  
  function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  
  function s.stage_x_operation(e, tc, tp, stage)
  	if stage == FusionSpell.STAGE_BEFORE_SUMMON_COMPLETE then
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(tc:GetMaterialCount() * 500)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  		tc:RegisterEffect(e1)
  	end
  end
  
  function s.costfilter(c)
  	return c:IsRace(RACE_PYRO) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsAbleToRemoveAsCost()
  end
  
  function s.crfilter(c)
  	return c:IsFaceup() and not c:IsRace(RACE_PYRO)
  end
  
  function s.attcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, c) and c:IsAbleToRemoveAsCost()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, c)
  	g:AddCard(c)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  
  function s.atttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.crfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  end
  
  function s.attop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	for tc in aux.Next(g) do
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_CHANGE_RACE)
  		e1:SetValue(RACE_PYRO)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		tc:RegisterEffect(e1)
  	end
  end
  
  