feat(client): add current world

This commit is contained in:
Anna 2023-10-05 00:40:08 -04:00
parent bd334442b5
commit 805b8ac861
Signed by: anna
GPG Key ID: D0943384CD9F87D1
2 changed files with 22 additions and 2 deletions

12
client/ListExt.cs Normal file
View File

@ -0,0 +1,12 @@
namespace PlayerMap;
internal static class ListExt {
public static void Shuffle<T>(this IList<T> list) {
var n = list.Count;
while (n > 1) {
n--;
var k = Random.Shared.Next(n + 1);
(list[k], list[n]) = (list[n], list[k]);
}
}
}

View File

@ -53,7 +53,14 @@ public class Plugin : IDalamudPlugin {
})
.ToList();
var update = new Update(territory, players);
if (players.Count == 0 || this.ClientState.LocalPlayer is not { } player) {
return;
}
// shuffle so first player isn't always local player
players.Shuffle();
var update = new Update(territory, player.CurrentWorld.Id, players);
var json = JsonConvert.SerializeObject(update, new JsonSerializerSettings {
ContractResolver = new DefaultContractResolver {
NamingStrategy = new SnakeCaseNamingStrategy(),
@ -73,8 +80,9 @@ public class Plugin : IDalamudPlugin {
}
[Serializable]
internal struct Update(uint territory, List<PlayerInfo> players) {
internal struct Update(uint territory, uint world, List<PlayerInfo> players) {
public readonly uint Territory = territory;
public readonly uint World = world;
public readonly List<PlayerInfo> Players = players;
}