
local str = {}

local cache_1
local cache_2
local cache_3
local cache_4
local cache_5
local cache_6
local cache_7
local cache_8
local cache_9

_G.fun = {}

---------------------------------

str["效果卡的种类表"] = {}

str["效果卡的种类表"][1] = TYPE_SPELL
str["效果卡的种类表"][2] = TYPE_TRAP
str["效果卡的种类表"][3] = TYPE_EFFECT

str["无效果灵摆怪兽表"] = {}

str["无效果灵摆怪兽表"][1] = 28363749
str["无效果灵摆怪兽表"][2] = 19474136
str["无效果灵摆怪兽表"][3] = 17390179
str["无效果灵摆怪兽表"][4] = 83980492

cache_1 = 0

cache_1 = cache_1 + LOCATION_HAND
cache_1 = cache_1 + LOCATION_MZONE
cache_1 = cache_1 + LOCATION_SZONE
cache_1 = cache_1 + LOCATION_GRAVE
cache_1 = cache_1 + LOCATION_REMOVED

str["除卡组与额外卡组以外的区域"] = cache_1

cache_1 = cache_1 + LOCATION_DECK
cache_1 = cache_1 + LOCATION_EXTRA

str["所有区域"] = cache_1

---------------------------------

fun["Debug.ReloadFieldBegin"] = Debug.ReloadFieldBegin

Debug.ReloadFieldBegin = function(str_1, str_2) --{
  
  str["不洗牌"] = str_1 & DUEL_PSEUDO_SHUFFLE
  
  str["无BP"] = str_1 & DUEL_ATTACK_FIRST_TURN
  
  str["规则表"] = {}
  str["规则表"][3] = "大师3 "
  str["规则表"][4] = "新大师 "
  str["规则表"][5] = "大师2020 "
  
  if str_2 then --{
    
    str["规则"] = str["规则表"][str_2]
    
    --}
    
  else --{
    
    str["规则"] = str["规则表"][5]
    
    end --}
    
  fun["Debug.ReloadFieldBegin"](str_1, str_2)
  
  end --}
  
fun["Debug.ReloadFieldEnd"] = Debug.ReloadFieldEnd

Debug.ReloadFieldEnd = function(str_1) --{
  
  fun["Debug.ReloadFieldEnd"]()
  
  if str_1 then --{
    
    fun["随机抽卡"](str_1)
    
    end --}
    
  end --}
  
fun["aux.BeginPuzzle"] = aux.BeginPuzzle

aux.BeginPuzzle = function(str_1, str_2) --{
  
  fun["aux.BeginPuzzle"]()
  
  if str_1 then --{
    
    fun["开局添加手卡"](str_1)
    
    end --}
    
  if str_2 then --{
    
    fun["禁格"](str_2)
    
    end --}
    
  fun["开局说明"]()
  
  fun["通关邀请"]()
  
  fun["失败得分"]()
  
  end --}
  
fun["通关邀请"] = function() --{
  
  str["效果"] = Effect.GlobalEffect()
  
  str["效果"]:SetType(EFFECT_TYPE_FIELD
  + EFFECT_TYPE_CONTINUOUS)
  
  str["效果"]:SetCode(EVENT_DAMAGE)
  
  function cache_1() --{
    
    cache_1 = Duel.GetLP(1)
    
    if cache_1 <= 0 then --{
      
      if cache_1 == 0 then --{
        
        --}
        
      else  --{
        
        Debug.ShowHint("QB：「你居然二解了，请加群告诉我怎么二解。」")
        
        end --}
        
      Debug.ShowHint("残局群181175613")
      
      --}
      
    else --{
      
      return false
      
      end --}
      
    end --}
    
  str["效果"]:SetCondition(cache_1)
  
  str["效果"]:SetOperation(aux.NULL)
  
  Duel.RegisterEffect(str["效果"]
  , 0)
  
  end --}
  
fun["是否效果卡"] = function(card) --{
  
  for i = 1, #str["效果卡的种类表"] do --{
    
    cache_1 = Card.IsType(card, str["效果卡的种类表"][i])
    
    if cache_1 then --{
      
      return true
      end --}
      
    end --}
    
  cache_1 = Card.IsType(card, TYPE_PENDULUM)
  
  if cache_1 then --{
    
    for i = 1, #str["无效果灵摆怪兽表"] do --{
      
      if Card.IsCode(card, str["无效果灵摆怪兽表"][i]) then --{
        
        --}
        
      else  --{
        
        return true
        
        end --}
        
      end --}
      
    end --}
    
  return false
  
  end --}
  
