Move ParseInlineMap To TCPProtocol
Implement Lottso! Deluxe Singleplayer Mode Support
This commit is contained in:
parent
68e3ac5b4a
commit
b5c9f3dd08
65
Core/Rooms/GameRooms/Lottso2Room.cs
Normal file
65
Core/Rooms/GameRooms/Lottso2Room.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
namespace NotPogo.Core.Rooms.GameRooms
|
||||||
|
{
|
||||||
|
[GameRoom("lottso2")]
|
||||||
|
public class Lottso2Room : IGameRoom
|
||||||
|
{
|
||||||
|
public Task OnGameJoinAsync(Room room, Player player)
|
||||||
|
{
|
||||||
|
// TODO - implement multiplayer
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> OnMessageAsync(Room room, Player player, string op, Dictionary<string, string> msg)
|
||||||
|
{
|
||||||
|
return op switch
|
||||||
|
{
|
||||||
|
"ext.over" => HandleResults(player, msg),
|
||||||
|
_ => Task.FromResult(false),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<bool> HandleResults(Player player, Dictionary<string, string> msg)
|
||||||
|
{
|
||||||
|
// determine jackpot win
|
||||||
|
msg.TryGetValue("gm.won", out var won);
|
||||||
|
bool isJackpot = won == "true";
|
||||||
|
|
||||||
|
// send ext.rslt
|
||||||
|
await player.SendAsync(
|
||||||
|
("msg.op", "ext.rslt"),
|
||||||
|
("tokb", "9999"),
|
||||||
|
("tokn.won", TCPProtocol.ParseInlineMap(msg["tokn.won"])["allt"].ToString()),
|
||||||
|
("spin.rslt", isJackpot ? "2" : "0"),
|
||||||
|
("spin.tokn", isJackpot ? Random.Shared.Next(0, 500).ToString() : "0"),
|
||||||
|
("inst.desc", ""),
|
||||||
|
("jpot", "0"),
|
||||||
|
("pzpm", ""),
|
||||||
|
("bmlt", "1"),
|
||||||
|
("bspo", "0"),
|
||||||
|
("xpup", "0")
|
||||||
|
);
|
||||||
|
|
||||||
|
// CDL games require more for the results screen
|
||||||
|
|
||||||
|
await player.SendAsync(
|
||||||
|
("msg.op", "ext.rank"),
|
||||||
|
("rank.ord", "1"), ("rank.nam", "Rookie"), ("rank.pts", "0"),
|
||||||
|
("rank.nord", "2"), ("rank.nnam", "Novice"), ("rank.npts", "100"),
|
||||||
|
("rank.ppts", "0"), ("rank.incr", "0"), ("rank.new", "false")
|
||||||
|
);
|
||||||
|
|
||||||
|
await player.SendAsync(
|
||||||
|
("msg.op", "cdl.awar"),
|
||||||
|
("nava", "false"), ("ilvl", "0"),
|
||||||
|
("nbad", "false"), ("badg", "0"),
|
||||||
|
("ainf", "")
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task OnPlayerJoinedAsync(Room room, Player player) => Task.CompletedTask;
|
||||||
|
|
||||||
|
public Task OnPlayerLeftAsync(Room room, Player player) => Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,7 +7,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Core\Rooms\GameRooms\" />
|
|
||||||
<Folder Include="Example Folder Structure\JARs\" />
|
<Folder Include="Example Folder Structure\JARs\" />
|
||||||
<Folder Include="Example Folder Structure\PublicAssets\" />
|
<Folder Include="Example Folder Structure\PublicAssets\" />
|
||||||
<Folder Include="Services\" />
|
<Folder Include="Services\" />
|
||||||
|
|||||||
@ -142,23 +142,6 @@ namespace NotPogo
|
|||||||
return TCPProtocol.WriteMessageAsync(stream, msg);
|
return TCPProtocol.WriteMessageAsync(stream, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Dictionary<string, int> ParseInlineMap(string raw)
|
|
||||||
{
|
|
||||||
var result = new Dictionary<string, int>();
|
|
||||||
if (string.IsNullOrEmpty(raw)) return result;
|
|
||||||
|
|
||||||
var trimmed = raw.Trim('{', '}');
|
|
||||||
foreach(var pair in trimmed.Split(','))
|
|
||||||
{
|
|
||||||
var kv = pair.Split('=');
|
|
||||||
if(kv.Length != 2) continue;
|
|
||||||
var key = kv[0].Trim();
|
|
||||||
if (int.TryParse(kv[1].Trim(), out int value))
|
|
||||||
result[key] = value;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task StopAsync(CancellationToken cancellationToken)
|
public override Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if(!cancellationToken.IsCancellationRequested)
|
if(!cancellationToken.IsCancellationRequested)
|
||||||
|
|||||||
@ -55,6 +55,23 @@ namespace NotPogo
|
|||||||
await stream.FlushAsync();
|
await stream.FlushAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, int> ParseInlineMap(string raw)
|
||||||
|
{
|
||||||
|
var result = new Dictionary<string, int>();
|
||||||
|
if (string.IsNullOrEmpty(raw)) return result;
|
||||||
|
|
||||||
|
var trimmed = raw.Trim('{', '}');
|
||||||
|
foreach (var pair in trimmed.Split(','))
|
||||||
|
{
|
||||||
|
var kv = pair.Split('=');
|
||||||
|
if (kv.Length != 2) continue;
|
||||||
|
var key = kv[0].Trim();
|
||||||
|
if (int.TryParse(kv[1].Trim(), out int value))
|
||||||
|
result[key] = value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task<int> ReadUInt16BEAsync(NetworkStream stream)
|
private static async Task<int> ReadUInt16BEAsync(NetworkStream stream)
|
||||||
{
|
{
|
||||||
byte[] buf = await ReadExactAsync(stream, 2);
|
byte[] buf = await ReadExactAsync(stream, 2);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user