name: 血の代償
card_text: 500ライフポイントを払う事で、モンスター1体を通常召喚する。
  この効果は自分のメインフェイズ時及び相手のバトルフェイズ時にのみ発動できる。
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMING_BATTLE_START + TIMING_BATTLE_END)
  	e2:SetCondition(s.condition)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.activate)
  	c:RegisterEffect(e2)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tn = Duel.GetTurnPlayer()
  	local ph = Duel.GetCurrentPhase()
  	return (tn == tp and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2)) or (tn == 1 - tp and ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLPCost(tp, 500)
  	end
  	Duel.PayLPCost(tp, 500)
  end
  function s.filter(c)
  	return c:IsSummonable(true, nil) or c:IsMSetable(true, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ct1 = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_HAND + LOCATION_MZONE, 0, nil)
  		local ct2 = Duel.GetFlagEffect(tp, id)
  		return ct1 - ct2 > 0
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_CHAIN, 0, 1)
  	Duel.SetOperationInfo(0, CATEGORY_SUMMON, nil, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_HAND + LOCATION_MZONE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		local s1 = tc:IsSummonable(true, nil)
  		local s2 = tc:IsMSetable(true, nil)
  		if (s1 and s2 and Duel.SelectPosition(tp, tc, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) == POS_FACEUP_ATTACK) or not s2 then
  			Duel.Summon(tp, tc, true, nil)
  		else
  			Duel.MSet(tp, tc, true, nil)
  		end
  	end
  end
  
  
source_text: 血の代償
  500ライフポイントを払う事で、モンスター1体を通常召喚する。
  この効果は自分のメインフェイズ時及び相手のバトルフェイズ時にのみ発動できる。
target_text: -- 血の代償
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetHintTiming(0, TIMING_BATTLE_START + TIMING_BATTLE_END)
  	e2:SetCondition(s.condition)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.activate)
  	c:RegisterEffect(e2)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local tn = Duel.GetTurnPlayer()
  	local ph = Duel.GetCurrentPhase()
  	return (tn == tp and (ph == PHASE_MAIN1 or ph == PHASE_MAIN2)) or (tn == 1 - tp and ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLPCost(tp, 500)
  	end
  	Duel.PayLPCost(tp, 500)
  end
  function s.filter(c)
  	return c:IsSummonable(true, nil) or c:IsMSetable(true, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ct1 = Duel.GetMatchingGroupCount(s.filter, tp, LOCATION_HAND + LOCATION_MZONE, 0, nil)
  		local ct2 = Duel.GetFlagEffect(tp, id)
  		return ct1 - ct2 > 0
  	end
  	Duel.RegisterFlagEffect(tp, id, RESET_CHAIN, 0, 1)
  	Duel.SetOperationInfo(0, CATEGORY_SUMMON, nil, 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_HAND + LOCATION_MZONE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		local s1 = tc:IsSummonable(true, nil)
  		local s2 = tc:IsMSetable(true, nil)
  		if (s1 and s2 and Duel.SelectPosition(tp, tc, POS_FACEUP_ATTACK + POS_FACEDOWN_DEFENSE) == POS_FACEUP_ATTACK) or not s2 then
  			Duel.Summon(tp, tc, true, nil)
  		else
  			Duel.MSet(tp, tc, true, nil)
  		end
  	end
  end
  
  