name: Terrorking
card_text: Cannot be Normal or Flip Summoned unless you control an "Archfiend" monster. Once per turn, during your Standby Phase, you must pay 800 LP (this is not optional), or this card is destroyed. When resolving an opponent's card effect that targets this card, roll a six-sided die and negate that effect if you roll a 2 or 5, and if you do, destroy that card. Negate the effects of Effect Monsters destroyed by battle with this card (including in the GY).
external_ids: local CARD_ID_0 = 94585852 --Pandemonium
  local SETCARD_ID_0 = 0x45 --Archfiend
  
lua: local CARD_ID_0 = 94585852 --Pandemonium
  local SETCARD_ID_0 = 0x45 --Archfiend
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--sumlimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CANNOT_SUMMON)
  	e1:SetCondition(s.excon)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_FLIP_SUMMON)
  	c:RegisterEffect(e2)
  	--maintain
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e3:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.mtcon)
  	e3:SetOperation(s.mtop)
  	c:RegisterEffect(e3)
  	--disable and destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCategory(CATEGORY_DICE)
  	e4:SetCode(EVENT_CHAIN_SOLVING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetOperation(s.disop)
  	c:RegisterEffect(e4)
  	--disable
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e5:SetCode(EVENT_BATTLED)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetOperation(s.disop2)
  	c:RegisterEffect(e5)
  end
  function s.exfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.excon(e)
  	return not Duel.IsExistingMatchingCard(s.exfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
  end
  function s.mtcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.CheckLPCost(tp, 800) or Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		if not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) or not Duel.SelectEffectYesNo(tp, e:GetHandler(), aux.Stringid(94585852, 1)) then
  			Duel.PayLPCost(tp, 800)
  		end
  	else
  		Duel.Destroy(e:GetHandler(), REASON_COST)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp then
  		return
  	end
  	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return false
  	end
  	local tg = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	if not tg or not tg:IsContains(e:GetHandler()) or not Duel.IsChainDisablable(ev) then
  		return false
  	end
  	local rc = re:GetHandler()
  	local dc = Duel.TossDice(tp, 1)
  	if dc ~= 2 and dc ~= 5 then
  		return
  	end
  	if Duel.NegateEffect(ev, true) and rc:IsRelateToEffect(re) then
  		Duel.Destroy(rc, REASON_EFFECT)
  	end
  end
  function s.disop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetBattleTarget()
  	if tc and tc:IsType(TYPE_EFFECT) and tc:IsStatus(STATUS_BATTLE_DESTROYED) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + 0x17a0000)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetReset(RESET_EVENT + 0x17a0000)
  		tc:RegisterEffect(e2)
  	end
  end
  
  
source_text: Terrorking
  Cannot be Normal or Flip Summoned unless you control an "Archfiend" monster. Once per turn, during your Standby Phase, you must pay 800 LP (this is not optional), or this card is destroyed. When resolving an opponent's card effect that targets this card, roll a six-sided die and negate that effect if you roll a 2 or 5, and if you do, destroy that card. Negate the effects of Effect Monsters destroyed by battle with this card (including in the GY).
target_text: -- Terrorking
  local CARD_ID_0 = 94585852 --Pandemonium
  local SETCARD_ID_0 = 0x45 --Archfiend
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--sumlimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_CANNOT_SUMMON)
  	e1:SetCondition(s.excon)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_CANNOT_FLIP_SUMMON)
  	c:RegisterEffect(e2)
  	--maintain
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e3:SetCode(EVENT_PHASE + PHASE_STANDBY)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.mtcon)
  	e3:SetOperation(s.mtop)
  	c:RegisterEffect(e3)
  	--disable and destroy
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e4:SetCategory(CATEGORY_DICE)
  	e4:SetCode(EVENT_CHAIN_SOLVING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetOperation(s.disop)
  	c:RegisterEffect(e4)
  	--disable
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e5:SetCode(EVENT_BATTLED)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetOperation(s.disop2)
  	c:RegisterEffect(e5)
  end
  function s.exfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.excon(e)
  	return not Duel.IsExistingMatchingCard(s.exfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
  end
  function s.mtcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == tp
  end
  function s.mtop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.CheckLPCost(tp, 800) or Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		if not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) or not Duel.SelectEffectYesNo(tp, e:GetHandler(), aux.Stringid(94585852, 1)) then
  			Duel.PayLPCost(tp, 800)
  		end
  	else
  		Duel.Destroy(e:GetHandler(), REASON_COST)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp then
  		return
  	end
  	if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then
  		return false
  	end
  	local tg = Duel.GetChainInfo(ev, CHAININFO_TARGET_CARDS)
  	if not tg or not tg:IsContains(e:GetHandler()) or not Duel.IsChainDisablable(ev) then
  		return false
  	end
  	local rc = re:GetHandler()
  	local dc = Duel.TossDice(tp, 1)
  	if dc ~= 2 and dc ~= 5 then
  		return
  	end
  	if Duel.NegateEffect(ev, true) and rc:IsRelateToEffect(re) then
  		Duel.Destroy(rc, REASON_EFFECT)
  	end
  end
  function s.disop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = c:GetBattleTarget()
  	if tc and tc:IsType(TYPE_EFFECT) and tc:IsStatus(STATUS_BATTLE_DESTROYED) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_DISABLE)
  		e1:SetReset(RESET_EVENT + 0x17a0000)
  		tc:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_DISABLE_EFFECT)
  		e2:SetReset(RESET_EVENT + 0x17a0000)
  		tc:RegisterEffect(e2)
  	end
  end
  
  