package com.test.adrenalin;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main {
static class Skill {
Skill(int id, String name, int range) {
this.id = id;
this.name = name;
this.range = range;
}
int id;
String name;
int range;
}
static class Item {
Item(int id, String name) {
this.id = id;
this.name = name;
}
int id;
String name;
}
static class NPC {
NPC(int id, String name, int type) {
this.id = id;
this.name = name;
this.type = type;
}
int id;
String name;
int type; /* 1 - NPC , 2 - SUM, 3 - PET */
}
public static String path = "/Users/macbookpro/temp/ItemName-ru/";
public static String fileSkills = "SkillName-ru.txt";
public static String fileItems = "ItemName-ru.txt";
public static String fileNPC = "NpcName-ru.txt";
public static Map<Integer, Skill> skills = new HashMap<Integer, Skill>();
public static Map<Integer, Item> items = new HashMap<Integer, Item>();
public static Map<Integer, NPC> npc = new HashMap<Integer, NPC>();
public static void loadSkills() {
List<String> result = Utils.openAndReadFile(path + fileSkills);
int i = -1;
for (String line : result) {
i++;
if (i == 0) {
continue;
}
String[] fields = line.split("\t", -1);
if (fields.length < 4) {
System.out.print("Filed: " + line + "\n Params size < 4");
continue;
}
int id = 0;
try {
id = Integer.valueOf(fields[0]);
} catch (NumberFormatException e) {
System.out.print("Filed: " + line + "\n Not contain INT value at " + fields[0]);
}
if (skills.containsKey(id)) {
continue;
} else {
String name = fields[2];
name = name.replace("u,", "");
name = name.substring(0, name.length() - 2);
skills.put(id, new Skill(id, name, 70));
}
}
System.out.print("Parse " + skills.size() + " skills");
}
public static void loadItems() {
List<String> result = Utils.openAndReadFile(path + fileItems);
int i = -1;
for (String line : result) {
i++;
if (i == 0) {
continue;
}
String[] fields = line.split("\t", -1);
if (fields.length < 4) {
System.out.print("Filed: " + line + "\n Params size < 4");
continue;
}
int id = 0;
try {
id = Integer.valueOf(fields[0]);
} catch (NumberFormatException e) {
System.out.print("Filed: " + line + "\n Not contain INT value at " + fields[0]);
}
if (items.containsKey(id)) {
continue;
} else {
String name = fields[1];
items.put(id, new Item(id, name));
}
}
System.out.print("Parse " + items.size() + " items");
}
public static void loadNPC() {
List<String> result = Utils.openAndReadFile(path + fileNPC);
int i = -1;
for (String line : result) {
i++;
if (i == 0) {
continue;
}
String[] fields = line.split("\t", -1);
if (fields.length < 4) {
System.out.print("Filed: " + line + "\n Params size < 4");
continue;
}
int id = 0;
try {
id = Integer.valueOf(fields[0]);
} catch (NumberFormatException e) {
System.out.print("Filed: " + line + "\n Not contain INT value at " + fields[0]);
}
if (npc.containsKey(id)) {
continue;
} else {
String name = fields[1];
name = name.replace("u,", "");
name = name.substring(0, name.length() - 2);
npc.put(id, new NPC(id, name, 0));
}
}
System.out.print("Parse " + items.size() + " items");
}
public static void main(String[] args) {
loadSkills();
loadItems();
loadNPC();
System.out.print("End");
try {
PrintWriter writer = new PrintWriter(path + "L2DB_wog.txt", "windows-1251");
writer.println("[ITEMS]");
for (Integer key : items.keySet())
{
writer.println(Integer.toString(key) + "=" +items.get(key).name);
}
writer.println("[NPCS]");
for (Integer key : npc.keySet())
{
writer.println(Integer.toString(key) + "=" +npc.get(key).name + "|" + npc.get(key).type);
}
writer.println("[SKILLS]");
for (Integer key : skills.keySet())
{
writer.println(Integer.toString(key) + "=" +skills.get(key).name + "|" + skills.get(key).range);
}
writer.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}