Hp and Mp Pouches for Pets!

Re: [Release] Hp and Mp Pouches for Pets!

My another method, but not fully tested.

recvops.properties:
Add:
Code:
PET_ITEM = 0x81

net\sf\odinms\net\RecvPacketOpcode.java:
Add:
Code:
PET_ITEM,

net\sf\odinms\net\PacketProcessor.java:
Add in reset function:
Code:
registerHandler(RecvPacketOpcode.PET_ITEM, new PetItemHandler());

net\sf\odinms\net\channel\handler\PetItemHandler.java:
Create new file:
Code:
/*
        This file is part of the OdinMS Maple Story Server
    Copyright (C) 2008 Patrick Huy <[email protected]> 
                       Matthias Butz <[email protected]>
                       Jan Christian Meyer <[email protected]>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package net.sf.odinms.net.channel.handler;

import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;

public class PetItemHandler extends AbstractMovementPacketHandler {

        private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MovePetHandler.class);

        @Override
        public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
                log.info(slea.toString());
                int petId = slea.readInt();
                slea.skip(5);
                slea.readInt();

                byte slot = (byte)slea.readShort();
                int itemid = slea.readInt();

                MapleCharacter player = c.getPlayer();
                MapleInventory use = player.getInventory(MapleInventoryType.USE);
                MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();


                if (use.getItem(slot) != null && use.getItem(slot).getItemId() == itemid) {
                        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short)1, false, true);
                        mii.getItemEffect(itemid).applyTo(player);
                }
                c.getSession().write(MaplePacketCreator.enableActions());
        }
}
 
Last edited:
Re: [Release] Hp and Mp Pouches for Pets!

My another method, but not fully tested.

recvops.properties:
Add:
Code:
PET_ITEM = 0x81
net\sf\odinms\net\RecvPacketOpcode.java:
Add:
Code:
PET_ITEM,
net\sf\odinms\net\PacketProcessor.java:
Add in reset function:
Code:
registerHandler(RecvPacketOpcode.PET_ITEM, new PetItemHandler());
net\sf\odinms\net\channel\handler\PetItemHandler.java:
Create new file:
Code:
/*
        This file is part of the OdinMS Maple Story Server
    Copyright (C) 2008 Patrick Huy <[email protected]> 
                       Matthias Butz <[email protected]>
                       Jan Christian Meyer <[email protected]>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package net.sf.odinms.net.channel.handler;

import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;

public class PetItemHandler extends AbstractMovementPacketHandler {

        // private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MovePetHandler.class);

        @Override
        public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
                int petId = slea.readInt();
        slea.skip(5);
                slea.readInt();

        byte slot = (byte)slea.readShort();
        int itemid = slea.readInt();

                MapleCharacter player = c.getPlayer();
                MapleInventory use = player.getInventory(MapleInventoryType.USE);
                MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();


                if (use.getItem(slot).getItemId() == itemid) {
            MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(itemid), itemid, 1, true, false);
                        use.removeItem(slot);
            mii.getItemEffect(itemid).applyTo(player);
                }
        }
}


Looks Weird =P Make Your Own Topic on it
 
Re: [Release] Hp and Mp Pouches for Pets!

My another method, but not fully tested.

recvops.properties:
Add:
Code:
PET_ITEM = 0x81

net\sf\odinms\net\RecvPacketOpcode.java:
Add:
Code:
PET_ITEM,

net\sf\odinms\net\PacketProcessor.java:
Add in reset function:
Code:
registerHandler(RecvPacketOpcode.PET_ITEM, new PetItemHandler());

net\sf\odinms\net\channel\handler\PetItemHandler.java:
Create new file:
Code:
/*
        This file is part of the OdinMS Maple Story Server
    Copyright (C) 2008 Patrick Huy <[email protected]> 
                       Matthias Butz <[email protected]>
                       Jan Christian Meyer <[email protected]>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package net.sf.odinms.net.channel.handler;

import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;

public class PetItemHandler extends AbstractMovementPacketHandler {

        // private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(MovePetHandler.class);

        @Override
        public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
                int petId = slea.readInt();
		slea.skip(5);
                slea.readInt();

		byte slot = (byte)slea.readShort();
		int itemid = slea.readInt();

                MapleCharacter player = c.getPlayer();
                MapleInventory use = player.getInventory(MapleInventoryType.USE);
                MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();


                if (use.getItem(slot).getItemId() == itemid) {
			MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(itemid), itemid, 1, true, false);
                        use.removeItem(slot);
			mii.getItemEffect(itemid).applyTo(player);
                }
        }
}

That way works awesome! The only issue I had was that it was taking two potions everytime it triggered. All I did to fix that was comment out the "use.removeItem(slot);" line, and it worked perfectly.

One other thing, it doesn't save which potions I've set up if I log off and log back in. Any clue how to get it to store that information with the rest of the character's equipment?
 
Re: [Release] Hp and Mp Pouches for Pets!

Love this release! I tweaked it a little though, and thought others might be interested. Here's what I did:

At the top of MapleCharacter.java, along with the other private variables, insert:
Code:
        // Auto-HP Potion Pouch/Auto-MP Potion Pouch related information
        private int Ahppot;
        private int Amppot;
        private int charId;
        private Boolean hpp = false;
        private Boolean mpp = false;

And at the bottom of MapleCharacter.java above the last }, I inserted:
Code:
        public void AutoHpMp() {

        MapleCharacter player = client.getPlayer();
        MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();

        if (client.getPlayer().getInventory(MapleInventoryType.EQUIPPED).findById(1812002) != null) {
            hpp = true;
        }
        if (client.getPlayer().getInventory(MapleInventoryType.EQUIPPED).findById(1812003) != null) {
            mpp = true;
        }
        if (hpp || mpp) {
            if (hpp) {
                charId = player.getId();
                try {
                    Connection con = DatabaseConnection.getConnection();
                    PreparedStatement ps = con.prepareStatement("SELECT action FROM keymap WHERE characterid = ? AND keymap.key = 12");
                    ps.setInt(1, charId);
                    ResultSet rs = ps.executeQuery();
                    while (rs.next()) {
                        Ahppot = rs.getInt("action");
                    }
                    ps.close();
                    rs.close();
                } catch (SQLException e) {
                }

                if (player.getHp() > 0) {
                    if (player.getHp() < (player.getCurrentMaxHp() * 0.25)) {
                        if (player.haveItem(Ahppot)) {
                            MapleInventoryManipulator.removeById(client, MapleItemInformationProvider.getInstance().getInventoryType(Ahppot), Ahppot, 1, true, false);
                            mii.getItemEffect(Ahppot).applyTo(client.getPlayer());
                        }
                    }
                }
            }

            if (mpp) {
                charId = player.getId();
                try {
                    Connection con = DatabaseConnection.getConnection();
                    PreparedStatement ps = con.prepareStatement("SELECT * FROM keymap WHERE characterid = ? AND keymap.key = 13");
                    ps.setInt(1, charId);
                    ResultSet rs = ps.executeQuery();
                    while (rs.next()) {
                        Amppot = rs.getInt("action");
                    }
                    ps.close();
                    rs.close();
                } catch (SQLException e) {
                }

                if (player.getMp() < (player.getCurrentMaxMp() * 0.25)) {
                    if (player.haveItem(Amppot)) {
                        MapleInventoryManipulator.removeById(client, MapleItemInformationProvider.getInstance().getInventoryType(Amppot), Amppot, 1, true, false);
                        mii.getItemEffect(Amppot).applyTo(client.getPlayer());
                    }
                }
            }
        }
    }

Instead of inserting all the code into MaplePetHandler.java, I just inserted this above the last two } :
Code:
        player.AutoHpMp();

Also, while I was testing, I found that the occasional delay with healing was pretty bad, so I also modified the TakeDamageHandler.java file. Here's the original:
Code:
				}				
				player.addHP(-damage);
			} else {
				player.addHP(-damage);
			}

And here's what I added:
Code:
				}				
				player.addHP(-damage);
                                player.AutoHpMp();
			} else {
				player.addHP(-damage);
                                player.AutoHpMp();
			}

Overall, what I did was made it so that the AutoHpMp is coded to use the potions when the character is below 25% Hp or Mp. For the AutoHp, it uses whatever potion is assigned to the - key. The AutoMp part of it will use whatever potion is assigned to the = key.

Also, to avoid players having to log out to save the keymap changes to the DB, I added this to the KeymapChangeHandler above the last two } :
Code:
                player.saveToDB(true);

Feel free to clean up my work, re-post or whatever, but definitely give credits to the original release (xcheater3161), and me for the little bit of tweaking I did. ;)

but i cant find MaplePetHandler.java anywhere? pls advise lol
 
Re: [Release] Hp and Mp Pouches for Pets!

Why i add
Code:
if (splitted[0].equals("#sethp"))
                        {
                            if (splitted.length > 1)
                {
                    int hp = Integer.parseInt(splitted[1]);
                                        player.setAuto("hp", hp);
                                        mc.dropMessage("You will be automatically healed if your hp goes below "+hp+"");
                        }
                        }
                        
                        else if (splitted[0].equals("#setmp"))
                        {
                            if (splitted.length > 1)
                {
                    int mp = Integer.parseInt(splitted[1]);
                                        player.setAuto("mp", mp);
                                        mc.dropMessage("You will be automatically healed if your mp goes below "+mp+"");
                        }
                        }
then got errors? other than that dun have
 
Re: [Release] Hp and Mp Pouches for Pets!

I got this error zzz

init:
deps-jar:
Compiling 1 source file to D:\Documents\odinms\build\classes
C:\Users\Yao Wei\Desktop\Ems Repack\Ems Repack\src\net\sf\odinms\client\messages\CommandProcessor.java:313: cannot find symbol
symbol : method setAuto(java.lang.String,int)
location: class net.sf.odinms.client.MapleCharacter
player.setAuto("hp", hp);
C:\Users\Yao Wei\Desktop\Ems Repack\Ems Repack\src\net\sf\odinms\client\messages\CommandProcessor.java:323: cannot find symbol
symbol : method setAuto(java.lang.String,int)
location: class net.sf.odinms.client.MapleCharacter
player.setAuto("mp", mp);
 
Back