use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleHiredMerchant method buy.
public void buy(MapleClient c, int item, short quantity) {
synchronized (items) {
MaplePlayerShopItem pItem = items.get(item);
Item newItem = pItem.getItem().copy();
newItem.setQuantity((short) ((pItem.getItem().getQuantity() * quantity)));
if ((newItem.getFlag() & ItemConstants.KARMA) == ItemConstants.KARMA) {
newItem.setFlag((byte) (newItem.getFlag() ^ ItemConstants.KARMA));
}
if (quantity < 1 || pItem.getBundles() < 1 || !pItem.isExist() || pItem.getBundles() < quantity) {
c.announce(MaplePacketCreator.enableActions());
return;
} else if (newItem.getInventoryType().equals(MapleInventoryType.EQUIP) && newItem.getQuantity() > 1) {
c.announce(MaplePacketCreator.enableActions());
return;
} else if (!pItem.isExist()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
int price = (int) Math.min((long) pItem.getPrice() * quantity, Integer.MAX_VALUE);
if (c.getPlayer().getMeso() >= price) {
if (canBuy(c, newItem)) {
c.getPlayer().gainMeso(-price, false);
// idea thanks to vcoc
announceItemSold(newItem, price);
synchronized (sold) {
sold.add(new SoldItem(c.getPlayer().getName(), pItem.getItem().getItemId(), quantity, price));
}
pItem.setBundles((short) (pItem.getBundles() - quantity));
if (pItem.getBundles() < 1) {
pItem.setDoesExist(false);
}
MapleCharacter owner = Server.getInstance().getWorld(world).getPlayerStorage().getCharacterByName(ownerName);
if (owner != null) {
owner.addMerchantMesos(price);
} else {
try {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET MerchantMesos = MerchantMesos + " + price + " WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) {
ps.setInt(1, ownerId);
ps.executeUpdate();
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
c.getPlayer().dropMessage(1, "Your inventory is full. Please clean a slot before buying this item.");
}
} else {
c.getPlayer().dropMessage(1, "You do not have enough mesos.");
}
try {
this.saveItems(false);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class MapleMap method spawnItemDropList.
// spawns item instances of all defined item ids on a list
public final void spawnItemDropList(List<Integer> list, int minCopies, int maxCopies, final MapleMapObject dropper, final MapleCharacter owner, Point pos, final boolean ffaDrop, final boolean playerDrop) {
int copies = (maxCopies - minCopies) + 1;
if (copies < 1)
return;
Collections.shuffle(list);
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Random rnd = new Random();
final Point dropPos = new Point(pos);
dropPos.x -= (12 * list.size());
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == 0) {
spawnMesoDrop(owner != null ? 10 * owner.getMesoRate() : 10, calcDropPos(dropPos, pos), dropper, owner, playerDrop, (byte) (ffaDrop ? 2 : 0));
} else {
final Item drop;
int randomedId = list.get(i);
if (ItemConstants.getInventoryType(randomedId) != MapleInventoryType.EQUIP) {
drop = new Item(randomedId, (short) 0, (short) (rnd.nextInt(copies) + minCopies));
} else {
drop = ii.randomizeStats((Equip) ii.getEquipById(randomedId));
}
spawnItemDrop(dropper, owner, drop, calcDropPos(dropPos, pos), ffaDrop, playerDrop);
}
dropPos.x += 25;
}
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class ItemAction method check.
@Override
public boolean check(MapleCharacter chr, Integer extSelection) {
List<Pair<Item, MapleInventoryType>> gainList = new LinkedList<>();
List<Pair<Item, MapleInventoryType>> selectList = new LinkedList<>();
List<Pair<Item, MapleInventoryType>> randomList = new LinkedList<>();
List<Integer> allSlotUsed = new ArrayList(5);
for (byte i = 0; i < 5; i++) allSlotUsed.add(0);
for (ItemData item : items) {
if (!canGetItem(item, chr)) {
continue;
}
MapleInventoryType type = ItemConstants.getInventoryType(item.getId());
if (item.getProp() != null) {
Item toItem = new Item(item.getId(), (short) 0, (short) item.getCount());
if (item.getProp() < 0) {
selectList.add(new Pair<>(toItem, type));
} else {
randomList.add(new Pair<>(toItem, type));
}
} else {
if (item.getCount() > 0) {
// Make sure they can hold the item.
Item toItem = new Item(item.getId(), (short) 0, (short) item.getCount());
gainList.add(new Pair<>(toItem, type));
} else {
// Make sure they actually have the item.
int quantity = item.getCount() * -1;
int freeSlotCount = chr.getInventory(type).freeSlotCountById(item.getId(), quantity);
if (freeSlotCount == -1) {
if (type.equals(MapleInventoryType.EQUIP) && chr.getInventory(MapleInventoryType.EQUIPPED).countById(item.getId()) > quantity)
continue;
chr.dropMessage(1, "Please check if you have enough items in your inventory.");
return false;
} else {
// more slots available from the given items!
int idx = type.getType() - 1;
allSlotUsed.set(idx, allSlotUsed.get(idx) - freeSlotCount);
}
}
}
}
if (!randomList.isEmpty()) {
int result;
MapleClient c = chr.getClient();
List<Integer> rndUsed = new ArrayList(5);
for (byte i = 0; i < 5; i++) rndUsed.add(allSlotUsed.get(i));
for (Pair<Item, MapleInventoryType> it : randomList) {
int idx = it.getRight().getType() - 1;
result = MapleInventoryManipulator.checkSpaceProgressively(c, it.getLeft().getItemId(), it.getLeft().getQuantity(), "", rndUsed.get(idx));
if (result % 2 == 0) {
chr.dropMessage(1, "Please check if you have enough space in your inventory.");
return false;
}
allSlotUsed.set(idx, Math.max(allSlotUsed.get(idx), result >> 1));
}
}
if (!selectList.isEmpty()) {
Pair<Item, MapleInventoryType> selected = selectList.get(extSelection);
gainList.add(selected);
}
if (!MapleInventory.checkSpots(chr, gainList, allSlotUsed)) {
chr.dropMessage(1, "Please check if you have enough space in your inventory.");
return false;
}
return true;
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class Commands method executeHeavenMsCommandLv1.
public static boolean executeHeavenMsCommandLv1(Channel cserv, Server srv, MapleClient c, String[] sub) {
// Donator
MapleCharacter player = c.getPlayer();
switch(sub[0]) {
case "buffme":
// GM Skills : Haste(Super) - Holy Symbol - Bless - Hyper Body - Echo of Hero
SkillFactory.getSkill(4101004).getEffect(SkillFactory.getSkill(4101004).getMaxLevel()).applyTo(player);
SkillFactory.getSkill(2311003).getEffect(SkillFactory.getSkill(2311003).getMaxLevel()).applyTo(player);
SkillFactory.getSkill(1301007).getEffect(SkillFactory.getSkill(1301007).getMaxLevel()).applyTo(player);
SkillFactory.getSkill(2301004).getEffect(SkillFactory.getSkill(2301004).getMaxLevel()).applyTo(player);
SkillFactory.getSkill(1005).getEffect(SkillFactory.getSkill(1005).getMaxLevel()).applyTo(player);
player.setHp(player.getMaxHp());
player.updateSingleStat(MapleStat.HP, player.getMaxHp());
player.setMp(player.getMaxMp());
player.updateSingleStat(MapleStat.MP, player.getMaxMp());
break;
case "goto":
if (sub.length < 2) {
player.yellowMessage("Syntax: !goto <map name>");
break;
}
if (gotomaps.containsKey(sub[1])) {
MapleMap target = c.getChannelServer().getMapFactory().getMap(gotomaps.get(sub[1]));
MaplePortal targetPortal = target.getPortal(0);
if (player.getEventInstance() != null) {
player.getEventInstance().removePlayer(player);
}
player.changeMap(target, targetPortal);
} else {
player.dropMessage(5, "That map does not exist.");
}
break;
case "recharge":
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
for (Item torecharge : c.getPlayer().getInventory(MapleInventoryType.USE).list()) {
if (ItemConstants.isThrowingStar(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge);
} else if (ItemConstants.isArrow(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge);
} else if (ItemConstants.isBullet(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge);
} else if (ItemConstants.isConsumable(torecharge.getItemId())) {
torecharge.setQuantity(ii.getSlotMax(c, torecharge.getItemId()));
c.getPlayer().forceUpdateItem(torecharge);
}
}
player.dropMessage(5, "USE Recharged.");
break;
case "whereami":
player.yellowMessage("Map ID: " + player.getMap().getId());
player.yellowMessage("Players on this map:");
for (MapleMapObject mmo : player.getMap().getPlayers()) {
MapleCharacter chr = (MapleCharacter) mmo;
player.dropMessage(5, ">> " + chr.getName() + " - " + chr.getId() + " - Oid: " + chr.getObjectId());
}
player.yellowMessage("NPCs on this map:");
for (MapleMapObject npcs : player.getMap().getMapObjects()) {
if (npcs instanceof MapleNPC) {
MapleNPC npc = (MapleNPC) npcs;
player.dropMessage(5, ">> " + npc.getName() + " - " + npc.getId() + " - Oid: " + npc.getObjectId());
}
}
player.yellowMessage("Monsters on this map:");
for (MapleMapObject mobs : player.getMap().getMapObjects()) {
if (mobs instanceof MapleMonster) {
MapleMonster mob = (MapleMonster) mobs;
if (mob.isAlive()) {
player.dropMessage(5, ">> " + mob.getName() + " - " + mob.getId() + " - Oid: " + mob.getObjectId());
}
}
}
break;
default:
return false;
}
return true;
}
use of client.inventory.Item in project HeavenMS by ronancpl.
the class Commands method executeHeavenMsCommandLv4.
public static boolean executeHeavenMsCommandLv4(Channel cserv, Server srv, MapleClient c, String[] sub) {
// SuperGM
MapleCharacter player = c.getPlayer();
switch(sub[0]) {
case "servermessage":
c.getWorldServer().setServerMessage(joinStringFrom(sub, 1));
break;
case "proitem":
if (sub.length < 3) {
player.yellowMessage("Syntax: !proitem <itemid> <statvalue>");
break;
}
int itemid = Integer.parseInt(sub[1]);
short multiply = Short.parseShort(sub[2]);
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
MapleInventoryType type = ItemConstants.getInventoryType(itemid);
if (type.equals(MapleInventoryType.EQUIP)) {
Item it = ii.getEquipById(itemid);
it.setOwner(player.getName());
hardsetItemStats((Equip) it, multiply);
MapleInventoryManipulator.addFromDrop(c, it);
} else {
player.dropMessage(6, "Make sure it's an equippable item.");
}
break;
case "seteqstat":
if (sub.length < 2) {
player.yellowMessage("Syntax: !seteqstat <statvalue>");
break;
}
int newStat = Integer.parseInt(sub[1]);
MapleInventory equip = player.getInventory(MapleInventoryType.EQUIP);
for (byte i = 1; i <= equip.getSlotLimit(); i++) {
try {
Equip eu = (Equip) equip.getItem(i);
if (eu == null)
continue;
short incval = (short) newStat;
eu.setWdef(incval);
eu.setAcc(incval);
eu.setAvoid(incval);
eu.setJump(incval);
eu.setMatk(incval);
eu.setMdef(incval);
eu.setHp(incval);
eu.setMp(incval);
eu.setSpeed(incval);
eu.setWatk(incval);
eu.setDex(incval);
eu.setInt(incval);
eu.setStr(incval);
eu.setLuk(incval);
byte flag = eu.getFlag();
flag |= ItemConstants.UNTRADEABLE;
eu.setFlag(flag);
player.forceUpdateItem(eu);
} catch (Exception e) {
e.printStackTrace();
}
}
break;
case "exprate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !exprate <newrate>");
break;
}
int exprate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setExpRate(exprate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Exp Rate has been changed to " + exprate + "x."));
break;
case "mesorate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !mesorate <newrate>");
break;
}
int mesorate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setMesoRate(mesorate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Meso Rate has been changed to " + mesorate + "x."));
break;
case "droprate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !droprate <newrate>");
break;
}
int droprate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setDropRate(droprate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Drop Rate has been changed to " + droprate + "x."));
break;
case "questrate":
if (sub.length < 2) {
player.yellowMessage("Syntax: !questrate <newrate>");
break;
}
int questrate = Math.max(Integer.parseInt(sub[1]), 1);
c.getWorldServer().setQuestRate(questrate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Quest Rate has been changed to " + questrate + "x."));
break;
case "itemvac":
List<MapleMapObject> list = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.ITEM));
for (MapleMapObject item : list) {
player.pickupItem(item);
}
break;
case "forcevac":
List<MapleMapObject> items = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.ITEM));
for (MapleMapObject item : items) {
MapleMapItem mapItem = (MapleMapItem) item;
if (mapItem.getMeso() > 0) {
player.gainMeso(mapItem.getMeso(), true);
} else if (mapItem.getItemId() == 4031865 || mapItem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
player.getCashShop().gainCash(1, mapItem.getItemId() == 4031865 ? 100 : 250);
} else if (mapItem.getItem().getItemId() >= 5000000 && mapItem.getItem().getItemId() <= 5000100) {
int petId = MaplePet.createPet(mapItem.getItem().getItemId());
if (petId == -1) {
continue;
}
MapleInventoryManipulator.addById(c, mapItem.getItem().getItemId(), mapItem.getItem().getQuantity(), null, petId);
} else {
MapleInventoryManipulator.addFromDrop(c, mapItem.getItem(), true);
}
player.getMap().pickItemDrop(MaplePacketCreator.removeItemFromMap(mapItem.getObjectId(), 2, player.getId()), mapItem);
}
break;
case "zakum":
player.getMap().spawnFakeMonsterOnGroundBelow(MapleLifeFactory.getMonster(8800000), player.getPosition());
for (int x = 8800003; x < 8800011; x++) {
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(x), player.getPosition());
}
break;
case "horntail":
final Point targetPoint = player.getPosition();
final MapleMap targetMap = player.getMap();
targetMap.spawnHorntailOnGroundBelow(targetPoint);
break;
case "pinkbean":
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(8820001), player.getPosition());
break;
case "pap":
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(8500001), player.getPosition());
break;
case "pianus":
player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(8510000), player.getPosition());
break;
case "cake":
MapleMonster monster = MapleLifeFactory.getMonster(9400606);
if (sub.length > 1) {
int newHp = Integer.parseInt(sub[1]);
if (newHp < 0)
newHp = Integer.MAX_VALUE;
monster.getStats().setHp(newHp);
monster.setStartingHp(newHp);
}
player.getMap().spawnMonsterOnGroundBelow(monster, player.getPosition());
break;
default:
return false;
}
return true;
}
Aggregations