/* * 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 3 of the License, 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, see . */ package com.l2jserver.gameserver.datatables; import java.io.File; import java.util.HashMap; import java.util.Map; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import com.l2jserver.Config; import com.l2jserver.gameserver.engines.DocumentParser; /** * This class holds the Experience points for each level for players and pets. * @author mrTJO */ public final class ExperienceTable extends DocumentParser { private final Map _expTable = new HashMap<>(); private byte MAX_LEVEL; private byte MAX_PET_LEVEL; private ExperienceTable() { _expTable.clear(); final Document doc = parseFile(new File(Config.DATAPACK_ROOT, "data/stats/experience.xml")); if (doc != null) { parseDocument(doc); } _log.info(getClass().getSimpleName() + ": Loaded " + _expTable.size() + " levels."); _log.info(getClass().getSimpleName() + ": Max Player Level is: " + (MAX_LEVEL - 1)); _log.info(getClass().getSimpleName() + ": Max Pet Level is: " + (MAX_PET_LEVEL - 1)); } @Override protected void parseDocument(Document doc) { final Node table = doc.getFirstChild(); final NamedNodeMap tableAttr = table.getAttributes(); MAX_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxLevel").getNodeValue()) + 1); MAX_PET_LEVEL = (byte) (Byte.parseByte(tableAttr.getNamedItem("maxPetLevel").getNodeValue()) + 1); NamedNodeMap attrs; for (Node n = table.getFirstChild(); n != null; n = n.getNextSibling()) { if ("experience".equals(n.getNodeName())) { attrs = n.getAttributes(); _expTable.put(parseInteger(attrs, "level"), parseLong(attrs, "tolevel")); } } } /** * @param level the level required. * @return the experience points required to reach the given level. */ public long getExpForLevel(int level) { return _expTable.get(level); } /** * @return the maximum level acquirable by a player. */ public byte getMaxLevel() { return MAX_LEVEL; } /** * @return the maximum level acquirable by a pet. */ public byte getMaxPetLevel() { return MAX_PET_LEVEL; } public static ExperienceTable getInstance() { return SingletonHolder._instance; } @SuppressWarnings("synthetic-access") private static class SingletonHolder { protected static final ExperienceTable _instance = new ExperienceTable(); } }