use of org.apache.poi.xssf.usermodel.XSSFRow in project ImmunogeneticDataTools by nmdp-bioinformatics.
the class DetectedFindingsWriter method reportDetectedFindings.
/**
* @param linkagesFound
* @throws IOException
* @throws SecurityException
*/
public synchronized void reportDetectedFindings(DetectedLinkageFindings findings) {
XSSFRow row = spreadsheet.createRow(rowId++);
int cellId = 0;
XSSFCell cell = row.createCell(cellId++);
cell.setCellValue(findings.getGLId());
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_A));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_B));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_C));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_DRB1));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_DRB345));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getAlleleCount(Locus.HLA_DQB1));
for (Linkages linkage : LinkagesLoader.getInstance().getLinkages()) {
cell = row.createCell(cellId++);
cell.setCellValue(findings.getLinkageCount(linkage.getLoci()));
cell = row.createCell(cellId++);
cell.setCellValue(findings.getMinimumDifference(linkage.getLoci()) + "");
}
String detectedFindings = formatDetectedFindings(findings);
printWriter.write(detectedFindings);
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project mots by motech-implementations.
the class LocationImporter method parseChiefdoms.
private void parseChiefdoms(XSSFSheet sheet) {
XSSFRow row;
XSSFCell cell;
Iterator rows = sheet.rowIterator();
HashSet<Chiefdom> newChiefdomSet = new HashSet<>();
while (rows.hasNext()) {
row = (XSSFRow) rows.next();
cell = row.getCell(CHIEFDOM_COL_NUMBER);
if (cell == null) {
continue;
}
String cellText = cell.getStringCellValue();
if (cellText.equals(CHIEFDOM_HEADER) || StringUtils.isEmpty(cellText)) {
continue;
}
Chiefdom chiefdom = new Chiefdom(cellText);
String parentName = row.getCell(DISTRICT_COL_NUMBER).getStringCellValue();
District parent = currentDistrictList.stream().filter(district -> district.getName().equals(parentName)).findFirst().orElseThrow(() -> new RuntimeException(String.format("'%s' Chiefdom parent " + "is not defined properly in spreadsheet", chiefdom.getName())));
chiefdom.setDistrict(parent);
newChiefdomSet.add(chiefdom);
}
newChiefdomSet.forEach(newChiefdom -> {
if (!currentChiefdomList.contains(newChiefdom)) {
locationService.createChiefdom(newChiefdom);
}
});
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project dom5utils by larzm42.
the class MercenaryStatIndexer method run.
public static void run() {
FileInputStream stream = null;
List<Mercenary> mercenaryList = new ArrayList<Mercenary>();
try {
long startIndex = Starts.MERCENARY;
int ch;
stream = new FileInputStream(EXE_NAME);
stream.skip(startIndex);
// name
InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
Reader in = new BufferedReader(isr);
int rowNumber = 1;
while ((ch = in.read()) > -1) {
StringBuffer name = new StringBuffer();
while (ch != 0) {
name.append((char) ch);
ch = in.read();
}
if (name.length() == 0) {
continue;
}
if (name.toString().equals("end")) {
break;
}
in.close();
Mercenary merc = new Mercenary();
merc.parameters = new HashMap<String, Object>();
merc.parameters.put("id", rowNumber);
merc.parameters.put("name", name.toString());
merc.parameters.put("bossname", getString(startIndex + 36l));
merc.parameters.put("com", getBytes2(startIndex + 74));
merc.parameters.put("unit", getBytes2(startIndex + 78));
merc.parameters.put("nrunits", getBytes2(startIndex + 82));
merc.parameters.put("minmen", getBytes2(startIndex + 86));
merc.parameters.put("minpay", getBytes2(startIndex + 90));
merc.parameters.put("xp", getBytes2(startIndex + 94));
merc.parameters.put("randequip", getBytes2(startIndex + 158));
merc.parameters.put("recrate", getBytes2(startIndex + 306));
merc.parameters.put("item1", getString(startIndex + 162l));
merc.parameters.put("item2", getString(startIndex + 198l));
merc.parameters.put("eramask", getBytes1(startIndex - 2));
merc.parameters.put("level", getBytes1(startIndex - 1));
mercenaryList.add(merc);
stream = new FileInputStream(EXE_NAME);
startIndex = startIndex + 312l;
stream.skip(startIndex);
isr = new InputStreamReader(stream, "ISO-8859-1");
in = new BufferedReader(isr);
rowNumber++;
}
in.close();
stream.close();
XSSFWorkbook wb = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("Mercenary.xlsx");
XSSFSheet sheet = wb.createSheet();
int rowNum = 0;
for (Mercenary merc : mercenaryList) {
// Mercenary
if (rowNum == 0) {
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < mercenary_columns.length; i++) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(mercenary_columns[i]);
}
rowNum++;
}
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < mercenary_columns.length; i++) {
Object object = merc.parameters.get(mercenary_columns[i]);
if (object != null) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
}
}
rowNum++;
}
wb.write(fos);
fos.close();
wb.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project dom5utils by larzm42.
the class MonsterStatIndexer method run.
public static void run() {
FileInputStream stream = null;
List<Monster> monsterList = new ArrayList<Monster>();
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("monsters.txt"));
BufferedWriter writerUnknown = new BufferedWriter(new FileWriter("monstersUnknown.txt"));
long startIndex = Starts.MONSTER;
int ch;
stream = new FileInputStream(EXE_NAME);
stream.skip(Starts.MONSTER_MAGIC);
Set<String> unknown = new TreeSet<String>();
// magic
byte[] c = new byte[4];
while ((stream.read(c, 0, 4)) != -1) {
String high = String.format("%02X", c[1]);
String low = String.format("%02X", c[0]);
if ((high + low).equals("FFFF")) {
break;
}
int id = Integer.decode("0X" + high + low);
Magic monMagic = monsterMagic.get(id);
if (monMagic == null) {
monMagic = new Magic();
monsterMagic.put(id, monMagic);
}
stream.read(c, 0, 4);
high = String.format("%02X", c[1]);
low = String.format("%02X", c[0]);
int path = Integer.decode("0X" + high + low);
stream.read(c, 0, 4);
high = String.format("%02X", c[1]);
low = String.format("%02X", c[0]);
int value = Integer.decode("0X" + high + low);
switch(path) {
case 0:
monMagic.F = value;
break;
case 1:
monMagic.A = value;
break;
case 2:
monMagic.W = value;
break;
case 3:
monMagic.E = value;
break;
case 4:
monMagic.S = value;
break;
case 5:
monMagic.D = value;
break;
case 6:
monMagic.N = value;
break;
case 7:
monMagic.B = value;
break;
case 8:
monMagic.H = value;
break;
default:
RandomMagic monRandomMagic = null;
List<RandomMagic> randomMagicList = monMagic.rand;
if (randomMagicList == null) {
randomMagicList = new ArrayList<RandomMagic>();
monRandomMagic = new RandomMagic();
if (path == 50) {
monRandomMagic.mask = 32640;
monRandomMagic.nbr = 1;
monRandomMagic.link = value;
monRandomMagic.rand = 100;
} else if (path == 51) {
monRandomMagic.mask = 1920;
monRandomMagic.nbr = 1;
monRandomMagic.link = value;
monRandomMagic.rand = 100;
} else {
monRandomMagic.mask = path;
monRandomMagic.nbr = 1;
if (value > 100) {
monRandomMagic.link = value / 100;
monRandomMagic.rand = 100;
} else {
monRandomMagic.link = 1;
monRandomMagic.rand = value;
}
}
randomMagicList.add(monRandomMagic);
monMagic.rand = randomMagicList;
} else {
boolean found = false;
for (RandomMagic ranMagic : randomMagicList) {
if (ranMagic.mask == path && ranMagic.rand == value) {
ranMagic.nbr++;
found = true;
}
if (ranMagic.mask == 32640 && path == 50 && ranMagic.link == value) {
ranMagic.nbr++;
found = true;
}
if (ranMagic.mask == 1920 && path == 51 && ranMagic.link == value) {
ranMagic.nbr++;
found = true;
}
}
if (!found) {
monRandomMagic = new RandomMagic();
if (path == 50) {
monRandomMagic.mask = 32640;
monRandomMagic.nbr = 1;
monRandomMagic.link = value;
monRandomMagic.rand = 100;
} else if (path == 51) {
monRandomMagic.mask = 1920;
monRandomMagic.nbr = 1;
monRandomMagic.link = value;
monRandomMagic.rand = 100;
} else {
monRandomMagic.mask = path;
monRandomMagic.nbr = 1;
if (value > 100) {
monRandomMagic.link = value / 100;
monRandomMagic.rand = 100;
} else {
monRandomMagic.link = 1;
monRandomMagic.rand = value;
}
}
randomMagicList.add(monRandomMagic);
}
}
}
}
stream.close();
stream = new FileInputStream(EXE_NAME);
stream.skip(startIndex);
// Name
InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
Reader in = new BufferedReader(isr);
int rowNumber = 1;
while ((ch = in.read()) > -1) {
StringBuffer name = new StringBuffer();
while (ch != 0) {
name.append((char) ch);
ch = in.read();
}
if (name.length() == 0) {
continue;
}
if (name.toString().equals("end")) {
break;
}
in.close();
Monster monster = new Monster();
monster.parameters = new TreeMap<String, Object>();
monster.parameters.put("id", rowNumber);
monster.parameters.put("name", name.toString());
monster.parameters.put("ap", getBytes2(startIndex + 40));
monster.parameters.put("mapmove", getBytes2(startIndex + 42));
monster.parameters.put("size", getBytes2(startIndex + 44));
monster.parameters.put("ressize", getBytes2(startIndex + 44));
monster.parameters.put("hp", getBytes2(startIndex + 46));
monster.parameters.put("prot", getBytes2(startIndex + 48));
monster.parameters.put("str", getBytes2(startIndex + 50));
monster.parameters.put("enc", getBytes2(startIndex + 52));
monster.parameters.put("prec", getBytes2(startIndex + 54));
monster.parameters.put("att", getBytes2(startIndex + 56));
monster.parameters.put("def", getBytes2(startIndex + 58));
monster.parameters.put("mr", getBytes2(startIndex + 60));
monster.parameters.put("mor", getBytes2(startIndex + 62));
monster.parameters.put("wpn1", getBytes2(startIndex + 208) == 0 ? "" : getBytes2(startIndex + 208));
monster.parameters.put("wpn2", getBytes2(startIndex + 210) == 0 ? "" : getBytes2(startIndex + 210));
monster.parameters.put("wpn3", getBytes2(startIndex + 212) == 0 ? "" : getBytes2(startIndex + 212));
monster.parameters.put("wpn4", getBytes2(startIndex + 214) == 0 ? "" : getBytes2(startIndex + 214));
monster.parameters.put("wpn5", getBytes2(startIndex + 216) == 0 ? "" : getBytes2(startIndex + 216));
monster.parameters.put("wpn6", getBytes2(startIndex + 218) == 0 ? "" : getBytes2(startIndex + 218));
monster.parameters.put("wpn7", getBytes2(startIndex + 220) == 0 ? "" : getBytes2(startIndex + 220));
monster.parameters.put("armor1", getBytes2(startIndex + 228) == 0 ? "" : getBytes2(startIndex + 228));
monster.parameters.put("armor2", getBytes2(startIndex + 230) == 0 ? "" : getBytes2(startIndex + 230));
monster.parameters.put("armor3", getBytes2(startIndex + 232) == 0 ? "" : getBytes2(startIndex + 232));
monster.parameters.put("basecost", getBytes2(startIndex + 234));
monster.parameters.put("rcost", getBytes2(startIndex + 236));
monster.parameters.put("rpcost", getBytes2(startIndex + 240));
List<AttributeValue> attributes = getAttributes(startIndex + Starts.MONSTER_ATTRIBUTE_OFFSET, Starts.MONSTER_ATTRIBUTE_GAP);
for (AttributeValue attr : attributes) {
boolean found = false;
for (int x = 0; x < KNOWN_MONSTER_ATTRS.length; x++) {
if (KNOWN_MONSTER_ATTRS[x][0].equals(attr.attribute)) {
found = true;
if (KNOWN_MONSTER_ATTRS[x][1].endsWith("#")) {
int i = 1;
for (String value : attr.values) {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1].replace("#", i + ""), Integer.parseInt(value));
i++;
}
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("startage")) {
int age = Integer.parseInt(attr.values.get(0));
if (age == -1) {
age = 0;
}
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Integer.toString((int) (age + age * .1)));
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("heatrec")) {
int val = Integer.parseInt(attr.values.get(0));
if (val == 10) {
val = 0;
} else {
val = 1;
}
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val));
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("coldrec")) {
int val = Integer.parseInt(attr.values.get(0));
if (val == 10) {
val = 0;
} else {
val = 1;
}
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val));
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("barbs")) {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], "1");
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("corrupt")) {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], "1");
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("ethtrue")) {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], "1");
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("incunrest")) {
double val = Double.parseDouble(attr.values.get(0)) / 10d;
if (val < 1 && val > -1) {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Double.toString(val));
} else {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Integer.toString((int) val));
}
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("petrify")) {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], "1");
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("eyes")) {
int age = Integer.parseInt(attr.values.get(0));
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(age + 2));
} else if (KNOWN_MONSTER_ATTRS[x][0].equals("A400")) {
monster.parameters.put("n_summon", "1");
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0));
} else if (KNOWN_MONSTER_ATTRS[x][0].equals("A500")) {
monster.parameters.put("n_summon", "2");
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0));
} else if (KNOWN_MONSTER_ATTRS[x][0].equals("A600")) {
monster.parameters.put("n_summon", "3");
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0));
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod fire")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "F";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod air")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "A";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod water")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "W";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod earth")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "E";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod astral")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "S";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod death")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "D";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod nature")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "N";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod blood")) {
String gemprod = "";
if (monster.parameters.get("gemprod") != null) {
gemprod = monster.parameters.get("gemprod").toString();
}
gemprod += attr.values.get(0) + "B";
monster.parameters.put("gemprod", gemprod);
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("pathcost")) {
if (monster.parameters.get("startdom") == null) {
monster.parameters.put("startdom", 1);
}
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0));
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("spreadchaos/death")) {
if (attr.values.get(0).equals("100")) {
monster.parameters.put("spreadchaos", 1);
} else if (attr.values.get(0).equals("103")) {
monster.parameters.put("spreaddeath", 1);
}
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("spreadorder/growth")) {
if (attr.values.get(0).equals("100")) {
monster.parameters.put("spreadorder", 1);
} else if (attr.values.get(0).equals("103")) {
monster.parameters.put("spreadgrowth", 1);
}
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("damagerev")) {
int val = Integer.parseInt(attr.values.get(0));
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val - 1));
} else if (KNOWN_MONSTER_ATTRS[x][1].equals("popkill")) {
int val = Integer.parseInt(attr.values.get(0));
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val * 10));
} else {
monster.parameters.put(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0));
}
}
}
if (!found) {
monster.parameters.put("\tUnknown Attribute<" + attr.attribute + ">", attr.values.get(0));
unknown.add(attr.attribute);
}
}
List<String> largeBitmap = largeBitmap(startIndex + 248, values);
for (String bit : largeBitmap) {
monster.parameters.put(bit, 1);
}
if (monster.parameters.containsKey("slow_to_recruit")) {
monster.parameters.put("rt", "2");
} else {
monster.parameters.put("rt", "1");
}
if (largeBitmap.contains("heat")) {
monster.parameters.put("heat", "3");
}
if (largeBitmap.contains("cold")) {
monster.parameters.put("cold", "3");
}
String additionalLeader = "0";
if (monster.parameters.get("additional leadership") != null) {
additionalLeader = monster.parameters.get("additional leadership").toString();
}
monster.parameters.put("leader", 40 + Integer.parseInt(additionalLeader));
if (largeBitmap.contains("noleader")) {
if (!"".equals(additionalLeader)) {
monster.parameters.put("leader", additionalLeader);
} else {
monster.parameters.put("leader", 0);
}
}
if (largeBitmap.contains("poorleader")) {
if (!"".equals(additionalLeader)) {
monster.parameters.put("leader", 10 + Integer.parseInt(additionalLeader));
} else {
monster.parameters.put("leader", 10);
}
}
if (largeBitmap.contains("goodleader")) {
if (!"".equals(additionalLeader)) {
monster.parameters.put("leader", 80 + Integer.parseInt(additionalLeader));
} else {
monster.parameters.put("leader", 80);
}
}
if (largeBitmap.contains("expertleader")) {
if (!"".equals(additionalLeader)) {
monster.parameters.put("leader", 120 + Integer.parseInt(additionalLeader));
} else {
monster.parameters.put("leader", 120);
}
}
if (largeBitmap.contains("superiorleader")) {
if (!"".equals(additionalLeader)) {
monster.parameters.put("leader", 160 + Integer.parseInt(additionalLeader));
} else {
monster.parameters.put("leader", 160);
}
}
if (largeBitmap.contains("poormagicleader")) {
monster.parameters.put("magicleader", 10);
}
if (largeBitmap.contains("okmagicleader")) {
monster.parameters.put("magicleader", 40);
}
if (largeBitmap.contains("goodmagicleader")) {
monster.parameters.put("magicleader", 80);
}
if (largeBitmap.contains("expertmagicleader")) {
monster.parameters.put("magicleader", 120);
}
if (largeBitmap.contains("superiormagicleader")) {
monster.parameters.put("magicleader", 160);
}
if (largeBitmap.contains("poorundeadleader")) {
monster.parameters.put("undeadleader", 10);
}
if (largeBitmap.contains("okundeadleader")) {
monster.parameters.put("undeadleader", 40);
}
if (largeBitmap.contains("goodundeadleader")) {
monster.parameters.put("undeadleader", 80);
}
if (largeBitmap.contains("expertundeadleader")) {
monster.parameters.put("undeadleader", 120);
}
if (largeBitmap.contains("superiorundeadleader")) {
monster.parameters.put("undeadleader", 160);
}
if (largeBitmap.contains("coldres15")) {
String additionalCold = "0";
if (monster.parameters.get("coldres") != null) {
additionalCold = monster.parameters.get("coldres").toString();
}
boolean cold = false;
if (largeBitmap.contains("cold") || monster.parameters.get("cold") != null) {
cold = true;
}
monster.parameters.put("coldres", 15 + Integer.parseInt(additionalCold.equals("") ? "0" : additionalCold) + (cold ? 10 : 0));
} else {
String additionalCold = "0";
if (monster.parameters.get("coldres") != null) {
additionalCold = monster.parameters.get("coldres").toString();
}
boolean cold = false;
if (largeBitmap.contains("cold") || monster.parameters.get("cold") != null) {
cold = true;
}
int coldres = Integer.parseInt(additionalCold.equals("") ? "0" : additionalCold) + (cold ? 10 : 0);
monster.parameters.put("coldres", coldres == 0 ? "" : Integer.toString(coldres));
}
if (largeBitmap.contains("fireres15")) {
String additionalFire = "0";
if (monster.parameters.get("fireres") != null) {
additionalFire = monster.parameters.get("fireres").toString();
}
boolean heat = false;
if (largeBitmap.contains("heat") || monster.parameters.get("heat") != null) {
heat = true;
}
monster.parameters.put("fireres", 15 + Integer.parseInt(additionalFire.equals("") ? "0" : additionalFire) + (heat ? 10 : 0));
} else {
String additionalFire = "0";
if (monster.parameters.get("fireres") != null) {
additionalFire = monster.parameters.get("fireres").toString();
}
boolean heat = false;
if (largeBitmap.contains("heat") || monster.parameters.get("heat") != null) {
heat = true;
}
int fireres = Integer.parseInt(additionalFire.equals("") ? "0" : additionalFire) + (heat ? 10 : 0);
monster.parameters.put("fireres", fireres == 0 ? "" : Integer.toString(fireres));
}
if (largeBitmap.contains("poisonres15")) {
String additionalPoisin = "0";
if (monster.parameters.get("poisonres") != null) {
additionalPoisin = monster.parameters.get("poisonres").toString();
}
boolean poisoncloud = false;
if (largeBitmap.contains("undead") || largeBitmap.contains("inanimate") || monster.parameters.get("poisoncloud") != null) {
poisoncloud = true;
}
monster.parameters.put("poisonres", 15 + Integer.parseInt(additionalPoisin.equals("") ? "0" : additionalPoisin) + (poisoncloud ? 10 : 0));
} else {
String additionalPoison = "0";
if (monster.parameters.get("poisonres") != null) {
additionalPoison = monster.parameters.get("poisonres").toString();
}
boolean poisoncloud = false;
if (largeBitmap.contains("undead") || largeBitmap.contains("inanimate") || monster.parameters.get("poisoncloud") != null) {
poisoncloud = true;
}
int poisonres = Integer.parseInt(additionalPoison.equals("") ? "0" : additionalPoison) + (poisoncloud ? 10 : 0);
monster.parameters.put("poisonres", poisonres == 0 ? "" : Integer.toString(poisonres));
}
if (largeBitmap.contains("shockres15")) {
String additionalShock = "0";
if (monster.parameters.get("shockres") != null) {
additionalShock = monster.parameters.get("shockres").toString();
}
monster.parameters.put("shockres", 15 + Integer.parseInt(additionalShock.equals("") ? "0" : additionalShock));
} else {
String additionalShock = "0";
if (monster.parameters.get("shockres") != null) {
additionalShock = monster.parameters.get("shockres").toString();
}
int shockres = Integer.parseInt(additionalShock.equals("") ? "0" : additionalShock);
monster.parameters.put("shockres", shockres == 0 ? "" : Integer.toString(shockres));
}
if (largeBitmap.contains("stealthy40")) {
String additionalStealth = "0";
if (monster.parameters.get("stealthy") != null) {
additionalStealth = monster.parameters.get("stealthy").toString();
}
boolean glamour = false;
if (monster.parameters.get("illusion") != null) {
glamour = true;
}
monster.parameters.put("stealthy", 40 + Integer.parseInt(additionalStealth.equals("") ? "0" : additionalStealth) + (glamour ? 25 : 0));
} else {
String additionalStealth = "0";
if (monster.parameters.get("stealthy") != null) {
additionalStealth = monster.parameters.get("stealthy").toString();
}
monster.parameters.put("stealthy", additionalStealth == null || additionalStealth.equals("0") ? "" : additionalStealth);
}
// magic
Magic monMagic = monsterMagic.get(rowNumber);
if (monMagic != null) {
monster.parameters.put("F", magicStrip(monMagic.F));
monster.parameters.put("A", magicStrip(monMagic.A));
monster.parameters.put("W", magicStrip(monMagic.W));
monster.parameters.put("E", magicStrip(monMagic.E));
monster.parameters.put("S", magicStrip(monMagic.S));
monster.parameters.put("D", magicStrip(monMagic.D));
monster.parameters.put("N", magicStrip(monMagic.N));
monster.parameters.put("B", magicStrip(monMagic.B));
monster.parameters.put("H", magicStrip(monMagic.H));
if (monMagic.rand != null) {
int count = 1;
for (RandomMagic ranMag : monMagic.rand) {
monster.parameters.put("rand" + count, magicStrip(ranMag.rand));
monster.parameters.put("nbr" + count, magicStrip(ranMag.nbr));
monster.parameters.put("link" + count, magicStrip(ranMag.link));
monster.parameters.put("mask" + count, magicStrip(ranMag.mask));
count++;
}
}
}
if (largeBitmap.contains("misc2")) {
monster.parameters.put("hand", 0);
monster.parameters.put("head", 0);
monster.parameters.put("body", 0);
monster.parameters.put("foot", 0);
monster.parameters.put("misc", 2);
}
if (monster.parameters.containsKey("itemslots")) {
String slots = monster.parameters.get("itemslots").toString();
int numHands = 0;
int numHeads = 0;
int numBody = 0;
int numFoot = 0;
int numMisc = 0;
long val = Long.parseLong(slots);
if ((val & 0x0002) != 0) {
numHands++;
}
if ((val & 0x0004) != 0) {
numHands++;
}
if ((val & 0x0008) != 0) {
numHands++;
}
if ((val & 0x0010) != 0) {
numHands++;
}
if ((val & 0x0080) != 0) {
numHeads++;
}
if ((val & 0x0100) != 0) {
numHeads++;
}
if ((val & 0x0200) != 0) {
numHeads++;
}
if ((val & 0x0400) != 0) {
numBody++;
}
if ((val & 0x0800) != 0) {
numFoot++;
}
if ((val & 0x1000) != 0) {
numMisc++;
}
if ((val & 0x2000) != 0) {
numMisc++;
}
if ((val & 0x4000) != 0) {
numMisc++;
}
if ((val & 0x8000) != 0) {
numMisc++;
}
if ((val & 0x10000) != 0) {
numMisc++;
}
monster.parameters.put("hand", numHands);
monster.parameters.put("head", numHeads);
monster.parameters.put("body", numBody);
monster.parameters.put("foot", numFoot);
monster.parameters.put("misc", numMisc);
} else if (!largeBitmap.contains("misc2")) {
monster.parameters.put("hand", 2);
monster.parameters.put("head", 1);
monster.parameters.put("body", 1);
monster.parameters.put("foot", 1);
monster.parameters.put("misc", 2);
}
if (largeBitmap.contains("mounted")) {
monster.parameters.put("foot", 0);
}
monsterList.add(monster);
stream = new FileInputStream(EXE_NAME);
startIndex = startIndex + Starts.MONSTER_SIZE;
stream.skip(startIndex);
isr = new InputStreamReader(stream, "ISO-8859-1");
in = new BufferedReader(isr);
rowNumber++;
}
in.close();
stream.close();
// fixedname
File heroesFile = new File("heroes.txt");
Set<Integer> heroes = new HashSet<Integer>();
File namesFile = new File("names.txt");
List<String> names = new ArrayList<String>();
FileReader herosFileReader = new FileReader(heroesFile);
FileReader namesFileReader = new FileReader(namesFile);
BufferedReader bufferedReader = new BufferedReader(herosFileReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
heroes.add(Integer.parseInt(line));
}
bufferedReader.close();
bufferedReader = new BufferedReader(namesFileReader);
while ((line = bufferedReader.readLine()) != null) {
names.add(line);
}
bufferedReader.close();
int nameIndex = 0;
for (Monster monster : monsterList) {
Object unique = monster.parameters.get("unique");
int id = (Integer) (monster.parameters.get("id"));
if (id == 621 || id == 980 || id == 981 || id == 994 || id == 995 || id == 996 || id == 997 || id == 1484 || id == 1485 || id == 1486 || id == 1487 || (id >= 2765 && id <= 2781)) {
unique = "0";
}
if (heroes.contains(monster.parameters.get("id")) || (unique != null && unique.equals("1"))) /* || monster.parameters.get("id").equals("641")*/
{
monster.parameters.put("fixedname", names.get(nameIndex++));
}
}
XSSFWorkbook wb = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("BaseU.xlsx");
XSSFSheet sheet = wb.createSheet();
int rowNum = 0;
for (Monster monster : monsterList) {
if (rowNum == 0) {
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < unit_columns.length; i++) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(unit_columns[i]);
}
rowNum++;
}
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < unit_columns.length; i++) {
Object object = monster.parameters.get(unit_columns[i]);
if (object != null) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
}
}
dumpTextFile(monster, writer);
rowNum++;
}
dumpUnknown(unknown, writerUnknown);
writer.close();
writerUnknown.close();
wb.write(fos);
fos.close();
wb.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project dom5utils by larzm42.
the class SiteStatIndexer method run.
public static void run() {
FileInputStream stream = null;
List<Site> siteList = new ArrayList<Site>();
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("sites.txt"));
BufferedWriter writerUnknown = new BufferedWriter(new FileWriter("sitesUnknown.txt"));
long startIndex = Starts.SITE;
int ch;
stream = new FileInputStream(EXE_NAME);
stream.skip(Starts.SITE);
Set<String> unknown = new TreeSet<String>();
// Name
InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1");
Reader in = new BufferedReader(isr);
int rowNumber = 1;
while ((ch = in.read()) > -1) {
StringBuffer name = new StringBuffer();
while (ch != 0) {
name.append((char) ch);
ch = in.read();
}
if (name.length() == 0) {
continue;
}
if (name.toString().equals("end")) {
break;
}
in.close();
Site site = new Site();
site.parameters = new TreeMap<String, Object>();
site.parameters.put("id", rowNumber);
site.parameters.put("name", name.toString());
short rarity = getBytes1(startIndex + 42);
site.parameters.put("rarity", rarity == -1 ? "0" : rarity);
site.parameters.put("loc", getBytes4(startIndex + 208));
site.parameters.put("level", getBytes2(startIndex + 40));
String[] paths = { "Fire", "Air", "Water", "Earth", "Astral", "Death", "Nature", "Blood", "Holy" };
int[] spriteOffset = { 1, 9, 18, 26, 35, 42, 50, 59, 68 };
short path = getBytes1(startIndex + 38);
short sprite = getBytes1(startIndex + 36);
site.parameters.put("path", path == -1 ? "" : paths[path]);
site.parameters.put("sprite", path == -1 ? "" : spriteOffset[path] + sprite);
List<AttributeValue> attributes = getAttributes(startIndex + Starts.SITE_ATTRIBUTE_OFFSET, Starts.SITE_ATTRIBUTE_GAP, 8);
for (AttributeValue attr : attributes) {
boolean found = false;
for (int x = 0; x < KNOWN_SITE_ATTRS.length; x++) {
if (KNOWN_SITE_ATTRS[x][0].equals(attr.attribute)) {
found = true;
if (KNOWN_SITE_ATTRS[x][1].endsWith("#")) {
int i = 1;
for (String value : attr.values) {
site.parameters.put(KNOWN_SITE_ATTRS[x][1].replace("#", i + ""), Integer.parseInt(value));
i++;
}
} else {
switch(KNOWN_SITE_ATTRS[x][1]) {
case ("conj"):
case ("alter"):
case ("evo"):
case ("const"):
case ("ench"):
case ("thau"):
case ("blood"):
case ("heal"):
case ("disease"):
case ("curse"):
case ("horror"):
case ("holyfire"):
case ("holypow"):
case ("voidgate"):
site.parameters.put(KNOWN_SITE_ATTRS[x][1], attr.values.get(0) + "%");
break;
case ("lab"):
site.parameters.put(KNOWN_SITE_ATTRS[x][1], "lab");
break;
case ("unr"):
site.parameters.put(KNOWN_SITE_ATTRS[x][1], -Integer.parseInt(attr.values.get(0)));
break;
default:
site.parameters.put(KNOWN_SITE_ATTRS[x][1], attr.values.get(0));
}
}
}
}
if (!found) {
site.parameters.put("\tUnknown Attribute<" + attr.attribute + ">", attr.values.get(0));
unknown.add(attr.attribute);
}
}
// scales
String[] scales = { "Turmoil", "Sloth", "Cold", "Death", "Misfortune", "Drain" };
String[] opposite = { "Order", "Productivity", "Heat", "Growth", "Luck", "Magic" };
String[] scalesValue = { "", "" };
int index = 0;
if (attributes.contains(new AttributeValue("1F00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("1F00")));
for (String vals : attributeValue.values) {
scalesValue[index++] = opposite[Integer.parseInt(vals)];
}
}
if (attributes.contains(new AttributeValue("2000"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("2000")));
for (String vals : attributeValue.values) {
scalesValue[index++] = scales[Integer.parseInt(vals)];
}
}
site.parameters.put("scale1", scalesValue[0]);
site.parameters.put("scale2", scalesValue[1]);
// rit/ritrng
boolean[] boolPaths = { false, false, false, false, false, false, false, false };
String[] boolPathsStr = { "F", "A", "W", "E", "S", "D", "N", "B" };
String value = "";
if (attributes.contains(new AttributeValue("FA00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FA00")));
value = attributeValue.values.get(0);
boolPaths[0] = true;
}
if (attributes.contains(new AttributeValue("FB00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FB00")));
value = attributeValue.values.get(0);
boolPaths[1] = true;
}
if (attributes.contains(new AttributeValue("FC00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FC00")));
value = attributeValue.values.get(0);
boolPaths[2] = true;
}
if (attributes.contains(new AttributeValue("FD00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FD00")));
value = attributeValue.values.get(0);
boolPaths[3] = true;
}
if (attributes.contains(new AttributeValue("FE00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FE00")));
value = attributeValue.values.get(0);
boolPaths[4] = true;
}
if (attributes.contains(new AttributeValue("FF00"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("FF00")));
value = attributeValue.values.get(0);
boolPaths[5] = true;
}
if (attributes.contains(new AttributeValue("0001"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0001")));
value = attributeValue.values.get(0);
boolPaths[6] = true;
}
if (attributes.contains(new AttributeValue("0101"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0101")));
value = attributeValue.values.get(0);
boolPaths[7] = true;
}
if (attributes.contains(new AttributeValue("0201"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0201")));
value = attributeValue.values.get(0);
boolPaths = new boolean[] { true, true, true, true, false, false, false, false };
}
if (attributes.contains(new AttributeValue("0301"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0301")));
value = attributeValue.values.get(0);
boolPaths = new boolean[] { false, false, false, false, true, true, true, true };
}
if (attributes.contains(new AttributeValue("0401"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("0401")));
value = attributeValue.values.get(0);
boolPaths = new boolean[] { true, true, true, true, true, true, true, true };
}
StringBuffer rit = new StringBuffer();
for (int x = 0; x < boolPaths.length; x++) {
if (boolPaths[x]) {
rit.append(boolPathsStr[x]);
}
}
site.parameters.put("rit", rit.toString());
site.parameters.put("ritrng", value);
// summoning
String sum1 = null;
int sum1count = 0;
String sum2 = null;
int sum2count = 0;
String sum3 = null;
int sum3count = 0;
String sum4 = null;
int sum4count = 0;
if (attributes.contains(new AttributeValue("1200"))) {
AttributeValue attributeValue = attributes.get(attributes.indexOf(new AttributeValue("1200")));
for (String val : attributeValue.values) {
if (sum1 == null || sum1.equals(val)) {
sum1 = val;
sum1count++;
} else if (sum2 == null || sum2.equals(val)) {
sum2 = val;
sum2count++;
} else if (sum3 == null || sum3.equals(val)) {
sum3 = val;
sum3count++;
} else if (sum4 == null || sum4.equals(val)) {
sum4 = val;
sum4count++;
}
}
}
if (sum1 != null) {
site.parameters.put("sum1", sum1);
site.parameters.put("n_sum1", sum1count);
}
if (sum2 != null) {
site.parameters.put("sum2", sum2);
site.parameters.put("n_sum2", sum2count);
}
if (sum3 != null) {
site.parameters.put("sum3", sum3);
site.parameters.put("n_sum3", sum3count);
}
if (sum4 != null) {
site.parameters.put("sum4", sum4);
site.parameters.put("n_sum4", sum4count);
}
siteList.add(site);
stream = new FileInputStream(EXE_NAME);
startIndex = startIndex + Starts.SITE_SIZE;
stream.skip(startIndex);
isr = new InputStreamReader(stream, "ISO-8859-1");
in = new BufferedReader(isr);
rowNumber++;
}
in.close();
stream.close();
XSSFWorkbook wb = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("MagicSites.xlsx");
XSSFSheet sheet = wb.createSheet();
int rowNum = 0;
for (Site site : siteList) {
if (rowNum == 0) {
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < site_columns.length; i++) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(site_columns[i]);
}
rowNum++;
}
XSSFRow row = sheet.createRow(rowNum);
for (int i = 0; i < site_columns.length; i++) {
Object object = site.parameters.get(site_columns[i]);
if (object != null) {
row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
}
}
dumpTextFile(site, writer);
rowNum++;
}
dumpUnknown(unknown, writerUnknown);
writer.close();
writerUnknown.close();
wb.write(fos);
fos.close();
wb.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Aggregations