public async Task <BodyResponse <RewardInfoVM> > Handle(GetGameActRewardCommand request, CancellationToken cancellationToken) { DateTime tnow = DateTime.Now; var roomConfig = _activityConfig.AllGameConfigs .Find(x => x.ActivityId == request.ActId).RoomConfigs .Find(x => x.SubId == request.SubId); using (var locker = _redis.Locker(KeyGenHelper.GenUserDayKey(tnow, request.Id, "GameActivity", request.ActId))) { await locker.LockAsync(); var subAct = await _redis.GetGameActProgress(tnow, request.Id, request.ActId, request.SubId); long rewardCoins = 0; if (subAct.State == 1) { return(new BodyResponse <RewardInfoVM>(StatusCodeDefines.Error)); } if (subAct.CurCount >= roomConfig.NeedCount) { rewardCoins = roomConfig.RewardCoins; _ = _mqBus.Publish(new AddMoneyMqCommand(request.Id, rewardCoins, 0, AddReason.GameAct)); subAct.State = 1; await _redis.SetGameActProgress(tnow, request.Id, request.ActId, request.SubId, subAct); return(new BodyResponse <RewardInfoVM>(StatusCodeDefines.Success, null, new RewardInfoVM(rewardCoins))); } else { return(new BodyResponse <RewardInfoVM>(StatusCodeDefines.Error)); } } }
public async Task <GameSubActInfo> GetGameActProgress(DateTime time, long id, string activityId, string subId) { GameSubActInfo subAct = await _redis.GetHashValueAsync <GameSubActInfo> (KeyGenHelper.GenUserDayKey(time, id, "GameActivity", activityId), subId); return(subAct); }
public async Task <OneGameActivityInfo> GetGameActivity(DateTime time, long id, string activityId) { Dictionary <string, GameSubActInfo> dic = await _redis.GetHashAllAsync <string, GameSubActInfo> (KeyGenHelper.GenUserDayKey(time, id, "GameActivity", activityId)); return(new OneGameActivityInfo(activityId, dic)); }
public async Task <BodyResponse <RewardInfoVM> > Handle(GetBankruptcyRewardCommand request, CancellationToken cancellationToken) { DateTime tnow = DateTime.Now; using (var locker = _redis.Locker(KeyGenHelper.GenUserDayKey(tnow, request.Id, BankruptcyInfo.className))) { await locker.LockAsync(); var bankruptcyInfo = await _redis.GetBankruptcyInfo(tnow, request.Id); int totalTimes = _bankruptcyConfig.BankruptcyRewards.Count; if (bankruptcyInfo == null) { bankruptcyInfo = new BankruptcyInfo(0); } if (bankruptcyInfo.CurTimes >= 2) { return(new BodyResponse <RewardInfoVM>(StatusCodeDefines.RewardNotAvailable)); } long rewardCoins = _bankruptcyConfig.BankruptcyRewards[bankruptcyInfo.CurTimes]; ++bankruptcyInfo.CurTimes; await _redis.SetBankruptcyInfo(tnow, bankruptcyInfo); _ = _mqBus.Publish(new AddMoneyMqCommand(request.Id, rewardCoins, 0, AddReason.Bankruptcy)); return(new BodyResponse <RewardInfoVM>(StatusCodeDefines.Success, null, new RewardInfoVM(rewardCoins))); } }
public void DealOneRoom(DateTime time, List <long> players, string actId, string subId) { ParallelLoopResult result = Parallel.ForEach(players, async player => { using (var locker = _redis.Locker(KeyGenHelper.GenUserDayKey(time, player, "GameActivity", actId))) { await locker.LockAsync(); var oneSub = await _redis.GetGameActProgress(time, player, actId, subId); if (oneSub == null) { oneSub = new GameSubActInfo(0, 0); } if (oneSub.State == 1) { return; } ++oneSub.CurCount; await _redis.SetGameActProgress(time, player, actId, subId, oneSub); } }); }
public Task SetBankruptcyInfo(DateTime date, BankruptcyInfo info) { return(_redis.SetStringAsync(KeyGenHelper.GenUserDayKey (date, info.Id, BankruptcyInfo.className), info, TimeSpan.FromDays(1))); }
public Task <BankruptcyInfo> GetBankruptcyInfo(DateTime date, long id) { return(_redis.GetStringAsync <BankruptcyInfo> (KeyGenHelper.GenUserDayKey(date, id, BankruptcyInfo.className))); }
public Task SetGameActProgress(DateTime time, long id, string activityId, string subId, GameSubActInfo subAct) { return(_redis.AddHashValueAsync(KeyGenHelper.GenUserDayKey(time, id, "GameActivity", activityId), subId, subAct, TimeSpan.FromDays(1))); }