name: Kaiki
card_text: If this card is Special Summoned (except during the Damage Step): You can pay 500 LP; Fusion Summon 1 Warrior Fusion Monster from your Extra Deck, using monsters from your hand or field as Fusion Material. During your opponent's turn, if this card is in your GY and you control a Level 5 or higher Warrior monster whose current ATK is different from its original ATK (Quick Effect): You can Special Summon this card. You can only use each effect of "Kaiki the Unity Star" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Fusion Summon
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  	})
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.fuscon)
  	e1:SetCost(s.fuscost)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  
  function s.fuscon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph ~= PHASE_DAMAGE and ph ~= PHASE_DAMAGE_CAL
  end
  
  function s.fuscost(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.fusfilter(c)
  	return c:IsRace(RACE_WARRIOR)
  end
  
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_WARRIOR) and c:IsLevelAbove(5) and not c:IsAttack(c:GetBaseAttack())
  end
  
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp and Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) > 0 and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Kaiki
  If this card is Special Summoned (except during the Damage Step): You can pay 500 LP; Fusion Summon 1 Warrior Fusion Monster from your Extra Deck, using monsters from your hand or field as Fusion Material. During your opponent's turn, if this card is in your GY and you control a Level 5 or higher Warrior monster whose current ATK is different from its original ATK (Quick Effect): You can Special Summon this card. You can only use each effect of "Kaiki the Unity Star" once per turn.
target_text: -- Kaiki
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Fusion Summon
  	local e1 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  	})
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.fuscon)
  	e1:SetCost(s.fuscost)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  
  function s.fuscon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph ~= PHASE_DAMAGE and ph ~= PHASE_DAMAGE_CAL
  end
  
  function s.fuscost(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.fusfilter(c)
  	return c:IsRace(RACE_WARRIOR)
  end
  
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_WARRIOR) and c:IsLevelAbove(5) and not c:IsAttack(c:GetBaseAttack())
  end
  
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() ~= tp and Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) > 0 and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  