Search in sources :

Example 1 with TimerManager

use of server.TimerManager in project HeavenMS by ronancpl.

the class MapleMonster method applyStatus.

public boolean applyStatus(MapleCharacter from, final MonsterStatusEffect status, boolean poison, long duration, boolean venom) {
    switch(getMonsterEffectiveness(status.getSkill().getElement())) {
        case IMMUNE:
        case STRONG:
        case NEUTRAL:
            return false;
        case NORMAL:
        case WEAK:
            break;
        default:
            {
                System.out.println("Unknown elemental effectiveness: " + getMonsterEffectiveness(status.getSkill().getElement()));
                return false;
            }
    }
    if (status.getSkill().getId() == FPMage.ELEMENT_COMPOSITION) {
        // fp compo
        ElementalEffectiveness effectiveness = getMonsterEffectiveness(Element.POISON);
        if (effectiveness == ElementalEffectiveness.IMMUNE || effectiveness == ElementalEffectiveness.STRONG) {
            return false;
        }
    } else if (status.getSkill().getId() == ILMage.ELEMENT_COMPOSITION) {
        // il compo
        ElementalEffectiveness effectiveness = getMonsterEffectiveness(Element.ICE);
        if (effectiveness == ElementalEffectiveness.IMMUNE || effectiveness == ElementalEffectiveness.STRONG) {
            return false;
        }
    } else if (status.getSkill().getId() == NightLord.VENOMOUS_STAR || status.getSkill().getId() == Shadower.VENOMOUS_STAB || status.getSkill().getId() == NightWalker.VENOM) {
        // venom
        if (getMonsterEffectiveness(Element.POISON) == ElementalEffectiveness.WEAK) {
            return false;
        }
    }
    if (poison && hp.get() <= 1) {
        return false;
    }
    final Map<MonsterStatus, Integer> statis = status.getStati();
    if (stats.isBoss()) {
        if (!(statis.containsKey(MonsterStatus.SPEED) && statis.containsKey(MonsterStatus.NINJA_AMBUSH) && statis.containsKey(MonsterStatus.WATK))) {
            return false;
        }
    }
    if (statis.size() > 0) {
        statiLock.lock();
        try {
            for (MonsterStatus stat : statis.keySet()) {
                final MonsterStatusEffect oldEffect = stati.get(stat);
                if (oldEffect != null) {
                    oldEffect.removeActiveStatus(stat);
                    if (oldEffect.getStati().isEmpty()) {
                        oldEffect.cancelTask();
                        oldEffect.cancelDamageSchedule();
                    }
                }
            }
        } finally {
            statiLock.unlock();
        }
    }
    TimerManager timerManager = TimerManager.getInstance();
    final Runnable cancelTask = new Runnable() {

        @Override
        public void run() {
            if (isAlive()) {
                byte[] packet = MaplePacketCreator.cancelMonsterStatus(getObjectId(), status.getStati());
                map.broadcastMessage(packet, getPosition());
                MapleCharacter controller = getController();
                if (controller != null && !controller.isMapObjectVisible(MapleMonster.this)) {
                    controller.getClient().announce(packet);
                }
            }
            statiLock.lock();
            try {
                for (MonsterStatus stat : status.getStati().keySet()) {
                    stati.remove(stat);
                }
            } finally {
                statiLock.unlock();
            }
            setVenomMulti(0);
            status.cancelDamageSchedule();
        }
    };
    int animationTime;
    if (poison) {
        int poisonLevel = from.getSkillLevel(status.getSkill());
        int poisonDamage = Math.min(Short.MAX_VALUE, (int) (getMaxHp() / (70.0 - poisonLevel) + 0.999));
        status.setValue(MonsterStatus.POISON, Integer.valueOf(poisonDamage));
        animationTime = broadcastStatusEffect(status);
        status.setDamageSchedule(timerManager.register(new DamageTask(poisonDamage, from, status, cancelTask, 0), 1000, 1000));
    } else if (venom) {
        if (from.getJob() == MapleJob.NIGHTLORD || from.getJob() == MapleJob.SHADOWER || from.getJob().isA(MapleJob.NIGHTWALKER3)) {
            int poisonLevel, matk, jobid = from.getJob().getId();
            int skillid = (jobid == 412 ? NightLord.VENOMOUS_STAR : (jobid == 422 ? Shadower.VENOMOUS_STAB : NightWalker.VENOM));
            poisonLevel = from.getSkillLevel(SkillFactory.getSkill(skillid));
            if (poisonLevel <= 0) {
                return false;
            }
            matk = SkillFactory.getSkill(skillid).getEffect(poisonLevel).getMatk();
            int luk = from.getLuk();
            int maxDmg = (int) Math.ceil(Math.min(Short.MAX_VALUE, 0.2 * luk * matk));
            int minDmg = (int) Math.ceil(Math.min(Short.MAX_VALUE, 0.1 * luk * matk));
            int gap = maxDmg - minDmg;
            if (gap == 0) {
                gap = 1;
            }
            int poisonDamage = 0;
            for (int i = 0; i < getVenomMulti(); i++) {
                poisonDamage += (Randomizer.nextInt(gap) + minDmg);
            }
            poisonDamage = Math.min(Short.MAX_VALUE, poisonDamage);
            status.setValue(MonsterStatus.VENOMOUS_WEAPON, Integer.valueOf(poisonDamage));
            status.setValue(MonsterStatus.POISON, Integer.valueOf(poisonDamage));
            animationTime = broadcastStatusEffect(status);
            status.setDamageSchedule(timerManager.register(new DamageTask(poisonDamage, from, status, cancelTask, 0), 1000, 1000));
        } else {
            return false;
        }
    /*
        } else if (status.getSkill().getId() == Hermit.SHADOW_WEB || status.getSkill().getId() == NightWalker.SHADOW_WEB) { //Shadow Web
            int webDamage = (int) (getMaxHp() / 50.0 + 0.999);
            status.setValue(MonsterStatus.SHADOW_WEB, Integer.valueOf(webDamage));
            animationTime = broadcastStatusEffect(status);
            status.setDamageSchedule(timerManager.schedule(new DamageTask(webDamage, from, status, cancelTask, 1), 3500));
            */
    } else if (status.getSkill().getId() == 4121004 || status.getSkill().getId() == 4221004) {
        // Ninja Ambush
        final Skill skill = SkillFactory.getSkill(status.getSkill().getId());
        final byte level = from.getSkillLevel(skill);
        final int damage = (int) ((from.getStr() + from.getLuk()) * (1.5 + (level * 0.05)) * skill.getEffect(level).getDamage());
        status.setValue(MonsterStatus.NINJA_AMBUSH, Integer.valueOf(damage));
        animationTime = broadcastStatusEffect(status);
        status.setDamageSchedule(timerManager.register(new DamageTask(damage, from, status, cancelTask, 2), 1000, 1000));
    } else {
        animationTime = broadcastStatusEffect(status);
    }
    statiLock.lock();
    try {
        for (MonsterStatus stat : status.getStati().keySet()) {
            stati.put(stat, status);
            alreadyBuffed.add(stat);
        }
    } finally {
        statiLock.unlock();
    }
    status.setCancelTask(timerManager.schedule(cancelTask, duration + animationTime - 100));
    return true;
}
Also used : MapleCharacter(client.MapleCharacter) MonsterStatusEffect(client.status.MonsterStatusEffect) MonsterStatus(client.status.MonsterStatus) TimerManager(server.TimerManager) Point(java.awt.Point) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Skill(client.Skill)

