Skip to content

Commit 5ea1284

Browse files
committed
add some events
1 parent 718342d commit 5ea1284

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

TaleKit/Game/Animation/EffectEvent.cs renamed to TaleKit/Game/Event/Animations/EffectEvent.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using TaleKit.Game.Entities;
2-
using TaleKit.Game.Event;
32

4-
namespace TaleKit.Game.Animation;
3+
namespace TaleKit.Game.Event.Animations;
54

65
public class EffectEvent : IEvent
76
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace TaleKit.Game.Event.Characters;
2+
3+
public class PositionChangedEvent : IEvent
4+
{
5+
public Position From { get; init; }
6+
public Position To { get; init; }
7+
8+
public Session Session { get; init; }
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using TaleKit.Game.Entities;
2+
3+
namespace TaleKit.Game.Event.Entities;
4+
5+
public class EntityMovedEvent : IEvent
6+
{
7+
public Session Session { get; init; }
8+
public LivingEntity Entity { get; init; }
9+
public Position From { get; init; }
10+
public Position To { get; init; }
11+
}

TaleKit/Network/Packet/Animation/Eff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using TaleKit.Extension;
22
using TaleKit.Game;
3-
using TaleKit.Game.Animation;
43
using TaleKit.Game.Entities;
4+
using TaleKit.Game.Event.Animations;
55

66
namespace TaleKit.Network.Packet.Animation;
77

TaleKit/Network/Packet/Characters/Walk.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using TaleKit.Extension;
22
using TaleKit.Game;
3+
using TaleKit.Game.Event.Characters;
4+
using TaleKit.Game.Event.Entities;
35

46
namespace TaleKit.Network.Packet.Characters;
57

@@ -38,13 +40,22 @@ protected override void Process(Session session, Walk packet)
3840
Y = packet.Y
3941
});
4042

43+
var from = session.Character.Position;
44+
4145
Task.Delay(distance * 200).Then(() =>
4246
{
4347
session.Character.Position = new Position
4448
{
4549
X = packet.X,
4650
Y = packet.Y
4751
};
52+
53+
session.Emit(new PositionChangedEvent
54+
{
55+
Session = session,
56+
From = from,
57+
To = session.Character.Position
58+
});
4859
});
4960
}
5061
}

TaleKit/Network/Packet/Entities/Mv.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using TaleKit.Extension;
22
using TaleKit.Game;
33
using TaleKit.Game.Entities;
4+
using TaleKit.Game.Event.Entities;
45

56
namespace TaleKit.Network.Packet.Entities;
67

@@ -46,6 +47,15 @@ protected override void Process(Session session, Mv packet)
4647
return;
4748
}
4849

50+
var from = entity.Position;
4951
entity.Position = new Position(packet.X, packet.Y);
52+
53+
session.Emit(new EntityMovedEvent
54+
{
55+
Session = session,
56+
Entity = entity,
57+
From = from,
58+
To = entity.Position
59+
});
5060
}
5161
}

0 commit comments

Comments
 (0)