コミットメタ情報

リビジョン3ff2f1006fe0f1aaf6e7e812ecddebb0174b2080 (tree)
日時2018-08-01 21:40:12
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

ShipStatusのSlotとSlotExに触ったときにItemSpecを取得する

変更サマリ

差分

--- a/KancolleSniffer.Test/SnifferTest.cs
+++ b/KancolleSniffer.Test/SnifferTest.cs
@@ -425,12 +425,14 @@ namespace KancolleSniffer.Test
425425 ships.Select(ship => (int)(ship.NightBattlePower * 100))
426426 .SequenceEqual(new[] {11202, 14985, 20092, 17354}));
427427 // 夜間作戦航空要員を外す
428- ships[0].Slot[3] = ships[1].Slot[2] = ships[3].Slot[2] = new ItemStatus();
428+ ships[0].FreeSlot(3);
429+ ships[1].FreeSlot(2);
430+ ships[3].FreeSlot(2);
429431 PAssert.That(() =>
430432 ships.Select(ship => (int)(ship.NightBattlePower * 100))
431433 .SequenceEqual(new[] {6900, 7500, 20092, 0}));
432434 // Ark RoyalからSwordfishを外す
433- ships[0].Slot[0] = new ItemStatus();
435+ ships[0].FreeSlot(0);
434436 PAssert.That(() => (int)ships[0].NightBattlePower == 0);
435437 }
436438
--- a/KancolleSniffer/Model/BattleInfo.cs
+++ b/KancolleSniffer/Model/BattleInfo.cs
@@ -193,11 +193,11 @@ namespace KancolleSniffer.Model
193193 ship.SlotEx = new ItemStatus();
194194 return;
195195 }
196- for (var i = 0; i < ship.Slot.Length; i++)
196+ for (var i = 0; i < ship.Slot.Count; i++)
197197 {
198198 if (ship.Slot[i].Spec.Id == id)
199199 {
200- ship.Slot[i] = new ItemStatus();
200+ ship.FreeSlot(i);
201201 break;
202202 }
203203 }
--- a/KancolleSniffer/Model/ShipInfo.cs
+++ b/KancolleSniffer/Model/ShipInfo.cs
@@ -169,6 +169,7 @@ namespace KancolleSniffer.Model
169169 Fuel = (int)entry.api_fuel,
170170 Bull = (int)entry.api_bull,
171171 OnSlot = (int[])entry.api_onslot,
172+ GetItem = item => _itemInventry[item.Id],
172173 Slot = ((int[])entry.api_slot).Select(item => new ItemStatus(item)).ToArray(),
173174 SlotEx = entry.api_slot_ex() ? new ItemStatus((int)entry.api_slot_ex) : new ItemStatus(0),
174175 NdockTime = (int)entry.api_ndock_time,
@@ -341,8 +342,6 @@ namespace KancolleSniffer.Model
341342 {
342343 if (ship.Empty)
343344 return ship;
344- ship.Slot = ship.Slot.Select(item => _itemInventry[item.Id]).ToArray();
345- ship.SlotEx = _itemInventry[ship.SlotEx.Id];
346345 ship.Escaped = _escapedShips.Contains(ship.Id);
347346 ship.Fleet = FindFleet(ship.Id, out var idx);
348347 ship.DeckIndex = idx;
--- a/KancolleSniffer/Model/ShipStatus.cs
+++ b/KancolleSniffer/Model/ShipStatus.cs
@@ -37,8 +37,6 @@ namespace KancolleSniffer.Model
3737 public int Fuel { get; set; }
3838 public int Bull { get; set; }
3939 public int[] OnSlot { get; set; }
40- public ItemStatus[] Slot { get; set; }
41- public ItemStatus SlotEx { get; set; }
4240 public int NdockTime { get; set; }
4341 public int[] NdockItem { get; set; }
4442 public int LoS { get; set; }
@@ -52,6 +50,24 @@ namespace KancolleSniffer.Model
5250
5351 public Damage DamageLevel => CalcDamage(NowHp, MaxHp);
5452
53+ private IList<ItemStatus> _slot;
54+ private ItemStatus _slotEx;
55+ public Func<ItemStatus, ItemStatus> GetItem { get; set; } = item => item;
56+
57+ public IReadOnlyList<ItemStatus> Slot
58+ {
59+ get => _slot.Select(item => GetItem(item)).ToList();
60+ set => _slot = value.ToList();
61+ }
62+
63+ public ItemStatus SlotEx
64+ {
65+ get => GetItem(_slotEx);
66+ set => _slotEx = value;
67+ }
68+
69+ public void FreeSlot(int idx) => _slot[idx] = new ItemStatus();
70+
5571 public IEnumerable<ItemStatus> AllSlot => SlotEx.Id == 0 ? Slot : Slot.Concat(new[] {SlotEx});
5672
5773 public ShipStatus()
--- a/KancolleSniffer/TextGenerator.cs
+++ b/KancolleSniffer/TextGenerator.cs
@@ -155,7 +155,7 @@ namespace KancolleSniffer
155155 sb.Append(
156156 $"\"s{s + 1}\":{{\"id\":\"{ship.Spec.Id}\",\"lv\":{ship.Level},\"luck\":{ship.Lucky},\"items\":{{");
157157 var items = ship.Slot;
158- for (var i = 0; i < items.Length; i++)
158+ for (var i = 0; i < items.Count; i++)
159159 {
160160 var item = items[i];
161161 if (item.Empty)
--- a/KancolleSniffer/View/BattleResultPanel.cs
+++ b/KancolleSniffer/View/BattleResultPanel.cs
@@ -262,7 +262,7 @@ namespace KancolleSniffer.View
262262 private string GetEqipString(ShipStatus ship)
263263 {
264264 var result =
265- (from i in Enumerable.Range(0, ship.Slot.Length)
265+ (from i in Enumerable.Range(0, ship.Slot.Count)
266266 let item = ship.Slot[i]
267267 where !item.Empty
268268 select item.Spec.Name + (item.Spec.IsAircraft && ship.OnSlot.Length > 0 && ship.Spec.MaxEq.Length > 0
--- a/KancolleSniffer/View/FleetPanel.cs
+++ b/KancolleSniffer/View/FleetPanel.cs
@@ -98,7 +98,7 @@ namespace KancolleSniffer.View
9898 foreach (var s in fleet.Ships)
9999 {
100100 var equips = new List<Record>();
101- for (var i = 0; i < s.Slot.Length; i++)
101+ for (var i = 0; i < s.Slot.Count; i++)
102102 {
103103 var item = s.Slot[i];
104104 var onslot = s.OnSlot[i];
旧リポジトリブラウザで表示