public void clearslot(MapleClient c, int x) {
   MapleInventoryType type = MapleInventoryType.getByType((byte) x);
   for (byte i = 0; i < 101; i++) {
     IItem tempItem = c.getPlayer().getInventory(type).getItem(i);
     if (tempItem == null) {
       continue;
     }
     MapleInventoryManipulator.removeFromSlot(c, type, i);
   }
 }
 public void execute(MapleClient c, MessageCallback mc, String[] splitted)
     throws Exception, IllegalCommandSyntaxException {
   MapleCharacter player = c.getPlayer();
   if (splitted[0].equals("shop")) {
     MapleShopFactory sfact = MapleShopFactory.getInstance();
     MapleShop shop = sfact.getShop(getOptionalIntArg(splitted, 1, 1));
     shop.sendShop(c);
   } else if (splitted[0].equals("item")) {
     short quantity = (short) getOptionalIntArg(splitted, 2, 1);
     int itemId = Integer.parseInt(splitted[1]);
     if (ii.getSlotMax(itemId) > 0) {
       if (itemId >= 5000000 && itemId <= 5000100) {
         if (quantity > 1) {
           quantity = 1;
         }
         int petId = MaplePet.createPet(itemId);
         MapleInventoryManipulator.addById(
             c,
             itemId,
             quantity,
             c.getPlayer().getName() + "used !item with quantity " + quantity,
             player.getName(),
             petId);
         return;
       }
       MapleInventoryManipulator.addById(
           c,
           itemId,
           quantity,
           c.getPlayer().getName() + "used !item with quantity " + quantity,
           player.getName());
     } else {
       mc.dropMessage("Item " + itemId + " not found.");
     }
   } else if (splitted[0].equals("drop")) {
     int itemId = Integer.parseInt(splitted[1]);
     if (ii.getSlotMax(itemId) > 0) {
       if (SpecialStuff.getInstance().isGMBlocked(itemId) && !player.isHokage()) {
         mc.dropMessage("Sunny says you cannot drop this item");
         return;
       }
       short quantity = (short) (short) getOptionalIntArg(splitted, 2, 1);
       IItem toDrop;
       if (ii.getInventoryType(itemId) == MapleInventoryType.EQUIP) {
         toDrop = ii.getEquipById(itemId);
       } else {
         toDrop = new Item(itemId, (byte) 0, (short) quantity);
       }
       toDrop.setOwner(player.getName());
       c.getPlayer()
           .getMap()
           .spawnItemDrop(
               c.getPlayer(), c.getPlayer(), toDrop, c.getPlayer().getPosition(), true, true);
     } else {
       mc.dropMessage("The Item " + itemId + " does not exist");
     }
   } else if (splitted[0].equalsIgnoreCase("clearslot")) {
     if (splitted[1].equalsIgnoreCase("all")) {
       clearslot(c, 1);
       clearslot(c, 2);
       clearslot(c, 3);
       clearslot(c, 4);
       clearslot(c, 5);
       mc.dropMessage("All inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("eq")) {
       clearslot(c, 1);
       mc.dropMessage("Eq inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("use")) {
       clearslot(c, 2);
       mc.dropMessage("Use inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("etc")) {
       clearslot(c, 4);
       mc.dropMessage("Etc inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("setup")) {
       clearslot(c, 3);
       mc.dropMessage("Setup inventory slots cleared.");
     } else if (splitted[1].equalsIgnoreCase("cash")) {
       clearslot(c, 5);
       mc.dropMessage("Cash inventory slots cleared.");
     } else {
       mc.dropMessage("!clearslot " + splitted[1] + " does not exist!");
     }
   } else if (splitted[0].equalsIgnoreCase("omghax")) {
     short stat = 1;
     short wa = 1;
     int itemid = 1302000;
     if (splitted.length == 4) {
       try {
         itemid = Integer.parseInt(splitted[1]);
         stat = Short.parseShort(splitted[2]);
         wa = Short.parseShort(splitted[3]);
       } catch (NumberFormatException numberFormatException) {
       }
     } else if (splitted.length == 3) {
       try {
         itemid = Integer.parseInt(splitted[1]);
         stat = Short.parseShort(splitted[2]);
       } catch (NumberFormatException numberFormatException) {
       }
     } else if (splitted.length == 2) {
       try {
         itemid = Integer.parseInt(splitted[1]);
       } catch (NumberFormatException numberFormatException) {
       }
       stat = 32767;
     }
     if (itemid > 1000000 && itemid > 2000000 || ii.getSlotMax(itemid) > 0) {
       MapleInventoryManipulator.addStatItemById(c, itemid, c.getPlayer().getName(), stat, wa, wa);
     } else {
       mc.dropMessage("You have entered invalid Item ID : " + itemid);
     }
   }
 }
  /*	TODO:
   *	1. Move the equpping into a function.
   */
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    c.getPlayer().resetAfkTime();
    slea.readInt();
    byte slot = slea.readByte();
    slea.readByte();
    boolean lead = slea.readByte() == 1;
    MapleCharacter player = c.getPlayer();
    IItem item = player.getInventory(MapleInventoryType.CASH).getItem(slot);

    if (item.getItemId() == 5000028 || item.getItemId() == 5000047) {
      boolean done = false;
      int petno;
      int[] pet;
      int[] dragon = {5000029, 5000030, 5000031, 5000032, 5000033};
      int[] robot = {5000048, 5000049, 5000050, 5000051, 5000052, 5000053};

      pet = item.getItemId() == 5000028 ? dragon : robot;
      Random egg = new Random();
      for (int i = 0; i < pet.length && !done; i++) {
        petno = egg.nextInt(pet.length);
        if (!player.haveItem(pet[petno], 1, true, true)) {
          MapleInventoryManipulator.removeFromSlot(
              c, MapleInventoryType.CASH, item.getPosition(), (short) 1, true, false);
          MapleInventoryManipulator.addById(
              c, pet[petno], (short) 1, null, MaplePet.createPet(pet[petno]));
          done = true;
        }
      }
      if (!done) {
        player.dropMessage(1, "You currently have all the dragons or robots.");
        return;
      }
    }
    // New instance of MaplePet - using the item ID and unique pet ID
    MaplePet pet =
        MaplePet.loadFromDb(
            player.getInventory(MapleInventoryType.CASH).getItem(slot).getItemId(),
            slot,
            player.getInventory(MapleInventoryType.CASH).getItem(slot).getPetId());

    if (pet == null) {
      MapleInventoryManipulator.removeById(
          c, MapleInventoryType.CASH, item.getItemId(), (short) item.getQuantity(), false, false);
      c.getSession().write(MaplePacketCreator.enableActions());
      return;
    }
    // Assign the pet to the player, set stats
    if (player.getPetIndex(pet) != -1) {
      player.unequipPet(pet, true);
    } else {
      if (player.getSkillLevel(SkillFactory.getSkill(8)) == 0 && player.getPet(0) != null) {
        player.unequipPet(player.getPet(0), false);
      }
      if (lead) {
        player.shiftPetsRight();
      }
      Point pos = player.getPosition();
      pos.y -= 12;
      pet.setPos(pos);
      pet.setFh(player.getMap().getFootholds().findBelow(pet.getPos()).getId());
      pet.setStance(0);

      player.addPet(pet);
      // Broadcast packet to the map...
      player
          .getMap()
          .broadcastMessage(player, MaplePacketCreator.showPet(player, pet, false), true);
      // Find the pet's unique ID
      int uniqueid = pet.getUniqueId();
      // Make a new List for the stat update
      List<Pair<MapleStat, Integer>> stats = new ArrayList<Pair<MapleStat, Integer>>();
      stats.add(new Pair<MapleStat, Integer>(MapleStat.PET, Integer.valueOf(uniqueid)));
      // Write the stat update to the player...
      c.getSession().write(MaplePacketCreator.petStatUpdate(player));
      c.getSession().write(MaplePacketCreator.enableActions());
      // Get the data
      int hunger = PetDataFactory.getHunger(pet.getItemId());
      // Start the fullness schedule
      player.startFullnessSchedule(hunger, pet, player.getPetIndex(pet));
    }
  }
 @Override
 public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
   c.getPlayer().resetAfkTime();
   if (c.getPlayer().getNoPets() == 0) {
     return;
   }
   int slot = 0;
   MaplePet[] pets = c.getPlayer().getPets();
   for (int i = 0; i < 3; i++) {
     if (pets[i] != null) {
       if (pets[i].getFullness() < 100) {
         slot = i;
       }
     } else {
       break;
     }
   }
   MaplePet pet = c.getPlayer().getPet(slot);
   slea.readInt();
   slea.readShort();
   int itemId = slea.readInt();
   if (c.getPlayer().haveItem(itemId, 1, false, true)) {
     boolean gainCloseness = new Random().nextInt(101) <= 50;
     int newFullness = pet.getFullness() + 30;
     if (pet.getFullness() < 100) {
       if (newFullness > 100) {
         newFullness = 100;
       }
       pet.setFullness(newFullness);
       if (gainCloseness && pet.getCloseness() < 30000) {
         int newCloseness = pet.getCloseness() + (1 * c.getChannelServer().getPetExpRate());
         if (newCloseness > 30000) {
           newCloseness = 30000;
         }
         pet.setCloseness(newCloseness);
         if (newCloseness >= ExpTable.getClosenessNeededForLevel(pet.getLevel() + 1)) {
           pet.setLevel(pet.getLevel() + 1);
           c.getSession()
               .write(MaplePacketCreator.showOwnPetLevelUp(c.getPlayer().getPetIndex(pet)));
           c.getPlayer()
               .getMap()
               .broadcastMessage(
                   MaplePacketCreator.showPetLevelUp(
                       c.getPlayer(), c.getPlayer().getPetIndex(pet)));
         }
       }
     } else {
       if (gainCloseness) {
         int newCloseness = pet.getCloseness() - (1 * c.getChannelServer().getPetExpRate());
         if (newCloseness < 0) {
           newCloseness = 0;
         }
         pet.setCloseness(newCloseness);
         if (newCloseness < ExpTable.getClosenessNeededForLevel(pet.getLevel())) {
           pet.setLevel(pet.getLevel() - 1);
         }
       }
     }
     c.getSession().write(MaplePacketCreator.updatePet(pet, true));
     c.getPlayer()
         .getMap()
         .broadcastMessage(
             c.getPlayer(),
             MaplePacketCreator.commandResponse(c.getPlayer().getId(), (byte) 1, slot, true, true),
             true);
     MapleInventoryManipulator.removeById(c, MapleInventoryType.USE, itemId, 1, true, false);
   }
 }
Esempio n. 5
0
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    slea.readByte();
    slea.readInt(); // ?
    slea.readInt(); // position, but we dont need it o.o
    int oid = slea.readInt();
    MapleMapObject ob = c.getPlayer().getMap().getMapObject(oid);
    if (ob == null) {
      c.getSession().write(MaplePacketCreator.getInventoryFull());
      c.getSession().write(MaplePacketCreator.getShowInventoryFull());
      return;
    }
    if (ob instanceof MapleMapItem) {
      MapleMapItem mapitem = (MapleMapItem) ob;
      synchronized (mapitem) {
        if (mapitem.isPickedUp()) {
          c.getSession().write(MaplePacketCreator.getInventoryFull());
          c.getSession().write(MaplePacketCreator.getShowInventoryFull());
          return;
        }
        double distance = c.getPlayer().getPosition().distanceSq(mapitem.getPosition());
        c.getPlayer().getCheatTracker().checkPickupAgain();
        if (distance > 90000.0) { // 300^2, 550 is approximatly the range of ultis
          // AutobanManager.getInstance().addPoints(c, 100, 300000, "Itemvac");
          c.getPlayer().getCheatTracker().registerOffense(CheatingOffense.ITEMVAC);
          // Double.valueOf(Math.sqrt(distance))
        } else if (distance > 30000.0) {
          // log.warn("[h4x] Player {} is picking up an item that's fairly far away: {}",
          // c.getPlayer().getName(), Double.valueOf(Math.sqrt(distance)));
          c.getPlayer().getCheatTracker().registerOffense(CheatingOffense.SHORT_ITEMVAC);
        }

        if (mapitem.getMeso() > 0) {
          if (c.getPlayer().getParty() != null) {
            ChannelServer cserv = c.getChannelServer();
            int mesoAmm = mapitem.getMeso();
            int partyNum = 0;
            Collection<MaplePartyCharacter> partyMembers = c.getPlayer().getParty().getMembers();
            for (MaplePartyCharacter partyMember : partyMembers) {
              if (partyMember.getMapid() == c.getPlayer().getMapId()) {
                partyNum++;
              }
            }
            int mesoGain = mesoAmm / partyNum;
            for (MaplePartyCharacter partyMember : partyMembers) {
              if (partyMember.getMapid() == c.getPlayer().getMapId()) {
                cserv
                    .getPlayerStorage()
                    .getCharacterById(partyMember.getId())
                    .gainMeso(mesoGain, true, true);
              }
            }
          } else {
            c.getPlayer().gainMeso(mapitem.getMeso(), true, true);
          }
          c.getPlayer()
              .getMap()
              .broadcastMessage(
                  MaplePacketCreator.removeItemFromMap(
                      mapitem.getObjectId(), 2, c.getPlayer().getId()),
                  mapitem.getPosition());
          c.getPlayer().getCheatTracker().pickupComplete();
          c.getPlayer().getMap().removeMapObject(ob);
        } else {
          StringBuilder logInfo = new StringBuilder("Picked up by ");
          logInfo.append(c.getPlayer().getName());
          if (mapitem.getItem().getItemId() >= 5000000
              && mapitem.getItem().getItemId() <= 5000100) {
            int petId = MaplePet.createPet(mapitem.getItem().getItemId());
            if (petId == -1) {
              return;
            }
            MapleInventoryManipulator.addById(
                c,
                mapitem.getItem().getItemId(),
                mapitem.getItem().getQuantity(),
                "Cash Item was purchased.",
                null,
                petId);
            c.getPlayer()
                .getMap()
                .broadcastMessage(
                    MaplePacketCreator.removeItemFromMap(
                        mapitem.getObjectId(), 2, c.getPlayer().getId()),
                    mapitem.getPosition());
            c.getPlayer().getCheatTracker().pickupComplete();
            c.getPlayer().getMap().removeMapObject(ob);
          } else {
            if (MapleInventoryManipulator.addFromDrop(c, mapitem.getItem(), logInfo.toString())) {
              c.getPlayer()
                  .getMap()
                  .broadcastMessage(
                      MaplePacketCreator.removeItemFromMap(
                          mapitem.getObjectId(), 2, c.getPlayer().getId()),
                      mapitem.getPosition());
              c.getPlayer().getCheatTracker().pickupComplete();
              c.getPlayer().getMap().removeMapObject(ob);
            } else {
              c.getPlayer().getCheatTracker().pickupComplete();
              return;
            }
            if (mapitem.getItem().getItemId() == 1002357) {
              c.getPlayer().finishAchievement(13);
            }
          }
        }
        mapitem.setPickedUp(true);
      }
    }
    c.getSession().write(MaplePacketCreator.enableActions());
  }