Search in sources :

Example 1 with RewardItem

use of server.MapleItemInformationProvider.RewardItem in project HeavenMS by ronancpl.

the class ItemRewardHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    byte slot = (byte) slea.readShort();
    // will load from xml I don't care.
    int itemId = slea.readInt();
    if (c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot).getItemId() != itemId || c.getPlayer().getInventory(MapleInventoryType.USE).countById(itemId) < 1)
        return;
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Pair<Integer, List<RewardItem>> rewards = ii.getItemReward(itemId);
    for (RewardItem reward : rewards.getRight()) {
        if (!MapleInventoryManipulator.checkSpace(c, reward.itemid, reward.quantity, "")) {
            c.announce(MaplePacketCreator.getShowInventoryFull());
            break;
        }
        if (Randomizer.nextInt(rewards.getLeft()) < reward.prob) {
            // Is it even possible to get an item with prob 1?
            if (ItemConstants.getInventoryType(reward.itemid) == MapleInventoryType.EQUIP) {
                final Item item = ii.getEquipById(reward.itemid);
                if (reward.period != -1) {
                    item.setExpiration(System.currentTimeMillis() + (reward.period * 60 * 60 * 10));
                }
                MapleInventoryManipulator.addFromDrop(c, item, false);
            } else {
                MapleInventoryManipulator.addById(c, reward.itemid, reward.quantity);
            }
            MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, false, false);
            if (reward.worldmsg != null) {
                String msg = reward.worldmsg;
                msg.replaceAll("/name", c.getPlayer().getName());
                msg.replaceAll("/item", ii.getName(reward.itemid));
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, msg));
            }
            break;
        }
    }
    c.announce(MaplePacketCreator.enableActions());
}
Also used : RewardItem(server.MapleItemInformationProvider.RewardItem) Item(client.inventory.Item) MapleItemInformationProvider(server.MapleItemInformationProvider) RewardItem(server.MapleItemInformationProvider.RewardItem) List(java.util.List)

Aggregations

Item (client.inventory.Item)1 List (java.util.List)1 MapleItemInformationProvider (server.MapleItemInformationProvider)1 RewardItem (server.MapleItemInformationProvider.RewardItem)1