예제 #1
0
        // Private members

        private async Task InitializeGotchiContextAsync()
        {
            GotchiContext gotchiContext = new GotchiContext();

            gotchiContext.LogAsync += async x => await OnLogAsync(x);

            // Load gotchi config.

            if (GotchiUtilities.TryReadGotchiConfigurationFromFile(out GotchiConfiguration gotchiConfiguration))
            {
                gotchiContext.Config = gotchiConfiguration;
            }
            else
            {
                await OnLogAsync(LogSeverity.Warning, "Gotchi", "Gotchi configuration file could not be found");
            }

            // Initialize registries.

            await OnLogAsync(LogSeverity.Info, "Gotchi", "Registering gotchi types");

            await gotchiContext.TypeRegistry.RegisterAllAsync(Constants.GotchiDataDirectory + "types/");

            await OnLogAsync(LogSeverity.Info, "Gotchi", "Finished registering gotchi types");

            await OnLogAsync(LogSeverity.Info, "Gotchi", "Registering gotchi statuses");

            await gotchiContext.StatusRegistry.RegisterAllAsync(Constants.GotchiDataDirectory + "statuses/");

            await OnLogAsync(LogSeverity.Info, "Gotchi", "Finished registering gotchi statuses");

            await OnLogAsync(LogSeverity.Info, "Gotchi", "Registering gotchi moves");

            await gotchiContext.MoveRegistry.RegisterAllAsync(Constants.GotchiDataDirectory + "moves/");

            await OnLogAsync(LogSeverity.Info, "Gotchi", "Finished registering gotchi moves");

            Global.GotchiContext = gotchiContext;
        }
        public static async Task <int> FeedGotchisAsync(this SQLiteDatabase database, GotchiContext context, ulong userId)
        {
            // Although we only display the state of the primary Gotchi at the moment, update the feed time for all Gotchis owned by this user.
            // Only Gotchis that are still alive (i.e. have been fed recently enough) get their timestamp updated.

            using (SQLiteCommand cmd = new SQLiteCommand("UPDATE Gotchi SET fed_ts = $fed_ts WHERE owner_id = $owner_id AND fed_ts >= $min_ts")) {
                cmd.Parameters.AddWithValue("$fed_ts", DateTimeOffset.UtcNow.ToUnixTimeSeconds());
                cmd.Parameters.AddWithValue("$owner_id", userId);
                cmd.Parameters.AddWithValue("$min_ts", context.MinimumFedTimestamp());

                return(await database.ExecuteNonQueryAsync(cmd));
            }
        }