PeepingTom/Peeping Tom.Ipc/Targeter.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2021-08-23 03:33:57 +00:00
using System;
using System.Linq;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.Text.SeStringHandling;
2023-09-28 06:56:38 +00:00
using Dalamud.Plugin.Services;
2021-09-11 17:22:41 +00:00
using Newtonsoft.Json;
2021-08-23 03:33:57 +00:00
namespace PeepingTom.Ipc {
[Serializable]
public class Targeter {
2021-09-11 17:22:41 +00:00
[JsonConverter(typeof(SeStringConverter))]
2021-08-23 03:33:57 +00:00
public SeString Name { get; }
2024-07-02 01:30:54 +00:00
2021-08-23 03:33:57 +00:00
public uint HomeWorldId { get; }
2024-07-02 01:30:54 +00:00
public ulong GameObjectId { get; }
public uint EntityId { get; }
2021-08-23 03:33:57 +00:00
public DateTime When { get; }
2024-07-02 01:30:54 +00:00
public Targeter(IPlayerCharacter character) {
2021-08-23 03:33:57 +00:00
this.Name = character.Name;
this.HomeWorldId = character.HomeWorld.Id;
2024-07-02 01:30:54 +00:00
this.EntityId = character.EntityId;
this.GameObjectId = character.GameObjectId;
2021-08-23 03:33:57 +00:00
this.When = DateTime.UtcNow;
}
2021-09-11 17:22:41 +00:00
[JsonConstructor]
2024-07-02 01:30:54 +00:00
public Targeter(SeString name, uint homeWorldId, uint entityId, ulong gameObjectId, DateTime when) {
2021-09-11 17:22:41 +00:00
this.Name = name;
this.HomeWorldId = homeWorldId;
2024-07-02 01:30:54 +00:00
this.EntityId = entityId;
this.GameObjectId = gameObjectId;
2021-09-11 17:22:41 +00:00
this.When = when;
}
2024-07-02 01:30:54 +00:00
public IPlayerCharacter? GetPlayerCharacter(IObjectTable objectTable) {
return objectTable.FirstOrDefault(actor => actor.GameObjectId == this.GameObjectId && actor is IPlayerCharacter) as IPlayerCharacter;
2021-08-23 03:33:57 +00:00
}
}
}