Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PartyChanged event #17

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion OverlayPlugin.Core/EventSources/MiniParseEventSource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -8,6 +9,7 @@
using Advanced_Combat_Tracker;
using System.Diagnostics;
using System.Windows.Forms;
using FFXIV_ACT_Plugin.Common.Models;

namespace RainbowMage.OverlayPlugin.EventSources
{
Expand Down Expand Up @@ -36,6 +38,7 @@ partial class MiniParseEventSource : EventSourceBase
private const string ChangePrimaryPlayerEvent = "ChangePrimaryPlayer";
private const string FileChangedEvent = "FileChanged";
private const string OnlineStatusChangedEvent = "OnlineStatusChanged";
private const string PartyChangedEvent = "PartyChanged";

// Event Source

Expand All @@ -47,7 +50,14 @@ public MiniParseEventSource(ILogger logger) : base(logger)

// FileChanged isn't actually raised by this event source. That event is generated in MiniParseOverlay directly.
RegisterEventTypes(new List<string> {
CombatDataEvent, LogLineEvent, ImportedLogLinesEvent, ChangeZoneEvent, ChangePrimaryPlayerEvent, FileChangedEvent, OnlineStatusChangedEvent,
ChangePrimaryPlayerEvent,
ChangeZoneEvent,
CombatDataEvent,
FileChangedEvent,
LogLineEvent,
ImportedLogLinesEvent,
OnlineStatusChangedEvent,
PartyChangedEvent,
});

ActGlobals.oFormActMain.BeforeLogLineRead += LogLineHandler;
Expand All @@ -61,6 +71,8 @@ public MiniParseEventSource(ILogger logger) : base(logger)

DispatchEvent(obj);
};

FFXIVRepository.RegisterPartyChangeDelegate((partyList, partySize) => DispatchPartyChangeEvent());
}

private void LogLineHandler(bool isImport, LogLineEventArgs args)
Expand Down Expand Up @@ -127,6 +139,48 @@ private void LogLineHandler(bool isImport, LogLineEventArgs args)
}));
}

struct PartyMember
{
// Player id in hex (for ease in matching logs).
public string id;
public string name;
public uint worldId;
// Raw job id.
public int job;
// In immediate party (true), vs in alliance (false).
public bool inParty;
}

private void DispatchPartyChangeEvent()
{
var combatants = FFXIVRepository.GetCombatants();
if (combatants == null)
return;

List<PartyMember> result = new List<PartyMember>(24);

// The partyList contents from the PartyListChangedDelegate
// are equivalent to the set of ids enumerated by |query|
var query = combatants.Where(c => c.PartyType != PartyTypeEnum.None);
foreach (var c in query)
{
result.Add(new PartyMember()
{
id = $"{c.ID:X}",
name = c.Name,
worldId = c.WorldID,
job = c.Job,
inParty = c.PartyType == PartyTypeEnum.Party,
});
}

DispatchEvent(JObject.FromObject(new
{
type = PartyChangedEvent,
party = result,
}));
}

public override Control CreateConfigControl()
{
return new MiniParseEventSourceConfigPanel(this);
Expand Down
23 changes: 23 additions & 0 deletions OverlayPlugin.Core/FFXIVRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Advanced_Combat_Tracker;
using FFXIV_ACT_Plugin.Common;
Expand Down Expand Up @@ -118,17 +119,39 @@ public static string GetPlayerName()
return playerInfo.Name;
}

public static ReadOnlyCollection<FFXIV_ACT_Plugin.Common.Models.Combatant> GetCombatants()
{
var repo = GetRepository();
if (repo == null) return null;

return repo.GetCombatantList();
}

// LogLineDelegate(uint EventType, uint Seconds, string logline);
public static void RegisterLogLineHandler(Action<uint, uint, string> handler)
{
var sub = GetSubscription();
sub.LogLine += new LogLineDelegate(handler);
}

// NetworkReceivedDelegate(string connection, long epoch, byte[] message)
public static void RegisterNetworkParser(Action<string, long, byte[]> handler)
{
var sub = GetSubscription();
sub.NetworkReceived += new NetworkReceivedDelegate(handler);
}

// PartyListChangedDelegate(ReadOnlyCollection<uint> partyList, int partySize)
//
// Details: partySize may differ from partyList.Count.
// In non-cross world parties, players who are not in the same
// zone count in the partySize but do not appear in the partyList.
// In cross world parties, nobody will appear in the partyList.
// Alliance data members show up in partyList but not in partySize.
public static void RegisterPartyChangeDelegate(Action<ReadOnlyCollection<uint>, int> handler)
{
var sub = GetSubscription();
sub.PartyListChanged += new PartyListChangedDelegate(handler);
}
}
}