Search in sources :

Example 11 with MapleData

use of provider.MapleData in project HeavenMS by ronancpl.

the class MapleMapFactory method loadMapFromWz.

private synchronized MapleMap loadMapFromWz(int mapid, Integer omapid) {
    MapleMap map;
    mapsRLock.lock();
    try {
        map = maps.get(omapid);
    } finally {
        mapsRLock.unlock();
    }
    if (map != null) {
        return map;
    }
    String mapName = getMapName(mapid);
    MapleData mapData = source.getData(mapName);
    MapleData infoData = mapData.getChildByPath("info");
    String link = MapleDataTool.getString(infoData.getChildByPath("link"), "");
    if (!link.equals("")) {
        // nexon made hundreds of dojo maps so to reduce the size they added links.
        mapName = getMapName(Integer.parseInt(link));
        mapData = source.getData(mapName);
    }
    float monsterRate = 0;
    MapleData mobRate = infoData.getChildByPath("mobRate");
    if (mobRate != null) {
        monsterRate = ((Float) mobRate.getData()).floatValue();
    }
    map = new MapleMap(mapid, world, channel, MapleDataTool.getInt("returnMap", infoData), monsterRate);
    map.setEventInstance(event);
    String onFirstEnter = MapleDataTool.getString(infoData.getChildByPath("onFirstUserEnter"), String.valueOf(mapid));
    map.setOnFirstUserEnter(onFirstEnter.equals("") ? String.valueOf(mapid) : onFirstEnter);
    String onEnter = MapleDataTool.getString(infoData.getChildByPath("onUserEnter"), String.valueOf(mapid));
    map.setOnUserEnter(onEnter.equals("") ? String.valueOf(mapid) : onEnter);
    map.setFieldLimit(MapleDataTool.getInt(infoData.getChildByPath("fieldLimit"), 0));
    map.setMobInterval((short) MapleDataTool.getInt(infoData.getChildByPath("createMobInterval"), 5000));
    PortalFactory portalFactory = new PortalFactory();
    for (MapleData portal : mapData.getChildByPath("portal")) {
        map.addPortal(portalFactory.makePortal(MapleDataTool.getInt(portal.getChildByPath("pt")), portal));
    }
    MapleData timeMob = infoData.getChildByPath("timeMob");
    if (timeMob != null) {
        map.timeMob(MapleDataTool.getInt(timeMob.getChildByPath("id")), MapleDataTool.getString(timeMob.getChildByPath("message")));
    }
    int[] bounds = new int[4];
    bounds[0] = MapleDataTool.getInt(infoData.getChildByPath("VRTop"));
    bounds[1] = MapleDataTool.getInt(infoData.getChildByPath("VRBottom"));
    if (bounds[0] == bounds[1]) {
        // old-style baked map
        MapleData minimapData = mapData.getChildByPath("miniMap");
        if (minimapData != null) {
            bounds[0] = MapleDataTool.getInt(minimapData.getChildByPath("centerX")) * -1;
            bounds[1] = MapleDataTool.getInt(minimapData.getChildByPath("centerY")) * -1;
            bounds[2] = MapleDataTool.getInt(minimapData.getChildByPath("height"));
            bounds[3] = MapleDataTool.getInt(minimapData.getChildByPath("width"));
            map.setMapPointBoundings(bounds[0], bounds[1], bounds[2], bounds[3]);
        } else {
            int dist = (1 << 18);
            map.setMapPointBoundings(-dist / 2, -dist / 2, dist, dist);
        }
    } else {
        bounds[2] = MapleDataTool.getInt(infoData.getChildByPath("VRLeft"));
        bounds[3] = MapleDataTool.getInt(infoData.getChildByPath("VRRight"));
        map.setMapLineBoundings(bounds[0], bounds[1], bounds[2], bounds[3]);
    }
    List<MapleFoothold> allFootholds = new LinkedList<>();
    Point lBound = new Point();
    Point uBound = new Point();
    for (MapleData footRoot : mapData.getChildByPath("foothold")) {
        for (MapleData footCat : footRoot) {
            for (MapleData footHold : footCat) {
                int x1 = MapleDataTool.getInt(footHold.getChildByPath("x1"));
                int y1 = MapleDataTool.getInt(footHold.getChildByPath("y1"));
                int x2 = MapleDataTool.getInt(footHold.getChildByPath("x2"));
                int y2 = MapleDataTool.getInt(footHold.getChildByPath("y2"));
                MapleFoothold fh = new MapleFoothold(new Point(x1, y1), new Point(x2, y2), Integer.parseInt(footHold.getName()));
                fh.setPrev(MapleDataTool.getInt(footHold.getChildByPath("prev")));
                fh.setNext(MapleDataTool.getInt(footHold.getChildByPath("next")));
                if (fh.getX1() < lBound.x) {
                    lBound.x = fh.getX1();
                }
                if (fh.getX2() > uBound.x) {
                    uBound.x = fh.getX2();
                }
                if (fh.getY1() < lBound.y) {
                    lBound.y = fh.getY1();
                }
                if (fh.getY2() > uBound.y) {
                    uBound.y = fh.getY2();
                }
                allFootholds.add(fh);
            }
        }
    }
    MapleFootholdTree fTree = new MapleFootholdTree(lBound, uBound);
    for (MapleFoothold fh : allFootholds) {
        fTree.insert(fh);
    }
    map.setFootholds(fTree);
    if (mapData.getChildByPath("area") != null) {
        for (MapleData area : mapData.getChildByPath("area")) {
            int x1 = MapleDataTool.getInt(area.getChildByPath("x1"));
            int y1 = MapleDataTool.getInt(area.getChildByPath("y1"));
            int x2 = MapleDataTool.getInt(area.getChildByPath("x2"));
            int y2 = MapleDataTool.getInt(area.getChildByPath("y2"));
            map.addMapleArea(new Rectangle(x1, y1, (x2 - x1), (y2 - y1)));
        }
    }
    try {
        Connection con = DatabaseConnection.getConnection();
        try (PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE map = ?")) {
            ps.setInt(1, omapid);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    map.addMapObject(new PlayerNPCs(rs));
                }
            }
        }
        con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    for (MapleData life : mapData.getChildByPath("life")) {
        String id = MapleDataTool.getString(life.getChildByPath("id"));
        String type = MapleDataTool.getString(life.getChildByPath("type"));
        AbstractLoadedMapleLife myLife = loadLife(life, id, type);
        if (myLife instanceof MapleMonster) {
            MapleMonster monster = (MapleMonster) myLife;
            int mobTime = MapleDataTool.getInt("mobTime", life, 0);
            int team = MapleDataTool.getInt("team", life, -1);
            if (mobTime == -1) {
                // does not respawn, force spawn once
                map.spawnMonster(monster);
            } else {
                map.addMonsterSpawn(monster, mobTime, team);
            }
            // should the map be reseted, use allMonsterSpawn list of monsters to spawn them again
            map.addAllMonsterSpawn(monster, mobTime, team);
        } else {
            map.addMapObject(myLife);
        }
    }
    if (mapData.getChildByPath("reactor") != null) {
        for (MapleData reactor : mapData.getChildByPath("reactor")) {
            String id = MapleDataTool.getString(reactor.getChildByPath("id"));
            if (id != null) {
                MapleReactor newReactor = loadReactor(reactor, id);
                map.spawnReactor(newReactor);
            }
        }
    }
    try {
        map.setMapName(MapleDataTool.getString("mapName", nameData.getChildByPath(getMapStringName(omapid)), ""));
        map.setStreetName(MapleDataTool.getString("streetName", nameData.getChildByPath(getMapStringName(omapid)), ""));
    } catch (Exception e) {
        if (omapid / 1000 != 1020) {
            // explorer job introducion scenes
            e.printStackTrace();
            System.err.println("Not found mapid " + omapid);
        }
        map.setMapName("");
        map.setStreetName("");
    }
    map.setClock(mapData.getChildByPath("clock") != null);
    map.setEverlast(infoData.getChildByPath("everlast") != null);
    map.setTown(infoData.getChildByPath("town") != null);
    map.setHPDec(MapleDataTool.getIntConvert("decHP", infoData, 0));
    map.setHPDecProtect(MapleDataTool.getIntConvert("protectItem", infoData, 0));
    map.setForcedReturnMap(MapleDataTool.getInt(infoData.getChildByPath("forcedReturn"), 999999999));
    map.setBoat(mapData.getChildByPath("shipObj") != null);
    map.setTimeLimit(MapleDataTool.getIntConvert("timeLimit", infoData, -1));
    map.setFieldType(MapleDataTool.getIntConvert("fieldType", infoData, 0));
    // Is there a map that contains more than 500 mobs?
    map.setMobCapacity(MapleDataTool.getIntConvert("fixedMobCapacity", infoData, 500));
    HashMap<Integer, Integer> backTypes = new HashMap<>();
    try {
        for (MapleData layer : mapData.getChildByPath("back")) {
            // yolo
            int layerNum = Integer.parseInt(layer.getName());
            int btype = MapleDataTool.getInt(layer.getChildByPath("type"), 0);
            backTypes.put(layerNum, btype);
        }
    } catch (Exception e) {
        e.printStackTrace();
    // swallow cause I'm cool
    }
    map.setBackgroundTypes(backTypes);
    map.generateMapDropRangeCache();
    mapsWLock.lock();
    try {
        maps.put(omapid, map);
    } finally {
        mapsWLock.unlock();
    }
    return map;
}
Also used : SQLException(java.sql.SQLException) HashMap(java.util.HashMap) Rectangle(java.awt.Rectangle) ResultSet(java.sql.ResultSet) MapleData(provider.MapleData) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Point(java.awt.Point) AbstractLoadedMapleLife(server.life.AbstractLoadedMapleLife) Point(java.awt.Point) LinkedList(java.util.LinkedList) SQLException(java.sql.SQLException) PortalFactory(server.PortalFactory) MapleMonster(server.life.MapleMonster)

