--冰结界的灾厄 古剑豹
local s,id,o=GetID()
function s.initial_effect(c)
    c:SetUniqueOnField(1,0,id)
    aux.AddSynchroProcedure(c,aux.FilterBoolFunction(Card.IsAttribute,ATTRIBUTE_WATER),aux.NonTuner(Card.IsAttribute,ATTRIBUTE_WATER),1)
    c:EnableReviveLimit()
    --[[1个连锁上1次，对方把怪兽效果发动时或者对方怪兽的攻击宣言时才能选从以下效果中选其中1个发动。这个回合，这张卡不能攻击。
        ●那只怪兽破坏。直到回合结束时这张卡不能选这个效果的另外1个效果发动。
        ●这张卡直到回合结束时除外。直到下个回合结束时这个卡名的卡不能选这个效果发动。]]
    local e0=Effect.CreateEffect(c)
    e0:SetType(EFFECT_TYPE_QUICK_O)
    e0:SetCode(EVENT_CHAINING)
    e0:SetRange(LOCATION_MZONE)
    e0:SetCountLimit(1,EFFECT_COUNT_CODE_CHAIN)
    e0:SetCondition(s.con0)
    e0:SetTarget(s.tg0)
    e0:SetOperation(s.op0)
    c:RegisterEffect(e0)
    local e5=e0:Clone()
    e5:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_TRIGGER_O)
    e5:SetCode(EVENT_ATTACK_ANNOUNCE)
    e5:SetCondition(s.con5)
    e5:SetTarget(s.tg5)
    c:RegisterEffect(e5)
    --[[双方怪兽在各自控制者的战斗阶段内攻击力上升1200]]
    local e1=Effect.CreateEffect(c)
    e1:SetType(EFFECT_TYPE_FIELD)
    e1:SetCode(EFFECT_UPDATE_ATTACK)
    e1:SetRange(LOCATION_MZONE)
    e1:SetTargetRange(LOCATION_MZONE,LOCATION_MZONE)
    e1:SetCondition(s.con1)
    e1:SetTarget(s.tg1)
    e1:SetValue(1200)
    c:RegisterEffect(e1)
    --[[和这张卡战斗的对方怪兽的攻击力·守备力只在伤害计算时变成原本数值]]
    local e2=Effect.CreateEffect(c)
    e2:SetType(EFFECT_TYPE_FIELD)
    e2:SetCode(EFFECT_SET_ATTACK_FINAL)
    e2:SetRange(LOCATION_MZONE)
    e2:SetTargetRange(0,LOCATION_MZONE)
    e2:SetCondition(s.con2)
    e2:SetTarget(s.tg2)
    e2:SetValue(s.value2)
    c:RegisterEffect(e2)
    local e3=e2:Clone()
    e3:SetCode(EFFECT_SET_DEFENSE_FINAL)
    e3:SetValue(s.value3)
    c:RegisterEffect(e3)
    --[[这张卡因对方从场上离开的场合才能发动。
    这张卡特殊召唤。这个效果特殊召唤的这张卡从场上离开的场合除外]]
    local e4=Effect.CreateEffect(c)
    e4:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_GRAVE_ACTION)
    e4:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
    e4:SetCode(EVENT_LEAVE_FIELD)
    e4:SetProperty(EFFECT_FLAG_DELAY)
    e4:SetCountLimit(1,id)
    e4:SetCondition(s.con4)
    e4:SetTarget(s.tg4)
    e4:SetOperation(s.op4)
    c:RegisterEffect(e4)
end
function s.con0(e,tp,eg,ep,ev,re,r,rp)
    return ep==1-tp and re:IsActiveType(TYPE_MONSTER)
        and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED)
end
function s.con5(e,tp,eg,ep,ev,re,r,rp)
    return Duel.GetAttacker():GetControler()~=tp
end
function s.tg0(e,tp,eg,ep,ev,re,r,rp,chk)
    local c=e:GetHandler()
    if chk==0 then return (re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re)) or (c:IsAbleToRemove() and (c:GetFlagEffect(id)==0 and Duel.GetFlagEffect(tp,id)==0)) end
    local off=1
    local ops,opval={},{}
    if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
        ops[off]=aux.Stringid(id,0)
        opval[off]=0
        off=off+1
    end
    if c:IsAbleToRemove() and (c:GetFlagEffect(id)==0 and Duel.GetFlagEffect(tp,id)==0) then
        ops[off]=aux.Stringid(id,1)
        opval[off]=1
        off=off+1
    end
    local op=Duel.SelectOption(tp,table.unpack(ops))+1
    local num=opval[op]
    if num==0 then c:RegisterFlagEffect(id,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,1)
        Duel.SetOperationInfo(0,CATEGORY_DESTROY,eg,1,0,0)
    else Duel.RegisterFlagEffect(tp,id,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,2)
        Duel.SetOperationInfo(0,CATEGORY_REMOVE,c,1,0,0)
    end
    e:SetLabel(num)
