name: Dinomist
card_text: Pendulum Scale = 3
  [ Pendulum Effect ]
  If another "Dinomist" card(s) you control would be destroyed by battle or an opponent's card effect, you can destroy this card instead.
  ----------------------------------------
  [ Monster Effect ]
  You can Tribute 1 other "Dinomist" monster, then activate 1 of these effects;
  ● This card can attack your opponent directly this turn.
  ● This card can make a second attack during each Battle Phase this turn.
external_ids: local SETCARD_ID_0 = 0xd8 --Dinomist
  
lua: local SETCARD_ID_0 = 0xd8 --Dinomist
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--destroy replace
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_DESTROY_REPLACE)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetTarget(s.reptg)
  	e1:SetValue(s.repval)
  	e1:SetOperation(s.repop)
  	c:RegisterEffect(e1)
  	--Attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.atkcon)
  	e2:SetCost(s.atkcost)
  	e2:SetTarget(s.atktg)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsControler(tp)
  		and c:IsOnField()
  		and c:IsSetCard(SETCARD_ID_0)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, c, tp) and c:IsDestructable(e) and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  	end
  	return Duel.SelectEffectYesNo(tp, c, 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT + REASON_REPLACE)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsAbleToEnterBP()
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsSetCard, 1, c, 0xd8)
  	end
  	local rg = Duel.SelectReleaseGroup(tp, Card.IsSetCard, 1, 1, c, 0xd8)
  	Duel.Release(rg, REASON_COST)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local con1 = c:GetFlagEffect(id) == 0
  	local con2 = c:GetFlagEffect(5067885) == 0
  	if chk == 0 then
  		return con1 or con2
  	end
  	local op = 0
  	if con1 and con2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif con1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	e:SetLabel(op)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local op = e:GetLabel()
  	if op == 0 then
  		if c:IsFaceup() and c:IsRelateToEffect(e) then
  			c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END, 0, 0)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DIRECT_ATTACK)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			c:RegisterEffect(e1)
  		end
  	elseif op == 1 then
  		if c:IsFaceup() and c:IsRelateToEffect(e) then
  			c:RegisterFlagEffect(5067885, RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END, 0, 0)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_EXTRA_ATTACK)
  			e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e2:SetValue(1)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			c:RegisterEffect(e2)
  		end
  	end
  end
  
  
source_text: Dinomist
  Pendulum Scale = 3
  [ Pendulum Effect ]
  If another "Dinomist" card(s) you control would be destroyed by battle or an opponent's card effect, you can destroy this card instead.
  ----------------------------------------
  [ Monster Effect ]
  You can Tribute 1 other "Dinomist" monster, then activate 1 of these effects;
  ● This card can attack your opponent directly this turn.
  ● This card can make a second attack during each Battle Phase this turn.
target_text: -- Dinomist
  local SETCARD_ID_0 = 0xd8 --Dinomist
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--pendulum summon
  	aux.EnablePendulumAttribute(c)
  	--destroy replace
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_DESTROY_REPLACE)
  	e1:SetRange(LOCATION_PZONE)
  	e1:SetTarget(s.reptg)
  	e1:SetValue(s.repval)
  	e1:SetOperation(s.repop)
  	c:RegisterEffect(e1)
  	--Attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.atkcon)
  	e2:SetCost(s.atkcost)
  	e2:SetTarget(s.atktg)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsControler(tp)
  		and c:IsOnField()
  		and c:IsSetCard(SETCARD_ID_0)
  		and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp))
  		and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, c, tp) and c:IsDestructable(e) and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  	end
  	return Duel.SelectEffectYesNo(tp, c, 96)
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT + REASON_REPLACE)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsAbleToEnterBP()
  end
  function s.atkcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.CheckReleaseGroup(tp, Card.IsSetCard, 1, c, 0xd8)
  	end
  	local rg = Duel.SelectReleaseGroup(tp, Card.IsSetCard, 1, 1, c, 0xd8)
  	Duel.Release(rg, REASON_COST)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local con1 = c:GetFlagEffect(id) == 0
  	local con2 = c:GetFlagEffect(5067885) == 0
  	if chk == 0 then
  		return con1 or con2
  	end
  	local op = 0
  	if con1 and con2 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1), aux.Stringid(id, 2))
  	elseif con1 then
  		op = Duel.SelectOption(tp, aux.Stringid(id, 1))
  	else
  		op = Duel.SelectOption(tp, aux.Stringid(id, 2)) + 1
  	end
  	e:SetLabel(op)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local op = e:GetLabel()
  	if op == 0 then
  		if c:IsFaceup() and c:IsRelateToEffect(e) then
  			c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END, 0, 0)
  			local e1 = Effect.CreateEffect(c)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DIRECT_ATTACK)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			c:RegisterEffect(e1)
  		end
  	elseif op == 1 then
  		if c:IsFaceup() and c:IsRelateToEffect(e) then
  			c:RegisterFlagEffect(5067885, RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END, 0, 0)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetCode(EFFECT_EXTRA_ATTACK)
  			e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e2:SetValue(1)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			c:RegisterEffect(e2)
  		end
  	end
  end
  
  