Skip to content

Commit d31f41a

Browse files
authored
[Game] The elevator's correct operation has been restored: (AAEmu#1302)
* [Game] The elevator's correct operation has been restored: - The elevator now stops at all floors again. * Corrected the name of the variable.
1 parent 24768bd commit d31f41a

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

AAEmu.Game/Models/Game/Gimmicks/Gimmick.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Numerics;
2+
23
using AAEmu.Commons.Network;
34
using AAEmu.Commons.Utils;
45
using AAEmu.Game.Core.Managers;
@@ -32,15 +33,16 @@ public class Gimmick : Unit
3233
/// MoveZ
3334
/// </summary>
3435
public bool MoveDown { get; set; }
36+
public bool IsMoving { get; set; }
3537
public DateTime WaitTime { get; set; }
3638
public uint TimeLeft => WaitTime > DateTime.UtcNow ? (uint)(WaitTime - DateTime.UtcNow).TotalMilliseconds : 0;
3739
public TimeSpan TotalLifeTime { get; set; } = TimeSpan.Zero;
3840
private TimeSpan LastLifeTime { get; set; } = TimeSpan.Zero;
39-
private Vector3 LastPos { get; set; } = Vector3.Zero;
40-
private Vector3 LastRot { get; set; } = Vector3.Zero;
41+
internal Vector3 LastPos { get; set; } = Vector3.Zero;
42+
internal Vector3 LastRot { get; set; } = Vector3.Zero;
4143
private bool SkillStarted { get; set; }
4244
// ReSharper disable once ChangeFieldTypeToSystemThreadingLock
43-
private readonly object _skillStartedLock = new();
45+
private readonly object _skillStartedLock = new();
4446
public GimmickMovementHandler MovementHandler { get; set; }
4547

4648
public void SetScale(float scale)
@@ -130,7 +132,7 @@ public void StopMovement()
130132
return;
131133
DoGimmickSkill(Template?.SkillId ?? 0);
132134
}
133-
135+
134136
public override void AddVisibleObject(Character character)
135137
{
136138
character.SendPacket(new SCGimmicksCreatedPacket([this]));
@@ -177,41 +179,41 @@ private void DoGimmickSkill(uint skillId)
177179
TaskManager.Instance.Schedule(new UseSkillTask(useSkill, caster, skillCaster, this, skillCastTarget, skillObject), TimeSpan.FromMilliseconds(0));
178180
// var skill = new Skill(SkillManager.Instance.GetSkillTemplate(skillId));
179181
// var skillResult = skill.Use(caster, skillCaster, skillCastTarget, null, true, out _);
180-
182+
181183
BroadcastPacket(new SCChatMessagePacket(ChatType.System, $"Gimmick {ObjId} used skill {skillId}"), false);
182184
}
183-
185+
184186
public void GimmickTick(TimeSpan delta)
185187
{
186188
LastLifeTime = TotalLifeTime;
187189
TotalLifeTime += delta;
188190
if (TimeLeft > 0)
189191
return;
190-
192+
191193
MovementHandler?.Tick(delta);
192-
194+
193195
// Handle Delayed Skills
194196
if ((Template?.SkillDelay > 0) && (!SkillStarted) && (LastLifeTime.TotalMilliseconds < Template.SkillDelay) && (TotalLifeTime.TotalMilliseconds >= Template.SkillDelay))
195197
{
196198
DoGimmickSkill(Template.SkillId);
197199
}
198-
200+
199201
// TODO: Skill on collision (requires physics engine rewrite)
200202

201203
var deltaTime = (float)delta.TotalSeconds;
202204
var deltaPosition = Transform.World.Position - LastPos;
203205
Vel = deltaPosition * deltaTime;
204206
AngVel = new Vector3(0f, 0f, 0f);
205-
207+
206208
// Time += (uint)delta.Milliseconds;
207209
Time = (uint)(DateTime.UtcNow - DateTime.UtcNow.Date).TotalMilliseconds;
208210

209211
BroadcastPacket(new SCGimmickMovementPacket(this), false);
210-
212+
211213
LastPos = Transform.World.Position;
212214
LastRot = Transform.World.Rotation;
213215

214-
MovementHandler?.AfterMove(delta, deltaPosition);
216+
MovementHandler?.AfterMove(delta, deltaPosition);
215217

216218
// Check LifeTime and apply despawn time if needed
217219
if ((Template?.LifeTime > 0) && (Despawn <= DateTime.MinValue) && (TotalLifeTime.TotalMilliseconds >= Template.LifeTime))// && (LastLifeTime.TotalMilliseconds < Template.LifeTime))
@@ -241,11 +243,13 @@ public void MoveAlongZAxis(Gimmick gimmick, ref Vector3 position, Vector3 target
241243
{
242244
position.Z += movingDistance;
243245
gimmick.Vel = gimmick.Vel with { Z = velocityZ };
246+
gimmick.IsMoving = true;
244247
}
245248
else
246249
{
247250
position.Z = target.Z;
248251
gimmick.Vel = Vector3.Zero;
252+
gimmick.IsMoving = false;
249253
}
250254
}
251255
}