fun["开局说明"] = function() --{
  
  str["这个残局的效果卡数量"] = Duel.GetMatchingGroupCount(fun["是否效果卡"]
  , 0
  , str["所有区域"]
  , str["所有区域"]
  , nil)
  
  str["超量素材组"] = Duel.GetOverlayGroup(0
  , LOCATION_MZONE
  , LOCATION_MZONE)
  
  for k in aux.Next(str["超量素材组"]) do --{
    
    if fun["是否效果卡"](k) then --{
      
      str["这个残局的效果卡数量"] = str["这个残局的效果卡数量"] + 1
      
      end --}
      
    end --}
    
  str["开局说明"] = str["这个残局的效果卡数量"]
  .. "卡 "
  .. str["规则"]
  
  if str["不洗牌"] == 0 then --{
    
    --}
    
  else --{
    
    str["开局说明"] = str["开局说明"] .. "伪洗牌 "
    
    end --}
    
  if str["无BP"] == 0 then --{
    
    str["开局说明"] = str["开局说明"] .. "无BP "
    
    end --}
    
  if str["开局添加手卡"] then --{
    
    str["开局说明"] = str["开局说明"]
    .. "选"
    .. str["开局添加手卡的数量"]
    .. "卡 "
    
    end --}
    
  if str["禁格"] then --{
    
    str["开局说明"] = str["开局说明"]
    .. "禁"
    .. str["禁格的数量"]
    .. "格 "
    
    end --}
    
  if str["随机抽卡的数量"] then --{
    
    str["开局说明"] = str["开局说明"]
    .. "抽"
    .. str["随机抽卡的数量"]
    .. "卡 "
    end --}
    
  Debug.ShowHint(str["开局说明"])
  
  end --}
  
fun["开局添加手卡"] = function(str_1) --{
  
  str["开局添加手卡的数量"] = str_1
  
  str["效果"] = Effect.GlobalEffect()
  
  str["效果"]:SetType(EFFECT_TYPE_FIELD
  + EFFECT_TYPE_CONTINUOUS)
  
  str["效果"]:SetCode(EVENT_ADJUST)
  
  str["效果"]:SetCondition(aux.TRUE)
  
  function cache_1(effect_event
  , player_who_activate_the_effect) --{
    
    str["玩家选定的卡"] = Duel.SelectMatchingCard(player_who_activate_the_effect
    , Card.IsAbleToHand
    , player_who_activate_the_effect
    , LOCATION_DECK
    , 0
    , str_1
    , str_1
    , nil)
    
    Duel.SendtoHand(str["玩家选定的卡"]
    , nil
    , REASON_RULE)
    
    effect_event:Reset()
    
    end --}
    
  str["效果"]:SetOperation(cache_1)
  
  Duel.RegisterEffect(str["效果"]
  , 0)
  
  end --}
  
fun["禁格"] = function(str_1) --{
  
  str["禁格的数量"] = str_1
  
  str["效果"] = Effect.GlobalEffect()
  
  str["效果"]:SetCode(EFFECT_USE_EXTRA_MZONE)
  
  str["效果"]:SetValue(str_1)
  
  Duel.RegisterEffect(str["效果"],0)
  
  end --}
  
fun["该效果不能被连锁"] = function() --{
  
  Duel.SetChainLimit(aux.FALSE)
  
  return true
  end --}
  
fun["印卡"] = function(str_1, str_2, str_3) --{
  
  if str_3 then --{
    
    --}
    
  else --{
    
    str_3 = str_2
    
    end --}
    
  Debug.ShowHint("点击对方额外卡组可以进行印卡。\n手卡只能印 "
  .. str_2
  .. " 张。\n最多可以印 "
  .. str_3
  .. " 张")
  
  str["效果"] = Effect.CreateEffect(str_1)
  
  str["当前印卡数"] = 1
  
  str["效果"]:SetType(EFFECT_TYPE_IGNITION)
  
  str["效果"]:SetProperty(EFFECT_FLAG_BOTH_SIDE
  + EFFECT_FLAG_UNCOPYABLE
  + EFFECT_FLAG_CANNOT_NEGATE
  + EFFECT_FLAG_CANNOT_DISABLE)
  
  str["效果"]:SetTarget(fun["该效果不能被连锁"])
  
  str["效果"]:SetRange(LOCATION_EXTRA)
  
  function print_hand(effect_event
  , player_who_activate_the_effect) --{
    
    announce_card = Duel.AnnounceCard(player_who_activate_the_effect)
    
    card = Duel.CreateToken(player_who_activate_the_effect
    , announce_card)
    
    if str["当前印卡数"] <= str_2 then --{
      
      str["当前印卡数"] = str["当前印卡数"] + 1
      
      Duel.SendtoHand(card,nil,REASON_RULE)
      
      --}
      
    else --{
      
      if str["当前印卡数"] <= str_3 then --{
        
        str["当前印卡数"] = str["当前印卡数"] + 1
        
        Duel.Remove(card,POS_FACEUP,REASON_RULE)
        
        Duel.SendtoDeck(card,player_who_activate_the_effect,0,REASON_RULE)
        
        --}
        
      else --{
        
        Debug.ShowHint("印卡过多！")
        
        effect_event:Reset()
        
        end --}
        
      end --}
      
    end --}
    
  str["效果"]:SetOperation(print_hand)
  
  str_1:RegisterEffect(str["效果"])
  
  end --}
  
