name: Curse
card_text: When a monster effect is activated that would inflict damage to you: Your opponent takes that damage instead. When you take battle damage, while this card is in your GY: You can Set this card. You can only use this effect of "Curse Reflection Doll" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--reflect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCondition(s.condition)
  	e1:SetOperation(s.refop)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DAMAGE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.setcon)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return aux.damcon1(e, tp, eg, ep, ev, re, r, rp) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.refop(e, tp, eg, ep, ev, re, r, rp)
  	local cid = Duel.GetChainInfo(ev, CHAININFO_CHAIN_ID)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_REFLECT_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetLabel(cid)
  	e1:SetValue(s.refcon)
  	e1:SetReset(RESET_CHAIN)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.refcon(e, re, val, r, rp, rc)
  	local cc = Duel.GetCurrentChain()
  	if cc == 0 or bit.band(r, REASON_EFFECT) == 0 then
  		return
  	end
  	local cid = Duel.GetChainInfo(0, CHAININFO_CHAIN_ID)
  	return cid == e:GetLabel()
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  
source_text: Curse
  When a monster effect is activated that would inflict damage to you: Your opponent takes that damage instead. When you take battle damage, while this card is in your GY: You can Set this card. You can only use this effect of "Curse Reflection Doll" once per turn.
target_text: -- Curse
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--reflect
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_CHAINING)
  	e1:SetCondition(s.condition)
  	e1:SetOperation(s.refop)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DAMAGE)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.setcon)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return aux.damcon1(e, tp, eg, ep, ev, re, r, rp) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.refop(e, tp, eg, ep, ev, re, r, rp)
  	local cid = Duel.GetChainInfo(ev, CHAININFO_CHAIN_ID)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_REFLECT_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(1, 0)
  	e1:SetLabel(cid)
  	e1:SetValue(s.refcon)
  	e1:SetReset(RESET_CHAIN)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.refcon(e, re, val, r, rp, rc)
  	local cc = Duel.GetCurrentChain()
  	if cc == 0 or bit.band(r, REASON_EFFECT) == 0 then
  		return
  	end
  	local cid = Duel.GetChainInfo(0, CHAININFO_CHAIN_ID)
  	return cid == e:GetLabel()
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == tp
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SSet(tp, c)
  	end
  end
  
  