Example 2 with TimerManager

use of server.TimerManager in project HeavenMS by ronancpl.

the class MapleMonster method applyMonsterBuff.

public void applyMonsterBuff(final Map<MonsterStatus, Integer> stats, final int x, int skillId, long duration, MobSkill skill, final List<Integer> reflection) {
    TimerManager timerManager = TimerManager.getInstance();
    final Runnable cancelTask = new Runnable() {

        @Override
        public void run() {
            if (isAlive()) {
                byte[] packet = MaplePacketCreator.cancelMonsterStatus(getObjectId(), stats);
                map.broadcastMessage(packet, getPosition());
                MapleCharacter controller = getController();
                if (controller != null && !controller.isMapObjectVisible(MapleMonster.this)) {
                    controller.getClient().announce(packet);
                }
                statiLock.lock();
                try {
                    for (final MonsterStatus stat : stats.keySet()) {
                        stati.remove(stat);
                    }
                } finally {
                    statiLock.unlock();
                }
            }
        }
    };
    final MonsterStatusEffect effect = new MonsterStatusEffect(stats, null, skill, true);
    byte[] packet = MaplePacketCreator.applyMonsterStatus(getObjectId(), effect, reflection);
    map.broadcastMessage(packet, getPosition());
    statiLock.lock();
    try {
        for (MonsterStatus stat : stats.keySet()) {
            stati.put(stat, effect);
            alreadyBuffed.add(stat);
        }
    } finally {
        statiLock.unlock();
    }
    MapleCharacter controller = getController();
    if (controller != null && !controller.isMapObjectVisible(this)) {
        controller.getClient().announce(packet);
    }
    effect.setCancelTask(timerManager.schedule(cancelTask, duration));
}
Also used : MapleCharacter(client.MapleCharacter) MonsterStatusEffect(client.status.MonsterStatusEffect) MonsterStatus(client.status.MonsterStatus) TimerManager(server.TimerManager)

