Created
November 5, 2014 00:01
-
-
Save adraffy/0a1a27e23ad48c0a80bb to your computer and use it in GitHub Desktop.
Example of How to dump Items to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wktest; | |
import com.antistupid.warbase.data.ArmorCurve; | |
import com.antistupid.warbase.ids.ItemClass; | |
import com.antistupid.warbase.types.ArmorT; | |
import com.antistupid.warbase.types.ClassT; | |
import com.antistupid.warbase.types.EquipT; | |
import com.antistupid.warbase.types.QualityT; | |
import com.antistupid.warbase.types.RaceT; | |
import com.antistupid.warkit.WarKit; | |
import com.antistupid.warkit.items.Armor; | |
import com.antistupid.warkit.items.Gem; | |
import com.antistupid.warkit.items.Item; | |
import com.antistupid.warkit.items.SetBonus; | |
import com.antistupid.warkit.items.Weapon; | |
import com.antistupid.warkit.items.Wearable; | |
import java.io.BufferedWriter; | |
import java.io.IOException; | |
import java.io.UncheckedIOException; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.stream.Collectors; | |
import org.json.simple.JSONArray; | |
import org.json.simple.JSONObject; | |
public class DumpItems { | |
static public void main(String... args) { | |
WarKit wk = WarKit.load(); | |
try (BufferedWriter w = Files.newBufferedWriter(Paths.get("Dump.json"))) { | |
w.append("["); | |
boolean first = true; | |
for (Wearable x: wk.wearableMap.values()) { | |
if (first) { | |
first = false; | |
} else { | |
w.append(","); | |
} | |
w.newLine(); | |
JSONObject row = exportWearable(x); | |
w.append(row.toJSONString()); | |
} | |
for (Gem x: wk.gemMap.values()) { | |
if (first) { | |
first = false; | |
} else { | |
w.append(","); | |
} | |
w.newLine(); | |
JSONObject row = exportGem(x); | |
w.append(row.toJSONString()); | |
} | |
w.append("]"); | |
} catch (IOException err) { | |
throw new UncheckedIOException("Dump Failed", err); | |
} | |
} | |
static JSONObject exportItem(Item item) { | |
JSONObject root = new JSONObject(); | |
root.put("id", item.itemId); | |
root.put("itemLevel", item.itemLevel); | |
root.put("name", item.name); | |
root.put("icon", item.icon); | |
root.put("itemBind", item.bind.id); | |
root.put("quality", item.quality.id); | |
return root; | |
} | |
static JSONObject exportWearable(Wearable wear) { | |
JSONObject root = exportItem(wear); | |
if (wear.nameDesc != null) { | |
root.put("description", wear.nameDesc); | |
} | |
root.put("allowableClasses", ClassT.db.toList(wear.reqClass).stream().map(x -> x.id).collect(Collectors.toCollection(JSONArray::new))); | |
root.put("allowableRaces", RaceT.db.toList(wear.reqRace).stream().map(x -> x.id).collect(Collectors.toCollection(JSONArray::new))); | |
if (wear instanceof Weapon) { | |
root.put("itemClass", ItemClass.WEAPON); | |
Weapon w = (Weapon)wear; | |
JSONObject weapInfo = new JSONObject(); | |
weapInfo.put("weaponSpeed", w.speed / 1000D); | |
} else { | |
root.put("itemClass", ItemClass.ARMOR); | |
Armor a = (Armor)wear; | |
root.put("baseArmor", ArmorCurve.get(a.itemLevel, a.quality, a.type, a.equip)); | |
} | |
if (wear.itemSet != null) { | |
JSONObject setInfo = new JSONObject(); | |
setInfo.put("id", wear.itemSet.id); | |
setInfo.put("name", wear.itemSet.name); | |
JSONArray bonuses = new JSONArray(); | |
for (SetBonus[] v: wear.itemSet.bonuses) { | |
} | |
setInfo.put("bonuses", bonuses); | |
root.put("itemSet", setInfo); | |
} | |
return root; | |
} | |
static JSONObject exportGem(Gem gem) { | |
JSONObject root = exportItem(gem); | |
root.put("itemClass", ItemClass.GEM); | |
root.put("itemSubClass", gem.type.id); | |
JSONObject gemBonus = new JSONObject(); | |
gemBonus.put("name", gem.getStats(100).toString_noBracket(false)); | |
if (gem.reqProf != null) { | |
gemBonus.put("requiredSkillId", gem.reqProf.id); | |
gemBonus.put("requiredSkillRank", gem.reqProfLevel); | |
} | |
JSONObject gemType = new JSONObject(); | |
gemType.put("type", gem.type.name.toUpperCase()); | |
JSONObject gemInfo = new JSONObject(); | |
gemInfo.put("bonus", gemBonus); | |
gemInfo.put("type", gemType); | |
gemInfo.put("minItemLevel", gem.reqItemLevel); | |
if (gem.spellId != 0) { | |
gemInfo.put("spellId", gem.spellId); | |
} | |
root.put("gemInfo", gemInfo); | |
return root; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment