📄 textmapreader.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package l1j.server;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import l1j.server.server.datatables.MapsTable;
import l1j.server.server.model.map.L1Map;
import l1j.server.server.model.map.L1V1Map;
/**
* テキストマップ(maps/\d*.txt)を読み込む.
*/
public class TextMapReader extends MapReader {
/** メッセージログ用. */
private static Logger _log = Logger
.getLogger(TextMapReader.class.getName());
/** マップホルダー. */
private static final String MAP_DIR = "./maps/";
/** MAP_INFO用 マップ番号位置. */
public static final int MAPINFO_MAP_NO = 0;
/** MAP_INFO用 開始X座標の位置. */
public static final int MAPINFO_START_X = 1;
/** MAP_INFO用 最終X座標の位置. */
public static final int MAPINFO_END_X = 2;
/** MAP_INFO用 開始Y座標の位置. */
public static final int MAPINFO_START_Y = 3;
/** MAP_INFO用 開始Y座標の位置. */
public static final int MAPINFO_END_Y = 4;
/**
* 指定のマップ番号のテキストマップを読み込む.
*
* @param mapId
* マップ番号
* @param xSize
* X座標のサイズ
* @param ySize
* Y座標のサイズ
* @return byte[][]
* @throws IOException
*/
public byte[][] read(final int mapId, final int xSize, final int ySize)
throws IOException {
byte[][] map = new byte[xSize][ySize];
LineNumberReader in = new LineNumberReader(new BufferedReader(
new FileReader(MAP_DIR + mapId + ".txt")));
int y = 0;
String line;
while ((line = in.readLine()) != null) {
if (line.trim().length() == 0 || line.startsWith("#")) {
continue; // 空行とコメントをスキップ
}
int x = 0;
StringTokenizer tok = new StringTokenizer(line, ",");
while (tok.hasMoreTokens()) {
byte tile = Byte.parseByte(tok.nextToken());
map[x][y] = tile;
x++;
}
y++;
}
in.close();
return map;
}
/**
* 指定のマップ番号のテキストマップを読み込む.
*
* @param id
* マップ番号
* @return L1Map
* @throws IOException
*/
@Override
public L1Map read(final int id) throws IOException {
for (int[] info : MAP_INFO) {
int mapId = info[MAPINFO_MAP_NO];
int xSize = info[MAPINFO_END_X] - info[MAPINFO_START_X] + 1;
int ySize = info[MAPINFO_END_Y] - info[MAPINFO_START_Y] + 1;
if (mapId == id) {
L1V1Map map = new L1V1Map((short) mapId, this.read(mapId,
xSize, ySize), info[MAPINFO_START_X],
info[MAPINFO_START_Y],
MapsTable.getInstance().isUnderwater(mapId),
MapsTable.getInstance().isMarkable(mapId),
MapsTable.getInstance().isTeleportable(mapId),
MapsTable.getInstance().isEscapable(mapId),
MapsTable.getInstance().isUseResurrection(mapId),
MapsTable.getInstance().isUsePainwand(mapId),
MapsTable.getInstance().isEnabledDeathPenalty(mapId),
MapsTable.getInstance().isTakePets(mapId),
MapsTable.getInstance().isRecallPets(mapId),
MapsTable.getInstance().isUsableItem(mapId),
MapsTable.getInstance().isUsableSkill(mapId));
return map;
}
}
throw new FileNotFoundException("MapId: " + id);
}
/**
* 全てのテキストマップを読み込む.
*
* @return Map
* @throws IOException
*/
@Override
public Map<Integer, L1Map> read() throws IOException {
Map<Integer, L1Map> maps = new HashMap<Integer, L1Map>();
for (int[] info : MAP_INFO) {
int mapId = info[MAPINFO_MAP_NO];
int xSize = info[MAPINFO_END_X] - info[MAPINFO_START_X] + 1;
int ySize = info[MAPINFO_END_Y] - info[MAPINFO_START_Y] + 1;
try {
L1V1Map map = new L1V1Map((short) mapId, this.read(mapId,
xSize, ySize), info[MAPINFO_START_X],
info[MAPINFO_START_Y],
MapsTable.getInstance().isUnderwater(mapId),
MapsTable.getInstance().isMarkable(mapId),
MapsTable.getInstance().isTeleportable(mapId),
MapsTable.getInstance().isEscapable(mapId),
MapsTable.getInstance().isUseResurrection(mapId),
MapsTable.getInstance().isUsePainwand(mapId),
MapsTable.getInstance().isEnabledDeathPenalty(mapId),
MapsTable.getInstance().isTakePets(mapId),
MapsTable.getInstance().isRecallPets(mapId),
MapsTable.getInstance().isUsableItem(mapId),
MapsTable.getInstance().isUsableSkill(mapId));
maps.put(mapId, map);
} catch (IOException e) {
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
return maps;
}
/**
* mapInfo:マップNo、マップサイズを保持している.
* 1レコードが{mapNo,StartX,EndX,StartY,EndY}で構成されている.
*/
private static final int[][] MAP_INFO = {
{ 0, 32256, 32767, 32768, 33279 },
{ 1, 32640, 32767, 32768, 32895 },
{ 2, 32640, 32831, 32768, 32895 },
{ 3, 32640, 32767, 32768, 32831 },
{ 4, 32384, 34303, 32064, 33535 },
{ 5, 32704, 32767, 32768, 32831 },
{ 6, 32704, 32767, 32768, 32831 },
{ 7, 32704, 32831, 32704, 32831 },
{ 8, 32704, 32831, 32704, 32831 },
{ 9, 32704, 32831, 32704, 32831 },
{ 10, 32704, 32831, 32704, 32831 },
{ 11, 32704, 32831, 32704, 32831 },
{ 12, 32704, 32831, 32704, 32831 },
{ 13, 32704, 32831, 32704, 32831 },
{ 14, 32512, 33023, 32768, 32831 },
{ 15, 32704, 32767, 32768, 32831 },
{ 16, 32704, 32767, 32768, 32831 },
{ 17, 32704, 32767, 32768, 32831 },
{ 18, 32704, 32767, 32768, 32831 },
{ 19, 32704, 32831, 32704, 32831 },
{ 20, 32704, 32831, 32704, 32831 },
{ 21, 32704, 32831, 32704, 32831 },
{ 22, 32704, 32831, 32704, 32831 },
{ 23, 32704, 32831, 32704, 32831 },
{ 24, 32704, 32831, 32704, 32831 },
{ 25, 32704, 32831, 32704, 32831 },
{ 26, 32704, 32831, 32704, 32831 },
{ 27, 32704, 32831, 32704, 32831 },
{ 28, 32704, 32831, 32704, 32831 },
{ 29, 32704, 32767, 32768, 32831 },
{ 30, 32704, 32831, 32704, 32831 },
{ 31, 32704, 32831, 32704, 32831 },
{ 32, 32640, 32767, 32768, 32895 },
{ 33, 32640, 32767, 32768, 32895 },
{ 34, 32704, 32767, 32768, 32831 },
{ 35, 32640, 32767, 32768, 32895 },
{ 36, 32640, 32767, 32768, 32895 },
{ 37, 32640, 32767, 32768, 32895 },
{ 38, 32704, 32767, 32768, 32831 },
{ 39, 32704, 32767, 32768, 32831 },
{ 40, 32704, 32767, 32768, 32831 },
{ 41, 32704, 32767, 32768, 32831 },
{ 43, 32704, 32831, 32704, 32831 },
{ 44, 32704, 32831, 32704, 32831 },
{ 45, 32704, 32831, 32704, 32831 },
{ 46, 32704, 32831, 32704, 32831 },
{ 47, 32704, 32831, 32704, 32831 },
{ 48, 32704, 32831, 32704, 32831 },
{ 49, 32704, 32831, 32704, 32831 },
{ 50, 32704, 32831, 32704, 32831 },
{ 51, 32640, 32831, 32704, 32895 },
{ 52, 32640, 32767, 32768, 32895 },
{ 53, 32704, 32831, 32704, 32831 },
{ 54, 32704, 32831, 32704, 32831 },
{ 55, 32704, 32767, 32704, 32895 },
{ 56, 32704, 32831, 32704, 32831 },
{ 57, 32576, 33023, 32512, 32959 },
{ 58, 32512, 32831, 32704, 33023 },
{ 59, 32640, 32767, 32768, 32895 },
{ 60, 32640, 32767, 32768, 32895 },
{ 61, 32640, 32767, 32768, 32895 },
{ 62, 32640, 32767, 32768, 32895 },
{ 63, 32576, 32895, 32640, 32959 },
{ 64, 32512, 32639, 32768, 32895 },
{ 65, 32704, 32831, 32768, 32895 },
{ 66, 32704, 32895, 32768, 32959 },
{ 67, 32640, 32831, 32704, 32895 },
{ 68, 32576, 33023, 32512, 32959 },
{ 69, 32512, 32831, 32704, 33023 },
{ 70, 32576, 33023, 32640, 33087 },
{ 72, 32704, 32831, 32768, 32895 },
{ 73, 32704, 32831, 32768, 32895 },
{ 74, 32704, 32831, 32832, 32959 },
{ 75, 32704, 32831, 32768, 32959 },
{ 76, 32704, 32831, 32768, 32895 },
{ 77, 32704, 32831, 32768, 32895 },
{ 78, 32832, 32959, 32704, 32831 },
{ 79, 32704, 32831, 32768, 32895 },
{ 80, 32704, 32831, 32768, 32895 },
{ 81, 32704, 32831, 32768, 32895 },
{ 82, 32640, 32767, 32768, 32895 },
{ 83, 32704, 32767, 32768, 32831 },
{ 84, 32704, 32767, 32768, 32831 },
{ 85, 32576, 32767, 32704, 32895 },
{ 86, 32768, 32959, 32704, 32895 },
{ 87, 32704, 32767, 32768, 32831 },
{ 88, 33472, 33535, 32704, 32767 },
{ 89, 32640, 32767, 32832, 32959 },
{ 90, 32640, 32767, 32832, 32959 },
{ 91, 32640, 32767, 32832, 32959 },
{ 92, 32640, 32767, 32832, 32959 },
{ 93, 32640, 32767, 32832, 32959 },
{ 94, 32640, 32767, 32832, 32959 },
{ 95, 32640, 32767, 32832, 32959 },
{ 96, 32640, 32767, 32832, 32959 },
{ 97, 32640, 32767, 32832, 32959 },
{ 98, 32640, 32767, 32832, 32959 },
{ 99, 32704, 32767, 32768, 32831 },
{ 101, 32704, 32895, 32704, 32895 },
{ 102, 32704, 32895, 32704, 32895 },
{ 103, 32704, 32895, 32704, 32895 },
{ 104, 32576, 32767, 32768, 32959 },
{ 105, 32576, 32767, 32768, 32959 },
{ 106, 33728, 33855, 32832, 32895 },
{ 107, 32576, 32767, 32768, 32959 },
{ 108, 32576, 32767, 32768, 32959 },
{ 109, 32576, 32767, 32768, 32959 },
{ 110, 32704, 32895, 32704, 32895 },
{ 111, 32576, 32767, 32768, 32959 },
{ 112, 32704, 32895, 32704, 32895 },
{ 113, 32704, 32895, 32704, 32895 },
{ 114, 32576, 32767, 32768, 32959 },
{ 115, 32576, 32767, 32768, 32959 },
{ 116, 32704, 32831, 32832, 32895 },
{ 117, 32576, 32767, 32768, 32959 },
{ 118, 32576, 32767, 32768, 32959 },
{ 119, 32576, 32767, 32768, 32959 },
{ 120, 32704, 32895, 32704, 32895 },
{ 121, 32576, 32767, 32768, 32959 },
{ 122, 32704, 32895, 32704, 32895 },
{ 123, 32704, 32895, 32704, 32895 },
{ 124, 32576, 32767, 32768, 32959 },
{ 125, 32576, 32767, 32768, 32959 },
{ 126, 32704, 32831, 32832, 32895 },
{ 127, 32576, 32767, 32768, 32959 },
{ 128, 32576, 32767, 32768, 32959 },
{ 129, 32576, 32767, 32768, 32959 },
{ 130, 32704, 32895, 32704, 32895 },
{ 131, 32576, 32767, 32768, 32959 },
{ 132, 32704, 32895, 32704, 32895 },
{ 133, 32704, 32895, 32704, 32895 },
{ 134, 32576, 32767, 32768, 32959 },
{ 135, 32576, 32767, 32768, 32959 },
{ 136, 32704, 32831, 32832, 32895 },
{ 137, 32576, 32767, 32768, 32959 },
{ 138, 32576, 32767, 32768, 32959 },
{ 139, 32576, 32767, 32768, 32959 },
{ 140, 32704, 32895, 32704, 32895 },
{ 141, 32576, 32767, 32768, 32959 },
{ 142, 32704, 32895, 32704, 32895 },
{ 143, 32704, 32895, 32704, 32895 },
{ 144, 32576, 32767, 32768, 32959 },
{ 145, 32576, 32767, 32768, 32959 },
{ 146, 32704, 32831, 32832, 32895 },
{ 147, 32576, 32767, 32768, 32959 },
{ 148, 32576, 32767, 32768, 32959 },
{ 149, 32576, 32767, 32768, 32959 },
{ 150, 32704, 32895, 32704, 32895 },
{ 151, 32576, 32767, 32768, 32959 },
{ 152, 32576, 32767, 32768, 32959 },
{ 153, 32576, 32767, 32768, 32959 },
{ 154, 32704, 32895, 32704, 32895 },
{ 155, 32704, 32895, 32704, 32895 },
{ 156, 32704, 32831, 32768, 32831 },
{ 157, 32576, 32767, 32768, 32959 },
{ 158, 32576, 32767, 32768, 32959 },
{ 159, 32576, 32767, 32768, 32959 },
{ 160, 32576, 32767, 32768, 32959 },
{ 161, 32576, 32767, 32768, 32959 },
{ 162, 32576, 32767, 32768, 32959 },
{ 163, 32576, 32767, 32768, 32959 },
{ 164, 32704, 32895, 32704, 32895 },
{ 165, 32704, 32895, 32704, 32895 },
{ 166, 32704, 32831, 32768, 32831 },
{ 167, 32576, 32767, 32768, 32959 },
{ 168, 32576, 32767, 32768, 32959 },
{ 169, 32576, 32767, 32768, 32959 },
{ 170, 32576, 32767, 32768, 32959 },
{ 171, 32576, 32767, 32768, 32959 },
{ 172, 32576, 32767, 32768, 32959 },
{ 173, 32576, 32767, 32768, 32959 },
{ 174, 32704, 32895, 32704, 32895 },
{ 175, 32704, 32895, 32704, 32895 },
{ 176, 32704, 32831, 32768, 32831 },
{ 177, 32576, 32767, 32768, 32959 },
{ 178, 32576, 32767, 32768, 32959 },
{ 179, 32576, 32767, 32768, 32959 },
{ 180, 32576, 32767, 32768, 32959 },
{ 181, 32576, 32767, 32768, 32959 },
{ 182, 32576, 32767, 32768, 32959 },
{ 183, 32576, 32767, 32768, 32959 },
{ 184, 32704, 32895, 32704, 32895 },
{ 185, 32704, 32895, 32704, 32895 },
{ 186, 32704, 32831, 32768, 32831 },
{ 187, 32576, 32767, 32768, 32959 },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -