Search in sources :

Example 46 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class MapleMap method getDoorPositionStatus.

public Pair<String, Integer> getDoorPositionStatus(Point pos) {
    MaplePortal portal = findClosestPlayerSpawnpoint(pos);
    double angle = getAngle(portal.getPosition(), pos);
    double distn = pos.distanceSq(portal.getPosition());
    if (distn <= 777777.7) {
        return null;
    }
    distn = Math.sqrt(distn);
    return new Pair<>(getRoundedCoordinate(angle), Integer.valueOf((int) distn));
}
Also used : MaplePortal(server.MaplePortal) Pair(tools.Pair)

Example 47 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class ItemAction method run.

@Override
public void run(MapleCharacter chr, Integer extSelection) {
    List<Pair<Integer, Integer>> takeItem = new LinkedList<>();
    List<Pair<Integer, Integer>> giveItem = new LinkedList<>();
    int props = 0, rndProps = 0, accProps = 0;
    for (ItemData item : items) {
        if (item.getProp() != null && item.getProp() != -1 && canGetItem(item, chr)) {
            props += item.getProp();
        }
    }
    int extNum = 0;
    if (props > 0) {
        rndProps = Randomizer.nextInt(props);
    }
    for (ItemData iEntry : items) {
        if (!canGetItem(iEntry, chr)) {
            continue;
        }
        if (iEntry.getProp() != null) {
            if (iEntry.getProp() == -1) {
                if (extSelection != extNum++)
                    continue;
            } else {
                accProps += iEntry.getProp();
                if (accProps <= rndProps) {
                    continue;
                } else {
                    accProps = Integer.MIN_VALUE;
                }
            }
        }
        if (iEntry.getCount() < 0) {
            // Remove Item
            takeItem.add(new Pair<>(iEntry.getId(), iEntry.getCount()));
        } else {
            // Give Item
            giveItem.add(new Pair<>(iEntry.getId(), iEntry.getCount()));
        }
    }
    for (Pair<Integer, Integer> iPair : takeItem) {
        MapleInventoryType type = ItemConstants.getInventoryType(iPair.getLeft());
        // Invert
        int quantity = iPair.getRight() * -1;
        if (type.equals(MapleInventoryType.EQUIP)) {
            if (chr.getInventory(type).countById(iPair.getLeft()) < quantity) {
                // Not enough in the equip inventoty, so check Equipped...
                if (chr.getInventory(MapleInventoryType.EQUIPPED).countById(iPair.getLeft()) > quantity) {
                    // Found it equipped, so change the type to equipped.
                    type = MapleInventoryType.EQUIPPED;
                }
            }
        }
        MapleInventoryManipulator.removeById(chr.getClient(), type, iPair.getLeft(), quantity, true, false);
        chr.announce(MaplePacketCreator.getShowItemGain(iPair.getLeft(), (short) iPair.getRight().shortValue(), true));
    }
    for (Pair<Integer, Integer> iPair : giveItem) {
        MapleInventoryManipulator.addById(chr.getClient(), iPair.getLeft(), (short) iPair.getRight().shortValue());
        chr.announce(MaplePacketCreator.getShowItemGain(iPair.getLeft(), (short) iPair.getRight().shortValue(), true));
    }
}
Also used : MapleInventoryType(client.inventory.MapleInventoryType) LinkedList(java.util.LinkedList) Pair(tools.Pair)

Example 48 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class MapleLifeFactory method getAllMonsterStats.