Example 3 with TimerManager

use of server.TimerManager in project HeavenMS by ronancpl.

the class Server method run.

@Override
public void run() {
    Properties p = new Properties();
    try {
        p.load(new FileInputStream("world.ini"));
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Please start create_server.bat");
        System.exit(0);
    }
    System.out.println("HeavenMS v" + ServerConstants.VERSION + " starting up.\r\n");
    if (ServerConstants.SHUTDOWNHOOK)
        Runtime.getRuntime().addShutdownHook(new Thread(shutdown(false)));
    Connection c = null;
    try {
        c = DatabaseConnection.getConnection();
        PreparedStatement ps = c.prepareStatement("UPDATE accounts SET loggedin = 0");
        ps.executeUpdate();
        ps.close();
        ps = c.prepareStatement("UPDATE characters SET HasMerchant = 0");
        ps.executeUpdate();
        ps.close();
        loadCouponRates(c);
        updateActiveCoupons();
        c.close();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    }
    IoBuffer.setUseDirectBuffer(false);
    IoBuffer.setAllocator(new SimpleBufferAllocator());
    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
    TimerManager tMan = TimerManager.getInstance();
    tMan.start();
    // Purging ftw...
    tMan.register(tMan.purge(), ServerConstants.PURGING_INTERVAL);
    disconnectIdlesOnLoginTask();
    long timeLeft = getTimeLeftForNextHour();
    tMan.register(new CouponWorker(), ServerConstants.COUPON_INTERVAL, timeLeft);
    tMan.register(new RankingWorker(), ServerConstants.RANKING_INTERVAL, timeLeft);
    long timeToTake = System.currentTimeMillis();
    SkillFactory.loadAllSkills();
    System.out.println("Skills loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds");
    timeToTake = System.currentTimeMillis();
    // MapleItemInformationProvider.getInstance().getAllItems(); //unused, rofl
    CashItemFactory.getSpecialCashItems();
    System.out.println("Items loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds");
    timeToTake = System.currentTimeMillis();
    MapleQuest.loadAllQuest();
    System.out.println("Quest loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds\r\n");
    NewYearCardRecord.startPendingNewYearCardRequests();
    if (ServerConstants.USE_THREAD_TRACKER)
        ThreadTracker.getInstance().registerThreadTrackerTask();
    try {
        Integer worldCount = Math.min(ServerConstants.WORLD_NAMES.length, Integer.parseInt(p.getProperty("worlds")));
        for (int i = 0; i < worldCount; i++) {
            System.out.println("Starting world " + i);
            World world = new World(i, Integer.parseInt(p.getProperty("flag" + i)), p.getProperty("eventmessage" + i), ServerConstants.EXP_RATE, ServerConstants.DROP_RATE, ServerConstants.MESO_RATE, ServerConstants.QUEST_RATE);
            worldRecommendedList.add(new Pair<>(i, p.getProperty("whyamirecommended" + i)));
            worlds.add(world);
            channels.add(new HashMap<Integer, String>());
            for (int j = 0; j < Integer.parseInt(p.getProperty("channels" + i)); j++) {
                int channelid = j + 1;
                Channel channel = new Channel(i, channelid);
                world.addChannel(channel);
                channels.get(i).put(channelid, channel.getIP());
            }
            world.setServerMessage(p.getProperty("servermessage" + i));
            System.out.println("Finished loading world " + i + "\r\n");
        }
    } catch (Exception e) {
        // For those who get errors
        e.printStackTrace();
        System.out.println("Error in moople.ini, start CreateINI.bat to re-make the file.");
        System.exit(0);
    }
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
    acceptor.setHandler(new MapleServerHandler());
    try {
        acceptor.bind(new InetSocketAddress(8484));
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    System.out.println("Listening on port 8484\r\n\r\n");
    System.out.println("HeavenMS is now online.\r\n");
    online = true;
}
Also used : MapleCodecFactory(net.mina.MapleCodecFactory) SQLException(java.sql.SQLException) InetSocketAddress(java.net.InetSocketAddress) SimpleBufferAllocator(org.apache.mina.core.buffer.SimpleBufferAllocator) Properties(java.util.Properties) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) World(net.server.world.World) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) RankingWorker(net.server.worker.RankingWorker) CouponWorker(net.server.worker.CouponWorker) Channel(net.server.channel.Channel) Connection(java.sql.Connection) DatabaseConnection(tools.DatabaseConnection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) TimerManager(server.TimerManager) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException) IOException(java.io.IOException) MapleServerHandler(net.MapleServerHandler)

