name: Despian
card_text: 1 "Despia" monster + 1 LIGHT monster + 1 DARK monster
  During the Main Phase (Quick Effect): You can target 1 Fusion, Synchro, Xyz, or Link Monster in your opponent's GY; banish it, or Special Summon it to your field. When this card destroys an opponent's monster by battle: You can inflict damage to your opponent equal to that monster's original ATK or DEF (whichever is higher). You can only use each effect of "Despian Proskenion" once per turn.
external_ids: local SETCARD_ID_0 = 0x164 --Despia
  
lua: local SETCARD_ID_0 = 0x164 --Despia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion procedure
  	c:EnableReviveLimit()
  	aux.AddFusionProcMix(c, false, true, aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_0), s.matfilter1, s.matfilter2, nil)
  	--special summon or banish
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMING_MAIN_END)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.effcon)
  	e1:SetTarget(s.efftg)
  	e1:SetOperation(s.effop)
  	c:RegisterEffect(e1)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(aux.bdocon)
  	e2:SetTarget(s.damtg)
  	e2:SetOperation(s.damop)
  	c:RegisterEffect(e2)
  end
  function s.matfilter1(c)
  	return c:IsFusionAttribute(ATTRIBUTE_LIGHT)
  end
  function s.matfilter2(c)
  	return c:IsFusionAttribute(ATTRIBUTE_DARK)
  end
  function s.effcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph == PHASE_MAIN1 or ph == PHASE_MAIN2
  end
  function s.rmfilter(c, e, tp, check)
  	return c:IsType(TYPE_FUSION + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK) and (c:IsAbleToRemove() or check and c:IsCanBeSpecialSummoned(e, 0, tp, false, false))
  end
  function s.efftg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local check = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_GRAVE) and s.rmfilter(chkc, e, tp, check)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.rmfilter, tp, 0, LOCATION_GRAVE, 1, nil, e, tp, check)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.rmfilter, tp, 0, LOCATION_GRAVE, 1, 1, nil, e, tp, check)
  end
  function s.effop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		if aux.NecroValleyNegateCheck(tc) then
  			return
  		end
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and tc:IsCanBeSpecialSummoned(e, 0, tp, false, false) and (not tc:IsAbleToRemove() or Duel.SelectOption(tp, 1192, 1152) == 1) then
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		else
  			Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  		end
  	end
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	local dam = bc:GetBaseAttack()
  	if bc:GetBaseAttack() < bc:GetBaseDefense() then
  		dam = bc:GetBaseDefense()
  	end
  	if chk == 0 then
  		return dam > 0
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  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: Despian
  1 "Despia" monster + 1 LIGHT monster + 1 DARK monster
  During the Main Phase (Quick Effect): You can target 1 Fusion, Synchro, Xyz, or Link Monster in your opponent's GY; banish it, or Special Summon it to your field. When this card destroys an opponent's monster by battle: You can inflict damage to your opponent equal to that monster's original ATK or DEF (whichever is higher). You can only use each effect of "Despian Proskenion" once per turn.
target_text: -- Despian
  local SETCARD_ID_0 = 0x164 --Despia
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion procedure
  	c:EnableReviveLimit()
  	aux.AddFusionProcMix(c, false, true, aux.FilterBoolFunction(Card.IsFusionSetCard, SETCARD_ID_0), s.matfilter1, s.matfilter2, nil)
  	--special summon or banish
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMING_MAIN_END)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.effcon)
  	e1:SetTarget(s.efftg)
  	e1:SetOperation(s.effop)
  	c:RegisterEffect(e1)
  	--damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DAMAGE)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCode(EVENT_BATTLE_DESTROYING)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(aux.bdocon)
  	e2:SetTarget(s.damtg)
  	e2:SetOperation(s.damop)
  	c:RegisterEffect(e2)
  end
  function s.matfilter1(c)
  	return c:IsFusionAttribute(ATTRIBUTE_LIGHT)
  end
  function s.matfilter2(c)
  	return c:IsFusionAttribute(ATTRIBUTE_DARK)
  end
  function s.effcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph == PHASE_MAIN1 or ph == PHASE_MAIN2
  end
  function s.rmfilter(c, e, tp, check)
  	return c:IsType(TYPE_FUSION + TYPE_SYNCHRO + TYPE_XYZ + TYPE_LINK) and (c:IsAbleToRemove() or check and c:IsCanBeSpecialSummoned(e, 0, tp, false, false))
  end
  function s.efftg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local check = Duel.GetLocationCount(tp, LOCATION_MZONE) > 0
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_GRAVE) and s.rmfilter(chkc, e, tp, check)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.rmfilter, tp, 0, LOCATION_GRAVE, 1, nil, e, tp, check)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.rmfilter, tp, 0, LOCATION_GRAVE, 1, 1, nil, e, tp, check)
  end
  function s.effop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		if aux.NecroValleyNegateCheck(tc) then
  			return
  		end
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and tc:IsCanBeSpecialSummoned(e, 0, tp, false, false) and (not tc:IsAbleToRemove() or Duel.SelectOption(tp, 1192, 1152) == 1) then
  			Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  		else
  			Duel.Remove(tc, POS_FACEUP, REASON_EFFECT)
  		end
  	end
  end
  function s.damtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	local dam = bc:GetBaseAttack()
  	if bc:GetBaseAttack() < bc:GetBaseDefense() then
  		dam = bc:GetBaseDefense()
  	end
  	if chk == 0 then
  		return dam > 0
  	end
  	Duel.SetTargetPlayer(1 - tp)
  	Duel.SetTargetParam(dam)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, dam)
  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
  
  