public static Map<Integer, MapleMonsterStats> getAllMonsterStats() {
    MapleDataDirectoryEntry root = data.getRoot();
    System.out.print("Parsing mob stats... ");
    for (MapleDataFileEntry mFile : root.getFiles()) {
        try {
            String fileName = mFile.getName();
            // System.out.println("Parsing '" + fileName + "'");
            MapleData monsterData = data.getData(fileName);
            if (monsterData == null) {
                continue;
            }
            Integer mid = getMonsterId(fileName);
            MapleData monsterInfoData = monsterData.getChildByPath("info");
            MapleMonsterStats stats = new MapleMonsterStats();
            stats.setHp(MapleDataTool.getIntConvert("maxHP", monsterInfoData));
            stats.setFriendly(MapleDataTool.getIntConvert("damagedByMob", monsterInfoData, 0) == 1);
            stats.setPADamage(MapleDataTool.getIntConvert("PADamage", monsterInfoData));
            stats.setPDDamage(MapleDataTool.getIntConvert("PDDamage", monsterInfoData));
            stats.setMADamage(MapleDataTool.getIntConvert("MADamage", monsterInfoData));
            stats.setMDDamage(MapleDataTool.getIntConvert("MDDamage", monsterInfoData));
            stats.setMp(MapleDataTool.getIntConvert("maxMP", monsterInfoData, 0));
            stats.setExp(MapleDataTool.getIntConvert("exp", monsterInfoData, 0));
            stats.setLevel(MapleDataTool.getIntConvert("level", monsterInfoData));
            stats.setRemoveAfter(MapleDataTool.getIntConvert("removeAfter", monsterInfoData, 0));
            stats.setBoss(MapleDataTool.getIntConvert("boss", monsterInfoData, 0) > 0);
            stats.setExplosiveReward(MapleDataTool.getIntConvert("explosiveReward", monsterInfoData, 0) > 0);
            stats.setFfaLoot(MapleDataTool.getIntConvert("publicReward", monsterInfoData, 0) > 0);
            stats.setUndead(MapleDataTool.getIntConvert("undead", monsterInfoData, 0) > 0);
            stats.setName(MapleDataTool.getString(mid + "/name", mobStringData, "MISSINGNO"));
            stats.setBuffToGive(MapleDataTool.getIntConvert("buff", monsterInfoData, -1));
            stats.setCP(MapleDataTool.getIntConvert("getCP", monsterInfoData, 0));
            stats.setRemoveOnMiss(MapleDataTool.getIntConvert("removeOnMiss", monsterInfoData, 0) > 0);
            MapleData special = monsterInfoData.getChildByPath("coolDamage");
            if (special != null) {
                int coolDmg = MapleDataTool.getIntConvert("coolDamage", monsterInfoData);
                int coolProb = MapleDataTool.getIntConvert("coolDamageProb", monsterInfoData, 0);
                stats.setCool(new Pair<>(coolDmg, coolProb));
            }
            special = monsterInfoData.getChildByPath("loseItem");
            if (special != null) {
                for (MapleData liData : special.getChildren()) {
                    stats.addLoseItem(new loseItem(MapleDataTool.getInt(liData.getChildByPath("id")), (byte) MapleDataTool.getInt(liData.getChildByPath("prop")), (byte) MapleDataTool.getInt(liData.getChildByPath("x"))));
                }
            }
            special = monsterInfoData.getChildByPath("selfDestruction");
            if (special != null) {
                stats.setSelfDestruction(new selfDestruction((byte) MapleDataTool.getInt(special.getChildByPath("action")), MapleDataTool.getIntConvert("removeAfter", special, -1), MapleDataTool.getIntConvert("hp", special, -1)));
            }
            MapleData firstAttackData = monsterInfoData.getChildByPath("firstAttack");
            int firstAttack = 0;
            if (firstAttackData != null) {
                if (firstAttackData.getType() == MapleDataType.FLOAT) {
                    firstAttack = Math.round(MapleDataTool.getFloat(firstAttackData));
                } else {
                    firstAttack = MapleDataTool.getInt(firstAttackData);
                }
            }
            stats.setFirstAttack(firstAttack > 0);
            stats.setDropPeriod(MapleDataTool.getIntConvert("dropItemPeriod", monsterInfoData, 0) * 10000);
            stats.setTagColor(MapleDataTool.getIntConvert("hpTagColor", monsterInfoData, 0));
            stats.setTagBgColor(MapleDataTool.getIntConvert("hpTagBgcolor", monsterInfoData, 0));
            for (MapleData idata : monsterData) {
                if (!idata.getName().equals("info")) {
                    int delay = 0;
                    for (MapleData pic : idata.getChildren()) {
                        delay += MapleDataTool.getIntConvert("delay", pic, 0);
                    }
                    stats.setAnimationTime(idata.getName(), delay);
                }
            }
            MapleData reviveInfo = monsterInfoData.getChildByPath("revive");
            if (reviveInfo != null) {
                List<Integer> revives = new LinkedList<>();
                for (MapleData data_ : reviveInfo) {
                    revives.add(MapleDataTool.getInt(data_));
                }
                stats.setRevives(revives);
            }
            decodeElementalString(stats, MapleDataTool.getString("elemAttr", monsterInfoData, ""));
            MapleData monsterSkillData = monsterInfoData.getChildByPath("skill");
            if (monsterSkillData != null) {
                int i = 0;
                List<Pair<Integer, Integer>> skills = new ArrayList<>();
                while (monsterSkillData.getChildByPath(Integer.toString(i)) != null) {
                    skills.add(new Pair<>(Integer.valueOf(MapleDataTool.getInt(i + "/skill", monsterSkillData, 0)), Integer.valueOf(MapleDataTool.getInt(i + "/level", monsterSkillData, 0))));
                    i++;
                }
                stats.setSkills(skills);
            }
            MapleData banishData = monsterInfoData.getChildByPath("ban");
            if (banishData != null) {
                stats.setBanishInfo(new BanishInfo(MapleDataTool.getString("banMsg", banishData), MapleDataTool.getInt("banMap/0/field", banishData, -1), MapleDataTool.getString("banMap/0/portal", banishData, "sp")));
            }
            monsterStats.put(mid, stats);
        } catch (NullPointerException npe) {
        // System.out.println("[SEVERE] " + mFile.getName() + " failed to load. Issue: " + npe.getMessage() + "\n\n");
        }
    }
    System.out.println("done!");
    return monsterStats;
}
Also used : MapleData(provider.MapleData) MapleDataDirectoryEntry(provider.MapleDataDirectoryEntry) MapleDataFileEntry(provider.MapleDataFileEntry) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pair(tools.Pair)

