Reworked GameTime task manager.
This commit is contained in:
@ -169,6 +169,9 @@ public class GameServer
|
||||
printSection("ThreadPool");
|
||||
ThreadPool.init();
|
||||
|
||||
// Start game time task manager early
|
||||
GameTimeTaskManager.getInstance();
|
||||
|
||||
printSection("IdManager");
|
||||
IdManager.getInstance();
|
||||
if (!IdManager.hasInitialized())
|
||||
@ -192,7 +195,6 @@ public class GameServer
|
||||
TeleportLocationTable.getInstance();
|
||||
PartyMatchWaitingList.getInstance();
|
||||
PartyMatchRoomList.getInstance();
|
||||
GameTimeTaskManager.getInstance();
|
||||
CharNameTable.getInstance();
|
||||
ExperienceData.getInstance();
|
||||
|
||||
|
@ -47,6 +47,7 @@ import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerClose;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
@ -297,10 +298,22 @@ public class Shutdown extends Thread
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().stopTimer();
|
||||
MovementTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Movement Task Manager thread has been shutdown.");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
GameTimeTaskManager.getInstance().interrupt();
|
||||
LOGGER.info("Game Time Task Manager thread has been shutdown.");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
// saveData sends messages to exit players, so shutdown selector after it
|
||||
@ -308,7 +321,7 @@ public class Shutdown extends Thread
|
||||
{
|
||||
ClientNetworkManager.getInstance().stop();
|
||||
EventLoopGroupManager.getInstance().shutdown();
|
||||
LOGGER.info("Game Server: Selector thread has been shut down.");
|
||||
LOGGER.info("Game Server: Selector thread has been shutdown.");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
|
@ -33,8 +33,8 @@ import org.l2jmobius.gameserver.model.actor.Summon;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStart;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MoveToLocation;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.Die;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MoveToLocation;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MoveToLocationInVehicle;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MoveToPawn;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.StopMove;
|
||||
@ -442,7 +442,7 @@ abstract class AbstractAI implements Ctrl
|
||||
{
|
||||
if (_clientMovingToPawnOffset == offset)
|
||||
{
|
||||
if (GameTimeTaskManager.getGameTicks() < _moveToPawnTimeout)
|
||||
if (GameTimeTaskManager.getInstance().getGameTicks() < _moveToPawnTimeout)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -452,7 +452,7 @@ abstract class AbstractAI implements Ctrl
|
||||
else if (_actor.isOnGeodataPath())
|
||||
{
|
||||
// minimum time to calculate new route is 2 seconds
|
||||
if (GameTimeTaskManager.getGameTicks() < (_moveToPawnTimeout + 10))
|
||||
if (GameTimeTaskManager.getInstance().getGameTicks() < (_moveToPawnTimeout + 10))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -465,7 +465,7 @@ abstract class AbstractAI implements Ctrl
|
||||
|
||||
setTarget(pawn);
|
||||
|
||||
_moveToPawnTimeout = GameTimeTaskManager.getGameTicks();
|
||||
_moveToPawnTimeout = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_moveToPawnTimeout += /* 1000 */ 200 / GameTimeTaskManager.MILLIS_IN_TICK;
|
||||
|
||||
if ((pawn == null) || (_accessor == null))
|
||||
|
@ -361,7 +361,7 @@ public class AttackableAI extends CreatureAI
|
||||
protected void onIntentionAttack(Creature target)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
|
||||
super.onIntentionAttack(target);
|
||||
@ -655,18 +655,18 @@ public class AttackableAI extends CreatureAI
|
||||
}
|
||||
|
||||
// Check if the actor is running
|
||||
if ((_attackTimeout < GameTimeTaskManager.getGameTicks()) && _actor.isRunning())
|
||||
if ((_attackTimeout < GameTimeTaskManager.getInstance().getGameTicks()) && _actor.isRunning())
|
||||
{
|
||||
// Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others Player
|
||||
_actor.setWalking();
|
||||
|
||||
// Calculate a new attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
// Check if target is dead or if timeout is expired to stop this attack
|
||||
final Creature originalAttackTarget = getAttackTarget();
|
||||
if ((originalAttackTarget == null) || originalAttackTarget.isAlikeDead() || ((originalAttackTarget instanceof Player) && (((Player) originalAttackTarget).isInOfflineMode() || !((Player) originalAttackTarget).isOnline())) || (_attackTimeout < GameTimeTaskManager.getGameTicks()))
|
||||
if ((originalAttackTarget == null) || originalAttackTarget.isAlikeDead() || ((originalAttackTarget instanceof Player) && (((Player) originalAttackTarget).isInOfflineMode() || !((Player) originalAttackTarget).isOnline())) || (_attackTimeout < GameTimeTaskManager.getInstance().getGameTicks()))
|
||||
{
|
||||
// Stop hating this target after the attack timeout or if target is dead
|
||||
if (originalAttackTarget != null)
|
||||
@ -933,7 +933,7 @@ public class AttackableAI extends CreatureAI
|
||||
return;
|
||||
}
|
||||
// Else, if this is close enough to attack
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// check for close combat skills && heal/buff skills
|
||||
if (!_actor.isMuted() /* && _rnd.nextInt(100) <= 5 */)
|
||||
@ -1042,7 +1042,7 @@ public class AttackableAI extends CreatureAI
|
||||
protected void onEvtAttacked(Creature attacker)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Set the _globalAggro to 0 to permit attack even just after spawn
|
||||
if (_globalAggro < 0)
|
||||
|
@ -260,7 +260,7 @@ public class FortSiegeGuardAI extends CreatureAI implements Runnable
|
||||
protected void onIntentionAttack(Creature target)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
|
||||
// if (_actor.getTarget() != null)
|
||||
@ -378,18 +378,18 @@ public class FortSiegeGuardAI extends CreatureAI implements Runnable
|
||||
private void thinkAttack()
|
||||
{
|
||||
// Check if the actor is running
|
||||
if ((_attackTimeout < GameTimeTaskManager.getGameTicks()) && _actor.isRunning())
|
||||
if ((_attackTimeout < GameTimeTaskManager.getInstance().getGameTicks()) && _actor.isRunning())
|
||||
{
|
||||
// Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others Player
|
||||
_actor.setWalking();
|
||||
|
||||
// Calculate a new attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
final Creature attackTarget = getAttackTarget();
|
||||
// Check if target is dead or if timeout is expired to stop this attack
|
||||
if ((attackTarget == null) || attackTarget.isAlikeDead() || (_attackTimeout < GameTimeTaskManager.getGameTicks()))
|
||||
if ((attackTarget == null) || attackTarget.isAlikeDead() || (_attackTimeout < GameTimeTaskManager.getInstance().getGameTicks()))
|
||||
{
|
||||
// Stop hating this target after the attack timeout or if target is dead
|
||||
if (attackTarget != null)
|
||||
@ -771,7 +771,7 @@ public class FortSiegeGuardAI extends CreatureAI implements Runnable
|
||||
attackTarget = hated;
|
||||
}
|
||||
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// check for close combat skills && heal/buff skills
|
||||
if (!_actor.isMuted() && (Rnd.get(100) <= 5))
|
||||
@ -871,7 +871,7 @@ public class FortSiegeGuardAI extends CreatureAI implements Runnable
|
||||
protected void onEvtAttacked(Creature attacker)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Set the _globalAggro to 0 to permit attack even just after spawn
|
||||
if (_globalAggro < 0)
|
||||
|
@ -216,7 +216,7 @@ public class SiegeGuardAI extends CreatureAI implements Runnable
|
||||
protected void onIntentionAttack(Creature target)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Manage the Attack Intention : Stop current Attack (if necessary), Start a new Attack and Launch Think Event
|
||||
// if (_actor.getTarget() != null)
|
||||
@ -470,7 +470,7 @@ public class SiegeGuardAI extends CreatureAI implements Runnable
|
||||
setAttackTarget(hated);
|
||||
}
|
||||
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// check for close combat skills && heal/buff skills
|
||||
if (!_actor.isMuted() && (Rnd.get(100) <= 5))
|
||||
@ -531,19 +531,19 @@ public class SiegeGuardAI extends CreatureAI implements Runnable
|
||||
private void thinkAttack()
|
||||
{
|
||||
// Check if the actor is running
|
||||
if ((_attackTimeout < GameTimeTaskManager.getGameTicks()) && _actor.isRunning())
|
||||
if ((_attackTimeout < GameTimeTaskManager.getInstance().getGameTicks()) && _actor.isRunning())
|
||||
{
|
||||
// Set the actor movement type to walk and send Server->Client packet ChangeMoveType to all others Player
|
||||
_actor.setWalking();
|
||||
|
||||
// Calculate a new attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
final Creature attackTarget = getAttackTarget();
|
||||
|
||||
// Check if target is dead or if timeout is expired to stop this attack
|
||||
if ((attackTarget == null) || attackTarget.isAlikeDead() || (_attackTimeout < GameTimeTaskManager.getGameTicks()))
|
||||
if ((attackTarget == null) || attackTarget.isAlikeDead() || (_attackTimeout < GameTimeTaskManager.getInstance().getGameTicks()))
|
||||
{
|
||||
// Stop hating this target after the attack timeout or if target is dead
|
||||
if (attackTarget != null)
|
||||
@ -679,7 +679,7 @@ public class SiegeGuardAI extends CreatureAI implements Runnable
|
||||
protected void onEvtAttacked(Creature attacker)
|
||||
{
|
||||
// Calculate the attack timeout
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getGameTicks();
|
||||
_attackTimeout = MAX_ATTACK_TIMEOUT + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Set the _globalAggro to 0 to permit attack even just after spawn
|
||||
if (_globalAggro < 0)
|
||||
|
@ -191,7 +191,7 @@ public class ScrollOfEscape implements IItemHandler
|
||||
// Continue execution later.
|
||||
final EscapeFinalizer escapeFinalizer = new EscapeFinalizer(player, itemId);
|
||||
player.setSkillCast(ThreadPool.schedule(escapeFinalizer, hitTime));
|
||||
player.setSkillCastEndTime(10 + GameTimeTaskManager.getGameTicks() + (hitTime / GameTimeTaskManager.MILLIS_IN_TICK));
|
||||
player.setSkillCastEndTime(10 + GameTimeTaskManager.getInstance().getGameTicks() + (hitTime / GameTimeTaskManager.MILLIS_IN_TICK));
|
||||
}
|
||||
|
||||
static class EscapeFinalizer implements Runnable
|
||||
|
@ -117,7 +117,7 @@ public class Escape implements IUserCommandHandler
|
||||
// Continue execution later.
|
||||
final EscapeFinalizer escapeFinalizer = new EscapeFinalizer(player);
|
||||
player.setSkillCast(ThreadPool.schedule(escapeFinalizer, unstuckTimer));
|
||||
player.setSkillCastEndTime(10 + GameTimeTaskManager.getGameTicks() + (unstuckTimer / GameTimeTaskManager.MILLIS_IN_TICK));
|
||||
player.setSkillCastEndTime(10 + GameTimeTaskManager.getInstance().getGameTicks() + (unstuckTimer / GameTimeTaskManager.MILLIS_IN_TICK));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ public class Wedding implements IVoicedCommandHandler
|
||||
// Continue execution later.
|
||||
final EscapeFinalizer escapeFinalizer = new EscapeFinalizer(activeChar, partner.getX(), partner.getY(), partner.getZ(), partner.isIn7sDungeon());
|
||||
activeChar.setSkillCast(ThreadPool.schedule(escapeFinalizer, teleportTimer));
|
||||
activeChar.setSkillCastEndTime(10 + GameTimeTaskManager.getGameTicks() + (teleportTimer / GameTimeTaskManager.MILLIS_IN_TICK));
|
||||
activeChar.setSkillCastEndTime(10 + GameTimeTaskManager.getInstance().getGameTicks() + (teleportTimer / GameTimeTaskManager.MILLIS_IN_TICK));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,7 @@ public class DayNightSpawnManager
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("DayNightSpawnManager: Removed " + i + " " + unspawnLogInfo + " creatures");
|
||||
}
|
||||
|
||||
@ -151,14 +152,14 @@ public class DayNightSpawnManager
|
||||
{
|
||||
spawnDayCreatures();
|
||||
specialNightBoss(0);
|
||||
ShadowSenseMsg(0);
|
||||
shadowSenseMsg(0);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
spawnNightCreatures();
|
||||
specialNightBoss(1);
|
||||
ShadowSenseMsg(1);
|
||||
shadowSenseMsg(1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -262,7 +263,7 @@ public class DayNightSpawnManager
|
||||
}
|
||||
}
|
||||
|
||||
private void ShadowSenseMsg(int mode)
|
||||
private void shadowSenseMsg(int mode)
|
||||
{
|
||||
final Skill skill = SkillTable.getInstance().getSkill(294, 1);
|
||||
if (skill == null)
|
||||
@ -294,7 +295,6 @@ public class DayNightSpawnManager
|
||||
{
|
||||
final RaidBoss raidboss = (RaidBoss) spawnDat.doSpawn();
|
||||
_bosses.put(spawnDat, raidboss);
|
||||
|
||||
return raidboss;
|
||||
}
|
||||
return null;
|
||||
|
@ -129,7 +129,7 @@ public class Party
|
||||
public void setPendingInvitation(boolean value)
|
||||
{
|
||||
_pendingInvitation = value;
|
||||
_pendingInviteTimeout = GameTimeTaskManager.getGameTicks() + (Player.REQUEST_TIMEOUT * GameTimeTaskManager.TICKS_PER_SECOND);
|
||||
_pendingInviteTimeout = GameTimeTaskManager.getInstance().getGameTicks() + (Player.REQUEST_TIMEOUT * GameTimeTaskManager.TICKS_PER_SECOND);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,7 +139,7 @@ public class Party
|
||||
*/
|
||||
public boolean isInvitationRequestExpired()
|
||||
{
|
||||
return (_pendingInviteTimeout <= GameTimeTaskManager.getGameTicks());
|
||||
return (_pendingInviteTimeout <= GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,6 +124,7 @@ import org.l2jmobius.gameserver.network.serverpackets.TargetUnselected;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.TeleportToLocation;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ValidateLocationInVehicle;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Broadcast;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
@ -819,7 +820,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
}
|
||||
|
||||
// Verify if the bow can be use
|
||||
if (_disableBowAttackEndTime <= GameTimeTaskManager.getGameTicks())
|
||||
if (_disableBowAttackEndTime <= GameTimeTaskManager.getInstance().getGameTicks())
|
||||
{
|
||||
// Verify if Player owns enough MP
|
||||
final int saMpConsume = (int) getStat().calcStat(Stat.MP_CONSUME, 0, null, null);
|
||||
@ -836,7 +837,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
getStatus().reduceMp(mpConsume);
|
||||
|
||||
// Set the period of bow non re-use
|
||||
_disableBowAttackEndTime = (5 * GameTimeTaskManager.TICKS_PER_SECOND) + GameTimeTaskManager.getGameTicks();
|
||||
_disableBowAttackEndTime = (5 * GameTimeTaskManager.TICKS_PER_SECOND) + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -848,7 +849,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
}
|
||||
else if (this instanceof Npc)
|
||||
{
|
||||
if (_disableBowAttackEndTime > GameTimeTaskManager.getGameTicks())
|
||||
if (_disableBowAttackEndTime > GameTimeTaskManager.getInstance().getGameTicks())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -898,7 +899,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
// the hit is calculated to happen halfway to the animation - might need further tuning e.g. in bow case
|
||||
final int timeAtk = calculateTimeBetweenAttacks(target, weaponItem);
|
||||
final int timeToHit = timeAtk / 2;
|
||||
_attackEndTime = GameTimeTaskManager.getGameTicks();
|
||||
_attackEndTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_attackEndTime += (timeAtk / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
_attackEndTime -= 1;
|
||||
int ssGrade = 0;
|
||||
@ -1067,7 +1068,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
ThreadPool.schedule(new HitTask(target, damage1, crit1, miss1, attack.soulshot, shld1), sAtk);
|
||||
|
||||
// Calculate and set the disable delay of the bow in function of the Attack Speed
|
||||
_disableBowAttackEndTime = ((sAtk + reuse) / GameTimeTaskManager.MILLIS_IN_TICK) + GameTimeTaskManager.getGameTicks();
|
||||
_disableBowAttackEndTime = ((sAtk + reuse) / GameTimeTaskManager.MILLIS_IN_TICK) + GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Add this hit to the Server-Client packet Attack
|
||||
attack.addHit(target, damage1, miss1, crit1, shld1);
|
||||
@ -1505,14 +1506,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
if (skill.isPotion())
|
||||
{
|
||||
// Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
|
||||
_castPotionEndTime = 10 + GameTimeTaskManager.getGameTicks() + ((coolTime + hitTime) / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
_castPotionInterruptTime = -2 + GameTimeTaskManager.getGameTicks() + (hitTime / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
_castPotionEndTime = 10 + GameTimeTaskManager.getInstance().getGameTicks() + ((coolTime + hitTime) / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
_castPotionInterruptTime = -2 + GameTimeTaskManager.getInstance().getGameTicks() + (hitTime / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the _castEndTime and _castInterruptTim. +10 ticks for lag situations, will be reseted in onMagicFinalizer
|
||||
_castEndTime = 10 + GameTimeTaskManager.getGameTicks() + ((coolTime + hitTime) / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
_castInterruptTime = -2 + GameTimeTaskManager.getGameTicks() + (hitTime / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
_castEndTime = 10 + GameTimeTaskManager.getInstance().getGameTicks() + ((coolTime + hitTime) / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
_castInterruptTime = -2 + GameTimeTaskManager.getInstance().getGameTicks() + (hitTime / GameTimeTaskManager.MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
// Init the reuse time of the skill
|
||||
@ -4791,7 +4792,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return _castEndTime > GameTimeTaskManager.getGameTicks();
|
||||
return _castEndTime > GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4800,7 +4801,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
*/
|
||||
public boolean isCastingPotionNow()
|
||||
{
|
||||
return _castPotionEndTime > GameTimeTaskManager.getGameTicks();
|
||||
return _castPotionEndTime > GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4809,7 +4810,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
*/
|
||||
public boolean canAbortCast()
|
||||
{
|
||||
return _castInterruptTime > GameTimeTaskManager.getGameTicks();
|
||||
return _castInterruptTime > GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4818,7 +4819,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
*/
|
||||
public boolean isAttackingNow()
|
||||
{
|
||||
return _attackEndTime > GameTimeTaskManager.getGameTicks();
|
||||
return _attackEndTime > GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4908,10 +4909,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
* client send regularly a Client->Server ValidatePosition packet to eventually correct the gap on the server. But, it's always the server position that is used in range calculation.<br>
|
||||
* At the end of the estimated movement time, the Creature position is automatically set to the destination position even if the movement is not finished.<br>
|
||||
* <font color=#FF0000><b><u>Caution</u>: The current Z position is obtained FROM THE CLIENT by the Client->Server ValidatePosition Packet. But x and y positions must be calculated to avoid that players try to modify their movement speed.</b></font>
|
||||
* @param gameTicks number of ticks since the server start
|
||||
* @return True if the movement is finished
|
||||
*/
|
||||
public boolean updatePosition(int gameTicks)
|
||||
public boolean updatePosition()
|
||||
{
|
||||
// Get movement data
|
||||
final MoveData m = _move;
|
||||
@ -4934,6 +4934,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
m._yAccurate = getY();
|
||||
}
|
||||
|
||||
final int gameTicks = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Check if the position has already been calculated
|
||||
if (m._moveTimestamp == gameTicks)
|
||||
{
|
||||
@ -5043,7 +5045,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
}
|
||||
}
|
||||
|
||||
return distFraction > 1;
|
||||
if (distFraction > 1)
|
||||
{
|
||||
getKnownList().updateKnownObjects();
|
||||
ThreadPool.execute(() -> getAI().notifyEvent(CtrlEvent.EVT_ARRIVED));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -5481,14 +5490,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
setHeading(Util.calculateHeadingFrom(cos, sin));
|
||||
}
|
||||
|
||||
m._moveStartTime = GameTimeTaskManager.getGameTicks();
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
@ -5561,14 +5570,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
// One tick added for rounding reasons
|
||||
final int ticksToMove = 1 + (int) ((GameTimeTaskManager.TICKS_PER_SECOND * distance) / speed);
|
||||
m._heading = 0; // initial value for coordinate sync
|
||||
m._moveStartTime = GameTimeTaskManager.getGameTicks();
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the GameTimeTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
|
||||
// Create a task to notify the AI that Creature arrives at a check point of the movement
|
||||
if ((ticksToMove * GameTimeTaskManager.MILLIS_IN_TICK) > 3000)
|
||||
|
@ -38,6 +38,7 @@ import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.LoginServerThread;
|
||||
import org.l2jmobius.gameserver.ai.CreatureAI;
|
||||
import org.l2jmobius.gameserver.ai.CtrlEvent;
|
||||
import org.l2jmobius.gameserver.ai.CtrlIntention;
|
||||
import org.l2jmobius.gameserver.ai.PlayerAI;
|
||||
import org.l2jmobius.gameserver.cache.HtmCache;
|
||||
@ -714,12 +715,12 @@ public class Player extends Playable
|
||||
|
||||
public boolean isSpawnProtected()
|
||||
{
|
||||
return (_protectEndTime != 0) && (_protectEndTime > GameTimeTaskManager.getGameTicks());
|
||||
return (_protectEndTime != 0) && (_protectEndTime > GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
|
||||
public boolean isTeleportProtected()
|
||||
{
|
||||
return (_teleportProtectEndTime != 0) && (_teleportProtectEndTime > GameTimeTaskManager.getGameTicks());
|
||||
return (_teleportProtectEndTime != 0) && (_teleportProtectEndTime > GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4160,7 +4161,7 @@ public class Player extends Playable
|
||||
return;
|
||||
}
|
||||
|
||||
_protectEndTime = protect ? GameTimeTaskManager.getGameTicks() + (Config.PLAYER_SPAWN_PROTECTION * GameTimeTaskManager.TICKS_PER_SECOND) : 0;
|
||||
_protectEndTime = protect ? GameTimeTaskManager.getInstance().getGameTicks() + (Config.PLAYER_SPAWN_PROTECTION * GameTimeTaskManager.TICKS_PER_SECOND) : 0;
|
||||
if (protect)
|
||||
{
|
||||
ThreadPool.schedule(new TeleportProtectionFinalizer(this), (Config.PLAYER_SPAWN_PROTECTION - 1) * 1000);
|
||||
@ -4173,7 +4174,7 @@ public class Player extends Playable
|
||||
*/
|
||||
public void setTeleportProtection(boolean protect)
|
||||
{
|
||||
_teleportProtectEndTime = protect ? GameTimeTaskManager.getGameTicks() + (Config.PLAYER_TELEPORT_PROTECTION * GameTimeTaskManager.TICKS_PER_SECOND) : 0;
|
||||
_teleportProtectEndTime = protect ? GameTimeTaskManager.getInstance().getGameTicks() + (Config.PLAYER_TELEPORT_PROTECTION * GameTimeTaskManager.TICKS_PER_SECOND) : 0;
|
||||
if (protect)
|
||||
{
|
||||
ThreadPool.schedule(new TeleportProtectionFinalizer(this), (Config.PLAYER_TELEPORT_PROTECTION - 1) * 1000);
|
||||
@ -4225,7 +4226,7 @@ public class Player extends Playable
|
||||
*/
|
||||
public void setRecentFakeDeath(boolean protect)
|
||||
{
|
||||
_recentFakeDeathEndTime = protect ? GameTimeTaskManager.getGameTicks() + (Config.PLAYER_FAKEDEATH_UP_PROTECTION * GameTimeTaskManager.TICKS_PER_SECOND) : 0;
|
||||
_recentFakeDeathEndTime = protect ? GameTimeTaskManager.getInstance().getGameTicks() + (Config.PLAYER_FAKEDEATH_UP_PROTECTION * GameTimeTaskManager.TICKS_PER_SECOND) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4234,7 +4235,7 @@ public class Player extends Playable
|
||||
*/
|
||||
public boolean isRecentFakeDeath()
|
||||
{
|
||||
return _recentFakeDeathEndTime > GameTimeTaskManager.getGameTicks();
|
||||
return _recentFakeDeathEndTime > GameTimeTaskManager.getInstance().getGameTicks();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6449,7 +6450,7 @@ public class Player extends Playable
|
||||
*/
|
||||
public boolean isProcessingRequest()
|
||||
{
|
||||
return (_activeRequester != null) || (_requestExpireTime > GameTimeTaskManager.getGameTicks());
|
||||
return (_activeRequester != null) || (_requestExpireTime > GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6458,7 +6459,7 @@ public class Player extends Playable
|
||||
*/
|
||||
public boolean isProcessingTransaction()
|
||||
{
|
||||
return (_activeRequester != null) || (_activeTradeList != null) || (_requestExpireTime > GameTimeTaskManager.getGameTicks());
|
||||
return (_activeRequester != null) || (_activeTradeList != null) || (_requestExpireTime > GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -6467,7 +6468,7 @@ public class Player extends Playable
|
||||
*/
|
||||
public void onTransactionRequest(Player partner)
|
||||
{
|
||||
_requestExpireTime = GameTimeTaskManager.getGameTicks() + (REQUEST_TIMEOUT * GameTimeTaskManager.TICKS_PER_SECOND);
|
||||
_requestExpireTime = GameTimeTaskManager.getInstance().getGameTicks() + (REQUEST_TIMEOUT * GameTimeTaskManager.TICKS_PER_SECOND);
|
||||
if (partner != null)
|
||||
{
|
||||
partner.setActiveRequester(this);
|
||||
@ -6982,7 +6983,7 @@ public class Player extends Playable
|
||||
@Override
|
||||
public boolean isInvul()
|
||||
{
|
||||
return _isInvul || _isTeleporting || (_protectEndTime > GameTimeTaskManager.getGameTicks()) || (_teleportProtectEndTime > GameTimeTaskManager.getGameTicks());
|
||||
return _isInvul || _isTeleporting || (_protectEndTime > GameTimeTaskManager.getInstance().getGameTicks()) || (_teleportProtectEndTime > GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -12226,7 +12227,7 @@ public class Player extends Playable
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePosition(int gameTicks)
|
||||
public boolean updatePosition()
|
||||
{
|
||||
// Get movement data
|
||||
final MoveData m = _move;
|
||||
@ -12247,6 +12248,8 @@ public class Player extends Playable
|
||||
m._moveTimestamp = m._moveStartTime;
|
||||
}
|
||||
|
||||
final int gameTicks = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Check if the position has alreday be calculated
|
||||
if (m._moveTimestamp == gameTicks)
|
||||
{
|
||||
@ -12273,7 +12276,14 @@ public class Player extends Playable
|
||||
m._moveTimestamp = gameTicks;
|
||||
revalidateZone(false);
|
||||
|
||||
return distFraction > 1;
|
||||
if (distFraction > 1)
|
||||
{
|
||||
getKnownList().updateKnownObjects();
|
||||
ThreadPool.execute(() -> getAI().notifyEvent(CtrlEvent.EVT_ARRIVED));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -14179,7 +14189,7 @@ public class Player extends Playable
|
||||
*/
|
||||
public boolean isRequestExpired()
|
||||
{
|
||||
return (_requestExpireTime <= GameTimeTaskManager.getGameTicks());
|
||||
return (_requestExpireTime <= GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,6 +39,7 @@ import org.l2jmobius.gameserver.network.serverpackets.PlaySound;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.VehicleDeparture;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.VehicleInfo;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.MovementTaskManager;
|
||||
|
||||
/**
|
||||
* @author Maktakien
|
||||
@ -96,14 +97,14 @@ public class Boat extends Creature
|
||||
m._zDestination = z; // this is what was requested from client
|
||||
m._heading = 0;
|
||||
m.onGeodataPathIndex = -1; // Initialize not on geodata path
|
||||
m._moveStartTime = GameTimeTaskManager.getGameTicks();
|
||||
m._moveStartTime = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
|
||||
// Set the Creature _move object to MoveData object
|
||||
_move = m;
|
||||
|
||||
// Add the Creature to movingObjects of the GameTimeTaskManager
|
||||
// The GameTimeTaskManager manage objects movement
|
||||
GameTimeTaskManager.getInstance().registerMovingObject(this);
|
||||
// Add the Creature to moving objects of the MovementTaskManager.
|
||||
// The MovementTaskManager manages object movement.
|
||||
MovementTaskManager.getInstance().registerMovingObject(this);
|
||||
}
|
||||
|
||||
public void evtArrived()
|
||||
|
@ -97,7 +97,7 @@ public abstract class Effect
|
||||
{
|
||||
if (_periodfirsttime == 0)
|
||||
{
|
||||
setPeriodStartTicks(GameTimeTaskManager.getGameTicks());
|
||||
setPeriodStartTicks(GameTimeTaskManager.getInstance().getGameTicks());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -146,7 +146,7 @@ public abstract class Effect
|
||||
_abnormalEffect = template.abnormalEffect;
|
||||
_stackType = template.stackType;
|
||||
_stackOrder = template.stackOrder;
|
||||
_periodStartTicks = GameTimeTaskManager.getGameTicks();
|
||||
_periodStartTicks = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
_periodfirsttime = 0;
|
||||
scheduleEffect();
|
||||
}
|
||||
@ -170,7 +170,7 @@ public abstract class Effect
|
||||
{
|
||||
if (_currentFuture != null)
|
||||
{
|
||||
_periodStartTicks = GameTimeTaskManager.getGameTicks() - (newfirsttime * GameTimeTaskManager.TICKS_PER_SECOND);
|
||||
_periodStartTicks = GameTimeTaskManager.getInstance().getGameTicks() - (newfirsttime * GameTimeTaskManager.TICKS_PER_SECOND);
|
||||
_currentFuture.cancel(false);
|
||||
_currentFuture = null;
|
||||
_currentTask = null;
|
||||
@ -188,7 +188,7 @@ public abstract class Effect
|
||||
|
||||
public int getTime()
|
||||
{
|
||||
return (GameTimeTaskManager.getGameTicks() - _periodStartTicks) / GameTimeTaskManager.TICKS_PER_SECOND;
|
||||
return (GameTimeTaskManager.getInstance().getGameTicks() - _periodStartTicks) / GameTimeTaskManager.TICKS_PER_SECOND;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,7 +168,7 @@ public class RequestActionUse implements IClientIncomingPacket
|
||||
{
|
||||
if (pet.isAttackDisabled())
|
||||
{
|
||||
if (pet.getAttackEndTime() > GameTimeTaskManager.getGameTicks())
|
||||
if (pet.getAttackEndTime() > GameTimeTaskManager.getInstance().getGameTicks())
|
||||
{
|
||||
pet.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ public class ClientSetTime implements IClientOutgoingPacket
|
||||
public boolean write(PacketWriter packet)
|
||||
{
|
||||
OutgoingPackets.CLIENT_SET_TIME.writeId(packet);
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // time in client minutes
|
||||
packet.writeD(6); // constant to match the server time( this determines the speed of the client clock)
|
||||
packet.writeD(GameTimeTaskManager.getInstance().getGameTime()); // Time in client minutes.
|
||||
packet.writeD(GameTimeTaskManager.IG_DAYS_PER_DAY); // Constant to match the server time. This determines the speed of the client clock.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -16,50 +16,67 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.Calendar;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.gameserver.ai.CtrlEvent;
|
||||
import org.l2jmobius.gameserver.instancemanager.DayNightSpawnManager;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Game Time task manager class.
|
||||
* @author Forsaiken
|
||||
* GameTime task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class GameTimeTaskManager
|
||||
public class GameTimeTaskManager extends Thread
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
private static final Logger LOGGER = Logger.getLogger(GameTimeTaskManager.class.getName());
|
||||
|
||||
public static final int TICKS_PER_SECOND = 10;
|
||||
public static final int TICKS_PER_SECOND = 10; // Not able to change this without checking through code.
|
||||
public static final int MILLIS_IN_TICK = 1000 / TICKS_PER_SECOND;
|
||||
public static final int IG_DAYS_PER_DAY = 6;
|
||||
public static final int MILLIS_PER_IG_DAY = (3600000 * 24) / IG_DAYS_PER_DAY;
|
||||
public static final int SECONDS_PER_IG_DAY = MILLIS_PER_IG_DAY / 1000;
|
||||
public static final int TICKS_PER_IG_DAY = SECONDS_PER_IG_DAY * TICKS_PER_SECOND;
|
||||
|
||||
protected static int _gameTicks;
|
||||
protected static long _gameStartTime;
|
||||
protected static boolean _isNight = false;
|
||||
|
||||
private static final Set<Creature> _movingObjects = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected static TimerThread _timer;
|
||||
private final ScheduledFuture<?> _timerWatcher;
|
||||
private final long _referenceTime;
|
||||
private boolean _isNight;
|
||||
|
||||
protected GameTimeTaskManager()
|
||||
{
|
||||
_gameStartTime = System.currentTimeMillis() - 3600000; // offset so that the server starts a day begin
|
||||
_gameTicks = 3600000 / MILLIS_IN_TICK; // offset so that the server starts a day begin
|
||||
super("GameTimeTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(NORM_PRIORITY);
|
||||
|
||||
_timer = new TimerThread();
|
||||
_timer.start();
|
||||
final Calendar c = Calendar.getInstance();
|
||||
c.set(Calendar.HOUR_OF_DAY, 0);
|
||||
c.set(Calendar.MINUTE, 0);
|
||||
c.set(Calendar.SECOND, 0);
|
||||
c.set(Calendar.MILLISECOND, 0);
|
||||
_referenceTime = c.getTimeInMillis();
|
||||
|
||||
_timerWatcher = ThreadPool.scheduleAtFixedRate(new TimerWatcher(), 0, 1000);
|
||||
ThreadPool.scheduleAtFixedRate(new BroadcastSunState(), 0, 600000);
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if ((getGameHour() < 6) != _isNight)
|
||||
{
|
||||
_isNight = !_isNight;
|
||||
ThreadPool.execute(() -> DayNightSpawnManager.getInstance().notifyChangeMode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNight()
|
||||
@ -67,14 +84,17 @@ public class GameTimeTaskManager
|
||||
return _isNight;
|
||||
}
|
||||
|
||||
public int getGameTime()
|
||||
/**
|
||||
* @return The actual GameTime tick. Directly taken from current time.
|
||||
*/
|
||||
public int getGameTicks()
|
||||
{
|
||||
return _gameTicks / (TICKS_PER_SECOND * 10);
|
||||
return (int) ((System.currentTimeMillis() - _referenceTime) / MILLIS_IN_TICK);
|
||||
}
|
||||
|
||||
public static int getGameTicks()
|
||||
public int getGameTime()
|
||||
{
|
||||
return _gameTicks;
|
||||
return (getGameTicks() % TICKS_PER_IG_DAY) / MILLIS_IN_TICK;
|
||||
}
|
||||
|
||||
public int getGameHour()
|
||||
@ -87,180 +107,6 @@ public class GameTimeTaskManager
|
||||
return getGameTime() % 60;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.
|
||||
* @param creature The Creature to add to movingObjects of GameTimeTaskManager
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_movingObjects.add(creature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move all Creatures contained in movingObjects of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Concept</u>:</b><br>
|
||||
* <br>
|
||||
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager.<br>
|
||||
* <br>
|
||||
* <b><u>Actions</u>:</b><br>
|
||||
* <li>Update the position of each Creature</li>
|
||||
* <li>If movement is finished, the Creature is removed from movingObjects</li>
|
||||
* <li>Create a task to update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED</li>
|
||||
*/
|
||||
protected void moveObjects()
|
||||
{
|
||||
final List<Creature> finished = new LinkedList<>();
|
||||
for (Creature creature : _movingObjects)
|
||||
{
|
||||
if (creature.updatePosition(_gameTicks))
|
||||
{
|
||||
finished.add(creature);
|
||||
}
|
||||
}
|
||||
|
||||
if (!finished.isEmpty())
|
||||
{
|
||||
for (Creature creature : finished)
|
||||
{
|
||||
_movingObjects.remove(creature);
|
||||
}
|
||||
ThreadPool.execute(new MovingObjectArrived(finished));
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTimer()
|
||||
{
|
||||
_timerWatcher.cancel(true);
|
||||
_timer.interrupt();
|
||||
}
|
||||
|
||||
private class TimerThread extends Thread
|
||||
{
|
||||
protected Exception _error;
|
||||
|
||||
public TimerThread()
|
||||
{
|
||||
super("GameTimeTaskManager");
|
||||
setDaemon(true);
|
||||
setPriority(MAX_PRIORITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
final int _oldTicks = _gameTicks; // save old ticks value to avoid moving objects 2x in same tick
|
||||
long runtime = System.currentTimeMillis() - _gameStartTime; // from server boot to now
|
||||
|
||||
_gameTicks = (int) (runtime / MILLIS_IN_TICK); // new ticks value (ticks now)
|
||||
|
||||
if (_oldTicks != _gameTicks)
|
||||
{
|
||||
moveObjects(); // XXX: if this makes objects go slower, remove it
|
||||
// but I think it can't make that effect. is it better to call moveObjects() twice in same
|
||||
// tick to make-up for missed tick ? or is it better to ignore missed tick ?
|
||||
// (will happen very rarely but it will happen ... on garbage collection definitely)
|
||||
}
|
||||
|
||||
runtime = System.currentTimeMillis() - _gameStartTime - runtime;
|
||||
|
||||
// calculate sleep time... time needed to next tick minus time it takes to call moveObjects()
|
||||
final int sleepTime = (1 + MILLIS_IN_TICK) - ((int) runtime % MILLIS_IN_TICK);
|
||||
|
||||
// LOGGER.finest("TICK: "+_gameTicks);
|
||||
|
||||
try
|
||||
{
|
||||
sleep(sleepTime); // hope other threads will have much more cpu time available now
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
// SelectorThread most of all
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class TimerWatcher implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!_timer.isAlive())
|
||||
{
|
||||
final String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
|
||||
LOGGER.warning(time + " TimerThread stop with following error. restart it.");
|
||||
if (_timer._error != null)
|
||||
{
|
||||
_timer._error.printStackTrace();
|
||||
}
|
||||
|
||||
_timer = new TimerThread();
|
||||
_timer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the _knownObject and _knowPlayers of each Creature that finished its movement and of their already known WorldObject then notify AI with EVT_ARRIVED.
|
||||
*/
|
||||
private class MovingObjectArrived implements Runnable
|
||||
{
|
||||
private final List<Creature> _finished;
|
||||
|
||||
MovingObjectArrived(List<Creature> finished)
|
||||
{
|
||||
_finished = finished;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (int i = 0; i < _finished.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Creature creature = _finished.get(i);
|
||||
creature.getKnownList().updateKnownObjects();
|
||||
creature.getAI().notifyEvent(CtrlEvent.EVT_ARRIVED);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class BroadcastSunState implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final int h = (getGameTime() / 60) % 24; // Time in hour
|
||||
final boolean tempIsNight = h < 6;
|
||||
|
||||
// If diff day/night state
|
||||
if (tempIsNight != _isNight)
|
||||
{
|
||||
// Set current day/night varible to value of temp varible
|
||||
_isNight = tempIsNight;
|
||||
DayNightSpawnManager.getInstance().notifyChangeMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final GameTimeTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
@ -270,4 +116,4 @@ public class GameTimeTaskManager
|
||||
{
|
||||
protected static final GameTimeTaskManager INSTANCE = new GameTimeTaskManager();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
|
||||
/**
|
||||
* Movement task manager class.
|
||||
* @author Forsaiken, Mobius
|
||||
*/
|
||||
public class MovementTaskManager extends Thread
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(MovementTaskManager.class.getName());
|
||||
|
||||
private static final Set<Creature> MOVING_OBJECTS = ConcurrentHashMap.newKeySet();
|
||||
|
||||
protected MovementTaskManager()
|
||||
{
|
||||
super("MovementTaskManager");
|
||||
super.setDaemon(true);
|
||||
super.setPriority(MAX_PRIORITY);
|
||||
super.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Creature to moving objects of MovementTaskManager.
|
||||
* @param creature The Creature to add to moving objects of MovementTaskManager.
|
||||
*/
|
||||
public void registerMovingObject(Creature creature)
|
||||
{
|
||||
if (creature == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MOVING_OBJECTS.add(creature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
MOVING_OBJECTS.removeIf(Creature::updatePosition);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final MovementTaskManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final MovementTaskManager INSTANCE = new MovementTaskManager();
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ public class FloodProtectorAction
|
||||
/**
|
||||
* Next game tick when new request is allowed.
|
||||
*/
|
||||
private volatile int _nextGameTick = GameTimeTaskManager.getGameTicks();
|
||||
private volatile int _nextGameTick = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
/**
|
||||
* Request counter.
|
||||
*/
|
||||
@ -84,7 +84,7 @@ public class FloodProtectorAction
|
||||
return true;
|
||||
}
|
||||
|
||||
final int curTick = GameTimeTaskManager.getGameTicks();
|
||||
final int curTick = GameTimeTaskManager.getInstance().getGameTicks();
|
||||
if ((curTick < _nextGameTick) || _punishmentInProgress)
|
||||
{
|
||||
if (_config.LOG_FLOODING && !_logged && LOGGER.isLoggable(Level.WARNING))
|
||||
|
Reference in New Issue
Block a user