Search in sources :

Example 1 with MapleDoor

use of server.maps.MapleDoor in project HeavenMS by ronancpl.

the class MaplePacketCreator method partyCreated.

public static byte[] partyCreated(MaplePartyCharacter partychar) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.PARTY_OPERATION.getValue());
    mplew.write(8);
    mplew.writeShort(0x8b);
    mplew.writeShort(1);
    if (partychar.getDoors().size() > 0) {
        boolean deployedPortal = false;
        for (MapleDoor door : partychar.getDoors()) {
            if (door.getOwnerId() == partychar.getId()) {
                MapleDoorObject mdo = door.getAreaDoor();
                mplew.writeInt(mdo.getTo().getId());
                mplew.writeInt(mdo.getFrom().getId());
                mplew.writeInt(mdo.getPosition().x);
                mplew.writeInt(mdo.getPosition().y);
                deployedPortal = true;
            }
        }
        if (!deployedPortal) {
            mplew.writeInt(999999999);
            mplew.writeInt(999999999);
            mplew.writeInt(0);
            mplew.writeInt(0);
        }
    } else {
        mplew.writeInt(999999999);
        mplew.writeInt(999999999);
        mplew.writeInt(0);
        mplew.writeInt(0);
    }
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MapleDoorObject(server.maps.MapleDoorObject) MapleDoor(server.maps.MapleDoor)

Example 2 with MapleDoor

use of server.maps.MapleDoor in project HeavenMS by ronancpl.

the class MapleStatEffect method applyTo.