fun["随机抽卡"] = function(str_1) --{
  
  str["随机抽卡的数量"] = str_1
  
  str["效果"] = Effect.GlobalEffect()
  
  str["效果"]:SetType(EFFECT_TYPE_FIELD
  + EFFECT_TYPE_CONTINUOUS)
  
  str["效果"]:SetCode(EVENT_ADJUST)
  
  str["效果"]:SetCondition(aux.TRUE)
  
  function cache_1(effect_event
  , player_who_activate_the_effect) --{
    
    Duel.ShuffleDeck(0)
    
    Duel.Draw(0,str_1,REASON_RULE)
    
    effect_event:Reset()
    
    end --}
    
  str["效果"]:SetOperation(cache_1)
  
  Duel.RegisterEffect(str["效果"]
  , 0)
  
  end --}
  
fun["失败得分"] = function() --{
  
  str["失败得分表"] = {}
  str["失败得分表"][0] = "神龙之圣刻印"
  str["失败得分表"][100] = "调和支援士"
  str["失败得分表"][200] = "深渊的暗杀者"
  str["失败得分表"][300] = "救援猫"
  str["失败得分表"][400] = "注射天使 莉莉"
  str["失败得分表"][500] = "不知火的隐者"
  str["失败得分表"][600] = "影依猎鹰"
  str["失败得分表"][700] = "铁兽战线 姬特"
  str["失败得分表"][800] = "召唤僧"
  str["失败得分表"][900] = "恩底弥翁的仆从"
  str["失败得分表"][1000] = "机壳工具 丑恶"
  str["失败得分表"][1100] = "欧尼斯特"
  str["失败得分表"][1200] = "次元吸引者"
  str["失败得分表"][1300] = "黑羽-疾风之盖尔"
  str["失败得分表"][1400] = "加农炮兵"
  str["失败得分表"][1500] = "青眼白龙"
  str["失败得分表"][1600] = "青眼白龙"
  str["失败得分表"][1700] = "青眼白龙"
  str["失败得分表"][1800] = "青眼白龙"
  str["失败得分表"][1900] = "青眼白龙"
  str["失败得分表"][2000] = "青眼白龙"
  str["失败得分表"][2100] = "青眼白龙"
  str["失败得分表"][2200] = "青眼白龙"
  str["失败得分表"][2300] = "青眼白龙"
  str["失败得分表"][2400] = "青眼白龙"
  str["失败得分表"][2500] = "青眼白龙"
  str["失败得分表"][2600] = "青眼白龙"
  str["失败得分表"][2700] = "青眼白龙"
  str["失败得分表"][2800] = "青眼白龙"
  str["失败得分表"][2900] = "青眼白龙"
  str["失败得分表"][3000] = "青眼白龙"
  
  str["对方玩家的初始生命值"] = Duel.GetLP(1)
  
  str["效果"] = Effect.GlobalEffect()
  
  str["效果"]:SetType(EFFECT_TYPE_FIELD
  + EFFECT_TYPE_CONTINUOUS)
  
  str["效果"]:SetCode(EVENT_PHASE_START+PHASE_END)
  
  function cache_1(effect_event
  , player_who_activate_the_effect) --{
    
    cache_1 = Duel.GetLP(1) - str["对方玩家的初始生命值"]
    
    if cache_1 > 0 then --{
      
      Debug.ShowHint("对面耍赖")
      
      --}
      
    else --{
      
      cache_1 = math.abs(cache_1) / (str["对方玩家的初始生命值"] - 100)
      
      cache_1 = math.tointeger(cache_1 * 3000 // 100 * 100)
      
      end --}
      
    if cache_1 > 3000 then --{
      
      Debug.ShowHint("比青眼白龙还厉害了")
      
      --}
      
    else --{
      
      Debug.ShowHint("您的得分是　"
      .. cache_1
      .. "　分！\n相当于「"
      .. str["失败得分表"][cache_1]
      .. "」级别！\n非常棒！")
      
      end --}
      
    effect_event:Reset()
    
    end --}
    
  str["效果"]:SetOperation(cache_1)
  
  Duel.RegisterEffect(str["效果"]
  , 0)
  
  end --}
  
