|
1 | 1 | using System.Numerics; |
| 2 | + |
2 | 3 | using AAEmu.Commons.Network; |
3 | 4 | using AAEmu.Commons.Utils; |
4 | 5 | using AAEmu.Game.Core.Managers; |
@@ -32,15 +33,16 @@ public class Gimmick : Unit |
32 | 33 | /// MoveZ |
33 | 34 | /// </summary> |
34 | 35 | public bool MoveDown { get; set; } |
| 36 | + public bool IsMoving { get; set; } |
35 | 37 | public DateTime WaitTime { get; set; } |
36 | 38 | public uint TimeLeft => WaitTime > DateTime.UtcNow ? (uint)(WaitTime - DateTime.UtcNow).TotalMilliseconds : 0; |
37 | 39 | public TimeSpan TotalLifeTime { get; set; } = TimeSpan.Zero; |
38 | 40 | 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; |
41 | 43 | private bool SkillStarted { get; set; } |
42 | 44 | // ReSharper disable once ChangeFieldTypeToSystemThreadingLock |
43 | | - private readonly object _skillStartedLock = new(); |
| 45 | + private readonly object _skillStartedLock = new(); |
44 | 46 | public GimmickMovementHandler MovementHandler { get; set; } |
45 | 47 |
|
46 | 48 | public void SetScale(float scale) |
@@ -130,7 +132,7 @@ public void StopMovement() |
130 | 132 | return; |
131 | 133 | DoGimmickSkill(Template?.SkillId ?? 0); |
132 | 134 | } |
133 | | - |
| 135 | + |
134 | 136 | public override void AddVisibleObject(Character character) |
135 | 137 | { |
136 | 138 | character.SendPacket(new SCGimmicksCreatedPacket([this])); |
@@ -177,41 +179,41 @@ private void DoGimmickSkill(uint skillId) |
177 | 179 | TaskManager.Instance.Schedule(new UseSkillTask(useSkill, caster, skillCaster, this, skillCastTarget, skillObject), TimeSpan.FromMilliseconds(0)); |
178 | 180 | // var skill = new Skill(SkillManager.Instance.GetSkillTemplate(skillId)); |
179 | 181 | // var skillResult = skill.Use(caster, skillCaster, skillCastTarget, null, true, out _); |
180 | | - |
| 182 | + |
181 | 183 | BroadcastPacket(new SCChatMessagePacket(ChatType.System, $"Gimmick {ObjId} used skill {skillId}"), false); |
182 | 184 | } |
183 | | - |
| 185 | + |
184 | 186 | public void GimmickTick(TimeSpan delta) |
185 | 187 | { |
186 | 188 | LastLifeTime = TotalLifeTime; |
187 | 189 | TotalLifeTime += delta; |
188 | 190 | if (TimeLeft > 0) |
189 | 191 | return; |
190 | | - |
| 192 | + |
191 | 193 | MovementHandler?.Tick(delta); |
192 | | - |
| 194 | + |
193 | 195 | // Handle Delayed Skills |
194 | 196 | if ((Template?.SkillDelay > 0) && (!SkillStarted) && (LastLifeTime.TotalMilliseconds < Template.SkillDelay) && (TotalLifeTime.TotalMilliseconds >= Template.SkillDelay)) |
195 | 197 | { |
196 | 198 | DoGimmickSkill(Template.SkillId); |
197 | 199 | } |
198 | | - |
| 200 | + |
199 | 201 | // TODO: Skill on collision (requires physics engine rewrite) |
200 | 202 |
|
201 | 203 | var deltaTime = (float)delta.TotalSeconds; |
202 | 204 | var deltaPosition = Transform.World.Position - LastPos; |
203 | 205 | Vel = deltaPosition * deltaTime; |
204 | 206 | AngVel = new Vector3(0f, 0f, 0f); |
205 | | - |
| 207 | + |
206 | 208 | // Time += (uint)delta.Milliseconds; |
207 | 209 | Time = (uint)(DateTime.UtcNow - DateTime.UtcNow.Date).TotalMilliseconds; |
208 | 210 |
|
209 | 211 | BroadcastPacket(new SCGimmickMovementPacket(this), false); |
210 | | - |
| 212 | + |
211 | 213 | LastPos = Transform.World.Position; |
212 | 214 | LastRot = Transform.World.Rotation; |
213 | 215 |
|
214 | | - MovementHandler?.AfterMove(delta, deltaPosition); |
| 216 | + MovementHandler?.AfterMove(delta, deltaPosition); |
215 | 217 |
|
216 | 218 | // Check LifeTime and apply despawn time if needed |
217 | 219 | 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 |
241 | 243 | { |
242 | 244 | position.Z += movingDistance; |
243 | 245 | gimmick.Vel = gimmick.Vel with { Z = velocityZ }; |
| 246 | + gimmick.IsMoving = true; |
244 | 247 | } |
245 | 248 | else |
246 | 249 | { |
247 | 250 | position.Z = target.Z; |
248 | 251 | gimmick.Vel = Vector3.Zero; |
| 252 | + gimmick.IsMoving = false; |
249 | 253 | } |
250 | 254 | } |
251 | 255 | } |
0 commit comments