Search in sources :

Example 51 with MapleCharacter

use of client.MapleCharacter 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 52 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class DenyGuildRequestHandler method handlePacket.

public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    slea.readByte();
    MapleCharacter cfrom = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
    if (cfrom != null) {
        cfrom.getClient().announce(MaplePacketCreator.denyGuildInvitation(c.getPlayer().getName()));
    }
}
Also used : MapleCharacter(client.MapleCharacter)

Example 53 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class BBSOperationHandler method deleteBBSReply.

public static void deleteBBSReply(MapleClient client, int replyid) {
    MapleCharacter mc = client.getPlayer();
    if (mc.getGuildId() <= 0) {
        return;
    }
    int threadid;
    Connection con = null;
    try {
        con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT postercid, threadid FROM bbs_replies WHERE replyid = ?");
        ps.setInt(1, replyid);
        ResultSet rs = ps.executeQuery();
        if (!rs.next()) {
            rs.close();
            ps.close();
            return;
        }
        if (mc.getId() != rs.getInt("postercid") && mc.getGuildRank() > 2) {
            rs.close();
            ps.close();
            return;
        }
        threadid = rs.getInt("threadid");
        rs.close();
        ps.close();
        ps = con.prepareStatement("DELETE FROM bbs_replies WHERE replyid = ?");
        ps.setInt(1, replyid);
        ps.execute();
        ps.close();
        ps = con.prepareStatement("UPDATE bbs_threads SET replycount = replycount - 1 WHERE threadid = ?");
        ps.setInt(1, threadid);
        ps.execute();
        ps.close();
        con.close();
        displayThread(client, threadid, false);
    } catch (SQLException se) {
        se.printStackTrace();
    }
}
Also used : MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 54 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class BBSOperationHandler method newBBSThread.

private static void newBBSThread(MapleClient client, String title, String text, int icon, boolean bNotice) {
    MapleCharacter c = client.getPlayer();
    if (c.getGuildId() <= 0) {
        return;
    }
    int nextId = 0;
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps;
        if (!bNotice) {
            ps = con.prepareStatement("SELECT MAX(localthreadid) AS lastLocalId FROM bbs_threads WHERE guildid = ?");
            ps.setInt(1, c.getGuildId());
            try (ResultSet rs = ps.executeQuery()) {
                rs.next();
                nextId = rs.getInt("lastLocalId") + 1;
            }
            ps.close();
        }
        ps = con.prepareStatement("INSERT INTO bbs_threads " + "(`postercid`, `name`, `timestamp`, `icon`, `startpost`, " + "`guildid`, `localthreadid`) " + "VALUES(?, ?, ?, ?, ?, ?, ?)");
        ps.setInt(1, c.getId());
        ps.setString(2, title);
        ps.setLong(3, System.currentTimeMillis());
        ps.setInt(4, icon);
        ps.setString(5, text);
        ps.setInt(6, c.getGuildId());
        ps.setInt(7, nextId);
        ps.execute();
        ps.close();
        con.close();
        displayThread(client, nextId);
    } catch (SQLException se) {
        se.printStackTrace();
    }
}
Also used : MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 55 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class BBSOperationHandler method deleteBBSThread.

public static void deleteBBSThread(MapleClient client, int localthreadid) {
    MapleCharacter mc = client.getPlayer();
    if (mc.getGuildId() <= 0) {
        return;
    }
    Connection con = null;
    try {
        con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT threadid, postercid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?");
        ps.setInt(1, mc.getGuildId());
        ps.setInt(2, localthreadid);
        ResultSet threadRS = ps.executeQuery();
        if (!threadRS.next()) {
            threadRS.close();
            ps.close();
            return;
        }
        if (mc.getId() != threadRS.getInt("postercid") && mc.getGuildRank() > 2) {
            threadRS.close();
            ps.close();
            return;
        }
        int threadid = threadRS.getInt("threadid");
        ps.close();
        ps = con.prepareStatement("DELETE FROM bbs_replies WHERE threadid = ?");
        ps.setInt(1, threadid);
        ps.execute();
        ps.close();
        ps = con.prepareStatement("DELETE FROM bbs_threads WHERE threadid = ?");
        ps.setInt(1, threadid);
        ps.execute();
        threadRS.close();
        ps.close();
        con.close();
    } catch (SQLException se) {
        se.printStackTrace();
    }
}
Also used : MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MapleCharacter (client.MapleCharacter)163 Point (java.awt.Point)32 SQLException (java.sql.SQLException)22 Item (client.inventory.Item)21 Connection (java.sql.Connection)15 PreparedStatement (java.sql.PreparedStatement)15 MapleMonster (server.life.MapleMonster)15 MapleMapObject (server.maps.MapleMapObject)15 DatabaseConnection (tools.DatabaseConnection)15 MapleMap (server.maps.MapleMap)14 ArrayList (java.util.ArrayList)13 Skill (client.Skill)12 SpawnPoint (server.life.SpawnPoint)12 LinkedList (java.util.LinkedList)11 MapleInventory (client.inventory.MapleInventory)10 World (net.server.world.World)10 MapleStatEffect (server.MapleStatEffect)10 MapleInventoryType (client.inventory.MapleInventoryType)9 ResultSet (java.sql.ResultSet)9 MapleItemInformationProvider (server.MapleItemInformationProvider)9