Dalamud/Dalamud/Game/ClientState/Party/PartyMember.cs
Haselnussbomber c93f04f0e4
Code cleanup (#2439)
* Use new Lock objects

* Fix CA1513: Use ObjectDisposedException.ThrowIf

* Fix CA1860: Avoid using 'Enumerable.Any()' extension method

* Fix IDE0028: Use collection initializers or expressions

* Fix CA2263: Prefer generic overload when type is known

* Fix CA1862: Use the 'StringComparison' method overloads to perform case-insensitive string comparisons

* Fix IDE0270: Null check can be simplified

* Fix IDE0280: Use 'nameof'

* Fix IDE0009: Add '.this'

* Fix IDE0007: Use 'var' instead of explicit type

* Fix IDE0062: Make local function static

* Fix CA1859: Use concrete types when possible for improved performance

* Fix IDE0066: Use switch expression

Only applied to where it doesn't look horrendous.

* Use is over switch

* Fix CA1847: Use String.Contains(char) instead of String.Contains(string) with single characters

* Fix SYSLIB1045: Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time.

* Fix CA1866: Use 'string.EndsWith(char)' instead of 'string.EndsWith(string)' when you have a string with a single char

* Fix IDE0057: Substring can be simplified

* Fix IDE0059: Remove unnecessary value assignment

* Fix CA1510: Use ArgumentNullException throw helper

* Fix IDE0300: Use collection expression for array

* Fix IDE0250: Struct can be made 'readonly'

* Fix IDE0018: Inline variable declaration

* Fix CA1850: Prefer static HashData method over ComputeHash

* Fi CA1872: Prefer 'Convert.ToHexString' and 'Convert.ToHexStringLower' over call chains based on 'BitConverter.ToString'

* Update ModuleLog instantiations

* Organize usings
2026-01-06 08:36:55 -08:00

192 lines
5 KiB
C#

using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Dalamud.Data;
using Dalamud.Game.ClientState.Objects;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Game.ClientState.Statuses;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Utility;
using Lumina.Excel;
using CSPartyMember = FFXIVClientStructs.FFXIV.Client.Game.Group.PartyMember;
namespace Dalamud.Game.ClientState.Party;
/// <summary>
/// Interface representing a party member.
/// </summary>
public interface IPartyMember : IEquatable<IPartyMember>
{
/// <summary>
/// Gets the address of this party member in memory.
/// </summary>
nint Address { get; }
/// <summary>
/// Gets a list of buffs or debuffs applied to this party member.
/// </summary>
StatusList Statuses { get; }
/// <summary>
/// Gets the position of the party member.
/// </summary>
Vector3 Position { get; }
/// <summary>
/// Gets the content ID of the party member.
/// </summary>
long ContentId { get; }
/// <summary>
/// Gets the actor ID of this party member.
/// </summary>
[Obsolete("Renamed to EntityId")]
uint ObjectId { get; }
/// <summary>
/// Gets the entity ID of this party member.
/// </summary>
uint EntityId { get; }
/// <summary>
/// Gets the actor associated with this buddy.
/// </summary>
/// <remarks>
/// This iterates the actor table, it should be used with care.
/// </remarks>
IGameObject? GameObject { get; }
/// <summary>
/// Gets the current HP of this party member.
/// </summary>
uint CurrentHP { get; }
/// <summary>
/// Gets the maximum HP of this party member.
/// </summary>
uint MaxHP { get; }
/// <summary>
/// Gets the current MP of this party member.
/// </summary>
ushort CurrentMP { get; }
/// <summary>
/// Gets the maximum MP of this party member.
/// </summary>
ushort MaxMP { get; }
/// <summary>
/// Gets the territory this party member is located in.
/// </summary>
RowRef<Lumina.Excel.Sheets.TerritoryType> Territory { get; }
/// <summary>
/// Gets the World this party member resides in.
/// </summary>
RowRef<Lumina.Excel.Sheets.World> World { get; }
/// <summary>
/// Gets the displayname of this party member.
/// </summary>
SeString Name { get; }
/// <summary>
/// Gets the sex of this party member.
/// </summary>
byte Sex { get; }
/// <summary>
/// Gets the classjob of this party member.
/// </summary>
RowRef<Lumina.Excel.Sheets.ClassJob> ClassJob { get; }
/// <summary>
/// Gets the level of this party member.
/// </summary>
byte Level { get; }
}
/// <summary>
/// This struct represents a party member in the group manager.
/// </summary>
/// <param name="ptr">A pointer to the PartyMember.</param>
internal unsafe readonly struct PartyMember(CSPartyMember* ptr) : IPartyMember
{
/// <inheritdoc/>
public nint Address => (nint)ptr;
/// <inheritdoc/>
public StatusList Statuses => new(&ptr->StatusManager);
/// <inheritdoc/>
public Vector3 Position => ptr->Position;
/// <inheritdoc/>
[Api15ToDo("Change type to ulong.")]
public long ContentId => (long)ptr->ContentId;
/// <inheritdoc/>
public uint ObjectId => ptr->EntityId;
/// <inheritdoc/>
public uint EntityId => ptr->EntityId;
/// <inheritdoc/>
public IGameObject? GameObject => Service<ObjectTable>.Get().SearchById(this.EntityId);
/// <inheritdoc/>
public uint CurrentHP => ptr->CurrentHP;
/// <inheritdoc/>
public uint MaxHP => ptr->MaxHP;
/// <inheritdoc/>
public ushort CurrentMP => ptr->CurrentMP;
/// <inheritdoc/>
public ushort MaxMP => ptr->MaxMP;
/// <inheritdoc/>
public RowRef<Lumina.Excel.Sheets.TerritoryType> Territory => LuminaUtils.CreateRef<Lumina.Excel.Sheets.TerritoryType>(ptr->TerritoryType);
/// <inheritdoc/>
public RowRef<Lumina.Excel.Sheets.World> World => LuminaUtils.CreateRef<Lumina.Excel.Sheets.World>(ptr->HomeWorld);
/// <inheritdoc/>
public SeString Name => SeString.Parse(ptr->Name);
/// <inheritdoc/>
public byte Sex => ptr->Sex;
/// <inheritdoc/>
public RowRef<Lumina.Excel.Sheets.ClassJob> ClassJob => LuminaUtils.CreateRef<Lumina.Excel.Sheets.ClassJob>(ptr->ClassJob);
/// <inheritdoc/>
public byte Level => ptr->Level;
public static bool operator ==(PartyMember x, PartyMember y) => x.Equals(y);
public static bool operator !=(PartyMember x, PartyMember y) => !(x == y);
/// <inheritdoc/>
public bool Equals(IPartyMember? other)
{
return this.EntityId == other.EntityId;
}
/// <inheritdoc/>
public override bool Equals([NotNullWhen(true)] object? obj)
{
return obj is PartyMember fate && this.Equals(fate);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return this.EntityId.GetHashCode();
}
}