AAEmu.Game/Models/Game/Gimmicks/GimmickMovementElevator.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public override void Tick(TimeSpan delta)
2828
if (position.Z < owner.Spawner.MiddleZ && owner.Vel.Z >= 0 && !isMovingDown)
2929
owner.MoveAlongZAxis(owner, ref position, middleTarget, MaxVelocity, deltaTime, ref velocityZ, ref isMovingDown);
3030
else if (position.Z < owner.Spawner.TopZ && owner.Vel.Z >= 0 && !isMovingDown)
31-
owner.MoveAlongZAxis(owner, ref position, topTarget, MaxVelocity, deltaTime, ref velocityZ,
32-
ref isMovingDown);
31+
owner.MoveAlongZAxis(owner, ref position, topTarget, MaxVelocity, deltaTime, ref velocityZ, ref isMovingDown);
3332
else if (position.Z > owner.Spawner.MiddleZ && owner.Vel.Z <= 0 && isMovingDown)
3433
owner.MoveAlongZAxis(owner, ref position, middleTarget, MaxVelocity, deltaTime, ref velocityZ, ref isMovingDown);
3534
else
@@ -38,8 +37,7 @@ public override void Tick(TimeSpan delta)
3837
else
3938
{
4039
if (position.Z < owner.Spawner.TopZ && owner.Vel.Z >= 0)
41-
owner.MoveAlongZAxis(owner, ref position, topTarget, MaxVelocity, deltaTime, ref velocityZ,
42-
ref isMovingDown);
40+
owner.MoveAlongZAxis(owner, ref position, topTarget, MaxVelocity, deltaTime, ref velocityZ, ref isMovingDown);
4341
else
4442
owner.MoveAlongZAxis(owner, ref position, bottomTarget, MaxVelocity, deltaTime, ref velocityZ, ref isMovingDown);
4543
}
@@ -50,12 +48,17 @@ public override void Tick(TimeSpan delta)
5048
public override void AfterMove(TimeSpan delta, Vector3 deltaPosition)
5149
{
5250
base.AfterMove(delta, deltaPosition);
53-
if (deltaPosition.Length() > 0.01f)
51+
if (owner.IsMoving)
5452
{
5553
return;
5654
}
5755

5856
owner.WaitTime = DateTime.UtcNow.AddSeconds(owner.Spawner.WaitTime);
59-
owner.MoveDown = !owner.MoveDown;
57+
if (owner.LastPos.Z > owner.Spawner.BottomZ && owner.MoveDown)
58+
owner.MoveDown = true;
59+
else if (owner.LastPos.Z < owner.Spawner.TopZ && !owner.MoveDown)
60+
owner.MoveDown = false;
61+
else
62+
owner.MoveDown = !owner.MoveDown;
6063
}
6164
}

0 commit comments

Comments
 (0)