AttackEndTime rework and proper MovementTaskManager comments.

This commit is contained in:
MobiusDevelopment
2022-10-16 21:44:29 +00:00
parent 739e49bd8e
commit 8c4fff7541
83 changed files with 963 additions and 513 deletions

View File

@@ -310,9 +310,11 @@ public class CreatureAI extends AbstractAI
return;
}
if (_actor.isAttackingNow())
final long currentTime = System.nanoTime();
final long attackEndTime = _actor.getAttackEndTime();
if (attackEndTime > currentTime)
{
ThreadPool.schedule(new CastTask(_actor, skill, target, item, forceUse, dontMove), _actor.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
ThreadPool.schedule(new CastTask(_actor, skill, target, item, forceUse, dontMove), TimeUnit.NANOSECONDS.toMillis(attackEndTime - currentTime));
}
else
{

View File

@@ -1176,7 +1176,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
final boolean isTwoHanded = (weaponItem != null) && (weaponItem.getBodyPart() == ItemTemplate.SLOT_LR_HAND);
final int timeAtk = Formulas.calculateTimeBetweenAttacks(_stat.getPAtkSpd());
final int timeToHit = Formulas.calculateTimeToHit(timeAtk, weaponType, isTwoHanded, false);
_attackEndTime = System.nanoTime() + (TimeUnit.MILLISECONDS.toNanos(timeAtk));
final long currentTime = System.nanoTime();
_attackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(timeAtk);
// Precaution. It has happened in the past. Probably impossible to happen now, but will not risk it.
if (_attackEndTime < currentTime)
{
_attackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(Integer.MAX_VALUE);
}
// Make sure that char is facing selected target
// also works: setHeading(Util.convertDegreeToClientHeading(Util.calculateAngleFrom(this, target)));
@@ -1225,7 +1231,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
}
// Calculate and set the disable delay of the bow in function of the Attack Speed
_disableRangedAttackEndTime = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(reuse);
_disableRangedAttackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(reuse);
// Precaution. It happened in the past for _attackEndTime. Will not risk it.
if (_disableRangedAttackEndTime < currentTime)
{
_disableRangedAttackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(Integer.MAX_VALUE);
}
_hitTask = ThreadPool.schedule(() -> onHitTimeNotDual(weaponItem, attack, timeToHit, timeAtk), timeToHit);
break;
}
@@ -3345,13 +3356,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// called from AIAccessor only
/**
* Calculate movement data for a move to location action and add the Creature to movingObjects of GameTimeTaskManager (only called by AI Accessor).<br>
* Calculate movement data for a move to location action and add the Creature to MOVING_OBJECTS of MovementTaskManager (only called by AI Accessor).<br>
* <br>
* <b><u>Concept</u>:</b><br>
* <br>
* At the beginning of the move action, all properties of the movement are stored in the MoveData object called <b>_move</b> of the Creature.<br>
* The position of the start point and of the destination permit to estimated in function of the movement speed the time to achieve the destination.<br>
* All Creature in movement are identified in <b>movingObjects</b> of GameTimeTaskManager that will call the updatePosition method of those Creature each 0.1s.<br>
* All Creature in movement are identified in <b>MOVING_OBJECTS</b> of MovementTaskManager that will call the updatePosition method of those Creature each 0.1s.<br>
* <br>
* <b><u>Actions</u>:</b>
* <ul>
@@ -3359,7 +3370,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
* <li>Calculate distance (dx,dy) between current position and destination including offset</li>
* <li>Create and Init a MoveData object</li>
* <li>Set the Creature _move object to MoveData object</li>
* <li>Add the Creature to movingObjects of the GameTimeTaskManager</li>
* <li>Add the Creature to MOVING_OBJECTS of the MovementTaskManager</li>
* <li>Create a task to notify the AI that Creature arrives at a check point of the movement</li>
* </ul>
* <font color=#FF0000><b><u>Caution</u>: This method DOESN'T send Server->Client packet MoveToPawn/MoveToLocation.</b></font><br>
@@ -3665,7 +3676,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
ThreadPool.schedule(new NotifyAITask(this, CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
}
// the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive to destination by GameTimeTaskManager
// the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive to destination by MovementTaskManager
}
public boolean moveToNextRoutePoint()
@@ -3735,7 +3746,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Set the Creature _move object to MoveData object
_move = m;
// Add the Creature to moving objects of the GameTimeTaskManager.
// Add the Creature to moving objects of the MovementTaskManager.
// The MovementTaskManager manages object movement.
MovementTaskManager.getInstance().registerMovingObject(this);
@@ -3745,8 +3756,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
ThreadPool.schedule(new NotifyAITask(this, CtrlEvent.EVT_ARRIVED_REVALIDATE), 2000);
}
// the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive
// to destination by GameTimeTaskManager
// the CtrlEvent.EVT_ARRIVED will be sent when the character will actually arrive to destination by MovementTaskManager
// Send a Server->Client packet MoveToLocation to the actor and all Player in its _knownPlayers
broadcastMoveToLocation();

View File

@@ -267,14 +267,18 @@ public class UseItem implements IClientIncomingPacket
// Create and Bind the next action to the AI.
player.getAI().setNextAction(new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> player.useEquippableItem(item, true)));
}
else if (player.isAttackingNow())
else // Equip or unEquip.
{
// Equip or unEquip.
ThreadPool.schedule(() -> player.useEquippableItem(item, false), player.getAttackEndTime() - TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis()));
}
else
{
player.useEquippableItem(item, true);
final long currentTime = System.nanoTime();
final long attackEndTime = player.getAttackEndTime();
if (attackEndTime > currentTime)
{
ThreadPool.schedule(() -> player.useEquippableItem(item, false), TimeUnit.NANOSECONDS.toMillis(attackEndTime - currentTime));
}
else
{
player.useEquippableItem(item, true);
}
}
}
else