public LadderHookInfoResponse StartHook(Guid managerId, int maxTimes, int minScore, int maxScore, int winTimes) { if (maxTimes < 1 && minScore < 1 && maxScore < 1 && winTimes < 1) { return(ResponseHelper.Create <LadderHookInfoResponse>(MessageCode.NbParameterError)); } if (IsExists(managerId)) { return(ResponseHelper.Create <LadderHookInfoResponse>(MessageCode.Success)); } var hook = LadderHookMgr.GetById(managerId); var nextMatchTime = DateTime.Now.AddSeconds(_ladderHookCD); var curTime = DateTime.Now; hook.UpdateTime = curTime; hook.RowTime = curTime; hook.NextMatchTime = nextMatchTime; hook.Status = 0; hook.CurTimes = 0; hook.CurWiningTimes = 0; hook.MaxTimes = maxTimes; hook.MinScore = minScore; hook.MaxScore = maxScore; hook.MaxWiningTimes = winTimes; hook.Expired = curTime.AddMinutes(_hookExpired); if (LadderHookMgr.Update(hook)) { AddToDic(hook); return(BuildHookInfoResponse(hook, true)); } else { return(ResponseHelper.Create <LadderHookInfoResponse>(MessageCode.NbUpdateFail)); } }
/// <summary> /// 更新挂机信息 /// </summary> /// <param name="managerId">经理ID</param> /// <param name="score">获得积分</param> /// <param name="isWin">是否胜利</param> /// <param name="homtScore">主队进球数</param> /// <param name="awayScore">客队进球数</param> /// <param name="homeName">主队名</param> /// <param name="awayName">客队名</param> /// <param name="myCoin">获得金币</param> public void UpdateHookScore(Guid managerId, int score, bool isWin, int homtScore, int awayScore, string homeName, string awayName, int myCoin) { try { LadderHookEntity entity = null; _hookDic.TryGetValue(managerId, out entity); if (entity != null) { if (entity.LadderManager != null) { entity.LadderManager.Score += score; entity.Score = entity.LadderManager.Score; } else { entity.Score += score; } entity.CurTimes++; if (isWin) { entity.CurWiningTimes++; } try { if (_hookListDic == null) { _hookListDic = new ConcurrentDictionary <Guid, List <LadderHook> >(); } if (!_hookListDic.ContainsKey(managerId)) { _hookListDic.TryAdd(managerId, new List <LadderHook>()); } if (_hookListDic[managerId].Count >= 10) { _hookListDic[managerId].RemoveAt(0); } LadderHook hookrecord = new LadderHook(); hookrecord.HomeName = homeName; hookrecord.AwayName = awayName; hookrecord.HomeScore = homtScore; hookrecord.AwayScore = awayScore; hookrecord.MyCoin = myCoin; hookrecord.MyIntegral = score; _hookListDic[managerId].Add(hookrecord); } catch (Exception e) { } if (HookEndCheck(entity)) { HookEnd(managerId, entity.Status); } else { LadderHookMgr.Update(entity); } } } catch (Exception ex) { SystemlogMgr.Error("UpdateLadderHookInfo", ex); } }