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

@@ -309,9 +309,11 @@ public class CreatureAI extends AbstractAI
return;
}
if (_actor.getBowAttackEndTime() > GameTimeTaskManager.getInstance().getGameTicks())
final int gameTime = GameTimeTaskManager.getInstance().getGameTicks();
final int bowAttackEndTime = _actor.getBowAttackEndTime();
if (bowAttackEndTime > gameTime)
{
ThreadPool.schedule(new CastTask(_actor, skill, target), (_actor.getBowAttackEndTime() - GameTimeTaskManager.getInstance().getGameTicks()) * GameTimeTaskManager.MILLIS_IN_TICK);
ThreadPool.schedule(new CastTask(_actor, skill, target), (bowAttackEndTime - gameTime) * GameTimeTaskManager.MILLIS_IN_TICK);
}
else
{

View File

@@ -1054,6 +1054,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
final Attack attack = new Attack(this, target, isChargedShot(ShotType.SOULSHOTS), (weaponItem != null) ? weaponItem.getCrystalTypePlus().getLevel() : 0);
setHeading(Util.calculateHeadingFrom(this, target));
final int reuse = calculateReuseTime(weaponItem);
final long currentTime = System.nanoTime();
boolean hitted = false;
switch (getAttackType())
{
@@ -1063,13 +1064,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
_attackEndTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeToHit + (reuse / 2), TimeUnit.MILLISECONDS);
_attackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(timeToHit + (reuse / 2));
hitted = doAttackHitByBow(attack, target, timeAtk, reuse);
break;
}
case POLE:
{
_attackEndTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeAtk, TimeUnit.MILLISECONDS);
_attackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(timeAtk);
hitted = doAttackHitByPole(attack, target, timeToHit);
break;
}
@@ -1077,7 +1078,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (!isPlayer())
{
_attackEndTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeAtk, TimeUnit.MILLISECONDS);
_attackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(timeAtk);
hitted = doAttackHitSimple(attack, target, timeToHit);
break;
}
@@ -1087,18 +1088,24 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
case DUALFIST:
case DUALDAGGER:
{
_attackEndTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeAtk, TimeUnit.MILLISECONDS);
_attackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(timeAtk);
hitted = doAttackHitByDual(attack, target, timeToHit);
break;
}
default:
{
_attackEndTime = System.nanoTime() + TimeUnit.NANOSECONDS.convert(timeAtk, TimeUnit.MILLISECONDS);
_attackEndTime = currentTime + TimeUnit.MILLISECONDS.toNanos(timeAtk);
hitted = doAttackHitSimple(attack, target, timeToHit);
break;
}
}
// 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);
}
if (isFakePlayer() && (target.isPlayable() || target.isFakePlayer()))
{
final Npc npc = ((Npc) this);
@@ -1226,7 +1233,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
ThreadPool.schedule(new HitTask(this, target, damage1, crit1, miss1, shld1, attack.hasSoulshot(), true), sAtk);
// Calculate and set the disable delay of the bow in function of the Attack Speed
_disableBowAttackEndTime = ((sAtk + reuse) / GameTimeTaskManager.MILLIS_IN_TICK) + GameTimeTaskManager.getInstance().getGameTicks();
final int gameTime = GameTimeTaskManager.getInstance().getGameTicks();
_disableBowAttackEndTime = gameTime + ((sAtk + reuse) / GameTimeTaskManager.MILLIS_IN_TICK);
// Precaution. It happened in the past for _attackEndTime. Will not risk it.
if (_disableBowAttackEndTime < gameTime)
{
_disableBowAttackEndTime = Integer.MAX_VALUE;
}
// Add this hit to the Server-Client packet Attack
attack.addHit(target, damage1, miss1, crit1, shld1);
@@ -4124,13 +4137,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
}
/**
* 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>
@@ -4138,7 +4151,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>
@@ -4435,7 +4448,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);
@@ -4444,7 +4457,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()
@@ -4524,8 +4537,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

@@ -225,14 +225,18 @@ public class UseItem implements IClientIncomingPacket
// Binding next action to AI.
player.getAI().setNextAction(nextAction);
}
else if (player.isAttackingNow())
else // Equip or unEquip.
{
// Equip or unEquip.
ThreadPool.schedule(() -> player.useEquippableItem(item, false), TimeUnit.MILLISECONDS.convert(player.getAttackEndTime() - System.nanoTime(), TimeUnit.NANOSECONDS));
}
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