blob: 00eaf82e8697b4e6deab848b6d1716b2190b4d1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using System.Numerics;
using LiteNetLib.Utils;
using OnekoOnline.Net;
using Raylib_cs;
namespace OnekoOnline;
class OnekoLocal : Oneko
{
public static Oneko? Instance;
static int Id => OnekoOnline.Client?.Id ?? -1;
public OnekoLocal() : base()
{
Instance ??= this;
Client.UserConnected += OnekoNet.SpawnNetNeko;
Name = Client.UserName;
}
public override void OnekoUpdate()
{
Mouse? NearestMouse = Mouse.AllMice.Where(m => m.Visible).MinBy(m => Vector2.Distance(m.Position, Position));
if (NearestMouse != null) TargetPosition = NearestMouse.Position;
else TargetPosition = new Vector2(Math.Clamp((Id+1)*40, 20, 300), 240/2);
if (OnekoOnline.Client!.Connected) {
NetDataWriter writer = new();
writer.Put(new PacketInfo(PacketType.OnekoTargetPosition, Id));
writer.Put(TargetPosition);
OnekoOnline.Client?.ConnectedServer.Send(writer, LiteNetLib.DeliveryMethod.Unreliable);
}
base.OnekoUpdate();
}
}
|