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());
}
Aggregations