Example 49 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class MapleQuestItemFetcher method ReportQuestItemData.

private static void ReportQuestItemData() {
    // This will reference one line at a time
    String line = null;
    try {
        Class.forName(driver).newInstance();
        System.out.println("Reading WZs...");
        fileReader = new InputStreamReader(new FileInputStream(fileName), "UTF-8");
        bufferedReader = new BufferedReader(fileReader);
        while ((line = bufferedReader.readLine()) != null) {
            translateToken(line);
        }
        bufferedReader.close();
        fileReader.close();
        System.out.println("Calculating table diffs...");
        calculateQuestItemDiff();
        System.out.println("Filtering drops on DB...");
        List<Pair<Integer, Integer>> itemsWithQuest = getPairsQuestItem();
        // filter drop data on DB
        con = DriverManager.getConnection(host, username, password);
        filterQuestDropsOnDB(itemsWithQuest);
        con.close();
        System.out.println("Filtering drops on project files...");
        // finally, filter whether this item is mentioned on the source code or not.
        filterDirectorySearchMatchingData("scripts", itemsWithQuest);
        filterDirectorySearchMatchingData("sql", itemsWithQuest);
        filterDirectorySearchMatchingData("src", itemsWithQuest);
        System.out.println("Reporting results...");
        // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids.
        printWriter = new PrintWriter(newFile, "UTF-8");
        printReportFileHeader();
        if (!mixedQuestidItems.isEmpty()) {
            printWriter.println("INCORRECT QUESTIDS ON DB");
            for (Entry<Integer, int[]> emqi : getSortedMapEntries1(mixedQuestidItems)) {
                int[] mqi = emqi.getValue();
                printWriter.println(mqi[0] + " : " + mqi[1] + " -> " + mqi[2] + getExpiredStringLabel(mqi[2]));
            }
            printWriter.println("\n\n\n\n\n");
        }
        if (!itemsWithQuest.isEmpty()) {
            Map<Integer, Integer> mapIwq = new HashMap<>(itemsWithQuest.size());
            for (Pair<Integer, Integer> iwq : itemsWithQuest) {
                mapIwq.put(iwq.getLeft(), iwq.getRight());
            }
            printWriter.println("ITEMS WITH NO QUEST DROP DATA ON DB");
            for (Entry<Integer, Integer> iwq : getSortedMapEntries0(mapIwq)) {
                printWriter.println(iwq.getKey() + " - " + iwq.getValue() + getExpiredStringLabel(iwq.getValue()));
            }
            printWriter.println("\n\n\n\n\n");
        }
        if (displayExtraInfo) {
            if (!zeroedStartQuestItems.isEmpty()) {
                printWriter.println("START QUEST ITEMS WITH ZERO QUANTITY");
                for (Pair<Integer, List<Integer>> iwq : getSortedMapEntries2(zeroedStartQuestItems)) {
                    printWriter.println(iwq.getLeft() + getExpiredStringLabel(iwq.getLeft()) + ":");
                    for (Integer i : iwq.getRight()) {
                        printWriter.println("  " + i);
                    }
                    printWriter.println();
                }
                printWriter.println("\n\n\n\n\n");
            }
            if (!zeroedCompleteQuestItems.isEmpty()) {
                printWriter.println("COMPLETE QUEST ITEMS WITH ZERO QUANTITY");
                for (Pair<Integer, List<Integer>> iwq : getSortedMapEntries2(zeroedCompleteQuestItems)) {
                    printWriter.println(iwq.getLeft() + getExpiredStringLabel(iwq.getLeft()) + ":");
                    for (Integer i : iwq.getRight()) {
                        printWriter.println("  " + i);
                    }
                    printWriter.println();
                }
                printWriter.println("\n\n\n\n\n");
            }
        }
        printWriter.close();
        System.out.println("Done!");
    } catch (FileNotFoundException ex) {
        System.out.println("Unable to open file '" + fileName + "'");
    } catch (IOException ex) {
        System.out.println("Error reading file '" + fileName + "'");
    } catch (SQLException e) {
        System.out.println("Warning: Could not establish connection to database to report quest data.");
        System.out.println(e.getMessage());
    } catch (ClassNotFoundException e) {
        System.out.println("Error: could not find class");
        System.out.println(e.getMessage());
    } catch (InstantiationException e) {
        System.out.println("Error: instantiation failure");
        System.out.println(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) Pair(tools.Pair) PrintWriter(java.io.PrintWriter)

Example 50 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class MapleQuestItemFetcher method filterQuestDropsOnDB.

private static void filterQuestDropsOnDB(List<Pair<Integer, Integer>> itemsWithQuest) throws SQLException {
    List<Pair<Integer, Integer>> copyItemsWithQuest = new ArrayList<>(itemsWithQuest);
    try {
        for (Pair<Integer, Integer> iq : copyItemsWithQuest) {
            PreparedStatement ps = con.prepareStatement("SELECT questid FROM drop_data WHERE itemid = ?;");
            ps.setInt(1, iq.getLeft());
            ResultSet rs = ps.executeQuery();
            if (rs.isBeforeFirst()) {
                while (rs.next()) {
                    int curQuest = rs.getInt(1);
                    if (curQuest != iq.getRight()) {
                        int[] mixed = new int[3];
                        mixed[0] = iq.getLeft();
                        mixed[1] = curQuest;
                        mixed[2] = iq.getRight();
                        mixedQuestidItems.put(iq.getLeft(), mixed);
                    }
                }
                itemsWithQuest.remove(iq);
            }
            rs.close();
            ps.close();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Pair(tools.Pair)

Aggregations

Pair (tools.Pair)51 ArrayList (java.util.ArrayList)34 Point (java.awt.Point)16 Item (client.inventory.Item)15 LinkedList (java.util.LinkedList)12 MapleData (provider.MapleData)11 SQLException (java.sql.SQLException)10 PreparedStatement (java.sql.PreparedStatement)7 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 MobSkill (server.life.MobSkill)6 MapleCharacter (client.MapleCharacter)5 Connection (java.sql.Connection)5 ResultSet (java.sql.ResultSet)5 MapleMap (server.maps.MapleMap)5 LinkedHashMap (java.util.LinkedHashMap)4 CharacterIdChannelPair (net.server.channel.CharacterIdChannelPair)4 MaplePartyCharacter (net.server.world.MaplePartyCharacter)4 MapleStatEffect (server.MapleStatEffect)4 DatabaseConnection (tools.DatabaseConnection)4