name: Lavalval
card_text: 1 Tuner + 1+ non-Tuner FIRE monsters
  If this card is Synchro Summoned: You can draw 2 cards, then, if you have a FIRE monster in your hand, send 2 cards from your hand to the GY including a FIRE monster. Otherwise, reveal your entire hand, and shuffle it into the Deck. You can only use this effect of "Lavalval Salamander" once per turn. Once per turn: You can banish 1 FIRE monster from your GY; change face-up monsters your opponent controls, up to the number of "Laval" monsters you control, to face-down Defense Position.
external_ids: local SETCARD_ID_0 = 0x39 --Laval
  
lua: local SETCARD_ID_0 = 0x39 --Laval
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(Card.IsAttribute, ATTRIBUTE_FIRE), 1)
  	c:EnableReviveLimit()
  	--Draw
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.drcon)
  	e1:SetTarget(s.drtg)
  	e1:SetOperation(s.drop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_POSITION)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 2)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(2)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 2)
  end
  function s.tgcheck(g)
  	return g:IsExists(Card.IsAttribute, 1, nil, ATTRIBUTE_FIRE)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  	Duel.BreakEffect()
  	local g = Duel.GetFieldGroup(tp, LOCATION_HAND, 0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local tg = g:SelectSubGroup(tp, s.tgcheck, false, 2, 2)
  	if tg then
  		if Duel.SendtoGrave(tg, REASON_EFFECT) == 0 then
  			Duel.ShuffleHand(p)
  		end
  	else
  		local sg = Duel.GetFieldGroup(p, LOCATION_HAND, 0)
  		Duel.ConfirmCards(1 - p, sg)
  		Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.refilter(c)
  	return c:IsAttribute(ATTRIBUTE_FIRE) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.refilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.refilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.posfilter(c)
  	return c:IsFaceup() and c:IsCanTurnSet()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.posfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectMatchingCard(tp, s.posfilter, tp, 0, LOCATION_MZONE, 1, ct, nil)
  	if #g > 0 then
  		Duel.HintSelection(g)
  		Duel.ChangePosition(g, POS_FACEDOWN_DEFENSE)
  	end
  end
  
  
source_text: Lavalval
  1 Tuner + 1+ non-Tuner FIRE monsters
  If this card is Synchro Summoned: You can draw 2 cards, then, if you have a FIRE monster in your hand, send 2 cards from your hand to the GY including a FIRE monster. Otherwise, reveal your entire hand, and shuffle it into the Deck. You can only use this effect of "Lavalval Salamander" once per turn. Once per turn: You can banish 1 FIRE monster from your GY; change face-up monsters your opponent controls, up to the number of "Laval" monsters you control, to face-down Defense Position.
target_text: -- Lavalval
  local SETCARD_ID_0 = 0x39 --Laval
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(Card.IsAttribute, ATTRIBUTE_FIRE), 1)
  	c:EnableReviveLimit()
  	--Draw
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.drcon)
  	e1:SetTarget(s.drtg)
  	e1:SetOperation(s.drop)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_POSITION)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_SYNCHRO)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 2)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(2)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 2)
  end
  function s.tgcheck(g)
  	return g:IsExists(Card.IsAttribute, 1, nil, ATTRIBUTE_FIRE)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  	Duel.BreakEffect()
  	local g = Duel.GetFieldGroup(tp, LOCATION_HAND, 0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local tg = g:SelectSubGroup(tp, s.tgcheck, false, 2, 2)
  	if tg then
  		if Duel.SendtoGrave(tg, REASON_EFFECT) == 0 then
  			Duel.ShuffleHand(p)
  		end
  	else
  		local sg = Duel.GetFieldGroup(p, LOCATION_HAND, 0)
  		Duel.ConfirmCards(1 - p, sg)
  		Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.refilter(c)
  	return c:IsAttribute(ATTRIBUTE_FIRE) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.refilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.refilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.posfilter(c)
  	return c:IsFaceup() and c:IsCanTurnSet()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.posfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetMatchingGroupCount(s.cfilter, tp, LOCATION_MZONE, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectMatchingCard(tp, s.posfilter, tp, 0, LOCATION_MZONE, 1, ct, nil)
  	if #g > 0 then
  		Duel.HintSelection(g)
  		Duel.ChangePosition(g, POS_FACEDOWN_DEFENSE)
  	end
  end
  
  