--- /dev/null
+// Copyright (C) 2017 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 ExpressionToCodeLib;\r
+using Microsoft.VisualStudio.TestTools.UnitTesting;\r
+\r
+namespace KancolleSniffer.Test\r
+{\r
+ [TestClass]\r
+ public class BattleTest\r
+ {\r
+ private ItemInfo _itemInfo;\r
+ private ShipInfo _shipInfo;\r
+ private BattleInfo _battleInfo;\r
+\r
+ private string[] ReadAllLines(string log)\r
+ {\r
+ using (var logfile = SnifferTest.OpenLogFile(log))\r
+ return logfile.ReadToEnd().Split(new [] {"\r\n"}, StringSplitOptions.None);\r
+ }\r
+\r
+ [TestInitialize]\r
+ public void Initialize()\r
+ {\r
+ _itemInfo = new ItemInfo();\r
+ _shipInfo = new ShipInfo(_itemInfo);\r
+ _battleInfo = new BattleInfo(_shipInfo, _itemInfo);\r
+ }\r
+\r
+ [TestMethod]\r
+ public void Damecon()\r
+ {\r
+ var logs = ReadAllLines("damecon_001");\r
+ var items = _itemInfo.InjectItems(new[]{43});\r
+ dynamic battle = JsonParser.Parse(logs[2]);\r
+ _shipInfo.InjectShips(battle);\r
+ _shipInfo.GetStatus(5).Slot = new []{items[0]};\r
+ _battleInfo.InspectBattle(battle, logs[0]);\r
+ dynamic result = JsonParser.Parse(logs[5]);\r
+ _battleInfo.InspectBattleResult(result);\r
+ PAssert.That(() => _shipInfo.GetStatus(5).NowHp == 31);\r
+ }\r
+ }\r
+}
\ No newline at end of file
<ItemGroup>\r
<Compile Include="Ascii85Test.cs" />\r
<Compile Include="BattleLogProcessorTest.cs" />\r
+ <Compile Include="BattleTest.cs" />\r
<Compile Include="JsonTest.cs" />\r
<Compile Include="ShipLabelTest.cs" />\r
<Compile Include="SnifferTest.cs" />\r
-Subproject commit 17f72eb97f79b2e51c183a4bc2c8a91d4db99445
+Subproject commit f5e1607ccd2dbfb825c413ac0f3255cc04e0f486
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
+\r
+ public ItemStatus[] InjectItems(int[] itemIds)\r
+ {\r
+ var id = _itemInfo.Keys.Count + 1;\r
+ return itemIds.Select(itemId =>\r
+ {\r
+ if (!_itemSpecs.TryGetValue(itemId, out var spec))\r
+ {\r
+ spec = new ItemSpec {Id = itemId};\r
+ _itemSpecs.Add(itemId, spec);\r
+ }\r
+ var item = new ItemStatus {Id = id++, Spec = spec};\r
+ _itemInfo.Add(item.Id, item);\r
+ return item;\r
+ }).ToArray();\r
+ }\r
}\r
}
\ No newline at end of file
{\r
set => _shipMaster.UseOldEnemyId = value;\r
}\r
+\r
+ public void InjectShips(dynamic battle)\r
+ {\r
+ var deck = (int)battle.api_deck_id;\r
+ var id = 1;\r
+ var ships = ((int[])battle.api_f_nowhps).Zip((int[])battle.api_f_maxhps,\r
+ (now, max) => new ShipStatus {Id = id++, NowHp = now, MaxHp = max}).ToArray();\r
+ _decks[deck - 1] = (from ship in ships select ship.Id).ToArray();\r
+ foreach (var ship in ships)\r
+ _shipInfo[ship.Id] = ship;\r
+ if (battle.api_f_nowhps_combined())\r
+ {\r
+ var guards = ((int[])battle.api_f_nowhps_combined).Zip((int[])battle.api_f_maxhps_combined,\r
+ (now, max) => new ShipStatus {Id = id++, NowHp = now, MaxHp = max}).ToArray();\r
+ _decks[1] = (from ship in guards select ship.Id).ToArray();\r
+ foreach (var ship in guards)\r
+ _shipInfo[ship.Id] = ship;\r
+ }\r
+ foreach (var enemy in (int[])battle.api_ship_ke)\r
+ _shipMaster[enemy] = new ShipSpec {Id = enemy};\r
+ if (battle.api_ship_ke_combined())\r
+ {\r
+ foreach (var enemy in (int[])battle.api_ship_ke_combined)\r
+ _shipMaster[enemy] = new ShipSpec {Id = enemy};\r
+ }\r
+ }\r
}\r
}
\ No newline at end of file
return name + "(" + flagship + ")";\r
}\r
\r
- public ShipSpec this[int id] => _shipSpecs[id];\r
+ public ShipSpec this[int id]\r
+ {\r
+ get => _shipSpecs[id];\r
+ set => _shipSpecs[id] = value;\r
+ }\r
\r
private void SetRemodelBaseAndStep()\r
{\r