public MessageCode HookAttend(LadderHookEntity entity) { if (!IsManagerBusy(entity.ManagerId)) { if (!CompetitorDic.ContainsKey(entity.ManagerId)) { entity.LadderManager.UpdateTime = DateTime.Now; //锁住 lock (_competitorLock) { if (_playerNum == 0) { StartTime = DateTime.Now; } CompetitorDic.Add(entity.ManagerId, entity.LadderManager); _playerNum++; } } return(MessageCode.Success); } else { return(MessageCode.LadderBusy); } }
bool AddToDic(LadderHookEntity entity) { var manager = ManagerCore.Instance.GetManager(entity.ManagerId); if (manager == null) { return(false); } var arenaManager = LadderCore.Instance.InnerGetLadderManager(entity.ManagerId); if (arenaManager == null) { return(false); } arenaManager.IsBot = false; arenaManager.Name = manager.Name; arenaManager.UpdateTime = DateTime.Now; arenaManager.HasTask = true; arenaManager.IsHook = true; entity.Score = arenaManager.Score; entity.Status = (int)EnumHookStatus.Run; entity.LadderManager = arenaManager; if (_hookDic.ContainsKey(entity.ManagerId)) { _hookDic[entity.ManagerId] = entity; } else { _hookDic.TryAdd(entity.ManagerId, entity); } return(true); }
public LadderHookInfoResponse GetHookInfoResponse(Guid managerId) { LadderHookEntity hook = null; _hookDic.TryGetValue(managerId, out hook); return(GetHookInfoResponse(managerId, hook, true)); }
/// <summary> /// 带事务的Update /// </summary> /// <param name="entity"></param> /// <param name="trans">The trans.</param> /// <returns></returns> /// <remarks>2016-06-20 8:50:07</remarks> public bool Update(LadderHookEntity entity, DbTransaction trans = null) { var database = new SqlDatabase(this.ConnectionString); DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_LadderHook_Update"); database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId); database.AddInParameter(commandWrapper, "@CurTimes", DbType.Int32, entity.CurTimes); database.AddInParameter(commandWrapper, "@CurWiningTimes", DbType.Int32, entity.CurWiningTimes); database.AddInParameter(commandWrapper, "@MaxTimes", DbType.Int32, entity.MaxTimes); database.AddInParameter(commandWrapper, "@MinScore", DbType.Int32, entity.MinScore); database.AddInParameter(commandWrapper, "@MaxScore", DbType.Int32, entity.MaxScore); database.AddInParameter(commandWrapper, "@MaxWiningTimes", DbType.Int32, entity.MaxWiningTimes); database.AddInParameter(commandWrapper, "@NextMatchTime", DbType.DateTime, entity.NextMatchTime); database.AddInParameter(commandWrapper, "@Status", DbType.Int32, entity.Status); database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime); database.AddInParameter(commandWrapper, "@UpdateTime", DbType.DateTime, entity.UpdateTime); database.AddInParameter(commandWrapper, "@Expired", DbType.DateTime, entity.Expired); int results = 0; if (trans != null) { results = database.ExecuteNonQuery(commandWrapper, trans); } else { results = database.ExecuteNonQuery(commandWrapper); } entity.ManagerId = (System.Guid)database.GetParameterValue(commandWrapper, "@ManagerId"); return(Convert.ToBoolean(results)); }
bool HookEnd(Guid managerId, int hookStatus) { if (LadderHookMgr.End(managerId, hookStatus)) { var e = new LadderHookEntity(); _hookDic.TryRemove(managerId, out e); return(true); } return(false); }
public LadderHookInfoResponse GetHookInfoResponse(Guid managerId, LadderHookEntity hook, bool isHook = false) { if (hook != null) { if (hook.Status >= (int)EnumHookStatus.Run) { return(BuildHookInfoResponse(hook, isHook)); } } var response = ResponseHelper.CreateSuccess <LadderHookInfoResponse>(); response.Data = new LadderHookInfoEntity(); return(response); }
void Hook(LadderHookEntity entity) { if (HookEndCheck(entity)) { _finishList.Add(entity); return; } DateTime compareTime = DateTime.Now; if (compareTime < entity.NextMatchTime) { return; } entity.NextMatchTime = compareTime.AddSeconds(_ladderHookCD); LadderCore.Instance.HookAttend(entity); }
/// <summary> /// 将IDataReader的当前记录读取到LadderHookEntity 对象 /// </summary> /// <param name="reader"></param> /// <returns></returns> public LadderHookEntity LoadSingleRow(IDataReader reader) { var obj = new LadderHookEntity(); obj.ManagerId = (System.Guid)reader["ManagerId"]; obj.CurTimes = (System.Int32)reader["CurTimes"]; obj.CurWiningTimes = (System.Int32)reader["CurWiningTimes"]; obj.MaxTimes = (System.Int32)reader["MaxTimes"]; obj.MinScore = (System.Int32)reader["MinScore"]; obj.MaxScore = (System.Int32)reader["MaxScore"]; obj.MaxWiningTimes = (System.Int32)reader["MaxWiningTimes"]; obj.NextMatchTime = (System.DateTime)reader["NextMatchTime"]; obj.Status = (System.Int32)reader["Status"]; obj.RowTime = (System.DateTime)reader["RowTime"]; obj.UpdateTime = (System.DateTime)reader["UpdateTime"]; obj.Expired = (System.DateTime)reader["Expired"]; return(obj); }
/// <summary> /// GetById /// </summary> /// <param name="managerId">managerId</param> /// <returns>LadderHookEntity</returns> /// <remarks>2016-06-20 8:50:07</remarks> public LadderHookEntity GetById(System.Guid managerId) { var database = new SqlDatabase(this.ConnectionString); DbCommand commandWrapper = database.GetStoredProcCommand("C_LadderHook_GetById"); database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, managerId); LadderHookEntity obj = null; using (IDataReader reader = database.ExecuteReader(commandWrapper)) { if (reader.Read()) { obj = LoadSingleRow(reader); } } return(obj); }
bool HookEndCheck(LadderHookEntity entity) { if (entity.Status != (int)EnumHookStatus.Run) { return(true); } if (entity.Expired <= DateTime.Now) { return(true); } int local = entity.Status; entity.Status = (int)EnumHookStatus.Finish; if (entity.MaxTimes > 0 && entity.CurTimes >= entity.MaxTimes) { return(true); } if (entity.MaxWiningTimes > 0 && entity.CurWiningTimes >= entity.MaxWiningTimes) { return(true); } if (entity.Score > 0) { if (entity.MaxScore > 0 && entity.Score >= entity.MaxScore) { return(true); } if (entity.MinScore > 0 && entity.Score <= entity.MinScore) { return(true); } } if (entity.MaxTimes < 1 && entity.MinScore < 1 && entity.MaxScore < 1 && entity.MaxWiningTimes < 1) { return(true); } entity.Status = local; return(false); }
LadderHookInfoResponse BuildHookInfoResponse(LadderHookEntity entity, bool isHook) { var response = ResponseHelper.CreateSuccess <LadderHookInfoResponse>(); response.Data = new LadderHookInfoEntity(); response.Data.IsHook = isHook; response.Data.CurTimes = entity.CurTimes; response.Data.CurWiningTimes = entity.CurWiningTimes; response.Data.MaxScore = entity.MaxScore; response.Data.MaxTimes = entity.MaxTimes; response.Data.MinScore = entity.MinScore; response.Data.LadderHookList = new List <LadderHook>(); if (_hookListDic.ContainsKey(entity.ManagerId)) { response.Data.LadderHookList = _hookListDic[entity.ManagerId]; } var curTime = DateTime.Now; response.Data.NextMatchWaitSeconds = isHook ? ShareUtil.CalWaitTime(entity.NextMatchTime, curTime) : 0; response.Data.ExpiredTick = ShareUtil.GetTimeTick(entity.Expired); return(response); }
/// <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); } }
public static bool Update(LadderHookEntity ladderHookEntity, DbTransaction trans = null, string zoneId = "") { var provider = new LadderHookProvider(zoneId); return(provider.Update(ladderHookEntity, trans)); }