Example 4 with TimerManager

use of server.TimerManager in project HeavenMS by ronancpl.

the class Commands method executeHeavenMsCommandLv5.

public static boolean executeHeavenMsCommandLv5(Channel cserv, Server srv, MapleClient c, String[] sub) {
    // Developer
    MapleCharacter player = c.getPlayer();
    MapleMonster monster;
    switch(sub[0]) {
        case "debugmonster":
            List<MapleMapObject> monsters = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
            for (MapleMapObject monstermo : monsters) {
                monster = (MapleMonster) monstermo;
                player.message("Monster ID: " + monster.getId() + " Aggro target: " + ((monster.getController() != null) ? monster.getController().getName() : "<none>"));
            }
            break;
        case "debugpacket":
            player.getMap().broadcastMessage(MaplePacketCreator.customPacket(joinStringFrom(sub, 1)));
            break;
        case "debugportal":
            MaplePortal portal = player.getMap().findClosestPortal(player.getPosition());
            if (portal != null)
                player.dropMessage(6, "Closest portal: " + portal.getId() + " '" + portal.getName() + "' Type: " + portal.getType() + " --> toMap: " + portal.getTargetMapId() + " scriptname: '" + portal.getScriptName() + "' state: " + portal.getPortalState() + ".");
            else
                player.dropMessage(6, "There is no portal on this map.");
            break;
        case "debugspawnpoint":
            SpawnPoint sp = player.getMap().findClosestSpawnpoint(player.getPosition());
            if (sp != null)
                player.dropMessage(6, "Closest mob spawn point: " + " Position: x " + sp.getPosition().getX() + " y " + sp.getPosition().getY() + " Spawns mobid: '" + sp.getMonsterId() + "' --> canSpawn: " + !sp.getDenySpawn() + " canSpawnRightNow: " + sp.shouldSpawn() + ".");
            else
                player.dropMessage(6, "There is no mob spawn point on this map.");
            break;
        case "debugpos":
            player.dropMessage(6, "Current map position: (" + player.getPosition().getX() + ", " + player.getPosition().getY() + ").");
            break;
        case "debugmap":
            player.dropMessage(6, "Current map id " + player.getMap().getId() + ", event: '" + ((player.getMap().getEventInstance() != null) ? player.getMap().getEventInstance().getName() : "null") + "'; Players: " + player.getMap().getAllPlayers().size() + ", Mobs: " + player.getMap().countMonsters() + ", Reactors: " + player.getMap().countReactors() + ", Items: " + player.getMap().countItems() + ", Objects: " + player.getMap().getMapObjects().size() + ".");
            break;
        case "debugmobsp":
            player.getMap().reportMonsterSpawnPoints(player);
            break;
        case "debugevent":
            if (player.getEventInstance() == null)
                player.dropMessage(6, "Player currently not in an event.");
            else
                player.dropMessage(6, "Current event name: " + player.getEventInstance().getName() + ".");
            break;
        case "debugareas":
            player.dropMessage(6, "Configured areas on map " + player.getMapId() + ":");
            byte index = 0;
            for (Rectangle rect : player.getMap().getAreas()) {
                player.dropMessage(6, "Id: " + index + " -> posX: " + rect.getX() + " posY: '" + rect.getY() + "' dX: " + rect.getWidth() + " dY: " + rect.getHeight() + ".");
                index++;
            }
            break;
        case "debugreactors":
            player.dropMessage(6, "Current reactor states on map " + player.getMapId() + ":");
            for (MapleMapObject mmo : player.getMap().getReactors()) {
                MapleReactor mr = (MapleReactor) mmo;
                player.dropMessage(6, "Id: " + mr.getId() + " Oid: " + mr.getObjectId() + " name: '" + mr.getName() + "' -> Type: " + mr.getReactorType() + " State: " + mr.getState() + " Event State: " + mr.getEventState() + " Position: x " + mr.getPosition().getX() + " y " + mr.getPosition().getY() + ".");
            }
            break;
        case "debugservercoupons":
        case "debugcoupons":
            String s = "Currently active SERVER coupons: ";
            for (Integer i : Server.getInstance().getActiveCoupons()) {
                s += (i + " ");
            }
            player.dropMessage(6, s);
            break;
        case "debugplayercoupons":
            String st = "Currently active PLAYER coupons: ";
            for (Integer i : player.getActiveCoupons()) {
                st += (i + " ");
            }
            player.dropMessage(6, st);
            break;
        case "debugtimer":
            TimerManager tMan = TimerManager.getInstance();
            player.dropMessage(6, "Total Task: " + tMan.getTaskCount() + " Current Task: " + tMan.getQueuedTasks() + " Active Task: " + tMan.getActiveCount() + " Completed Task: " + tMan.getCompletedTaskCount());
            break;
        default:
            return false;
    }
    return true;
}
Also used : MapleCharacter(client.MapleCharacter) MaplePortal(server.MaplePortal) MapleReactor(server.maps.MapleReactor) Rectangle(java.awt.Rectangle) MapleMapObject(server.maps.MapleMapObject) TimerManager(server.TimerManager) SpawnPoint(server.life.SpawnPoint) MapleMonster(server.life.MapleMonster)

