name: Dark
card_text: Once per turn, during your Standby Phase: Take 1000 damage.
  You can only use 1 of the following effects of "Dark Contract with the Yamimakai" per turn, and only once that turn.
  ● During your Main Phase: You can target 1 "D/D" Pendulum Monster in your Graveyard; place it in your Pendulum Zone.
  ● During your Main Phase: You can place 1 face-up "D/D" Pendulum Monster from your Extra Deck in your Pendulum Zone.
external_ids: local SETCARD_ID_0 = 0xaf --D/D
  
lua: local SETCARD_ID_0 = 0xaf --D/D
  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)
  	--tohand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.pctg)
  	e2:SetOperation(s.pcop)
  	c:RegisterEffect(e2)
  	--damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 3))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.damcon)
  	e3:SetTarget(s.damtg)
  	e3:SetOperation(s.damop)
  	c:RegisterEffect(e3)
  end
  function s.pcfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and not c:IsForbidden()
  end
  function s.pctg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.pcfilter(chkc)
  	end
  	local b1 = Duel.IsExistingTarget(s.pcfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	local b2 = Duel.IsExistingMatchingCard(s.pcfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	if chk == 0 then
  		if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) and not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  			return false
  		end
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	e:SetLabel(op)
  	if op == 0 then
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g = Duel.SelectTarget(tp, s.pcfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  	else
  		e:SetProperty(0)
  	end
  end
  function s.pcop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		local tc = Duel.GetFirstTarget()
  		if tc:IsRelateToEffect(e) then
  			Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  		end
  	else
  		if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) and not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g = Duel.SelectMatchingCard(tp, s.pcfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.MoveToField(g:GetFirst(), tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  		end
  	end
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1000)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, 0, 0, tp, 1000)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  
  
source_text: Dark
  Once per turn, during your Standby Phase: Take 1000 damage.
  You can only use 1 of the following effects of "Dark Contract with the Yamimakai" per turn, and only once that turn.
  ● During your Main Phase: You can target 1 "D/D" Pendulum Monster in your Graveyard; place it in your Pendulum Zone.
  ● During your Main Phase: You can place 1 face-up "D/D" Pendulum Monster from your Extra Deck in your Pendulum Zone.
target_text: -- Dark
  local SETCARD_ID_0 = 0xaf --D/D
  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)
  	--tohand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.pctg)
  	e2:SetOperation(s.pcop)
  	c:RegisterEffect(e2)
  	--damage
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 3))
  	e3:SetCategory(CATEGORY_DAMAGE)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.damcon)
  	e3:SetTarget(s.damtg)
  	e3:SetOperation(s.damop)
  	c:RegisterEffect(e3)
  end
  function s.pcfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM) and not c:IsForbidden()
  end
  function s.pctg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.pcfilter(chkc)
  	end
  	local b1 = Duel.IsExistingTarget(s.pcfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	local b2 = Duel.IsExistingMatchingCard(s.pcfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	if chk == 0 then
  		if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) and not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  			return false
  		end
  		return b1 or b2
  	end
  	local op = 0
  	if b1 and b2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif b1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	e:SetLabel(op)
  	if op == 0 then
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g = Duel.SelectTarget(tp, s.pcfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, g, 1, 0, 0)
  	else
  		e:SetProperty(0)
  	end
  end
  function s.pcop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 0 then
  		local tc = Duel.GetFirstTarget()
  		if tc:IsRelateToEffect(e) then
  			Duel.MoveToField(tc, tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  		end
  	else
  		if not Duel.CheckLocation(tp, LOCATION_PZONE, 0) and not Duel.CheckLocation(tp, LOCATION_PZONE, 1) then
  			return
  		end
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOFIELD)
  		local g = Duel.SelectMatchingCard(tp, s.pcfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.MoveToField(g:GetFirst(), tp, tp, LOCATION_PZONE, POS_FACEUP, true)
  		end
  	end
  end
  function s.damcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1000)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, 0, 0, tp, 1000)
  end
  function s.damop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Damage(p, d, REASON_EFFECT)
  end
  
  