Search in sources :

Example 1 with MaplePet

use of client.inventory.MaplePet in project HeavenMS by ronancpl.

the class MapleCharacter method runFullnessSchedule.

public void runFullnessSchedule(int petSlot) {
    MaplePet pet = getPet(petSlot);
    if (pet == null)
        return;
    int newFullness = pet.getFullness() - PetDataFactory.getHunger(pet.getItemId());
    if (newFullness <= 5) {
        pet.setFullness(15);
        pet.saveToDb();
        unequipPet(pet, true);
        dropMessage(6, "Your pet grew hungry! Treat it some pet food to keep it healthy!");
    } else {
        pet.setFullness(newFullness);
        pet.saveToDb();
        Item petz = getInventory(MapleInventoryType.CASH).getItem(pet.getPosition());
        if (petz != null) {
            forceUpdateItem(petz);
        }
    }
}
Also used : MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) MaplePet(client.inventory.MaplePet) Point(java.awt.Point)

Example 2 with MaplePet

use of client.inventory.MaplePet in project HeavenMS by ronancpl.

the class PetCommandHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    int petId = slea.readInt();
    byte petIndex = chr.getPetIndex(petId);
    MaplePet pet;
    if (petIndex == -1) {
        return;
    } else {
        pet = chr.getPet(petIndex);
    }
    slea.readInt();
    slea.readByte();
    byte command = slea.readByte();
    PetCommand petCommand = PetDataFactory.getPetCommand(pet.getItemId(), (int) command);
    if (petCommand == null) {
        return;
    }
    if (Randomizer.nextInt(101) <= petCommand.getProbability()) {
        pet.gainClosenessFullness(chr, petCommand.getIncrease(), 0, command);
    } else {
        chr.getMap().broadcastMessage(MaplePacketCreator.commandResponse(chr.getId(), petIndex, command, false));
        if (chr.getMount() != null)
            chr.getMap().broadcastMessage(MaplePacketCreator.updateMount(chr.getId(), chr.getMount(), false));
    }
}
Also used : MapleCharacter(client.MapleCharacter) PetCommand(client.inventory.PetCommand) MaplePet(client.inventory.MaplePet)

Example 3 with MaplePet

use of client.inventory.MaplePet in project HeavenMS by ronancpl.

the class PetExcludeItemsHandler method handlePacket.

public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final int petId = slea.readInt();
    slea.skip(4);
    MapleCharacter chr = c.getPlayer();
    byte petIndex = (byte) chr.getPetIndex(petId);
    if (petIndex < 0)
        return;
    final MaplePet pet = chr.getPet(petIndex);
    if (pet == null) {
        return;
    }
    chr.resetExcluded(petId);
    byte amount = slea.readByte();
    for (int i = 0; i < amount; i++) {
        chr.addExcluded(petId, slea.readInt());
    }
    chr.commitExcludedItems();
}
Also used : MapleCharacter(client.MapleCharacter) MaplePet(client.inventory.MaplePet)

Example 4 with MaplePet

use of client.inventory.MaplePet in project HeavenMS by ronancpl.

the class PetFoodHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    AutobanManager abm = chr.getAutobanManager();
    if (abm.getLastSpam(2) + 500 > System.currentTimeMillis()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    abm.spam(2);
    abm.setTimestamp(1, slea.readInt(), 3);
    if (chr.getNoPets() == 0) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    int previousFullness = 100;
    byte slot = 0;
    MaplePet[] pets = chr.getPets();
    for (byte i = 0; i < 3; i++) {
        if (pets[i] != null) {
            if (pets[i].getFullness() < previousFullness) {
                slot = i;
                previousFullness = pets[i].getFullness();
            }
        }
    }
    MaplePet pet = chr.getPet(slot);
    if (pet == null)
        return;
    short pos = slea.readShort();
    int itemId = slea.readInt();
    Item use = chr.getInventory(MapleInventoryType.USE).getItem(pos);
    if (use == null || (itemId / 10000) != 212 || use.getItemId() != itemId) {
        return;
    }
    // 50% chance to get +1 closeness
    pet.gainClosenessFullness(chr, (Randomizer.nextInt(101) <= 50) ? 1 : 0, 30, 1);
    MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, pos, (short) 1, false);
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) AutobanManager(client.autoban.AutobanManager) MaplePet(client.inventory.MaplePet)

