コミットメタ情報

リビジョン3ade1c41e291f93021e52b50f9680c690d857628 (tree)
日時2018-07-30 18:19:40
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

装備のマスターの処理をItemMasterに分離する

変更サマリ

差分

--- a/KancolleSniffer.Test/BattleTest.cs
+++ b/KancolleSniffer.Test/BattleTest.cs
@@ -36,7 +36,7 @@ namespace KancolleSniffer.Test
3636 [TestInitialize]
3737 public void Initialize()
3838 {
39- _itemInfo = new ItemInfo();
39+ _itemInfo = new ItemInfo(new ItemMaster());
4040 _shipInfo = new ShipInfo(new ShipMaster(), _itemInfo);
4141 _battleInfo = new BattleInfo(_shipInfo, _itemInfo);
4242 }
--- a/KancolleSniffer.Test/QuestInfoTest.cs
+++ b/KancolleSniffer.Test/QuestInfoTest.cs
@@ -1087,7 +1087,7 @@ namespace KancolleSniffer.Test
10871087 [TestMethod]
10881088 public void DestroyItem_613_638_643_645_663_673_674_675_676_677_678()
10891089 {
1090- var itemInfo = new ItemInfo();
1090+ var itemInfo = new ItemInfo(new ItemMaster());
10911091 var questInfo = new QuestInfo(itemInfo, null, () => new DateTime(2015, 1, 1)) {AcceptMax = 12};
10921092
10931093 itemInfo.InjectItemSpec(new[]
--- a/KancolleSniffer/KancolleSniffer.csproj
+++ b/KancolleSniffer/KancolleSniffer.csproj
@@ -57,6 +57,7 @@
5757 <Compile Include="Model\Achievement.cs" />
5858 <Compile Include="Model\AkashiTimer.cs" />
5959 <Compile Include="Model\AlarmTimer.cs" />
60+ <Compile Include="Model\ItemMaster.cs" />
6061 <Compile Include="Model\ItemSpec.cs" />
6162 <Compile Include="Model\ItemStatus.cs" />
6263 <Compile Include="Model\ShipSpec.cs" />
--- a/KancolleSniffer/Model/ItemInfo.cs
+++ b/KancolleSniffer/Model/ItemInfo.cs
@@ -21,10 +21,8 @@ namespace KancolleSniffer.Model
2121 public class ItemInfo
2222 {
2323 private int _nowShips, _nowEquips;
24- private readonly Dictionary<int, ItemSpec> _itemSpecs = new Dictionary<int, ItemSpec>();
24+ private readonly ItemMaster _itemMaster;
2525 private readonly Dictionary<int, ItemStatus> _itemInfo = new Dictionary<int, ItemStatus>();
26- private readonly Dictionary<int, string> _useItemName = new Dictionary<int, string>();
27-
2826 public int MaxShips { get; private set; }
2927 public int MarginShips { get; set; }
3028 public bool AlarmShips { get; set; }
@@ -64,14 +62,13 @@ namespace KancolleSniffer.Model
6462
6563 public bool TooManyEquips => MaxEquips != 0 && NowEquips >= MaxEquips - MarginEquips;
6664
67- public ItemInfo()
65+ public ItemInfo(ItemMaster itemMaster)
6866 {
67+ _itemMaster = itemMaster;
6968 MarginShips = 4;
7069 MarginEquips = 10;
7170 }
7271
73- public AdditionalData AdditionalData { get; set; }
74-
7572 public void InspectBasic(dynamic json)
7673 {
7774 MaxShips = (int)json.api_max_chara;
@@ -83,36 +80,7 @@ namespace KancolleSniffer.Model
8380
8481 public void InspectMaster(dynamic json)
8582 {
86- var dict = new Dictionary<int, string>();
87- foreach (var entry in json.api_mst_slotitem_equiptype)
88- dict[(int)entry.api_id] = entry.api_name;
89- AdditionalData.LoadTpSpec();
90- foreach (var entry in json.api_mst_slotitem)
91- {
92- var type = (int)entry.api_type[2];
93- var id = (int)entry.api_id;
94- _itemSpecs[(int)entry.api_id] = new ItemSpec
95- {
96- Id = id,
97- Name = (string)entry.api_name,
98- Type = type,
99- TypeName = dict.TryGetValue(type, out var typeName) ? typeName : "不明",
100- IconType = (int)entry.api_type[3],
101- Firepower = (int)entry.api_houg,
102- AntiAir = (int)entry.api_tyku,
103- LoS = (int)entry.api_saku,
104- AntiSubmarine = (int)entry.api_tais,
105- Torpedo = (int)entry.api_raig,
106- Bomber = (int)entry.api_baku,
107- Interception = type == 48 ? (int)entry.api_houk : 0, // 局地戦闘機は回避の値が迎撃
108- AntiBomber = type == 48 ? (int)entry.api_houm : 0, // 〃命中の値が対爆
109- Distance = entry.api_distance() ? (int)entry.api_distance : 0,
110- GetItemTp = () => AdditionalData.ItemTp(id)
111- };
112- }
113- _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();
114- foreach (var entry in json.api_mst_useitem)
115- _useItemName[(int)entry.api_id] = entry.api_name;
83+ _itemMaster.InspectMaster(json);
11684 }
11785
11886 public void InspectSlotItem(dynamic json, bool full = false)
@@ -129,7 +97,7 @@ namespace KancolleSniffer.Model
12997 var id = (int)entry.api_id;
13098 _itemInfo[id] = new ItemStatus(id)
13199 {
132- Spec = _itemSpecs[(int)entry.api_slotitem_id],
100+ Spec = _itemMaster[(int)entry.api_slotitem_id],
133101 Level = entry.api_level() ? (int)entry.api_level : 0,
134102 Alv = entry.api_alv() ? (int)entry.api_alv : 0
135103 };
@@ -181,7 +149,7 @@ namespace KancolleSniffer.Model
181149 }
182150 }
183151
184- public ItemSpec GetSpecByItemId(int id) => _itemSpecs.TryGetValue(id, out var spec) ? spec : new ItemSpec();
152+ public ItemSpec GetSpecByItemId(int id) => _itemMaster[id];
185153
186154 public string GetName(int id) => GetStatus(id).Spec.Name;
187155
@@ -198,12 +166,12 @@ namespace KancolleSniffer.Model
198166
199167 public ItemStatus[] ItemList => (from e in _itemInfo where e.Key != -1 select e.Value).ToArray();
200168
201- public string GetUseItemName(int id) => _useItemName[id];
169+ public string GetUseItemName(int id) => _itemMaster.GetUseItemName(id);
202170
203171 public void InjectItemSpec(IEnumerable<ItemSpec> specs)
204172 {
205173 foreach (var spec in specs)
206- _itemSpecs.Add(spec.Id, spec);
174+ _itemMaster[spec.Id] = spec;
207175 }
208176
209177 public ItemStatus[] InjectItems(IEnumerable<int> itemIds)
@@ -211,10 +179,11 @@ namespace KancolleSniffer.Model
211179 var id = _itemInfo.Keys.Count + 1;
212180 return itemIds.Select(itemId =>
213181 {
214- if (!_itemSpecs.TryGetValue(itemId, out var spec))
182+ var spec = _itemMaster[itemId];
183+ if (spec.Id == -1)
215184 {
216185 spec = new ItemSpec {Id = itemId};
217- _itemSpecs.Add(itemId, spec);
186+ _itemMaster[itemId] = spec;
218187 }
219188 var item = new ItemStatus {Id = id++, Spec = spec};
220189 _itemInfo.Add(item.Id, item);
--- /dev/null
+++ b/KancolleSniffer/Model/ItemMaster.cs
@@ -0,0 +1,69 @@
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+using System.Collections.Generic;
17+
18+namespace KancolleSniffer.Model
19+{
20+ public class ItemMaster
21+ {
22+ private readonly Dictionary<int, ItemSpec> _itemSpecs = new Dictionary<int, ItemSpec>();
23+ private readonly Dictionary<int, string> _useItemName = new Dictionary<int, string>();
24+
25+ public AdditionalData AdditionalData { get; set; }
26+
27+ public void InspectMaster(dynamic json)
28+ {
29+ var dict = new Dictionary<int, string>();
30+ foreach (var entry in json.api_mst_slotitem_equiptype)
31+ dict[(int)entry.api_id] = entry.api_name;
32+ AdditionalData.LoadTpSpec();
33+ foreach (var entry in json.api_mst_slotitem)
34+ {
35+ var type = (int)entry.api_type[2];
36+ var id = (int)entry.api_id;
37+ _itemSpecs[(int)entry.api_id] = new ItemSpec
38+ {
39+ Id = id,
40+ Name = (string)entry.api_name,
41+ Type = type,
42+ TypeName = dict.TryGetValue(type, out var typeName) ? typeName : "不明",
43+ IconType = (int)entry.api_type[3],
44+ Firepower = (int)entry.api_houg,
45+ AntiAir = (int)entry.api_tyku,
46+ LoS = (int)entry.api_saku,
47+ AntiSubmarine = (int)entry.api_tais,
48+ Torpedo = (int)entry.api_raig,
49+ Bomber = (int)entry.api_baku,
50+ Interception = type == 48 ? (int)entry.api_houk : 0, // 局地戦闘機は回避の値が迎撃
51+ AntiBomber = type == 48 ? (int)entry.api_houm : 0, // 〃命中の値が対爆
52+ Distance = entry.api_distance() ? (int)entry.api_distance : 0,
53+ GetItemTp = () => AdditionalData.ItemTp(id)
54+ };
55+ }
56+ _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();
57+ foreach (var entry in json.api_mst_useitem)
58+ _useItemName[(int)entry.api_id] = entry.api_name;
59+ }
60+
61+ public ItemSpec this[int id]
62+ {
63+ get => _itemSpecs.TryGetValue(id, out var spec) ? spec : new ItemSpec();
64+ set => _itemSpecs[id] = value;
65+ }
66+
67+ public string GetUseItemName(int id) => _useItemName[id];
68+ }
69+}
\ No newline at end of file
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -24,7 +24,8 @@ namespace KancolleSniffer
2424 public class Sniffer
2525 {
2626 private bool _start;
27- private readonly ItemInfo _itemInfo = new ItemInfo();
27+ private readonly ItemMaster _itemMaster = new ItemMaster();
28+ private readonly ItemInfo _itemInfo;
2829 private readonly MaterialInfo _materialInfo = new MaterialInfo();
2930 private readonly QuestInfo _questInfo;
3031 private readonly MissionInfo _missionInfo = new MissionInfo();
@@ -76,6 +77,7 @@ namespace KancolleSniffer
7677 public Sniffer(bool start = false)
7778 {
7879 _start = start;
80+ _itemInfo = new ItemInfo(_itemMaster);
7981 _shipInfo = new ShipInfo(_shipMaster, _itemInfo);
8082 _conditionTimer = new ConditionTimer(_shipInfo);
8183 _dockInfo = new DockInfo(_shipInfo, _materialInfo);
@@ -95,8 +97,8 @@ namespace KancolleSniffer
9597 set
9698 {
9799 _additionalData = value;
100+ _itemMaster.AdditionalData = value;
98101 _shipMaster.AdditionalData = value;
99- _itemInfo.AdditionalData = value;
100102 }
101103 }
102104
旧リポジトリブラウザで表示