EXP system & Mob buffs/diseases optimization
Solved a problem within EXP distribution system that would hand out less overall EXP than the expected when the amount to be earned is low. Optimized mob buffs and diseases, now using a dedicated thread to process all status expirations on a batch. Refactored MonitoredLockTypes names to something more easily identificable. Added a delay on mob effect applications, to be registered in after the cast animation time. Fixed Flame Thrower acting passively when a attacking skill is used by the player.
This commit is contained in:
@@ -96,8 +96,8 @@ public class Server {
|
||||
private final Map<Integer, MapleGuild> guilds = new HashMap<>(100);
|
||||
private final Map<MapleClient, Long> inLoginState = new HashMap<>(100);
|
||||
private final Lock srvLock = new MonitoredReentrantLock(MonitoredLockType.SERVER);
|
||||
private final Lock lgnLock = new MonitoredReentrantLock(MonitoredLockType.SERVER);
|
||||
private final Lock disLock = new MonitoredReentrantLock(MonitoredLockType.SERVER);
|
||||
private final Lock lgnLock = new MonitoredReentrantLock(MonitoredLockType.SERVER_LOGIN);
|
||||
private final Lock disLock = new MonitoredReentrantLock(MonitoredLockType.SERVER_DISEASES);
|
||||
private final PlayerBuffStorage buffStorage = new PlayerBuffStorage();
|
||||
private final Map<Integer, MapleAlliance> alliances = new HashMap<>(100);
|
||||
private final Map<Integer, NewYearCardRecord> newyears = new HashMap<>();
|
||||
|
||||
@@ -233,7 +233,7 @@ public class ThreadTracker {
|
||||
|
||||
List<MonitoredLockType> list = threadTracker.get(tid);
|
||||
for(int i = list.size() - 1; i >= 0; i--) {
|
||||
if(lockId.getValue() == list.get(i).getValue()) {
|
||||
if(lockId.equals(list.get(i))) {
|
||||
list.remove(i);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.channel;
|
||||
|
||||
import net.server.channel.worker.MobStatusScheduler;
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
@@ -70,6 +71,7 @@ import server.maps.MapleMiniDungeon;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.Pair;
|
||||
import client.MapleCharacter;
|
||||
import client.status.MonsterStatusEffect;
|
||||
import constants.ServerConstants;
|
||||
import server.maps.MapleMiniDungeonInfo;
|
||||
import tools.locks.MonitoredLockType;
|
||||
@@ -83,6 +85,7 @@ public final class Channel {
|
||||
private String ip, serverMessage;
|
||||
private MapleMapFactory mapFactory;
|
||||
private EventScriptManager eventSM;
|
||||
private MobStatusScheduler mobStatusSchedulers[] = new MobStatusScheduler[4];
|
||||
private Map<Integer, MapleHiredMerchant> hiredMerchants = new HashMap<>();
|
||||
private final Map<Integer, Integer> storedVars = new HashMap<>();
|
||||
private List<MapleExpedition> expeditions = new ArrayList<>();
|
||||
@@ -149,6 +152,10 @@ public final class Channel {
|
||||
dojoTask[i] = null;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
mobStatusSchedulers[i] = new MobStatusScheduler();
|
||||
}
|
||||
|
||||
System.out.println(" Channel " + getId() + ": Listening on port " + port);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -817,6 +824,34 @@ public final class Channel {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getMobStatusSchedulerIndex(int mapid) {
|
||||
if(mapid >= 250000000) {
|
||||
if(mapid >= 900000000) {
|
||||
return 3;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
if(mapid >= 200000000) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerMobStatus(int mapid, MonsterStatusEffect mse, Runnable cancelAction, long duration) {
|
||||
registerMobStatus(mapid, mse, cancelAction, duration, null, -1);
|
||||
}
|
||||
|
||||
public void registerMobStatus(int mapid, MonsterStatusEffect mse, Runnable cancelAction, long duration, Runnable overtimeAction, int overtimeDelay) {
|
||||
mobStatusSchedulers[getMobStatusSchedulerIndex(mapid)].registerMobStatus(mse, cancelAction, duration, overtimeAction, overtimeDelay);
|
||||
}
|
||||
|
||||
public void interruptMobStatus(int mapid, MonsterStatusEffect mse) {
|
||||
mobStatusSchedulers[getMobStatusSchedulerIndex(mapid)].interruptMobStatus(mse);
|
||||
}
|
||||
|
||||
public void debugMarriageStatus() {
|
||||
System.out.println(" ----- WORLD DATA -----");
|
||||
Server.getInstance().getWorld(world).debugMarriageStatus();
|
||||
|
||||
@@ -326,6 +326,15 @@ public abstract class AbstractDealDamageHandler extends AbstractMaplePacketHandl
|
||||
} else if (attack.skill == Outlaw.HOMING_BEACON || attack.skill == Corsair.BULLSEYE) {
|
||||
player.setMarkedMonster(monster.getObjectId());
|
||||
player.announce(MaplePacketCreator.giveBuff(1, attack.skill, Collections.singletonList(new Pair<>(MapleBuffStat.HOMING_BEACON, monster.getObjectId()))));
|
||||
} else if (attack.skill == Outlaw.FLAME_THROWER) {
|
||||
if (!monster.isBoss()) {
|
||||
Skill type = SkillFactory.getSkill(Outlaw.FLAME_THROWER);
|
||||
if (player.getSkillLevel(type) > 0) {
|
||||
MapleStatEffect DoT = type.getEffect(player.getSkillLevel(type));
|
||||
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.POISON, 1), type, null, false);
|
||||
monster.applyStatus(player, monsterStatusEffect, true, DoT.getDuration(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (job == 2111 || job == 2112) {
|
||||
@@ -406,15 +415,6 @@ public abstract class AbstractDealDamageHandler extends AbstractMaplePacketHandl
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (job == 521 || job == 522) { // from what I can gather this is how it should work
|
||||
if (!monster.isBoss()) {
|
||||
Skill type = SkillFactory.getSkill(Outlaw.FLAME_THROWER);
|
||||
if (player.getSkillLevel(type) > 0) {
|
||||
MapleStatEffect DoT = type.getEffect(player.getSkillLevel(type));
|
||||
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.POISON, 1), type, null, false);
|
||||
monster.applyStatus(player, monsterStatusEffect, true, DoT.getDuration(), false);
|
||||
}
|
||||
}
|
||||
} else if (job >= 311 && job <= 322) {
|
||||
if (!monster.isBoss()) {
|
||||
Skill mortalBlow;
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import server.life.MapleMonster;
|
||||
import server.life.MapleMonsterInformationProvider;
|
||||
//import server.life.MobAttackInfo;
|
||||
//import server.life.MobAttackInfoFactory;
|
||||
import server.life.MobSkill;
|
||||
@@ -94,20 +95,27 @@ public final class MoveLifeHandler extends AbstractMovementPacketHandler {
|
||||
} else if (toUse.getHP() < percHpLeft) {
|
||||
toUse = null;
|
||||
} else if (monster.canUseSkill(toUse)) {
|
||||
toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
|
||||
int animationTime = MapleMonsterInformationProvider.getInstance().getMobSkillAnimationTime(monster.getId(), Random);
|
||||
if(animationTime > 0) {
|
||||
toUse.applyDelayedEffect(c.getPlayer(), monster, true, banishPlayers, animationTime);
|
||||
} else {
|
||||
toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
|
||||
}
|
||||
} else {
|
||||
toUse = null;
|
||||
}
|
||||
} else {
|
||||
toUse = null; // paliative measure for suspicious mob movement
|
||||
|
||||
/*
|
||||
long curtime = System.currentTimeMillis();
|
||||
if(curtime >= monster.getNextBasicSkillTime()) { // dont use the special attack too often, chase the player f3
|
||||
//MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
|
||||
//monster.setNextBasicSkillTime(curtime);
|
||||
|
||||
toUse = null; // paliative measure for suspicious mob movement
|
||||
MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
|
||||
monster.setNextBasicSkillTime(curtime);
|
||||
} else {
|
||||
toUse = null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
148
src/net/server/channel/worker/MobStatusScheduler.java
Normal file
148
src/net/server/channel/worker/MobStatusScheduler.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft 2016 - 2018 RonanLana
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.channel.worker;
|
||||
|
||||
import client.status.MonsterStatusEffect;
|
||||
import constants.ServerConstants;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import server.TimerManager;
|
||||
import tools.Pair;
|
||||
import tools.locks.MonitoredLockType;
|
||||
import tools.locks.MonitoredReentrantLock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MobStatusScheduler {
|
||||
private int idleProcs = 0;
|
||||
private Map<MonsterStatusEffect, Pair<Runnable, Long>> registeredMobStatus = new HashMap<>();
|
||||
private Map<MonsterStatusEffect, MobStatusOvertimeEntry> registeredMobStatusOvertime = new HashMap<>();
|
||||
|
||||
private class MobStatusOvertimeEntry {
|
||||
private int procCount;
|
||||
private int procLimit;
|
||||
private Runnable r;
|
||||
|
||||
protected MobStatusOvertimeEntry(int delay, Runnable run) {
|
||||
procCount = 0;
|
||||
procLimit = (int)Math.ceil((float) delay / ServerConstants.MOB_STATUS_MONITOR_PROC);
|
||||
r = run;
|
||||
}
|
||||
|
||||
protected void update() {
|
||||
procCount++;
|
||||
if(procCount >= procLimit) {
|
||||
procCount = 0;
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ScheduledFuture<?> mobStatusSchedule = null;
|
||||
private Lock mobStatusLock = new MonitoredReentrantLock(MonitoredLockType.CHANNEL_MOBSTATUS, true);
|
||||
private Runnable monitorTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runMobStatusSchedule();
|
||||
}
|
||||
};
|
||||
|
||||
private void runMobStatusSchedule() {
|
||||
mobStatusLock.lock();
|
||||
try {
|
||||
if(registeredMobStatus.isEmpty()) {
|
||||
idleProcs++;
|
||||
|
||||
if(idleProcs >= ServerConstants.MOB_STATUS_MONITOR_LIFE) {
|
||||
if(mobStatusSchedule != null) {
|
||||
mobStatusSchedule.cancel(false);
|
||||
mobStatusSchedule = null;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
idleProcs = 0;
|
||||
|
||||
long timeNow = System.currentTimeMillis();
|
||||
List<MonsterStatusEffect> toRemove = new LinkedList<>();
|
||||
for(Entry<MonsterStatusEffect, Pair<Runnable, Long>> rmd : registeredMobStatus.entrySet()) {
|
||||
Pair<Runnable, Long> r = rmd.getValue();
|
||||
|
||||
if(r.getRight() < timeNow) {
|
||||
r.getLeft().run(); // runs the cancel action
|
||||
toRemove.add(rmd.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for(MonsterStatusEffect mse : toRemove) {
|
||||
registeredMobStatus.remove(mse);
|
||||
registeredMobStatusOvertime.remove(mse);
|
||||
}
|
||||
|
||||
// it's probably ok to use one thread for both management & overtime actions
|
||||
List<MobStatusOvertimeEntry> mdoeList = new ArrayList<>(registeredMobStatusOvertime.values());
|
||||
for(MobStatusOvertimeEntry mdoe : mdoeList) {
|
||||
mdoe.update();
|
||||
}
|
||||
} finally {
|
||||
mobStatusLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerMobStatus(MonsterStatusEffect mse, Runnable cancelStatus, long duration, Runnable overtimeStatus, int overtimeDelay) {
|
||||
mobStatusLock.lock();
|
||||
try {
|
||||
idleProcs = 0;
|
||||
if(mobStatusSchedule == null) {
|
||||
mobStatusSchedule = TimerManager.getInstance().register(monitorTask, ServerConstants.MOB_STATUS_MONITOR_PROC, ServerConstants.MOB_STATUS_MONITOR_PROC);
|
||||
}
|
||||
|
||||
registeredMobStatus.put(mse, new Pair<>(cancelStatus, System.currentTimeMillis() + duration));
|
||||
|
||||
if(overtimeStatus != null) {
|
||||
MobStatusOvertimeEntry mdoe = new MobStatusOvertimeEntry(overtimeDelay, overtimeStatus);
|
||||
registeredMobStatusOvertime.put(mse, mdoe);
|
||||
}
|
||||
} finally {
|
||||
mobStatusLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void interruptMobStatus(MonsterStatusEffect mse) {
|
||||
mobStatusLock.lock();
|
||||
try {
|
||||
Pair<Runnable, Long> rmd = registeredMobStatus.remove(mse);
|
||||
if(rmd != null) rmd.getLeft().run();
|
||||
|
||||
registeredMobStatusOvertime.remove(mse);
|
||||
} finally {
|
||||
mobStatusLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import net.server.world.World;
|
||||
/**
|
||||
* @author Ronan
|
||||
*/
|
||||
public class BaseWorker implements Runnable {
|
||||
public abstract class BaseWorker implements Runnable {
|
||||
protected World wserv;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -124,7 +124,7 @@ public class World {
|
||||
|
||||
private Map<Runnable, Long> registeredTimedMapObjects = new LinkedHashMap<>();
|
||||
private ScheduledFuture<?> timedMapObjectsSchedule;
|
||||
private Lock timedMapObjectLock = new MonitoredReentrantLock(MonitoredLockType.MAP_OBJS, true);
|
||||
private Lock timedMapObjectLock = new MonitoredReentrantLock(MonitoredLockType.WORLD_MAPOBJS, true);
|
||||
|
||||
private ScheduledFuture<?> charactersSchedule;
|
||||
private ScheduledFuture<?> marriagesSchedule;
|
||||
|
||||
Reference in New Issue
Block a user