use of client.inventory.MapleInventory 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;
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class MapleInventoryManipulator method removeById.
public static void removeById(MapleClient c, MapleInventoryType type, int itemId, int quantity, boolean fromDrop, boolean consume) {
int removeQuantity = quantity;
MapleInventory inv = c.getPlayer().getInventory(type);
int slotLimit = type == MapleInventoryType.EQUIPPED ? 128 : inv.getSlotLimit();
for (short i = 0; i <= slotLimit; i++) {
Item item = inv.getItem((short) (type == MapleInventoryType.EQUIPPED ? -i : i));
if (item != null) {
if (item.getItemId() == itemId || item.getCashId() == itemId) {
if (removeQuantity <= item.getQuantity()) {
removeFromSlot(c, type, item.getPosition(), (short) removeQuantity, fromDrop, consume);
removeQuantity = 0;
break;
} else {
removeQuantity -= item.getQuantity();
removeFromSlot(c, type, item.getPosition(), item.getQuantity(), fromDrop, consume);
}
}
}
}
if (removeQuantity > 0) {
throw new RuntimeException("[HACK] Not enough items available of Item:" + itemId + ", Quantity (After Quantity/Over Current Quantity): " + (quantity - removeQuantity) + "/" + quantity);
}
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class MaplePacketCreator method addCharEquips.
private static void addCharEquips(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
MapleInventory equip = chr.getInventory(MapleInventoryType.EQUIPPED);
Collection<Item> ii = MapleItemInformationProvider.getInstance().canWearEquipment(chr, equip.list());
Map<Short, Integer> myEquip = new LinkedHashMap<>();
Map<Short, Integer> maskedEquip = new LinkedHashMap<>();
for (Item item : ii) {
short pos = (byte) (item.getPosition() * -1);
if (pos < 100 && myEquip.get(pos) == null) {
myEquip.put(pos, item.getItemId());
} else if (pos > 100 && pos != 111) {
// don't ask. o.o
pos -= 100;
if (myEquip.get(pos) != null) {
maskedEquip.put(pos, myEquip.get(pos));
}
myEquip.put(pos, item.getItemId());
} else if (myEquip.get(pos) != null) {
maskedEquip.put(pos, item.getItemId());
}
}
for (Entry<Short, Integer> entry : myEquip.entrySet()) {
mplew.write(entry.getKey());
mplew.writeInt(entry.getValue());
}
mplew.write(0xFF);
for (Entry<Short, Integer> entry : maskedEquip.entrySet()) {
mplew.write(entry.getKey());
mplew.writeInt(entry.getValue());
}
mplew.write(0xFF);
Item cWeapon = equip.getItem((short) -111);
mplew.writeInt(cWeapon != null ? cWeapon.getItemId() : 0);
for (int i = 0; i < 3; i++) {
if (chr.getPet(i) != null) {
mplew.writeInt(chr.getPet(i).getItemId());
} else {
mplew.writeInt(0);
}
}
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class MapleStatEffect method applyTo.
// primary: the player caster of the buff
private boolean applyTo(MapleCharacter applyfrom, MapleCharacter applyto, boolean primary, Point pos, boolean useMaxRange) {
if (skill && (sourceid == GM.HIDE || sourceid == SuperGM.HIDE)) {
applyto.toggleHide(false);
return true;
}
int hpchange = calcHPChange(applyfrom, primary);
int mpchange = calcMPChange(applyfrom, primary);
if (primary) {
if (itemConNo != 0) {
if (!applyto.getClient().getAbstractPlayerInteraction().hasItem(itemCon, itemConNo)) {
applyto.getClient().announce(MaplePacketCreator.enableActions());
return false;
}
MapleInventoryManipulator.removeById(applyto.getClient(), ItemConstants.getInventoryType(itemCon), itemCon, itemConNo, false, true);
}
}
List<Pair<MapleStat, Integer>> hpmpupdate = new ArrayList<>(2);
if (!primary) {
if (isResurrection()) {
hpchange = applyto.getMaxHp();
applyto.setStance(0);
applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.removePlayerFromMap(applyto.getId()), false);
applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.spawnPlayerMapObject(applyto), false);
}
}
if (isDispel() && makeChanceResult()) {
applyto.dispelDebuffs();
} else if (isCureAllAbnormalStatus()) {
applyto.dispelDebuff(MapleDisease.SEDUCE);
applyto.dispelDebuff(MapleDisease.ZOMBIFY);
applyto.dispelDebuffs();
} else if (isComboReset()) {
applyto.setCombo((short) 0);
}
/*if (applyfrom.getMp() < getMpCon()) {
AutobanFactory.MPCON.addPoint(applyfrom.getAutobanManager(), "mpCon hack for skill:" + sourceid + "; Player MP: " + applyto.getMp() + " MP Needed: " + getMpCon());
} */
if (hpchange != 0) {
if (hpchange < 0 && (-hpchange) >= applyto.getHp() && (!applyto.hasDisease(MapleDisease.ZOMBIFY) || hpCon > 0)) {
if (!applyto.isGM()) {
applyto.getClient().announce(MaplePacketCreator.enableActions());
return false;
}
}
int newHp = applyto.getHp() + hpchange;
if (newHp < 1) {
newHp = 1;
}
applyto.setHp(newHp);
hpmpupdate.add(new Pair<>(MapleStat.HP, Integer.valueOf(applyto.getHp())));
}
int newMp = applyto.getMp() + mpchange;
if (mpchange != 0) {
if (mpchange < 0 && -mpchange > applyto.getMp()) {
if (!applyto.isGM()) {
applyto.getClient().announce(MaplePacketCreator.enableActions());
return false;
} else {
newMp = 0;
}
}
applyto.setMp(newMp);
hpmpupdate.add(new Pair<>(MapleStat.MP, Integer.valueOf(applyto.getMp())));
}
applyto.getClient().announce(MaplePacketCreator.updatePlayerStats(hpmpupdate, true, applyto));
if (moveTo != -1) {
if (moveTo != applyto.getMapId()) {
MapleMap target;
MaplePortal pt;
if (moveTo == 999999999) {
if (sourceid != 2030100) {
target = applyto.getMap().getReturnMap();
pt = target.getRandomPlayerSpawnpoint();
} else {
if (!applyto.canRecoverLastBanish())
return false;
Pair<Integer, Integer> lastBanishInfo = applyto.getLastBanishData();
target = applyto.getWarpMap(lastBanishInfo.getLeft());
pt = target.getPortal(lastBanishInfo.getRight());
}
} else {
target = applyto.getClient().getWorldServer().getChannel(applyto.getClient().getChannel()).getMapFactory().getMap(moveTo);
int targetid = target.getId() / 10000000;
if (targetid != 60 && applyto.getMapId() / 10000000 != 61 && targetid != applyto.getMapId() / 10000000 && targetid != 21 && targetid != 20 && targetid != 12 && (applyto.getMapId() / 10000000 != 10 && applyto.getMapId() / 10000000 != 12)) {
return false;
}
pt = target.getRandomPlayerSpawnpoint();
}
applyto.changeMap(target, pt);
} else {
return false;
}
}
if (isShadowClaw()) {
int projectile = 0;
MapleInventory use = applyto.getInventory(MapleInventoryType.USE);
for (int i = 1; i <= use.getSlotLimit(); i++) {
// impose order...
Item item = use.getItem((short) i);
if (item != null) {
if (ItemConstants.isThrowingStar(item.getItemId()) && item.getQuantity() >= 200) {
projectile = item.getItemId();
break;
}
}
}
if (projectile == 0) {
return false;
} else {
MapleInventoryManipulator.removeById(applyto.getClient(), MapleInventoryType.USE, projectile, 200, false, true);
}
}
SummonMovementType summonMovementType = getSummonMovementType();
if (overTime || isCygnusFA() || summonMovementType != null) {
if (summonMovementType != null && pos != null) {
if (summonMovementType.getValue() == summonMovementType.STATIONARY.getValue())
applyto.cancelBuffStats(MapleBuffStat.PUPPET);
else
applyto.cancelBuffStats(MapleBuffStat.SUMMON);
}
applyBuffEffect(applyfrom, applyto, primary);
}
if (primary && (overTime || isHeal())) {
applyBuff(applyfrom, useMaxRange);
}
if (primary && isMonsterBuff()) {
applyMonsterBuff(applyfrom);
}
if (this.getFatigue() != 0) {
applyto.getMount().setTiredness(applyto.getMount().getTiredness() + this.getFatigue());
}
if (summonMovementType != null && pos != null) {
final MapleSummon tosummon = new MapleSummon(applyfrom, sourceid, pos, summonMovementType);
applyfrom.getMap().spawnSummon(tosummon);
applyfrom.addSummon(sourceid, tosummon);
tosummon.addHP(x);
if (isBeholder()) {
tosummon.addHP(1);
}
}
if (isMagicDoor() && !FieldLimit.DOOR.check(applyto.getMap().getFieldLimit())) {
// Magic Door
int y = applyto.getFh();
if (y == 0) {
y = applyto.getPosition().y;
}
Point doorPosition = new Point(applyto.getPosition().x, y);
MapleDoor door = new MapleDoor(applyto, doorPosition);
if (door.getOwnerId() >= 0) {
if (applyto.getParty() != null) {
for (MaplePartyCharacter partyMember : applyto.getParty().getMembers()) {
partyMember.getPlayer().addDoor(door.getOwnerId(), door);
partyMember.addDoor(door.getOwnerId(), door);
}
applyto.silentPartyUpdate();
} else {
applyto.addDoor(door.getOwnerId(), door);
}
door.getTarget().spawnDoor(door.getAreaDoor());
door.getTown().spawnDoor(door.getTownDoor());
applyto.disableDoorSpawn();
} else {
MapleInventoryManipulator.addFromDrop(applyto.getClient(), new Item(4006000, (short) 0, (short) 1), false);
if (door.getOwnerId() == -3)
applyto.dropMessage(5, "Mystic Door cannot be cast far from a spawn point. Nearest one is at " + door.getDoorStatus().getRight() + "pts " + door.getDoorStatus().getLeft());
else if (door.getOwnerId() == -2)
applyto.dropMessage(5, "Mystic Door cannot be cast on a slope, try elsewhere.");
else
applyto.dropMessage(5, "There are no door portals available for the town at this moment. Try again later.");
// cancel door buff
applyto.cancelBuffStats(MapleBuffStat.SOULARROW);
}
} else if (isMist()) {
Rectangle bounds = calculateBoundingBox(sourceid == NightWalker.POISON_BOMB ? pos : applyfrom.getPosition(), applyfrom.isFacingLeft());
MapleMist mist = new MapleMist(bounds, applyfrom, this);
applyfrom.getMap().spawnMist(mist, getDuration(), mist.isPoisonMist(), false, mist.isRecoveryMist());
} else if (isTimeLeap()) {
applyto.removeAllCooldownsExcept(Buccaneer.TIME_LEAP, true);
} else if (isHyperBody() && !primary) {
applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.removePlayerFromMap(applyto.getId()), false);
applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.spawnPlayerMapObject(applyto), false);
}
return true;
}
use of client.inventory.MapleInventory in project HeavenMS by ronancpl.
the class MapleItemInformationProvider method canWearEquipment.
public Collection<Item> canWearEquipment(MapleCharacter chr, Collection<Item> items) {
MapleInventory inv = chr.getInventory(MapleInventoryType.EQUIPPED);
if (inv.checked()) {
return items;
}
Collection<Item> itemz = new LinkedList<>();
if (chr.getJob() == MapleJob.SUPERGM || chr.getJob() == MapleJob.GM) {
for (Item item : items) {
Equip equip = (Equip) item;
equip.wear(true);
itemz.add(item);
}
return itemz;
}
boolean highfivestamp = false;
/* Removed because players shouldn't even get this, and gm's should just be gm job.
try {
for (Pair<Item, MapleInventoryType> ii : ItemFactory.INVENTORY.loadItems(chr.getId(), false)) {
if (ii.getRight() == MapleInventoryType.CASH) {
if (ii.getLeft().getItemId() == 5590000) {
highfivestamp = true;
}
}
}
} catch (SQLException ex) {
ex.printStackTrace();
}*/
int tdex = chr.getDex(), tstr = chr.getStr(), tint = chr.getInt(), tluk = chr.getLuk(), fame = chr.getFame();
if (chr.getJob() != MapleJob.SUPERGM || chr.getJob() != MapleJob.GM) {
for (Item item : inv.list()) {
Equip equip = (Equip) item;
tdex += equip.getDex();
tstr += equip.getStr();
tluk += equip.getLuk();
tint += equip.getInt();
}
}
for (Item item : items) {
Equip equip = (Equip) item;
int reqLevel = getEquipStats(equip.getItemId()).get("reqLevel");
if (highfivestamp) {
reqLevel -= 5;
if (reqLevel < 0) {
reqLevel = 0;
}
}
/*
int reqJob = getEquipStats(equip.getItemId()).get("reqJob");
if (reqJob != 0) {
Really hard check, and not really needed in this one
Gm's should just be GM job, and players cannot change jobs.
}*/
if (reqLevel > chr.getLevel()) {
continue;
} else if (getEquipStats(equip.getItemId()).get("reqDEX") > tdex) {
continue;
} else if (getEquipStats(equip.getItemId()).get("reqSTR") > tstr) {
continue;
} else if (getEquipStats(equip.getItemId()).get("reqLUK") > tluk) {
continue;
} else if (getEquipStats(equip.getItemId()).get("reqINT") > tint) {
continue;
}
int reqPOP = getEquipStats(equip.getItemId()).get("reqPOP");
if (reqPOP > 0) {
if (getEquipStats(equip.getItemId()).get("reqPOP") > fame) {
continue;
}
}
equip.wear(true);
itemz.add(equip);
}
inv.checked(true);
return itemz;
}
Aggregations