Remove WordRiotRoom (was mostly for prototyping)
Load CDL Rooms From File Move ext.rslt To Game Specific Rooms
This commit is contained in:
parent
2631d3199c
commit
68e3ac5b4a
@ -1,23 +0,0 @@
|
|||||||
namespace NotPogo.Core.Rooms.GameRooms
|
|
||||||
{
|
|
||||||
[GameRoom("wordriot_cdl")]
|
|
||||||
public class WordRiotRoom(string ruleId) : IGameRoom
|
|
||||||
{
|
|
||||||
public Task OnGameJoinAsync(Room room, Player player) => Task.CompletedTask;
|
|
||||||
|
|
||||||
public Task<bool> OnMessageAsync(Room room, Player player, string op, Dictionary<string, string> msg) => Task.FromResult(true);
|
|
||||||
|
|
||||||
public async Task OnPlayerJoinedAsync(Room room, Player player)
|
|
||||||
{
|
|
||||||
await player.SendAsync(
|
|
||||||
("msg.op", "say"),
|
|
||||||
("chnl", "serv"),
|
|
||||||
("scrn", ""),
|
|
||||||
("type", "stnd"),
|
|
||||||
("text", "Welcome To Word Riot! Please Wait For Players To Join")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task OnPlayerLeftAsync(Room room, Player player) => Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
using NotPogo.Core.Rooms.GameRooms;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace NotPogo.Core.Rooms
|
namespace NotPogo.Core.Rooms
|
||||||
{
|
{
|
||||||
@ -10,6 +10,18 @@ namespace NotPogo.Core.Rooms
|
|||||||
|
|
||||||
static readonly Dictionary<string, Func<string, IGameRoom>> Factories = BuildFactories();
|
static readonly Dictionary<string, Func<string, IGameRoom>> Factories = BuildFactories();
|
||||||
|
|
||||||
|
public sealed record RoomDef(string Key, string Name, string Rule, int Capacity = 50);
|
||||||
|
|
||||||
|
public static void LoadFromFile(string path)
|
||||||
|
{
|
||||||
|
var opts = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true };
|
||||||
|
var games = JsonSerializer.Deserialize<Dictionary<string, RoomDef[]>>(File.ReadAllText(path), opts)!;
|
||||||
|
|
||||||
|
foreach (var (gameCode, rooms) in games)
|
||||||
|
foreach (var r in rooms)
|
||||||
|
Define(r.Key, r.Name, gameCode, r.Rule, true, r.Capacity);
|
||||||
|
}
|
||||||
|
|
||||||
static Dictionary<string, Func<string, IGameRoom>> BuildFactories()
|
static Dictionary<string, Func<string, IGameRoom>> BuildFactories()
|
||||||
{
|
{
|
||||||
var map = new Dictionary<string, Func<string, IGameRoom>>(StringComparer.OrdinalIgnoreCase);
|
var map = new Dictionary<string, Func<string, IGameRoom>>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
</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\" />
|
||||||
|
|||||||
@ -52,10 +52,8 @@ namespace NotPogo
|
|||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.MapFlashGateway();
|
app.MapFlashGateway();
|
||||||
|
|
||||||
// Define Rooms For Word Riot Deluxe
|
// Define Rooms For CDL Games
|
||||||
RoomManager.Define("npwr_classic_1", "NotPogo Classic Room 1", "wordriot_cdl", "classic", true);
|
RoomManager.LoadFromFile(Path.Combine(AppContext.BaseDirectory, "StaticFiles", "rooms.json"));
|
||||||
RoomManager.Define("npwr_rally_1", "NotPogo Rally Room 1", "wordriot_cdl", "rally", true);
|
|
||||||
RoomManager.Define("npwr_advanced_1", "NotPogo Advanced Room 1", "wordriot_cdl", "advanced", true);
|
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,29 +77,6 @@ namespace NotPogo
|
|||||||
{
|
{
|
||||||
await player.Room.HandleAsync(player, op, received);
|
await player.Room.HandleAsync(player, op, received);
|
||||||
}
|
}
|
||||||
else if (op == "ext.over") // TODO: move to rooms extending IGameRoom
|
|
||||||
{
|
|
||||||
// because we aren't actually keeping track of anything going on in the games, we can just send the correct placeholders
|
|
||||||
|
|
||||||
bool isJackpot = (received["gm.won"] == "true") ? true : false;
|
|
||||||
int tokensWon = isJackpot ? Random.Shared.Next(0, 999) : 0;
|
|
||||||
|
|
||||||
await SendAsync(stream,
|
|
||||||
("msg.op", "ext.rslt"),
|
|
||||||
("tokb", "9999"),
|
|
||||||
("tokn.won", isJackpot ? "100" : "0"),
|
|
||||||
("spin.rslt", isJackpot ? "2" : "0"), // we aren't doing anything with the other outcomes so always issue tokens
|
|
||||||
("spin.tokn", tokensWon.ToString()), // standalone reference implementation
|
|
||||||
("inst.desc", ""),
|
|
||||||
("jpot", "0"),
|
|
||||||
("pzpm", ""),
|
|
||||||
("bmlt", "1"),
|
|
||||||
("bspo", "0"),
|
|
||||||
("xpup", "0")
|
|
||||||
);
|
|
||||||
|
|
||||||
_logger.LogInformation("Results Sent");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) when (e is EndOfStreamException or IOException or SocketException) { _logger.LogInformation("plid {Plid} disconnected ({Reason})", player.Id, e.GetBaseException().Message); }
|
} catch (Exception e) when (e is EndOfStreamException or IOException or SocketException) { _logger.LogInformation("plid {Plid} disconnected ({Reason})", player.Id, e.GetBaseException().Message); }
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user