diff --git a/Content.Server/Tabletop/Components/TabletopGameComponent.cs b/Content.Server/Tabletop/Components/TabletopGameComponent.cs index 0e755193d6..6e3a5b9105 100644 --- a/Content.Server/Tabletop/Components/TabletopGameComponent.cs +++ b/Content.Server/Tabletop/Components/TabletopGameComponent.cs @@ -2,6 +2,8 @@ using Content.Shared.Verbs; using Robust.Shared.GameObjects; using Robust.Shared.Localization; +using Robust.Shared.Maths; +using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Tabletop.Components { @@ -13,6 +15,18 @@ namespace Content.Server.Tabletop.Components { public override string Name => "TabletopGame"; + [DataField("boardName")] + public string BoardName { get; } = "tabletop-default-board-name"; + + [DataField("setup", required: true)] + public TabletopSetup Setup { get; } = new TabletopChessSetup(); + + [DataField("size")] + public Vector2i Size { get; } = (300, 300); + + [DataField("cameraZoom")] + public Vector2 CameraZoom { get; } = Vector2.One; + /// /// A verb that allows the player to start playing a tabletop game. /// diff --git a/Content.Server/Tabletop/TabletopChessSetup.cs b/Content.Server/Tabletop/TabletopChessSetup.cs new file mode 100644 index 0000000000..9b5dfbd09d --- /dev/null +++ b/Content.Server/Tabletop/TabletopChessSetup.cs @@ -0,0 +1,80 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.Map; +using Robust.Shared.Serialization.Manager.Attributes; + +namespace Content.Server.Tabletop +{ + public class TabletopChessSetup : TabletopSetup + { + [DataField("boardPrototype")] + public string ChessBoardPrototype { get; } = "ChessBoardTabletop"; + + // TODO: Un-hardcode the rest of entity prototype IDs, probably. + + public override void SetupTabletop(MapId mapId, IEntityManager entityManager) + { + var chessboard = entityManager.SpawnEntity(ChessBoardPrototype, new MapCoordinates(-1, 0, mapId)); + chessboard.Transform.Anchored = true; + + SpawnPieces(entityManager, new MapCoordinates(-4.5f, 3.5f, mapId)); + } + + private void SpawnPieces(IEntityManager entityManager, MapCoordinates topLeft, float separation = 1f) + { + var (mapId, x, y) = topLeft; + + // Spawn all black pieces + SpawnPiecesRow(entityManager, "Black", topLeft, separation); + SpawnPawns(entityManager, "Black", new MapCoordinates(x, y - separation, mapId) , separation); + + // Spawn all white pieces + SpawnPawns(entityManager, "White", new MapCoordinates(x, y - 6 * separation, mapId) , separation); + SpawnPiecesRow(entityManager, "White", new MapCoordinates(x, y - 7 * separation, mapId), separation); + + // Extra queens + entityManager.SpawnEntity("BlackQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 3 * separation, mapId)); + entityManager.SpawnEntity("WhiteQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 4 * separation, mapId)); + } + + // TODO: refactor to load FEN instead + private void SpawnPiecesRow(IEntityManager entityManager, string color, MapCoordinates left, float separation = 1f) + { + const string piecesRow = "rnbqkbnr"; + + var (mapId, x, y) = left; + + for (int i = 0; i < 8; i++) + { + switch (piecesRow[i]) + { + case 'r': + entityManager.SpawnEntity(color + "Rook", new MapCoordinates(x + i * separation, y, mapId)); + break; + case 'n': + entityManager.SpawnEntity(color + "Knight", new MapCoordinates(x + i * separation, y, mapId)); + break; + case 'b': + entityManager.SpawnEntity(color + "Bishop", new MapCoordinates(x + i * separation, y, mapId)); + break; + case 'q': + entityManager.SpawnEntity(color + "Queen", new MapCoordinates(x + i * separation, y, mapId)); + break; + case 'k': + entityManager.SpawnEntity(color + "King", new MapCoordinates(x + i * separation, y, mapId)); + break; + } + } + } + + // TODO: refactor to load FEN instead + private void SpawnPawns(IEntityManager entityManager, string color, MapCoordinates left, float separation = 1f) + { + var (mapId, x, y) = left; + + for (int i = 0; i < 8; i++) + { + entityManager.SpawnEntity(color + "Pawn", new MapCoordinates(x + i * separation, y, mapId)); + } + } + } +} diff --git a/Content.Server/Tabletop/TabletopParchisSetup.cs b/Content.Server/Tabletop/TabletopParchisSetup.cs new file mode 100644 index 0000000000..89d1001851 --- /dev/null +++ b/Content.Server/Tabletop/TabletopParchisSetup.cs @@ -0,0 +1,60 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.Map; +using Robust.Shared.Serialization.Manager.Attributes; + +namespace Content.Server.Tabletop +{ + public class TabletopParchisSetup : TabletopSetup + { + [DataField("boardPrototype")] + public string ParchisBoardPrototype { get; } = "ParchisBoardTabletop"; + + [DataField("redPiecePrototype")] + public string RedPiecePrototype { get; } = "RedParchisPiece"; + + [DataField("greenPiecePrototype")] + public string GreenPiecePrototype { get; } = "GreenParchisPiece"; + + [DataField("yellowPiecePrototype")] + public string YellowPiecePrototype { get; } = "YellowParchisPiece"; + + [DataField("bluePiecePrototype")] + public string BluePiecePrototype { get; } = "BlueParchisPiece"; + + public override void SetupTabletop(MapId mapId, IEntityManager entityManager) + { + var board = entityManager.SpawnEntity(ParchisBoardPrototype, new MapCoordinates(0, 0, mapId)); + board.Transform.Anchored = true; + + const float x1 = 6.25f; + const float x2 = 4.25f; + + const float y1 = 6.25f; + const float y2 = 4.25f; + + // Red pieces. + entityManager.SpawnEntity(RedPiecePrototype, new MapCoordinates(-x1, -y1, mapId)); + entityManager.SpawnEntity(RedPiecePrototype, new MapCoordinates(-x1, -y2, mapId)); + entityManager.SpawnEntity(RedPiecePrototype, new MapCoordinates(-x2, -y1, mapId)); + entityManager.SpawnEntity(RedPiecePrototype, new MapCoordinates(-x2, -y2, mapId)); + + // Green pieces. + entityManager.SpawnEntity(GreenPiecePrototype, new MapCoordinates(x1, -y1, mapId)); + entityManager.SpawnEntity(GreenPiecePrototype, new MapCoordinates(x1, -y2, mapId)); + entityManager.SpawnEntity(GreenPiecePrototype, new MapCoordinates(x2, -y1, mapId)); + entityManager.SpawnEntity(GreenPiecePrototype, new MapCoordinates(x2, -y2, mapId)); + + // Yellow pieces. + entityManager.SpawnEntity(YellowPiecePrototype, new MapCoordinates(x1, y1, mapId)); + entityManager.SpawnEntity(YellowPiecePrototype, new MapCoordinates(x1, y2, mapId)); + entityManager.SpawnEntity(YellowPiecePrototype, new MapCoordinates(x2, y1, mapId)); + entityManager.SpawnEntity(YellowPiecePrototype, new MapCoordinates(x2, y2, mapId)); + + // Blue pieces. + entityManager.SpawnEntity(BluePiecePrototype, new MapCoordinates(-x1, y1, mapId)); + entityManager.SpawnEntity(BluePiecePrototype, new MapCoordinates(-x1, y2, mapId)); + entityManager.SpawnEntity(BluePiecePrototype, new MapCoordinates(-x2, y1, mapId)); + entityManager.SpawnEntity(BluePiecePrototype, new MapCoordinates(-x2, y2, mapId)); + } + } +} diff --git a/Content.Server/Tabletop/TabletopSetup.cs b/Content.Server/Tabletop/TabletopSetup.cs new file mode 100644 index 0000000000..75710dc92f --- /dev/null +++ b/Content.Server/Tabletop/TabletopSetup.cs @@ -0,0 +1,12 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.Map; +using Robust.Shared.Serialization.Manager.Attributes; + +namespace Content.Server.Tabletop +{ + [ImplicitDataDefinitionForInheritors] + public abstract class TabletopSetup + { + public abstract void SetupTabletop(MapId mapId, IEntityManager entityManager); + } +} diff --git a/Content.Server/Tabletop/TabletopSystem.Chess.cs b/Content.Server/Tabletop/TabletopSystem.Chess.cs deleted file mode 100644 index 28fb5d6694..0000000000 --- a/Content.Server/Tabletop/TabletopSystem.Chess.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Robust.Shared.Map; - -namespace Content.Server.Tabletop -{ - public partial class TabletopSystem - { - private void SetupChessBoard(MapId mapId) - { - var chessboard = EntityManager.SpawnEntity("ChessBoardTabletop", new MapCoordinates(-1, 0, mapId)); - chessboard.Transform.Anchored = true; - - SpawnPieces(new MapCoordinates(-4.5f, 3.5f, mapId)); - } - - private void SpawnPieces(MapCoordinates topLeft, float separation = 1f) - { - var (mapId, x, y) = topLeft; - - // Spawn all black pieces - SpawnPiecesRow("Black", topLeft, separation); - SpawnPawns("Black", new MapCoordinates(x, y - separation, mapId) , separation); - - // Spawn all white pieces - SpawnPawns("White", new MapCoordinates(x, y - 6 * separation, mapId) , separation); - SpawnPiecesRow("White", new MapCoordinates(x, y - 7 * separation, mapId), separation); - - // Extra queens - EntityManager.SpawnEntity("BlackQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 3 * separation, mapId)); - EntityManager.SpawnEntity("WhiteQueen", new MapCoordinates(x + 9 * separation + 9f / 32, y - 4 * separation, mapId)); - } - - // TODO: refactor to load FEN instead - private void SpawnPiecesRow(string color, MapCoordinates left, float separation = 1f) - { - const string piecesRow = "rnbqkbnr"; - - var (mapId, x, y) = left; - - for (int i = 0; i < 8; i++) - { - switch (piecesRow[i]) - { - case 'r': - EntityManager.SpawnEntity(color + "Rook", new MapCoordinates(x + i * separation, y, mapId)); - break; - case 'n': - EntityManager.SpawnEntity(color + "Knight", new MapCoordinates(x + i * separation, y, mapId)); - break; - case 'b': - EntityManager.SpawnEntity(color + "Bishop", new MapCoordinates(x + i * separation, y, mapId)); - break; - case 'q': - EntityManager.SpawnEntity(color + "Queen", new MapCoordinates(x + i * separation, y, mapId)); - break; - case 'k': - EntityManager.SpawnEntity(color + "King", new MapCoordinates(x + i * separation, y, mapId)); - break; - } - } - } - - // TODO: refactor to load FEN instead - private void SpawnPawns(string color, MapCoordinates left, float separation = 1f) - { - var (mapId, x, y) = left; - - for (int i = 0; i < 8; i++) - { - EntityManager.SpawnEntity(color + "Pawn", new MapCoordinates(x + i * separation, y, mapId)); - } - } - } -} diff --git a/Content.Server/Tabletop/TabletopSystem.cs b/Content.Server/Tabletop/TabletopSystem.cs index b6b3b246b4..35551592a8 100644 --- a/Content.Server/Tabletop/TabletopSystem.cs +++ b/Content.Server/Tabletop/TabletopSystem.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using Content.Server.Tabletop.Components; +using Content.Shared.ActionBlocker; +using Content.Shared.Interaction; using Content.Shared.Tabletop; using Content.Shared.Tabletop.Events; using JetBrains.Annotations; @@ -8,6 +10,7 @@ using Robust.Server.Player; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; +using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; using DrawDepth = Content.Shared.DrawDepth.DrawDepth; @@ -19,6 +22,7 @@ namespace Content.Server.Tabletop { [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly ViewSubscriberSystem _viewSubscriberSystem = default!; + [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; /// /// All tabletop games currently in progress. Sessions are associated with an entity UID, which acts as a @@ -31,10 +35,17 @@ namespace Content.Server.Tabletop SubscribeNetworkEvent(OnTabletopMove); SubscribeNetworkEvent(OnDraggingPlayerChanged); SubscribeNetworkEvent(OnStopPlaying); + SubscribeLocalEvent(OnTabletopActivate); SubscribeLocalEvent(OnGameShutdown); SubscribeLocalEvent(GetCompState); } + private void OnTabletopActivate(EntityUid uid, TabletopGameComponent component, ActivateInWorldEvent args) + { + if(_actionBlockerSystem.CanInteract(args.User)) + OpenTable(args.User, args.Target); + } + private void GetCompState(EntityUid uid, TabletopDraggableComponent component, ref ComponentGetState args) { args.State = new TabletopDraggableComponentState(component.DraggingPlayer); @@ -47,19 +58,19 @@ namespace Content.Server.Tabletop /// The entity with which the tabletop game session will be associated. public void OpenTable(IEntity user, IEntity table) { - if (user.PlayerSession() is not { } playerSession) return; + if (user.PlayerSession() is not { } playerSession + || !table.TryGetComponent(out TabletopGameComponent? tabletop)) return; // Make sure we have a session, and add the player to it - var session = EnsureSession(table.Uid); + var session = EnsureSession(table.Uid, tabletop); session.StartPlaying(playerSession); // Create a camera for the user to use // TODO: set correct coordinates, depending on the piece the game was started from - IEntity camera = CreateCamera(user, new MapCoordinates(0, 0, session.MapId)); + IEntity camera = CreateCamera(tabletop, user, new MapCoordinates(0, 0, session.MapId)); // Tell the client to open a viewport for the tabletop game - // TODO: use actual title/size from prototype, for now we assume its chess - RaiseNetworkEvent(new TabletopPlayEvent(table.Uid, camera.Uid, "Chess", (274 + 64, 274)), playerSession.ConnectedClient); + RaiseNetworkEvent(new TabletopPlayEvent(table.Uid, camera.Uid, Loc.GetString(tabletop.BoardName), tabletop.Size), playerSession.ConnectedClient); } /// @@ -67,7 +78,7 @@ namespace Content.Server.Tabletop /// /// The entity UID to ensure a session for. /// The created/stored tabletop game session. - private TabletopSession EnsureSession(EntityUid uid) + private TabletopSession EnsureSession(EntityUid uid, TabletopGameComponent tabletop) { // We already have a session, return it // TODO: if tables are connected, treat them as a single entity @@ -88,8 +99,7 @@ namespace Content.Server.Tabletop var session = _gameSessions[uid]; // Since this is the first time opening this session, set up the game - // TODO: don't assume we're playing chess - SetupChessBoard(session.MapId); + tabletop.Setup.SetupTabletop(session.MapId, EntityManager); return session; } @@ -169,10 +179,11 @@ namespace Content.Server.Tabletop /// /// Create a camera entity for a user to control, and add the user to the view subscribers. /// + /// The tabletop to create the camera for. /// The user entity to create this camera for and add to the view subscribers. /// The map coordinates to spawn this camera at. // TODO: this can probably be generalized into a "CctvSystem" or whatever - private IEntity CreateCamera(IEntity user, MapCoordinates coordinates) + private IEntity CreateCamera(TabletopGameComponent tabletop, IEntity user, MapCoordinates coordinates) { // Spawn an empty entity at the coordinates var camera = EntityManager.SpawnEntity(null, coordinates); @@ -180,6 +191,7 @@ namespace Content.Server.Tabletop // Add an eye component and disable FOV var eyeComponent = camera.EnsureComponent(); eyeComponent.DrawFov = false; + eyeComponent.Zoom = tabletop.CameraZoom; // Add the user to the view subscribers. If there is no player session, just skip this step if (user.PlayerSession() is { } playerSession) diff --git a/Resources/Locale/en-US/tabletop/tabletop.ftl b/Resources/Locale/en-US/tabletop/tabletop.ftl index 126177e30e..854b71a020 100644 --- a/Resources/Locale/en-US/tabletop/tabletop.ftl +++ b/Resources/Locale/en-US/tabletop/tabletop.ftl @@ -1,5 +1,10 @@ ## TabletopGameComponent tabletop-verb-play-game = Play Game +tabletop-default-board-name = Board Game ## Chess +tabletop-chess-board-name = Chess tabletop-chess-flip = Flip + +## Parchís +tabletop-parchis-board-name = Parchís diff --git a/Resources/Prototypes/Entities/Objects/Fun/Tabletop/chess.yml b/Resources/Prototypes/Entities/Objects/Fun/Tabletop/chess.yml index 79f63df0f7..c4cd6956a8 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/Tabletop/chess.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/Tabletop/chess.yml @@ -9,6 +9,9 @@ sprite: Objects/Fun/Tabletop/chessboard.rsi state: chessboard - type: TabletopGame + boardName: tabletop-chess-board-name + size: 338, 274 + setup: !type:TabletopChessSetup # Chessboard tabletop item (item only visible in tabletop game) - type: entity diff --git a/Resources/Prototypes/Entities/Objects/Fun/Tabletop/parchis.yml b/Resources/Prototypes/Entities/Objects/Fun/Tabletop/parchis.yml new file mode 100644 index 0000000000..43f694a529 --- /dev/null +++ b/Resources/Prototypes/Entities/Objects/Fun/Tabletop/parchis.yml @@ -0,0 +1,74 @@ +# Parchís board item (normal in game item you can hold in your hand) +- type: entity + parent: BaseItem + id: ParchisBoard + name: parchís board + description: Cross and circle board game famous for destroying countless friendships. + components: + - type: Sprite + sprite: Objects/Fun/Tabletop/parchis.rsi + state: board + - type: TabletopGame + boardName: tabletop-parchis-board-name + size: 574, 574 + setup: + !type:TabletopParchisSetup + +# Parchís tabletop item (item only visible in tabletop game) +- type: entity + id: ParchisBoardTabletop + name: parchís + abstract: true + components: + - type: Sprite + sprite: Objects/Fun/Tabletop/parchis_tabletop.rsi + state: board + noRot: false + drawdepth: FloorTiles + +# Parchís pieces +- type: entity + id: BaseParchisPiece + parent: BaseItem + abstract: true + components: + - type: TabletopDraggable + - type: Sprite + netsync: false + noRot: true + sprite: Objects/Fun/Tabletop/parchis_pieces.rsi + - type: Appearance + visuals: + - type: TabletopItemVisualizer + +- type: entity + id: RedParchisPiece + name: red piece + parent: BaseParchisPiece + components: + - type: Sprite + state: red + +- type: entity + id: GreenParchisPiece + name: green piece + parent: BaseParchisPiece + components: + - type: Sprite + state: green + +- type: entity + id: YellowParchisPiece + name: yellow piece + parent: BaseParchisPiece + components: + - type: Sprite + state: yellow + +- type: entity + id: BlueParchisPiece + name: blue piece + parent: BaseParchisPiece + components: + - type: Sprite + state: blue diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis.rsi/board.png b/Resources/Textures/Objects/Fun/Tabletop/parchis.rsi/board.png new file mode 100644 index 0000000000..79f577cafe Binary files /dev/null and b/Resources/Textures/Objects/Fun/Tabletop/parchis.rsi/board.png differ diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis.rsi/meta.json b/Resources/Textures/Objects/Fun/Tabletop/parchis.rsi/meta.json new file mode 100644 index 0000000000..66a7d89f26 --- /dev/null +++ b/Resources/Textures/Objects/Fun/Tabletop/parchis.rsi/meta.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Zumorica", + "size": { + "x": 18, + "y": 18 + }, + "states": [ + { + "name": "board" + } + ] +} diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/blue.png b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/blue.png new file mode 100644 index 0000000000..c9918b4293 Binary files /dev/null and b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/blue.png differ diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/green.png b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/green.png new file mode 100644 index 0000000000..6faef466c4 Binary files /dev/null and b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/green.png differ diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/meta.json b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/meta.json new file mode 100644 index 0000000000..5412a69967 --- /dev/null +++ b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/meta.json @@ -0,0 +1,23 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Zumorica", + "size": { + "x": 24, + "y": 24 + }, + "states": [ + { + "name": "red" + }, + { + "name": "green" + }, + { + "name": "yellow" + }, + { + "name": "blue" + } + ] +} diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/red.png b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/red.png new file mode 100644 index 0000000000..5e0c0aef6f Binary files /dev/null and b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/red.png differ diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/yellow.png b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/yellow.png new file mode 100644 index 0000000000..2a2fd48301 Binary files /dev/null and b/Resources/Textures/Objects/Fun/Tabletop/parchis_pieces.rsi/yellow.png differ diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis_tabletop.rsi/board.png b/Resources/Textures/Objects/Fun/Tabletop/parchis_tabletop.rsi/board.png new file mode 100644 index 0000000000..ddc8bd3589 Binary files /dev/null and b/Resources/Textures/Objects/Fun/Tabletop/parchis_tabletop.rsi/board.png differ diff --git a/Resources/Textures/Objects/Fun/Tabletop/parchis_tabletop.rsi/meta.json b/Resources/Textures/Objects/Fun/Tabletop/parchis_tabletop.rsi/meta.json new file mode 100644 index 0000000000..64f2d96581 --- /dev/null +++ b/Resources/Textures/Objects/Fun/Tabletop/parchis_tabletop.rsi/meta.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "Zumorica", + "size": { + "x": 548, + "y": 548 + }, + "states": [ + { + "name": "board" + } + ] +}