Exemple #1
0
        /// <summary>
        /// Runs the game until they win, die or exit.
        /// </summary>
        public static void StartEngine()
        {
            AttachedClients.DetachAllClients("Server restart");
            GrainSiloHost.StopAsync().Wait();
            GrainClusterClient.StopAsync().Wait();
            RunGameLoop     = true;
            RunFactory      = true;
            shutdownStarted = false;

            // After the game state is loaded is the appropriate time to start accepting connections
            try
            {
                GrainSiloHost.StartAsync().Wait();
                GrainClusterClient.StartAsync().Wait();

                GrainClusterClient.SetGameUniverseName("Spark"); // TODO: get this name from game data

                var sysopAccount = GrainClusterClient.Accounts.GetSysopAccount().Result;
                CommandRunner.TryRunCommandFromAccount("autoloadbestgamestate", new List <string>(), sysopAccount);

                Broker.StartHost();

                // Main game loop goes 1 loop for 1 game turn.
                while (RunGameLoop)
                {
                    // Get all characters in the game that are still alive
                    var turningNPC = GrainClusterClient.Universe.GetNextTurnNPC().Result;

                    if (turningNPC == null)
                    {
                        Task.Delay(200).Wait();
                        continue;
                    }
                    else
                    {
                        // Only characters that are alive get a turn
                        if (!turningNPC.IsDead())
                        {
                            turningNPC.Turn();
                        }
                        else if (turningNPC.CanRespawn())
                        {
                            turningNPC.Respawn();
                        }
                        turningNPC.TurnComplete();
                    }
                }
            }
            finally
            {
                EngineShutdown(null, null);
            }
        }
Exemple #2
0
 private void ClientConnection_Closed(IAmqpObject sender, Amqp.Framing.Error error)
 {
     System.Console.WriteLine($"Client connection closed.\r\n   Client Tracking Id: {this.TrackingId}\r\n   Details: {error?.Description}");
     AttachedClients.DetachClient(this, error?.Description);
 }