generated from goatcorp/SamplePlugin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop using Hunt Helper to detect A ranks and do it ourselves (#38)
* Use object table to look for marks ourself Submit found marks to turtle
- Loading branch information
Showing
5 changed files
with
176 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using CSharpFunctionalExtensions; | ||
using System; | ||
using System.Collections.Generic; | ||
using Dalamud.Plugin; | ||
using Dalamud.Plugin.Services; | ||
using Dalamud.Game.ClientState.Objects.Types; | ||
using XIVHuntUtils.Models; | ||
using System.Linq; | ||
using System.Numerics; | ||
using FFXIVClientStructs.FFXIV.Client.Game.UI; | ||
using static XIVHuntUtils.Utils.XivUtils; | ||
using Lumina.Excel.Sheets; | ||
|
||
namespace ScoutHelper.Managers; | ||
|
||
using MobDict = IDictionary<uint, (Patch patch, uint turtleMobId)>; | ||
|
||
public class HuntMarkManager : IDisposable { | ||
private static readonly TimeSpan ExecDelay = TimeSpan.FromSeconds(1); | ||
|
||
private readonly IFramework _framework; | ||
private readonly IObjectTable _objectTable; | ||
private readonly IClientState _clientState; | ||
private readonly IPluginLog _log; | ||
private readonly IChatGui _chat; | ||
|
||
private TimeSpan _lastUpdate = TimeSpan.FromSeconds(0); | ||
|
||
private List<uint> _ARankbNPCIds = new(); | ||
private List<uint> _sentARankIds = new(); | ||
|
||
public event Action<ScoutHelper.Models.TrainMob>? OnMarkFound; | ||
|
||
public HuntMarkManager( | ||
IFramework framework, | ||
IPluginLog log, | ||
IChatGui chat, | ||
IClientState clientState, | ||
IObjectTable objectTable | ||
) { | ||
_framework = framework; | ||
_log = log; | ||
_chat = chat; | ||
_clientState = clientState; | ||
_objectTable = objectTable; | ||
} | ||
|
||
private bool IsHWTerritory(uint territoryId) { | ||
//EVERYTHING EXCEPT HEAVENSWARD HAS A SCALE OF 100, BUT FOR SOME REASON HW HAS 95 | ||
if (territoryId is >= 397 and <= 402) return true; | ||
return false; | ||
} | ||
|
||
private unsafe uint GetCurrentInstance() { | ||
return UIState.Instance()->PublicInstance.InstanceId; | ||
} | ||
|
||
private void CheckObjectTable() { | ||
foreach (var obj in _objectTable) { | ||
if (obj is not IBattleNpc mob) continue; | ||
var battlenpc = mob as IBattleNpc; | ||
|
||
if (_ARankbNPCIds.Contains(battlenpc.NameId)) { | ||
if (_sentARankIds.Contains(battlenpc.NameId)) { | ||
//_log.Debug($"Got that A already..."); | ||
continue; | ||
} | ||
var trainMob = new ScoutHelper.Models.TrainMob(); | ||
|
||
trainMob.Name = battlenpc.Name.ToString(); | ||
trainMob.MobId = battlenpc.NameId; | ||
trainMob.TerritoryId = _clientState.TerritoryType; | ||
//trainMob.MapId = | ||
trainMob.Instance = GetCurrentInstance(); | ||
trainMob.Position = XIVHuntUtils.Utils.XivUtils.AsMapPosition( | ||
new Vector2(battlenpc.Position.X, battlenpc.Position.Z), | ||
IsHWTerritory(trainMob.TerritoryId) | ||
); | ||
trainMob.Dead = battlenpc.IsDead; | ||
//trainMob.LastSeenUtc = | ||
_log.Debug( | ||
$"I spy with my little eye: {trainMob.Name} ({trainMob.MobId}) in {trainMob.TerritoryId} i{trainMob.Instance} @{trainMob.Position} Dead?{trainMob.Dead}" | ||
); | ||
OnMarkFound?.Invoke(trainMob); | ||
_sentARankIds.Add(trainMob.MobId); | ||
} | ||
} | ||
} | ||
|
||
private void Tick(IFramework framework) { | ||
_lastUpdate += framework.UpdateDelta; | ||
if (_lastUpdate > ExecDelay) { | ||
DoUpdate(framework); | ||
_lastUpdate = new(0); | ||
} | ||
} | ||
|
||
private void DoUpdate(IFramework framework) { | ||
CheckObjectTable(); | ||
} | ||
|
||
public void StartLooking(MobDict mobIdToTurtleId) { | ||
_log.Debug("HuntMarkManager: Start looking for Ranks"); | ||
_ARankbNPCIds = mobIdToTurtleId.Keys.ToList(); | ||
_sentARankIds = new(); | ||
_framework.Update += Tick; | ||
} | ||
|
||
public void StopLooking() { | ||
_log.Debug("HuntMarkManager: Stop looking for Ranks"); | ||
_framework.Update -= Tick; | ||
} | ||
|
||
public void Dispose() { | ||
_framework.Update -= Tick; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters