Search in sources :

Example 6 with TimerManager

use of server.TimerManager in project HeavenMS by ronancpl.

the class MapleMap method spawnMist.

public void spawnMist(final MapleMist mist, final int duration, boolean poison, boolean fake, boolean recovery) {
    addMapObject(mist);
    broadcastMessage(fake ? mist.makeFakeSpawnData(30) : mist.makeSpawnData());
    TimerManager tMan = TimerManager.getInstance();
    final ScheduledFuture<?> poisonSchedule;
    if (poison) {
        Runnable poisonTask = new Runnable() {

            @Override
            public void run() {
                List<MapleMapObject> affectedMonsters = getMapObjectsInBox(mist.getBox(), Collections.singletonList(MapleMapObjectType.MONSTER));
                for (MapleMapObject mo : affectedMonsters) {
                    if (mist.makeChanceResult()) {
                        MonsterStatusEffect poisonEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.POISON, 1), mist.getSourceSkill(), null, false);
                        ((MapleMonster) mo).applyStatus(mist.getOwner(), poisonEffect, true, duration);
                    }
                }
            }
        };
        poisonSchedule = tMan.register(poisonTask, 2000, 2500);
    } else if (recovery) {
        Runnable poisonTask = new Runnable() {

            @Override
            public void run() {
                List<MapleMapObject> players = getMapObjectsInBox(mist.getBox(), Collections.singletonList(MapleMapObjectType.PLAYER));
                for (MapleMapObject mo : players) {
                    if (mist.makeChanceResult()) {
                        MapleCharacter chr = (MapleCharacter) mo;
                        if (mist.getOwner().getId() == chr.getId() || mist.getOwner().getParty() != null && mist.getOwner().getParty().containsMembers(chr.getMPC())) {
                            chr.addMP((int) mist.getSourceSkill().getEffect(chr.getSkillLevel(mist.getSourceSkill().getId())).getX() * chr.getMp() / 100);
                        }
                    }
                }
            }
        };
        poisonSchedule = tMan.register(poisonTask, 2000, 2500);
    } else {
        poisonSchedule = null;
    }
    tMan.schedule(new Runnable() {

        @Override
        public void run() {
            removeMapObject(mist);
            if (poisonSchedule != null) {
                poisonSchedule.cancel(false);
            }
            broadcastMessage(mist.makeDestroyData());
        }
    }, duration);
}
Also used : MapleCharacter(client.MapleCharacter) MonsterStatusEffect(client.status.MonsterStatusEffect) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TimerManager(server.TimerManager) MapleMonster(server.life.MapleMonster)

Aggregations

TimerManager (server.TimerManager)6 MapleCharacter (client.MapleCharacter)4 MonsterStatusEffect (client.status.MonsterStatusEffect)3 MonsterStatus (client.status.MonsterStatus)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MapleMonster (server.life.MapleMonster)2 Skill (client.Skill)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 MapleServerHandler (net.MapleServerHandler)1