Addition of RandomAnimationManager.
This commit is contained in:
+8
-8
@@ -251,19 +251,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1859,10 +1859,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1876,10 +1876,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1884,10 +1884,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1864,10 +1864,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1940,10 +1940,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1940,10 +1940,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1970,10 +1970,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,15 +107,14 @@ ForceCompletePlayerStatusUpdate = True
|
|||||||
# The maximum deviation from the point of Spawn mobs
|
# The maximum deviation from the point of Spawn mobs
|
||||||
MaxDriftRange = 200
|
MaxDriftRange = 200
|
||||||
|
|
||||||
# Minimum and maximum delay animation
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# The minimum can not be greater than the maximum.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# "0" by default.
|
MinNpcAnimation = 5
|
||||||
MinNPCAnimation = 10
|
MaxNpcAnimation = 60
|
||||||
MaxNPCAnimation = 20
|
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Show the lvl and type of agro mobs?
|
# Show the lvl and type of aggro mobs?
|
||||||
ShowNpcLevel = False
|
ShowNpcLevel = False
|
||||||
|
|
||||||
# Record the location of the characters in the file before the off / restarting the server?
|
# Record the location of the characters in the file before the off / restarting the server?
|
||||||
|
|||||||
@@ -1287,10 +1287,10 @@ public final class Config
|
|||||||
|
|
||||||
MAX_DRIFT_RANGE = Integer.parseInt(optionsSettings.getProperty("MaxDriftRange", "300"));
|
MAX_DRIFT_RANGE = Integer.parseInt(optionsSettings.getProperty("MaxDriftRange", "300"));
|
||||||
|
|
||||||
MIN_NPC_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MinNPCAnimation", "10"));
|
MIN_NPC_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MinNpcAnimation", "5"));
|
||||||
MAX_NPC_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MaxNPCAnimation", "20"));
|
MAX_NPC_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MaxNpcAnimation", "60"));
|
||||||
MIN_MONSTER_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MinMonsterAnimation", "5"));
|
MIN_MONSTER_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MinMonsterAnimation", "5"));
|
||||||
MAX_MONSTER_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MaxMonsterAnimation", "20"));
|
MAX_MONSTER_ANIMATION = Integer.parseInt(optionsSettings.getProperty("MaxMonsterAnimation", "60"));
|
||||||
|
|
||||||
SHOW_NPC_LVL = Boolean.valueOf(optionsSettings.getProperty("ShowNpcLevel", "false"));
|
SHOW_NPC_LVL = Boolean.valueOf(optionsSettings.getProperty("ShowNpcLevel", "false"));
|
||||||
|
|
||||||
|
|||||||
@@ -30,14 +30,12 @@ import org.l2jmobius.gameserver.ai.PlayerAI.IntentionCommand;
|
|||||||
import org.l2jmobius.gameserver.model.Inventory;
|
import org.l2jmobius.gameserver.model.Inventory;
|
||||||
import org.l2jmobius.gameserver.model.Skill;
|
import org.l2jmobius.gameserver.model.Skill;
|
||||||
import org.l2jmobius.gameserver.model.WorldObject;
|
import org.l2jmobius.gameserver.model.WorldObject;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||||
import org.l2jmobius.gameserver.model.actor.Playable;
|
import org.l2jmobius.gameserver.model.actor.Playable;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.BoatInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.BoatInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.DoorInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.DoorInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance.ItemLocation;
|
import org.l2jmobius.gameserver.model.actor.instance.ItemInstance.ItemLocation;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.position.Location;
|
import org.l2jmobius.gameserver.model.actor.position.Location;
|
||||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||||
@@ -147,13 +145,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor instanceof Attackable)
|
|
||||||
{
|
|
||||||
((NpcInstance) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
@@ -1215,13 +1206,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor instanceof Attackable)
|
|
||||||
{
|
|
||||||
((NpcInstance) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.l2jmobius.gameserver.model.spawn.Spawn;
|
|||||||
import org.l2jmobius.gameserver.model.zone.ZoneManager;
|
import org.l2jmobius.gameserver.model.zone.ZoneManager;
|
||||||
import org.l2jmobius.gameserver.model.zone.ZoneType;
|
import org.l2jmobius.gameserver.model.zone.ZoneType;
|
||||||
import org.l2jmobius.gameserver.model.zone.type.PeaceZone;
|
import org.l2jmobius.gameserver.model.zone.type.PeaceZone;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
@@ -222,6 +223,12 @@ public final class WorldRegion
|
|||||||
((SiegeGuardAI) mob.getAI()).stopAITask();
|
((SiegeGuardAI) mob.getAI()).stopAITask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
|
}
|
||||||
|
else if (o instanceof NpcInstance)
|
||||||
|
{
|
||||||
|
RandomAnimationManager.getInstance().remove((NpcInstance) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,12 +240,11 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
// Start HP/MP/CP Regeneration task
|
// Start HP/MP/CP Regeneration task
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((NpcInstance) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof NpcInstance)
|
else if (o instanceof NpcInstance)
|
||||||
{
|
{
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay if the server allow it
|
RandomAnimationManager.getInstance().add((NpcInstance) o);
|
||||||
// Monsterinstance/Attackable socials are handled by AI (TODO: check the instances)
|
|
||||||
((NpcInstance) o).startRandomAnimationTask();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-107
@@ -16,14 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.l2jmobius.gameserver.model.actor.instance;
|
package org.l2jmobius.gameserver.model.actor.instance;
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
import org.l2jmobius.gameserver.cache.HtmCache;
|
import org.l2jmobius.gameserver.cache.HtmCache;
|
||||||
@@ -131,116 +128,12 @@ public class NpcInstance extends Creature
|
|||||||
private int _isSpoiledBy = 0;
|
private int _isSpoiledBy = 0;
|
||||||
private long _lastSocialBroadcast = 0;
|
private long _lastSocialBroadcast = 0;
|
||||||
private static final int MINIMUM_SOCIAL_INTERVAL = 6000;
|
private static final int MINIMUM_SOCIAL_INTERVAL = 6000;
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentCollisionHeight; // used for npc grow effect skills
|
private int _currentCollisionHeight; // used for npc grow effect skills
|
||||||
private int _currentCollisionRadius; // used for npc grow effect skills
|
private int _currentCollisionRadius; // used for npc grow effect skills
|
||||||
private int _scriptValue = 0;
|
private int _scriptValue = 0;
|
||||||
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private final NpcInstance _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(NpcInstance npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(_npc.isDead() || _npc.isStunned() || _npc.isSleeping() || _npc.isParalyzed()))
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<NpcInstance, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<NpcInstance, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final NpcInstance npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if ((npc instanceof Attackable) && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.isStunned() && !npc.isSleeping() && !npc.isParalyzed())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(NpcInstance npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(NpcInstance npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -244,19 +244,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -2065,10 +2065,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -203,13 +203,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TrainerInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.Fort;
|
import org.l2jmobius.gameserver.model.entity.Fort;
|
||||||
@@ -139,7 +138,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -242,37 +240,6 @@ public class Npc extends Creature
|
|||||||
return getTemplate().getAISkills(AISkillScope.SHORT_RANGE);
|
return getTemplate().getAISkills(AISkillScope.SHORT_RANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(_npc.isDead() || _npc.isStunned() || _npc.isSleeping() || _npc.isParalyzed()))
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.isStunned() && !npc.isSleeping() && !npc.isParalyzed())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1785,10 +1785,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-14
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1789,10 +1789,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1789,10 +1789,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-14
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1789,10 +1789,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-14
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -255,19 +255,19 @@ LazyCache = False
|
|||||||
# Default: True
|
# Default: True
|
||||||
CacheCharNames = True
|
CacheCharNames = True
|
||||||
|
|
||||||
# Minimum and maximum variables in seconds for npc animation delay.
|
# Minimum and maximum variables in seconds for NPC animation delay.
|
||||||
# You must keep MinNPCAnimation < = MaxNPCAnimation.
|
# You must keep MinNpcAnimation < = MaxNpcAnimation.
|
||||||
# Default: 10
|
# Default: 5
|
||||||
MinNPCAnimation = 10
|
MinNpcAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxNPCAnimation = 20
|
MaxNpcAnimation = 60
|
||||||
|
|
||||||
# Default: 5
|
# Default: 5
|
||||||
MinMonsterAnimation = 5
|
MinMonsterAnimation = 5
|
||||||
|
|
||||||
# Default: 20
|
# Default: 60
|
||||||
MaxMonsterAnimation = 20
|
MaxMonsterAnimation = 60
|
||||||
|
|
||||||
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
# Grid options: Grids can turn themselves on and off. This also affects the loading and processing of all AI tasks and (in the future) geodata within this grid.
|
||||||
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
# Turn on for a grid with a person in it is immediate, but it then turns on the 8 neighboring grids based on the specified number of seconds.
|
||||||
|
|||||||
@@ -1789,10 +1789,10 @@ public final class Config
|
|||||||
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
FORCE_INVENTORY_UPDATE = General.getBoolean("ForceInventoryUpdate", false);
|
||||||
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
LAZY_CACHE = General.getBoolean("LazyCache", true);
|
||||||
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
CACHE_CHAR_NAMES = General.getBoolean("CacheCharNames", true);
|
||||||
MIN_NPC_ANIMATION = General.getInt("MinNPCAnimation", 10);
|
MIN_NPC_ANIMATION = General.getInt("MinNpcAnimation", 5);
|
||||||
MAX_NPC_ANIMATION = General.getInt("MaxNPCAnimation", 20);
|
MAX_NPC_ANIMATION = General.getInt("MaxNpcAnimation", 60);
|
||||||
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
MIN_MONSTER_ANIMATION = General.getInt("MinMonsterAnimation", 5);
|
||||||
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 20);
|
MAX_MONSTER_ANIMATION = General.getInt("MaxMonsterAnimation", 60);
|
||||||
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
GRIDS_ALWAYS_ON = General.getBoolean("GridsAlwaysOn", false);
|
||||||
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
GRID_NEIGHBOR_TURNON_TIME = General.getInt("GridNeighborTurnOnTime", 1);
|
||||||
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
GRID_NEIGHBOR_TURNOFF_TIME = General.getInt("GridNeighborTurnOffTime", 90);
|
||||||
|
|||||||
@@ -188,13 +188,6 @@ public class CreatureAI extends AbstractAI
|
|||||||
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
// Stop the actor auto-attack client side by sending Server->Client packet AutoAttackStop (broadcast)
|
||||||
clientStopAutoAttack();
|
clientStopAutoAttack();
|
||||||
|
|
||||||
// Also enable random animations for this Creature if allowed
|
|
||||||
// This is only for mobs - town npcs are handled in their constructor
|
|
||||||
if (_actor.isAttackable())
|
|
||||||
{
|
|
||||||
((Npc) _actor).startRandomAnimationTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch the Think Event
|
// Launch the Think Event
|
||||||
onEvtThink();
|
onEvtThink();
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-14
@@ -20,18 +20,15 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
import org.l2jmobius.Config;
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
import org.l2jmobius.gameserver.model.actor.Attackable;
|
import org.l2jmobius.gameserver.model.actor.Attackable;
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
import org.l2jmobius.gameserver.model.actor.Vehicle;
|
import org.l2jmobius.gameserver.taskmanager.RandomAnimationManager;
|
||||||
|
|
||||||
public final class WorldRegion
|
public final class WorldRegion
|
||||||
{
|
{
|
||||||
private static final Logger LOGGER = Logger.getLogger(WorldRegion.class.getName());
|
|
||||||
|
|
||||||
/** Map containing visible objects in this world region. */
|
/** Map containing visible objects in this world region. */
|
||||||
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
private volatile Map<Integer, WorldObject> _visibleObjects = new ConcurrentHashMap<>();
|
||||||
/** Map containing nearby regions forming this world region's effective area. */
|
/** Map containing nearby regions forming this world region's effective area. */
|
||||||
@@ -81,14 +78,12 @@ public final class WorldRegion
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
if (!isOn)
|
if (!isOn)
|
||||||
{
|
{
|
||||||
for (WorldObject o : _visibleObjects.values())
|
for (WorldObject o : _visibleObjects.values())
|
||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
final Attackable mob = (Attackable) o;
|
final Attackable mob = (Attackable) o;
|
||||||
|
|
||||||
// Set target to null and cancel attack or cast.
|
// Set target to null and cancel attack or cast.
|
||||||
@@ -109,13 +104,14 @@ public final class WorldRegion
|
|||||||
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
mob.getAI().setIntention(org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_IDLE);
|
||||||
mob.getAI().stopAITask();
|
mob.getAI().stopAITask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomAnimationManager.getInstance().remove(mob);
|
||||||
}
|
}
|
||||||
else if (o instanceof Vehicle)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
c++;
|
RandomAnimationManager.getInstance().remove((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned off");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -123,16 +119,15 @@ public final class WorldRegion
|
|||||||
{
|
{
|
||||||
if (o.isAttackable())
|
if (o.isAttackable())
|
||||||
{
|
{
|
||||||
c++;
|
|
||||||
// Start HP/MP/CP regeneration task.
|
// Start HP/MP/CP regeneration task.
|
||||||
((Attackable) o).getStatus().startHpMpRegeneration();
|
((Attackable) o).getStatus().startHpMpRegeneration();
|
||||||
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
else if (o instanceof Npc)
|
else if (o instanceof Npc)
|
||||||
{
|
{
|
||||||
((Npc) o).startRandomAnimationTask();
|
RandomAnimationManager.getInstance().add((Npc) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.finer(c + " mobs were turned on");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +156,6 @@ public final class WorldRegion
|
|||||||
|
|
||||||
// Turn the AI on or off to match the region's activation.
|
// Turn the AI on or off to match the region's activation.
|
||||||
switchAI(value);
|
switchAI(value);
|
||||||
|
|
||||||
LOGGER.finer((value ? "Starting" : "Stopping") + " Grid " + this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
-33
@@ -59,7 +59,6 @@ import org.l2jmobius.gameserver.model.actor.instance.TeleporterInstance;
|
|||||||
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.WarehouseInstance;
|
||||||
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
import org.l2jmobius.gameserver.model.actor.stat.NpcStat;
|
||||||
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
import org.l2jmobius.gameserver.model.actor.status.NpcStatus;
|
||||||
import org.l2jmobius.gameserver.model.actor.tasks.npc.RandomAnimationTask;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||||
import org.l2jmobius.gameserver.model.entity.Castle;
|
import org.l2jmobius.gameserver.model.entity.Castle;
|
||||||
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
import org.l2jmobius.gameserver.model.entity.ClanHall;
|
||||||
@@ -132,7 +131,6 @@ public class Npc extends Creature
|
|||||||
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
private final boolean _isQuestMonster = getTemplate().isQuestMonster();
|
||||||
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
private final boolean _isFakePlayer = getTemplate().isFakePlayer();
|
||||||
|
|
||||||
protected RandomAnimationTask _rAniTask;
|
|
||||||
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentLHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentRHandId; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
private int _currentEnchant; // normally this shouldn't change from the template, but there exist exceptions
|
||||||
@@ -189,37 +187,6 @@ public class Npc extends Creature
|
|||||||
initStatusUpdateCache();
|
initStatusUpdateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRandomAnimationTask()
|
|
||||||
{
|
|
||||||
if (!hasRandomAnimation())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
synchronized (this)
|
|
||||||
{
|
|
||||||
if (_rAniTask == null)
|
|
||||||
{
|
|
||||||
_rAniTask = new RandomAnimationTask(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_rAniTask.startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRandomAnimationTask()
|
|
||||||
{
|
|
||||||
final RandomAnimationTask rAniTask = _rAniTask;
|
|
||||||
if (rAniTask != null)
|
|
||||||
{
|
|
||||||
rAniTask.stopRandomAnimationTimer();
|
|
||||||
_rAniTask = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
* Send a packet SocialAction to all PlayerInstance in the _KnownPlayers of the NpcInstance and create a new RandomAnimation Task.
|
||||||
* @param animationId
|
* @param animationId
|
||||||
|
|||||||
-104
@@ -1,104 +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.actor.tasks.npc;
|
|
||||||
|
|
||||||
import static org.l2jmobius.gameserver.ai.CtrlIntention.AI_INTENTION_ACTIVE;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.Config;
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.util.Rnd;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.Npc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nik
|
|
||||||
*/
|
|
||||||
public class RandomAnimationTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(RandomAnimationTask.class.getName());
|
|
||||||
private final Npc _npc;
|
|
||||||
private boolean _stopTask;
|
|
||||||
|
|
||||||
public RandomAnimationTask(Npc npc)
|
|
||||||
{
|
|
||||||
_npc = npc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if (_stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (!_npc.isInActiveRegion())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cancel further animation timers until intention is changed to ACTIVE again.
|
|
||||||
if (_npc.isAttackable() && (_npc.getAI().getIntention() != AI_INTENTION_ACTIVE))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_npc.isDead() && !_npc.hasBlockActions())
|
|
||||||
{
|
|
||||||
_npc.onRandomAnimation(Rnd.get(2, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
startRandomAnimationTimer();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.SEVERE, "Execution of RandomAnimationTask has failed.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a RandomAnimation Task that will be launched after the calculated delay.
|
|
||||||
*/
|
|
||||||
public void startRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
if (!_npc.hasRandomAnimation() || _stopTask)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int minWait = _npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION;
|
|
||||||
final int maxWait = _npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION;
|
|
||||||
|
|
||||||
// Calculate the delay before the next animation
|
|
||||||
final int interval = Rnd.get(minWait, maxWait) * 1000;
|
|
||||||
|
|
||||||
// Create a RandomAnimation Task that will be launched after the calculated delay
|
|
||||||
ThreadPool.schedule(this, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the task from continuing and blocks it from continuing ever again. You need to create new task if you want to start it again.
|
|
||||||
*/
|
|
||||||
public void stopRandomAnimationTimer()
|
|
||||||
{
|
|
||||||
_stopTask = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.Config;
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.commons.util.Rnd;
|
||||||
|
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.Npc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class RandomAnimationManager
|
||||||
|
{
|
||||||
|
private static final Map<Npc, Long> PENDING_ANIMATIONS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RandomAnimationManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Npc, Long> entry : PENDING_ANIMATIONS.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
final Npc npc = entry.getKey();
|
||||||
|
if (!npc.isInActiveRegion())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel further animation schedules until intention is changed to ACTIVE again.
|
||||||
|
if (npc.isAttackable() && (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ACTIVE))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!npc.isDead() && !npc.hasBlockActions())
|
||||||
|
{
|
||||||
|
npc.onRandomAnimation(Rnd.get(2, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
PENDING_ANIMATIONS.put(npc, time + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Npc npc)
|
||||||
|
{
|
||||||
|
if (npc.hasRandomAnimation())
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.putIfAbsent(npc, System.currentTimeMillis() + (Rnd.get((npc.isAttackable() ? Config.MIN_MONSTER_ANIMATION : Config.MIN_NPC_ANIMATION), (npc.isAttackable() ? Config.MAX_MONSTER_ANIMATION : Config.MAX_NPC_ANIMATION)) * 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(Npc npc)
|
||||||
|
{
|
||||||
|
PENDING_ANIMATIONS.remove(npc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RandomAnimationManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final RandomAnimationManager INSTANCE = new RandomAnimationManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user