Esempio n. 1
0
        public async Task <bool> AddAsync(Stream eventStream, SporeServerUser author)
        {
            try
            {
                var events = await EventsModel.SerializeAsync(eventStream);

                foreach (var eventsEvent in events.Events)
                {
                    switch (eventsEvent.Verb)
                    {
                    // Unlocked Achievement
                    case (Int64)SporeEventType.AchievementUnlocked:
                        await _achievementManager.UnlockAsync(eventsEvent.Args[0], author);

                        break;

                    // Befriended Creature
                    case (Int64)SporeEventType.CreatureBefriended:
                        break;

                    // Extincted Creature
                    case (Int64)SporeEventType.CreatureExtinction:
                        break;

                    // Adventure Won
                    case (Int64)SporeEventType.AdventureWon:
                    {
                        var adventureAssetId    = eventsEvent.AssetId;
                        var percentageCompleted = (Int32)eventsEvent.Args[0];
                        var timeInMs            = (Int32)eventsEvent.Args[1];
                        // Args[2] contains the amount of captain points earned
                        // maybe a thing to track in the future?
                        // seems to be unrequired for anything ingame though
                        var captainAssetId = eventsEvent.Args[3];

                        var adventureAsset = await _assetManager.FindByIdAsync(adventureAssetId);

                        var captainAsset = await _assetManager.FindByIdAsync(captainAssetId);

                        // make sure we can find the needed assets
                        if (adventureAsset == null || captainAsset == null)
                        {
                            break;
                        }

                        await _leaderboardManager.AddAsync(adventureAsset, captainAsset, percentageCompleted, timeInMs, author);
                    }
                    break;

                    // Adventure Lost
                    case (Int64)SporeEventType.AdventureLost:
                        break;

                    // Adventure Captain Stats
                    case (Int64)SporeEventType.AdventureCaptainStats:
                        break;

                    // Adventure Captain Name
                    case (Int64)SporeEventType.AdventureCaptainName:
                        break;

                    // Adventure Captain Unlocked Parts
                    case (Int64)SporeEventType.AdventureCaptainUnlockedParts:
                        break;

                    // Unsupported
                    default:
                        _logger.LogWarning($"Invalid Event Verb 0x{eventsEvent.Verb:x}");
                        break;
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError($"Failed To Add Event For {author.Id}: {e}");
                return(false);
            }
        }