Skip to content

Commit

Permalink
艦娘別TP設定を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
veigr committed Sep 14, 2018
1 parent b784570 commit 5c96fbc
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 128 deletions.
2 changes: 2 additions & 0 deletions EventMapHpViewer/EventMapHpViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,14 @@
<Compile Include="Models\RemainingCount.cs" />
<Compile Include="Models\Settings\RemoteSettingsClient.cs" />
<Compile Include="Models\Settings\AutoCalcTpSettings.cs" />
<Compile Include="Models\Settings\TpSetting.cs" />
<Compile Include="Models\TpExtensions.cs" />
<Compile Include="Models\TransportCapacity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\Settings\BossSettingsViewModel.cs" />
<Compile Include="ViewModels\Settings\SettingsViewModel.cs" />
<Compile Include="ViewModels\Settings\TpSettingsViewModel.cs" />
<Compile Include="Views\Controls\DecimalRule.cs" />
<Compile Include="Views\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
</Compile>
Expand Down
185 changes: 99 additions & 86 deletions EventMapHpViewer/Models/Settings/AutoCalcTpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace EventMapHpViewer.Models.Settings
{
class AutoCalcTpSettings : Livet.NotificationObject
{
#region ShipTypeTp

private ObservableSynchronizedCollection<TpSetting> _ShipTypeTp;
public ObservableSynchronizedCollection<TpSetting> ShipTypeTp
{
Expand All @@ -28,6 +30,11 @@ private set
this.RaisePropertyChanged();
}
}

#endregion

#region SlotItemTp

private ObservableSynchronizedCollection<TpSetting> _SlotItemTp;
public ObservableSynchronizedCollection<TpSetting> SlotItemTp
{
Expand All @@ -41,28 +48,51 @@ private set
}
}

#endregion

#region ShipTp

private ObservableSynchronizedCollection<TpSetting> _ShipTp;
public ObservableSynchronizedCollection<TpSetting> ShipTp
{
get => this._ShipTp;
private set
{
if (this._ShipTp == value)
return;
this._ShipTp = value;
this.RaisePropertyChanged();
}
}

#endregion

public AutoCalcTpSettings()
{
this.ShipTypeTp = Default.ShipTypeTp;
this.SlotItemTp = Default.SlotItemTp;
this.ShipTp = Default.ShipTp;
}

private AutoCalcTpSettings(string stypeTp, string slotitemTp)
private AutoCalcTpSettings(string stypeTp, string slotitemTp, string shipTp)
{
this.ShipTypeTp = !string.IsNullOrEmpty(stypeTp) ? DynamicJson.Parse(stypeTp) : Default.ShipTypeTp;
this.SlotItemTp = !string.IsNullOrEmpty(slotitemTp) ? DynamicJson.Parse(slotitemTp) : Default.SlotItemTp;
this.ShipTp = !string.IsNullOrEmpty(shipTp) ? DynamicJson.Parse(shipTp) : Default.ShipTp;
}

private AutoCalcTpSettings(IEnumerable<TpSetting> stypeTp, IEnumerable<TpSetting> slotitemTp)
private AutoCalcTpSettings(IEnumerable<TpSetting> stypeTp, IEnumerable<TpSetting> slotitemTp, IEnumerable<TpSetting> shipTp)
{
this.ShipTypeTp = new ObservableSynchronizedCollection<TpSetting>(new ObservableCollection<TpSetting>(stypeTp));
this.SlotItemTp = new ObservableSynchronizedCollection<TpSetting>(new ObservableCollection<TpSetting>(slotitemTp));
this.ShipTp = new ObservableSynchronizedCollection<TpSetting>(new ObservableCollection<TpSetting>(shipTp));
}

public void RestoreDefault()
{
this.ShipTypeTp = Default.ShipTypeTp;
this.SlotItemTp = Default.SlotItemTp;
this.ShipTp = Default.ShipTp;
this.UpdateFromMaster();
}

Expand All @@ -72,38 +102,17 @@ public void UpdateFromMaster()

var master = KanColleClient.Current.Master;

IDictionary<int, TpSetting> newStypeTp = master.ShipTypes
.Select(x => new TpSetting(x.Value.Id, x.Value.Name))
.ToDictionary(x => x.Id);
foreach (var oldStyleTp in this.ShipTypeTp)
{
if (newStypeTp.Any(x => x.Key == oldStyleTp.Id))
{
newStypeTp[oldStyleTp.Id].Tp = oldStyleTp.Tp;
}
else
{
newStypeTp.Add(oldStyleTp.Id, oldStyleTp);
}
}
this.ShipTypeTp = new ObservableSynchronizedCollection<TpSetting>(new ObservableCollection<TpSetting>(newStypeTp.Select(x => x.Value)));
this.ShipTypeTp = master.ShipTypes.UpdateSettings(this.ShipTypeTp,
x => true,
x => new TpSetting(x.Id, x.SortNumber, x.Name));

