Search in sources :

Example 1 with MapleInventory

use of client.inventory.MapleInventory in project HeavenMS by ronancpl.

the class MapleCharacter method saveToDB.

public synchronized void saveToDB(boolean notAutosave) {
    if (!loggedIn)
        return;
    Calendar c = Calendar.getInstance();
    if (notAutosave)
        FilePrinter.print(FilePrinter.SAVING_CHARACTER, "Attempting to save " + name + " at " + c.getTime().toString());
    else
        FilePrinter.print(FilePrinter.AUTOSAVING_CHARACTER, "Attempting to autosave " + name + " at " + c.getTime().toString());
    Connection con = null;
    try {
        con = DatabaseConnection.getConnection();
        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
        con.setAutoCommit(false);
        PreparedStatement ps;
        ps = con.prepareStatement("UPDATE characters SET level = ?, fame = ?, str = ?, dex = ?, luk = ?, `int` = ?, exp = ?, gachaexp = ?, hp = ?, mp = ?, maxhp = ?, maxmp = ?, sp = ?, ap = ?, gm = ?, skincolor = ?, gender = ?, job = ?, hair = ?, face = ?, map = ?, meso = ?, hpMpUsed = ?, spawnpoint = ?, party = ?, buddyCapacity = ?, messengerid = ?, messengerposition = ?, mountlevel = ?, mountexp = ?, mounttiredness= ?, equipslots = ?, useslots = ?, setupslots = ?, etcslots = ?,  monsterbookcover = ?, vanquisherStage = ?, dojoPoints = ?, lastDojoStage = ?, finishedDojoTutorial = ?, vanquisherKills = ?, matchcardwins = ?, matchcardlosses = ?, matchcardties = ?, omokwins = ?, omoklosses = ?, omokties = ?, dataString = ?, fquest = ?, jailexpire = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS);
        if (gmLevel < 1 && level > 199) {
            ps.setInt(1, isCygnus() ? 120 : 200);
        } else {
            ps.setInt(1, level);
        }
        ps.setInt(2, fame);
        ps.setInt(3, str);
        ps.setInt(4, dex);
        ps.setInt(5, luk);
        ps.setInt(6, int_);
        ps.setInt(7, Math.abs(exp.get()));
        ps.setInt(8, Math.abs(gachaexp.get()));
        ps.setInt(9, hp);
        ps.setInt(10, mp);
        ps.setInt(11, maxhp);
        ps.setInt(12, maxmp);
        StringBuilder sps = new StringBuilder();
        for (int i = 0; i < remainingSp.length; i++) {
            sps.append(remainingSp[i]);
            sps.append(",");
        }
        String sp = sps.toString();
        ps.setString(13, sp.substring(0, sp.length() - 1));
        ps.setInt(14, remainingAp);
        ps.setInt(15, gmLevel);
        ps.setInt(16, skinColor.getId());
        ps.setInt(17, gender);
        ps.setInt(18, job.getId());
        ps.setInt(19, hair);
        ps.setInt(20, face);
        if (map == null || (cashshop != null && cashshop.isOpened())) {
            ps.setInt(21, mapid);
        } else {
            if (map.getForcedReturnId() != 999999999) {
                ps.setInt(21, map.getForcedReturnId());
            } else {
                ps.setInt(21, getHp() < 1 ? map.getReturnMapId() : map.getId());
            }
        }
        ps.setInt(22, meso.get());
        ps.setInt(23, hpMpApUsed);
        if (map == null || map.getId() == 610020000 || map.getId() == 610020001) {
            // reset to first spawnpoint on those maps
            ps.setInt(24, 0);
        } else {
            MaplePortal closest = map.findClosestPlayerSpawnpoint(getPosition());
            if (closest != null) {
                ps.setInt(24, closest.getId());
            } else {
                ps.setInt(24, 0);
            }
        }
        prtLock.lock();
        try {
            if (party != null) {
                ps.setInt(25, party.getId());
            } else {
                ps.setInt(25, -1);
            }
        } finally {
            prtLock.unlock();
        }
        ps.setInt(26, buddylist.getCapacity());
        if (messenger != null) {
            ps.setInt(27, messenger.getId());
            ps.setInt(28, messengerposition);
        } else {
            ps.setInt(27, 0);
            ps.setInt(28, 4);
        }
        if (maplemount != null) {
            ps.setInt(29, maplemount.getLevel());
            ps.setInt(30, maplemount.getExp());
            ps.setInt(31, maplemount.getTiredness());
        } else {
            ps.setInt(29, 1);
            ps.setInt(30, 0);
            ps.setInt(31, 0);
        }
        for (int i = 1; i < 5; i++) {
            ps.setInt(i + 31, getSlots(i));
        }
        monsterbook.saveCards(getId());
        ps.setInt(36, bookCover);
        ps.setInt(37, vanquisherStage);
        ps.setInt(38, dojoPoints);
        ps.setInt(39, dojoStage);
        ps.setInt(40, finishedDojoTutorial ? 1 : 0);
        ps.setInt(41, vanquisherKills);
        ps.setInt(42, matchcardwins);
        ps.setInt(43, matchcardlosses);
        ps.setInt(44, matchcardties);
        ps.setInt(45, omokwins);
        ps.setInt(46, omoklosses);
        ps.setInt(47, omokties);
        ps.setString(48, dataString);
        ps.setInt(49, quest_fame);
        ps.setLong(50, jailExpiration);
        ps.setInt(51, id);
        int updateRows = ps.executeUpdate();
        if (updateRows < 1) {
            throw new RuntimeException("Character not in database (" + id + ")");
        }
        petLock.lock();
        try {
            for (int i = 0; i < 3; i++) {
                if (pets[i] != null) {
                    pets[i].saveToDb();
                }
            }
        } finally {
            petLock.unlock();
        }
        for (Entry<Integer, Set<Integer>> es : getExcluded().entrySet()) {
            // this set is already protected
            try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM petignores WHERE petid=?")) {
                ps2.setInt(1, es.getKey());
                ps2.executeUpdate();
            }
            try (PreparedStatement ps2 = con.prepareStatement("INSERT INTO petignores (petid, itemid) VALUES (?, ?)")) {
                ps2.setInt(1, es.getKey());
                for (Integer x : es.getValue()) {
                    ps2.setInt(2, x);
                    ps2.addBatch();
                }
                ps2.executeBatch();
            }
        }
        deleteWhereCharacterId(con, "DELETE FROM keymap WHERE characterid = ?");
        ps = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)");
        ps.setInt(1, id);
        Set<Entry<Integer, MapleKeyBinding>> keybindingItems = Collections.unmodifiableSet(keymap.entrySet());
        for (Entry<Integer, MapleKeyBinding> keybinding : keybindingItems) {
            ps.setInt(2, keybinding.getKey());
            ps.setInt(3, keybinding.getValue().getType());
            ps.setInt(4, keybinding.getValue().getAction());
            ps.addBatch();
        }
        ps.executeBatch();
        deleteWhereCharacterId(con, "DELETE FROM skillmacros WHERE characterid = ?");
        ps = con.prepareStatement("INSERT INTO skillmacros (characterid, skill1, skill2, skill3, name, shout, position) VALUES (?, ?, ?, ?, ?, ?, ?)");
        ps.setInt(1, getId());
        for (int i = 0; i < 5; i++) {
            SkillMacro macro = skillMacros[i];
            if (macro != null) {
                ps.setInt(2, macro.getSkill1());
                ps.setInt(3, macro.getSkill2());
                ps.setInt(4, macro.getSkill3());
                ps.setString(5, macro.getName());
                ps.setInt(6, macro.getShout());
                ps.setInt(7, i);
                ps.addBatch();
            }
        }
        ps.executeBatch();
        List<Pair<Item, MapleInventoryType>> itemsWithType = new ArrayList<>();
        for (MapleInventory iv : inventory) {
            for (Item item : iv.list()) {
                itemsWithType.add(new Pair<>(item, iv.getType()));
            }
        }
        ItemFactory.INVENTORY.saveItems(itemsWithType, id, con);
        deleteWhereCharacterId(con, "DELETE FROM skills WHERE characterid = ?");
        ps = con.prepareStatement("INSERT INTO skills (characterid, skillid, skilllevel, masterlevel, expiration) VALUES (?, ?, ?, ?, ?)");
        ps.setInt(1, id);
        for (Entry<Skill, SkillEntry> skill : skills.entrySet()) {
            ps.setInt(2, skill.getKey().getId());
            ps.setInt(3, skill.getValue().skillevel);
            ps.setInt(4, skill.getValue().masterlevel);
            ps.setLong(5, skill.getValue().expiration);
            ps.addBatch();
        }
        ps.executeBatch();
        deleteWhereCharacterId(con, "DELETE FROM savedlocations WHERE characterid = ?");
        ps = con.prepareStatement("INSERT INTO savedlocations (characterid, `locationtype`, `map`, `portal`) VALUES (?, ?, ?, ?)");
        ps.setInt(1, id);
        for (SavedLocationType savedLocationType : SavedLocationType.values()) {
            if (savedLocations[savedLocationType.ordinal()] != null) {
                ps.setString(2, savedLocationType.name());
                ps.setInt(3, savedLocations[savedLocationType.ordinal()].getMapId());
                ps.setInt(4, savedLocations[savedLocationType.ordinal()].getPortal());
                ps.addBatch();
            }
        }
        ps.executeBatch();
        deleteWhereCharacterId(con, "DELETE FROM trocklocations WHERE characterid = ?");
        ps = con.prepareStatement("INSERT INTO trocklocations(characterid, mapid, vip) VALUES (?, ?, 0)");
        for (int i = 0; i < getTrockSize(); i++) {
            if (trockmaps.get(i) != 999999999) {
                ps.setInt(1, getId());
                ps.setInt(2, trockmaps.get(i));
                ps.addBatch();
            }
        }
        ps.executeBatch();
        ps = con.prepareStatement("INSERT INTO trocklocations(characterid, mapid, vip) VALUES (?, ?, 1)");
        for (int i = 0; i < getVipTrockSize(); i++) {
            if (viptrockmaps.get(i) != 999999999) {
                ps.setInt(1, getId());
                ps.setInt(2, viptrockmaps.get(i));
                ps.addBatch();
            }
        }
        ps.executeBatch();
        deleteWhereCharacterId(con, "DELETE FROM buddies WHERE characterid = ? AND pending = 0");
        ps = con.prepareStatement("INSERT INTO buddies (characterid, `buddyid`, `pending`, `group`) VALUES (?, ?, 0, ?)");
        ps.setInt(1, id);
        for (BuddylistEntry entry : buddylist.getBuddies()) {
            if (entry.isVisible()) {
                ps.setInt(2, entry.getCharacterId());
                ps.setString(3, entry.getGroup());
                ps.addBatch();
            }
        }
        ps.executeBatch();
        deleteWhereCharacterId(con, "DELETE FROM area_info WHERE charid = ?");
        ps = con.prepareStatement("INSERT INTO area_info (id, charid, area, info) VALUES (DEFAULT, ?, ?, ?)");
        ps.setInt(1, id);
        for (Entry<Short, String> area : area_info.entrySet()) {
            ps.setInt(2, area.getKey());
            ps.setString(3, area.getValue());
            ps.addBatch();
        }
        ps.executeBatch();
        deleteWhereCharacterId(con, "DELETE FROM eventstats WHERE characterid = ?");
        deleteWhereCharacterId(con, "DELETE FROM queststatus WHERE characterid = ?");
        ps = con.prepareStatement("INSERT INTO queststatus (`queststatusid`, `characterid`, `quest`, `status`, `time`, `expires`, `forfeited`) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
        PreparedStatement psf;
        try (PreparedStatement pse = con.prepareStatement("INSERT INTO questprogress VALUES (DEFAULT, ?, ?, ?)")) {
            psf = con.prepareStatement("INSERT INTO medalmaps VALUES (DEFAULT, ?, ?)");
            ps.setInt(1, id);
            synchronized (quests) {
                for (MapleQuestStatus q : quests.values()) {
                    ps.setInt(2, q.getQuest().getId());
                    ps.setInt(3, q.getStatus().getId());
                    ps.setInt(4, (int) (q.getCompletionTime() / 1000));
                    ps.setLong(5, q.getExpirationTime());
                    ps.setInt(6, q.getForfeited());
                    ps.executeUpdate();
                    try (ResultSet rs = ps.getGeneratedKeys()) {
                        rs.next();
                        for (int mob : q.getProgress().keySet()) {
                            pse.setInt(1, rs.getInt(1));
                            pse.setInt(2, mob);
                            pse.setString(3, q.getProgress(mob));
                            pse.addBatch();
                        }
                        for (int i = 0; i < q.getMedalMaps().size(); i++) {
                            psf.setInt(1, rs.getInt(1));
                            psf.setInt(2, q.getMedalMaps().get(i));
                            psf.addBatch();
                        }
                        pse.executeBatch();
                        psf.executeBatch();
                    }
                }
            }
        }
        psf.close();
        ps = con.prepareStatement("UPDATE accounts SET gm = ? WHERE id = ?");
        ps.setInt(1, gmLevel > 1 ? 1 : 0);
        ps.setInt(2, client.getAccID());
        ps.executeUpdate();
        ps.close();
        con.commit();
        con.setAutoCommit(true);
        if (cashshop != null) {
            cashshop.save(con);
        }
        if (storage != null) {
            storage.saveToDB(con);
        }
    } catch (SQLException | RuntimeException t) {
        FilePrinter.printError(FilePrinter.SAVE_CHAR, t, "Error saving " + name + " Level: " + level + " Job: " + job.getId());
        try {
            con.rollback();
        } catch (SQLException se) {
            FilePrinter.printError(FilePrinter.SAVE_CHAR, se, "Error trying to rollback " + name);
        }
    } catch (Exception e) {
        FilePrinter.printError(FilePrinter.SAVE_CHAR, e, "Error saving " + name + " Level: " + level + " Job: " + job.getId());
    } finally {
        try {
            con.setAutoCommit(true);
            con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Entry(java.util.Map.Entry) ResultSet(java.sql.ResultSet) Pair(tools.Pair) Calendar(java.util.Calendar) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SavedLocationType(server.maps.SavedLocationType) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point) SQLException(java.sql.SQLException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MobSkill(server.life.MobSkill) MaplePortal(server.MaplePortal)

Example 2 with MapleInventory

use of client.inventory.MapleInventory in project HeavenMS by ronancpl.

the class MapleCharacter method recalcLocalStats.

private void recalcLocalStats() {
    int oldmaxhp = localmaxhp;
    localmaxhp = getMaxHp();
    localmaxmp = getMaxMp();
    localdex = getDex();
    localint_ = getInt();
    localstr = getStr();
    localluk = getLuk();
    int speed = 100, jump = 100;
    magic = localint_;
    watk = 0;
    for (Item item : getInventory(MapleInventoryType.EQUIPPED)) {
        Equip equip = (Equip) item;
        localmaxhp += equip.getHp();
        localmaxmp += equip.getMp();
        localdex += equip.getDex();
        localint_ += equip.getInt();
        localstr += equip.getStr();
        localluk += equip.getLuk();
        magic += equip.getMatk() + equip.getInt();
        watk += equip.getWatk();
        speed += equip.getSpeed();
        jump += equip.getJump();
    }
    magic = Math.min(magic, 2000);
    Integer hbhp = getBuffedValue(MapleBuffStat.HYPERBODYHP);
    if (hbhp != null) {
        localmaxhp += (hbhp.doubleValue() / 100) * localmaxhp;
    }
    Integer hbmp = getBuffedValue(MapleBuffStat.HYPERBODYMP);
    if (hbmp != null) {
        localmaxmp += (hbmp.doubleValue() / 100) * localmaxmp;
    }
    localmaxhp = Math.min(30000, localmaxhp);
    localmaxmp = Math.min(30000, localmaxmp);
    Integer watkbuff = getBuffedValue(MapleBuffStat.WATK);
    if (watkbuff != null) {
        watk += watkbuff.intValue();
    }
    MapleStatEffect combo = getBuffEffect(MapleBuffStat.ARAN_COMBO);
    if (combo != null) {
        watk += combo.getX();
    }
    if (energybar == 15000) {
        Skill energycharge = isCygnus() ? SkillFactory.getSkill(ThunderBreaker.ENERGY_CHARGE) : SkillFactory.getSkill(Marauder.ENERGY_CHARGE);
        MapleStatEffect ceffect = energycharge.getEffect(getSkillLevel(energycharge));
        watk += ceffect.getWatk();
    }
    Integer mwarr = getBuffedValue(MapleBuffStat.MAPLE_WARRIOR);
    if (mwarr != null) {
        localstr += getStr() * mwarr / 100;
        localdex += getDex() * mwarr / 100;
        localint_ += getInt() * mwarr / 100;
        localluk += getLuk() * mwarr / 100;
    }
    if (job.isA(MapleJob.BOWMAN)) {
        Skill expert = null;
        if (job.isA(MapleJob.MARKSMAN)) {
            expert = SkillFactory.getSkill(3220004);
        } else if (job.isA(MapleJob.BOWMASTER)) {
            expert = SkillFactory.getSkill(3120005);
        }
        if (expert != null) {
            int boostLevel = getSkillLevel(expert);
            if (boostLevel > 0) {
                watk += expert.getEffect(boostLevel).getX();
            }
        }
    }
    Integer matkbuff = getBuffedValue(MapleBuffStat.MATK);
    if (matkbuff != null) {
        magic += matkbuff.intValue();
    }
    Integer speedbuff = getBuffedValue(MapleBuffStat.SPEED);
    if (speedbuff != null) {
        speed += speedbuff.intValue();
    }
    Integer jumpbuff = getBuffedValue(MapleBuffStat.JUMP);
    if (jumpbuff != null) {
        jump += jumpbuff.intValue();
    }
    Integer blessing = getSkillLevel(10000000 * getJobType() + 12);
    if (blessing > 0) {
        watk += blessing;
        magic += blessing * 2;
    }
    if (job.isA(MapleJob.THIEF) || job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.PIRATE) || job.isA(MapleJob.NIGHTWALKER1) || job.isA(MapleJob.WINDARCHER1)) {
        Item weapon_item = getInventory(MapleInventoryType.EQUIPPED).getItem((short) -11);
        if (weapon_item != null) {
            MapleWeaponType weapon = ii.getWeaponType(weapon_item.getItemId());
            boolean bow = weapon == MapleWeaponType.BOW;
            boolean crossbow = weapon == MapleWeaponType.CROSSBOW;
            boolean claw = weapon == MapleWeaponType.CLAW;
            boolean gun = weapon == MapleWeaponType.GUN;
            if (bow || crossbow || claw || gun) {
                // Also calc stars into this.
                MapleInventory inv = getInventory(MapleInventoryType.USE);
                for (short i = 1; i <= inv.getSlotLimit(); i++) {
                    Item item = inv.getItem(i);
                    if (item != null) {
                        if ((claw && ItemConstants.isThrowingStar(item.getItemId())) || (gun && ItemConstants.isBullet(item.getItemId())) || (bow && ItemConstants.isArrowForBow(item.getItemId())) || (crossbow && ItemConstants.isArrowForCrossBow(item.getItemId()))) {
                            if (item.getQuantity() > 0) {
                                // Finally there!
                                watk += ii.getWatkForProjectile(item.getItemId());
                                break;
                            }
                        }
                    }
                }
            }
        }
    // Add throwing stars to dmg.
    }
    if (oldmaxhp != 0 && oldmaxhp != localmaxhp) {
        updatePartyMemberHP();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Equip(client.inventory.Equip) MobSkill(server.life.MobSkill) MapleStatEffect(server.MapleStatEffect) MapleWeaponType(client.inventory.MapleWeaponType) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point)

Example 3 with MapleInventory

use of client.inventory.MapleInventory in project HeavenMS by ronancpl.

the class RangedAttackHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    chr.setPetLootCd(System.currentTimeMillis());
    /*long timeElapsed = System.currentTimeMillis() - chr.getAutobanManager().getLastSpam(8);
        if(timeElapsed < 300) {
            AutobanFactory.FAST_ATTACK.alert(chr, "Time: " + timeElapsed);
        }
        chr.getAutobanManager().spam(8);*/
    AttackInfo attack = parseDamage(slea, chr, true, false);
    if (chr.getBuffEffect(MapleBuffStat.MORPH) != null) {
        if (chr.getBuffEffect(MapleBuffStat.MORPH).isMorphWithoutAttack()) {
            // How are they attacking when the client won't let them?
            chr.getClient().disconnect(false, false);
            return;
        }
    }
    if (chr.getMap().isDojoMap() && attack.numAttacked > 0) {
        chr.setDojoEnergy(chr.getDojoEnergy() + ServerConstants.DOJO_ENERGY_ATK);
        c.announce(MaplePacketCreator.getEnergy("energy", chr.getDojoEnergy()));
    }
    if (attack.skill == Buccaneer.ENERGY_ORB || attack.skill == ThunderBreaker.SPARK || attack.skill == Shadower.TAUNT || attack.skill == NightLord.TAUNT) {
        chr.getMap().broadcastMessage(chr, MaplePacketCreator.rangedAttack(chr, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, 0, attack.allDamage, attack.speed, attack.direction, attack.display), false);
        applyAttack(attack, chr, 1);
    } else if (attack.skill == Aran.COMBO_SMASH || attack.skill == Aran.COMBO_FENRIR || attack.skill == Aran.COMBO_TEMPEST) {
        chr.getMap().broadcastMessage(chr, MaplePacketCreator.rangedAttack(chr, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, 0, attack.allDamage, attack.speed, attack.direction, attack.display), false);
        if (attack.skill == Aran.COMBO_SMASH && chr.getCombo() >= 30) {
            chr.setCombo((short) 0);
            applyAttack(attack, chr, 1);
        } else if (attack.skill == Aran.COMBO_FENRIR && chr.getCombo() >= 100) {
            chr.setCombo((short) 0);
            applyAttack(attack, chr, 2);
        } else if (attack.skill == Aran.COMBO_TEMPEST && chr.getCombo() >= 200) {
            chr.setCombo((short) 0);
            applyAttack(attack, chr, 4);
        }
    } else {
        Item weapon = chr.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -11);
        MapleWeaponType type = MapleItemInformationProvider.getInstance().getWeaponType(weapon.getItemId());
        if (type == MapleWeaponType.NOT_A_WEAPON) {
            return;
        }
        short slot = -1;
        int projectile = 0;
        byte bulletCount = 1;
        MapleStatEffect effect = null;
        if (attack.skill != 0) {
            effect = attack.getAttackEffect(chr, null);
            bulletCount = effect.getBulletCount();
            if (effect.getCooldown() > 0) {
                c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect.getCooldown()));
            }
        }
        boolean hasShadowPartner = chr.getBuffedValue(MapleBuffStat.SHADOWPARTNER) != null;
        if (hasShadowPartner) {
            bulletCount *= 2;
        }
        MapleInventory inv = chr.getInventory(MapleInventoryType.USE);
        for (short i = 1; i <= inv.getSlotLimit(); i++) {
            Item item = inv.getItem(i);
            if (item != null) {
                int id = item.getItemId();
                slot = item.getPosition();
                boolean bow = ItemConstants.isArrowForBow(id);
                boolean cbow = ItemConstants.isArrowForCrossBow(id);
                if (item.getQuantity() >= bulletCount) {
                    // Fixes the bug where you can't use your last arrow.
                    if (type == MapleWeaponType.CLAW && ItemConstants.isThrowingStar(id) && weapon.getItemId() != 1472063) {
                        if (((id == 2070007 || id == 2070018) && chr.getLevel() < 70) || (id == 2070016 && chr.getLevel() < 50)) {
                        } else {
                            projectile = id;
                            break;
                        }
                    } else if ((type == MapleWeaponType.GUN && ItemConstants.isBullet(id))) {
                        if (id == 2331000 && id == 2332000) {
                            if (chr.getLevel() > 69) {
                                projectile = id;
                                break;
                            }
                        } else if (chr.getLevel() > (id % 10) * 20 + 9) {
                            projectile = id;
                            break;
                        }
                    } else if ((type == MapleWeaponType.BOW && bow) || (type == MapleWeaponType.CROSSBOW && cbow) || (weapon.getItemId() == 1472063 && (bow || cbow))) {
                        projectile = id;
                        break;
                    }
                }
            }
        }
        boolean soulArrow = chr.getBuffedValue(MapleBuffStat.SOULARROW) != null;
        boolean shadowClaw = chr.getBuffedValue(MapleBuffStat.SHADOW_CLAW) != null;
        if (projectile != 0) {
            if (!soulArrow && !shadowClaw && attack.skill != 11101004 && attack.skill != 15111007 && attack.skill != 14101006) {
                byte bulletConsume = bulletCount;
                if (effect != null && effect.getBulletConsume() != 0) {
                    bulletConsume = (byte) (effect.getBulletConsume() * (hasShadowPartner ? 2 : 1));
                }
                if (slot < 0)
                    System.out.println("<ERROR> Projectile to use was unable to be found.");
                else
                    MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, bulletConsume, false, true);
            }
        }
        if (projectile != 0 || soulArrow || attack.skill == 11101004 || attack.skill == 15111007 || attack.skill == 14101006) {
            // visible projectile sent to players
            int visProjectile = projectile;
            if (ItemConstants.isThrowingStar(projectile)) {
                MapleInventory cash = chr.getInventory(MapleInventoryType.CASH);
                for (int i = 1; i <= cash.getSlotLimit(); i++) {
                    // impose order...
                    Item item = cash.getItem((short) i);
                    if (item != null) {
                        if (item.getItemId() / 1000 == 5021) {
                            visProjectile = item.getItemId();
                            break;
                        }
                    }
                }
            } else // bow, crossbow
            if (soulArrow || attack.skill == 3111004 || attack.skill == 3211004 || attack.skill == 11101004 || attack.skill == 15111007 || attack.skill == 14101006) {
                visProjectile = 0;
            }
            byte[] packet;
            switch(attack.skill) {
                // Hurricane
                case 3121004:
                // Pierce
                case 3221001:
                // Rapid Fire
                case 5221004:
                case // KoC Hurricane
                13111002:
                    packet = MaplePacketCreator.rangedAttack(chr, attack.skill, attack.skilllevel, attack.rangedirection, attack.numAttackedAndDamage, visProjectile, attack.allDamage, attack.speed, attack.direction, attack.display);
                    break;
                default:
                    packet = MaplePacketCreator.rangedAttack(chr, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, visProjectile, attack.allDamage, attack.speed, attack.direction, attack.display);
                    break;
            }
            chr.getMap().broadcastMessage(chr, packet, false, true);
            if (effect != null) {
                int money = effect.getMoneyCon();
                if (money != 0) {
                    int moneyMod = money / 2;
                    money += Randomizer.nextInt(moneyMod);
                    if (money > chr.getMeso()) {
                        money = chr.getMeso();
                    }
                    chr.gainMeso(-money, false);
                }
            }
            if (attack.skill != 0) {
                Skill skill = SkillFactory.getSkill(attack.skill);
                MapleStatEffect effect_ = skill.getEffect(chr.getSkillLevel(skill));
                if (effect_.getCooldown() > 0) {
                    if (chr.skillIsCooling(attack.skill)) {
                        return;
                    } else {
                        c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
                        chr.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000);
                    }
                }
            }
            if (chr.getSkillLevel(SkillFactory.getSkill(NightWalker.VANISH)) > 0 && chr.getBuffedValue(MapleBuffStat.DARKSIGHT) != null && attack.numAttacked > 0 && chr.getBuffSource(MapleBuffStat.DARKSIGHT) != 9101004) {
                chr.cancelEffectFromBuffStat(MapleBuffStat.DARKSIGHT);
                chr.cancelBuffStats(MapleBuffStat.DARKSIGHT);
            } else if (chr.getSkillLevel(SkillFactory.getSkill(WindArcher.WIND_WALK)) > 0 && chr.getBuffedValue(MapleBuffStat.WIND_WALK) != null && attack.numAttacked > 0) {
                chr.cancelEffectFromBuffStat(MapleBuffStat.WIND_WALK);
                chr.cancelBuffStats(MapleBuffStat.WIND_WALK);
            }
            applyAttack(attack, chr, bulletCount);
        }
    }
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) Skill(client.Skill) MapleWeaponType(client.inventory.MapleWeaponType) MapleStatEffect(server.MapleStatEffect) MapleInventory(client.inventory.MapleInventory)

