// Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
//\r
-// This program is part of KancolleSniffer.\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
-// KancolleSniffer is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
//\r
-// This program is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with this program; if not, see <http://www.gnu.org/licenses/>.\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.Collections.Generic;\r
+using System.IO;\r
using System.Linq;\r
using System.Text;\r
\r
select $"{ship.Id},{ship.Spec.ShipTypeName},{ship.Name},{ship.Level}");\r
\r
public static string GenerateItemList(IEnumerable<ItemStatus> itemList)\r
- => "区分,装備名,改修・熟練度,個数\r\n" +\r
+ => "区分,装備名,熟練度,改修,個数\r\n" +\r
string.Join("\r\n",\r
(from item in itemList\r
where item.Spec.Id != -1\r
orderby item.Spec.Type, item.Spec.Id, item.Alv, item.Level\r
group item by\r
- $"{item.Spec.TypeName},{item.Spec.Name},{(item.Level == 0 ? item.Alv == 0 ? 0 : item.Alv : item.Level)}"\r
+ $"{item.Spec.TypeName},{item.Spec.Name},{item.Alv},{item.Level}"\r
into grp\r
select grp.Key + $",{grp.Count()}"));\r
\r
- public static string GenerateFleetInfo(Sniffer sniffer)\r
+ public static string GenerateFleetData(Sniffer sniffer)\r
{\r
+ var dict = new ItemName();\r
var sb = new StringBuilder();\r
- var fn = new[] { "第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊" };\r
+ var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};\r
for (var f = 0; f < fn.Length; f++)\r
{\r
sb.Append(fn[f] + "\r\n");\r
sb.Append($"{s.Name} Lv{s.Level}");\r
foreach (var item in s.Slot.Where(item => item.Id != -1))\r
{\r
- sb.Append(" " + item.Spec.Name +\r
+ sb.Append(" " + dict[item.Spec.Name] +\r
(item.Alv == 0 ? "" : "+" + item.Alv) +\r
(item.Level == 0 ? "" : "★" + item.Level));\r
}\r
if (s.SlotEx.Id > 0)\r
{\r
var item = s.SlotEx;\r
- sb.Append(" " + item.Spec.Name);\r
+ sb.Append(" " + dict[item.Spec.Name]);\r
}\r
sb.Append("\r\n");\r
}\r
- sb.Append($"制空: {sniffer.GetFighterPower(f)} 索敵: {sniffer.GetFleetLineOfSights(f):F1}\r\n");\r
+ var fp = sniffer.GetFighterPower(f);\r
+ sb.Append($"制空: {(fp[0] == fp[1] ? fp[0].ToString() : fp[0] + "~" + fp[1])} " +\r
+ $"索敵: {sniffer.GetFleetLineOfSights(f):F1}\r\n");\r
+ }\r
+ return sb.ToString();\r
+ }\r
+\r
+ private class ItemName\r
+ {\r
+ private readonly Dictionary<string, string> _dict = new Dictionary<string, string>();\r
+\r
+ public ItemName()\r
+ {\r
+ try\r
+ {\r
+ foreach (var line in File.ReadLines("ItemName.csv"))\r
+ {\r
+ var cols = line.Split(',');\r
+ _dict[cols[0]] = cols[1];\r
+ }\r
+ }\r
+ catch (IOException)\r
+ {\r
+ }\r
+ }\r
+\r
+ public string this[string name]\r
+ {\r
+ get\r
+ {\r
+ string shortName;\r
+ return _dict.TryGetValue(name, out shortName) ? shortName : name;\r
+ }\r
+ }\r
+ }\r
+\r
+ public static string GenerateDeckBuilderData(Sniffer sniffer)\r
+ {\r
+ var sb = new StringBuilder("{\"version\": 3,");\r
+ for (var f = 0; f < ShipInfo.FleetCount; f++)\r
+ {\r
+ if (f != 0)\r
+ sb.Append(",");\r
+ sb.Append($"\"f{f + 1}\":{{");\r
+ var ships = sniffer.GetShipStatuses(f);\r
+ for (var s = 0; s < ships.Length; s++)\r
+ {\r
+ if (s != 0)\r
+ sb.Append(",");\r
+ var st = ships[s];\r
+ sb.Append($"\"s{s + 1}\":{{\"id\":\"{st.Spec.Id}\",\"lv\":{st.Level},\"luck\":{st.Lucky},\"items\":{{");\r
+ var items = st.Slot;\r
+ for (var i = 0; i < items.Length; i++)\r
+ {\r
+ var it = items[i];\r
+ if (it.Id == -1)\r
+ continue;\r
+ if (i != 0)\r
+ sb.Append(",");\r
+ sb.Append($"\"i{i + 1}\":{{\"id\":{it.Spec.Id},\"rf\":{(it.Alv != 0 && !it.Spec.IsReconSeaplane ? it.Alv : it.Level)}}}");\r
+ }\r
+ sb.Append("}}");\r
+ }\r
+ sb.Append("}");\r
}\r
+ sb.Append("}");\r
return sb.ToString();\r
}\r
}\r