Search in sources :

Example 76 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class World method buddyChanged.

public void buddyChanged(int cid, int cidFrom, String name, int channel, BuddyOperation operation) {
    MapleCharacter addChar = getPlayerStorage().getCharacterById(cid);
    if (addChar != null) {
        BuddyList buddylist = addChar.getBuddylist();
        switch(operation) {
            case ADDED:
                if (buddylist.contains(cidFrom)) {
                    buddylist.put(new BuddylistEntry(name, "Default Group", cidFrom, channel, true));
                    addChar.getClient().announce(MaplePacketCreator.updateBuddyChannel(cidFrom, (byte) (channel - 1)));
                }
                break;
            case DELETED:
                if (buddylist.contains(cidFrom)) {
                    buddylist.put(new BuddylistEntry(name, "Default Group", cidFrom, (byte) -1, buddylist.get(cidFrom).isVisible()));
                    addChar.getClient().announce(MaplePacketCreator.updateBuddyChannel(cidFrom, (byte) -1));
                }
                break;
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) BuddylistEntry(client.BuddylistEntry) BuddyList(client.BuddyList)

Example 77 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class ViewCharHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    try {
        short charsNum;
        List<Integer> worlds;
        List<MapleCharacter> chars;
        Connection con = DatabaseConnection.getConnection();
        try (PreparedStatement ps = con.prepareStatement("SELECT world, id FROM characters WHERE accountid = ?")) {
            ps.setInt(1, c.getAccID());
            charsNum = 0;
            worlds = new ArrayList<>();
            chars = new ArrayList<>();
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    int cworld = rs.getByte("world");
                    boolean inside = false;
                    for (int w : worlds) {
                        if (w == cworld) {
                            inside = true;
                        }
                    }
                    if (!inside) {
                        worlds.add(cworld);
                    }
                    MapleCharacter chr = MapleCharacter.loadCharFromDB(rs.getInt("id"), c, false);
                    chars.add(chr);
                    charsNum++;
                }
            }
        }
        int unk = charsNum + 3 - charsNum % 3;
        c.announce(MaplePacketCreator.showAllCharacter(charsNum, unk));
        for (Iterator<Integer> it = worlds.iterator(); it.hasNext(); ) {
            int w = it.next();
            List<MapleCharacter> chrsinworld = new ArrayList<>();
            for (MapleCharacter chr : chars) {
                if (chr.getWorld() == w) {
                    chrsinworld.add(chr);
                }
            }
            c.announce(MaplePacketCreator.showAllCharacterInfo(w, chrsinworld));
        }
        con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MapleCharacter(client.MapleCharacter) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet)

Example 78 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MaplePacketCreator method getMiniGame.

public static byte[] getMiniGame(MapleClient c, MapleMiniGame minigame, boolean owner, int piece) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.PLAYER_INTERACTION.getValue());
    mplew.write(PlayerInteractionHandler.Action.ROOM.getCode());
    mplew.write(1);
    mplew.write(0);
    mplew.write(owner ? 0 : 1);
    mplew.write(0);
    addCharLook(mplew, minigame.getOwner(), false);
    mplew.writeMapleAsciiString(minigame.getOwner().getName());
    if (minigame.getVisitor() != null) {
        MapleCharacter visitor = minigame.getVisitor();
        mplew.write(1);
        addCharLook(mplew, visitor, false);
        mplew.writeMapleAsciiString(visitor.getName());
    }
    mplew.write(0xFF);
    mplew.write(0);
    mplew.writeInt(1);
    mplew.writeInt(minigame.getOwner().getMiniGamePoints("wins", true));
    mplew.writeInt(minigame.getOwner().getMiniGamePoints("ties", true));
    mplew.writeInt(minigame.getOwner().getMiniGamePoints("losses", true));
    mplew.writeInt(2000);
    if (minigame.getVisitor() != null) {
        MapleCharacter visitor = minigame.getVisitor();
        mplew.write(1);
        mplew.writeInt(1);
        mplew.writeInt(visitor.getMiniGamePoints("wins", true));
        mplew.writeInt(visitor.getMiniGamePoints("ties", true));
        mplew.writeInt(visitor.getMiniGamePoints("losses", true));
        mplew.writeInt(2000);
    }
    mplew.write(0xFF);
    mplew.writeMapleAsciiString(minigame.getDescription());
    mplew.write(piece);
    mplew.write(0);
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MapleCharacter(client.MapleCharacter)

Example 79 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MaplePacketCreator method getHiredMerchant.

/*
         * Possible things for ENTRUSTED_SHOP_CHECK_RESULT
         * 0x0E = 00 = Renaming Failed - Can't find the merchant, 01 = Renaming succesful
         * 0x10 = Changes channel to the store (Store is open at Channel 1, do you want to change channels?)
         * 0x11 = You cannot sell any items when managing.. blabla
         * 0x12 = FKING POPUP LOL
         */
public static byte[] getHiredMerchant(MapleCharacter chr, MapleHiredMerchant hm, boolean firstTime) {
    // Thanks Dustin
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.PLAYER_INTERACTION.getValue());
    mplew.write(PlayerInteractionHandler.Action.ROOM.getCode());
    mplew.write(0x05);
    mplew.write(0x04);
    mplew.writeShort(hm.getVisitorSlotThreadsafe(chr) + 1);
    mplew.writeInt(hm.getItemId());
    mplew.writeMapleAsciiString("Hired Merchant");
    MapleCharacter[] visitors = hm.getVisitors();
    for (int i = 0; i < 3; i++) {
        if (visitors[i] != null) {
            mplew.write(i + 1);
            addCharLook(mplew, visitors[i], false);
            mplew.writeMapleAsciiString(visitors[i].getName());
        }
    }
    mplew.write(-1);
    if (hm.isOwner(chr)) {
        List<Pair<String, Byte>> msgList = hm.getMessages();
        mplew.writeShort(msgList.size());
        for (int i = 0; i < msgList.size(); i++) {
            mplew.writeMapleAsciiString(msgList.get(i).getLeft());
            mplew.write(msgList.get(i).getRight());
        }
    } else {
        mplew.writeShort(0);
    }
    mplew.writeMapleAsciiString(hm.getOwner());
    if (hm.isOwner(chr)) {
        mplew.writeInt(hm.getTimeLeft());
        mplew.write(firstTime ? 1 : 0);
        // List<SoldItem> sold = hm.getSold();
        // sold.size()
        mplew.write(0);
        /*for (SoldItem s : sold) { fix this
                     mplew.writeInt(s.getItemId());
                     mplew.writeShort(s.getQuantity());
                     mplew.writeInt(s.getMesos());
                     mplew.writeMapleAsciiString(s.getBuyer());
                     }*/
        // :D?
        mplew.writeInt(chr.getMerchantMeso());
    }
    mplew.writeMapleAsciiString(hm.getDescription());
    // TODO SLOTS, which is 16 for most stores...slotMax
    mplew.write(0x10);
    mplew.writeInt(chr.getMeso());
    mplew.write(hm.getItems().size());
    if (hm.getItems().isEmpty()) {
        // Hmm??
        mplew.write(0);
    } else {
        for (MaplePlayerShopItem item : hm.getItems()) {
            mplew.writeShort(item.getBundles());
            mplew.writeShort(item.getItem().getQuantity());
            mplew.writeInt(item.getPrice());
            addItemInfo(mplew, item.getItem(), true);
        }
    }
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MapleCharacter(client.MapleCharacter) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Point(java.awt.Point)

Example 80 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleStatEffect method applyBuff.

private void applyBuff(MapleCharacter applyfrom, boolean useMaxRange) {
    if (isPartyBuff() && (applyfrom.getParty() != null || isGmBuff())) {
        Rectangle bounds = (!useMaxRange) ? calculateBoundingBox(applyfrom.getPosition(), applyfrom.isFacingLeft()) : new Rectangle(Integer.MIN_VALUE / 2, Integer.MIN_VALUE / 2, Integer.MAX_VALUE, Integer.MAX_VALUE);
        List<MapleMapObject> affecteds = applyfrom.getMap().getMapObjectsInRect(bounds, Arrays.asList(MapleMapObjectType.PLAYER));
        List<MapleCharacter> affectedp = new ArrayList<>(affecteds.size());
        for (MapleMapObject affectedmo : affecteds) {
            MapleCharacter affected = (MapleCharacter) affectedmo;
            if (affected != applyfrom && (isGmBuff() || applyfrom.getParty().equals(affected.getParty()))) {
                if ((!isResurrection() && affected.isAlive()) || (isResurrection() && !affected.isAlive())) {
                    affectedp.add(affected);
                }
            }
        }
        for (MapleCharacter affected : affectedp) {
            applyTo(applyfrom, affected, false, null, useMaxRange);
            affected.getClient().announce(MaplePacketCreator.showOwnBuffEffect(sourceid, 2));
            affected.getMap().broadcastMessage(affected, MaplePacketCreator.showBuffeffect(affected.getId(), sourceid, 2), false);
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) MapleMapObject(server.maps.MapleMapObject)

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