Revamped buff system + skill cd/buff schedule rework

Completely rearranged buff system (system can smartly check for the best
statup to take effect for it's duration, or the server can be flagged to
act as usual). Refactored scheduling system for buffs expiration and
cooldowns to use one single thread per player rather than one per
instance.
This commit is contained in:
ronancpl
2017-09-22 19:09:56 -03:00
parent 1ffcf47f79
commit 9c72ce1e3a
104 changed files with 1321 additions and 583 deletions

View File

@@ -523,7 +523,7 @@ public class MapleInventoryManipulator {
return;
}
int itemId = source.getItemId();
if (itemId >= 5000000 && itemId <= 5000102) {
if (ItemConstants.isPet(itemId)) {
return;
}
if (type == MapleInventoryType.EQUIPPED && itemId == 1122017) {

View File

@@ -110,6 +110,7 @@ public class MapleItemInformationProvider {
protected Map<Integer, Boolean> consumeOnPickupCache = new HashMap<>();
protected Map<Integer, Boolean> isQuestItemCache = new HashMap<>();
protected Map<Integer, String> equipmentSlotCache = new HashMap<>();
protected Map<Integer, Boolean> noCancelMouseCache = new HashMap<>();
private MapleItemInformationProvider() {
loadCardIdData();
@@ -246,7 +247,7 @@ public class MapleItemInformationProvider {
} else if (itemId >= 1080000 && itemId < 1090000) {
theData = eqpStringData;
cat = "Eqp/Glove";
} else if (itemId >= 30000 && itemId < 32000) {
} else if (itemId >= 30000 && itemId < 35000) {
theData = eqpStringData;
cat = "Eqp/Hair";
} else if (itemId >= 1050000 && itemId < 1060000) {
@@ -278,7 +279,7 @@ public class MapleItemInformationProvider {
cat = "Etc";
} else if (itemId >= 3000000 && itemId < 4000000) {
theData = insStringData;
} else if (itemId >= 5000000 && itemId < 5010000) {
} else if (ItemConstants.isPet(itemId)) {
theData = petStringData;
} else {
return null;
@@ -291,11 +292,19 @@ public class MapleItemInformationProvider {
}
public boolean noCancelMouse(int itemId) {
if (noCancelMouseCache.containsKey(itemId)) {
return noCancelMouseCache.get(itemId);
}
MapleData item = getItemData(itemId);
if (item == null) {
noCancelMouseCache.put(itemId, false);
return false;
}
return MapleDataTool.getIntConvert("info/noCancelMouse", item, 0) == 1;
boolean blockMouse = MapleDataTool.getIntConvert("info/noCancelMouse", item, 0) == 1;
noCancelMouseCache.put(itemId, blockMouse);
return blockMouse;
}
private MapleData getItemData(int itemId) {

View File

@@ -132,7 +132,7 @@ public class MapleShop {
int cardreduce = value - cost;
int diff = cardreduce + c.getPlayer().getMeso();
if (MapleInventoryManipulator.checkSpace(c, itemId, quantity, "")) {
if (itemId >= 5000000 && itemId <= 5000100) {
if (ItemConstants.isPet(itemId)) {
int petid = MaplePet.createPet(itemId);
MapleInventoryManipulator.addById(c, itemId, quantity, null, petid, -1);
} else {

View File

@@ -565,8 +565,8 @@ public class MapleStatEffect {
case Crusader.ARMOR_CRASH:
case DragonKnight.POWER_CRASH:
case WhiteKnight.MAGIC_CRASH:
monsterStatus.put(MonsterStatus.SEAL_SKILL, Integer.valueOf(1));
break;
monsterStatus.put(MonsterStatus.SEAL_SKILL, Integer.valueOf(1));
break;
case Rogue.DISORDER:
monsterStatus.put(MonsterStatus.WATK, Integer.valueOf(ret.x));
monsterStatus.put(MonsterStatus.WDEF, Integer.valueOf(ret.y));
@@ -842,7 +842,6 @@ public class MapleStatEffect {
} else {
MapleInventoryManipulator.removeById(applyto.getClient(), MapleInventoryType.USE, projectile, 200, false, true);
}
}
SummonMovementType summonMovementType = getSummonMovementType();
if (overTime || isCygnusFA() || summonMovementType != null) {
@@ -983,9 +982,12 @@ public class MapleStatEffect {
public void silentApplyBuff(MapleCharacter chr, long starttime) {
int localDuration = duration;
localDuration = alchemistModifyVal(chr, localDuration, false);
CancelEffectAction cancelAction = new CancelEffectAction(chr, this, starttime);
ScheduledFuture<?> schedule = TimerManager.getInstance().schedule(cancelAction, ((starttime + localDuration) - System.currentTimeMillis()));
chr.registerEffect(this, starttime, schedule);
//CancelEffectAction cancelAction = new CancelEffectAction(chr, this, starttime);
//ScheduledFuture<?> schedule = TimerManager.getInstance().schedule(cancelAction, ((starttime + localDuration) - System.currentTimeMillis()));
if(starttime + localDuration <= System.currentTimeMillis()) return;
chr.registerEffect(this, starttime, (starttime + localDuration), true);
SummonMovementType summonMovementType = getSummonMovementType();
if (summonMovementType != null) {
final MapleSummon tosummon = new MapleSummon(chr, sourceid, chr.getPosition(), summonMovementType);
@@ -1006,7 +1008,18 @@ public class MapleStatEffect {
final long starttime = System.currentTimeMillis();
// final CancelEffectAction cancelAction = new CancelEffectAction(applyto, this, starttime);
// final ScheduledFuture<?> schedule = TimerManager.getInstance().schedule(cancelAction, ((starttime + 99999) - System.currentTimeMillis()));
applyto.registerEffect(this, starttime, null);
applyto.registerEffect(this, starttime, Long.MAX_VALUE, false);
}
public void updateBuffEffect(MapleCharacter target, List<Pair<MapleBuffStat, Integer>> activeStats, long starttime) {
int localDuration = duration;
localDuration = alchemistModifyVal(target, localDuration, false);
long leftDuration = (starttime + localDuration) - System.currentTimeMillis();
if(leftDuration > 0) {
byte[] buff = MaplePacketCreator.giveBuff((skill ? sourceid : -sourceid), (int)leftDuration, activeStats);
target.getClient().announce(buff);
}
}
private void applyBuffEffect(MapleCharacter applyfrom, MapleCharacter applyto, boolean primary) {
@@ -1107,11 +1120,7 @@ public class MapleStatEffect {
List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.MORPH, Integer.valueOf(getMorph(applyto))));
mbuff = MaplePacketCreator.giveForeignBuff(applyto.getId(), stat);
}
long starttime = System.currentTimeMillis();
CancelEffectAction cancelAction = new CancelEffectAction(applyto, this, starttime);
ScheduledFuture<?> schedule = TimerManager.getInstance().schedule(cancelAction, localDuration);
applyto.registerEffect(this, starttime, schedule);
if (buff != null) {
if (!hasNoIcon()) { //Thanks flav for such a simple release! :)
applyto.getClient().announce(buff);
@@ -1120,6 +1129,12 @@ public class MapleStatEffect {
System.out.println("<Error> NO buff icon for id " + sourceid);
}
}
long starttime = System.currentTimeMillis();
//CancelEffectAction cancelAction = new CancelEffectAction(applyto, this, starttime);
//ScheduledFuture<?> schedule = TimerManager.getInstance().schedule(cancelAction, localDuration);
applyto.registerEffect(this, starttime, starttime + localDuration, false);
if (mbuff != null) {
applyto.getMap().broadcastMessage(applyto, mbuff, false);
}
@@ -1511,11 +1526,16 @@ public class MapleStatEffect {
public int getSourceId() {
return sourceid;
}
public int getBuffSourceId() {
return skill ? sourceid : -sourceid;
}
public boolean makeChanceResult() {
return prop == 1.0 || Math.random() < prop;
}
/*
private static class CancelEffectAction implements Runnable {
private MapleStatEffect effect;
@@ -1536,6 +1556,7 @@ public class MapleStatEffect {
}
}
}
*/
public short getHp() {
return hp;

View File

@@ -35,12 +35,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import net.server.Server;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MaplePlayerShopItem;
import server.TimerManager;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.Pair;
@@ -61,7 +59,6 @@ public class HiredMerchant extends AbstractMapleMapObject {
private List<Pair<String, Byte>> messages = new LinkedList<>();
private List<SoldItem> sold = new LinkedList<>();
private boolean open;
public ScheduledFuture<?> schedule = null;
private MapleMap map;
public HiredMerchant(final MapleCharacter owner, int itemId, String desc) {
@@ -74,14 +71,6 @@ public class HiredMerchant extends AbstractMapleMapObject {
this.ownerName = owner.getName();
this.description = desc;
this.map = owner.getMap();
this.schedule = TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
HiredMerchant.this.forceClose();
Server.getInstance().getChannel(world, channel).removeHiredMerchant(ownerId);
}
}, 1000 * 60 * 60 * 24);
}
public void broadcastToVisitors(final byte[] packet) {
@@ -194,9 +183,8 @@ public class HiredMerchant extends AbstractMapleMapObject {
}
public void forceClose() {
if (schedule != null) {
schedule.cancel(false);
}
Server.getInstance().getWorld(world).unregisterHiredMerchant(this);
try {
saveItems(true);
items.clear();
@@ -226,7 +214,6 @@ public class HiredMerchant extends AbstractMapleMapObject {
}
map = null;
schedule = null;
}
public void closeShop(MapleClient c, boolean timeout) {
@@ -268,7 +255,8 @@ public class HiredMerchant extends AbstractMapleMapObject {
} catch (Exception e) {
e.printStackTrace();
}
schedule.cancel(false);
Server.getInstance().getWorld(world).unregisterHiredMerchant(this);
}
public String getOwner() {