gameserver/taskmanager/AutoPotTaskManager.java
/*
* 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.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.l2jmobius.Config;
import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.gameserver.model.actor.Player;
/**
* [member=6902]oRiGiNaL[/member] Code Mobius
* @Reworked Code Dramaa
*/
public class AutoPotTaskManager
{
private static final Set<Set<Player>> POOLS = ConcurrentHashMap.newKeySet();
private static final Map<Player, Integer> IDLE_COUNT = new ConcurrentHashMap<>();
private static final int POOL_SIZE = 300;
private static final int TASK_DELAY = 300;
protected AutoPotTaskManager()
{
}
private class AutoPot implements Runnable
{
private final Set<Player> _players;
public AutoPot(Set<Player> players)
{
_players = players;
}
[member=79]override[/member]
public void run()
{
if (_players.isEmpty())
{
return;
}
PLAY: for (Player player : _players)
{
if (!player.isOnline() || (player.isInOfflineMode() && !player.isOfflinePlay()) || !Config.ENABLE_AUTO_PPOT)
{
stopAutoPot(player);
continue PLAY;
}
if (player.isSitting() || player.isCastingNow() || (player.getQueuedSkill() != null))
{
continue PLAY;
}
}
}
}
public synchronized void startAutoPot(Player player)
{
for (Set<Player> pool : POOLS)
{
if (pool.contains(player))
{
return;
}
}
player.setAutoPot(true);
for (Set<Player> pool : POOLS)
{
if (pool.size() < POOL_SIZE)
{
player.onActionRequest();
pool.add(player);
return;
}
}
final Set<Player> pool = ConcurrentHashMap.newKeySet(POOL_SIZE);
player.onActionRequest();
pool.add(player);
ThreadPool.schedulePriorityTaskAtFixedRate(new AutoPot(pool), TASK_DELAY, TASK_DELAY);
POOLS.add(pool);
}
public void stopAutoPot(Player player)
{
for (Set<Player> pool : POOLS)
{
if (pool.remove(player))
{
player.setAutoPot(false);
// Pets must follow their owner.
if (player.hasServitor() || player.hasPet())
{
player.getSummon().followOwner();
}
IDLE_COUNT.remove(player);
return;
}
}
}
public static AutoPotTaskManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final AutoPotTaskManager INSTANCE = new AutoPotTaskManager();
}
}
gameserver/model/holders/AutoPlaySettingsHolder.java
/*
* 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.holders;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Mobius
*/
public class AutoPlaySettingsHolder
{
private final AtomicInteger _options = new AtomicInteger();
private final AtomicBoolean _pickup = new AtomicBoolean(true);
private final AtomicInteger _nextTargetMode = new AtomicInteger(1);
private final AtomicBoolean _shortRange = new AtomicBoolean();
private final AtomicBoolean _respectfulHunting = new AtomicBoolean(true);
+ private final AtomicInteger _autoHpPercent = new AtomicInteger(50);
+ private final AtomicInteger _autoCpPercent = new AtomicInteger(50);
+ private final AtomicInteger _autoMpPercent = new AtomicInteger(50);
private final AtomicInteger _autoPotionPercent = new AtomicInteger(50);
public AutoPlaySettingsHolder()
{
}
public int getOptions()
{
return _options.get();
}
public void setOptions(int options)
{
_options.set(options);
}
public boolean doPickup()
{
return _pickup.get();
}
public void setPickup(boolean value)
{
_pickup.set(value);
}
public int getNextTargetMode()
{
return _nextTargetMode.get();
}
public void setNextTargetMode(int nextTargetMode)
{
_nextTargetMode.set(nextTargetMode);
}
public boolean isShortRange()
{
return _shortRange.get();
}
public void setShortRange(boolean value)
{
_shortRange.set(value);
}
public boolean isRespectfulHunting()
{
return _respectfulHunting.get();
}
public void setRespectfulHunting(boolean value)
{
_respectfulHunting.set(value);
}
public int getAutoPotionPercent()
{
return _autoPotionPercent.get();
}
+ public int getAutoHpPercent()
+ {
+ return _autoHpPercent.get();
+ }
+
+ public int getAutoMpPercent()
+ {
+ return _autoMpPercent.get();
+ }
+
+ public int getAutoCpPercent()
+ {
+ return _autoCpPercent.get();
+ }
+
public void setAutoPotionPercent(int value)
{
_autoPotionPercent.set(value);
}
+ public void setAutoHpPercent(int value)
+ {
+ _autoHpPercent.set(value);
+ }
+
+ public void setAutoMpPercent(int value)
+ {
+ _autoMpPercent.set(value);
+ }
+
+ public void setAutoCpPercent(int value)
+ {
+ _autoCpPercent.set(value);
+ }
}