diff --git a/NotifyEx/Models/LandBaseNotifier.cs b/NotifyEx/Models/LandBaseNotifier.cs new file mode 100644 index 0000000..0c80c18 --- /dev/null +++ b/NotifyEx/Models/LandBaseNotifier.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Grabacr07.KanColleWrapper.Models; +using Livet; +using NotifyEx.Models.NotifyType; +using NotifyEx.Models.Settings; + +namespace NotifyEx.Models +{ + public class LandBaseNotifier : NotificationObject + { + public static LandBaseNotifier Current { get; } = new LandBaseNotifier(); + + public bool Enabled + { + get { return NotifierSettings.EnabledLandBaseNotifier.Value; } + set + { + if (NotifierSettings.EnabledLandBaseNotifier.Value != value) + { + NotifierSettings.EnabledLandBaseNotifier.Value = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowNotificationBeforeSelectMap + { + get { return NotifierSettings.ShowLandBaseNotificationBeforeSelectMap.Value; } + set + { + if (NotifierSettings.ShowLandBaseNotificationBeforeSelectMap.Value != value) + { + NotifierSettings.ShowLandBaseNotificationBeforeSelectMap.Value = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowUncompletedAirCorps + { + get { return NotifierSettings.ShowUncompletedAirCorps.Value; } + set + { + if (NotifierSettings.ShowUncompletedAirCorps.Value != value) + { + NotifierSettings.ShowUncompletedAirCorps.Value = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowNotReadyAirCorps + { + get { return NotifierSettings.ShowNotReadyAirCorps.Value; } + set + { + if (NotifierSettings.ShowNotReadyAirCorps.Value != value) + { + NotifierSettings.ShowNotReadyAirCorps.Value = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowNeedSupplyAirCorps + { + get { return NotifierSettings.ShowNeedSupplyAirCorps.Value; } + set + { + if (NotifierSettings.ShowNeedSupplyAirCorps.Value != value) + { + NotifierSettings.ShowNeedSupplyAirCorps.Value = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowTiredAirCorps + { + get { return NotifierSettings.ShowTiredAirCorps.Value; } + set + { + if (NotifierSettings.ShowTiredAirCorps.Value != value) + { + NotifierSettings.ShowTiredAirCorps.Value = value; + this.RaisePropertyChanged(); + } + } + } + + private LandBaseNotifier() + { + NotifyHost.Register("/kcsapi/api_get_member/base_air_corps", LandBaseType.Instance, s => + { + SvData svData; + SvData.TryParse(s, out svData); + this._data = svData?.Data; + return this.CheckSituation(true); + }); + NotifyHost.Register("/kcsapi/api_get_member/sortie_conditions", LandBaseType.Instance, s => this.CheckSituation()); + } + + private base_air_corps[] _data; + + private string CheckSituation(bool beforeSelectMap = false) + { + if (!this.Enabled) return ""; + + if (this._data == null) return ""; + + if (beforeSelectMap && !this.ShowNotificationBeforeSelectMap) return ""; + + var notificationContent = new List(); + + if (this.ShowUncompletedAirCorps) + { + var uncompleted = this._data.Where(s => s.api_plane_info.Any(p => p.api_state == 0)); + notificationContent.Add(this.FormatInfo(uncompleted, "有空位未配置")); + } + + if (this.ShowNotReadyAirCorps) + { + var notReady = this._data.Where(s => s.api_action_kind != 1 && s.api_action_kind != 2); + notificationContent.Add(this.FormatInfo(notReady, "未在出击/防空状态")); + } + + if (this.ShowNeedSupplyAirCorps) + { + var needSupply = this._data.Where(s => s.api_plane_info.Any(p => p.api_count < p.api_max_count)); + notificationContent.Add(this.FormatInfo(needSupply, "需要补给")); + } + + if (this.ShowTiredAirCorps) + { + var tired = this._data.Where(s => s.api_plane_info.Any(p => p.api_state > 1)); + notificationContent.Add(this.FormatInfo(tired, "疲劳")); + } + + return string.Join(Environment.NewLine, notificationContent); + } + + private string FormatInfo(IEnumerable airCorps, string info) + { + return airCorps.Any() + ? $"{string.Join(", ", airCorps.Select(s => s.api_name))} {info}" + : ""; + } + } +} diff --git a/NotifyEx/Models/NotifyType/LandBaseType.cs b/NotifyEx/Models/NotifyType/LandBaseType.cs new file mode 100644 index 0000000..b1603e9 --- /dev/null +++ b/NotifyEx/Models/NotifyType/LandBaseType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NotifyEx.Models.NotifyType +{ + public class LandBaseType : INotifyType + { + public static LandBaseType Instance { get; } = new LandBaseType(); + + public string Name => "基地航空队"; + + private LandBaseType() { } + } +} diff --git a/NotifyEx/Models/Settings/NotifierSettings.cs b/NotifyEx/Models/Settings/NotifierSettings.cs index 03487ce..13662d1 100644 --- a/NotifyEx/Models/Settings/NotifierSettings.cs +++ b/NotifyEx/Models/Settings/NotifierSettings.cs @@ -68,6 +68,28 @@ public static class NotifierSettings #endregion + #region Land base + + public static SerializableProperty EnabledLandBaseNotifier { get; } + = new SerializableProperty(GetKey(), Provider.Roaming, true) { AutoSave = true }; + + public static SerializableProperty ShowLandBaseNotificationBeforeSelectMap { get; } + = new SerializableProperty(GetKey(), Provider.Roaming, false) { AutoSave = true }; + + public static SerializableProperty ShowUncompletedAirCorps { get; } + = new SerializableProperty(GetKey(), Provider.Roaming, true) { AutoSave = true }; + + public static SerializableProperty ShowNotReadyAirCorps { get; } + = new SerializableProperty(GetKey(), Provider.Roaming, true) { AutoSave = true }; + + public static SerializableProperty ShowNeedSupplyAirCorps { get; } + = new SerializableProperty(GetKey(), Provider.Roaming, true) { AutoSave = true }; + + public static SerializableProperty ShowTiredAirCorps { get; } + = new SerializableProperty(GetKey(), Provider.Roaming, true) { AutoSave = true }; + + #endregion + private static string GetKey([CallerMemberName] string propertyName = "") { return $"{nameof(NotifierSettings)}.{propertyName}"; diff --git a/NotifyEx/Models/base_air_corps.cs b/NotifyEx/Models/base_air_corps.cs new file mode 100644 index 0000000..20a5395 --- /dev/null +++ b/NotifyEx/Models/base_air_corps.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NotifyEx.Models +{ + public class base_air_corps + { + public int api_rid { get; set; } + public string api_name { get; set; } + public int api_distance { get; set; } + public int api_action_kind { get; set; } + public api_plane_info[] api_plane_info { get; set; } + } + + public class api_plane_info + { + public int api_squadron_id { get; set; } + public int api_state { get; set; } + public int api_slotid { get; set; } + public int api_count { get; set; } + public int api_max_count { get; set; } + public int api_cond { get; set; } + } +} diff --git a/NotifyEx/NotifyEx.csproj b/NotifyEx/NotifyEx.csproj index 17ea014..a8f768c 100644 --- a/NotifyEx/NotifyEx.csproj +++ b/NotifyEx/NotifyEx.csproj @@ -144,10 +144,13 @@ + + + diff --git a/NotifyEx/Plugin.cs b/NotifyEx/Plugin.cs index 118d0f1..20ebbe6 100644 --- a/NotifyEx/Plugin.cs +++ b/NotifyEx/Plugin.cs @@ -20,7 +20,7 @@ namespace NotifyEx [ExportMetadata("Guid", "3190E362-3833-4953-87C3-B2C22C058EE8")] [ExportMetadata("Title", "NotifyEx")] [ExportMetadata("Description", "通知内容扩展")] - [ExportMetadata("Version", "0.7.0")] + [ExportMetadata("Version", "0.8.0")] [ExportMetadata("Author", "@Yoctillion")] public class Plugin : IPlugin, ISettings, IRequestNotify { diff --git a/NotifyEx/Properties/AssemblyInfo.cs b/NotifyEx/Properties/AssemblyInfo.cs index 6027739..2bc6303 100644 --- a/NotifyEx/Properties/AssemblyInfo.cs +++ b/NotifyEx/Properties/AssemblyInfo.cs @@ -51,4 +51,4 @@ // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を // 既定値にすることができます: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.0")] +[assembly: AssemblyVersion("0.8.0")] diff --git a/NotifyEx/ViewModels/ToolViewModel.cs b/NotifyEx/ViewModels/ToolViewModel.cs index 134a86f..b517fc9 100644 --- a/NotifyEx/ViewModels/ToolViewModel.cs +++ b/NotifyEx/ViewModels/ToolViewModel.cs @@ -14,6 +14,7 @@ public class ToolViewModel : ViewModel private readonly SlotNotifier _slotNotifier = SlotNotifier.Current; private readonly HpNotifier _hpNotifier = HpNotifier.Current; private readonly SupplyNotifier _supplyNotifier = SupplyNotifier.Current; + private readonly LandBaseNotifier _landBaseNotifier = LandBaseNotifier.Current; public bool EnabledShipNotifier { @@ -197,5 +198,82 @@ public bool EnabledExpenditionSupplyNotifier } } + public bool EnabledLandBaseNotifier + { + get { return this._landBaseNotifier.Enabled; } + set + { + if (this._landBaseNotifier.Enabled != value) + { + this._landBaseNotifier.Enabled = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowNotReadyAirCorps + { + get { return this._landBaseNotifier.ShowNotReadyAirCorps; } + set + { + if (this._landBaseNotifier.ShowNotReadyAirCorps != value) + { + this._landBaseNotifier.ShowNotReadyAirCorps = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowLandBaseNotificationBeforeSelectMap + { + get { return this._landBaseNotifier.ShowNotificationBeforeSelectMap; } + set + { + if (this._landBaseNotifier.ShowNotificationBeforeSelectMap != value) + { + this._landBaseNotifier.ShowNotificationBeforeSelectMap = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowUncompletedAirCorps + { + get { return this._landBaseNotifier.ShowUncompletedAirCorps; } + set + { + if (this._landBaseNotifier.ShowUncompletedAirCorps != value) + { + this._landBaseNotifier.ShowUncompletedAirCorps = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowNeedSupplyAirCorps + { + get { return this._landBaseNotifier.ShowNeedSupplyAirCorps; } + set + { + if (this._landBaseNotifier.ShowNeedSupplyAirCorps != value) + { + this._landBaseNotifier.ShowNeedSupplyAirCorps = value; + this.RaisePropertyChanged(); + } + } + } + + public bool ShowTiredAirCorps + { + get { return this._landBaseNotifier.ShowTiredAirCorps; } + set + { + if (this._landBaseNotifier.ShowTiredAirCorps != value) + { + this._landBaseNotifier.ShowTiredAirCorps = value; + this.RaisePropertyChanged(); + } + } + } } } diff --git a/NotifyEx/Views/ToolView.xaml b/NotifyEx/Views/ToolView.xaml index e5d7683..b9224f2 100644 --- a/NotifyEx/Views/ToolView.xaml +++ b/NotifyEx/Views/ToolView.xaml @@ -202,6 +202,53 @@ IsEnabled="{Binding EnabledSupplyNotifier, Mode=OneWay}" Margin="0,3,15,3" /> + + + + + + + + + + + + + + + + + + + + + + + + + +