Search in sources :

Example 1 with MakerItemCreateEntry

use of server.MakerItemFactory.MakerItemCreateEntry in project HeavenMS by ronancpl.

the class MakerSkillHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    int type = slea.readInt();
    int toCreate = slea.readInt();
    int toDisassemble = -1, pos = -1;
    boolean makerSucceeded = true;
    MakerItemCreateEntry recipe;
    Map<Integer, Short> reagentids = new LinkedHashMap<>();
    int stimulantid = -1;
    if (type == 3) {
        // building monster crystal
        int fromLeftover = toCreate;
        toCreate = ii.getMakerCrystalFromLeftover(toCreate);
        if (toCreate == -1) {
            c.announce(MaplePacketCreator.serverNotice(1, ii.getName(toCreate) + " is unavailable for Monster Crystal conversion."));
            return;
        }
        recipe = MakerItemFactory.generateLeftoverCrystalEntry(fromLeftover);
    } else if (type == 4) {
        // disassembling
        // 1... probably inventory type
        slea.readInt();
        pos = slea.readInt();
        Item it = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) pos);
        if (it != null && it.getItemId() == toCreate) {
            Pair<Integer, Integer> p;
            if ((p = generateDisassemblyInfo(toCreate)) != null) {
                recipe = MakerItemFactory.generateDisassemblyCrystalEntry(p.getLeft(), p.getRight());
                toDisassemble = toCreate;
                toCreate = ii.getMakerCrystalFromEquip(toCreate);
            } else {
                c.announce(MaplePacketCreator.serverNotice(1, ii.getName(toCreate) + " is unavailable for Monster Crystal disassembly."));
                return;
            }
        } else {
            c.announce(MaplePacketCreator.serverNotice(1, "An unknown error occurred when trying to apply that item for disassembly."));
            return;
        }
    } else {
        if (ItemConstants.isEquipment(toCreate)) {
            // only equips uses stimulant and reagents
            if (slea.readByte() != 0) {
                // stimulant
                stimulantid = getMakerStimulant(toCreate);
                if (!c.getAbstractPlayerInteraction().haveItem(stimulantid)) {
                    stimulantid = -1;
                }
            }
            int reagents = Math.min(slea.readInt(), getMakerReagentSlots(toCreate));
            for (int i = 0; i < reagents; i++) {
                // crystals
                int reagentid = slea.readInt();
                if (ItemConstants.isMakerReagent(reagentid)) {
                    Short rs = reagentids.get(reagentid);
                    if (rs == null) {
                        reagentids.put(reagentid, (short) 1);
                    } else {
                        reagentids.put(reagentid, (short) (rs + 1));
                    }
                }
            }
            List<Pair<Integer, Short>> toUpdate = new LinkedList<>();
            for (Entry<Integer, Short> r : reagentids.entrySet()) {
                int qty = c.getAbstractPlayerInteraction().getItemQuantity(r.getKey());
                if (qty < r.getValue()) {
                    toUpdate.add(new Pair<>(r.getKey(), (short) qty));
                }
            }
            // remove those not present on player inventory
            if (!toUpdate.isEmpty()) {
                for (Pair<Integer, Short> rp : toUpdate) {
                    if (rp.getRight() > 0) {
                        reagentids.put(rp.getLeft(), rp.getRight());
                    } else {
                        reagentids.remove(rp.getLeft());
                    }
                }
            }
            if (!reagentids.isEmpty())
                removeOddMakerReagents(toCreate, reagentids);
        }
        recipe = MakerItemFactory.getItemCreateEntry(toCreate, stimulantid, reagentids);
    }
    short createStatus = getCreateStatus(c, recipe);
    switch(createStatus) {
        case // non-available for Maker itemid has been tried to forge
        -1:
            FilePrinter.printError(FilePrinter.EXPLOITS, "Player " + c.getPlayer().getName() + " tried to craft itemid " + toCreate + " using the Maker skill.");
            c.announce(MaplePacketCreator.serverNotice(1, "The requested item could not be crafted on this operation."));
            break;
        case // no items
        1:
            c.announce(MaplePacketCreator.serverNotice(1, "You don't have all required items in your inventory to make " + recipe.getRewardAmount() + " " + ii.getName(toCreate) + "."));
            break;
        case // no meso
        2:
            NumberFormat nf = new DecimalFormat("#,###,###,###");
            c.announce(MaplePacketCreator.serverNotice(1, "You don't have enough mesos (" + nf.format(recipe.getCost()) + ") to complete this operation."));
            break;
        case // no req level
        3:
            c.announce(MaplePacketCreator.serverNotice(1, "You don't have enough level to complete this operation."));
            break;
        case // no req skill level
        4:
            c.announce(MaplePacketCreator.serverNotice(1, "You don't have enough Maker level to complete this operation."));
            break;
        default:
            if (MapleInventoryManipulator.checkSpace(c, toCreate, (short) recipe.getRewardAmount(), "")) {
                for (Pair<Integer, Integer> p : recipe.getReqItems()) {
                    c.getAbstractPlayerInteraction().gainItem(p.getLeft(), (short) -p.getRight());
                }
                if (toDisassemble != -1) {
                    MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.EQUIP, (short) pos, (short) 1, false);
                    c.announce(MaplePacketCreator.getShowItemGain(toDisassemble, (short) -1, true));
                }
                int cost = recipe.getCost();
                if (stimulantid == -1 && reagentids.isEmpty()) {
                    if (cost > 0)
                        c.getPlayer().gainMeso(-cost);
                    c.getPlayer().setCS(true);
                    c.getAbstractPlayerInteraction().gainItem(toCreate, (short) recipe.getRewardAmount());
                    c.getPlayer().setCS(false);
                } else {
                    if (stimulantid != -1)
                        c.getAbstractPlayerInteraction().gainItem(stimulantid, (short) -1);
                    if (!reagentids.isEmpty()) {
                        for (Entry<Integer, Short> r : reagentids.entrySet()) {
                            c.getAbstractPlayerInteraction().gainItem(r.getKey(), (short) (-1 * r.getValue()));
                        }
                    }
                    if (cost > 0)
                        c.getPlayer().gainMeso(-cost);
                    makerSucceeded = addBoostedMakerItem(c, toCreate, stimulantid, reagentids);
                }
                if (makerSucceeded)
                    c.announce(MaplePacketCreator.serverNotice(1, "You have successfully created " + recipe.getRewardAmount() + " " + ii.getName(toCreate) + "."));
                else
                    c.getPlayer().dropMessage(5, "The Maker skill lights up, but the skill winds up as if nothing happened.");
                c.announce(MaplePacketCreator.showMakerEffect(makerSucceeded));
                c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showForeignMakerEffect(c.getPlayer().getId(), makerSucceeded), false);
                if (toCreate == 4260003 && c.getPlayer().getQuestStatus(6033) == 1) {
                    c.getAbstractPlayerInteraction().setQuestProgress(6033, 1);
                }
            } else {
                c.announce(MaplePacketCreator.serverNotice(1, "Your inventory is full."));
            }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) LinkedHashMap(java.util.LinkedHashMap) Item(client.inventory.Item) MakerItemCreateEntry(server.MakerItemFactory.MakerItemCreateEntry) Entry(java.util.Map.Entry) List(java.util.List) LinkedList(java.util.LinkedList) MakerItemCreateEntry(server.MakerItemFactory.MakerItemCreateEntry) Pair(tools.Pair) NumberFormat(java.text.NumberFormat)

