Search in sources :

Example 1 with NewYearCardRecord

use of client.newyear.NewYearCardRecord 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 2 with NewYearCardRecord

use of client.newyear.NewYearCardRecord in project HeavenMS by ronancpl.

the class MaplePacketCreator method addNewYearInfo.

private static void addNewYearInfo(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
    Set<NewYearCardRecord> received = chr.getReceivedNewYearRecords();
    mplew.writeShort(received.size());
    for (NewYearCardRecord nyc : received) {
        encodeNewYearCard(nyc, mplew);
    }
}
Also used : NewYearCardRecord(client.newyear.NewYearCardRecord)

Example 3 with NewYearCardRecord

use of client.newyear.NewYearCardRecord in project HeavenMS by ronancpl.

the class MaplePacketCreator method encodeNewYearCardInfo.

private static void encodeNewYearCardInfo(MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
    Set<NewYearCardRecord> newyears = chr.getReceivedNewYearRecords();
    if (!newyears.isEmpty()) {
        mplew.write(1);
        mplew.writeInt(newyears.size());
        for (NewYearCardRecord nyc : newyears) {
            mplew.writeInt(nyc.getId());
        }
    } else {
        mplew.write(0);
    }
}
Also used : NewYearCardRecord(client.newyear.NewYearCardRecord)

Aggregations

NewYearCardRecord (client.newyear.NewYearCardRecord)3 MapleCharacter (client.MapleCharacter)1