This repository has been archived by the owner on May 11, 2018. It is now read-only.
forked from Provissy/HoppoPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cs
224 lines (201 loc) · 9.27 KB
/
Logger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Grabacr07.KanColleWrapper.Internal;
using Grabacr07.KanColleWrapper.Models;
using Grabacr07.KanColleWrapper.Models.Raw;
using Livet;
using Grabacr07.KanColleWrapper;
using System.Windows;
namespace HoppoPlugin
{
public class Logger : NotificationObject
{
public bool EnableLogging = true;
private bool waitingForShip;
private int dockid;
private readonly int[] shipmats;
public readonly string LogTimestampFormat = "yyyy-MM-dd HH:mm:ss";
private enum LogType
{
BuildItem,
BuildShip,
ShipDrop,
Materials
};
//initialize
internal Logger(KanColleProxy proxy)
{
this.shipmats = new int[5];
proxy.api_req_kousyou_createitem.TryParse<kcsapi_createitem>().Subscribe(x => this.CreateItem(x.Data, x.Request));
proxy.api_req_kousyou_createship.TryParse<kcsapi_createship>().Subscribe(x => this.CreateShip(x.Request));
proxy.api_get_member_kdock.TryParse<kcsapi_kdock[]>().Subscribe(x => this.KDock(x.Data));
proxy.api_req_sortie_battleresult.TryParse<kcsapi_battleresult>().Subscribe(x => this.BattleResult(x.Data));
proxy.api_req_combined_battle_battleresult.TryParse<kcsapi_combined_battle_battleresult>().Subscribe(x => this.CombinedBattleResult(x.Data));
//proxy.api_req_sortie_battleresult.TryParse<kcsapi_map_start>().Subscribe(x => this.MapStart(x.Data));
proxy.api_get_member_material.TryParse<kcsapi_material[]>().Subscribe(x => this.MaterialsHistory(x.Data));
proxy.api_req_hokyu_charge.TryParse<kcsapi_charge>().Subscribe(x => this.MaterialsHistory(x.Data.api_material));
proxy.api_req_kousyou_destroyship.TryParse<kcsapi_destroyship>().Subscribe(x => this.MaterialsHistory(x.Data.api_material));
}
private void CreateItem(kcsapi_createitem item, NameValueCollection req)
{
Log(LogType.BuildItem, "{0},{1},{2},{3},{4},{5},{6}",
DateTime.Now.ToString(this.LogTimestampFormat),
item.api_create_flag == 1 ? KanColleClient.Current.Master.SlotItems[item.api_slot_item.api_slotitem_id].Name : "Penguin",
KanColleClient.Current.Homeport.Organization.Fleets[1].Ships[0].Info.Name,
req["api_item1"], req["api_item2"], req["api_item3"], req["api_item4"]);
}
private void CreateShip(NameValueCollection req)
{
this.waitingForShip = true;
this.dockid = Int32.Parse(req["api_kdock_id"]);
this.shipmats[0] = Int32.Parse(req["api_item1"]);
this.shipmats[1] = Int32.Parse(req["api_item2"]);
this.shipmats[2] = Int32.Parse(req["api_item3"]);
this.shipmats[3] = Int32.Parse(req["api_item4"]);
this.shipmats[4] = Int32.Parse(req["api_item5"]);
}
private void KDock(kcsapi_kdock[] docks)
{
foreach (var dock in docks.Where(dock => this.waitingForShip && dock.api_id == this.dockid))
{
this.Log(LogType.BuildShip, "{0},{1},{2},{3},{4},{5},{6}", DateTime.Now.ToString(this.LogTimestampFormat), KanColleClient.Current.Master.Ships[dock.api_created_ship_id].Name, this.shipmats[0], this.shipmats[1], this.shipmats[2], this.shipmats[3], this.shipmats[4]);
this.waitingForShip = false;
}
}
private void CombinedBattleResult(kcsapi_combined_battle_battleresult br)
{
if (br.api_get_ship == null)
if (HoppoPluginSettings.Current.EnableNullDropLogging)
{
Log(LogType.ShipDrop, "{0},{1},{2},{3},{4}", DateTime.Now.ToString(this.LogTimestampFormat),
"无掉落",
br.api_quest_name,
br.api_enemy_info.api_deck_name,
br.api_win_rank);
}
else
{
return;
}
Log(LogType.ShipDrop, "{0},{1},{2},{3},{4}", DateTime.Now.ToString(this.LogTimestampFormat),
br.api_get_ship.api_ship_name,
br.api_quest_name,
br.api_enemy_info.api_deck_name,
br.api_win_rank);
}
private void BattleResult(kcsapi_battleresult br)
{
if (br.api_get_ship == null)
{
if (HoppoPluginSettings.Current.EnableNullDropLogging)
{
Log(LogType.ShipDrop, "{0},{1},{2},{3},{4}", DateTime.Now.ToString(this.LogTimestampFormat),
"无掉落",
br.api_quest_name,
br.api_enemy_info.api_deck_name,
br.api_win_rank);
}
}
else
{
Log(LogType.ShipDrop, "{0},{1},{2},{3},{4}", DateTime.Now.ToString(this.LogTimestampFormat),
br.api_get_ship.api_ship_name,
br.api_quest_name,
br.api_enemy_info.api_deck_name,
br.api_win_rank);
}
}
private void MaterialsHistory(kcsapi_material[] source)
{
if (source == null || source.Length != 7)
return;
Log(LogType.Materials, "{0},{1},{2},{3},{4},{5},{6},{7}",
DateTime.Now.ToString(this.LogTimestampFormat),
source[0].api_value, source[1].api_value, source[2].api_value, source[3].api_value, source[6].api_value, source[5].api_value, source[4].api_value);
}
private void MaterialsHistory(int[] source)
{
if (source == null || source.Length != 4)
return;
Log(LogType.Materials, "{0},{1},{2},{3},{4},{5},{6},{7}",
DateTime.Now.ToString(this.LogTimestampFormat),
source[0], source[1], source[2], source[3],
KanColleClient.Current.Homeport.Materials.DevelopmentMaterials,
KanColleClient.Current.Homeport.Materials.InstantRepairMaterials,
KanColleClient.Current.Homeport.Materials.InstantBuildMaterials);
}
private void Log(LogType type, string format, params object[] args)
{
try
{
string mainFolder = UniversalConstants.CurrentDirectory;
switch (type)
{
case LogType.BuildItem:
if (!File.Exists(mainFolder + "\\ItemBuildLog.csv"))
{
using (var w = File.AppendText(mainFolder + "\\ItemBuildLog.csv"))
{
w.WriteLine("Date,Result,Secretary,Fuel,Ammo,Steel,Bauxite");
}
}
using (var w = File.AppendText(mainFolder + "\\ItemBuildLog.csv"))
{
w.WriteLine(format, args);
}
break;
case LogType.BuildShip:
if (!File.Exists(mainFolder + "\\ShipBuildLog.csv"))
{
using (var w = File.AppendText(mainFolder + "\\ShipBuildLog.csv"))
{
w.WriteLine("Date,Result,Fuel,Ammo,Steel,Bauxite,# of Develop Kits");
}
}
using (var w = File.AppendText(mainFolder + "\\ShipBuildLog.csv"))
{
w.WriteLine(format, args);
}
break;
case LogType.ShipDrop:
if (!File.Exists(mainFolder + "\\DropLog.csv"))
{
using (var w = File.AppendText(mainFolder + "\\DropLog.csv"))
{
w.WriteLine("Date,Result,Operation,Enemy Fleet,Rank");
}
}
using (var w = File.AppendText(mainFolder + "\\DropLog.csv"))
{
w.WriteLine(format, args);
}
break;
case LogType.Materials:
if (!File.Exists(mainFolder + "\\MaterialsLog.csv"))
{
using (var w = File.AppendText(mainFolder + "\\MaterialsLog.csv"))
{
w.WriteLine("Date,Fuel,Ammunition,Steel,Bauxite,DevKits,Buckets,Flamethrowers");
}
}
using (var w = File.AppendText(mainFolder + "\\MaterialsLog.csv"))
{
w.WriteLine(format, args);
}
break;
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}
}