Example 5 with TimerManager

use of server.TimerManager in project HeavenMS by ronancpl.

the class MapleCharacter method handleEnergyChargeGain.

public void handleEnergyChargeGain() {
    // to get here energychargelevel has to be > 0
    Skill energycharge = isCygnus() ? SkillFactory.getSkill(ThunderBreaker.ENERGY_CHARGE) : SkillFactory.getSkill(Marauder.ENERGY_CHARGE);
    MapleStatEffect ceffect;
    ceffect = energycharge.getEffect(getSkillLevel(energycharge));
    TimerManager tMan = TimerManager.getInstance();
    if (energybar < 10000) {
        energybar += 102;
        if (energybar > 10000) {
            energybar = 10000;
        }
        List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.ENERGY_CHARGE, energybar));
        setBuffedValue(MapleBuffStat.ENERGY_CHARGE, energybar);
        client.announce(MaplePacketCreator.giveBuff(energybar, 0, stat));
        client.announce(MaplePacketCreator.showOwnBuffEffect(energycharge.getId(), 2));
        getMap().broadcastMessage(this, MaplePacketCreator.showBuffeffect(id, energycharge.getId(), 2));
        getMap().broadcastMessage(this, MaplePacketCreator.giveForeignBuff(energybar, stat));
    }
    if (energybar >= 10000 && energybar < 11000) {
        energybar = 15000;
        final MapleCharacter chr = this;
        tMan.schedule(new Runnable() {

            @Override
            public void run() {
                energybar = 0;
                List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.ENERGY_CHARGE, energybar));
                setBuffedValue(MapleBuffStat.ENERGY_CHARGE, energybar);
                client.announce(MaplePacketCreator.giveBuff(energybar, 0, stat));
                getMap().broadcastMessage(chr, MaplePacketCreator.giveForeignBuff(energybar, stat));
            }
        }, ceffect.getDuration());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MobSkill(server.life.MobSkill) MapleStatEffect(server.MapleStatEffect) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) TimerManager(server.TimerManager) Pair(tools.Pair)

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