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

@@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.StampedLock;
import java.util.logging.Level;
@@ -114,6 +115,7 @@ 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.AbnormalVisualEffect;
import org.l2jmobius.gameserver.model.skills.BuffFinishTask;
import org.l2jmobius.gameserver.model.skills.BuffInfo;
import org.l2jmobius.gameserver.model.skills.CommonSkill;
import org.l2jmobius.gameserver.model.skills.EffectScope;
@@ -243,6 +245,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private SkillChannelized _channelized = null;
private BuffFinishTask _buffFinishTask = null;
/** Map 32 bits, containing all abnormal visual effects in progress. */
private int _abnormalVisualEffects;
/** Map 32 bits, containing all special abnormal visual effects in progress. */
@@ -2439,6 +2443,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
getAI().stopAITask();
}
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
// Set world region to null.
setWorldRegion(null);
@@ -6741,4 +6748,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

@@ -52,8 +52,6 @@ public final class BuffInfo
// Tasks
/** Effect tasks for ticks. */
private volatile Map<AbstractEffect, EffectTaskInfo> _tasks = new ConcurrentHashMap<>();
/** Scheduled future. */
private ScheduledFuture<?> _scheduledFutureTimeTask;
// Time and ticks
/** Abnormal time. */
private int _abnormalTime;
@@ -227,11 +225,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();
}
@@ -253,7 +248,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);
}
boolean update = false;
@@ -463,6 +458,6 @@ public final class BuffInfo
@Override
public String toString()
{
return "BuffInfo [effector=" + _effector + ", effected=" + _effected + ", skill=" + _skill + ", effects=" + _effects + ", tasks=" + _tasks + ", scheduledFutureTimeTask=" + _scheduledFutureTimeTask + ", abnormalTime=" + _abnormalTime + ", periodStartTicks=" + _periodStartTicks + ", isRemoved=" + _isRemoved + ", isInUse=" + _isInUse + "]";
return "BuffInfo [effector=" + _effector + ", effected=" + _effected + ", skill=" + _skill + ", effects=" + _effects + ", tasks=" + _tasks + ", abnormalTime=" + _abnormalTime + ", periodStartTicks=" + _periodStartTicks + ", isRemoved=" + _isRemoved + ", isInUse=" + _isInUse + "]";
}
}

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());
}
}
}