Search in sources :

Example 16 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class CloseRangeDamageHandler 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, false, 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 (// PE hacking or maybe just lagging
    chr.getDojoEnergy() < 10000 && (attack.skill == 1009 || attack.skill == 10001009 || attack.skill == 20001009))
        return;
    if (chr.getMap().isDojoMap() && attack.numAttacked > 0) {
        chr.setDojoEnergy(chr.getDojoEnergy() + ServerConstants.DOJO_ENERGY_ATK);
        c.announce(MaplePacketCreator.getEnergy("energy", chr.getDojoEnergy()));
    }
    chr.getMap().broadcastMessage(chr, MaplePacketCreator.closeRangeAttack(chr, attack.skill, attack.skilllevel, attack.stance, attack.numAttackedAndDamage, attack.allDamage, attack.speed, attack.direction, attack.display), false, true);
    int numFinisherOrbs = 0;
    Integer comboBuff = chr.getBuffedValue(MapleBuffStat.COMBO);
    if (GameConstants.isFinisherSkill(attack.skill)) {
        if (comboBuff != null) {
            numFinisherOrbs = comboBuff.intValue() - 1;
        }
        chr.handleOrbconsume();
    } else if (attack.numAttacked > 0) {
        if (attack.skill != 1111008 && comboBuff != null) {
            int orbcount = chr.getBuffedValue(MapleBuffStat.COMBO);
            int oid = chr.isCygnus() ? DawnWarrior.COMBO : Crusader.COMBO;
            int advcomboid = chr.isCygnus() ? DawnWarrior.ADVANCED_COMBO : Hero.ADVANCED_COMBO;
            Skill combo = SkillFactory.getSkill(oid);
            Skill advcombo = SkillFactory.getSkill(advcomboid);
            MapleStatEffect ceffect;
            int advComboSkillLevel = chr.getSkillLevel(advcombo);
            if (advComboSkillLevel > 0) {
                ceffect = advcombo.getEffect(advComboSkillLevel);
            } else {
                int comboLv = chr.getSkillLevel(combo);
                if (comboLv <= 0 || chr.isGM())
                    comboLv = SkillFactory.getSkill(oid).getMaxLevel();
                if (comboLv > 0)
                    ceffect = combo.getEffect(comboLv);
                else
                    ceffect = null;
            }
            if (ceffect != null) {
                if (orbcount < ceffect.getX() + 1) {
                    int neworbcount = orbcount + 1;
                    if (advComboSkillLevel > 0 && ceffect.makeChanceResult()) {
                        if (neworbcount <= ceffect.getX()) {
                            neworbcount++;
                        }
                    }
                    int olv = chr.getSkillLevel(oid);
                    if (olv <= 0)
                        olv = SkillFactory.getSkill(oid).getMaxLevel();
                    int duration = combo.getEffect(olv).getDuration();
                    List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.COMBO, neworbcount));
                    chr.setBuffedValue(MapleBuffStat.COMBO, neworbcount);
                    duration -= (int) (System.currentTimeMillis() - chr.getBuffedStarttime(MapleBuffStat.COMBO));
                    c.announce(MaplePacketCreator.giveBuff(oid, duration, stat));
                    chr.getMap().broadcastMessage(chr, MaplePacketCreator.giveForeignBuff(chr.getId(), stat), false);
                }
            }
        } else if (chr.getSkillLevel(chr.isCygnus() ? SkillFactory.getSkill(15100004) : SkillFactory.getSkill(5110001)) > 0 && (chr.getJob().isA(MapleJob.MARAUDER) || chr.getJob().isA(MapleJob.THUNDERBREAKER2))) {
            for (int i = 0; i < attack.numAttacked; i++) {
                chr.handleEnergyChargeGain();
            }
        }
    }
    if (attack.numAttacked > 0 && attack.skill == DragonKnight.SACRIFICE) {
        // sacrifice attacks only 1 mob with 1 attack
        int totDamageToOneMonster = 0;
        final Iterator<List<Integer>> dmgIt = attack.allDamage.values().iterator();
        if (dmgIt.hasNext()) {
            totDamageToOneMonster = dmgIt.next().get(0).intValue();
        }
        int remainingHP = chr.getHp() - totDamageToOneMonster * attack.getAttackEffect(chr, null).getX() / 100;
        if (remainingHP > 1) {
            chr.setHp(remainingHP);
        } else {
            chr.setHp(1);
        }
        chr.updateSingleStat(MapleStat.HP, chr.getHp());
        chr.checkBerserk(chr.isHidden());
    }
    if (attack.numAttacked > 0 && attack.skill == 1211002) {
        boolean advcharge_prob = false;
        int advcharge_level = chr.getSkillLevel(SkillFactory.getSkill(1220010));
        if (advcharge_level > 0) {
            advcharge_prob = SkillFactory.getSkill(1220010).getEffect(advcharge_level).makeChanceResult();
        }
        if (!advcharge_prob) {
            chr.cancelEffectFromBuffStat(MapleBuffStat.WK_CHARGE);
        }
    }
    int attackCount = 1;
    if (attack.skill != 0) {
        attackCount = attack.getAttackEffect(chr, null).getAttackCount();
    }
    if (numFinisherOrbs == 0 && GameConstants.isFinisherSkill(attack.skill)) {
        return;
    }
    if (attack.skill % 10000000 == 1009) {
        // bamboo
        if (chr.getDojoEnergy() < 10000) {
            // PE hacking or maybe just lagging
            return;
        }
        chr.setDojoEnergy(0);
        c.announce(MaplePacketCreator.getEnergy("energy", chr.getDojoEnergy()));
        c.announce(MaplePacketCreator.serverNotice(5, "As you used the secret skill, your energy bar has been reset."));
    } else 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.getSkillLevel(SkillFactory.getSkill(Rogue.DARK_SIGHT)) > 0) && chr.getBuffedValue(MapleBuffStat.DARKSIGHT) != null) {
        // && 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) {
        chr.cancelEffectFromBuffStat(MapleBuffStat.WIND_WALK);
        chr.cancelBuffStats(MapleBuffStat.WIND_WALK);
    }
    applyAttack(attack, chr, attackCount);
}
Also used : MapleBuffStat(client.MapleBuffStat) MapleCharacter(client.MapleCharacter) Skill(client.Skill) MapleStatEffect(server.MapleStatEffect) List(java.util.List) Pair(tools.Pair)

