name: Frightfur
card_text: This card's name becomes "Toy Vendor" while on the field or in the GY. Once per turn: You can discard 1 card; draw 1 card and show it, then if it is an "Edge Imp" monster, you can destroy 1 card on the field, otherwise place 1 card from your hand on the top or bottom of the Deck. If this card is sent to the GY: You can target 1 face-up monster your opponent controls; halve its ATK until the end of this turn.
external_ids: local CARD_ID_0 = 70245411 --Toy Vendor
  local SETCARD_ID_0 = 0xc3 --Edge
  
lua: local CARD_ID_0 = 70245411 --Toy Vendor
  local SETCARD_ID_0 = 0xc3 --Edge
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_0, LOCATION_SZONE + LOCATION_GRAVE)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW + CATEGORY_DESTROY + CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, tp, LOCATION_HAND)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.Draw(tp, 1, REASON_EFFECT) == 0 then
  		return
  	end
  	local tc = Duel.GetOperatedGroup():GetFirst()
  	Duel.ConfirmCards(1 - tp, tc)
  	if not tc:IsLocation(LOCATION_HAND) then
  		return
  	end
  	Duel.ShuffleHand(tp)
  	if tc:IsSetCard(SETCARD_ID_0) and tc:IsType(TYPE_MONSTER) then
  		local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  		if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local sc = g:Select(tp, 1, 1, nil)
  			Duel.HintSelection(sc)
  			Duel.Destroy(sc, REASON_EFFECT)
  		end
  	else
  		local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_HAND, 0, nil)
  		if g:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  			local sc = g:Select(tp, 1, 1, nil)
  			if Duel.SelectOption(tp, aux.Stringid(id, 3), aux.Stringid(id, 4)) == 0 then
  				Duel.SendtoDeck(sc, nil, SEQ_DECKTOP, REASON_EFFECT)
  			else
  				Duel.SendtoDeck(sc, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  			end
  		end
  	end
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, 1, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local atk = tc:GetAttack()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(math.ceil(atk / 2))
  		tc:RegisterEffect(e1)
  	end
  end
  
  
source_text: Frightfur
  This card's name becomes "Toy Vendor" while on the field or in the GY. Once per turn: You can discard 1 card; draw 1 card and show it, then if it is an "Edge Imp" monster, you can destroy 1 card on the field, otherwise place 1 card from your hand on the top or bottom of the Deck. If this card is sent to the GY: You can target 1 face-up monster your opponent controls; halve its ATK until the end of this turn.
target_text: -- Frightfur
  local CARD_ID_0 = 70245411 --Toy Vendor
  local SETCARD_ID_0 = 0xc3 --Edge
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e0)
  	--change code
  	aux.EnableChangeCode(c, CARD_ID_0, LOCATION_SZONE + LOCATION_GRAVE)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW + CATEGORY_DESTROY + CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--atk
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_ATKCHANGE)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e3:SetTarget(s.atktg)
  	e3:SetOperation(s.atkop)
  	c:RegisterEffect(e3)
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.DiscardHand(tp, Card.IsDiscardable, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, tp, LOCATION_HAND)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.Draw(tp, 1, REASON_EFFECT) == 0 then
  		return
  	end
  	local tc = Duel.GetOperatedGroup():GetFirst()
  	Duel.ConfirmCards(1 - tp, tc)
  	if not tc:IsLocation(LOCATION_HAND) then
  		return
  	end
  	Duel.ShuffleHand(tp)
  	if tc:IsSetCard(SETCARD_ID_0) and tc:IsType(TYPE_MONSTER) then
  		local g = Duel.GetMatchingGroup(aux.TRUE, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  		if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local sc = g:Select(tp, 1, 1, nil)
  			Duel.HintSelection(sc)
  			Duel.Destroy(sc, REASON_EFFECT)
  		end
  	else
  		local g = Duel.GetMatchingGroup(Card.IsAbleToDeck, tp, LOCATION_HAND, 0, nil)
  		if g:GetCount() > 0 then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  			local sc = g:Select(tp, 1, 1, nil)
  			if Duel.SelectOption(tp, aux.Stringid(id, 3), aux.Stringid(id, 4)) == 0 then
  				Duel.SendtoDeck(sc, nil, SEQ_DECKTOP, REASON_EFFECT)
  			else
  				Duel.SendtoDeck(sc, nil, SEQ_DECKBOTTOM, REASON_EFFECT)
  			end
  		end
  	end
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, 1, nil)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		local atk = tc:GetAttack()
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(math.ceil(atk / 2))
  		tc:RegisterEffect(e1)
  	end
  end
  
  