|
@@ -14,7 +14,8 @@
|
|
*/
|
|
*/
|
|
package com.l2jserver.gameserver.taskmanager;
|
|
package com.l2jserver.gameserver.taskmanager;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.Map.Entry;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
@@ -22,30 +23,32 @@ import javolution.util.FastMap;
|
|
|
|
|
|
import com.l2jserver.gameserver.ThreadPoolManager;
|
|
import com.l2jserver.gameserver.ThreadPoolManager;
|
|
import com.l2jserver.gameserver.model.actor.L2Character;
|
|
import com.l2jserver.gameserver.model.actor.L2Character;
|
|
-import com.l2jserver.gameserver.model.actor.L2Summon;
|
|
|
|
import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
|
|
import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
|
|
import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @author Luca Baldi
|
|
|
|
|
|
+ * @author Luca Baldi, Zoey76
|
|
*/
|
|
*/
|
|
public class AttackStanceTaskManager
|
|
public class AttackStanceTaskManager
|
|
{
|
|
{
|
|
protected static final Logger _log = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
|
protected static final Logger _log = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
|
|
|
|
|
- protected Map<L2Character, Long> _attackStanceTasks = new FastMap<L2Character, Long>().shared();
|
|
|
|
|
|
+ protected static final FastMap<L2Character, Long> _attackStanceTasks = new FastMap<>();
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Instantiates a new attack stance task manager.
|
|
|
|
+ */
|
|
protected AttackStanceTaskManager()
|
|
protected AttackStanceTaskManager()
|
|
{
|
|
{
|
|
|
|
+ _attackStanceTasks.shared();
|
|
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FightModeScheduler(), 0, 1000);
|
|
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FightModeScheduler(), 0, 1000);
|
|
}
|
|
}
|
|
|
|
|
|
- public static AttackStanceTaskManager getInstance()
|
|
|
|
- {
|
|
|
|
- return SingletonHolder._instance;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Adds the attack stance task.
|
|
|
|
+ * @param actor the actor
|
|
|
|
+ */
|
|
public void addAttackStanceTask(L2Character actor)
|
|
public void addAttackStanceTask(L2Character actor)
|
|
{
|
|
{
|
|
if ((actor != null) && actor.isPlayable())
|
|
if ((actor != null) && actor.isPlayable())
|
|
@@ -62,67 +65,81 @@ public class AttackStanceTaskManager
|
|
_attackStanceTasks.put(actor, System.currentTimeMillis());
|
|
_attackStanceTasks.put(actor, System.currentTimeMillis());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Removes the attack stance task.
|
|
|
|
+ * @param actor the actor
|
|
|
|
+ */
|
|
public void removeAttackStanceTask(L2Character actor)
|
|
public void removeAttackStanceTask(L2Character actor)
|
|
{
|
|
{
|
|
- if (actor instanceof L2Summon)
|
|
|
|
|
|
+ if ((actor != null) && actor.isSummon())
|
|
{
|
|
{
|
|
- L2Summon summon = (L2Summon) actor;
|
|
|
|
- actor = summon.getOwner();
|
|
|
|
|
|
+ actor = actor.getActingPlayer();
|
|
}
|
|
}
|
|
_attackStanceTasks.remove(actor);
|
|
_attackStanceTasks.remove(actor);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Checks for attack stance task.<br>
|
|
|
|
+ * TODO: Rename this method to hasAttackStanceTask.
|
|
|
|
+ * @param actor the actor
|
|
|
|
+ * @return {@code true} if the character has an attack stance task, {@code false} otherwise
|
|
|
|
+ */
|
|
public boolean getAttackStanceTask(L2Character actor)
|
|
public boolean getAttackStanceTask(L2Character actor)
|
|
{
|
|
{
|
|
- if (actor instanceof L2Summon)
|
|
|
|
|
|
+ if ((actor != null) && actor.isSummon())
|
|
{
|
|
{
|
|
- L2Summon summon = (L2Summon) actor;
|
|
|
|
- actor = summon.getOwner();
|
|
|
|
|
|
+ actor = actor.getActingPlayer();
|
|
}
|
|
}
|
|
return _attackStanceTasks.containsKey(actor);
|
|
return _attackStanceTasks.containsKey(actor);
|
|
}
|
|
}
|
|
|
|
|
|
- private class FightModeScheduler implements Runnable
|
|
|
|
|
|
+ protected class FightModeScheduler implements Runnable
|
|
{
|
|
{
|
|
- protected FightModeScheduler()
|
|
|
|
- {
|
|
|
|
- // Do nothing
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void run()
|
|
public void run()
|
|
{
|
|
{
|
|
- Long current = System.currentTimeMillis();
|
|
|
|
|
|
+ long current = System.currentTimeMillis();
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- if (_attackStanceTasks != null)
|
|
|
|
|
|
+ final Iterator<Entry<L2Character, Long>> iter = _attackStanceTasks.entrySet().iterator();
|
|
|
|
+ Entry<L2Character, Long> e;
|
|
|
|
+ L2Character actor;
|
|
|
|
+ while (iter.hasNext())
|
|
{
|
|
{
|
|
- synchronized (this)
|
|
|
|
|
|
+ e = iter.next();
|
|
|
|
+ if ((current - e.getValue()) > 15000)
|
|
{
|
|
{
|
|
- for (L2Character actor : _attackStanceTasks.keySet())
|
|
|
|
|
|
+ actor = e.getKey();
|
|
|
|
+ if (actor != null)
|
|
{
|
|
{
|
|
- if ((current - _attackStanceTasks.get(actor)) > 15000)
|
|
|
|
|
|
+ actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
|
|
|
|
+ actor.getAI().setAutoAttacking(false);
|
|
|
|
+ if (actor.isPlayer() && actor.getActingPlayer().hasPet())
|
|
{
|
|
{
|
|
- actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
|
|
|
|
- if ((actor instanceof L2PcInstance) && (((L2PcInstance) actor).getPet() != null))
|
|
|
|
- {
|
|
|
|
- ((L2PcInstance) actor).getPet().broadcastPacket(new AutoAttackStop(((L2PcInstance) actor).getPet().getObjectId()));
|
|
|
|
- }
|
|
|
|
- actor.getAI().setAutoAttacking(false);
|
|
|
|
- _attackStanceTasks.remove(actor);
|
|
|
|
|
|
+ actor.getActingPlayer().getPet().broadcastPacket(new AutoAttackStop(actor.getActingPlayer().getPet().getObjectId()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ iter.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
{
|
|
{
|
|
- // TODO: Find out the reason for exception. Unless caught here, players remain in attack positions.
|
|
|
|
|
|
+ // Unless caught here, players remain in attack positions.
|
|
_log.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
|
|
_log.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets the single instance of AttackStanceTaskManager.
|
|
|
|
+ * @return single instance of AttackStanceTaskManager
|
|
|
|
+ */
|
|
|
|
+ public static AttackStanceTaskManager getInstance()
|
|
|
|
+ {
|
|
|
|
+ return SingletonHolder._instance;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static class SingletonHolder
|
|
private static class SingletonHolder
|
|
{
|
|
{
|
|
protected static final AttackStanceTaskManager _instance = new AttackStanceTaskManager();
|
|
protected static final AttackStanceTaskManager _instance = new AttackStanceTaskManager();
|