1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
15 using System.Collections.Generic;
\r
18 namespace KancolleSniffer.Model
\r
20 public class MiscTextInfo
\r
22 private readonly ShipInfo _shipInfo;
\r
23 private readonly ItemInfo _itemInfo;
\r
24 private bool _inSortie;
\r
25 private readonly Dictionary<int, int> _gaugeCount = new Dictionary<int, int>();
\r
26 private readonly Dictionary<int, string> _furniture = new Dictionary<int, string>();
\r
28 private const string GuideText =
\r
29 "[海域ゲージ情報]\r\n 海域選択画面に進むと表示します。\r\n[演習情報]\r\n 演習相手を選ぶと表示します。\r\n[獲得アイテム]\r\n 帰投したときに表示します。";
\r
31 public string Text { get; private set; } = GuideText;
\r
33 public MiscTextInfo(ShipInfo shipInfo, ItemInfo itemInfo)
\r
35 _shipInfo = shipInfo;
\r
36 _itemInfo = itemInfo;
\r
44 var text = GenerateItemGetText();
\r
45 Text = text == "" ? GuideText : "[獲得アイテム]\r\n" + text;
\r
50 public void InspectMaster(dynamic json)
\r
52 if (json.api_mst_mapinfo())
\r
54 foreach (var entry in json.api_mst_mapinfo)
\r
56 if (entry.api_required_defeat_count != null)
\r
57 _gaugeCount[(int)entry.api_id] = (int)entry.api_required_defeat_count;
\r
60 if (json.api_mst_furniture())
\r
62 foreach (var entry in json.api_mst_furniture)
\r
63 _furniture[(int)entry.api_id] = (string)entry.api_title;
\r
67 public void InspectMapInfo(dynamic json)
\r
69 Text = "[海域ゲージ]\r\n";
\r
70 foreach (var entry in json.api_map_info() ? json.api_map_info : json)
\r
72 var map = (int)entry.api_id;
\r
73 if (entry.api_eventmap())
\r
75 var eventMap = entry.api_eventmap;
\r
77 $"{map / 10}-{map % 10} : HP {(int)eventMap.api_now_maphp}/{(int)eventMap.api_max_maphp}\r\n";
\r
80 if (!entry.api_defeat_count())
\r
82 var max = entry.api_required_defeat_count()
\r
83 ? (int)entry.api_required_defeat_count
\r
85 var count = $"{max - (int)entry.api_defeat_count}/{max}";
\r
86 Text += $"{map / 10}-{map % 10} : 残り {count}\r\n";
\r
90 public void InspectPracticeEnemyInfo(dynamic json)
\r
92 Text = $"[演習情報]\r\n敵艦隊名 : {json.api_deckname}\r\n";
\r
93 var ships = json.api_deck.api_ships;
\r
94 var s1 = (int)ships[0].api_id != -1 ? (int)ships[0].api_level : 1;
\r
95 var s2 = (int)ships[1].api_id != -1 ? (int)ships[1].api_level : 1;
\r
96 var exp = PracticeExp.GetExp(s1, s2);
\r
97 var bonus = PracticeExp.TrainingCruiserBonus(_shipInfo.Fleets[0].Ships);
\r
98 Text += $"獲得経験値 : {(int)(exp * bonus)}\r\nS勝利 : {(int)((int)(exp * 1.2) * bonus)}";
\r
101 public void InspectMapNext(dynamic json)
\r
103 if (json.api_airsearch() && (int)json.api_airsearch.api_result != 0)
\r
105 var item = json.api_itemget;
\r
106 AddItemCount((int)item.api_usemst + 100, (int)item.api_id, (int)item.api_getcount);
\r
109 if (json.api_itemget())
\r
111 foreach (var item in json.api_itemget)
\r
112 AddItemCount((int)item.api_usemst, (int)item.api_id, (int)item.api_getcount);
\r
114 if (json.api_itemget_eo_result())
\r
116 var eo = json.api_itemget_eo_result;
\r
117 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);
\r
119 if (json.api_itemget_eo_comment())
\r
121 var eo = json.api_itemget_eo_comment;
\r
122 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);
\r
124 if (json.api_eventmap() && json.api_eventmap.api_itemget())
\r
126 foreach (var item in json.api_eventmap.api_itemget)
\r
128 var type = (int)item.api_type;
\r
129 type = type == 1 ? 5 :
\r
130 type == 5 ? 6 : type;
\r
131 AddItemCount(type, (int)item.api_id, (int)item.api_value);
\r
136 public void InspectMapStart(dynamic json)
\r
139 InspectMapNext(json);
\r
142 public void InspectBattleResult(dynamic json)
\r
144 if (json.api_get_eventitem())
\r
146 foreach (var item in json.api_get_eventitem)
\r
148 var type = (int)item.api_type;
\r
149 type = type == 1 ? 5 :
\r
150 type == 5 ? 6 : type;
\r
151 var id = (int)item.api_id;
\r
152 AddItemCount(type, id, (int)item.api_value);
\r
155 if (json.api_mapcell_incentive() && (int)json.api_mapcell_incentive == 1)
\r
157 foreach (var type in _items.Keys.Where(type => type > 100).ToArray())
\r
159 foreach (var id in _items[type])
\r
160 AddItemCount(type - 100, id.Key, id.Value);
\r
165 private readonly Dictionary<int, SortedDictionary<int, int>> _items =
\r
166 new Dictionary<int, SortedDictionary<int, int>>();
\r
168 private void AddItemCount(int type, int id, int count)
\r
170 if (!_items.ContainsKey(type))
\r
171 _items[type] = new SortedDictionary<int, int>();
\r
172 var dict = _items[type];
\r
173 if (!dict.ContainsKey(id))
\r
178 private string GetName(int type, int id)
\r
183 return _shipInfo.GetSpec(id).Name;
\r
185 return _itemInfo.GetSpecByItemId(id).Name;
\r
187 return new[] {"燃料", "弾薬", "鋼材", "ボーキサイト", "高速建造材", "高速修復材", "開発資材", "改修資材"}[id - 1];
\r
189 return _itemInfo.GetUseItemName(id);
\r
191 return _furniture[id];
\r
197 private string GenerateItemGetText()
\r
199 return string.Join("\r\n",
\r
200 new[] {4, 5, 3, 6, 2}.Where(_items.ContainsKey).SelectMany(type =>
\r
201 _items[type].Select(pair => GetName(type, pair.Key) + ": " + pair.Value)));
\r