public void clearBuffs(final CreatureObject creature) { // copy to array for thread safety for (final Buff buff : creature.getBuffList().get().toArray(new Buff[] {})) { if (buff.getGroup1().startsWith("setBonus")) { continue; } if (buff.isGroupBuff() && buff.getGroupBufferId() != creature.getObjectID()) { removeBuffFromCreature(creature, buff); continue; } if (buff.getRemainingDuration() > 0 && buff.getDuration() > 0) { ScheduledFuture<?> task = scheduler.schedule( new Runnable() { @Override public void run() { removeBuffFromCreature(creature, buff); } }, (long) buff.getRemainingDuration(), TimeUnit.SECONDS); buff.setRemovalTask(task); continue; } else { removeBuffFromCreature(creature, buff); } } }
public void updateRemovalTask() { if (removalTask == null) return; removalTask.cancel(true); final NGECore core = NGECore.getInstance(); final CreatureObject owner = (CreatureObject) core.objectService.getObject(getOwnerId()); if (owner == null) return; ScheduledFuture<?> task = Executors.newScheduledThreadPool(1) .schedule( new Runnable() { @Override public void run() { core.buffService.removeBuffFromCreature(owner, Buff.this); } }, (long) getRemainingDuration(), TimeUnit.SECONDS); setRemovalTask(task); }
public Buff doAddBuff(final CreatureObject creature, String buffName) { final Buff buff = new Buff(buffName, creature.getObjectID()); buff.setTotalPlayTime(((PlayerObject) creature.getSlottedObject("ghost")).getTotalPlayTime()); for (final Buff otherBuff : creature.getBuffList()) { if (buff.getGroup1().equals(otherBuff.getGroup1())) if (buff.getPriority() >= otherBuff.getPriority()) { if (buff.getBuffName().equals(otherBuff.getBuffName())) { if (otherBuff.getStacks() < otherBuff.getMaxStacks()) { buff.setStacks(otherBuff.getStacks() + 1); if (creature.getDotByBuff(otherBuff) != null) // reset duration when theres a dot stack creature.getDotByBuff(otherBuff).setStartTime(buff.getStartTime()); } if (otherBuff.getRemainingDuration() > buff.getDuration() && otherBuff.getStacks() >= otherBuff.getMaxStacks()) { return null; } } removeBuffFromCreature(creature, otherBuff); break; } else { System.out.println("buff not added:" + buffName); return null; } } if (FileUtilities.doesFileExist("scripts/buffs/" + buffName + ".py")) core.scriptService.callScript("scripts/buffs/", "setup", buffName, core, creature, buff); creature.addBuff(buff); if (buff.getDuration() > 0) { ScheduledFuture<?> task = scheduler.schedule( new Runnable() { @Override public void run() { removeBuffFromCreature(creature, buff); } }, (long) buff.getDuration(), TimeUnit.SECONDS); buff.setRemovalTask(task); } return buff; }