private void OnTabletopActivate(EntityUid uid, TabletopGameComponent component, ActivateInWorldEvent args) { // Check that a player is attached to the entity. if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) { return; } OpenSessionFor(actor.PlayerSession, uid); }
private void OnTabletopActivate(EntityUid uid, TabletopGameComponent component, ActivateInWorldEvent args) { // Check that a player is attached to the entity. if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor)) { return; } // Check that the entity can interact with the game board. if (_actionBlockerSystem.CanInteract(args.User)) { OpenSessionFor(actor.PlayerSession, uid); } }
/// <summary> /// Add a verb that allows the player to start playing a tabletop game. /// </summary> private void AddPlayGameVerb(EntityUid uid, TabletopGameComponent component, GetActivationVerbsEvent args) { if (!args.CanAccess || !args.CanInteract) { return; } if (!EntityManager.TryGetComponent <ActorComponent?>(args.User, out var actor)) { return; } Verb verb = new(); verb.Text = Loc.GetString("tabletop-verb-play-game"); verb.IconTexture = "/Textures/Interface/VerbIcons/die.svg.192dpi.png"; verb.Act = () => OpenSessionFor(actor.PlayerSession, uid); args.Verbs.Add(verb); }
/// <summary> /// A helper method that creates a camera for a specified player, in a tabletop game session. /// </summary> /// <param name="tabletop">The tabletop game component in question.</param> /// <param name="player">The player in question.</param> /// <param name="offset">An offset from the tabletop position for the camera. Zero by default.</param> /// <returns>The UID of the camera entity.</returns> private EntityUid CreateCamera(TabletopGameComponent tabletop, IPlayerSession player, Vector2 offset = default) { DebugTools.AssertNotNull(tabletop.Session); var session = tabletop.Session !; // Spawn an empty entity at the coordinates var camera = EntityManager.SpawnEntity(null, session.Position.Offset(offset)); // Add an eye component and disable FOV var eyeComponent = camera.EnsureComponent <EyeComponent>(); eyeComponent.DrawFov = false; eyeComponent.Zoom = tabletop.CameraZoom; // Add the user to the view subscribers. If there is no player session, just skip this step _viewSubscriberSystem.AddViewSubscriber(camera, player); return(camera); }
/// <summary> /// Ensures that a <see cref="TabletopSession"/> exists on a <see cref="TabletopGameComponent"/>. /// Creates it and sets it up if it doesn't. /// </summary> /// <param name="tabletop">The tabletop game in question.</param> /// <returns>The session for the given tabletop game.</returns> private TabletopSession EnsureSession(TabletopGameComponent tabletop) { // We already have a session, return it // TODO: if tables are connected, treat them as a single entity. This can be done by sharing the session. if (tabletop.Session != null) { return(tabletop.Session); } // We make sure that the tabletop map exists before continuing. EnsureTabletopMap(); // Create new session. var session = new TabletopSession(TabletopMap, GetNextTabletopPosition()); tabletop.Session = session; // Since this is the first time opening this session, set up the game tabletop.Setup.SetupTabletop(session, EntityManager); Logger.Info($"Created tabletop session number {tabletop} at position {session.Position}."); return(session); }
private void OnGameShutdown(EntityUid uid, TabletopGameComponent component, ComponentShutdown args) { CleanupSession(uid); }