end
function s.tg5(e,tp,eg,ep,ev,re,r,rp,chk)
    local c=e:GetHandler()
    if chk==0 then return (Duel.GetAttacker():IsRelateToBattle() and Duel.GetAttacker():IsDestructable()) or (c:IsAbleToRemove() and (c:GetFlagEffect(id)==0 and Duel.GetFlagEffect(tp,id)==0)) end
    local off=1
    local ops,opval={},{}
    if Duel.GetAttacker():IsDestructable() and Duel.GetAttacker():IsRelateToBattle() then
        ops[off]=aux.Stringid(id,0)
        opval[off]=0
        off=off+1
    end
    if c:IsAbleToRemove() and (c:GetFlagEffect(id)==0 and Duel.GetFlagEffect(tp,id)==0) then
        ops[off]=aux.Stringid(id,1)
        opval[off]=1
        off=off+1
    end
    local op=Duel.SelectOption(tp,table.unpack(ops))+1
    local num=opval[op]
    if num==0 then c:RegisterFlagEffect(id,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,1)
        Duel.SetOperationInfo(0,CATEGORY_DESTROY,Duel.GetAttacker(),1,0,0)
    else Duel.RegisterFlagEffect(tp,id,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,2)
        Duel.SetOperationInfo(0,CATEGORY_REMOVE,c,1,0,0)
    end
    e:SetLabel(num)
end
function s.op0(e,tp,eg,ep,ev,re,r,rp)
    local c=e:GetHandler()
    local num=e:GetLabel()
    if num==0 then
        if re:GetHandler():IsRelateToEffect(re) then
            Duel.Destroy(eg,REASON_EFFECT)
        end
    else
        local fid=c:GetFieldID()
        if c:IsRelateToEffect(e) and Duel.Remove(c,0,REASON_EFFECT+REASON_TEMPORARY)~=0 and c:IsLocation(LOCATION_REMOVED) then
            c:RegisterFlagEffect(id,RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END,0,1,fid)
            local e1=Effect.CreateEffect(c)
            e1:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
            e1:SetCode(EVENT_PHASE+PHASE_END)
            e1:SetReset(RESET_PHASE+PHASE_END)
            e1:SetLabel(fid)
            e1:SetLabelObject(c)
            e1:SetCountLimit(1)
            e1:SetCondition(s.retcon)
            e1:SetOperation(s.retop)
            Duel.RegisterEffect(e1,tp)
        end
    end
    local e1=Effect.CreateEffect(c)
    e1:SetType(EFFECT_TYPE_SINGLE)
    e1:SetCode(EFFECT_CANNOT_ATTACK)
    e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
    e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END)
    c:RegisterEffect(e1)
end
function s.retcon(e,tp,eg,ep,ev,re,r,rp)
    local tc=e:GetLabelObject()
    if tc:GetFlagEffectLabel(id)~=e:GetLabel() then
        e:Reset()
        return false
    else return true end
end
function s.retop(e,tp,eg,ep,ev,re,r,rp)
    Duel.ReturnToField(e:GetLabelObject())
end
function s.con1(e)
    local ph=Duel.GetCurrentPhase()
    return (ph>=PHASE_BATTLE_START and ph<=PHASE_BATTLE)
end
function s.tg1(e,c)
    return Duel.GetTurnPlayer()==c:GetControler()
end
function s.con2(e)
    return Duel.GetCurrentPhase()==PHASE_DAMAGE_CAL and e:GetHandler():GetBattleTarget()
end
function s.tg2(e,c)
    return c==e:GetHandler():GetBattleTarget()
end
function s.value2(e,c)
    return c:GetBaseAttack()
end
function s.value3(e,c)
    return c:GetBaseDefense()
end
function s.con4(e,tp,eg,ep,ev,re,r,rp)
    local c=e:GetHandler()
    return c:IsPreviousLocation(LOCATION_MZONE)
        and c:IsPreviousControler(tp) and c:GetReasonPlayer()==1-tp
end
function s.tg4(e,tp,eg,ep,ev,re,r,rp,chk)
    local c=e:GetHandler()
    if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>0 and c:IsCanBeSpecialSummoned(e,0,tp,false,false) end
    Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,c,1,0,0)
end
function s.op4(e,tp,eg,ep,ev,re,r,rp)
    local c=e:GetHandler()
    if c:IsRelateToEffect(e) and Duel.SpecialSummonStep(c,0,tp,tp,false,false,POS_FACEUP) then
        local e1=Effect.CreateEffect(c)
        e1:SetType(EFFECT_TYPE_SINGLE)
        e1:SetCode(EFFECT_LEAVE_FIELD_REDIRECT)
        e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
        e1:SetReset(RESET_EVENT+RESETS_REDIRECT)
        e1:SetValue(LOCATION_REMOVED)
        c:RegisterEffect(e1,true)
    end
    Duel.SpecialSummonComplete()
end