Addition of PvpFlagTaskManager.
This commit is contained in:
@@ -2982,36 +2982,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Task lauching the function stopPvPFlag().
|
||||
*/
|
||||
class PvPFlag implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// try
|
||||
// {
|
||||
if (System.currentTimeMillis() > _pvpFlagLasts)
|
||||
{
|
||||
stopPvPFlag();
|
||||
}
|
||||
else if (System.currentTimeMillis() > (_pvpFlagLasts - 5000))
|
||||
{
|
||||
updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
updatePvPFlag(1);
|
||||
}
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// LOGGER.warning("error in pvp flag task: " + e);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/** Map 32 bits (0x0000) containing all abnormal effect in progress. */
|
||||
private int _AbnormalEffects;
|
||||
|
||||
@@ -8373,71 +8343,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
_castInterruptTime = newSkillCastEndTime - 12;
|
||||
}
|
||||
|
||||
/** The _ pvp reg task. */
|
||||
private Future<?> _PvPRegTask;
|
||||
|
||||
/** The _pvp flag lasts. */
|
||||
long _pvpFlagLasts;
|
||||
|
||||
/**
|
||||
* Sets the pvp flag lasts.
|
||||
* @param time the new pvp flag lasts
|
||||
*/
|
||||
public void setPvpFlagLasts(long time)
|
||||
{
|
||||
_pvpFlagLasts = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pvp flag lasts.
|
||||
* @return the pvp flag lasts
|
||||
*/
|
||||
public long getPvpFlagLasts()
|
||||
{
|
||||
return _pvpFlagLasts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start pvp flag.
|
||||
*/
|
||||
public void startPvPFlag()
|
||||
{
|
||||
updatePvPFlag(1);
|
||||
|
||||
_PvPRegTask = ThreadPool.scheduleAtFixedRate(new PvPFlag(), 1000, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop pvp reg task.
|
||||
*/
|
||||
public void stopPvpRegTask()
|
||||
{
|
||||
if (_PvPRegTask != null)
|
||||
{
|
||||
_PvPRegTask.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop pvp flag.
|
||||
*/
|
||||
public void stopPvPFlag()
|
||||
{
|
||||
stopPvpRegTask();
|
||||
|
||||
updatePvPFlag(0);
|
||||
|
||||
_PvPRegTask = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update pvp flag.
|
||||
* @param value the value
|
||||
*/
|
||||
public void updatePvPFlag(int value)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Random Damage in function of the weapon.
|
||||
* @param target the target
|
||||
@@ -8456,7 +8361,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "mob " + getObjectId();
|
||||
return "Creature " + getObjectId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -229,6 +229,7 @@ import org.l2jmobius.gameserver.network.serverpackets.TradeStart;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ValidateLocation;
|
||||
import org.l2jmobius.gameserver.taskmanager.PlayerAutoSaveTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.PvpFlagTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.FloodProtectors;
|
||||
import org.l2jmobius.gameserver.util.IllegalPlayerAction;
|
||||
@@ -307,6 +308,7 @@ public class PlayerInstance extends Playable
|
||||
private int _lastKill = 0;
|
||||
private int _count = 0;
|
||||
private byte _pvpFlag;
|
||||
private long _pvpFlagLasts;
|
||||
private byte _siegeState = 0;
|
||||
private int _curWeightPenalty = 0;
|
||||
private int _lastCompassZone; // the last compass zone update send to the client
|
||||
@@ -1652,7 +1654,50 @@ public class PlayerInstance extends Playable
|
||||
return _pvpFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Sets the pvp flag lasts.
|
||||
* @param time the new pvp flag lasts
|
||||
*/
|
||||
public void setPvpFlagLasts(long time)
|
||||
{
|
||||
_pvpFlagLasts = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pvp flag lasts.
|
||||
* @return the pvp flag lasts
|
||||
*/
|
||||
public long getPvpFlagLasts()
|
||||
{
|
||||
return _pvpFlagLasts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start pvp flag.
|
||||
*/
|
||||
public void startPvPFlag()
|
||||
{
|
||||
updatePvPFlag(1);
|
||||
PvpFlagTaskManager.getInstance().add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop pvp reg task.
|
||||
*/
|
||||
public void stopPvpRegTask()
|
||||
{
|
||||
PvpFlagTaskManager.getInstance().remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop pvp flag.
|
||||
*/
|
||||
public void stopPvPFlag()
|
||||
{
|
||||
stopPvpRegTask();
|
||||
updatePvPFlag(0);
|
||||
}
|
||||
|
||||
public void updatePvPFlag(int value)
|
||||
{
|
||||
if (getPvpFlag() == value)
|
||||
|
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class PvpFlagTaskManager
|
||||
{
|
||||
private static final Set<PlayerInstance> PLAYERS = ConcurrentHashMap.newKeySet();
|
||||
private static boolean _working = false;
|
||||
|
||||
public PvpFlagTaskManager()
|
||||
{
|
||||
ThreadPool.scheduleAtFixedRate(() ->
|
||||
{
|
||||
if (_working)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_working = true;
|
||||
|
||||
if (!PLAYERS.isEmpty())
|
||||
{
|
||||
final long time = System.currentTimeMillis();
|
||||
for (PlayerInstance player : PLAYERS)
|
||||
{
|
||||
if (time > player.getPvpFlagLasts())
|
||||
{
|
||||
player.stopPvPFlag();
|
||||
}
|
||||
else if (time > (player.getPvpFlagLasts() - 5000))
|
||||
{
|
||||
player.updatePvPFlag(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.updatePvPFlag(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_working = false;
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
public void add(PlayerInstance player)
|
||||
{
|
||||
PLAYERS.add(player);
|
||||
}
|
||||
|
||||
public void remove(PlayerInstance player)
|
||||
{
|
||||
PLAYERS.remove(player);
|
||||
}
|
||||
|
||||
public static PvpFlagTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final PvpFlagTaskManager INSTANCE = new PvpFlagTaskManager();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user