public void UserToUser(ulong sourceUserId, ulong targetUserId, ulong amount)
        {
            if (sourceUserId == targetUserId)
            {
                throw new InvalidOperationException(Constants.ExTransferSameUser);
            }

            if (targetUserId == discordClient.GetCurrentUser().Id)
            {
                throw new InvalidOperationException(Constants.ExTransferToMiunie);
            }

            var transferSource = globalUserAccountProvider.GetById(sourceUserId);

            if (transferSource.Miunies < amount)
            {
                throw new InvalidOperationException(Constants.ExTransferNotEnoughFunds);
            }

            var transferTarget = globalUserAccountProvider.GetById(targetUserId);

            transferSource.Miunies -= amount;
            transferTarget.Miunies += amount;

            globalUserAccountProvider.SaveByIds(transferSource.Id, transferTarget.Id);
        }
Пример #2
0
        public void GetDaily(ulong userId)
        {
            var account        = globalUserAccountProvider.GetById(userId);
            var sinceLastDaily = DateTime.UtcNow - account.LastDaily;

            if (sinceLastDaily.TotalHours < 24)
            {
                var e = new InvalidOperationException(Constants.ExDailyTooSoon);
                e.Data.Add("sinceLastDaily", sinceLastDaily);
                throw e;
            }

            account.Miunies  += Constants.DailyMuiniesGain;
            account.LastDaily = DateTime.UtcNow;

            globalUserAccountProvider.SaveByIds(userId);
        }