Example 4 with MapleInventory

use of client.inventory.MapleInventory in project HeavenMS by ronancpl.

the class InventoryMergeHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    chr.getAutobanManager().setTimestamp(2, slea.readInt(), 3);
    MapleInventoryType inventoryType = MapleInventoryType.getByType(slea.readByte());
    if (!ServerConstants.USE_ITEM_SORT) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    MapleInventory inventory = c.getPlayer().getInventory(inventoryType);
    // ------------------- RonanLana's SLOT MERGER -----------------
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item srcItem, dstItem;
    for (short dst = 1; dst <= inventory.getSlotLimit(); dst++) {
        dstItem = inventory.getItem(dst);
        if (dstItem == null)
            continue;
        for (short src = (short) (dst + 1); src <= inventory.getSlotLimit(); src++) {
            srcItem = inventory.getItem(src);
            if (srcItem == null)
                continue;
            if (dstItem.getItemId() != srcItem.getItemId())
                continue;
            if (dstItem.getQuantity() == ii.getSlotMax(c, inventory.getItem(dst).getItemId()))
                break;
            MapleInventoryManipulator.move(c, inventoryType, src, dst);
        }
    }
    // ------------------------------------------------------------
    inventory = c.getPlayer().getInventory(inventoryType);
    boolean sorted = false;
    while (!sorted) {
        short freeSlot = inventory.getNextFreeSlot();
        if (freeSlot != -1) {
            short itemSlot = -1;
            for (short i = (short) (freeSlot + 1); i <= inventory.getSlotLimit(); i = (short) (i + 1)) {
                if (inventory.getItem(i) != null) {
                    itemSlot = i;
                    break;
                }
            }
            if (itemSlot > 0) {
                MapleInventoryManipulator.move(c, inventoryType, itemSlot, freeSlot);
            } else {
                sorted = true;
            }
        } else {
            sorted = true;
        }
    }
    c.announce(MaplePacketCreator.finishedSort(inventoryType.getType()));
    c.announce(MaplePacketCreator.enableActions());
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) MapleInventoryType(client.inventory.MapleInventoryType) MapleItemInformationProvider(server.MapleItemInformationProvider) MapleInventory(client.inventory.MapleInventory)