// primary: the player caster of the buff
private boolean applyTo(MapleCharacter applyfrom, MapleCharacter applyto, boolean primary, Point pos, boolean useMaxRange) {
    if (skill && (sourceid == GM.HIDE || sourceid == SuperGM.HIDE)) {
        applyto.toggleHide(false);
        return true;
    }
    int hpchange = calcHPChange(applyfrom, primary);
    int mpchange = calcMPChange(applyfrom, primary);
    if (primary) {
        if (itemConNo != 0) {
            if (!applyto.getClient().getAbstractPlayerInteraction().hasItem(itemCon, itemConNo)) {
                applyto.getClient().announce(MaplePacketCreator.enableActions());
                return false;
            }
            MapleInventoryManipulator.removeById(applyto.getClient(), ItemConstants.getInventoryType(itemCon), itemCon, itemConNo, false, true);
        }
    }
    List<Pair<MapleStat, Integer>> hpmpupdate = new ArrayList<>(2);
    if (!primary) {
        if (isResurrection()) {
            hpchange = applyto.getMaxHp();
            applyto.setStance(0);
            applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.removePlayerFromMap(applyto.getId()), false);
            applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.spawnPlayerMapObject(applyto), false);
        }
    }
    if (isDispel() && makeChanceResult()) {
        applyto.dispelDebuffs();
    } else if (isCureAllAbnormalStatus()) {
        applyto.dispelDebuff(MapleDisease.SEDUCE);
        applyto.dispelDebuff(MapleDisease.ZOMBIFY);
        applyto.dispelDebuffs();
    } else if (isComboReset()) {
        applyto.setCombo((short) 0);
    }
    /*if (applyfrom.getMp() < getMpCon()) {
         AutobanFactory.MPCON.addPoint(applyfrom.getAutobanManager(), "mpCon hack for skill:" + sourceid + "; Player MP: " + applyto.getMp() + " MP Needed: " + getMpCon());
         } */
    if (hpchange != 0) {
        if (hpchange < 0 && (-hpchange) >= applyto.getHp() && (!applyto.hasDisease(MapleDisease.ZOMBIFY) || hpCon > 0)) {
            if (!applyto.isGM()) {
                applyto.getClient().announce(MaplePacketCreator.enableActions());
                return false;
            }
        }
        int newHp = applyto.getHp() + hpchange;
        if (newHp < 1) {
            newHp = 1;
        }
        applyto.setHp(newHp);
        hpmpupdate.add(new Pair<>(MapleStat.HP, Integer.valueOf(applyto.getHp())));
    }
    int newMp = applyto.getMp() + mpchange;
    if (mpchange != 0) {
        if (mpchange < 0 && -mpchange > applyto.getMp()) {
            if (!applyto.isGM()) {
                applyto.getClient().announce(MaplePacketCreator.enableActions());
                return false;
            } else {
                newMp = 0;
            }
        }
        applyto.setMp(newMp);
        hpmpupdate.add(new Pair<>(MapleStat.MP, Integer.valueOf(applyto.getMp())));
    }
    applyto.getClient().announce(MaplePacketCreator.updatePlayerStats(hpmpupdate, true, applyto));
    if (moveTo != -1) {
        if (moveTo != applyto.getMapId()) {
            MapleMap target;
            MaplePortal pt;
            if (moveTo == 999999999) {
                if (sourceid != 2030100) {
                    target = applyto.getMap().getReturnMap();
                    pt = target.getRandomPlayerSpawnpoint();
                } else {
                    if (!applyto.canRecoverLastBanish())
                        return false;
                    Pair<Integer, Integer> lastBanishInfo = applyto.getLastBanishData();
                    target = applyto.getWarpMap(lastBanishInfo.getLeft());
                    pt = target.getPortal(lastBanishInfo.getRight());
                }
            } else {
                target = applyto.getClient().getWorldServer().getChannel(applyto.getClient().getChannel()).getMapFactory().getMap(moveTo);
                int targetid = target.getId() / 10000000;
                if (targetid != 60 && applyto.getMapId() / 10000000 != 61 && targetid != applyto.getMapId() / 10000000 && targetid != 21 && targetid != 20 && targetid != 12 && (applyto.getMapId() / 10000000 != 10 && applyto.getMapId() / 10000000 != 12)) {
                    return false;
                }
                pt = target.getRandomPlayerSpawnpoint();
            }
            applyto.changeMap(target, pt);
        } else {
            return false;
        }
    }
    if (isShadowClaw()) {
        int projectile = 0;
        MapleInventory use = applyto.getInventory(MapleInventoryType.USE);
        for (int i = 1; i <= use.getSlotLimit(); i++) {
            // impose order...
            Item item = use.getItem((short) i);
            if (item != null) {
                if (ItemConstants.isThrowingStar(item.getItemId()) && item.getQuantity() >= 200) {
                    projectile = item.getItemId();
                    break;
                }
            }
        }
        if (projectile == 0) {
            return false;
        } else {
            MapleInventoryManipulator.removeById(applyto.getClient(), MapleInventoryType.USE, projectile, 200, false, true);
        }
    }
    SummonMovementType summonMovementType = getSummonMovementType();
    if (overTime || isCygnusFA() || summonMovementType != null) {
        if (summonMovementType != null && pos != null) {
            if (summonMovementType.getValue() == summonMovementType.STATIONARY.getValue())
                applyto.cancelBuffStats(MapleBuffStat.PUPPET);
            else
                applyto.cancelBuffStats(MapleBuffStat.SUMMON);
        }
        applyBuffEffect(applyfrom, applyto, primary);
    }
    if (primary && (overTime || isHeal())) {
        applyBuff(applyfrom, useMaxRange);
    }
    if (primary && isMonsterBuff()) {
        applyMonsterBuff(applyfrom);
    }
    if (this.getFatigue() != 0) {
        applyto.getMount().setTiredness(applyto.getMount().getTiredness() + this.getFatigue());
    }
    if (summonMovementType != null && pos != null) {
        final MapleSummon tosummon = new MapleSummon(applyfrom, sourceid, pos, summonMovementType);
        applyfrom.getMap().spawnSummon(tosummon);
        applyfrom.addSummon(sourceid, tosummon);
        tosummon.addHP(x);
        if (isBeholder()) {
            tosummon.addHP(1);
        }
    }
    if (isMagicDoor() && !FieldLimit.DOOR.check(applyto.getMap().getFieldLimit())) {
        // Magic Door
        int y = applyto.getFh();
        if (y == 0) {
            y = applyto.getPosition().y;
        }
        Point doorPosition = new Point(applyto.getPosition().x, y);
        MapleDoor door = new MapleDoor(applyto, doorPosition);
        if (door.getOwnerId() >= 0) {
            if (applyto.getParty() != null) {
                for (MaplePartyCharacter partyMember : applyto.getParty().getMembers()) {
                    partyMember.getPlayer().addDoor(door.getOwnerId(), door);
                    partyMember.addDoor(door.getOwnerId(), door);
                }
                applyto.silentPartyUpdate();
            } else {
                applyto.addDoor(door.getOwnerId(), door);
            }
            door.getTarget().spawnDoor(door.getAreaDoor());
            door.getTown().spawnDoor(door.getTownDoor());
            applyto.disableDoorSpawn();
        } else {
            MapleInventoryManipulator.addFromDrop(applyto.getClient(), new Item(4006000, (short) 0, (short) 1), false);
            if (door.getOwnerId() == -3)
                applyto.dropMessage(5, "Mystic Door cannot be cast far from a spawn point. Nearest one is at " + door.getDoorStatus().getRight() + "pts " + door.getDoorStatus().getLeft());
            else if (door.getOwnerId() == -2)
                applyto.dropMessage(5, "Mystic Door cannot be cast on a slope, try elsewhere.");
            else
                applyto.dropMessage(5, "There are no door portals available for the town at this moment. Try again later.");
            // cancel door buff
            applyto.cancelBuffStats(MapleBuffStat.SOULARROW);
        }
    } else if (isMist()) {
        Rectangle bounds = calculateBoundingBox(sourceid == NightWalker.POISON_BOMB ? pos : applyfrom.getPosition(), applyfrom.isFacingLeft());
        MapleMist mist = new MapleMist(bounds, applyfrom, this);
        applyfrom.getMap().spawnMist(mist, getDuration(), mist.isPoisonMist(), false, mist.isRecoveryMist());
    } else if (isTimeLeap()) {
        applyto.removeAllCooldownsExcept(Buccaneer.TIME_LEAP, true);
    } else if (isHyperBody() && !primary) {
        applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.removePlayerFromMap(applyto.getId()), false);
        applyto.getMap().broadcastMessage(applyto, MaplePacketCreator.spawnPlayerMapObject(applyto), false);
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) Point(java.awt.Point) MapleInventory(client.inventory.MapleInventory) Point(java.awt.Point) MapleMap(server.maps.MapleMap) Item(client.inventory.Item) MapleMist(server.maps.MapleMist) MapleSummon(server.maps.MapleSummon) Pair(tools.Pair) SummonMovementType(server.maps.SummonMovementType) MapleDoor(server.maps.MapleDoor) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Example 3 with MapleDoor

