コミットメタ情報

リビジョン35bd15d3fd899ac4172a16c18113fc2f0a1d7cd2 (tree)
日時2018-07-30 22:43:48
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

カウンタの実装を変更してShipInfoからItemInfoへの依存をなくす

変更サマリ

差分

--- a/KancolleSniffer.Test/BattleTest.cs
+++ b/KancolleSniffer.Test/BattleTest.cs
@@ -13,6 +13,7 @@
1313 // limitations under the License.
1414
1515 using System;
16+using System.Linq;
1617 using ExpressionToCodeLib;
1718 using KancolleSniffer.Model;
1819 using KancolleSniffer.Util;
@@ -23,7 +24,11 @@ namespace KancolleSniffer.Test
2324 [TestClass]
2425 public class BattleTest
2526 {
27+ private ItemMaster _itemMaster;
28+ private ItemInventry _itemInventry;
2629 private ItemInfo _itemInfo;
30+ private ShipMaster _shipMaster;
31+ private ShipInventry _shipInventry;
2732 private ShipInfo _shipInfo;
2833 private BattleInfo _battleInfo;
2934
@@ -33,11 +38,49 @@ namespace KancolleSniffer.Test
3338 return logfile.ReadToEnd().Split(new [] {"\r\n"}, StringSplitOptions.None);
3439 }
3540
41+ public void InjectShips(dynamic battle, dynamic item)
42+ {
43+ var deck = (int)battle.api_deck_id - 1;
44+ InjectShips(deck, (int[])battle.api_f_nowhps, (int[])battle.api_f_maxhps, (int[][])item[0]);
45+ if (battle.api_f_nowhps_combined())
46+ InjectShips(1, (int[])battle.api_f_nowhps_combined, (int[])battle.api_f_maxhps_combined,
47+ (int[][])item[1]);
48+ foreach (var enemy in (int[])battle.api_ship_ke)
49+ _shipMaster.InjectSpec(enemy);
50+ if (battle.api_ship_ke_combined())
51+ {
52+ foreach (var enemy in (int[])battle.api_ship_ke_combined)
53+ _shipMaster.InjectSpec(enemy);
54+ }
55+ _itemInfo.InjectItems(((int[][])battle.api_eSlot).SelectMany(x => x));
56+ if (battle.api_eSlot_combined())
57+ _itemInfo.InjectItems(((int[][])battle.api_eSlot_combined).SelectMany(x => x));
58+ }
59+
60+ private void InjectShips(int deck, int[] nowhps, int[] maxhps, int[][] slots)
61+ {
62+ var id = _shipInventry.MaxId + 1;
63+ var ships = nowhps.Zip(maxhps,
64+ (now, max) => new ShipStatus {Id = id++, NowHp = now, MaxHp = max}).ToArray();
65+ _shipInfo.Fleets[deck].Deck = (from ship in ships select ship.Id).ToArray();
66+ _shipInventry.Add(ships);
67+ foreach (var entry in ships.Zip(slots, (ship, slot) => new {ship, slot}))
68+ {
69+ entry.ship.Slot = _itemInfo.InjectItems(entry.slot.Take(5));
70+ if (entry.slot.Length >= 6)
71+ entry.ship.SlotEx = _itemInfo.InjectItems(entry.slot.Skip(5)).First();
72+ }
73+ }
74+
3675 [TestInitialize]
3776 public void Initialize()
3877 {
39- _itemInfo = new ItemInfo(new ItemMaster(), new ItemInventry());
40- _shipInfo = new ShipInfo(new ShipMaster(), new ShipInventry(), _itemInfo);
78+ _itemMaster = new ItemMaster();
79+ _itemInventry = new ItemInventry();
80+ _itemInfo = new ItemInfo(_itemMaster, _itemInventry);
81+ _shipInventry = new ShipInventry();
82+ _shipMaster = new ShipMaster();
83+ _shipInfo = new ShipInfo(_shipMaster, _shipInventry, _itemInventry);
4184 _battleInfo = new BattleInfo(_shipInfo, _itemInfo);
4285 }
4386
@@ -50,7 +93,7 @@ namespace KancolleSniffer.Test
5093 var logs = ReadAllLines("damecon_001");
5194 var items = JsonParser.Parse("[[[],[],[],[],[43]]]");
5295 dynamic battle = JsonParser.Parse(logs[2]);
53- _shipInfo.InjectShips(battle, items);
96+ InjectShips(battle, items);
5497 _battleInfo.InspectBattle(logs[0], logs[1], battle);
5598 dynamic result = JsonParser.Parse(logs[5]);
5699 _battleInfo.InspectBattleResult(result);
@@ -65,7 +108,7 @@ namespace KancolleSniffer.Test
65108 {
66109 var logs = ReadAllLines("midnight_002");
67110 var battle = JsonParser.Parse(logs[3]);
68- _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
111+ InjectShips(battle, JsonParser.Parse(logs[0]));
69112 _battleInfo.InspectBattle(logs[1], logs[2], battle);
70113 _battleInfo.InspectBattleResult(JsonParser.Parse(logs[6]));
71114 PAssert.That(() => _shipInfo.Fleets[0].Ships[3].NowHp == 12);
@@ -81,7 +124,7 @@ namespace KancolleSniffer.Test
81124 {
82125 var logs = ReadAllLines("friendfleet_001");
83126 var battle = Data(logs[3]);
84- _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
127+ InjectShips(battle, JsonParser.Parse(logs[0]));
85128 _battleInfo.InspectBattle(logs[1], logs[2], battle);
86129 _battleInfo.InspectBattle(logs[4], logs[5], Data(logs[6]));
87130 _battleInfo.InspectBattleResult(Data(logs[9]));
@@ -96,7 +139,7 @@ namespace KancolleSniffer.Test
96139 {
97140 var logs = ReadAllLines("ld_airbattle_001");
98141 var battle = Data(logs[3]);
99- _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
142+ InjectShips(battle, JsonParser.Parse(logs[0]));
100143 _battleInfo.InspectBattle(logs[1], logs[2], battle);
101144 _battleInfo.InspectBattleResult(Data(logs[6]));
102145 PAssert.That(() => !_battleInfo.DisplayedResultRank.IsError);
@@ -110,7 +153,7 @@ namespace KancolleSniffer.Test
110153 {
111154 var logs = ReadAllLines("ld_airbattle_002");
112155 var battle = Data(logs[3]);
113- _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
156+ InjectShips(battle, JsonParser.Parse(logs[0]));
114157 _battleInfo.InspectBattle(logs[1], logs[2], battle);
115158 _battleInfo.InspectBattleResult(Data(logs[6]));
116159 PAssert.That(() => !_battleInfo.DisplayedResultRank.IsError);
@@ -124,7 +167,7 @@ namespace KancolleSniffer.Test
124167 {
125168 var logs = ReadAllLines("damecon_002");
126169 var battle = Data(logs[3]);
127- _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
170+ InjectShips(battle, JsonParser.Parse(logs[0]));
128171 _battleInfo.InspectBattle(logs[1], logs[2], battle);
129172 _battleInfo.InspectBattle(logs[4], logs[5], Data(logs[6]));
130173 _battleInfo.InspectBattleResult(Data(logs[9]));
--- a/KancolleSniffer.Test/SnifferTest.cs
+++ b/KancolleSniffer.Test/SnifferTest.cs
@@ -566,7 +566,7 @@ namespace KancolleSniffer.Test
566566 {
567567 var sniffer = new Sniffer();
568568 SniffLogFile(sniffer, "powerup_002");
569- PAssert.That(() => sniffer.Item.NowShips == 218);
569+ PAssert.That(() => sniffer.ShipCounter.Now == 218);
570570 }
571571
572572 /// <summary>
@@ -589,10 +589,10 @@ namespace KancolleSniffer.Test
589589 {
590590 var sniffer1 = new Sniffer();
591591 SniffLogFile(sniffer1, "createitem_001");
592- PAssert.That(() => sniffer1.Item.NowEquips == 900);
592+ PAssert.That(() => sniffer1.ItemCounter.Now == 900);
593593 var sniffer2 = new Sniffer();
594594 SniffLogFile(sniffer2, "createship_001");
595- PAssert.That(() => sniffer2.Item.NowEquips == 904);
595+ PAssert.That(() => sniffer2.ItemCounter.Now == 904);
596596 }
597597
598598 /// <summary>
@@ -601,12 +601,15 @@ namespace KancolleSniffer.Test
601601 [TestMethod]
602602 public void WarnItemCount()
603603 {
604+ Action<int> func = i => { };
604605 var sniffer1 = new Sniffer();
605606 SniffLogFile(sniffer1, "item_count_001");
606- PAssert.That(() => sniffer1.Item.AlarmEquips, "出撃から母港に戻ったとき");
607+ func.Invoke(sniffer1.ItemCounter.Now); // Nowを読まないとAlarmが立たない
608+ PAssert.That(() => sniffer1.ItemCounter.Alarm, "出撃から母港に戻ったとき");
607609 var sniffer2 = new Sniffer();
608610 SniffLogFile(sniffer2, "item_count_002");
609- PAssert.That(() => sniffer2.Item.AlarmEquips, "ログインしたとき");
611+ func.Invoke(sniffer2.ItemCounter.Now);
612+ PAssert.That(() => sniffer2.ItemCounter.Alarm, "ログインしたとき");
610613 }
611614
612615 /// <summary>
@@ -768,8 +771,8 @@ namespace KancolleSniffer.Test
768771 {
769772 var sniffer = new Sniffer();
770773 SniffLogFile(sniffer, "destroyship_001");
771- PAssert.That(() => sniffer.Item.NowShips == 250);
772- PAssert.That(() => sniffer.Item.NowEquips == 1118);
774+ PAssert.That(() => sniffer.ShipCounter.Now == 250);
775+ PAssert.That(() => sniffer.ItemCounter.Now == 1118);
773776 PAssert.That(() => sniffer.Material.Current.Take(4).SequenceEqual(new[] {285615, 286250, 291010, 284744}));
774777 }
775778
@@ -793,7 +796,7 @@ namespace KancolleSniffer.Test
793796 {
794797 var sniffer = new Sniffer();
795798 SniffLogFile(sniffer, "ship2_001");
796- PAssert.That(() => sniffer.Item.NowShips == 243);
799+ PAssert.That(() => sniffer.ShipCounter.Now == 243);
797800 }
798801
799802 /// <summary>
@@ -880,8 +883,8 @@ namespace KancolleSniffer.Test
880883 var sniffer = new Sniffer();
881884 sniffer.AdditionalData.RecordNumEquips(11, "", 1);
882885 SniffLogFile(sniffer, "dropship_002");
883- PAssert.That(() => sniffer.Item.NowShips == 250);
884- PAssert.That(() => sniffer.Item.NowEquips == 1159);
886+ PAssert.That(() => sniffer.ShipCounter.Now == 250);
887+ PAssert.That(() => sniffer.ItemCounter.Now == 1159);
885888 }
886889 }
887890 }
\ No newline at end of file
--- a/KancolleSniffer/KancolleSniffer.csproj
+++ b/KancolleSniffer/KancolleSniffer.csproj
@@ -56,6 +56,7 @@
5656 <ItemGroup>
5757 <Compile Include="Model\Achievement.cs" />
5858 <Compile Include="Model\AkashiTimer.cs" />
59+ <Compile Include="Model\AlarmCounter.cs" />
5960 <Compile Include="Model\AlarmTimer.cs" />
6061 <Compile Include="Model\ItemMaster.cs" />
6162 <Compile Include="Model\Inventry.cs" />
--- a/KancolleSniffer/MainForm.cs
+++ b/KancolleSniffer/MainForm.cs
@@ -434,9 +434,9 @@ namespace KancolleSniffer
434434 private void ApplyConfig()
435435 {
436436 _listForm.TopMost = TopMost = _config.TopMost;
437- _sniffer.Item.MarginShips = _config.MarginShips;
437+ _sniffer.ShipCounter.Margin = _config.MarginShips;
438438 UpdateNumOfShips();
439- _sniffer.Item.MarginEquips = _config.MarginEquips;
439+ _sniffer.ItemCounter.Margin = _config.MarginEquips;
440440 UpdateNumOfEquips();
441441 _sniffer.Achievement.ResetHours = _config.ResetHours;
442442 labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible =
@@ -551,27 +551,27 @@ namespace KancolleSniffer
551551
552552 private void UpdateNumOfShips()
553553 {
554- var item = _sniffer.Item;
555- labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}";
556- labelNumOfShips.ForeColor = item.TooManyShips ? CUDColor.Red : Color.Black;
557- if (item.AlarmShips)
554+ var ship = _sniffer.ShipCounter;
555+ labelNumOfShips.Text = $"{ship.Now:D}/{ship.Max:D}";
556+ labelNumOfShips.ForeColor = ship.TooMany ? CUDColor.Red : Color.Black;
557+ if (ship.Alarm)
558558 {
559- var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻";
559+ var message = $"残り{ship.Rest:D}隻";
560560 _notificationManager.Enqueue("艦娘数超過", message);
561- item.AlarmShips = false;
561+ ship.Alarm = false;
562562 }
563563 }
564564
565565 private void UpdateNumOfEquips()
566566 {
567- var item = _sniffer.Item;
568- labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}";
569- labelNumOfEquips.ForeColor = item.TooManyEquips ? CUDColor.Red : Color.Black;
570- if (item.AlarmEquips)
567+ var item = _sniffer.ItemCounter;
568+ labelNumOfEquips.Text = $"{item.Now:D}/{item.Max:D}";
569+ labelNumOfEquips.ForeColor = item.TooMany ? CUDColor.Red : Color.Black;
570+ if (item.Alarm)
571571 {
572- var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個";
572+ var message = $"残り{item.Rest:D}個";
573573 _notificationManager.Enqueue("装備数超過", message);
574- item.AlarmEquips = false;
574+ item.Alarm = false;
575575 }
576576 }
577577
--- /dev/null
+++ b/KancolleSniffer/Model/AlarmCounter.cs
@@ -0,0 +1,49 @@
1+// Copyright (C) 2018 Kazuhiro Fujieda <fujieda@users.osdn.me>
2+//
3+// Licensed under the Apache License, Version 2.0 (the "License");
4+// you may not use this file except in compliance with the License.
5+// You may obtain a copy of the License at
6+//
7+// http://www.apache.org/licenses/LICENSE-2.0
8+//
9+// Unless required by applicable law or agreed to in writing, software
10+// distributed under the License is distributed on an "AS IS" BASIS,
11+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+// See the License for the specific language governing permissions and
13+// limitations under the License.
14+
15+using System;
16+
17+namespace KancolleSniffer.Model
18+{
19+ public class AlarmCounter
20+ {
21+ private readonly Func<int> _getCount;
22+ private int _now;
23+
24+ public AlarmCounter(Func<int> getCount)
25+ {
26+ _getCount = getCount;
27+ }
28+
29+ public int Max { get; set; }
30+ public int Margin { private get; set; }
31+ public bool Alarm { get; set; }
32+ public bool TooMany => Max != 0 && Now >= Max - Margin;
33+ public int Rest => Max == 0 ? 0 : Max - Now;
34+
35+ public int Now
36+ {
37+ get
38+ {
39+ var prev = _now;
40+ _now = _getCount();
41+ if (Max == 0)
42+ return _now;
43+ var limit = Max - Margin;
44+ Alarm = Alarm || prev < limit && _now >= limit;
45+ return _now;
46+ }
47+ }
48+ }
49+}
\ No newline at end of file
--- a/KancolleSniffer/Model/Inventry.cs
+++ b/KancolleSniffer/Model/Inventry.cs
@@ -45,6 +45,7 @@ namespace KancolleSniffer.Model
4545 public abstract class Inventry<T>
4646 {
4747 private readonly Dictionary<int, T> _dict = new Dictionary<int, T>();
48+ private int _inflated;
4849
4950 protected abstract T CreateDummy(int id);
5051
@@ -57,6 +58,7 @@ namespace KancolleSniffer.Model
5758 {
5859 _dict.Clear();
5960 _dict[-1] = CreateDummy(-1);
61+ _inflated = 0;
6062 }
6163
6264 public virtual T this[int id]
@@ -108,7 +110,9 @@ namespace KancolleSniffer.Model
108110 public IEnumerable<T> AllItems =>
109111 from kv in _dict where kv.Key != -1 select kv.Value;
110112
111- public int Count => _dict.Count - 1;
113+ public void InflateCount(int count) => _inflated += count;
114+
115+ public int Count => _dict.Count + _inflated - 1;
112116
113117 public int MaxId => Math.Max(_dict.Keys.Max(), 0);
114118 }
--- a/KancolleSniffer/Model/ItemInfo.cs
+++ b/KancolleSniffer/Model/ItemInfo.cs
@@ -20,63 +20,20 @@ namespace KancolleSniffer.Model
2020 {
2121 public class ItemInfo
2222 {
23- private int _nowShips, _nowEquips;
2423 private readonly ItemMaster _itemMaster;
2524 private readonly ItemInventry _itemInventry;
26- public int MaxShips { get; private set; }
27- public int MarginShips { get; set; }
28- public bool AlarmShips { get; set; }
29- public int MaxEquips { get; private set; }
30- public int MarginEquips { get; set; }
31- public bool AlarmEquips { get; set; }
32-
33- public int NowShips
34- {
35- get => _nowShips;
36- set
37- {
38- if (MaxShips != 0)
39- {
40- var limit = MaxShips - MarginShips;
41- AlarmShips = AlarmShips || _nowShips < limit && value >= limit;
42- }
43- _nowShips = value;
44- }
45- }
46-
47- public bool TooManyShips => MaxShips != 0 && NowShips >= MaxShips - MarginShips;
48-
49- public int NowEquips
50- {
51- get => _nowEquips;
52- set
53- {
54- if (MaxEquips != 0)
55- {
56- var limit = MaxEquips - MarginEquips;
57- AlarmEquips = AlarmEquips || _nowEquips < limit && value >= limit;
58- }
59- _nowEquips = value;
60- }
61- }
62-
63- public bool TooManyEquips => MaxEquips != 0 && NowEquips >= MaxEquips - MarginEquips;
25+ public AlarmCounter Counter { get; }
6426
6527 public ItemInfo(ItemMaster itemMaster, ItemInventry itemInventry)
6628 {
6729 _itemMaster = itemMaster;
6830 _itemInventry = itemInventry;
69- MarginShips = 4;
70- MarginEquips = 10;
31+ Counter = new AlarmCounter(() => _itemInventry.Count) {Margin = 10};
7132 }
7233
7334 public void InspectBasic(dynamic json)
7435 {
75- MaxShips = (int)json.api_max_chara;
76- var check = MaxEquips == 0;
77- MaxEquips = (int)json.api_max_slotitem;
78- if (check)
79- AlarmEquips = NowEquips >= MaxEquips - MarginEquips;
36+ Counter.Max = (int)json.api_max_slotitem;
8037 }
8138
8239 public void InspectMaster(dynamic json)
@@ -100,7 +57,6 @@ namespace KancolleSniffer.Model
10057 Alv = entry.api_alv() ? (int)entry.api_alv : 0
10158 };
10259 }
103- NowEquips = _itemInventry.Count;
10460 }
10561
10662 public void InspectCreateItem(dynamic json)
@@ -112,7 +68,6 @@ namespace KancolleSniffer.Model
11268
11369 public void InspectGetShip(dynamic json)
11470 {
115- NowShips += 1;
11671 if (json.api_slotitem == null) // まるゆにはスロットがない
11772 return;
11873 InspectSlotItem(json.api_slotitem);
@@ -141,7 +96,6 @@ namespace KancolleSniffer.Model
14196 private void DeleteItems(IEnumerable<int> ids)
14297 {
14398 _itemInventry.Remove(ids);
144- NowEquips = _itemInventry.Count;
14599 }
146100
147101 public ItemSpec GetSpecByItemId(int id) => _itemMaster[id];
--- a/KancolleSniffer/Model/ShipInfo.cs
+++ b/KancolleSniffer/Model/ShipInfo.cs
@@ -28,10 +28,11 @@ namespace KancolleSniffer.Model
2828 private readonly Fleet[] _fleets;
2929 private readonly ShipMaster _shipMaster;
3030 private readonly ShipInventry _shipInventry;
31- private readonly ItemInfo _itemInfo;
31+ private readonly ItemInventry _itemInventry;
3232 private readonly List<int> _escapedShips = new List<int>();
3333 private ShipStatus[] _battleResult = new ShipStatus[0];
3434 private readonly NumEquipsChecker _numEquipsChecker = new NumEquipsChecker();
35+ public AlarmCounter Counter { get; }
3536 public int HqLevel { get; private set; }
3637 public ShipStatusPair[] BattleResultDiff { get; private set; } = new ShipStatusPair[0];
3738 public bool IsBattleResultError => BattleResultDiff.Length > 0;
@@ -63,12 +64,13 @@ namespace KancolleSniffer.Model
6364 }
6465 }
6566
66- public ShipInfo(ShipMaster shipMaster, ShipInventry shipInventry, ItemInfo itemInfo)
67+ public ShipInfo(ShipMaster shipMaster, ShipInventry shipInventry, ItemInventry itemInventry)
6768 {
6869 _shipMaster = shipMaster;
6970 _shipInventry = shipInventry;
7071 _fleets = Enumerable.Range(0, FleetCount).Select((x, i) => new Fleet(this, i)).ToArray();
71- _itemInfo = itemInfo;
72+ _itemInventry = itemInventry;
73+ Counter = new AlarmCounter(() => _shipInventry.Count){Margin = 4};
7274 }
7375
7476 public void InspectMaster(dynamic json)
@@ -89,7 +91,6 @@ namespace KancolleSniffer.Model
8991 InspectBasic(json.api_basic);
9092 if (json.api_combined_flag())
9193 _fleets[0].CombinedType = _fleets[1].CombinedType = (CombinedType)(int)json.api_combined_flag;
92- _itemInfo.NowShips = ((object[])json.api_ship).Length;
9394 VerifyBattleResult();
9495 }
9596 else if (json.api_data()) // ship2
@@ -105,10 +106,10 @@ namespace KancolleSniffer.Model
105106 // ship_deckでドロップ艦を反映する
106107 if (DropShipId != -1)
107108 {
108- _itemInfo.NowShips++;
109+ _shipInventry.InflateCount(1);
109110 var num = _shipMaster.GetSpec(DropShipId).NumEquips;
110111 if (num > 0)
111- _itemInfo.NowEquips += num;
112+ _itemInventry.InflateCount(num);
112113 }
113114 }
114115 else if (json.api_ship()) // getshipとpowerup
@@ -189,6 +190,7 @@ namespace KancolleSniffer.Model
189190 private void InspectBasic(dynamic json)
190191 {
191192 HqLevel = (int)json.api_level;
193+ Counter.Max = (int)json.api_max_chara;
192194 }
193195
194196 public void InspectCharge(dynamic json)
@@ -263,8 +265,7 @@ namespace KancolleSniffer.Model
263265 var ships = values["api_id_items"].Split(',').Select(int.Parse).ToArray();
264266 if (!_shipInventry.Contains(ships[0])) // 二重に実行された場合
265267 return;
266- _itemInfo.NowShips -= ships.Length;
267- _itemInfo.DeleteItems(ships.SelectMany(id => _shipInventry[id].Slot).ToArray());
268+ _itemInventry.Remove(ships.SelectMany(id => _shipInventry[id].Slot));
268269 _shipInventry.Remove(ships);
269270 InspectDeck(json.api_deck);
270271 InspectShip(json);
@@ -288,9 +289,8 @@ namespace KancolleSniffer.Model
288289 var delitem = int.Parse(values["api_slot_dest_flag"] ?? "0") == 1;
289290 foreach (var id in values["api_ship_id"].Split(',').Select(int.Parse))
290291 {
291- _itemInfo.NowShips--;
292292 if (delitem)
293- _itemInfo.DeleteItems(_shipInventry[id].AllSlot);
293+ _itemInventry.Remove(_shipInventry[id].AllSlot);
294294 var of = FindFleet(id, out var oi);
295295 if (of != null)
296296 WithdrowShip(of, oi);
@@ -341,8 +341,8 @@ namespace KancolleSniffer.Model
341341 {
342342 if (ship.Empty)
343343 return ship;
344- ship.Slot = ship.Slot.Select(item => _itemInfo.GetStatus(item.Id)).ToArray();
345- ship.SlotEx = _itemInfo.GetStatus(ship.SlotEx.Id);
344+ ship.Slot = ship.Slot.Select(item => _itemInventry[item.Id]).ToArray();
345+ ship.SlotEx = _itemInventry[ship.SlotEx.Id];
346346 ship.Escaped = _escapedShips.Contains(ship.Id);
347347 ship.Fleet = FindFleet(ship.Id, out var idx);
348348 ship.DeckIndex = idx;
@@ -354,8 +354,8 @@ namespace KancolleSniffer.Model
354354 foreach (var ship in _shipInventry.AllShips)
355355 {
356356 foreach (var item in ship.Slot)
357- _itemInfo.GetStatus(item.Id).Holder = ship;
358- _itemInfo.GetStatus(ship.SlotEx.Id).Holder = ship;
357+ _itemInventry[item.Id].Holder = ship;
358+ _itemInventry[ship.SlotEx.Id].Holder = ship;
359359 }
360360 }
361361
@@ -395,39 +395,5 @@ namespace KancolleSniffer.Model
395395 {
396396 _escapedShips.Clear();
397397 }
398-
399- public void InjectShips(dynamic battle, dynamic item)
400- {
401- var deck = (int)battle.api_deck_id - 1;
402- InjectShips(deck, (int[])battle.api_f_nowhps, (int[])battle.api_f_maxhps, (int[][])item[0]);
403- if (battle.api_f_nowhps_combined())
404- InjectShips(1, (int[])battle.api_f_nowhps_combined, (int[])battle.api_f_maxhps_combined,
405- (int[][])item[1]);
406- foreach (var enemy in (int[])battle.api_ship_ke)
407- _shipMaster.InjectSpec(enemy);
408- if (battle.api_ship_ke_combined())
409- {
410- foreach (var enemy in (int[])battle.api_ship_ke_combined)
411- _shipMaster.InjectSpec(enemy);
412- }
413- _itemInfo.InjectItems(((int[][])battle.api_eSlot).SelectMany(x => x));
414- if (battle.api_eSlot_combined())
415- _itemInfo.InjectItems(((int[][])battle.api_eSlot_combined).SelectMany(x => x));
416- }
417-
418- private void InjectShips(int deck, int[] nowhps, int[] maxhps, int[][] slots)
419- {
420- var id = _shipInventry.MaxId + 1;
421- var ships = nowhps.Zip(maxhps,
422- (now, max) => new ShipStatus {Id = id++, NowHp = now, MaxHp = max}).ToArray();
423- _fleets[deck].Deck = (from ship in ships select ship.Id).ToArray();
424- _shipInventry.Add(ships);
425- foreach (var entry in ships.Zip(slots, (ship, slot) => new {ship, slot}))
426- {
427- entry.ship.Slot = _itemInfo.InjectItems(entry.slot.Take(5));
428- if (entry.slot.Length >= 6)
429- entry.ship.SlotEx = _itemInfo.InjectItems(entry.slot.Skip(5)).First();
430- }
431- }
432398 }
433399 }
\ No newline at end of file
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -80,7 +80,7 @@ namespace KancolleSniffer
8080 {
8181 _start = start;
8282 _itemInfo = new ItemInfo(_itemMaster, _itemInventry);
83- _shipInfo = new ShipInfo(_shipMaster, _shipInventry, _itemInfo);
83+ _shipInfo = new ShipInfo(_shipMaster, _shipInventry, _itemInventry);
8484 _conditionTimer = new ConditionTimer(_shipInfo);
8585 _dockInfo = new DockInfo(_shipInfo, _materialInfo);
8686 _akashiTimer = new AkashiTimer(_shipInfo, _dockInfo, _presetDeck);
@@ -583,6 +583,8 @@ namespace KancolleSniffer
583583
584584 public AlarmTimer[] KDock => _dockInfo.KDock;
585585
586+ public AlarmCounter ItemCounter => _itemInfo.Counter;
587+
586588 public ItemInfo Item => _itemInfo;
587589
588590 public MaterialInfo Material => _materialInfo;
@@ -597,6 +599,8 @@ namespace KancolleSniffer
597599
598600 public int[] GetConditionNotice(DateTime prev, DateTime now) => _conditionTimer.GetNotice(prev, now);
599601
602+ public AlarmCounter ShipCounter => _shipInfo.Counter;
603+
600604 public Fleet[] Fleets => _shipInfo.Fleets;
601605
602606 public ShipInfo.ShipStatusPair[] BattleResultStatusDiff => _shipInfo.BattleResultDiff;
旧リポジトリブラウザで表示