Search in sources :

Example 21 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MoveDragonHandler method handlePacket.

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final MapleCharacter chr = c.getPlayer();
    final Point startPos = new Point(slea.readShort(), slea.readShort());
    List<LifeMovementFragment> res = parseMovement(slea);
    final MapleDragon dragon = chr.getDragon();
    if (dragon != null && res != null && res.size() > 0) {
        updatePosition(res, dragon, 0);
        if (chr.isHidden()) {
            chr.getMap().broadcastGMMessage(chr, MaplePacketCreator.moveDragon(dragon, startPos, res));
        } else {
            chr.getMap().broadcastMessage(chr, MaplePacketCreator.moveDragon(dragon, startPos, res), dragon.getPosition());
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) LifeMovementFragment(server.movement.LifeMovementFragment) MapleDragon(server.maps.MapleDragon) Point(java.awt.Point)

Example 22 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MoveLifeHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    int objectid = slea.readInt();
    short moveid = slea.readShort();
    MapleMapObject mmo = c.getPlayer().getMap().getMapObject(objectid);
    if (mmo == null || mmo.getType() != MapleMapObjectType.MONSTER) {
        return;
    }
    MapleMonster monster = (MapleMonster) mmo;
    List<LifeMovementFragment> res = null;
    List<MapleCharacter> banishPlayers = new ArrayList<>();
    byte pNibbles = slea.readByte();
    byte rawActivity = slea.readByte();
    byte useSkillId = slea.readByte();
    byte useSkillLevel = slea.readByte();
    short pOption = slea.readShort();
    slea.skip(8);
    if (rawActivity >= 0) {
        rawActivity = (byte) (rawActivity & 0xFF >> 1);
    }
    boolean isAttack = inRangeInclusive(rawActivity, 12, 20);
    boolean isSkill = inRangeInclusive(rawActivity, 21, 25);
    byte attackId = (byte) (isAttack ? rawActivity - 12 : -1);
    boolean nextMovementCouldBeSkill = (pNibbles & 0x0F) != 0;
    boolean pUnk = (pNibbles & 0xF0) != 0;
    int nextCastSkill = useSkillId;
    int nextCastSkillLevel = useSkillLevel;
    MobSkill toUse = null;
    int percHpLeft = (int) (((float) monster.getHp() / monster.getMaxHp()) * 100);
    if (nextMovementCouldBeSkill && monster.getNoSkills() > 0) {
        int Random = Randomizer.nextInt(monster.getNoSkills());
        Pair<Integer, Integer> skillToUse = monster.getSkills().get(Random);
        nextCastSkill = skillToUse.getLeft();
        nextCastSkillLevel = skillToUse.getRight();
        toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel);
        if (isSkill || isAttack) {
            if (nextCastSkill != toUse.getSkillId() || nextCastSkillLevel != toUse.getSkillLevel()) {
                // toUse.resetAnticipatedSkill();
                return;
            } else if (toUse.getHP() < percHpLeft) {
                toUse = null;
            } else if (monster.canUseSkill(toUse)) {
                toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
            // System.out.println("Applied: " + nextCastSkill + " Level: " + nextCastSkillLevel);
            }
        } else {
            MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
        // System.out.println("Attacked");
        }
    }
    slea.readByte();
    // whatever
    slea.readInt();
    // hmm.. startpos?
    short start_x = slea.readShort();
    // hmm...
    short start_y = slea.readShort();
    Point startPos = new Point(start_x, start_y);
    res = parseMovement(slea);
    if (monster.getController() != c.getPlayer()) {
        if (monster.isAttackedBy(c.getPlayer())) {
            monster.switchController(c.getPlayer(), true);
        } else {
            return;
        }
    } else if (rawActivity == -1 && monster.isControllerKnowsAboutAggro() && !monster.isMobile() && !monster.isFirstAttack()) {
        monster.setControllerHasAggro(false);
        monster.setControllerKnowsAboutAggro(false);
    }
    boolean aggro = monster.isControllerHasAggro();
    if (toUse != null) {
        c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro, toUse.getSkillId(), toUse.getSkillLevel()));
    } else {
        c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro));
    }
    if (aggro) {
        monster.setControllerKnowsAboutAggro(true);
    }
    if (res != null) {
        c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.moveMonster(objectid, nextMovementCouldBeSkill, rawActivity, useSkillId, useSkillLevel, pOption, startPos, res), monster.getPosition());
        updatePosition(res, monster, -1);
        c.getPlayer().getMap().moveMonster(monster, monster.getPosition());
    }
    for (MapleCharacter chr : banishPlayers) {
        chr.changeMapBanish(monster.getBanish().getMap(), monster.getBanish().getPortal(), monster.getBanish().getMsg());
    }
}
Also used : MapleCharacter(client.MapleCharacter) ArrayList(java.util.ArrayList) MapleMapObject(server.maps.MapleMapObject) MobAttackInfo(server.life.MobAttackInfo) Point(java.awt.Point) Point(java.awt.Point) LifeMovementFragment(server.movement.LifeMovementFragment) MobSkill(server.life.MobSkill) MapleMonster(server.life.MapleMonster)

