Addition of BuffFinishTask.

This commit is contained in:
MobiusDevelopment
2019-06-05 11:42:14 +00:00
parent 42df46f4bb
commit 33c731ee3f
52 changed files with 1300 additions and 893 deletions

View File

@ -120,6 +120,7 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType;
import org.l2jmobius.gameserver.model.options.OptionsSkillHolder;
import org.l2jmobius.gameserver.model.options.OptionsSkillType;
import org.l2jmobius.gameserver.model.skills.AbnormalType;
import org.l2jmobius.gameserver.model.skills.BuffFinishTask;
import org.l2jmobius.gameserver.model.skills.BuffInfo;
import org.l2jmobius.gameserver.model.skills.Skill;
import org.l2jmobius.gameserver.model.skills.SkillCaster;
@ -243,6 +244,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private SkillChannelized _channelized = null;
private BuffFinishTask _buffFinishTask = null;
private Optional<Transform> _transform = Optional.empty();
/** Movement data of this Creature */
@ -1694,6 +1697,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Cancel all timers related to this Creature
TimersManager.getInstance().cancelTimers(getObjectId());
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
// Set world region to null.
setWorldRegion(null);
@ -5412,4 +5418,34 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return _fakePlayerDrops;
}
public void addBuffInfoTime(BuffInfo info)
{
if (_buffFinishTask == null)
{
_buffFinishTask = new BuffFinishTask();
}
_buffFinishTask.addBuffInfo(info);
}
public void removeBuffInfoTime(BuffInfo info)
{
if (_buffFinishTask != null)
{
_buffFinishTask.removeBuffInfo(info);
}
}
public void cancelBuffFinishTask()
{
if (_buffFinishTask != null)
{
final ScheduledFuture<?> task = _buffFinishTask.getTask();
if ((task != null) && !task.isCancelled() && !task.isDone())
{
task.cancel(true);
}
_buffFinishTask = null;
}
}
}

View File

@ -0,0 +1,59 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.model.skills;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicInteger;
import org.l2jmobius.commons.concurrent.ThreadPool;
/**
* @author Mobius
*/
public class BuffFinishTask
{
private final Map<BuffInfo, AtomicInteger> _buffInfos = new ConcurrentHashMap<>();
private final ScheduledFuture<?> _task = ThreadPool.scheduleAtFixedRate(() ->
{
for (Entry<BuffInfo, AtomicInteger> entry : _buffInfos.entrySet())
{
final BuffInfo info = entry.getKey();
if ((info.getEffected() != null) && (entry.getValue().incrementAndGet() > info.getAbnormalTime()))
{
info.getEffected().getEffectList().stopSkillEffects(false, info.getSkill().getId());
}
}
}, 0, 1000);
public ScheduledFuture<?> getTask()
{
return _task;
}
public void addBuffInfo(BuffInfo info)
{
_buffInfos.put(info, new AtomicInteger());
}
public void removeBuffInfo(BuffInfo info)
{
_buffInfos.remove(info);
}
}

View File

@ -55,8 +55,6 @@ public final class BuffInfo
// Tasks
/** Effect tasks for ticks. */
private volatile Map<AbstractEffect, EffectTaskInfo> _tasks;
/** Scheduled future. */
private ScheduledFuture<?> _scheduledFutureTimeTask;
// Time and ticks
/** Abnormal time. */
private int _abnormalTime;
@ -296,11 +294,8 @@ public final class BuffInfo
public void stopAllEffects(boolean removed)
{
setRemoved(removed);
// Cancels the task that will end this buff info
if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled())
{
_scheduledFutureTimeTask.cancel(true);
}
// Remove this buff info from BuffFinishTask.
_effected.removeBuffInfoTime(this);
finishEffects();
}
@ -322,7 +317,7 @@ public final class BuffInfo
// Creates a task that will stop all the effects.
if (_abnormalTime > 0)
{
_scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000);
_effected.addBuffInfoTime(this);
}
for (AbstractEffect effect : _effects)
@ -453,11 +448,8 @@ public final class BuffInfo
{
_periodStartTicks = GameTimeController.getInstance().getGameTicks();
_abnormalTime = abnormalTime;
if ((_scheduledFutureTimeTask != null) && !_scheduledFutureTimeTask.isCancelled())
{
_scheduledFutureTimeTask.cancel(true);
}
_scheduledFutureTimeTask = ThreadPool.scheduleAtFixedRate(new BuffTimeTask(this), 0, 1000);
_effected.removeBuffInfoTime(this);
_effected.addBuffInfoTime(this);
}
}

View File

@ -1,56 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.model.skills;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Effect time task finish the effect when the abnormal time is reached.
* @author Zoey76
*/
public class BuffTimeTask implements Runnable
{
private final AtomicInteger _time = new AtomicInteger();
private final BuffInfo _info;
/**
* EffectTimeTask constructor.
* @param info the buff info
*/
public BuffTimeTask(BuffInfo info)
{
_info = info;
}
/**
* Gets the elapsed time.
* @return the tick count
*/
public int getElapsedTime()
{
return _time.get();
}
@Override
public void run()
{
if ((_info.getEffected() != null) && (_time.incrementAndGet() > _info.getAbnormalTime()))
{
_info.getEffected().getEffectList().stopSkillEffects(false, _info.getSkill().getId());
}
}
}