Search in sources :

Example 1 with EventInstanceManager

use of scripting.event.EventInstanceManager in project HeavenMS by ronancpl.

the class MapleCharacter method playerDead.

private void playerDead() {
    cancelAllBuffs(false);
    dispelDebuffs();
    EventInstanceManager eim = getEventInstance();
    if (eim != null) {
        eim.playerKilled(this);
    }
    int[] charmID = { 5130000, 4031283, 4140903 };
    int possesed = 0;
    int i;
    for (i = 0; i < charmID.length; i++) {
        int quantity = getItemQuantity(charmID[i], false);
        if (possesed == 0 && quantity > 0) {
            possesed = quantity;
            break;
        }
    }
    if (possesed > 0) {
        message("You have used a safety charm, so your EXP points have not been decreased.");
        MapleInventoryManipulator.removeById(client, ItemConstants.getInventoryType(charmID[i]), charmID[i], 1, true, false);
    } else if (mapid > 925020000 && mapid < 925030000) {
        this.dojoStage = 0;
    } else if (mapid > 980000100 && mapid < 980000700) {
        getMap().broadcastMessage(this, MaplePacketCreator.CPQDied(this));
    } else if (getJob() != MapleJob.BEGINNER) {
        // Hmm...
        int XPdummy = ExpTable.getExpNeededForLevel(getLevel());
        if (getMap().isTown()) {
            XPdummy /= 100;
        }
        if (XPdummy == ExpTable.getExpNeededForLevel(getLevel())) {
            if (getLuk() <= 100 && getLuk() > 8) {
                XPdummy *= (200 - getLuk()) / 2000;
            } else if (getLuk() < 8) {
                XPdummy /= 10;
            } else {
                XPdummy /= 20;
            }
        }
        if (getExp() > XPdummy) {
            loseExp(XPdummy, false, false);
        } else {
            loseExp(getExp(), false, false);
        }
    }
    if (getBuffedValue(MapleBuffStat.MORPH) != null) {
        cancelEffectFromBuffStat(MapleBuffStat.MORPH);
    }
    if (getBuffedValue(MapleBuffStat.MONSTER_RIDING) != null) {
        cancelEffectFromBuffStat(MapleBuffStat.MONSTER_RIDING);
    }
    if (getChair() != 0) {
        setChair(0);
        client.announce(MaplePacketCreator.cancelChair(-1));
        getMap().broadcastMessage(this, MaplePacketCreator.showChair(getId(), 0), false);
    }
    client.announce(MaplePacketCreator.enableActions());
}
Also used : EventInstanceManager(scripting.event.EventInstanceManager) Point(java.awt.Point)

Example 2 with EventInstanceManager

use of scripting.event.EventInstanceManager in project HeavenMS by ronancpl.

the class MapleCharacter method getWarpMap.

public MapleMap getWarpMap(int map) {
    MapleMap target;
    EventInstanceManager eim = getEventInstance();
    if (eim == null) {
        target = client.getChannelServer().getMapFactory().getMap(map);
    } else {
        target = eim.getMapInstance(map);
    }
    return target;
}
Also used : MapleMap(server.maps.MapleMap) EventInstanceManager(scripting.event.EventInstanceManager)

Example 3 with EventInstanceManager

use of scripting.event.EventInstanceManager in project HeavenMS by ronancpl.

the class PartyOperationHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    int operation = slea.readByte();
    MapleCharacter player = c.getPlayer();
    World world = c.getWorldServer();
    MapleParty party = player.getParty();
    MaplePartyCharacter partyplayer = player.getMPC();
    switch(operation) {
        case 1:
            {
                // create
                if (player.getLevel() < 10 && !ServerConstants.USE_PARTY_FOR_STARTERS) {
                    c.announce(MaplePacketCreator.partyStatusMessage(10));
                    return;
                }
                if (player.getParty() == null) {
                    partyplayer = new MaplePartyCharacter(player);
                    party = world.createParty(partyplayer);
                    player.setParty(party);
                    player.setMPC(partyplayer);
                    player.getMap().addPartyMember(player);
                    player.silentPartyUpdate();
                    c.announce(MaplePacketCreator.partyCreated(partyplayer));
                } else {
                    c.announce(MaplePacketCreator.serverNotice(5, "You can't create a party as you are already in one."));
                }
                break;
            }
        case 2:
            {
                // leave/disband
                leaveParty(party, partyplayer, c);
                break;
            }
        case 3:
            {
                // join
                int partyid = slea.readInt();
                if (c.getPlayer().getParty() == null) {
                    party = world.getParty(partyid);
                    if (party != null) {
                        if (party.getMembers().size() < 6) {
                            partyplayer = new MaplePartyCharacter(player);
                            player.getMap().addPartyMember(player);
                            world.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
                            player.receivePartyMemberHP();
                            player.updatePartyMemberHP();
                        } else {
                            c.announce(MaplePacketCreator.partyStatusMessage(17));
                        }
                    } else {
                        c.announce(MaplePacketCreator.serverNotice(5, "The person you have invited to the party is already in one."));
                    }
                } else {
                    c.announce(MaplePacketCreator.serverNotice(5, "You can't join the party as you are already in one."));
                }
                break;
            }
        case 4:
            {
                // invite
                String name = slea.readMapleAsciiString();
                MapleCharacter invited = world.getPlayerStorage().getCharacterByName(name);
                if (invited != null) {
                    if (invited.getLevel() < 10 && (!ServerConstants.USE_PARTY_FOR_STARTERS || player.getLevel() >= 10)) {
                        // min requirement is level 10
                        c.announce(MaplePacketCreator.serverNotice(5, "The player you have invited does not meet the requirements."));
                        return;
                    }
                    if (ServerConstants.USE_PARTY_FOR_STARTERS && invited.getLevel() >= 10 && player.getLevel() < 10) {
                        // trying to invite high level
                        c.announce(MaplePacketCreator.serverNotice(5, "The player you have invited does not meet the requirements."));
                        return;
                    }
                    if (invited.getParty() == null) {
                        if (player.getParty() == null) {
                            if (player.getLevel() < 10 && !ServerConstants.USE_PARTY_FOR_STARTERS) {
                                c.announce(MaplePacketCreator.partyStatusMessage(10));
                                return;
                            }
                            partyplayer = new MaplePartyCharacter(player);
                            party = world.createParty(partyplayer);
                            player.setParty(party);
                            player.setMPC(partyplayer);
                            player.getMap().addPartyMember(player);
                            c.announce(MaplePacketCreator.partyCreated(partyplayer));
                        }
                        if (party.getMembers().size() < 6) {
                            invited.getClient().announce(MaplePacketCreator.partyInvite(player));
                        } else {
                            c.announce(MaplePacketCreator.partyStatusMessage(17));
                        }
                    } else {
                        c.announce(MaplePacketCreator.partyStatusMessage(16));
                    }
                } else {
                    c.announce(MaplePacketCreator.partyStatusMessage(19));
                }
                break;
            }
        case 5:
            {
                // expel
                int cid = slea.readInt();
                if (partyplayer.equals(party.getLeader())) {
                    MaplePartyCharacter expelled = party.getMemberById(cid);
                    if (expelled != null) {
                        MapleCharacter emc = expelled.getPlayer();
                        if (emc != null) {
                            MapleMap map = emc.getMap();
                            if (map != null)
                                map.removePartyMember(emc);
                            EventInstanceManager eim = emc.getEventInstance();
                            if (eim != null) {
                                eim.leftParty(emc);
                            }
                            emc.setParty(null);
                        }
                        world.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
                    }
                }
                break;
            }
        case 6:
            {
                // change leader
                int newLeader = slea.readInt();
                MaplePartyCharacter newLeadr = party.getMemberById(newLeader);
                world.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, newLeadr);
                break;
            }
    }
}
Also used : MapleMap(server.maps.MapleMap) MapleCharacter(client.MapleCharacter) EventInstanceManager(scripting.event.EventInstanceManager) MapleParty(net.server.world.MapleParty) World(net.server.world.World) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Example 4 with EventInstanceManager

use of scripting.event.EventInstanceManager in project HeavenMS by ronancpl.

the class MapleCharacter method changeMapInternal.

private void changeMapInternal(final MapleMap to, final Point pos, final byte[] warpPacket) {
    if (!canWarpMap)
        return;
    this.mapTransitioning.set(true);
    this.unregisterChairBuff();
    this.clearBanishPlayerData();
    this.closePlayerInteractions();
    this.resetPlayerAggro();
    client.announce(warpPacket);
    map.removePlayer(this);
    if (client.getChannelServer().getPlayerStorage().getCharacterById(getId()) != null) {
        map = to;
        setPosition(pos);
        map.addPlayer(this);
        prtLock.lock();
        try {
            if (party != null) {
                mpc.setMapId(to.getId());
                silentPartyUpdateInternal();
                client.announce(MaplePacketCreator.updateParty(client.getChannel(), party, PartyOperation.SILENT_UPDATE, null));
                updatePartyMemberHPInternal();
            }
        } finally {
            prtLock.unlock();
        }
        if (getMap().getHPDec() > 0)
            resetHpDecreaseTask();
    } else {
        FilePrinter.printError(FilePrinter.MAPLE_MAP, "Character " + this.getName() + " got stuck when moving to map " + map.getId() + ".");
    }
    // alas, new map has been specified when a warping was being processed...
    if (newWarpMap != -1) {
        canWarpMap = true;
        int temp = newWarpMap;
        newWarpMap = -1;
        changeMap(temp);
    } else {
        // if this event map has a gate already opened, render it
        EventInstanceManager eim = getEventInstance();
        if (eim != null) {
            eim.recoverOpenedGate(this, map.getId());
        }
        // if this map has obstacle components moving, make it do so for this client
        for (Entry<String, Integer> e : map.getEnvironment().entrySet()) {
            announce(MaplePacketCreator.environmentMove(e.getKey(), e.getValue()));
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventInstanceManager(scripting.event.EventInstanceManager) Point(java.awt.Point)

Example 5 with EventInstanceManager

use of scripting.event.EventInstanceManager in project HeavenMS by ronancpl.

the class MapleCharacter method changeMap.

public void changeMap(int map, int portal) {
    MapleMap warpMap;
    EventInstanceManager eim = getEventInstance();
    if (eim != null) {
        warpMap = eim.getMapInstance(map);
    } else {
        warpMap = client.getChannelServer().getMapFactory().getMap(map);
    }
    changeMap(warpMap, warpMap.getPortal(portal));
}
Also used : MapleMap(server.maps.MapleMap) EventInstanceManager(scripting.event.EventInstanceManager)

Aggregations

EventInstanceManager (scripting.event.EventInstanceManager)8 MapleMap (server.maps.MapleMap)5 MapleCharacter (client.MapleCharacter)2 Point (java.awt.Point)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MapleParty (net.server.world.MapleParty)1 MaplePartyCharacter (net.server.world.MaplePartyCharacter)1 World (net.server.world.World)1