name: Prufinesse,
card_text: If this card is Normal or Special Summoned: You can banish 1 Trap from your Deck; increase this card's Level by 1. You can target 1 Trap in either GY; banish it, and if you do, increase this card's Level by 1. If this card in its owner's possession is destroyed by an opponent's card: You can Set 1 of your banished Normal Traps. You can only use each effect of "Prufinesse, the Tactical Trapper" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--level change(summon/special summon success)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.lvcost)
  	e1:SetTarget(s.lvtg)
  	e1:SetOperation(s.lvop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--level change(ignition)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetTarget(s.lvtg2)
  	e3:SetOperation(s.lvop2)
  	c:RegisterEffect(e3)
  	--set
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DESTROYED)
  	e4:SetProperty(EFFECT_FLAG_DELAY)
  	e4:SetCountLimit(1, id + 2)
  	e4:SetCondition(s.setcon)
  	e4:SetTarget(s.settg)
  	e4:SetOperation(s.setop)
  	c:RegisterEffect(e4)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_TRAP) and c:IsAbleToRemoveAsCost()
  end
  function s.lvcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsRelateToEffect(e) and c:IsLevelAbove(1)
  	end
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and c:IsFaceup() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.lvfilter(c)
  	return c:IsType(TYPE_TRAP) and c:IsAbleToRemove()
  end
  function s.lvtg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.lvfilter(chkc)
  	end
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsLevelAbove(1) and Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, 0, 0)
  end
  function s.lvop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Remove(tc, POS_FACEUP, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_REMOVED) and c:IsRelateToEffect(e) and c:IsFaceup() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and e:GetHandler():IsPreviousControler(tp)
  end
  function s.setfilter(c)
  	return c:IsFaceup() and c:GetType() == TYPE_TRAP and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		Duel.SSet(tp, tc)
  	end
  end
  
  
source_text: Prufinesse,
  If this card is Normal or Special Summoned: You can banish 1 Trap from your Deck; increase this card's Level by 1. You can target 1 Trap in either GY; banish it, and if you do, increase this card's Level by 1. If this card in its owner's possession is destroyed by an opponent's card: You can Set 1 of your banished Normal Traps. You can only use each effect of "Prufinesse, the Tactical Trapper" once per turn.
target_text: -- Prufinesse,
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--level change(summon/special summon success)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.lvcost)
  	e1:SetTarget(s.lvtg)
  	e1:SetOperation(s.lvop)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e2)
  	--level change(ignition)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_REMOVE)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetTarget(s.lvtg2)
  	e3:SetOperation(s.lvop2)
  	c:RegisterEffect(e3)
  	--set
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 2))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DESTROYED)
  	e4:SetProperty(EFFECT_FLAG_DELAY)
  	e4:SetCountLimit(1, id + 2)
  	e4:SetCondition(s.setcon)
  	e4:SetTarget(s.settg)
  	e4:SetOperation(s.setop)
  	c:RegisterEffect(e4)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_TRAP) and c:IsAbleToRemoveAsCost()
  end
  function s.lvcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.lvtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsRelateToEffect(e) and c:IsLevelAbove(1)
  	end
  end
  function s.lvop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and c:IsFaceup() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.lvfilter(c)
  	return c:IsType(TYPE_TRAP) and c:IsAbleToRemove()
  end
  function s.lvtg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and s.lvfilter(chkc)
  	end
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsLevelAbove(1) and Duel.IsExistingTarget(s.lvfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectTarget(tp, s.lvfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, 1, 0, 0)
  end
  function s.lvop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.Remove(tc, POS_FACEUP, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_REMOVED) and c:IsRelateToEffect(e) and c:IsFaceup() then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_LEVEL)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  	end
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and e:GetHandler():IsPreviousControler(tp)
  end
  function s.setfilter(c)
  	return c:IsFaceup() and c:GetType() == TYPE_TRAP and c:IsSSetable()
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.setfilter, tp, LOCATION_REMOVED, 0, 1, nil)
  	end
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SET)
  	local g = Duel.SelectMatchingCard(tp, s.setfilter, tp, LOCATION_REMOVED, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		Duel.SSet(tp, tc)
  	end
  end
  
  