[TestInitialize]\r
public void Initialize()\r
{\r
- _itemInfo = new ItemInfo();\r
+ _itemInfo = new ItemInfo(new ItemMaster());\r
_shipInfo = new ShipInfo(new ShipMaster(), _itemInfo);\r
_battleInfo = new BattleInfo(_shipInfo, _itemInfo);\r
}\r
[TestMethod]\r
public void DestroyItem_613_638_643_645_663_673_674_675_676_677_678()\r
{\r
- var itemInfo = new ItemInfo();\r
+ var itemInfo = new ItemInfo(new ItemMaster());\r
var questInfo = new QuestInfo(itemInfo, null, () => new DateTime(2015, 1, 1)) {AcceptMax = 12};\r
\r
itemInfo.InjectItemSpec(new[]\r
<Compile Include="Model\Achievement.cs" />\r
<Compile Include="Model\AkashiTimer.cs" />\r
<Compile Include="Model\AlarmTimer.cs" />\r
+ <Compile Include="Model\ItemMaster.cs" />\r
<Compile Include="Model\ItemSpec.cs" />\r
<Compile Include="Model\ItemStatus.cs" />\r
<Compile Include="Model\ShipSpec.cs" />\r
public class ItemInfo\r
{\r
private int _nowShips, _nowEquips;\r
- private readonly Dictionary<int, ItemSpec> _itemSpecs = new Dictionary<int, ItemSpec>();\r
+ private readonly ItemMaster _itemMaster;\r
private readonly Dictionary<int, ItemStatus> _itemInfo = new Dictionary<int, ItemStatus>();\r
- private readonly Dictionary<int, string> _useItemName = new Dictionary<int, string>();\r
-\r
public int MaxShips { get; private set; }\r
public int MarginShips { get; set; }\r
public bool AlarmShips { get; set; }\r
\r
public bool TooManyEquips => MaxEquips != 0 && NowEquips >= MaxEquips - MarginEquips;\r
\r
- public ItemInfo()\r
+ public ItemInfo(ItemMaster itemMaster)\r
{\r
+ _itemMaster = itemMaster;\r
MarginShips = 4;\r
MarginEquips = 10;\r
}\r
\r
- public AdditionalData AdditionalData { get; set; }\r
-\r
public void InspectBasic(dynamic json)\r
{\r
MaxShips = (int)json.api_max_chara;\r
\r
public void InspectMaster(dynamic json)\r
{\r
- var dict = new Dictionary<int, string>();\r
- foreach (var entry in json.api_mst_slotitem_equiptype)\r
- dict[(int)entry.api_id] = entry.api_name;\r
- AdditionalData.LoadTpSpec();\r
- foreach (var entry in json.api_mst_slotitem)\r
- {\r
- var type = (int)entry.api_type[2];\r
- var id = (int)entry.api_id;\r
- _itemSpecs[(int)entry.api_id] = new ItemSpec\r
- {\r
- Id = id,\r
- Name = (string)entry.api_name,\r
- Type = type,\r
- TypeName = dict.TryGetValue(type, out var typeName) ? typeName : "不明",\r
- IconType = (int)entry.api_type[3],\r
- Firepower = (int)entry.api_houg,\r
- AntiAir = (int)entry.api_tyku,\r
- LoS = (int)entry.api_saku,\r
- AntiSubmarine = (int)entry.api_tais,\r
- Torpedo = (int)entry.api_raig,\r
- Bomber = (int)entry.api_baku,\r
- Interception = type == 48 ? (int)entry.api_houk : 0, // 局地戦闘機は回避の値が迎撃\r
- AntiBomber = type == 48 ? (int)entry.api_houm : 0, // 〃命中の値が対爆\r
- Distance = entry.api_distance() ? (int)entry.api_distance : 0,\r
- GetItemTp = () => AdditionalData.ItemTp(id)\r
- };\r
- }\r
- _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();\r
- foreach (var entry in json.api_mst_useitem)\r
- _useItemName[(int)entry.api_id] = entry.api_name;\r
+ _itemMaster.InspectMaster(json);\r
}\r
\r
public void InspectSlotItem(dynamic json, bool full = false)\r
var id = (int)entry.api_id;\r
_itemInfo[id] = new ItemStatus(id)\r
{\r
- Spec = _itemSpecs[(int)entry.api_slotitem_id],\r
+ Spec = _itemMaster[(int)entry.api_slotitem_id],\r
Level = entry.api_level() ? (int)entry.api_level : 0,\r
Alv = entry.api_alv() ? (int)entry.api_alv : 0\r
};\r
}\r
}\r
\r
- public ItemSpec GetSpecByItemId(int id) => _itemSpecs.TryGetValue(id, out var spec) ? spec : new ItemSpec();\r
+ public ItemSpec GetSpecByItemId(int id) => _itemMaster[id];\r
\r
public string GetName(int id) => GetStatus(id).Spec.Name;\r
\r
\r
public ItemStatus[] ItemList => (from e in _itemInfo where e.Key != -1 select e.Value).ToArray();\r
\r
- public string GetUseItemName(int id) => _useItemName[id];\r
+ public string GetUseItemName(int id) => _itemMaster.GetUseItemName(id);\r
\r
public void InjectItemSpec(IEnumerable<ItemSpec> specs)\r
{\r
foreach (var spec in specs)\r
- _itemSpecs.Add(spec.Id, spec);\r
+ _itemMaster[spec.Id] = spec;\r
}\r
\r
public ItemStatus[] InjectItems(IEnumerable<int> itemIds)\r
var id = _itemInfo.Keys.Count + 1;\r
return itemIds.Select(itemId =>\r
{\r
- if (!_itemSpecs.TryGetValue(itemId, out var spec))\r
+ var spec = _itemMaster[itemId];\r
+ if (spec.Id == -1)\r
{\r
spec = new ItemSpec {Id = itemId};\r
- _itemSpecs.Add(itemId, spec);\r
+ _itemMaster[itemId] = spec;\r
}\r
var item = new ItemStatus {Id = id++, Spec = spec};\r
_itemInfo.Add(item.Id, item);\r
--- /dev/null
+// Copyright (C) 2018 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+\r
+namespace KancolleSniffer.Model\r
+{\r
+ public class ItemMaster\r
+ {\r
+ private readonly Dictionary<int, ItemSpec> _itemSpecs = new Dictionary<int, ItemSpec>();\r
+ private readonly Dictionary<int, string> _useItemName = new Dictionary<int, string>();\r
+\r
+ public AdditionalData AdditionalData { get; set; }\r
+\r
+ public void InspectMaster(dynamic json)\r
+ {\r
+ var dict = new Dictionary<int, string>();\r
+ foreach (var entry in json.api_mst_slotitem_equiptype)\r
+ dict[(int)entry.api_id] = entry.api_name;\r
+ AdditionalData.LoadTpSpec();\r
+ foreach (var entry in json.api_mst_slotitem)\r
+ {\r
+ var type = (int)entry.api_type[2];\r
+ var id = (int)entry.api_id;\r
+ _itemSpecs[(int)entry.api_id] = new ItemSpec\r
+ {\r
+ Id = id,\r
+ Name = (string)entry.api_name,\r
+ Type = type,\r
+ TypeName = dict.TryGetValue(type, out var typeName) ? typeName : "不明",\r
+ IconType = (int)entry.api_type[3],\r
+ Firepower = (int)entry.api_houg,\r
+ AntiAir = (int)entry.api_tyku,\r
+ LoS = (int)entry.api_saku,\r
+ AntiSubmarine = (int)entry.api_tais,\r
+ Torpedo = (int)entry.api_raig,\r
+ Bomber = (int)entry.api_baku,\r
+ Interception = type == 48 ? (int)entry.api_houk : 0, // 局地戦闘機は回避の値が迎撃\r
+ AntiBomber = type == 48 ? (int)entry.api_houm : 0, // 〃命中の値が対爆\r
+ Distance = entry.api_distance() ? (int)entry.api_distance : 0,\r
+ GetItemTp = () => AdditionalData.ItemTp(id)\r
+ };\r
+ }\r
+ _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();\r
+ foreach (var entry in json.api_mst_useitem)\r
+ _useItemName[(int)entry.api_id] = entry.api_name;\r
+ }\r
+\r
+ public ItemSpec this[int id]\r
+ {\r
+ get => _itemSpecs.TryGetValue(id, out var spec) ? spec : new ItemSpec();\r
+ set => _itemSpecs[id] = value;\r
+ }\r
+\r
+ public string GetUseItemName(int id) => _useItemName[id];\r
+ }\r
+}
\ No newline at end of file
public class Sniffer\r
{\r
private bool _start;\r
- private readonly ItemInfo _itemInfo = new ItemInfo();\r
+ private readonly ItemMaster _itemMaster = new ItemMaster();\r
+ private readonly ItemInfo _itemInfo;\r
private readonly MaterialInfo _materialInfo = new MaterialInfo();\r
private readonly QuestInfo _questInfo;\r
private readonly MissionInfo _missionInfo = new MissionInfo();\r
public Sniffer(bool start = false)\r
{\r
_start = start;\r
+ _itemInfo = new ItemInfo(_itemMaster);\r
_shipInfo = new ShipInfo(_shipMaster, _itemInfo);\r
_conditionTimer = new ConditionTimer(_shipInfo);\r
_dockInfo = new DockInfo(_shipInfo, _materialInfo);\r
set\r
{\r
_additionalData = value;\r
+ _itemMaster.AdditionalData = value;\r
_shipMaster.AdditionalData = value;\r
- _itemInfo.AdditionalData = value;\r
}\r
}\r
\r