var newSlotitemTp = master.SlotItems
.Where(x => x.Key <= 500) // 敵の装備は除外
.Select(x => new TpSetting(x.Value.Id, x.Value.Name, 0, x.Value.EquipType.Id, x.Value.EquipType.Name))
.ToDictionary(x => x.Id);
foreach (var oldSltitemTp in this.SlotItemTp)
{
if (newSlotitemTp.Any(x => x.Key == oldSltitemTp.Id))
{
newSlotitemTp[oldSltitemTp.Id].Tp = oldSltitemTp.Tp;
}
else
{
newSlotitemTp.Add(oldSltitemTp.Id, oldSltitemTp);
}
}
this.SlotItemTp = new ObservableSynchronizedCollection<TpSetting>(new ObservableCollection<TpSetting>(newSlotitemTp.Select(x => x.Value)));
this.SlotItemTp = master.SlotItems.UpdateSettings(this.SlotItemTp,
x => x.RawData.api_sortno != 0,
x => new TpSetting(x.Id, x.RawData.api_sortno, x.Name, 0, x.EquipType.Id, x.EquipType.Name));

this.ShipTp = master.Ships.UpdateSettings(this.ShipTp,
x => x.SortId != 0,
x => new TpSetting(x.Id, x.SortId, x.Name, 0, x.ShipType.Id, x.ShipType.Name));

this.Save();
}
Expand All @@ -114,73 +123,49 @@ private static AutoCalcTpSettings CreateDefault()
{
var stypTp = new[]
{
new TpSetting(2, "駆逐艦", 5),
new TpSetting(3, "軽巡洋艦", 2),
new TpSetting(10, "航空戦艦", 7),
new TpSetting(16, "水上機母艦", 9),
new TpSetting(14, "潜水空母", 1),
new TpSetting(21, "練習巡洋艦", 6),
new TpSetting(6, "航空巡洋艦", 4),
new TpSetting(22, "補給艦", 15),
new TpSetting(17, "揚陸艦", 12),
new TpSetting(20, "潜水母艦", 7),
new TpSetting(2, 2, "駆逐艦", 5),
new TpSetting(3, 3, "軽巡洋艦", 2),
new TpSetting(10, 10, "航空戦艦", 7),
new TpSetting(16, 16, "水上機母艦", 9),
new TpSetting(14, 14, "潜水空母", 1),
new TpSetting(21, 21, "練習巡洋艦", 6),
new TpSetting(6, 6, "航空巡洋艦", 4),
new TpSetting(22, 22, "補給艦", 15),
new TpSetting(17, 17, "揚陸艦", 12),
new TpSetting(20, 20, "潜水母艦", 7),
};

var slotitemTp = new[]
{
new TpSetting(75, "ドラム缶(輸送用)", 5),
new TpSetting(68, "大発動艇", 8),
new TpSetting(193, "特大発動艇", 8),
new TpSetting(166, "大発動艇(八九式中戦車&陸戦隊)", 8),
new TpSetting(230, "特大発動艇+戦車第11連隊", 8),
new TpSetting(167, "特二式内火艇", 2),
new TpSetting(145, "戦闘糧食", 1),
new TpSetting(150, "秋刀魚の缶詰", 1),
new TpSetting(241, "戦闘糧食(特別なおにぎり)", 1),
new TpSetting(75, 75, "ドラム缶(輸送用)", 5),
new TpSetting(68, 68, "大発動艇", 8),
new TpSetting(193, 193, "特大発動艇", 8),
new TpSetting(166, 166, "大発動艇(八九式中戦車&陸戦隊)", 8),
new TpSetting(230, 230, "特大発動艇+戦車第11連隊", 8),
new TpSetting(167, 167, "特二式内火艇", 2),
new TpSetting(145, 145, "戦闘糧食", 1),
new TpSetting(150, 150, "秋刀魚の缶詰", 1),
new TpSetting(241, 241, "戦闘糧食(特別なおにぎり)", 1),
};

var shipTp = new[]
{
new TpSetting(487, 287, "鬼怒改二", 8),
};

return new AutoCalcTpSettings(stypTp, slotitemTp);
return new AutoCalcTpSettings(stypTp, slotitemTp, shipTp);
}

public static AutoCalcTpSettings FromSettings
{
get => new AutoCalcTpSettings(MapHpSettings.ShipTypeTpSettings?.Value, MapHpSettings.SlotItemTpSettings?.Value);
get => new AutoCalcTpSettings(
MapHpSettings.ShipTypeTpSettings?.Value,
MapHpSettings.SlotItemTpSettings?.Value,
MapHpSettings.ShipTpSettings?.Value);
}

}

public class TpSetting: Livet.NotificationObject
{
public int Id { get; set; }
public string Name { get; set; }
public int TypeId { get; set; }
public string TypeName { get; set; }

private decimal _Tp;
public decimal Tp
{
get => this._Tp;
set
{
if (this._Tp == value)
return;
this._Tp = value;
this.RaisePropertyChanged();
}
}

public TpSetting() { }

public TpSetting(int id, string name, decimal tp = 0, int typeId = 0, string typeName = "")
{
this.Id = id;
this.Name = name;
this.Tp = tp;
this.TypeId = typeId;
this.TypeName = typeName;
}
}