use of server.maps.MapleDoor in project HeavenMS by ronancpl.

the class MapleCharacter method cancelEffectInternal.

private List<Pair<MapleBuffStat, MapleBuffStatValueHolder>> cancelEffectInternal(MapleStatEffect effect, boolean overwrite, long startTime, Set<MapleBuffStat> removedStats) {
    Map<MapleBuffStat, MapleBuffStatValueHolder> buffstats = null;
    MapleBuffStat ombs;
    if (!overwrite) {
        // is removing the source effect, meaning every effect from this srcid is being purged
        buffstats = extractCurrentBuffStats(effect);
    } else if ((ombs = getSingletonStatupFromEffect(effect)) != null) {
        // removing all effects of a buff having non-shareable buff stat.
        MapleBuffStatValueHolder mbsvh = effects.get(ombs);
        if (mbsvh != null) {
            buffstats = extractCurrentBuffStats(mbsvh.effect);
        }
    }
    if (buffstats == null) {
        // all else, is dropping ALL current statups that uses same stats as the given effect
        buffstats = extractLeastRelevantStatEffectsIfFull(effect);
    }
    if (effect.isMagicDoor()) {
        MapleDoor destroyDoor;
        chrLock.lock();
        try {
            destroyDoor = doors.remove(this.getId());
        } finally {
            chrLock.unlock();
        }
        if (destroyDoor != null) {
            destroyDoor.getTarget().removeMapObject(destroyDoor.getAreaDoor());
            destroyDoor.getTown().removeMapObject(destroyDoor.getTownDoor());
            for (MapleCharacter chr : destroyDoor.getTarget().getCharacters()) {
                destroyDoor.getAreaDoor().sendDestroyData(chr.getClient());
            }
            for (MapleCharacter chr : destroyDoor.getTown().getCharacters()) {
                destroyDoor.getTownDoor().sendDestroyData(chr.getClient());
            }
            prtLock.lock();
            try {
                if (party != null) {
                    for (MaplePartyCharacter partyMembers : party.getMembers()) {
                        partyMembers.getPlayer().removeDoor(this.getId());
                        partyMembers.removeDoor(this.getId());
                    }
                    silentPartyUpdateInternal();
                }
            } finally {
                prtLock.unlock();
            }
        }
    } else if (effect.isMapChair()) {
        stopChairTask();
    }
    List<Pair<MapleBuffStat, MapleBuffStatValueHolder>> toCancel = deregisterBuffStats(buffstats);
    if (effect.getSourceId() == Spearman.HYPER_BODY || effect.getSourceId() == GM.HYPER_BODY || effect.getSourceId() == SuperGM.HYPER_BODY) {
        List<Pair<MapleStat, Integer>> statup = new ArrayList<>(4);
        statup.add(new Pair<>(MapleStat.HP, Math.min(hp, maxhp)));
        statup.add(new Pair<>(MapleStat.MP, Math.min(mp, maxmp)));
        statup.add(new Pair<>(MapleStat.MAXHP, maxhp));
        statup.add(new Pair<>(MapleStat.MAXMP, maxmp));
        client.announce(MaplePacketCreator.updatePlayerStats(statup, this));
    }
    if (effect.isMonsterRiding()) {
        if (effect.getSourceId() != Corsair.BATTLE_SHIP) {
            this.getClient().getWorldServer().unregisterMountHunger(this);
            this.getMount().setActive(false);
        }
    }
    if (!overwrite) {
        List<MapleBuffStat> cancelStats = new LinkedList<>();
        chrLock.lock();
        try {
            for (Entry<MapleBuffStat, MapleBuffStatValueHolder> mbsl : buffstats.entrySet()) {
                cancelStats.add(mbsl.getKey());
            }
        } finally {
            chrLock.unlock();
        }
        for (MapleBuffStat mbs : cancelStats) removedStats.add(mbs);
        cancelPlayerBuffs(cancelStats);
    }
    return toCancel;
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MapleDoor(server.maps.MapleDoor) MaplePartyCharacter(net.server.world.MaplePartyCharacter) Pair(tools.Pair)

Example 4 with MapleDoor

use of server.maps.MapleDoor in project HeavenMS by ronancpl.

the class MaplePacketCreator method addPartyStatus.

private static void addPartyStatus(int forchannel, MapleParty party, LittleEndianWriter lew, boolean leaving) {
    List<MaplePartyCharacter> partymembers = new ArrayList<>(party.getMembers());
    while (partymembers.size() < 6) {
        partymembers.add(new MaplePartyCharacter());
    }
    for (MaplePartyCharacter partychar : partymembers) {
        lew.writeInt(partychar.getId());
    }
    for (MaplePartyCharacter partychar : partymembers) {
        lew.writeAsciiString(getRightPaddedStr(partychar.getName(), '\0', 13));
    }
    for (MaplePartyCharacter partychar : partymembers) {
        lew.writeInt(partychar.getJobId());
    }
    for (MaplePartyCharacter partychar : partymembers) {
        lew.writeInt(partychar.getLevel());
    }
    for (MaplePartyCharacter partychar : partymembers) {
        if (partychar.isOnline()) {
            lew.writeInt(partychar.getChannel() - 1);
        } else {
            lew.writeInt(-2);
        }
    }
    lew.writeInt(party.getLeader().getId());
    for (MaplePartyCharacter partychar : partymembers) {
        if (partychar.getChannel() == forchannel) {
            lew.writeInt(partychar.getMapId());
        } else {
            lew.writeInt(0);
        }
    }
    for (MaplePartyCharacter partychar : partymembers) {
        if (partychar.getChannel() == forchannel && !leaving) {
            if (partychar.getDoors().size() > 0) {
                boolean deployedPortal = false;
                for (MapleDoor door : partychar.getDoors()) {
                    if (door.getOwnerId() == partychar.getId()) {
                        MapleDoorObject mdo = door.getTownDoor();
                        lew.writeInt(mdo.getTown().getId());
                        lew.writeInt(mdo.getArea().getId());
                        lew.writeInt(mdo.getPosition().x);
                        lew.writeInt(mdo.getPosition().y);
                        deployedPortal = true;
                    }
                }
                if (!deployedPortal) {
                    lew.writeInt(999999999);
                    lew.writeInt(999999999);
                    lew.writeInt(0);
                    lew.writeInt(0);
                }
            } else {
                lew.writeInt(999999999);
                lew.writeInt(999999999);
                lew.writeInt(0);
                lew.writeInt(0);
            }
        } else {
            lew.writeInt(999999999);
            lew.writeInt(999999999);
            lew.writeInt(0);
            lew.writeInt(0);
        }
    }
}
Also used : MapleDoorObject(server.maps.MapleDoorObject) ArrayList(java.util.ArrayList) MaplePartyCharacter(net.server.world.MaplePartyCharacter) MapleDoor(server.maps.MapleDoor)

Aggregations

MapleDoor (server.maps.MapleDoor)4 ArrayList (java.util.ArrayList)3 MaplePartyCharacter (net.server.world.MaplePartyCharacter)3 MapleDoorObject (server.maps.MapleDoorObject)2 Pair (tools.Pair)2 Item (client.inventory.Item)1 MapleInventory (client.inventory.MapleInventory)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 LinkedList (java.util.LinkedList)1 MapleMap (server.maps.MapleMap)1 MapleMist (server.maps.MapleMist)1 MapleSummon (server.maps.MapleSummon)1 SummonMovementType (server.maps.SummonMovementType)1 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)1