Skip to content

Commit ce155ac

Browse files
author
dermow
committed
Add divcard tracking feature
1 parent 01fe183 commit ce155ac

10 files changed

Lines changed: 397148 additions & 182 deletions

File tree

.github/upgrades/assessment.csv

Lines changed: 17372 additions & 0 deletions
Large diffs are not rendered by default.

.github/upgrades/assessment.json

Lines changed: 378842 additions & 0 deletions
Large diffs are not rendered by default.

.github/upgrades/assessment.md

Lines changed: 284 additions & 0 deletions
Large diffs are not rendered by default.

TraXile/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
3232
// indem Sie "*" wie unten gezeigt eingeben:
3333
//[assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("2.2.3")]
35-
[assembly: AssemblyFileVersion("2.2.3")]
34+
[assembly: AssemblyVersion("2.2.4")]
35+
[assembly: AssemblyFileVersion("2.2.4")]
3636

3737
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config")]

TraXile/TrX_CoreLogic.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class TrX_CoreLogic
4949
// Event: initialization of history is finished
5050
public event Trx_GenericEventHandler OnHistoryInitialized;
5151

52+
// Event: DivCardDrawn
53+
public event Trx_GenericEventHandler OnDivCardDrawn;
54+
5255
// Event: called when an activity is finished
5356
public event TrX_ActivityEventHandler OnActivityFinished;
5457

@@ -3026,6 +3029,9 @@ private void HandleSingleEvent(TrX_TrackingEvent ev)
30263029
_currentActivity.AddTag("t16.5");
30273030
}
30283031
break;
3032+
case EVENT_TYPES.DIV_CARD_DRAWN:
3033+
_HandleDivCardDraw(ev);
3034+
break;
30293035
}
30303036

30313037
if (_eventQueueInitizalized)
@@ -3040,6 +3046,26 @@ private void HandleSingleEvent(TrX_TrackingEvent ev)
30403046
}
30413047
}
30423048

3049+
private void _HandleDivCardDraw(TrX_TrackingEvent ev)
3050+
{
3051+
try
3052+
{
3053+
string sDivCard = ev.LogLine.Split(new string[] { "{" }, StringSplitOptions.None)[1].Replace("}", "");
3054+
3055+
_dataBackend.AddDivCardEntry(sDivCard, ((DateTimeOffset)ev.EventTime).ToUnixTimeSeconds());
3056+
_log.Debug($"drawn divination card: {sDivCard}");
3057+
3058+
OnDivCardDrawn(new TrX_CoreLogicGenericEventArgs(this));
3059+
3060+
}
3061+
catch (Exception ex)
3062+
{
3063+
_log.Error($"Error handling div card draw event: {ex.Message}.");
3064+
_log.Debug(ex.ToString());
3065+
}
3066+
3067+
}
3068+
30433069
/// <summary>
30443070
/// Increment a stat with an defined value. Updates the database.
30453071
///

TraXile/TrX_DataBackend.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using log4net;
34
using Microsoft.Data.Sqlite;
45

@@ -232,6 +233,59 @@ public void Patch()
232233
catch
233234
{
234235
}
236+
237+
238+
// Update 2.2.4
239+
try
240+
{
241+
cmd = _dbConnection.CreateCommand();
242+
cmd.CommandText = "create table if not exists tx_divcards" +
243+
"(id INTEGER PRIMARY KEY," +
244+
"timestamp INTEGER, " +
245+
"divcard TEXT)";
246+
cmd.ExecuteNonQuery();
247+
// cmd = _dbConnection.CreateCommand();
248+
// cmd.CommandText = "create unique index if not exists kvstore on tx_kvstore(key)";
249+
_log.Info("PatchDatabase 2.2.4 -> " + cmd.CommandText);
250+
// DoNonQuery("INSERT INTO tx_kvstore (key, value) VALUES ('last_hash', '0')", false);
251+
}
252+
catch
253+
{
254+
}
255+
}
256+
257+
public List<KeyValuePair<string,int>> GetDivCardStats(DateTime filterFrom, DateTime filterTo)
258+
{
259+
List<KeyValuePair<string, int>> divCardStats = new List<KeyValuePair<string, int>>();
260+
261+
SqliteDataReader reader;
262+
reader = GetSQLReader(string.Format("SELECT divcard, COUNT(*) FROM tx_divcards WHERE timestamp >= {0} AND timestamp <= {1} GROUP BY divcard ORDER BY COUNT(*) DESC", ((DateTimeOffset)filterFrom).ToUnixTimeSeconds(), ((DateTimeOffset)filterTo).ToUnixTimeSeconds()));
263+
while (reader.Read())
264+
{
265+
divCardStats.Add(new KeyValuePair<string, int>(reader.GetString(0), reader.GetInt32(1)));
266+
}
267+
return divCardStats;
268+
269+
}
270+
271+
public DateTime GetFirstDivCardDraw(string divcard, DateTime from, DateTime to)
272+
{ SqliteDataReader reader;
273+
reader = GetSQLReader(string.Format("SELECT timestamp FROM tx_divcards WHERE divcard = '{0}' AND timestamp >= {1} AND timestamp <= {2} ORDER BY timestamp ASC LIMIT 1", divcard, ((DateTimeOffset)from).ToUnixTimeSeconds(), ((DateTimeOffset)to).ToUnixTimeSeconds()));
274+
reader.Read();
275+
return DateTimeOffset.FromUnixTimeSeconds(reader.GetInt64(0)).DateTime;
276+
}
277+
278+
public DateTime GetLatestDivCardDraw(string divcard, DateTime from, DateTime to)
279+
{
280+
SqliteDataReader reader;
281+
reader = GetSQLReader(string.Format("SELECT timestamp FROM tx_divcards WHERE divcard = '{0}' AND timestamp >= {1} AND timestamp <= {2} ORDER BY timestamp DESC LIMIT 1", divcard, ((DateTimeOffset)from).ToUnixTimeSeconds(), ((DateTimeOffset)to).ToUnixTimeSeconds()));
282+
reader.Read();
283+
return DateTimeOffset.FromUnixTimeSeconds(reader.GetInt64(0)).DateTime;
284+
}
285+
286+
public void AddDivCardEntry(string divcard, long timestamp)
287+
{
288+
DoNonQuery(string.Format("INSERT INTO tx_divcards (timestamp, divcard) VALUES ({0}, '{1}')", timestamp, divcard));
235289
}
236290

237291
/// <summary>

TraXile/TrX_EventMapping.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public enum EVENT_TYPES
6363
TRIALMASTER_ENCOUNTERED,
6464
TRIALMASTER_PLAYER_LOSS,
6565
ZANA_ORIGINATOR_SPEAK,
66-
HEIST_MEMBER_INTRODUCED
66+
HEIST_MEMBER_INTRODUCED,
67+
DIV_CARD_DRAWN
6768
}
6869

6970
public class TrX_EventMapping
@@ -325,6 +326,10 @@ public TrX_EventMapping()
325326

326327
{"Strange Voice: So be it.", EVENT_TYPES.SIMULACRUM_FULLCLEAR },
327328

329+
// DivCards
330+
{"Card drawn from the deck:", EVENT_TYPES.DIV_CARD_DRAWN },
331+
332+
328333
// Encounters
329334
{"Strange Voice: ", EVENT_TYPES.DELIRIUM_ENCOUNTER },
330335
{"The Nameless Seer has appeared nearby.", EVENT_TYPES.NAMELESSSEER_ENCOUNTER },

0 commit comments

Comments
 (0)