Tourist/Tourist/Markers.cs

101 lines
3.1 KiB
C#
Raw Permalink Normal View History

2021-03-21 05:48:48 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
2023-09-28 06:05:06 +00:00
using Dalamud.Plugin.Services;
2021-03-21 05:48:48 +00:00
using Lumina.Excel.GeneratedSheets;
namespace Tourist {
public class Markers : IDisposable {
private const string MarkerPath = "bgcommon/world/common/vfx_for_live/eff/b0810_tnsk_y.avfx";
private Plugin Plugin { get; }
2023-04-05 04:19:41 +00:00
private Dictionary<uint, nint> Spawned { get; } = new();
private HashSet<nint> Queue { get; } = new();
2021-03-21 05:48:48 +00:00
public Markers(Plugin plugin) {
this.Plugin = plugin;
2021-08-23 06:36:41 +00:00
this.Plugin.ClientState.TerritoryChanged += this.OnTerritoryChange;
2021-08-24 00:39:28 +00:00
this.Plugin.Framework.Update += this.OnFrameworkUpdate;
2021-03-21 05:48:48 +00:00
if (this.Plugin.Config.ShowArrVistas) {
2021-08-23 06:36:41 +00:00
this.SpawnVfxForCurrentZone(this.Plugin.ClientState.TerritoryType);
2021-03-21 05:48:48 +00:00
}
}
public void Dispose() {
2021-08-24 00:39:28 +00:00
this.Plugin.Framework.Update -= this.OnFrameworkUpdate;
2021-08-23 06:36:41 +00:00
this.Plugin.ClientState.TerritoryChanged -= this.OnTerritoryChange;
2021-03-21 05:48:48 +00:00
this.RemoveAllVfx();
}
internal void RemoveVfx(ushort index) {
var adventure = this.Plugin.DataManager.GetExcelSheet<Adventure>()!
2021-03-21 05:48:48 +00:00
.Skip(index)
.First();
if (!this.Spawned.TryGetValue(adventure.RowId, out var vfx)) {
return;
}
this.Plugin.Functions.RemoveVfx(vfx);
this.Spawned.Remove(adventure.RowId);
}
internal void RemoveAllVfx() {
foreach (var vfx in this.Spawned.Values) {
this.Plugin.Functions.RemoveVfx(vfx);
}
this.Spawned.Clear();
}
internal void SpawnVfxForCurrentZone(ushort territory) {
var row = 0;
foreach (var adventure in this.Plugin.DataManager.GetExcelSheet<Adventure>()!) {
2021-03-21 05:48:48 +00:00
if (row >= 80) {
break;
}
row += 1;
2021-12-19 00:52:01 +00:00
if (adventure.Level.Value!.Territory.Row != territory) {
2021-03-21 05:48:48 +00:00
continue;
}
if (this.Plugin.Functions.HasVistaUnlocked((short) (row - 1))) {
continue;
}
var loc = adventure.Level.Value;
var pos = new Vector3(loc.X, loc.Z, loc.Y + 0.5f);
var vfx = this.Plugin.Functions.SpawnVfx(MarkerPath, pos);
this.Spawned[adventure.RowId] = vfx;
this.Queue.Add(vfx);
}
}
2023-09-28 06:05:06 +00:00
private void OnTerritoryChange(ushort territory) {
2021-03-21 05:48:48 +00:00
if (!this.Plugin.Config.ShowArrVistas) {
return;
}
2021-04-16 12:21:29 +00:00
try {
this.RemoveAllVfx();
this.SpawnVfxForCurrentZone(territory);
} catch (Exception ex) {
2023-09-28 06:05:06 +00:00
Plugin.Log.Error(ex, "Exception in territory change");
2021-04-16 12:21:29 +00:00
}
2021-03-21 05:48:48 +00:00
}
2023-09-28 06:05:06 +00:00
private void OnFrameworkUpdate(IFramework framework1) {
2021-03-21 05:48:48 +00:00
foreach (var vfx in this.Queue.ToArray()) {
if (this.Plugin.Functions.PlayVfx(vfx)) {
this.Queue.Remove(vfx);
}
}
}
}
}