Example 5 with MapleInventory

use of client.inventory.MapleInventory in project HeavenMS by ronancpl.

the class InventorySortHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    chr.getAutobanManager().setTimestamp(3, slea.readInt(), 3);
    byte inventoryType = slea.readByte();
    if (!ServerConstants.USE_ITEM_SORT) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (inventoryType < 1 || inventoryType > 5) {
        c.disconnect(false, false);
        return;
    }
    MapleInventory inventory = chr.getInventory(MapleInventoryType.getByType(inventoryType));
    ArrayList<Item> itemarray = new ArrayList<>();
    List<ModifyInventory> mods = new ArrayList<>();
    for (short i = 1; i <= inventory.getSlotLimit(); i++) {
        Item item = inventory.getItem(i);
        if (item != null) {
            itemarray.add((Item) item.copy());
        }
    }
    for (Item item : itemarray) {
        inventory.removeSlot(item.getPosition());
        mods.add(new ModifyInventory(3, item));
    }
    int invTypeCriteria = (MapleInventoryType.getByType(inventoryType) == MapleInventoryType.EQUIP) ? 3 : 1;
    int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
    PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
    for (Item item : itemarray) {
        inventory.addItem(item);
        // to prevent crashes
        mods.add(new ModifyInventory(0, item.copy()));
    }
    itemarray.clear();
    c.announce(MaplePacketCreator.modifyInventory(true, mods));
    c.announce(MaplePacketCreator.finishedSort2(inventoryType));
    c.announce(MaplePacketCreator.enableActions());
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) ArrayList(java.util.ArrayList) MapleInventory(client.inventory.MapleInventory) ModifyInventory(client.inventory.ModifyInventory)

Aggregations

MapleInventory (client.inventory.MapleInventory)20 Item (client.inventory.Item)18 MapleCharacter (client.MapleCharacter)10 Point (java.awt.Point)8 ArrayList (java.util.ArrayList)8 MapleMapItem (server.maps.MapleMapItem)7 Equip (client.inventory.Equip)6 MaplePlayerShopItem (server.maps.MaplePlayerShopItem)6 MapleInventoryType (client.inventory.MapleInventoryType)4 SQLException (java.sql.SQLException)4 CashItem (server.CashShop.CashItem)3 MapleItemInformationProvider (server.MapleItemInformationProvider)3 MobSkill (server.life.MobSkill)3 Pair (tools.Pair)3 Skill (client.Skill)2 MapleWeaponType (client.inventory.MapleWeaponType)2 ModifyInventory (client.inventory.ModifyInventory)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2