Search in sources :

Example 16 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class ItemPickupHandler method handlePacket.

@Override
public final void handlePacket(final SeekableLittleEndianAccessor slea, final MapleClient c) {
    // Timestamp
    slea.readInt();
    slea.readByte();
    // cpos
    slea.readPos();
    int oid = slea.readInt();
    MapleCharacter chr = c.getPlayer();
    MapleMapObject ob = chr.getMap().getMapObject(oid);
    chr.pickupItem(ob);
}
Also used : MapleCharacter(client.MapleCharacter) MapleMapObject(server.maps.MapleMapObject)

Example 17 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class NewYearCardHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final MapleCharacter player = c.getPlayer();
    // [00] -> NewYearReq (0 = Send)
    byte reqMode = slea.readByte();
    if (reqMode == 0) {
        // card has been sent
        if (player.haveItem(2160101)) {
            // new year's card
            // [00 2C] -> nPOS (Item Slot Pos)
            short slot = slea.readShort();
            // [00 20 F5 E5] -> nItemID (item id)
            int itemid = slea.readInt();
            int status = getValidNewYearCardStatus(itemid, player, slot);
            if (status == 0) {
                if (player.canHold(4300000, 1)) {
                    // [04 00 54 65 73 74] -> sReceiverName (person to send to)
                    String receiver = slea.readMapleAsciiString();
                    int receiverid = getReceiverId(receiver, c.getWorld());
                    if (receiverid != -1) {
                        if (receiverid != c.getPlayer().getId()) {
                            // [06 00 4C 65 74 74 65 72] -> sContent (message)
                            String message = slea.readMapleAsciiString();
                            NewYearCardRecord newyear = new NewYearCardRecord(player.getId(), player.getName(), receiverid, receiver, message);
                            NewYearCardRecord.saveNewYearCard(newyear);
                            player.addNewYearRecord(newyear);
                            player.getClient().getAbstractPlayerInteraction().gainItem(2160101, (short) -1);
                            player.getClient().getAbstractPlayerInteraction().gainItem(4300000, (short) 1);
                            Server.getInstance().setNewYearCard(newyear);
                            newyear.startNewYearCardTask();
                            // successfully sent
                            player.announce(MaplePacketCreator.onNewYearCardRes(player, newyear, 4, 0));
                        } else {
                            // cannot send to yourself
                            player.announce(MaplePacketCreator.onNewYearCardRes(player, -1, 5, 0xF));
                        }
                    } else {
                        // cannot find such character
                        player.announce(MaplePacketCreator.onNewYearCardRes(player, -1, 5, 0x13));
                    }
                } else {
                    // inventory full
                    player.announce(MaplePacketCreator.onNewYearCardRes(player, -1, 5, 0x10));
                }
            } else {
                // item and inventory errors
                player.announce(MaplePacketCreator.onNewYearCardRes(player, -1, 5, status));
            }
        } else {
            // have no card to send
            player.announce(MaplePacketCreator.onNewYearCardRes(player, -1, 5, 0x11));
        }
    } else {
        // receiver accepted the card
        int cardid = slea.readInt();
        NewYearCardRecord newyear = NewYearCardRecord.loadNewYearCard(cardid);
        if (newyear != null && newyear.getReceiverId() == player.getId() && !newyear.isReceiverCardReceived()) {
            if (!newyear.isSenderCardDiscarded()) {
                if (player.canHold(4301000, 1)) {
                    newyear.stopNewYearCardTask();
                    NewYearCardRecord.updateNewYearCard(newyear);
                    player.getClient().getAbstractPlayerInteraction().gainItem(4301000, (short) 1);
                    if (!newyear.getMessage().isEmpty())
                        player.dropMessage(6, "[NEW YEAR] " + newyear.getSenderName() + ": " + newyear.getMessage());
                    player.addNewYearRecord(newyear);
                    // successfully rcvd
                    player.announce(MaplePacketCreator.onNewYearCardRes(player, newyear, 6, 0));
                    player.getMap().broadcastMessage(MaplePacketCreator.onNewYearCardRes(player, newyear, 0xD, 0));
                    MapleCharacter sender = c.getWorldServer().getPlayerStorage().getCharacterById(newyear.getSenderId());
                    if (sender != null && sender.isLoggedin() && !sender.isAwayFromWorld()) {
                        sender.getMap().broadcastMessage(MaplePacketCreator.onNewYearCardRes(sender, newyear, 0xD, 0));
                        sender.dropMessage(6, "[NEW YEAR] Your addressee successfully received the New Year card.");
                    }
                } else {
                    // inventory full
                    player.announce(MaplePacketCreator.onNewYearCardRes(player, -1, 5, 0x10));
                }
            } else {
                player.dropMessage(6, "[NEW YEAR] The sender of the New Year card already dropped it. Nothing to receive.");
            }
        } else {
            if (newyear == null) {
                player.dropMessage(6, "[NEW YEAR] The sender of the New Year card already dropped it. Nothing to receive.");
            }
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) NewYearCardRecord(client.newyear.NewYearCardRecord)

Example 18 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class PartyOperationHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    int operation = slea.readByte();
    MapleCharacter player = c.getPlayer();
    World world = c.getWorldServer();
    MapleParty party = player.getParty();
    MaplePartyCharacter partyplayer = player.getMPC();
    switch(operation) {
        case 1:
            {
                // create
                if (player.getLevel() < 10 && !ServerConstants.USE_PARTY_FOR_STARTERS) {
                    c.announce(MaplePacketCreator.partyStatusMessage(10));
                    return;
                }
                if (player.getParty() == null) {
                    partyplayer = new MaplePartyCharacter(player);
                    party = world.createParty(partyplayer);
                    player.setParty(party);
                    player.setMPC(partyplayer);
                    player.getMap().addPartyMember(player);
                    player.silentPartyUpdate();
                    c.announce(MaplePacketCreator.partyCreated(partyplayer));
                } else {
                    c.announce(MaplePacketCreator.serverNotice(5, "You can't create a party as you are already in one."));
                }
                break;
            }
        case 2:
            {
                // leave/disband
                leaveParty(party, partyplayer, c);
                break;
            }
        case 3:
            {
                // join
                int partyid = slea.readInt();
                if (c.getPlayer().getParty() == null) {
                    party = world.getParty(partyid);
                    if (party != null) {
                        if (party.getMembers().size() < 6) {
                            partyplayer = new MaplePartyCharacter(player);
                            player.getMap().addPartyMember(player);
                            world.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
                            player.receivePartyMemberHP();
                            player.updatePartyMemberHP();
                        } else {
                            c.announce(MaplePacketCreator.partyStatusMessage(17));
                        }
                    } else {
                        c.announce(MaplePacketCreator.serverNotice(5, "The person you have invited to the party is already in one."));
                    }
                } else {
                    c.announce(MaplePacketCreator.serverNotice(5, "You can't join the party as you are already in one."));
                }
                break;
            }
        case 4:
            {
                // invite
                String name = slea.readMapleAsciiString();
                MapleCharacter invited = world.getPlayerStorage().getCharacterByName(name);
                if (invited != null) {
                    if (invited.getLevel() < 10 && (!ServerConstants.USE_PARTY_FOR_STARTERS || player.getLevel() >= 10)) {
                        // min requirement is level 10
                        c.announce(MaplePacketCreator.serverNotice(5, "The player you have invited does not meet the requirements."));
                        return;
                    }
                    if (ServerConstants.USE_PARTY_FOR_STARTERS && invited.getLevel() >= 10 && player.getLevel() < 10) {
                        // trying to invite high level
                        c.announce(MaplePacketCreator.serverNotice(5, "The player you have invited does not meet the requirements."));
                        return;
                    }
                    if (invited.getParty() == null) {
                        if (player.getParty() == null) {
                            if (player.getLevel() < 10 && !ServerConstants.USE_PARTY_FOR_STARTERS) {
                                c.announce(MaplePacketCreator.partyStatusMessage(10));
                                return;
                            }
                            partyplayer = new MaplePartyCharacter(player);
                            party = world.createParty(partyplayer);
                            player.setParty(party);
                            player.setMPC(partyplayer);
                            player.getMap().addPartyMember(player);
                            c.announce(MaplePacketCreator.partyCreated(partyplayer));
                        }
                        if (party.getMembers().size() < 6) {
                            invited.getClient().announce(MaplePacketCreator.partyInvite(player));
                        } else {
                            c.announce(MaplePacketCreator.partyStatusMessage(17));
                        }
                    } else {
                        c.announce(MaplePacketCreator.partyStatusMessage(16));
                    }
                } else {
                    c.announce(MaplePacketCreator.partyStatusMessage(19));
                }
                break;
            }
        case 5:
            {
                // expel
                int cid = slea.readInt();
                if (partyplayer.equals(party.getLeader())) {
                    MaplePartyCharacter expelled = party.getMemberById(cid);
                    if (expelled != null) {
                        MapleCharacter emc = expelled.getPlayer();
                        if (emc != null) {
                            MapleMap map = emc.getMap();
                            if (map != null)
                                map.removePartyMember(emc);
                            EventInstanceManager eim = emc.getEventInstance();
                            if (eim != null) {
                                eim.leftParty(emc);
                            }
                            emc.setParty(null);
                        }
                        world.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
                    }
                }
                break;
            }
        case 6:
            {
                // change leader
                int newLeader = slea.readInt();
                MaplePartyCharacter newLeadr = party.getMemberById(newLeader);
                world.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
                break;
            }
    }
}
Also used : MapleMap(server.maps.MapleMap) MapleCharacter(client.MapleCharacter) EventInstanceManager(scripting.event.EventInstanceManager) MapleParty(net.server.world.MapleParty) World(net.server.world.World) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Example 19 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class PetAutoPotHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!c.getPlayer().isAlive()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    slea.readByte();
    slea.readLong();
    slea.readInt();
    slot = slea.readShort();
    itemId = slea.readInt();
    MapleCharacter chr = c.getPlayer();
    toUse = chr.getInventory(MapleInventoryType.USE).getItem(slot);
    if (toUse != null) {
        if (toUse.getItemId() != itemId) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        toUseList = null;
        // from now on, toUse becomes the "cursor" for the current pot being used
        if (toUse.getQuantity() <= 0) {
            if (!cursorOnNextAvailablePot(chr)) {
                c.announce(MaplePacketCreator.enableActions());
                return;
            }
        }
        MapleStatEffect stat = MapleItemInformationProvider.getInstance().getItemEffect(toUse.getItemId());
        hasHpGain = stat.getHp() > 0 || stat.getHpRate() > 0.0;
        hasMpGain = stat.getMp() > 0 || stat.getMpRate() > 0.0;
        // contabilize the HP and MP gains from equipments on one's effective MaxHP/MaxMP
        Pair<Short, Short> maxHpMp = calcEffectivePool(chr);
        maxHp = maxHpMp.left;
        maxMp = maxHpMp.right;
        incHp = stat.getHp();
        if (incHp <= 0 && hasHpGain)
            incHp = (short) ((maxHp * stat.getHpRate()) / 100.0);
        incMp = stat.getMp();
        if (incMp <= 0 && hasMpGain)
            incMp = (short) ((maxMp * stat.getMpRate()) / 100.0);
        curHp = chr.getHp();
        curMp = chr.getMp();
        // System.out.println("\n-------------------\n");
        while (true) {
            do {
                MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
                stat.applyTo(chr);
                curHp += incHp;
                curMp += incMp;
            // System.out.println();
            // System.out.println("hp: " + hasHpGain + " player hp " + curHp + " maxhp " + maxHp);
            // System.out.println("mp: " + hasMpGain + " player mp " + curMp + " maxmp " + maxMp);
            // System.out.println("redo? " + (shouldReusePot(chr) && toUse.getQuantity() > 0));
            } while (shouldReusePot(chr) && toUse.getQuantity() > 0);
            if (toUse.getQuantity() == 0 && shouldReusePot(chr)) {
                if (!cursorOnNextAvailablePot(chr)) {
                    // no more pots available
                    break;
                }
            } else {
                // gracefully finished it's job, quit the loop
                break;
            }
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) MapleStatEffect(server.MapleStatEffect)

Example 20 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MonsterCarnivalHandler method handlePacket.

public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    MonsterCarnival carnival = chr.getCarnival();
    int tab = slea.readByte();
    int number = slea.readShort();
    if (carnival != null) {
        if (chr.getCarnivalParty() != carnival.getPartyRed() || chr.getCarnivalParty() != carnival.getPartyBlue()) {
            chr.getMap().broadcastMessage(MaplePacketCreator.leaveCPQ(chr));
            chr.changeMap(980000010);
        }
        if (chr.getCP() > getPrice(tab, number)) {
            if (tab == 0) {
                // SPAWNING
                if (chr.getCarnivalParty().canSummon()) {
                    chr.getMap().spawnCPQMonster(MapleLifeFactory.getMonster(getMonster(number)), new Point(1, 1), carnival.oppositeTeam(chr.getCarnivalParty()).getTeam());
                    chr.getCarnivalParty().summon();
                } else
                    chr.announce(MaplePacketCreator.CPQMessage((byte) 2));
            } else if (tab == 1) {
            } else if (tab == 2) {
                int rid = 9980000 + chr.getTeam();
                MapleReactor reactor = new MapleReactor(MapleReactorFactory.getReactor(rid), rid);
                /*switch (number) {
                            case 0:
                                reactor.setMonsterStatus(tab, MonsterStatus.WEAPON_ATTACK_UP, MobSkillFactory.getMobSkill(150, 1));
                                break;
                            case 1:
                                reactor.setMonsterStatus(tab, MonsterStatus.WEAPON_DEFENSE_UP, MobSkillFactory.getMobSkill(151, 1));
                                break;
                            case 2:
                                reactor.setMonsterStatus(tab, MonsterStatus.MAGIC_ATTACK_UP, MobSkillFactory.getMobSkill(152, 1));
                                break;
                            case 3:
                                reactor.setMonsterStatus(tab, MonsterStatus.MAGIC_DEFENSE_UP, MobSkillFactory.getMobSkill(153, 1));
                                break;
                            case 4:
                                reactor.setMonsterStatus(tab, MonsterStatus.ACC, MobSkillFactory.getMobSkill(154, 1));
                                break;
                            case 5:
                                reactor.setMonsterStatus(tab, MonsterStatus.AVOID, MobSkillFactory.getMobSkill(155, 1));
                                break;
                            case 6:
                                reactor.setMonsterStatus(tab, MonsterStatus.SPEED, MobSkillFactory.getMobSkill(156, 1));
                                break;
                            case 7:
                                reactor.setMonsterStatus(tab, MonsterStatus.WEAPON_IMMUNITY, MobSkillFactory.getMobSkill(140, 1));
                                break;
                            case 8:
                                reactor.setMonsterStatus(tab, MonsterStatus.MAGIC_IMMUNITY, MobSkillFactory.getMobSkill(141, 1));
                                break;
                        } */
                chr.getMap().spawnReactor(reactor);
            }
        } else {
            chr.getMap().broadcastMessage(MaplePacketCreator.CPQMessage((byte) 1));
        }
    } else {
        chr.announce(MaplePacketCreator.CPQMessage((byte) 5));
    }
    chr.announce(MaplePacketCreator.enableActions());
}
Also used : MapleCharacter(client.MapleCharacter) MonsterCarnival(server.partyquest.MonsterCarnival) MapleReactor(server.maps.MapleReactor) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

MapleCharacter (client.MapleCharacter)163 Point (java.awt.Point)32 SQLException (java.sql.SQLException)22 Item (client.inventory.Item)21 Connection (java.sql.Connection)15 PreparedStatement (java.sql.PreparedStatement)15 MapleMonster (server.life.MapleMonster)15 MapleMapObject (server.maps.MapleMapObject)15 DatabaseConnection (tools.DatabaseConnection)15 MapleMap (server.maps.MapleMap)14 ArrayList (java.util.ArrayList)13 Skill (client.Skill)12 SpawnPoint (server.life.SpawnPoint)12 LinkedList (java.util.LinkedList)11 MapleInventory (client.inventory.MapleInventory)10 World (net.server.world.World)10 MapleStatEffect (server.MapleStatEffect)10 MapleInventoryType (client.inventory.MapleInventoryType)9 ResultSet (java.sql.ResultSet)9 MapleItemInformationProvider (server.MapleItemInformationProvider)9