Example 23 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class SkillBookHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!c.getPlayer().isAlive()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    slea.readInt();
    short slot = (short) slea.readShort();
    int itemId = slea.readInt();
    MapleCharacter player = c.getPlayer();
    Item toUse = c.getPlayer().getInventory(MapleInventoryType.USE).getItem(slot);
    if (toUse != null && toUse.getQuantity() == 1) {
        if (toUse.getItemId() != itemId) {
            return;
        }
        Map<String, Integer> skilldata = MapleItemInformationProvider.getInstance().getSkillStats(toUse.getItemId(), c.getPlayer().getJob().getId());
        boolean canuse;
        boolean success = false;
        int skill = 0;
        int maxlevel = 0;
        if (skilldata == null) {
            return;
        }
        Skill skill2 = SkillFactory.getSkill(skilldata.get("skillid"));
        if (skilldata.get("skillid") == 0) {
            canuse = false;
        } else if ((player.getSkillLevel(skill2) >= skilldata.get("reqSkillLevel") || skilldata.get("reqSkillLevel") == 0) && player.getMasterLevel(skill2) < skilldata.get("masterLevel")) {
            canuse = true;
            if (MapleItemInformationProvider.rollSuccessChance(skilldata.get("success"))) {
                success = true;
                player.changeSkillLevel(skill2, player.getSkillLevel(skill2), Math.max(skilldata.get("masterLevel"), player.getMasterLevel(skill2)), -1);
            } else {
                success = false;
            // player.dropMessage("The skill book lights up, but the skill winds up as if nothing happened.");
            }
            MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, slot, (short) 1, false);
        } else {
            canuse = false;
        }
        player.getClient().announce(MaplePacketCreator.skillBookSuccess(player, skill, maxlevel, canuse, success));
    }
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) Skill(client.Skill)

Example 24 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class SnowballHandler method handlePacket.

public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    // D3 00 02 00 00 A5 01
    MapleCharacter chr = c.getPlayer();
    MapleMap map = chr.getMap();
    final MapleSnowball snowball = map.getSnowball(chr.getTeam());
    final MapleSnowball othersnowball = map.getSnowball(chr.getTeam() == 0 ? (byte) 1 : 0);
    int what = slea.readByte();
    if (snowball == null || othersnowball == null || snowball.getSnowmanHP() == 0)
        return;
    if ((System.currentTimeMillis() - chr.getLastSnowballAttack()) < 500)
        return;
    if (chr.getTeam() != (what % 2))
        return;
    chr.setLastSnowballAttack(System.currentTimeMillis());
    int damage = 0;
    if (what < 2 && othersnowball.getSnowmanHP() > 0)
        damage = 10;
    else if (what == 2 || what == 3) {
        if (Math.random() < 0.03)
            damage = 45;
        else
            damage = 15;
    }
    if (what >= 0 && what <= 4)
        snowball.hit(what, damage);
}
Also used : MapleMap(server.maps.MapleMap) MapleSnowball(server.events.gm.MapleSnowball) MapleCharacter(client.MapleCharacter)

Example 25 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class SpawnPetHandler method handlePacket.

public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    slea.readInt();
    byte slot = slea.readByte();
    slea.readByte();
    boolean lead = slea.readByte() == 1;
    MaplePet pet = chr.getInventory(MapleInventoryType.CASH).getItem(slot).getPet();
    if (pet == null)
        return;
    int petid = pet.getItemId();
    if (// Handles Dragon AND Robos
    petid == 5000028 || petid == 5000047) {
        if (chr.haveItem(petid + 1)) {
            chr.dropMessage(5, "You can't hatch your " + (petid == 5000028 ? "Dragon egg" : "Robo egg") + " if you already have a Baby " + (petid == 5000028 ? "Dragon." : "Robo."));
            c.announce(MaplePacketCreator.enableActions());
            return;
        } else {
            int evolveid = MapleDataTool.getInt("info/evol1", dataRoot.getData("Pet/" + petid + ".img"));
            int petId = MaplePet.createPet(evolveid);
            if (petId == -1) {
                return;
            }
            long expiration = chr.getInventory(MapleInventoryType.CASH).getItem(slot).getExpiration();
            MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, petid, (short) 1, false, false);
            MapleInventoryManipulator.addById(c, evolveid, (short) 1, null, petId, expiration);
            pet.deleteFromDb();
            c.announce(MaplePacketCreator.enableActions());
            return;
        }
    }
    if (chr.getPetIndex(pet) != -1) {
        chr.unequipPet(pet, true);
    } else {
        if (chr.getSkillLevel(SkillFactory.getSkill(8)) == 0 && chr.getPet(0) != null) {
            chr.unequipPet(chr.getPet(0), false);
        }
        if (lead) {
            chr.shiftPetsRight();
        }
        Point pos = chr.getPosition();
        pos.y -= 12;
        pet.setPos(pos);
        pet.setFh(chr.getMap().getFootholds().findBelow(pet.getPos()).getId());
        pet.setStance(0);
        pet.setSummoned(true);
        pet.saveToDb();
        chr.addPet(pet);
        chr.getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showPet(c.getPlayer(), pet, false, false), true);
        c.announce(MaplePacketCreator.petStatUpdate(c.getPlayer()));
        c.announce(MaplePacketCreator.enableActions());
        chr.commitExcludedItems();
        chr.getClient().getWorldServer().registerPetHunger(chr, chr.getPetIndex(pet));
    }
}
Also used : MapleCharacter(client.MapleCharacter) Point(java.awt.Point) MaplePet(client.inventory.MaplePet) Point(java.awt.Point)

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