feat: make roleplaying status work as expected

Sort of. Only if it's the primary online status.
This commit is contained in:
Anna 2021-03-14 18:39:42 -04:00
parent 4289428548
commit dbc5fb1600
1 changed files with 17 additions and 11 deletions

View File

@ -17,9 +17,12 @@ namespace HUD_Manager {
private readonly Dictionary<Status, bool> _condition = new(); private readonly Dictionary<Status, bool> _condition = new();
private ClassJob? _job; private ClassJob? _job;
internal static byte GetStatus(DalamudPluginInterface pi, Actor actor) { internal static byte GetStatus(Actor actor) {
var statusPtr = pi.TargetModuleScanner.ResolveRelativeAddress(actor.Address, 0x1980); return Marshal.ReadByte(actor.Address + 0x1980);
return Marshal.ReadByte(statusPtr); }
internal static byte GetOnlineStatus(Actor actor) {
return Marshal.ReadByte(actor.Address + 0x195F);
} }
public Statuses(Plugin plugin) { public Statuses(Plugin plugin) {
@ -37,6 +40,7 @@ namespace HUD_Manager {
if (this._job != null && this._job != currentJob) { if (this._job != null && this._job != currentJob) {
anyChanged = true; anyChanged = true;
} }
this._job = currentJob; this._job = currentJob;
foreach (Status status in Enum.GetValues(typeof(Status))) { foreach (Status status in Enum.GetValues(typeof(Status))) {
@ -73,9 +77,11 @@ namespace HUD_Manager {
if (layoutId == Guid.Empty) { if (layoutId == Guid.Empty) {
return; // FIXME: do something better return; // FIXME: do something better
} }
if (!this.Plugin.Config.Layouts.TryGetValue(layoutId, out var layout)) { if (!this.Plugin.Config.Layouts.TryGetValue(layoutId, out var layout)) {
return; // FIXME: do something better return; // FIXME: do something better
} }
this.Plugin.Hud.WriteEffectiveLayout(this.Plugin.Config.StagingSlot, layoutId); this.Plugin.Hud.WriteEffectiveLayout(this.Plugin.Config.StagingSlot, layoutId);
this.Plugin.Hud.SelectSlot(this.Plugin.Config.StagingSlot, true); this.Plugin.Hud.SelectSlot(this.Plugin.Config.StagingSlot, true);
@ -101,12 +107,12 @@ namespace HUD_Manager {
// Note: Changing the names of these is a breaking change // Note: Changing the names of these is a breaking change
public enum Status { public enum Status {
InCombat = ConditionFlag.InCombat, InCombat = ConditionFlag.InCombat,
WeaponDrawn = ConditionFlag.None, WeaponDrawn = -1,
InInstance = ConditionFlag.BoundByDuty, InInstance = ConditionFlag.BoundByDuty,
Crafting = ConditionFlag.Crafting, Crafting = ConditionFlag.Crafting,
Gathering = ConditionFlag.Gathering, Gathering = ConditionFlag.Gathering,
Fishing = ConditionFlag.Fishing, Fishing = ConditionFlag.Fishing,
Roleplaying = ConditionFlag.RolePlaying, Roleplaying = -2,
} }
public static class StatusExtensions { public static class StatusExtensions {
@ -135,19 +141,19 @@ namespace HUD_Manager {
if (player == null) { if (player == null) {
throw new ArgumentNullException(nameof(player), "PlayerCharacter cannot be null"); throw new ArgumentNullException(nameof(player), "PlayerCharacter cannot be null");
} }
if (pi == null) {
throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
}
var flag = (ConditionFlag)status; if (status > 0) {
if (flag != ConditionFlag.None) { var flag = (ConditionFlag) status;
return pi.ClientState.Condition[flag]; return pi.ClientState.Condition[flag];
} }
switch (status) { switch (status) {
case Status.WeaponDrawn: case Status.WeaponDrawn:
return (Statuses.GetStatus(pi, player) & 4) > 0; return (Statuses.GetStatus(player) & 4) > 0;
case Status.Roleplaying:
return Statuses.GetOnlineStatus(player) == 22;
} }
return false; return false;
} }
} }