diff --git a/src/resources/objects/Buff.java b/src/resources/objects/Buff.java index 1b01f13d..de6081da 100644 --- a/src/resources/objects/Buff.java +++ b/src/resources/objects/Buff.java @@ -38,6 +38,8 @@ public class Buff implements IListObject { @NotPersistent private SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); + private String group1; + private int priority; private float duration; private String buffName; private long ownerId; @@ -70,6 +72,8 @@ public class Buff implements IListObject { if(visitor.getObject(i, 0) != null) if(((String) visitor.getObject(i, 0)).equalsIgnoreCase(buffName)) { + group1 = (String) visitor.getObject(i, 1); + priority = (int) visitor.getObject(i, 4); duration = (Float) visitor.getObject(i, 6); effect1Name = (String) visitor.getObject(i, 7); effect1Value = (Float) visitor.getObject(i, 8); @@ -112,14 +116,19 @@ public class Buff implements IListObject { IoBuffer buffer = bufferPool.allocate(28, false).order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(CRC.StringtoCRC(buffName.toLowerCase())); + if(duration < 1) { if(duration > 0) { buffer.putInt((int) (totalPlayTime + getRemainingDuration())); buffer.putInt(0); buffer.putInt((int) duration); } else { buffer.putInt(-1); + buffer.putInt(0); buffer.putInt(0); + } else { + buffer.putInt((int) (totalPlayTime + getRemainingDuration())); buffer.putInt(0); + buffer.putInt((int) duration); } buffer.putLong(ownerId); buffer.putInt(1); // unk @@ -130,6 +139,22 @@ public class Buff implements IListObject { } + public String getGroup1() { + return group1; + } + + public void setGroup1(String group1) { + this.group1 = group1; + } + + public float getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } + public float getDuration() { return duration; } diff --git a/src/services/BuffService.java b/src/services/BuffService.java index 6b64120b..52f982c8 100644 --- a/src/services/BuffService.java +++ b/src/services/BuffService.java @@ -34,6 +34,7 @@ import resources.objects.player.PlayerObject; import main.NGECore; +import engine.resources.common.CRC; import engine.resources.service.INetworkDispatch; import engine.resources.service.INetworkRemoteEvent; @@ -65,17 +66,27 @@ public class BuffService implements INetworkDispatch { final Buff buff = new Buff(buffName, creature.getObjectID()); buff.setTotalPlayTime(((PlayerObject) creature.getSlottedObject("ghost")).getTotalPlayTime()); - if(creature.getBuffByName(buffName) != null) { + + + for (Buff otherBuff : creature.getBuffList()) { + if (buff.getGroup1().equals(otherBuff.getGroup1())) + if (buff.getPriority() >= otherBuff.getPriority()) { + if (buff.getBuffName().equals(otherBuff.getBuffName())) { + if (otherBuff.getRemainingDuration() > buff.getDuration()) { + return; + } + } + + removeBuffFromCreature(creature, otherBuff); System.out.println("buff removed " + buffName); + break; + }else{ + System.out.println("buff not added:" + buffName); + return; + } + } - Buff otherBuff = creature.getBuffByName(buffName); - if(otherBuff.getRemainingDuration() > buff.getDuration()) { - return; - } else { - removeBuffFromCreature(creature, otherBuff); - } - - } - + + if (FileUtilities.doesFileExist("scripts/commands/" + buffName + ".py")) buffName = "buff_" + buffName; core.scriptService.callScript("scripts/buffs", "setup", buffName, core, creature, buff); creature.addBuff(buff); @@ -88,20 +99,23 @@ public class BuffService implements INetworkDispatch { removeBuffFromCreature(creature, buff); + } }, (long) buff.getDuration(), TimeUnit.SECONDS); } - } + } } public void removeBuffFromCreature(CreatureObject creature, Buff buff) { - if(!creature.getBuffList().contains(buff)) - return; - - core.scriptService.callScript("scripts/buffs", "removeBuff", buff.getBuffName(), core, creature, buff); - creature.removeBuff(buff); + if(!creature.getBuffList().contains(buff)) + return; + + String buffName = buff.getBuffName(); + if (FileUtilities.doesFileExist("scripts/commands/" + buffName + ".py")) buffName = "buff_" + buffName; + core.scriptService.callScript("scripts/buffs", "removeBuff", buffName, core, creature, buff); + creature.removeBuff(buff); }