Example 12 with MapleData

use of provider.MapleData in project HeavenMS by ronancpl.

the class MapleQuest method loadAllQuest.

public static void loadAllQuest() {
    questInfo = questData.getData("QuestInfo.img");
    questReq = questData.getData("Check.img");
    questAct = questData.getData("Act.img");
    try {
        for (MapleData quest : questInfo.getChildren()) {
            int questID = Integer.parseInt(quest.getName());
            quests.put(questID, new MapleQuest(questID));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : MapleData(provider.MapleData)

Example 13 with MapleData

use of provider.MapleData in project HeavenMS by ronancpl.

the class DataTool method monsterIdsFromName.

public static ArrayList<Integer> monsterIdsFromName(String name) {
    MapleData data = null;
    MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz"));
    ArrayList<Integer> ret = new ArrayList<>();
    data = dataProvider.getData("Mob.img");
    if (mob_pairs == null) {
        mob_pairs = new LinkedList<>();
        for (MapleData mobIdData : data.getChildren()) {
            int mobIdFromData = Integer.parseInt(mobIdData.getName());
            String mobNameFromData = MapleDataTool.getString(mobIdData.getChildByPath("name"), "NO-NAME");
            mob_pairs.add(new Pair<>(mobIdFromData, mobNameFromData));
        }
    }
    for (Pair<Integer, String> mobPair : mob_pairs) {
        if (mobPair.getRight().toLowerCase().equals(name.toLowerCase())) {
            ret.add(mobPair.getLeft());
        }
    }
    return ret;
}
Also used : MapleData(provider.MapleData) ArrayList(java.util.ArrayList) MapleDataProvider(provider.MapleDataProvider) File(java.io.File)

Example 14 with MapleData

use of provider.MapleData in project HeavenMS by ronancpl.

the class DataTool method npcIdsFromName.

public static ArrayList<Integer> npcIdsFromName(String name) {
    MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz"));
    ArrayList<Integer> ret = new ArrayList<>();
    if (npc_list == null) {
        ArrayList<Pair<Integer, String>> searchList = new ArrayList<>();
        for (MapleData searchData : dataProvider.getData("Npc.img").getChildren()) {
            int searchFromData = Integer.parseInt(searchData.getName());
            String infoFromData = MapleDataTool.getString(searchData.getChildByPath("name"), "NO-NAME");
            searchList.add(new Pair<>(searchFromData, infoFromData));
        }
        npc_list = searchList;
    }
    for (Pair<Integer, String> searched : npc_list) {
        if (searched.getRight().toLowerCase().contains(name.toLowerCase())) {
            ret.add(searched.getLeft());
        }
    }
    return ret;
}
Also used : MapleData(provider.MapleData) ArrayList(java.util.ArrayList) MapleDataProvider(provider.MapleDataProvider) File(java.io.File) Pair(tools.Pair)

Example 15 with MapleData

use of provider.MapleData in project HeavenMS by ronancpl.

the class MapleItemInformationProvider method getItemReward.

public Pair<Integer, List<RewardItem>> getItemReward(int itemId) {
    // Thanks Celino, used some stuffs :)
    if (rewardCache.containsKey(itemId)) {
        return rewardCache.get(itemId);
    }
    int totalprob = 0;
    List<RewardItem> rewards = new ArrayList<>();
    for (MapleData child : getItemData(itemId).getChildByPath("reward").getChildren()) {
        RewardItem reward = new RewardItem();
        reward.itemid = MapleDataTool.getInt("item", child, 0);
        reward.prob = (byte) MapleDataTool.getInt("prob", child, 0);
        reward.quantity = (short) MapleDataTool.getInt("count", child, 0);
        reward.effect = MapleDataTool.getString("Effect", child, "");
        reward.worldmsg = MapleDataTool.getString("worldMsg", child, null);
        reward.period = MapleDataTool.getInt("period", child, -1);
        totalprob += reward.prob;
        rewards.add(reward);
    }
    Pair<Integer, List<RewardItem>> hmm = new Pair<>(totalprob, rewards);
    rewardCache.put(itemId, hmm);
    return hmm;
}
Also used : MapleData(provider.MapleData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Pair(tools.Pair)

Aggregations

MapleData (provider.MapleData)90 ArrayList (java.util.ArrayList)19 Pair (tools.Pair)11 File (java.io.File)8 Point (java.awt.Point)7 LinkedList (java.util.LinkedList)6 MapleDataDirectoryEntry (provider.MapleDataDirectoryEntry)6 MapleDataFileEntry (provider.MapleDataFileEntry)6 LinkedHashMap (java.util.LinkedHashMap)5 SQLException (java.sql.SQLException)4 MapleDataProvider (provider.MapleDataProvider)4 Skill (client.Skill)2 IOException (java.io.IOException)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 AbstractLoadedMapleLife (server.life.AbstractLoadedMapleLife)2 MapleCharacter (client.MapleCharacter)1 Item (client.inventory.Item)1 MonsterStatus (client.status.MonsterStatus)1 Rectangle (java.awt.Rectangle)1