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