local this = {}

function this:req_enterScene(sceneId, pointId, creatorId, callback, transport)
  local data = {
    map_id = sceneId,
    point_id = pointId,
    creator_id = creatorId,
    trans_type = transport
  }
  if L_DungeonManager:getIsInDungeon() then
    L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("notice_cannot_goscene"))
    return
  end
  local operatorSendSystem = L_PlayerManager:getOperatorSendSystem()
  if operatorSendSystem then
    operatorSendSystem:shutdownSyncPosition()
  end
  L_Net:sendMessage(MsgGenCode.CSProtoEnterWorldMap, data, function(sData, errorCode)
    if errorCode == L_Const.errorCode.ErrCodeSucc then
      if callback then
        callback(sData, errorCode)
      end
    elseif errorCode == L_Const.errorCode.ErrCodeEnterFail then
      local operatorSendSystem = L_PlayerManager:getOperatorSendSystem()
      if operatorSendSystem then
        operatorSendSystem:syncPosition()
      end
      if callback then
        callback(sData, errorCode)
      end
    else
      local operatorSendSystem = L_PlayerManager:getOperatorSendSystem()
      if operatorSendSystem then
        operatorSendSystem:syncPosition()
      end
      if pointId then
        L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("notice_sceneStore"))
      else
      end
    end
  end, nil)
end

function this:req_transferInSameScene(pointId, transport, isStuck, callback)
  local data = {
    point_id = pointId,
    trans_type = transport,
    is_stuck = isStuck
  }
  local operatorSendSystem = L_PlayerManager:getOperatorSendSystem()
  if operatorSendSystem then
    operatorSendSystem:shutdownSyncPosition()
  end
  L_Net:sendMessage(MsgGenCode.CSProtoWorldPoint, data, function(sData, errorCode)
    if errorCode == L_Const.errorCode.ErrCodeSucc then
      if callback then
        callback(sData, errorCode)
      end
    else
      local operatorSendSystem = L_PlayerManager:getOperatorSendSystem()
      if operatorSendSystem then
        operatorSendSystem:syncPosition()
      end
    end
  end)
end

function this:transferToPoint(sceneId, pointId, creatorId, callback, transport, ignoreTaskLimit)
  if ignoreTaskLimit ~= true and L_TaskManager:checkIsDisableMapTransfer() then
    return
  end
  local curSceneId = AzurWorldInstance.CurWorldId
  if curSceneId == sceneId then
    self:req_transferInSameScene(pointId, transport, false, callback)
  else
    self:req_enterScene(sceneId, pointId, creatorId, callback, transport)
  end
end

function this:rsp_syncMapPoint(sData)
  local all = self:getAllUnlockPoint()
  for _, v in ipairs(sData.u32s) do
    all[v] = true
  end
  self:call(self.event.refreshPoint, sData.u32s)
end

return this