Example 5 with MaplePet

use of client.inventory.MaplePet in project HeavenMS by ronancpl.

the class SpawnPetHandler method handlePacket.

public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    slea.readInt();
    byte slot = slea.readByte();
    slea.readByte();
    boolean lead = slea.readByte() == 1;
    MaplePet pet = chr.getInventory(MapleInventoryType.CASH).getItem(slot).getPet();
    if (pet == null)
        return;
    int petid = pet.getItemId();
    if (// Handles Dragon AND Robos
    petid == 5000028 || petid == 5000047) {
        if (chr.haveItem(petid + 1)) {
            chr.dropMessage(5, "You can't hatch your " + (petid == 5000028 ? "Dragon egg" : "Robo egg") + " if you already have a Baby " + (petid == 5000028 ? "Dragon." : "Robo."));
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else {
            int evolveid = MapleDataTool.getInt("info/evol1", dataRoot.getData("Pet/" + petid + ".img"));
            int petId = MaplePet.createPet(evolveid);
            if (petId == -1) {
                return;
            }
            long expiration = chr.getInventory(MapleInventoryType.CASH).getItem(slot).getExpiration();
            MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, petid, (short) 1, false, false);
            MapleInventoryManipulator.addById(c, evolveid, (short) 1, null, petId, expiration);
            pet.deleteFromDb();
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
    }
    if (chr.getPetIndex(pet) != -1) {
        chr.unequipPet(pet, true);
    } else {
        if (chr.getSkillLevel(SkillFactory.getSkill(8)) == 0 && chr.getPet(0) != null) {
            chr.unequipPet(chr.getPet(0), false);
        }
        if (lead) {
            chr.shiftPetsRight();
        }
        Point pos = chr.getPosition();
        pos.y -= 12;
        pet.setPos(pos);
        pet.setFh(chr.getMap().getFootholds().findBelow(pet.getPos()).getId());
        pet.setStance(0);
        pet.setSummoned(true);
        pet.saveToDb();
        chr.addPet(pet);
        chr.getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showPet(c.getPlayer(), pet, false, false), true);
        c.announce(MaplePacketCreator.petStatUpdate(c.getPlayer()));
        c.announce(MaplePacketCreator.enableActions());
        chr.commitExcludedItems();
        chr.getClient().getWorldServer().registerPetHunger(chr, chr.getPetIndex(pet));
    }
}
Also used : MapleCharacter(client.MapleCharacter) Point(java.awt.Point) MaplePet(client.inventory.MaplePet) Point(java.awt.Point)

Aggregations

MaplePet (client.inventory.MaplePet)17 Item (client.inventory.Item)9 Point (java.awt.Point)9 MapleCharacter (client.MapleCharacter)7 MapleMapItem (server.maps.MapleMapItem)5 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)5 Equip (client.inventory.Equip)4 SQLException (java.sql.SQLException)3 MapleItemInformationProvider (server.MapleItemInformationProvider)3 Pair (tools.Pair)3 AutobanManager (client.autoban.AutobanManager)2 MapleInventoryType (client.inventory.MapleInventoryType)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 MapleAlliance (net.server.guild.MapleAlliance)2 MapleGuild (net.server.guild.MapleGuild)2 MaplePartyCharacter (net.server.world.MaplePartyCharacter)2 CashItem (server.CashShop.CashItem)2 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)2 BuddylistEntry (client.BuddylistEntry)1