Example 17 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class DataTool method npcIdsFromName.

public static ArrayList<Integer> npcIdsFromName(String name) {
    MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz"));
    ArrayList<Integer> ret = new ArrayList<>();
    if (npc_list == null) {
        ArrayList<Pair<Integer, String>> searchList = new ArrayList<>();
        for (MapleData searchData : dataProvider.getData("Npc.img").getChildren()) {
            int searchFromData = Integer.parseInt(searchData.getName());
            String infoFromData = MapleDataTool.getString(searchData.getChildByPath("name"), "NO-NAME");
            searchList.add(new Pair<>(searchFromData, infoFromData));
        }
        npc_list = searchList;
    }
    for (Pair<Integer, String> searched : npc_list) {
        if (searched.getRight().toLowerCase().contains(name.toLowerCase())) {
            ret.add(searched.getLeft());
        }
    }
    return ret;
}
Also used : MapleData(provider.MapleData) ArrayList(java.util.ArrayList) MapleDataProvider(provider.MapleDataProvider) File(java.io.File) Pair(tools.Pair)

Example 18 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class MapleItemInformationProvider method getItemReward.

public Pair<Integer, List<RewardItem>> getItemReward(int itemId) {
    // Thanks Celino, used some stuffs :)
    if (rewardCache.containsKey(itemId)) {
        return rewardCache.get(itemId);
    }
    int totalprob = 0;
    List<RewardItem> rewards = new ArrayList<>();
    for (MapleData child : getItemData(itemId).getChildByPath("reward").getChildren()) {
        RewardItem reward = new RewardItem();
        reward.itemid = MapleDataTool.getInt("item", child, 0);
        reward.prob = (byte) MapleDataTool.getInt("prob", child, 0);
        reward.quantity = (short) MapleDataTool.getInt("count", child, 0);
        reward.effect = MapleDataTool.getString("Effect", child, "");
        reward.worldmsg = MapleDataTool.getString("worldMsg", child, null);
        reward.period = MapleDataTool.getInt("period", child, -1);
        totalprob += reward.prob;
        rewards.add(reward);
    }
    Pair<Integer, List<RewardItem>> hmm = new Pair<>(totalprob, rewards);
    rewardCache.put(itemId, hmm);
    return hmm;
}
Also used : MapleData(provider.MapleData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Pair(tools.Pair)

Example 19 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class MapleItemInformationProvider method getAllItems.

// public MapleInventoryType getInventoryType(int itemId) {
// if (inventoryTypeCache.containsKey(itemId)) {
// return inventoryTypeCache.get(itemId);
// }
// MapleInventoryType ret;
// String idStr = "0" + String.valueOf(itemId);
// MapleDataDirectoryEntry root = itemData.getRoot();
// for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {
// for (MapleDataFileEntry iFile : topDir.getFiles()) {
// if (iFile.getName().equals(idStr.substring(0, 4) + ".img")) {
// ret = MapleInventoryType.getByWZName(topDir.getName());
// inventoryTypeCache.put(itemId, ret);
// return ret;
// } else if (iFile.getName().equals(idStr.substring(1) + ".img")) {
// ret = MapleInventoryType.getByWZName(topDir.getName());
// inventoryTypeCache.put(itemId, ret);
// return ret;
// }
// }
// }
// root = equipData.getRoot();
// for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {
// for (MapleDataFileEntry iFile : topDir.getFiles()) {
// if (iFile.getName().equals(idStr + ".img")) {
// ret = MapleInventoryType.EQUIP;
// inventoryTypeCache.put(itemId, ret);
// return ret;
// }
// }
// }
// ret = MapleInventoryType.UNDEFINED;
// inventoryTypeCache.put(itemId, ret);
// return ret;
// }
public List<Pair<Integer, String>> getAllItems() {
    if (!itemNameCache.isEmpty()) {
        return itemNameCache;
    }
    List<Pair<Integer, String>> itemPairs = new ArrayList<>();
    MapleData itemsData;
    itemsData = stringData.getData("Cash.img");
    for (MapleData itemFolder : itemsData.getChildren()) {
        itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
    }
    itemsData = stringData.getData("Consume.img");
    for (MapleData itemFolder : itemsData.getChildren()) {
        itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
    }
    itemsData = stringData.getData("Eqp.img").getChildByPath("Eqp");
    for (MapleData eqpType : itemsData.getChildren()) {
        for (MapleData itemFolder : eqpType.getChildren()) {
            itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
        }
    }
    itemsData = stringData.getData("Etc.img").getChildByPath("Etc");
    for (MapleData itemFolder : itemsData.getChildren()) {
        itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
    }
    itemsData = stringData.getData("Ins.img");
    for (MapleData itemFolder : itemsData.getChildren()) {
        itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
    }
    itemsData = stringData.getData("Pet.img");
    for (MapleData itemFolder : itemsData.getChildren()) {
        itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
    }
    return itemPairs;
}
Also used : MapleData(provider.MapleData) ArrayList(java.util.ArrayList) Pair(tools.Pair)

Example 20 with Pair

use of tools.Pair in project HeavenMS by ronancpl.

the class MapleItemInformationProvider method getAllEtcItems.

public List<Pair<Integer, String>> getAllEtcItems() {
    if (!itemNameCache.isEmpty()) {
        return itemNameCache;
    }
    List<Pair<Integer, String>> itemPairs = new ArrayList<>();
    MapleData itemsData;
    itemsData = stringData.getData("Etc.img").getChildByPath("Etc");
    for (MapleData itemFolder : itemsData.getChildren()) {
        itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
    }
    return itemPairs;
}
Also used : MapleData(provider.MapleData) ArrayList(java.util.ArrayList) Pair(tools.Pair)

Aggregations

Pair (tools.Pair)51 ArrayList (java.util.ArrayList)34 Point (java.awt.Point)16 Item (client.inventory.Item)15 LinkedList (java.util.LinkedList)12 MapleData (provider.MapleData)11 SQLException (java.sql.SQLException)10 PreparedStatement (java.sql.PreparedStatement)7 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 MobSkill (server.life.MobSkill)6 MapleCharacter (client.MapleCharacter)5 Connection (java.sql.Connection)5 ResultSet (java.sql.ResultSet)5 MapleMap (server.maps.MapleMap)5 LinkedHashMap (java.util.LinkedHashMap)4 CharacterIdChannelPair (net.server.channel.CharacterIdChannelPair)4 MaplePartyCharacter (net.server.world.MaplePartyCharacter)4 MapleStatEffect (server.MapleStatEffect)4 DatabaseConnection (tools.DatabaseConnection)4