public static StringBuilder getSkillInformation(int skill) { StringBuilder sb = new StringBuilder(); MapleDataProvider prov = MapleDataProviderFactory.getDataProvider("Skill.wz"); MapleData data = prov.getData(String.valueOf(skill / 10000) + ".img"); for (MapleData sub : data.getChildren()) { if (!sub.getName().equals("skill")) { continue; } for (MapleData sub2 : sub.getChildren()) { if (!sub2.getName().equals(String.valueOf(skill))) { continue; } System.out.println(skill / 10000); System.out.println(skill); for (MapleData sub3 : sub2.getChildren()) { if (!sub3.getName().equals("common")) { // continue; } for (MapleData sub4 : sub3.getChildren()) { String tab = ""; String name = sub3.getName() + "." + sub4.getName(); name += ":"; for (int i = 3; i > name.length() / 8; i--) { tab += "\t"; } String info; try { info = MapleDataTool.getString(sub4, "0"); } catch (Exception ex) { if (!exceptions.contains(ex)) { exceptions.add(ex); } continue; } sb.append(name).append(tab); sb.append(info).append("\r\n"); } } } } if (sb.toString().isEmpty()) { sb.append("No results were found.\r\n"); } else { sb.append("\r\n"); sb.append("\r\n"); sb.append("Results:"); sb.append("\r\n"); } return sb; }
/** @author Matze */ public class MapleQuest { private static Map<Integer, MapleQuest> quests = new HashMap<Integer, MapleQuest>(); protected short infoNumber, infoex, id; protected int timeLimit, timeLimit2; protected List<MapleQuestRequirement> startReqs; protected List<MapleQuestRequirement> completeReqs; protected List<MapleQuestAction> startActs; protected List<MapleQuestAction> completeActs; protected List<Integer> relevantMobs; private boolean autoStart; private boolean autoPreComplete; private boolean repeatable = false; private static final MapleDataProvider questData = MapleDataProviderFactory.getDataProvider( new File(System.getProperty("wzpath") + "/Quest.wz")); private static MapleData actions = questData.getData("Act.img"); private static MapleData requirements = questData.getData("Check.img"); private static MapleData info = questData.getData("QuestInfo.img"); private MapleQuest(int id) { this.id = (short) id; relevantMobs = new LinkedList<Integer>(); MapleData startReqData = requirements.getChildByPath(String.valueOf(id)).getChildByPath("0"); startReqs = new LinkedList<MapleQuestRequirement>(); if (startReqData != null) { for (MapleData startReq : startReqData.getChildren()) { MapleQuestRequirementType type = MapleQuestRequirementType.getByWZName(startReq.getName()); if (type.equals(MapleQuestRequirementType.INTERVAL)) { repeatable = true; } MapleQuestRequirement req = new MapleQuestRequirement(this, type, startReq); if (req.getType().equals(MapleQuestRequirementType.MOB)) { for (MapleData mob : startReq.getChildren()) { relevantMobs.add(MapleDataTool.getInt(mob.getChildByPath("id"))); } } startReqs.add(req); } } MapleData completeReqData = requirements.getChildByPath(String.valueOf(id)).getChildByPath("1"); completeReqs = new LinkedList<MapleQuestRequirement>(); if (completeReqData != null) { for (MapleData completeReq : completeReqData.getChildren()) { MapleQuestRequirement req = new MapleQuestRequirement( this, MapleQuestRequirementType.getByWZName(completeReq.getName()), completeReq); if (req.getType().equals(MapleQuestRequirementType.INFO_NUMBER)) infoNumber = (short) MapleDataTool.getInt(completeReq, 0); if (req.getType().equals(MapleQuestRequirementType.INFO_EX)) { MapleData zero = completeReq.getChildByPath("0"); if (zero != null) { MapleData value = zero.getChildByPath("value"); if (value != null) infoex = Short.parseShort(MapleDataTool.getString(value, "0")); } } if (req.getType().equals(MapleQuestRequirementType.MOB)) { for (MapleData mob : completeReq.getChildren()) { relevantMobs.add(MapleDataTool.getInt(mob.getChildByPath("id"))); } Collections.sort(relevantMobs); } completeReqs.add(req); } } MapleData startActData = actions.getChildByPath(String.valueOf(id)).getChildByPath("0"); startActs = new LinkedList<MapleQuestAction>(); if (startActData != null) { for (MapleData startAct : startActData.getChildren()) { MapleQuestActionType questActionType = MapleQuestActionType.getByWZName(startAct.getName()); startActs.add(new MapleQuestAction(questActionType, startAct, this)); } } MapleData completeActData = actions.getChildByPath(String.valueOf(id)).getChildByPath("1"); completeActs = new LinkedList<MapleQuestAction>(); if (completeActData != null) { for (MapleData completeAct : completeActData.getChildren()) { completeActs.add( new MapleQuestAction( MapleQuestActionType.getByWZName(completeAct.getName()), completeAct, this)); } } MapleData questInfo = info.getChildByPath(String.valueOf(id)); timeLimit = MapleDataTool.getInt("timeLimit", questInfo, 0); timeLimit2 = MapleDataTool.getInt("timeLimit2", questInfo, 0); autoStart = MapleDataTool.getInt("autoStart", questInfo, 0) == 1; autoPreComplete = MapleDataTool.getInt("autoPreComplete", questInfo, 0) == 1; } public static MapleQuest getInstance(int id) { MapleQuest ret = quests.get(id); if (ret == null) { ret = new MapleQuest(id); quests.put(id, ret); } return ret; } private boolean canStart(MapleCharacter c, int npcid) { if (c.getQuest(this).getStatus() != Status.NOT_STARTED && !(c.getQuest(this).getStatus() == Status.COMPLETED && repeatable)) { return false; } for (MapleQuestRequirement r : startReqs) { if (!r.check(c, npcid)) { return false; } } return true; } public boolean canComplete(MapleCharacter c, Integer npcid) { if (!c.getQuest(this).getStatus().equals(Status.STARTED)) { return false; } for (MapleQuestRequirement r : completeReqs) { if (!r.check(c, npcid)) { return false; } } return true; } public void start(MapleCharacter c, int npc) { if ((autoStart || checkNPCOnMap(c, npc)) && canStart(c, npc)) { for (MapleQuestAction a : startActs) { a.run(c, null); } forceStart(c, npc); } } public void complete(MapleCharacter c, int npc) { complete(c, npc, null); } public void complete(MapleCharacter c, int npc, Integer selection) { if ((autoPreComplete || checkNPCOnMap(c, npc)) && canComplete(c, npc)) { /*for (MapleQuestAction a : completeActs) { if (!a.check(c)) { return; } } */ forceComplete(c, npc); for (MapleQuestAction a : completeActs) { a.run(c, selection); } } } public void reset(MapleCharacter c) { c.updateQuest(new MapleQuestStatus(this, MapleQuestStatus.Status.NOT_STARTED)); } public void forfeit(MapleCharacter c) { if (!c.getQuest(this).getStatus().equals(Status.STARTED)) { return; } if (timeLimit > 0) { c.announce(MaplePacketCreator.removeQuestTimeLimit(id)); } MapleQuestStatus newStatus = new MapleQuestStatus(this, MapleQuestStatus.Status.NOT_STARTED); newStatus.setForfeited(c.getQuest(this).getForfeited() + 1); c.updateQuest(newStatus); } public void forceStart(MapleCharacter c, int npc) { MapleQuestStatus newStatus = new MapleQuestStatus(this, MapleQuestStatus.Status.STARTED, npc); newStatus.setForfeited(c.getQuest(this).getForfeited()); if (timeLimit > 0) c.questTimeLimit(this, 30000); // timeLimit * 1000 if (timeLimit2 > 0) { // =\ } c.updateQuest(newStatus); } public void forceComplete(MapleCharacter c, int npc) { MapleQuestStatus newStatus = new MapleQuestStatus(this, MapleQuestStatus.Status.COMPLETED, npc); newStatus.setForfeited(c.getQuest(this).getForfeited()); newStatus.setCompletionTime(System.currentTimeMillis()); c.announce(MaplePacketCreator.showSpecialEffect(9)); c.getMap().broadcastMessage(c, MaplePacketCreator.showForeignEffect(c.getId(), 9), false); c.updateQuest(newStatus); } public short getId() { return id; } public List<Integer> getRelevantMobs() { return relevantMobs; } private boolean checkNPCOnMap(MapleCharacter player, int npcid) { return player.getMap().containsNPC(npcid); } public int getItemAmountNeeded(int itemid) { MapleData data = requirements.getChildByPath(String.valueOf(id)).getChildByPath("1"); if (data != null) { for (MapleData req : data.getChildren()) { MapleQuestRequirementType type = MapleQuestRequirementType.getByWZName(req.getName()); if (!type.equals(MapleQuestRequirementType.ITEM)) continue; for (MapleData d : req.getChildren()) { if (MapleDataTool.getInt(d.getChildByPath("id"), 0) == itemid) return MapleDataTool.getInt(d.getChildByPath("count"), 0); } } } return 0; } public int getMobAmountNeeded(int mid) { MapleData data = requirements.getChildByPath(String.valueOf(id)).getChildByPath("1"); if (data != null) { for (MapleData req : data.getChildren()) { MapleQuestRequirementType type = MapleQuestRequirementType.getByWZName(req.getName()); if (!type.equals(MapleQuestRequirementType.MOB)) continue; for (MapleData d : req.getChildren()) { if (MapleDataTool.getInt(d.getChildByPath("id"), 0) == mid) return MapleDataTool.getInt(d.getChildByPath("count"), 0); } } } return 0; } public short getInfoNumber() { return infoNumber; } public short getInfoEx() { return infoex; } public int getTimeLimit() { return timeLimit; } }
public static void dumpSkills() { StringBuilder sb = new StringBuilder(); MapleDataProvider prov = MapleDataProviderFactory.getDataProvider("Skill.wz"); MapleDataDirectoryEntry root = prov.getRoot(); start = System.currentTimeMillis(); for (MapleDataFileEntry data : root.getFiles()) { if (data.getName().length() > 8) { continue; } System.out.println("Exporting job " + data.getName().replaceAll(".img", "")); for (MapleData sub : prov.getData(data.getName())) { if (!sub.getName().equals("skill")) { continue; } for (MapleData sub2 : sub.getChildren()) { for (MapleData sub3 : sub2.getChildren()) { boolean found = false; for (String s : opt) { if (s.equals(sub3.getName())) { found = true; } } if (!found) { System.out.println("New information type found: " + sub3.getName()); } for (MapleData sub4 : sub3.getChildren()) { String tab = ""; String name = sub3.getName() + "/" + sub4.getName(); name += ":"; for (int i = 4; i > name.length() / 8; i--) { tab += "\t"; } String info = ""; try { if (sub4.getData() instanceof String || sub4.getData() instanceof Integer) { info = MapleDataTool.getString(sub4, "0"); for (char c : info.toCharArray()) { if (Character.isAlphabetic(c) && name.contains("common")) { if (!b.contains(c)) { a.add(new Pair<>(Integer.parseInt(sub2.getName()), c)); b.add(c); } } } } else if (sub4.getData() instanceof Point) { info = MapleDataTool.getPoint(sub4).toString(); } else if (sub4.getData() instanceof MapleCanvas) { // info = MapleDataTool.getImage(sub4).toString(); info = "image"; } } catch (NumberFormatException ex) { System.out.println("0"); if (!exceptions.contains(ex)) { exceptions.add(ex); } continue; } if (!info.isEmpty()) { sb.append(name).append(tab); sb.append(info).append("\r\n"); } } } if (!sb.toString().isEmpty()) { try { if (saveSkillFile(Integer.parseInt(sub2.getName()), sb)) { saveReadme(); } } catch (NumberFormatException ex) { if (!exceptions.contains(ex)) { exceptions.add(ex); } System.out.println("Failed to get information of " + sub2.getName()); } sb = new StringBuilder(); } } } } end = System.currentTimeMillis(); long total = end - start; long minutes = (total / (60 * 1000)); long seconds = (total % (60 * 1000) / 1000); long milliseconds = (total % 1000); System.out.println( "Total time: " + minutes + " minute(s), " + seconds + " second(s), " + milliseconds + " millisecond(s)."); }