Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
crebier-corentin committed Oct 9, 2019
0 parents commit 35dbff9
Show file tree
Hide file tree
Showing 13 changed files with 990 additions and 0 deletions.
426 changes: 426 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions Armello/Event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace ArmelloLogTools.Armello
{
public abstract class Event
{
public abstract EventType Type { get; }
}

public class LoadGameEvent : Event
{
public override EventType Type => EventType.LoadGame;
}

public class LoadPlayerEvent : Event
{
public override EventType Type => EventType.LoadPlayer;

public Player Player;

public LoadPlayerEvent(int id, string name, string heroHexId)
{
Player = new Player(id, name, heroHexId);
}
}

public class StartTurnEvent : Event
{
public override EventType Type => EventType.StartTurn;

public int PlayerId;

public StartTurnEvent(int playerId)
{
PlayerId = playerId;
}
}

public class CompleteQuestEvent : Event
{
public override EventType Type => EventType.CompleteQuest;
}
}
12 changes: 12 additions & 0 deletions Armello/EventType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ArmelloLogTools.Armello
{
public enum EventType
{
LoadGame,
LoadPlayer,

StartTurn,

CompleteQuest
}
}
87 changes: 87 additions & 0 deletions Armello/Hero.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Collections.Generic;

namespace ArmelloLogTools.Armello
{
public enum Hero
{
//Wolf
Thane,
River,
Magna,
Fang,

//Rat
Mercurio,
Zosha,
Sargon,
Griotte,

//Bear
Sana,
Brun,
Ghor,
Yordana,

//Rabbit
Amber,
Barnaby,
Elyssia,
Hagrave,

//Bandit
Twiss,
Sylas,
Horace,
Scarlet,

//Dragon
Volodar,
Agniya,
Oxana,
Nazar,

Unknown
}

public static class HeroHelpers
{
public static readonly Dictionary<string, Hero> HeroesHexId = new Dictionary<string, Hero>()
{
//Wolf
["0x9AC46BF3"] = Hero.Thane,
["0x9AC46BF4"] = Hero.River,
["0x9AC46BF5"] = Hero.Magna,
["0x9AC46BF6"] = Hero.Fang,
//Rat
["0x04B158C6"] = Hero.Mercurio,
["0x04B158C7"] = Hero.Zosha,
["0x04B158C8"] = Hero.Sargon,
["0x04B158C9"] = Hero.Griotte,
//Bear
["0x765CE8D5"] = Hero.Sana,
["0x765CE8D6"] = Hero.Brun,
["0x765CE8D7"] = Hero.Ghor,
["0x765CE8D8"] = Hero.Yordana,
//Rabbit
["0xFE2E33BB"] = Hero.Amber,
["0xFE2E33BC"] = Hero.Barnaby,
["0xFE2E33BD"] = Hero.Elyssia,
["0xFE2E33BE"] = Hero.Hagrave,
//Bandit
["0x94B1BC41"] = Hero.Twiss,
["0x94B1BC42"] = Hero.Sylas,
["0x94B1BC43"] = Hero.Horace,
["0x94B1BC44"] = Hero.Scarlet,
//Dragon
["0xD1BBEF74"] = Hero.Volodar,
["0xD1BBEF75"] = Hero.Agniya,
["0xD1BBEF76"] = Hero.Oxana,
["0xD1BBEF77"] = Hero.Nazar
};

public static Hero HeroFromHexId(string hex)
{
return HeroesHexId.TryGetValue(hex, out var hero) ? hero : Hero.Unknown;
}
}
}
28 changes: 28 additions & 0 deletions Armello/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace ArmelloLogTools.Armello
{
public struct Player
{
public readonly int Id;
public readonly string Name;
public readonly Hero Hero;
public int QuestCount;

public Player(int id, string name, Hero hero)
{
Id = id;
Name = name;
Hero = hero;
QuestCount = 1;
}

public Player(int id, string name, string heroHexId)
{
Id = id;
Name = name;
Hero = HeroHelpers.HeroFromHexId(heroHexId);
QuestCount = 1;
}

public static Player Empty = new Player(-1, "", Hero.Unknown);
}
}
14 changes: 14 additions & 0 deletions ArmelloLogTools.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ConsoleTables" Version="2.3.0" />
<PackageReference Include="morelinq" Version="3.2.0" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions ArmelloLogTools.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArmelloLogTools", "ArmelloLogTools.csproj", "{09C8016D-50F2-40E2-A4C7-6CE8AB47A2FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09C8016D-50F2-40E2-A4C7-6CE8AB47A2FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09C8016D-50F2-40E2-A4C7-6CE8AB47A2FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09C8016D-50F2-40E2-A4C7-6CE8AB47A2FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09C8016D-50F2-40E2-A4C7-6CE8AB47A2FD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
59 changes: 59 additions & 0 deletions Interpreter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections.Generic;
using ArmelloLogTools.Armello;

namespace ArmelloLogTools
{
public class Interpreter
{
private readonly Dictionary<int, Player> _players = new Dictionary<int, Player>(4);

public IReadOnlyDictionary<int, Player> Players => _players;

private int _currentPlayerId = 0;

private Player CurrentPlayer
{
get => _players[_currentPlayerId];
set => _players[_currentPlayerId] = value;
}

public void ProcessEvents(IEnumerable<Event> events)
{
foreach (var @event in events)
{
ProcessEvent(@event);
}
}

private void ProcessEvent(Event @event)
{
switch (@event.Type)
{
//New game, reset players
case EventType.LoadGame:
_players.Clear();
_currentPlayerId = 0;
break;

//Add player to _players
case EventType.LoadPlayer:
var playerEvent = (LoadPlayerEvent) @event;
_players[playerEvent.Player.Id] = playerEvent.Player;
break;

//New turn, update currentPlayerId
case EventType.StartTurn:
var turnEvent = (StartTurnEvent) @event;
_currentPlayerId = turnEvent.PlayerId;
break;

//Quest complete, increment player's quest counter
case EventType.CompleteQuest:
var player = CurrentPlayer;
player.QuestCount++;
CurrentPlayer = player;
break;
}
}
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 bibo5088

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions LogReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using MoreLinq.Extensions;

namespace ArmelloLogTools
{
public class LogReader
{
private readonly StreamReader _reader;

public LogReader(string filename)
{
_reader = new StreamReader(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
}

public IEnumerable<string> ReadLines()
{
string line;
while ((line = _reader.ReadLine()) != null)
{
yield return line;
}
}
}

public static class LogFile
{
private static Regex _armelloLogFilenameDatetimeRegex =
new Regex(@"^.+_log_(.+)\.txt$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

public static string LatestLogFile(string dirPath)
{
var dir = new DirectoryInfo(dirPath);
var files = dir.GetFiles("*.txt");

return files.Select(info => (info: info, match: _armelloLogFilenameDatetimeRegex.Match(info.Name)))
.Where(t => t.match.Success)
.Select(t =>
(info: t.info,
datetime: DateTime.ParseExact(t.match.Groups[1].Value, "yyyy-MM-dd_hh-mm-ss-tt",
CultureInfo.InvariantCulture)))
.MaxBy(t => t.datetime).First().info.FullName;
}

public static string LatestLogFile()
{
var armelloLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"../LocalLow/League of Geeks/Armello/logs");
return LatestLogFile(armelloLogPath);
}
}
}
Loading

0 comments on commit 35dbff9

Please sign in to comment.