static class AutoCalcTpSettingsExtensions
{
public static void Save(this AutoCalcTpSettings settings)
Expand All @@ -189,13 +174,41 @@ public static void Save(this AutoCalcTpSettings settings)
MapHpSettings.ShipTypeTpSettings.Value = DynamicJson.Serialize(settings.ShipTypeTp);
if (settings.SlotItemTp.Any())
MapHpSettings.SlotItemTpSettings.Value = DynamicJson.Serialize(settings.SlotItemTp);
if (settings.ShipTp.Any())
MapHpSettings.ShipTpSettings.Value = DynamicJson.Serialize(settings.ShipTp);
}

public static void ResetAndSave(this AutoCalcTpSettings settings)
{
MapHpSettings.ShipTypeTpSettings?.Reset();
MapHpSettings.SlotItemTpSettings?.Reset();
MapHpSettings.ShipTpSettings?.Reset();
settings.RestoreDefault();
}

public static ObservableSynchronizedCollection<TpSetting> UpdateSettings<T>(this MasterTable<T> master,
IEnumerable<TpSetting> oldSettings,
Func<T, bool> filter,
Func<T, TpSetting> selector)
where T : class, IIdentifiable
{
var newTps = master
.Select(x => x.Value)
.Where(filter)
.Select(selector)
.ToDictionary(x => x.Id);
foreach (var oldTp in oldSettings)
{
if (newTps.Any(x => x.Key == oldTp.Id))
{
newTps[oldTp.Id].Tp = oldTp.Tp;
}
else
{
newTps.Add(oldTp.Id, oldTp);
}
}
return new ObservableSynchronizedCollection<TpSetting>(new ObservableCollection<TpSetting>(newTps.Select(x => x.Value)));
}
}
}
3 changes: 3 additions & 0 deletions EventMapHpViewer/Models/Settings/MapHpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ static class MapHpSettings
public static SerializableProperty<string> SlotItemTpSettings { get; }
= new SerializableProperty<string>(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.SlotItemTp.ToArray())) { AutoSave = true };

public static SerializableProperty<string> ShipTpSettings { get; }
= new SerializableProperty<string>(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTp.ToArray())) { AutoSave = true };

public static SerializableProperty<bool> UseAutoCalcTpSettings { get; }
= new SerializableProperty<bool>(GetKey(), roamingProvider, true) { AutoSave = true };

Expand Down
37 changes: 37 additions & 0 deletions EventMapHpViewer/Models/Settings/TpSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace EventMapHpViewer.Models.Settings
{
public class TpSetting: Livet.NotificationObject
{
public int TypeId { get; set; }
public string TypeName { get; set; }

public int Id { get; set; }
public int SortId { get; set; }
public string Name { get; set; }

private decimal _Tp;
public decimal Tp
{
get => this._Tp;
set
{
if (this._Tp == value)
return;
this._Tp = value;
this.RaisePropertyChanged();
}
}

public TpSetting() { }

public TpSetting(int id, int sortId, string name, decimal tp = 0, int typeId = 0, string typeName = "")
{
this.Id = id;
this.SortId = sortId;
this.Name = name;
this.Tp = tp;
this.TypeId = typeId;
this.TypeName = typeName;
}
}
}
10 changes: 8 additions & 2 deletions EventMapHpViewer/Models/TpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ public static TransportCapacity TransportationCapacity(this Organization org)

public static decimal CalcTp(this Ship ship, AutoCalcTpSettings settings)
{
var stypeTp = settings.ShipTypeTp.FirstOrDefault(x => x.Id == ship.Info.ShipType.Id)?.Tp ?? 0;
var stypeTp = settings.ShipTypeTp
.FirstOrDefault(x => x.Id == ship.Info.ShipType.Id)?.Tp
?? 0;

var shipTp = settings.ShipTp
.FirstOrDefault(x => x.Id == ship.Info.Id)?.Tp
?? 0;

var slotTp = ship.Slots
.Concat(new[] { ship.ExSlot })
.Where(x => x.Equipped)
.Select(x => x.Item.Info.Id)
.Sum(x => settings.SlotItemTp.FirstOrDefault(y => y.Id == x)?.Tp ?? 0);

return stypeTp + slotTp;
return stypeTp + shipTp + slotTp;
}

private static IEnumerable<Ship> TransportingShips(this Organization org)
Expand Down
11 changes: 11 additions & 0 deletions EventMapHpViewer/Styles/PluginStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@
</ResourceDictionary.MergedDictionaries>

<conv:ReverseBooleanConverter x:Key="ReverseBooelanConverter"/>

<Style x:Key="TabHeaderTextStyleKey"
TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource DefaultTextStyleKey}">
<Setter Property="Foreground"
Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Foreground}" />
<Setter Property="Margin"
Value="12,0" />
<Setter Property="FontSize"
Value="14" />
</Style>
</ResourceDictionary>
Loading

0 comments on commit 5c96fbc

Please sign in to comment.