Example 2 with MakerItemCreateEntry

use of server.MakerItemFactory.MakerItemCreateEntry in project HeavenMS by ronancpl.

the class MapleItemInformationProvider method getMakerItemEntry.

public MakerItemCreateEntry getMakerItemEntry(int toCreate) {
    MakerItemCreateEntry makerEntry;
    if ((makerEntry = makerItemCache.get(toCreate)) != null) {
        return new MakerItemCreateEntry(makerEntry);
    } else {
        try {
            Connection con = DatabaseConnection.getConnection();
            PreparedStatement ps = con.prepareStatement("SELECT req_level, req_maker_level, req_meso, quantity FROM makercreatedata WHERE itemid = ?");
            ps.setInt(1, toCreate);
            ResultSet rs = ps.executeQuery();
            int reqLevel = 0;
            int reqMakerLevel = 0;
            int cost = 0;
            int toGive = 0;
            if (rs.next()) {
                reqLevel = rs.getInt("req_level");
                reqMakerLevel = rs.getInt("req_maker_level");
                cost = rs.getInt("req_meso");
                toGive = rs.getInt("quantity");
            }
            ps.close();
            rs.close();
            makerEntry = new MakerItemCreateEntry(cost, reqLevel, reqMakerLevel, toGive);
            ps = con.prepareStatement("SELECT req_item, count FROM makerrecipedata WHERE itemid = ?");
            ps.setInt(1, toCreate);
            rs = ps.executeQuery();
            while (rs.next()) {
                makerEntry.addReqItem(rs.getInt("req_item"), rs.getInt("count"));
            }
            rs.close();
            ps.close();
            con.close();
            makerItemCache.put(toCreate, new MakerItemCreateEntry(makerEntry));
        } catch (SQLException sqle) {
            sqle.printStackTrace();
            makerEntry = null;
        }
    }
    return makerEntry;
}
Also used : SQLException(java.sql.SQLException) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MakerItemCreateEntry(server.MakerItemFactory.MakerItemCreateEntry)

Aggregations

MakerItemCreateEntry (server.MakerItemFactory.MakerItemCreateEntry)2 Item (client.inventory.Item)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 DatabaseConnection (tools.DatabaseConnection)1 Pair (tools.Pair)1