Search in sources :

Example 1 with ReactorDropEntry

use of server.maps.ReactorDropEntry in project HeavenMS by ronancpl.

the class ReactorActionManager method dropItems.

public void dropItems(boolean delayed, int posX, int posY, boolean meso, int mesoChance, final int minMeso, final int maxMeso, int minItems) {
    if (c.getPlayer() == null)
        return;
    List<ReactorDropEntry> items = generateDropList(getDropChances(), c.getPlayer().getDropRate(), meso, mesoChance, minItems);
    if (items.size() % 2 == 0)
        posX -= 12;
    final Point dropPos = new Point(posX, posY);
    if (!delayed) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        byte p = 1;
        for (ReactorDropEntry d : items) {
            dropPos.x = (int) (posX + ((p % 2 == 0) ? (25 * ((p + 1) / 2)) : -(25 * (p / 2))));
            p++;
            if (d.itemId == 0) {
                int range = maxMeso - minMeso;
                int displayDrop = (int) (Math.random() * range) + minMeso;
                int mesoDrop = (displayDrop * client.getWorldServer().getMesoRate());
                reactor.getMap().spawnMesoDrop(mesoDrop, reactor.getMap().calcDropPos(dropPos, reactor.getPosition()), reactor, client.getPlayer(), false, (byte) 2);
            } else {
                Item drop;
                if (ItemConstants.getInventoryType(d.itemId) != MapleInventoryType.EQUIP) {
                    drop = new Item(d.itemId, (short) 0, (short) 1);
                } else {
                    drop = ii.randomizeStats((Equip) ii.getEquipById(d.itemId));
                }
                reactor.getMap().dropFromReactor(getPlayer(), reactor, drop, dropPos, (short) d.questid);
            }
        }
    } else {
        final MapleCharacter chr = client.getPlayer();
        final MapleReactor r = reactor;
        final List<ReactorDropEntry> dropItems = items;
        final int worldMesoRate = client.getWorldServer().getMesoRate();
        dropPos.x -= (12 * items.size());
        sprayTask = TimerManager.getInstance().register(new Runnable() {

            @Override
            public void run() {
                if (dropItems.isEmpty()) {
                    sprayTask.cancel(false);
                    return;
                }
                ReactorDropEntry d = dropItems.remove(0);
                if (d.itemId == 0) {
                    int range = maxMeso - minMeso;
                    int displayDrop = (int) (Math.random() * range) + minMeso;
                    int mesoDrop = (displayDrop * worldMesoRate);
                    r.getMap().spawnMesoDrop(mesoDrop, r.getMap().calcDropPos(dropPos, r.getPosition()), r, chr, false, (byte) 2);
                } else {
                    Item drop;
                    if (ItemConstants.getInventoryType(d.itemId) != MapleInventoryType.EQUIP) {
                        drop = new Item(d.itemId, (short) 0, (short) 1);
                    } else {
                        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
                        drop = ii.randomizeStats((Equip) ii.getEquipById(d.itemId));
                    }
                    r.getMap().dropFromReactor(getPlayer(), r, drop, dropPos, (short) d.questid);
                }
                dropPos.x += 25;
            }
        }, 100);
    }
}
Also used : ReactorDropEntry(server.maps.ReactorDropEntry) Item(client.inventory.Item) Equip(client.inventory.Equip) MapleCharacter(client.MapleCharacter) MapleReactor(server.maps.MapleReactor) MapleItemInformationProvider(server.MapleItemInformationProvider) Point(java.awt.Point) Point(java.awt.Point)

Example 2 with ReactorDropEntry

use of server.maps.ReactorDropEntry in project HeavenMS by ronancpl.

the class ReactorActionManager method generateDropList.

private static List<ReactorDropEntry> generateDropList(List<ReactorDropEntry> drops, int dropRate, boolean meso, int mesoChance, int minItems) {
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    List<ReactorDropEntry> items = new ArrayList<>();
    List<ReactorDropEntry> questItems = new ArrayList<>();
    int numItems = 0;
    if (meso && Math.random() < (1 / (double) mesoChance)) {
        items.add(new ReactorDropEntry(0, mesoChance, -1));
    }
    for (ReactorDropEntry mde : drops) {
        if (Math.random() < (dropRate / (double) mde.chance)) {
            if (!ii.isQuestItem(mde.itemId)) {
                items.add(mde);
            } else {
                questItems.add(mde);
            }
            numItems++;
        }
    }
    while (numItems < minItems) {
        items.add(new ReactorDropEntry(0, mesoChance, -1));
        numItems++;
    }
    java.util.Collections.shuffle(items);
    java.util.Collections.shuffle(questItems);
    items.addAll(questItems);
    return items;
}
Also used : ReactorDropEntry(server.maps.ReactorDropEntry) MapleItemInformationProvider(server.MapleItemInformationProvider) ArrayList(java.util.ArrayList) Point(java.awt.Point)

Example 3 with ReactorDropEntry

use of server.maps.ReactorDropEntry in project HeavenMS by ronancpl.

the class ReactorScriptManager method getDrops.

public List<ReactorDropEntry> getDrops(int rid) {
    List<ReactorDropEntry> ret = drops.get(rid);
    if (ret == null) {
        ret = new LinkedList<>();
        try {
            Connection con = DatabaseConnection.getConnection();
            try (PreparedStatement ps = con.prepareStatement("SELECT itemid, chance, questid FROM reactordrops WHERE reactorid = ? AND chance >= 0")) {
                ps.setInt(1, rid);
                try (ResultSet rs = ps.executeQuery()) {
                    while (rs.next()) {
                        ret.add(new ReactorDropEntry(rs.getInt("itemid"), rs.getInt("chance"), rs.getInt("questid")));
                    }
                }
            }
            con.close();
        } catch (Throwable e) {
            FilePrinter.printError(FilePrinter.REACTOR + rid + ".txt", e);
        }
        drops.put(rid, ret);
    }
    return ret;
}
Also used : ReactorDropEntry(server.maps.ReactorDropEntry) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

ReactorDropEntry (server.maps.ReactorDropEntry)3 Point (java.awt.Point)2 MapleItemInformationProvider (server.MapleItemInformationProvider)2 MapleCharacter (client.MapleCharacter)1 Equip (client.inventory.Equip)1 Item (client.inventory.Item)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 MapleReactor (server.maps.MapleReactor)1 DatabaseConnection (tools.DatabaseConnection)1