Search in sources :

Example 21 with Skill

use of org.powerbot.bot.rt6.client.Skill in project HeavenMS by ronancpl.

the class TakeDamageHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    List<MapleCharacter> banishPlayers = new ArrayList<>();
    MapleCharacter chr = c.getPlayer();
    slea.readInt();
    byte damagefrom = slea.readByte();
    // Element
    slea.readByte();
    int damage = slea.readInt();
    int oid = 0, monsteridfrom = 0, pgmr = 0, direction = 0;
    int pos_x = 0, pos_y = 0, fake = 0;
    boolean is_pgmr = false, is_pg = true, is_deadly = false;
    int mpattack = 0;
    MapleMonster attacker = null;
    final MapleMap map = chr.getMap();
    if (damagefrom != -3 && damagefrom != -4) {
        monsteridfrom = slea.readInt();
        oid = slea.readInt();
        try {
            MapleMapObject mmo = map.getMapObject(oid);
            if (mmo instanceof MapleMonster) {
                attacker = (MapleMonster) mmo;
                if (attacker.getId() != monsteridfrom) {
                    attacker = null;
                }
            }
            if (attacker != null) {
                List<loseItem> loseItems;
                if (attacker.isBuffed(MonsterStatus.NEUTRALISE)) {
                    return;
                }
                if (damage > 0) {
                    MapleMonster assaulter = map.getMonsterById(monsteridfrom);
                    if (assaulter != null) {
                        loseItems = assaulter.getStats().loseItem();
                        if (loseItems != null) {
                            MapleInventoryType type;
                            final int playerpos = chr.getPosition().x;
                            byte d = 1;
                            Point pos = new Point(0, chr.getPosition().y);
                            for (loseItem loseItem : loseItems) {
                                type = ItemConstants.getInventoryType(loseItem.getId());
                                for (byte b = 0; b < loseItem.getX(); b++) {
                                    // LOL?
                                    if (Randomizer.nextInt(101) >= loseItem.getChance()) {
                                        if (chr.haveItem(loseItem.getId())) {
                                            pos.x = (int) (playerpos + ((d % 2 == 0) ? (25 * (d + 1) / 2) : -(25 * (d / 2))));
                                            MapleInventoryManipulator.removeById(c, type, loseItem.getId(), 1, false, false);
                                            map.spawnItemDrop(chr, chr, new Item(loseItem.getId(), (short) 0, (short) 1), map.calcDropPos(pos, chr.getPosition()), true, true);
                                            d++;
                                        } else {
                                            break;
                                        }
                                    }
                                }
                            }
                            map.removeMapObject(attacker);
                        }
                    }
                }
            } else {
                return;
            }
        } catch (ClassCastException e) {
            // this happens due to mob on last map damaging player just before changing maps
            e.printStackTrace();
            FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, "Attacker is not a mob-type, rather is a " + map.getMapObject(oid).getClass().getName() + " entity.");
            return;
        }
        direction = slea.readByte();
    }
    if (damagefrom != -1 && damagefrom != -2 && attacker != null) {
        MobAttackInfo attackInfo = MobAttackInfoFactory.getMobAttackInfo(attacker, damagefrom);
        if (attackInfo != null) {
            if (attackInfo.isDeadlyAttack()) {
                mpattack = chr.getMp() - 1;
                is_deadly = true;
            }
            mpattack += attackInfo.getMpBurn();
            MobSkill mobSkill = MobSkillFactory.getMobSkill(attackInfo.getDiseaseSkill(), attackInfo.getDiseaseLevel());
            if (mobSkill != null && damage > 0) {
                mobSkill.applyEffect(chr, attacker, false, banishPlayers);
            }
            attacker.setMp(attacker.getMp() - attackInfo.getMpCon());
            if (chr.getBuffedValue(MapleBuffStat.MANA_REFLECTION) != null && damage > 0 && !attacker.isBoss()) {
                int jobid = chr.getJob().getId();
                if (jobid == 212 || jobid == 222 || jobid == 232) {
                    int id = jobid * 10000 + 1002;
                    Skill manaReflectSkill = SkillFactory.getSkill(id);
                    if (chr.isBuffFrom(MapleBuffStat.MANA_REFLECTION, manaReflectSkill) && chr.getSkillLevel(manaReflectSkill) > 0 && manaReflectSkill.getEffect(chr.getSkillLevel(manaReflectSkill)).makeChanceResult()) {
                        int bouncedamage = (damage * manaReflectSkill.getEffect(chr.getSkillLevel(manaReflectSkill)).getX() / 100);
                        if (bouncedamage > attacker.getMaxHp() / 5) {
                            bouncedamage = attacker.getMaxHp() / 5;
                        }
                        map.damageMonster(chr, attacker, bouncedamage);
                        map.broadcastMessage(chr, MaplePacketCreator.damageMonster(oid, bouncedamage), true);
                        chr.getClient().announce(MaplePacketCreator.showOwnBuffEffect(id, 5));
                        map.broadcastMessage(chr, MaplePacketCreator.showBuffeffect(chr.getId(), id, 5), false);
                    }
                }
            }
        }
    }
    if (damage == -1) {
        fake = 4020002 + (chr.getJob().getId() / 10 - 40) * 100000;
    }
    // in dojo player cannot use pot, so deadly attacks should be turned off as well
    if (is_deadly && chr.getMap().isDojoMap() && !ServerConstants.USE_DEADLY_DOJO) {
        damage = 0;
        mpattack = 0;
    }
    if (damage == 0) {
        chr.getAutobanManager().addMiss();
    } else {
        chr.getAutobanManager().resetMisses();
    }
    if (damage > 0 && !chr.isHidden()) {
        if (attacker != null && damagefrom == -1 && chr.getBuffedValue(MapleBuffStat.POWERGUARD) != null) {
            // PG works on bosses, but only at half of the rate.
            int bouncedamage = (int) (damage * (chr.getBuffedValue(MapleBuffStat.POWERGUARD).doubleValue() / (attacker.isBoss() ? 200 : 100)));
            bouncedamage = Math.min(bouncedamage, attacker.getMaxHp() / 10);
            damage -= bouncedamage;
            map.damageMonster(chr, attacker, bouncedamage);
            map.broadcastMessage(chr, MaplePacketCreator.damageMonster(oid, bouncedamage), false, true);
            chr.checkMonsterAggro(attacker);
        }
        if (attacker != null && damagefrom == -1 && chr.getBuffedValue(MapleBuffStat.BODY_PRESSURE) != null) {
            Skill skill = SkillFactory.getSkill(Aran.BODY_PRESSURE);
            final MapleStatEffect eff = skill.getEffect(chr.getSkillLevel(skill));
            if (!attacker.alreadyBuffedStats().contains(MonsterStatus.NEUTRALISE)) {
                if (!attacker.isBoss() && eff.makeChanceResult()) {
                    attacker.applyStatus(chr, new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.NEUTRALISE, 1), skill, null, false), false, (eff.getDuration() / 10) * 2, false);
                }
            }
        }
        if (damagefrom != -3 && damagefrom != -4) {
            int achilles = 0;
            Skill achilles1 = null;
            int jobid = chr.getJob().getId();
            if (jobid < 200 && jobid % 10 == 2) {
                achilles1 = SkillFactory.getSkill(jobid * 10000 + (jobid == 112 ? 4 : 5));
                achilles = chr.getSkillLevel(achilles1);
            }
            if (achilles != 0 && achilles1 != null) {
                damage *= (achilles1.getEffect(achilles).getX() / 1000.0);
            }
        }
        Integer mesoguard = chr.getBuffedValue(MapleBuffStat.MESOGUARD);
        if (chr.getBuffedValue(MapleBuffStat.MAGIC_GUARD) != null && mpattack == 0) {
            int mploss = (int) (damage * (chr.getBuffedValue(MapleBuffStat.MAGIC_GUARD).doubleValue() / 100.0));
            int hploss = damage - mploss;
            int curmp = chr.getMp();
            if (mploss > curmp) {
                hploss += mploss - curmp;
                mploss = curmp;
            }
            chr.addMPHP(-hploss, -mploss);
        } else if (mesoguard != null) {
            damage = Math.round(damage / 2);
            int mesoloss = (int) (damage * (mesoguard.doubleValue() / 100.0));
            if (chr.getMeso() < mesoloss) {
                chr.gainMeso(-chr.getMeso(), false);
                chr.cancelBuffStats(MapleBuffStat.MESOGUARD);
            } else {
                chr.gainMeso(-mesoloss, false);
            }
            chr.addMPHP(-damage, -mpattack);
        } else {
            if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
                if (chr.getBuffedValue(MapleBuffStat.MONSTER_RIDING).intValue() == Corsair.BATTLE_SHIP) {
                    chr.decreaseBattleshipHp(damage);
                }
            }
            chr.addMPHP(-damage, -mpattack);
        }
    }
    if (!chr.isHidden()) {
        map.broadcastMessage(chr, MaplePacketCreator.damagePlayer(damagefrom, monsteridfrom, chr.getId(), damage, fake, direction, is_pgmr, pgmr, is_pg, oid, pos_x, pos_y), false);
        chr.checkBerserk(true);
    } else {
        map.broadcastGMMessage(chr, MaplePacketCreator.damagePlayer(damagefrom, monsteridfrom, chr.getId(), damage, fake, direction, is_pgmr, pgmr, is_pg, oid, pos_x, pos_y), false);
        chr.checkBerserk(false);
    }
    if (GameConstants.isDojo(map.getId())) {
        chr.setDojoEnergy(chr.getDojoEnergy() + ServerConstants.DOJO_ENERGY_DMG);
        c.announce(MaplePacketCreator.getEnergy("energy", chr.getDojoEnergy()));
    }
    for (MapleCharacter player : banishPlayers) {
        // chill, if this list ever gets non-empty an attacker does exist, trust me :)
        player.changeMapBanish(attacker.getBanish().getMap(), attacker.getBanish().getPortal(), attacker.getBanish().getMsg());
    }
}
Also used : MapleCharacter(client.MapleCharacter) MonsterStatusEffect(client.status.MonsterStatusEffect) ArrayList(java.util.ArrayList) MapleMapObject(server.maps.MapleMapObject) MobAttackInfo(server.life.MobAttackInfo) MapleLifeFactory.loseItem(server.life.MapleLifeFactory.loseItem) Point(java.awt.Point) Point(java.awt.Point) MapleMap(server.maps.MapleMap) Item(client.inventory.Item) MapleLifeFactory.loseItem(server.life.MapleLifeFactory.loseItem) MapleInventoryType(client.inventory.MapleInventoryType) Skill(client.Skill) MobSkill(server.life.MobSkill) MapleStatEffect(server.MapleStatEffect) MobSkill(server.life.MobSkill) MapleMonster(server.life.MapleMonster)

