feat: add restriction filtering

This commit is contained in:
Anna 2021-01-14 17:12:30 -05:00
parent 297402843e
commit 4d45e21c91
5 changed files with 215 additions and 21 deletions

View File

@ -10,7 +10,11 @@ namespace BetterPartyFinder {
public int Version { get; set; } = 1;
public Dictionary<Guid, ConfigurationFilter> Presets { get; } = new();
public Guid? SelectedPreset { get; set; } = null;
public Guid? SelectedPreset { get; set; }
internal static Configuration? Load(Plugin plugin) {
return (Configuration?) plugin.Interface.GetPluginConfig();
}
internal void Initialise(Plugin plugin) {
this.Plugin = plugin;
@ -27,17 +31,84 @@ namespace BetterPartyFinder {
public ListMode DutiesMode { get; set; } = ListMode.Blacklist;
public HashSet<uint> Duties { get; set; } = new();
public HashSet<UiCategory> Categories { get; set; } = Enum.GetValues(typeof(UiCategory))
.Cast<UiCategory>()
.ToHashSet();
public HashSet<UiCategory> Categories { get; set; } = new();
public List<JobFlags> Jobs { get; set; } = new();
// default to true because that's the PF's default
// use nosol if trying to avoid spam
public SearchAreaFlags SearchArea { get; set; } = (SearchAreaFlags) ~(uint) 0;
public LootRuleFlags LootRule { get; set; } = ~LootRuleFlags.None;
public DutyFinderSettingsFlags DutyFinderSettings { get; set; } = ~DutyFinderSettingsFlags.None;
public ConditionFlags Conditions { get; set; } = (ConditionFlags) ~(uint) 0;
public ObjectiveFlags Objectives { get; set; } = ~ObjectiveFlags.None;
public bool AllowHugeItemLevel { get; set; } = true;
public uint? MinItemLevel { get; set; }
public uint? MaxItemLevel { get; set; }
internal bool this[SearchAreaFlags flags] {
get => (this.SearchArea & flags) > 0;
set {
if (value) {
this.SearchArea |= flags;
} else {
this.SearchArea &= ~flags;
}
}
}
internal bool this[LootRuleFlags flags] {
get => (this.LootRule & flags) > 0;
set {
if (value) {
this.LootRule |= flags;
} else {
this.LootRule &= ~flags;
}
}
}
internal bool this[DutyFinderSettingsFlags flags] {
get => (this.DutyFinderSettings & flags) > 0;
set {
if (value) {
this.DutyFinderSettings |= flags;
} else {
this.DutyFinderSettings &= ~flags;
}
}
}
internal bool this[ConditionFlags flags] {
get => (this.Conditions & flags) > 0;
set {
if (value) {
this.Conditions |= flags;
} else {
this.Conditions &= ~flags;
}
}
}
internal bool this[ObjectiveFlags flags] {
get => (this.Objectives & flags) > 0;
set {
if (value) {
this.Objectives |= flags;
} else {
this.Objectives &= ~flags;
}
}
}
internal static ConfigurationFilter Create() {
return new() {
Categories = Enum.GetValues(typeof(UiCategory))
.Cast<UiCategory>()
.ToHashSet(),
};
}
}
public enum ListMode {

View File

@ -47,6 +47,28 @@ namespace BetterPartyFinder {
return false;
}
// filter based on restrictions
// make sure the listing doesn't contain any of the toggled off search areas
if (((listing.SearchArea ^ filter.SearchArea) & ~filter.SearchArea) > 0) {
return false;
}
if (!listing[filter.LootRule]) {
return false;
}
if (((listing.DutyFinderSettings ^ filter.DutyFinderSettings) & ~filter.DutyFinderSettings) > 0) {
return false;
}
if (!listing[filter.Conditions]) {
return false;
}
if (!listing[filter.Objectives]) {
return false;
}
// filter based on category (slow)
if (!filter.Categories.Any(category => category.ListingMatches(this.Plugin.Interface.Data, listing))) {
return false;

View File

@ -22,22 +22,32 @@ namespace BetterPartyFinder {
public IReadOnlyCollection<PartyFinderSlot> Slots => this._slots;
private readonly byte _objective;
public ObjectiveFlags Objective => (ObjectiveFlags) this._objective;
private readonly byte _conditions;
public ConditionFlags Conditions => (ConditionFlags) this._conditions;
private readonly byte _dutyFinderSettings;
public DutyFinderSettingsFlags DutyFinderSettings => (DutyFinderSettingsFlags) this._dutyFinderSettings;
private readonly byte _lootRules;
public LootRuleFlags LootRules => (LootRuleFlags) this._lootRules;
private readonly byte _searchArea;
public SearchAreaFlags SearchArea => (SearchAreaFlags) this._searchArea;
private readonly PartyFinderSlot[] _slots;
public bool this[ObjectiveFlags flag] => (this._objective & (uint) flag) > 0;
public bool this[ObjectiveFlags flag] => this._objective == 0 || (this._objective & (uint) flag) > 0;
public bool this[ConditionFlags flag] => (this._conditions & (uint) flag) > 0;
public bool this[DutyFinderSettingsFlags flag] => (this._dutyFinderSettings & (uint) flag) > 0;
public bool this[ConditionFlags flag] => this._conditions == 0 || (this._conditions & (uint) flag) > 0;
public bool this[LootRuleFlags flag] => (this._lootRules & (uint) flag) > 0;
public bool this[DutyFinderSettingsFlags flag] => this._dutyFinderSettings == 0 || (this._dutyFinderSettings & (uint) flag) > 0;
public bool this[SearchAreaFlags flag] => (this._searchArea & (uint) flag) > 0;
public bool this[LootRuleFlags flag] => this._lootRules == 0 || (this._lootRules & (uint) flag) > 0;
public bool this[SearchAreaFlags flag] => this._searchArea == 0 || (this._searchArea & (uint) flag) > 0;
internal PartyFinderListing(PfListing listing, DataManager dataManager) {
this.Id = listing.id;
@ -91,7 +101,7 @@ namespace BetterPartyFinder {
}
[Flags]
public enum SearchAreaFlags {
public enum SearchAreaFlags : uint {
DataCentre = 1 << 0,
Private = 1 << 1,
Unknown2 = 1 << 2, // set for copied factory pf
@ -131,7 +141,7 @@ namespace BetterPartyFinder {
}
[Flags]
public enum ObjectiveFlags {
public enum ObjectiveFlags : uint {
None = 0,
DutyCompletion = 1,
Practice = 2,
@ -139,21 +149,22 @@ namespace BetterPartyFinder {
}
[Flags]
public enum ConditionFlags {
public enum ConditionFlags : uint {
None = 1,
DutyComplete = 2,
DutyIncomplete = 4,
}
[Flags]
public enum DutyFinderSettingsFlags {
public enum DutyFinderSettingsFlags : uint {
None = 0,
UndersizedParty = 1,
MinimumItemLevel = 2,
UndersizedParty = 1 << 0,
MinimumItemLevel = 1 << 1,
SilenceEcho = 1 << 2,
}
[Flags]
public enum LootRuleFlags {
public enum LootRuleFlags : uint {
None = 0,
GreedOnly = 1,
Lootmaster = 2,

View File

@ -14,7 +14,7 @@ namespace BetterPartyFinder {
public void Initialize(DalamudPluginInterface pluginInterface) {
this.Interface = pluginInterface;
this.Config = (Configuration?) this.Interface.GetPluginConfig() ?? new Configuration();
this.Config = Configuration.Load(this) ?? new Configuration();
this.Config.Initialise(this);
this.Functions = new GameFunctions(this);

View File

@ -94,7 +94,7 @@ namespace BetterPartyFinder {
if (IconButton(FontAwesomeIcon.Plus, "add-preset")) {
var id = Guid.NewGuid();
this.Plugin.Config.Presets.Add(id, new ConfigurationFilter());
this.Plugin.Config.Presets.Add(id, ConfigurationFilter.Create());
this.Plugin.Config.SelectedPreset = id;
this.Plugin.Config.Save();
}
@ -305,7 +305,97 @@ namespace BetterPartyFinder {
return;
}
ImGui.TextUnformatted("Nothing here yet");
var practice = filter[ObjectiveFlags.Practice];
if (ImGui.Checkbox("Practice", ref practice)) {
filter[ObjectiveFlags.Practice] = practice;
this.Plugin.Config.Save();
}
var dutyCompletion = filter[ObjectiveFlags.DutyCompletion];
if (ImGui.Checkbox("Duty completion", ref dutyCompletion)) {
filter[ObjectiveFlags.DutyCompletion] = dutyCompletion;
this.Plugin.Config.Save();
}
var loot = filter[ObjectiveFlags.Loot];
if (ImGui.Checkbox("Loot", ref loot)) {
filter[ObjectiveFlags.Loot] = loot;
this.Plugin.Config.Save();
}
ImGui.Separator();
var noCondition = filter[ConditionFlags.None];
if (ImGui.Checkbox("No duty completion requirement", ref noCondition)) {
filter[ConditionFlags.None] = noCondition;
this.Plugin.Config.Save();
}
var dutyIncomplete = filter[ConditionFlags.DutyIncomplete];
if (ImGui.Checkbox("Duty incomplete", ref dutyIncomplete)) {
filter[ConditionFlags.DutyIncomplete] = dutyIncomplete;
this.Plugin.Config.Save();
}
var dutyComplete = filter[ConditionFlags.DutyComplete];
if (ImGui.Checkbox("Duty complete", ref dutyComplete)) {
filter[ConditionFlags.DutyComplete] = dutyComplete;
this.Plugin.Config.Save();
}
ImGui.Separator();
var undersized = filter[DutyFinderSettingsFlags.UndersizedParty];
if (ImGui.Checkbox("Undersized party", ref undersized)) {
filter[DutyFinderSettingsFlags.UndersizedParty] = undersized;
this.Plugin.Config.Save();
}
var minItemLevel = filter[DutyFinderSettingsFlags.MinimumItemLevel];
if (ImGui.Checkbox("Minimum item level", ref minItemLevel)) {
filter[DutyFinderSettingsFlags.MinimumItemLevel] = minItemLevel;
this.Plugin.Config.Save();
}
var silenceEcho = filter[DutyFinderSettingsFlags.SilenceEcho];
if (ImGui.Checkbox("Silence Echo", ref silenceEcho)) {
filter[DutyFinderSettingsFlags.SilenceEcho] = silenceEcho;
this.Plugin.Config.Save();
}
ImGui.Separator();
var greedOnly = filter[LootRuleFlags.GreedOnly];
if (ImGui.Checkbox("Greed only", ref greedOnly)) {
filter[LootRuleFlags.GreedOnly] = greedOnly;
this.Plugin.Config.Save();
}
var lootmaster = filter[LootRuleFlags.Lootmaster];
if (ImGui.Checkbox("Lootmaster", ref lootmaster)) {
filter[LootRuleFlags.Lootmaster] = lootmaster;
this.Plugin.Config.Save();
}
ImGui.Separator();
var dataCentre = filter[SearchAreaFlags.DataCentre];
if (ImGui.Checkbox("Data centre parties", ref dataCentre)) {
filter[SearchAreaFlags.DataCentre] = dataCentre;
this.Plugin.Config.Save();
}
var world = filter[SearchAreaFlags.World];
if (ImGui.Checkbox("World-local parties", ref world)) {
filter[SearchAreaFlags.World] = world;
this.Plugin.Config.Save();
}
var onePlayerPer = filter[SearchAreaFlags.OnePlayerPerJob];
if (ImGui.Checkbox("One player per job", ref onePlayerPer)) {
filter[SearchAreaFlags.OnePlayerPerJob] = onePlayerPer;
this.Plugin.Config.Save();
}
ImGui.EndTabItem();
}
@ -367,8 +457,8 @@ namespace BetterPartyFinder {
UiCategory.DutyRoulette => listing.DutyType == DutyType.Roulette && isDuty && !cr.GetRow(listing.RawDuty).Unknown10,
UiCategory.Dungeons => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Dungeons,
UiCategory.Guildhests => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Guildhests,
UiCategory.Trials => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Trials,
UiCategory.Raids => isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Raids,
UiCategory.Trials => isNormalDuty && !listing.Duty.Value.HighEndDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Trials,
UiCategory.Raids => isNormalDuty && !listing.Duty.Value.HighEndDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Raids,
UiCategory.HighEndDuty => isNormalDuty && listing.Duty.Value.HighEndDuty,
UiCategory.Pvp => listing.DutyType == DutyType.Roulette && isDuty && cr.GetRow(listing.RawDuty).Unknown10
|| isNormalDuty && listing.Duty.Value.ContentType.Row == (uint) ContentType2.Pvp,