Skip to content

Commit

Permalink
feat: filter by fc/individual purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
zhudotexe committed Jul 6, 2022
1 parent e1a9f97 commit ba4e4c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class DistrictNotifConfig {
public bool Small { get; set; } = true;
public bool Medium { get; set; } = true;
public bool Large { get; set; } = true;
public bool FreeCompany { get; set; } = true;
public bool Individual { get; set; } = true;
}

public enum OutputFormat {
Expand Down
8 changes: 6 additions & 2 deletions Paissa/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ string houseSizeName
.Replace("{houseSizeName}", houseSizeName);
}

public static bool ConfigEnabledForPlot(Plugin plugin, ushort worldId, ushort districtId, ushort size) {
public static bool ConfigEnabledForPlot(Plugin plugin, ushort worldId, ushort districtId, ushort size, PurchaseSystem purchaseSystem) {
if (!plugin.Configuration.Enabled) return false;
// does the config want notifs for this world?
World eventWorld = plugin.Worlds.GetRow(worldId);
if (!(plugin.Configuration.AllNotifs
|| plugin.Configuration.HomeworldNotifs && worldId == plugin.ClientState.LocalPlayer?.HomeWorld.Id
|| plugin.Configuration.DatacenterNotifs && eventWorld?.DataCenter.Row == plugin.ClientState.LocalPlayer?.HomeWorld.GameData.DataCenter.Row))
return false;
// what about house sizes in this district?
// get the district config
DistrictNotifConfig districtNotifs;
switch (districtId) {
case 339:
Expand All @@ -70,6 +70,7 @@ public static bool ConfigEnabledForPlot(Plugin plugin, ushort worldId, ushort di
PluginLog.Warning($"Unknown district in plot open event: {districtId}");
return false;
}
// what about house sizes in this district?
bool notifEnabled;
switch (size) {
case 0:
Expand All @@ -85,6 +86,9 @@ public static bool ConfigEnabledForPlot(Plugin plugin, ushort worldId, ushort di
PluginLog.Warning($"Unknown plot size in plot open event: {size}");
return false;
}
// and FC/individual purchase?
PurchaseSystem purchaseSystemMask = (districtNotifs.FreeCompany ? PurchaseSystem.FreeCompany : 0) | (districtNotifs.Individual ? PurchaseSystem.Individual : 0);
notifEnabled = notifEnabled && (purchaseSystem & purchaseSystemMask) != 0;
return notifEnabled;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private void OnNetworkEvent(IntPtr dataPtr, ushort opCode, uint sourceActorId, u
/// </summary>
private void OnPlotOpened(object sender, PlotOpenedEventArgs e) {
if (e.PlotDetail == null) return;
bool notifEnabled = Utils.ConfigEnabledForPlot(this, e.PlotDetail.world_id, e.PlotDetail.district_id, e.PlotDetail.size);
bool notifEnabled = Utils.ConfigEnabledForPlot(this, e.PlotDetail.world_id, e.PlotDetail.district_id, e.PlotDetail.size, e.PlotDetail.purchase_system);
if (!notifEnabled) return;
// we only notify on PlotOpen if the purchase type is FCFS or we know it is available
if (!((e.PlotDetail.purchase_system & PurchaseSystem.Lottery) == 0 || e.PlotDetail.lotto_phase == AvailabilityType.Available)) return;
Expand All @@ -173,7 +173,7 @@ private void OnPlotOpened(object sender, PlotOpenedEventArgs e) {

private void OnPlotUpdate(object sender, PlotUpdateEventArgs e) {
if (e.PlotUpdate == null) return;
bool notifEnabled = Utils.ConfigEnabledForPlot(this, e.PlotUpdate.world_id, e.PlotUpdate.district_id, e.PlotUpdate.size);
bool notifEnabled = Utils.ConfigEnabledForPlot(this, e.PlotUpdate.world_id, e.PlotUpdate.district_id, e.PlotUpdate.size, e.PlotUpdate.purchase_system);
if (!notifEnabled) return;
// we only notify on PlotUpdate if the purchase type is lottery and it is available now and was not before
if (!((e.PlotUpdate.purchase_system & PurchaseSystem.Lottery) == PurchaseSystem.Lottery
Expand Down
5 changes: 5 additions & 0 deletions PluginUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ private void DrawTabItemForDistrict(string districtName, DistrictNotifConfig not
if (ImGui.Checkbox("Medium", ref medium)) notifConfig.Medium = medium;
bool large = notifConfig.Large;
if (ImGui.Checkbox("Large", ref large)) notifConfig.Large = large;
ImGui.Separator();
bool fc = notifConfig.FreeCompany;
if (ImGui.Checkbox("Free Company Purchase Allowed", ref fc)) notifConfig.FreeCompany = fc;
bool solo = notifConfig.Individual;
if (ImGui.Checkbox("Individual Purchase Allowed", ref solo)) notifConfig.Individual = solo;
ImGui.EndTabItem();
}
}
Expand Down

0 comments on commit ba4e4c7

Please sign in to comment.