Example 22 with Skill

use of org.powerbot.bot.rt6.client.Skill in project HeavenMS by ronancpl.

the class UseCashItemHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final MapleCharacter player = c.getPlayer();
    if (System.currentTimeMillis() - player.getLastUsedCashItem() < 3000) {
        player.dropMessage(1, "You have used a cash item recently. Wait a moment, then try again.");
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    player.setLastUsedCashItem(System.currentTimeMillis());
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    slea.readShort();
    int itemId = slea.readInt();
    int itemType = itemId / 10000;
    Item toUse = c.getPlayer().getInventory(MapleInventoryType.CASH).getItem(c.getPlayer().getInventory(MapleInventoryType.CASH).findById(itemId).getPosition());
    String medal = "";
    Item medalItem = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) -49);
    if (medalItem != null) {
        medal = "<" + ii.getName(medalItem.getItemId()) + "> ";
    }
    if (toUse == null || toUse.getItemId() != itemId || toUse.getQuantity() < 1) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (itemType == 505) {
        // AP/SP reset
        if (!player.isAlive()) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (itemId > 5050000) {
            int SPTo = slea.readInt();
            int SPFrom = slea.readInt();
            Skill skillSPTo = SkillFactory.getSkill(SPTo);
            Skill skillSPFrom = SkillFactory.getSkill(SPFrom);
            byte curLevel = player.getSkillLevel(skillSPTo);
            byte curLevelSPFrom = player.getSkillLevel(skillSPFrom);
            if ((curLevel < skillSPTo.getMaxLevel()) && curLevelSPFrom > 0) {
                player.changeSkillLevel(skillSPFrom, (byte) (curLevelSPFrom - 1), player.getMasterLevel(skillSPFrom), -1);
                player.changeSkillLevel(skillSPTo, (byte) (curLevel + 1), player.getMasterLevel(skillSPTo), -1);
            }
        } else {
            List<Pair<MapleStat, Integer>> statupdate = new ArrayList<>(2);
            int APTo = slea.readInt();
            int APFrom = slea.readInt();
            switch(APFrom) {
                case // str
                64:
                    if (player.getStr() < 5) {
                        c.getPlayer().message("You don't have the minimum STR required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(1, -1);
                    break;
                case // dex
                128:
                    if (player.getDex() < 5) {
                        c.getPlayer().message("You don't have the minimum DEX required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(2, -1);
                    break;
                case // int
                256:
                    if (player.getInt() < 5) {
                        c.getPlayer().message("You don't have the minimum INT required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(3, -1);
                    break;
                case // luk
                512:
                    if (player.getLuk() < 5) {
                        c.getPlayer().message("You don't have the minimum LUK required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.addStat(4, -1);
                    break;
                case // HP
                2048:
                    if (ServerConstants.USE_ENFORCE_HPMP_SWAP) {
                        if (APTo != 8192) {
                            c.getPlayer().message("You can only swap HP ability points to MP.");
                            c.announce(MaplePacketCreator.enableActions());
                            return;
                        }
                    }
                    if (player.getHpMpApUsed() < 1) {
                        c.getPlayer().message("You don't have enough HPMP stat points to spend on AP Reset.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    int hp = player.getMaxHp();
                    int level_ = player.getLevel();
                    boolean canWash_ = true;
                    if (hp < level_ * 14 + 148) {
                        canWash_ = false;
                    }
                    if (!canWash_) {
                        c.getPlayer().message("You don't have the minimum HP pool required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.setHpMpApUsed(player.getHpMpApUsed() - 1);
                    int hplose = -DistributeAPHandler.takeHp(player, player.getJob());
                    int nextHp = Math.max(1, player.getHp() + hplose), nextMaxHp = Math.max(50, player.getMaxHp() + hplose);
                    player.setHp(nextHp);
                    player.setMaxHp(nextMaxHp);
                    statupdate.add(new Pair<>(MapleStat.HP, nextHp));
                    statupdate.add(new Pair<>(MapleStat.MAXHP, nextMaxHp));
                    break;
                case // MP
                8192:
                    if (ServerConstants.USE_ENFORCE_HPMP_SWAP) {
                        if (APTo != 2048) {
                            c.getPlayer().message("You can only swap MP ability points to HP.");
                            c.announce(MaplePacketCreator.enableActions());
                            return;
                        }
                    }
                    if (player.getHpMpApUsed() < 1) {
                        c.getPlayer().message("You don't have enough HPMP stat points to spend on AP Reset.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    int mp = player.getMaxMp();
                    int level = player.getLevel();
                    MapleJob job = player.getJob();
                    boolean canWash = true;
                    if (job.isA(MapleJob.SPEARMAN) && mp < 4 * level + 156) {
                        canWash = false;
                    } else if (job.isA(MapleJob.FIGHTER) && mp < 4 * level + 56) {
                        canWash = false;
                    } else if (job.isA(MapleJob.THIEF) && job.getId() % 100 > 0 && mp < level * 14 - 4) {
                        canWash = false;
                    } else if (mp < level * 14 + 148) {
                        canWash = false;
                    }
                    if (!canWash) {
                        c.getPlayer().message("You don't have the minimum MP pool required to swap.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                    player.setHpMpApUsed(player.getHpMpApUsed() - 1);
                    int mplose = -DistributeAPHandler.takeMp(player, job);
                    int nextMp = Math.max(0, player.getMp() + mplose), nextMaxMp = Math.max(5, player.getMaxMp() + mplose);
                    player.setMp(nextMp);
                    player.setMaxMp(nextMaxMp);
                    statupdate.add(new Pair<>(MapleStat.MP, nextMp));
                    statupdate.add(new Pair<>(MapleStat.MAXMP, nextMaxMp));
                    break;
                default:
                    c.announce(MaplePacketCreator.updatePlayerStats(MaplePacketCreator.EMPTY_STATUPDATE, true, c.getPlayer()));
                    return;
            }
            DistributeAPHandler.addStat(c, APTo, true);
            c.announce(MaplePacketCreator.updatePlayerStats(statupdate, true, c.getPlayer()));
        }
        remove(c, itemId);
    } else if (itemType == 506) {
        Item eq = null;
        if (itemId == 5060000) {
            // Item tag.
            int equipSlot = slea.readShort();
            if (equipSlot == 0) {
                return;
            }
            eq = player.getInventory(MapleInventoryType.EQUIPPED).getItem((short) equipSlot);
            eq.setOwner(player.getName());
        } else if (itemId == 5060001 || itemId == 5061000 || itemId == 5061001 || itemId == 5061002 || itemId == 5061003) {
            // Sealing lock
            MapleInventoryType type = MapleInventoryType.getByType((byte) slea.readInt());
            eq = c.getPlayer().getInventory(type).getItem((short) slea.readInt());
            if (eq == null) {
                // Check if the type is EQUIPMENT?
                return;
            }
            byte flag = eq.getFlag();
            flag |= ItemConstants.LOCK;
            if (eq.getExpiration() > -1) {
                // No perma items pls
                return;
            }
            eq.setFlag(flag);
            long period = 0;
            if (itemId == 5061000) {
                period = 7;
            } else if (itemId == 5061001) {
                period = 30;
            } else if (itemId == 5061002) {
                period = 90;
            } else if (itemId == 5061003) {
                period = 365;
            }
            if (period > 0) {
                eq.setExpiration(System.currentTimeMillis() + (period * 60 * 60 * 24 * 1000));
            }
            remove(c, itemId);
        } else if (itemId == 5060002) {
            // Incubator
            byte inventory2 = (byte) slea.readInt();
            short slot2 = (short) slea.readInt();
            Item item2 = c.getPlayer().getInventory(MapleInventoryType.getByType(inventory2)).getItem(slot2);
            if (// hacking
            item2 == null) {
                return;
            }
            if (getIncubatedItem(c, itemId)) {
                MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.getByType(inventory2), slot2, (short) 1, false);
                remove(c, itemId);
            }
            return;
        }
        // time stamp
        slea.readInt();
        if (eq != null) {
            player.forceUpdateItem(eq);
            remove(c, itemId);
        }
    } else if (itemType == 507) {
        boolean whisper;
        switch(itemId / 1000 % 10) {
            case // Megaphone
            1:
                if (player.getLevel() > 9) {
                    player.getClient().getChannelServer().broadcastPacket(MaplePacketCreator.serverNotice(2, medal + player.getName() + " : " + slea.readMapleAsciiString()));
                } else {
                    player.dropMessage(1, "You may not use this until you're level 10.");
                }
                break;
            case // Super megaphone
            2:
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + slea.readMapleAsciiString(), (slea.readByte() != 0)));
                break;
            case // Maple TV
            5:
                int tvType = itemId % 10;
                boolean megassenger = false;
                boolean ear = false;
                MapleCharacter victim = null;
                if (tvType != 1) {
                    if (tvType >= 3) {
                        megassenger = true;
                        if (tvType == 3) {
                            slea.readByte();
                        }
                        ear = 1 == slea.readByte();
                    } else if (tvType != 2) {
                        slea.readByte();
                    }
                    if (tvType != 4) {
                        victim = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
                    }
                }
                List<String> messages = new LinkedList<>();
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < 5; i++) {
                    String message = slea.readMapleAsciiString();
                    if (megassenger) {
                        builder.append(" ").append(message);
                    }
                    messages.add(message);
                }
                slea.readInt();
                if (megassenger) {
                    Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + builder.toString(), ear));
                }
                if (!MapleTVEffect.isActive()) {
                    new MapleTVEffect(player, victim, messages, tvType);
                    remove(c, itemId);
                } else {
                    player.dropMessage(1, "MapleTV is already in use.");
                    return;
                }
                break;
            case // item megaphone
            6:
                String msg = medal + c.getPlayer().getName() + " : " + slea.readMapleAsciiString();
                whisper = slea.readByte() == 1;
                Item item = null;
                if (slea.readByte() == 1) {
                    // item
                    item = c.getPlayer().getInventory(MapleInventoryType.getByType((byte) slea.readInt())).getItem((short) slea.readInt());
                    if (// hack
                    item == null) {
                        return;
                    } else if (((item.getFlag() & ItemConstants.UNTRADEABLE) == ItemConstants.UNTRADEABLE) || ii.isDropRestricted(item.getItemId())) {
                        player.dropMessage(1, "You cannot trade this item.");
                        c.announce(MaplePacketCreator.enableActions());
                        return;
                    }
                }
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.itemMegaphone(msg, whisper, c.getChannel(), item));
                break;
            case // triple megaphone
            7:
                int lines = slea.readByte();
                if (// hack
                lines < 1 || lines > 3) {
                    return;
                }
                String[] msg2 = new String[lines];
                for (int i = 0; i < lines; i++) {
                    msg2[i] = medal + c.getPlayer().getName() + " : " + slea.readMapleAsciiString();
                }
                whisper = slea.readByte() == 1;
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.getMultiMegaphone(msg2, c.getChannel(), whisper));
                break;
        }
        remove(c, itemId);
    } else if (itemType == 508) {
        // graduation banner
        // message, separated by 0A for lines
        slea.readMapleAsciiString();
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 509) {
        String sendTo = slea.readMapleAsciiString();
        String msg = slea.readMapleAsciiString();
        try {
            player.sendNote(sendTo, msg, (byte) 0);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        remove(c, itemId);
    } else if (itemType == 510) {
        player.getMap().broadcastMessage(MaplePacketCreator.musicChange("Jukebox/Congratulation"));
        remove(c, itemId);
    } else if (itemType == 512) {
        if (ii.getStateChangeItem(itemId) != 0) {
            for (MapleCharacter mChar : c.getPlayer().getMap().getCharacters()) {
                ii.getItemEffect(ii.getStateChangeItem(itemId)).applyTo(mChar);
            }
        }
        player.getMap().startMapEffect(ii.getMsg(itemId).replaceFirst("%s", c.getPlayer().getName()).replaceFirst("%s", slea.readMapleAsciiString()), itemId);
        remove(c, itemId);
    } else if (itemType == 517) {
        MaplePet pet = player.getPet(0);
        if (pet == null) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        String newName = slea.readMapleAsciiString();
        pet.setName(newName);
        pet.saveToDb();
        Item item = player.getInventory(MapleInventoryType.CASH).getItem(pet.getPosition());
        if (item != null)
            player.forceUpdateItem(item);
        player.getMap().broadcastMessage(player, MaplePacketCreator.changePetName(player, newName, 1), true);
        c.announce(MaplePacketCreator.enableActions());
        remove(c, itemId);
    } else if (itemType == 504) {
        // vip teleport rock
        String error1 = "Either the player could not be found or you were trying to teleport to an illegal location.";
        boolean vip = slea.readByte() == 1;
        remove(c, itemId);
        if (!vip) {
            int mapId = slea.readInt();
            if (c.getChannelServer().getMapFactory().getMap(mapId).getForcedReturnId() == 999999999) {
                player.changeMap(c.getChannelServer().getMapFactory().getMap(mapId));
            } else {
                MapleInventoryManipulator.addById(c, itemId, (short) 1);
                c.getPlayer().dropMessage(1, error1);
                c.announce(MaplePacketCreator.enableActions());
            }
        } else {
            String name = slea.readMapleAsciiString();
            MapleCharacter victim = c.getChannelServer().getPlayerStorage().getCharacterByName(name);
            boolean success = false;
            if (victim != null) {
                MapleMap target = victim.getMap();
                if (c.getChannelServer().getMapFactory().getMap(victim.getMapId()).getForcedReturnId() == 999999999 || victim.getMapId() < 100000000) {
                    if (victim.gmLevel() <= player.gmLevel()) {
                        if (itemId == 5041000 || victim.getMapId() / player.getMapId() == 1) {
                            // viprock & same continent
                            player.changeMap(target, target.findClosestPlayerSpawnpoint(victim.getPosition()));
                            success = true;
                        } else {
                            player.dropMessage(1, "You cannot teleport between continents with this teleport rock.");
                        }
                    } else {
                        player.dropMessage(1, error1);
                    }
                } else {
                    player.dropMessage(1, "You cannot teleport to this map.");
                }
            } else {
                player.dropMessage(1, "Player could not be found in this channel.");
            }
            if (!success) {
                MapleInventoryManipulator.addById(c, itemId, (short) 1);
                c.announce(MaplePacketCreator.enableActions());
            }
        }
    } else if (itemType == 520) {
        player.gainMeso(ii.getMeso(itemId), true, false, true);
        remove(c, itemId);
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 523) {
        int itemid = slea.readInt();
        if (!ServerConstants.USE_ENFORCE_OWL_SUGGESTIONS)
            c.getWorldServer().addOwlItemSearch(itemid);
        player.setOwlSearch(itemid);
        List<Pair<MaplePlayerShopItem, AbstractMapleMapObject>> hmsAvailable = c.getWorldServer().getAvailableItemBundles(itemid);
        if (!hmsAvailable.isEmpty())
            remove(c, itemId);
        c.announce(MaplePacketCreator.owlOfMinerva(c, itemid, hmsAvailable));
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 524) {
        for (byte i = 0; i < 3; i++) {
            MaplePet pet = player.getPet(i);
            if (pet != null) {
                if (pet.canConsume(itemId)) {
                    pet.gainClosenessFullness(player, 100, 100, 1);
                    remove(c, itemId);
                    break;
                }
            } else {
                break;
            }
        }
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 530) {
        ii.getItemEffect(itemId).applyTo(player);
        remove(c, itemId);
    } else if (itemType == 533) {
        NPCScriptManager.getInstance().start(c, 9010009, null);
    } else if (itemType == 537) {
        player.setChalkboard(slea.readMapleAsciiString());
        player.getMap().broadcastMessage(MaplePacketCreator.useChalkboard(player, false));
        player.getClient().announce(MaplePacketCreator.enableActions());
    } else if (itemType == 539) {
        List<String> strLines = new LinkedList<>();
        for (int i = 0; i < 4; i++) {
            strLines.add(slea.readMapleAsciiString());
        }
        final int world = c.getWorld();
        Server.getInstance().broadcastMessage(world, MaplePacketCreator.getAvatarMega(c.getPlayer(), medal, c.getChannel(), itemId, strLines, (slea.readByte() != 0)));
        TimerManager.getInstance().schedule(new Runnable() {

            @Override
            public void run() {
                Server.getInstance().broadcastMessage(world, MaplePacketCreator.byeAvatarMega());
            }
        }, 1000 * 10);
        remove(c, itemId);
    } else if (itemType == 545) {
        // MiuMiu's travel store
        if (player.getShop() == null) {
            MapleShop shop = MapleShopFactory.getInstance().getShop(1338);
            if (shop != null) {
                shop.sendShop(c);
                remove(c, itemId);
            }
        } else {
            c.announce(MaplePacketCreator.enableActions());
        }
    } else if (itemType == 550) {
        // Extend item expiration
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 552) {
        MapleInventoryType type = MapleInventoryType.getByType((byte) slea.readInt());
        short slot = (short) slea.readInt();
        Item item = c.getPlayer().getInventory(type).getItem(slot);
        if (item == null || item.getQuantity() <= 0 || (item.getFlag() & ItemConstants.KARMA) > 0 && ii.isKarmaAble(item.getItemId())) {
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
        if (!type.equals(MapleInventoryType.USE)) {
            item.setFlag((byte) ItemConstants.KARMA);
        }
        c.getPlayer().forceUpdateItem(item);
        remove(c, itemId);
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 552) {
        // DS EGG THING
        c.announce(MaplePacketCreator.enableActions());
    } else if (itemType == 557) {
        slea.readInt();
        int itemSlot = slea.readInt();
        slea.readInt();
        final Equip equip = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) itemSlot);
        if (equip.getVicious() == 2 || c.getPlayer().getInventory(MapleInventoryType.CASH).findById(5570000) == null) {
            return;
        }
        equip.setVicious(equip.getVicious() + 1);
        equip.setUpgradeSlots(equip.getUpgradeSlots() + 1);
        remove(c, itemId);
        c.announce(MaplePacketCreator.enableActions());
        c.announce(MaplePacketCreator.sendHammerData(equip.getVicious()));
        player.forceUpdateItem(equip);
    } else if (itemType == 561) {
        // VEGA'S SPELL
        if (slea.readInt() != 1) {
            return;
        }
        final byte eSlot = (byte) slea.readInt();
        final Item eitem = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(eSlot);
        if (slea.readInt() != 2) {
            return;
        }
        final byte uSlot = (byte) slea.readInt();
        final Item uitem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(uSlot);
        if (eitem == null || uitem == null) {
            return;
        }
        Equip toScroll = (Equip) eitem;
        if (toScroll.getUpgradeSlots() < 1) {
            c.getSession().write(MaplePacketCreator.getInventoryFull());
            return;
        }
        // should have a check here against PE hacks
        if (itemId / 1000000 != 5)
            itemId = 0;
        c.getPlayer().toggleBlockCashShop();
        final int curlevel = toScroll.getLevel();
        c.getSession().write(MaplePacketCreator.sendVegaScroll(0x40));
        final Equip scrolled = (Equip) ii.scrollEquipWithId(toScroll, uitem.getItemId(), false, itemId, c.getPlayer().isGM());
        c.getSession().write(MaplePacketCreator.sendVegaScroll(scrolled.getLevel() > curlevel ? 0x41 : 0x43));
        // opcodes 0x42, 0x44: "this item cannot be used"; 0x39, 0x45: crashes
        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, uSlot, (short) 1, false);
        remove(c, itemId);
        final MapleClient client = c;
        TimerManager.getInstance().schedule(new Runnable() {

            @Override
            public void run() {
                if (!player.isLoggedin())
                    return;
                player.toggleBlockCashShop();
                final List<ModifyInventory> mods = new ArrayList<>();
                mods.add(new ModifyInventory(3, scrolled));
                mods.add(new ModifyInventory(0, scrolled));
                client.announce(MaplePacketCreator.modifyInventory(true, mods));
                ScrollResult scrollResult = scrolled.getLevel() > curlevel ? ScrollResult.SUCCESS : ScrollResult.FAIL;
                player.getMap().broadcastMessage(MaplePacketCreator.getScrollEffect(player.getId(), scrollResult, false));
                if (eSlot < 0 && (scrollResult == ScrollResult.SUCCESS)) {
                    player.equipChanged();
                }
                client.getSession().write(MaplePacketCreator.enableActions());
            }
        }, 1000 * 3);
    } else {
        System.out.println("NEW CASH ITEM: " + itemType + "\n" + slea.toString());
        c.announce(MaplePacketCreator.enableActions());
    }
}
Also used : MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Item(client.inventory.Item) MapleMap(server.maps.MapleMap) Equip(client.inventory.Equip) MapleInventoryType(client.inventory.MapleInventoryType) ScrollResult(client.inventory.Equip.ScrollResult) MapleItemInformationProvider(server.MapleItemInformationProvider) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MaplePet(client.inventory.MaplePet) Pair(tools.Pair) MapleTVEffect(server.maps.MapleTVEffect) MapleShop(server.MapleShop) LinkedList(java.util.LinkedList) ModifyInventory(client.inventory.ModifyInventory) Skill(client.Skill) MapleClient(client.MapleClient) MapleJob(client.MapleJob)

Example 23 with Skill

use of org.powerbot.bot.rt6.client.Skill in project HeavenMS by ronancpl.

the class ScrollHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    // whatever...
    slea.readInt();
    short slot = slea.readShort();
    short dst = slea.readShort();
    byte ws = (byte) slea.readShort();
    // white scroll being used?
    boolean whiteScroll = false;
    // legendary spirit skill
    boolean legendarySpirit = false;
    if ((ws & 2) == 2) {
        whiteScroll = true;
    }
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Equip toScroll = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(dst);
    Skill LegendarySpirit = SkillFactory.getSkill(1003);
    if (c.getPlayer().getSkillLevel(LegendarySpirit) > 0 && dst >= 0) {
        legendarySpirit = true;
        toScroll = (Equip) c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem(dst);
    }
    byte oldLevel = toScroll.getLevel();
    byte oldSlots = toScroll.getUpgradeSlots();
    MapleInventory useInventory = c.getPlayer().getInventory(MapleInventoryType.USE);
    Item scroll = useInventory.getItem(slot);
    Item wscroll = null;
    if (((Equip) toScroll).getUpgradeSlots() < 1 && !ItemConstants.isCleanSlate(scroll.getItemId())) {
        c.announce(MaplePacketCreator.getInventoryFull());
        return;
    }
    List<Integer> scrollReqs = ii.getScrollReqs(scroll.getItemId());
    if (scrollReqs.size() > 0 && !scrollReqs.contains(toScroll.getItemId())) {
        c.announce(MaplePacketCreator.getInventoryFull());
        return;
    }
    if (whiteScroll) {
        wscroll = useInventory.findById(2340000);
        if (wscroll == null || wscroll.getItemId() != 2340000) {
            whiteScroll = false;
        }
    }
    if (!ItemConstants.isChaosScroll(scroll.getItemId()) && !ItemConstants.isCleanSlate(scroll.getItemId())) {
        if (!canScroll(scroll.getItemId(), toScroll.getItemId())) {
            return;
        }
    }
    if (ItemConstants.isCleanSlate(scroll.getItemId()) && !(toScroll.getLevel() + toScroll.getUpgradeSlots() < ii.getEquipStats(toScroll.getItemId()).get("tuc"))) {
        // upgrade slots can be over because of hammers
        return;
    }
    Equip scrolled = (Equip) ii.scrollEquipWithId(toScroll, scroll.getItemId(), whiteScroll, 0, c.getPlayer().isGM());
    // fail
    ScrollResult scrollSuccess = Equip.ScrollResult.FAIL;
    if (scrolled == null) {
        scrollSuccess = Equip.ScrollResult.CURSE;
    } else if (scrolled.getLevel() > oldLevel || (ItemConstants.isCleanSlate(scroll.getItemId()) && scrolled.getUpgradeSlots() == oldSlots + 1) || ItemConstants.isFlagModifier(scroll.getItemId(), scrolled.getFlag())) {
        scrollSuccess = Equip.ScrollResult.SUCCESS;
    }
    MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, scroll.getPosition(), (short) 1, false);
    if (whiteScroll && !ItemConstants.isCleanSlate(scroll.getItemId())) {
        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, wscroll.getPosition(), (short) 1, false, false);
    }
    final List<ModifyInventory> mods = new ArrayList<>();
    if (scrollSuccess == Equip.ScrollResult.CURSE) {
        mods.add(new ModifyInventory(3, toScroll));
        if (dst < 0) {
            c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).removeItem(toScroll.getPosition());
        } else {
            c.getPlayer().getInventory(MapleInventoryType.EQUIP).removeItem(toScroll.getPosition());
        }
    } else {
        mods.add(new ModifyInventory(3, scrolled));
        mods.add(new ModifyInventory(0, scrolled));
    }
    c.announce(MaplePacketCreator.modifyInventory(true, mods));
    c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.getScrollEffect(c.getPlayer().getId(), scrollSuccess, legendarySpirit));
    if (dst < 0 && (scrollSuccess == Equip.ScrollResult.SUCCESS || scrollSuccess == Equip.ScrollResult.CURSE)) {
        c.getPlayer().equipChanged();
    }
}
Also used : ArrayList(java.util.ArrayList) MapleInventory(client.inventory.MapleInventory) ModifyInventory(client.inventory.ModifyInventory) Equip(client.inventory.Equip) Item(client.inventory.Item) Skill(client.Skill) ScrollResult(client.inventory.Equip.ScrollResult) MapleItemInformationProvider(server.MapleItemInformationProvider)

Example 24 with Skill

use of org.powerbot.bot.rt6.client.Skill in project HeavenMS by ronancpl.

the class MaplePacketCreator method addSkillInfo.

private static void addSkillInfo(final MaplePacketLittleEndianWriter mplew, MapleCharacter chr) {
    // start of skills
    mplew.write(0);
    Map<Skill, MapleCharacter.SkillEntry> skills = chr.getSkills();
    int skillsSize = skills.size();
    // We don't want to include any hidden skill in this, so subtract them from the size list and ignore them.
    for (Iterator<Entry<Skill, SkillEntry>> it = skills.entrySet().iterator(); it.hasNext(); ) {
        Entry<Skill, MapleCharacter.SkillEntry> skill = it.next();
        if (GameConstants.isHiddenSkills(skill.getKey().getId())) {
            skillsSize--;
        }
    }
    mplew.writeShort(skillsSize);
    for (Iterator<Entry<Skill, SkillEntry>> it = skills.entrySet().iterator(); it.hasNext(); ) {
        Entry<Skill, MapleCharacter.SkillEntry> skill = it.next();
        if (GameConstants.isHiddenSkills(skill.getKey().getId())) {
            continue;
        }
        mplew.writeInt(skill.getKey().getId());
        mplew.writeInt(skill.getValue().skillevel);
        addExpirationTime(mplew, skill.getValue().expiration);
        if (skill.getKey().isFourthJob()) {
            mplew.writeInt(skill.getValue().masterlevel);
        }
    }
    mplew.writeShort(chr.getAllCooldowns().size());
    for (PlayerCoolDownValueHolder cooling : chr.getAllCooldowns()) {
        mplew.writeInt(cooling.skillId);
        int timeLeft = (int) (cooling.length + cooling.startTime - System.currentTimeMillis());
        mplew.writeShort(timeLeft / 1000);
    }
}
Also used : SkillEntry(client.MapleCharacter.SkillEntry) Skill(client.Skill) MobSkill(server.life.MobSkill) SkillEntry(client.MapleCharacter.SkillEntry) SummonAttackEntry(net.server.channel.handlers.SummonDamageHandler.SummonAttackEntry) Entry(java.util.Map.Entry) MapleFamilyEntry(client.MapleFamilyEntry) BuddylistEntry(client.BuddylistEntry) PlayerCoolDownValueHolder(net.server.PlayerCoolDownValueHolder) Point(java.awt.Point)

Example 25 with Skill

use of org.powerbot.bot.rt6.client.Skill in project powerbot by powerbot.

the class Skills method levels.

public int[] levels() {
    final Client client = ctx.client();
    if (client == null) {
        return new int[0];
    }
    final PlayerFacade info = client.getPlayerFacade();
    final Skill[] skills;
    if (info == null || (skills = info.getSkills()) == null) {
        return new int[0];
    }
    final int[] levels = new int[skills.length];
    for (int i = 0; i < skills.length; i++) {
        final Skill s = skills[i];
        if (!s.isNull()) {
            levels[i] = s.getEffectiveLevel();
        }
    }
    return levels;
}
Also used : Skill(org.powerbot.bot.rt6.client.Skill) PlayerFacade(org.powerbot.bot.rt6.client.PlayerFacade) Client(org.powerbot.bot.rt6.client.Client)

Aggregations

Skill (client.Skill)23 MapleCharacter (client.MapleCharacter)12 Point (java.awt.Point)9 MapleStatEffect (server.MapleStatEffect)9 Item (client.inventory.Item)6 ArrayList (java.util.ArrayList)6 MapleMonster (server.life.MapleMonster)6 MonsterStatusEffect (client.status.MonsterStatusEffect)5 MobSkill (server.life.MobSkill)4 MapleMap (server.maps.MapleMap)4 MapleItemInformationProvider (server.MapleItemInformationProvider)3 Equip (client.inventory.Equip)2 ScrollResult (client.inventory.Equip.ScrollResult)2 MapleInventory (client.inventory.MapleInventory)2 MapleInventoryType (client.inventory.MapleInventoryType)2 ModifyInventory (client.inventory.ModifyInventory)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 List (java.util.List)2 Client (org.powerbot.bot.rt6.client.Client)2