Example #1
0
        /// <summary>
        /// 初始化对手
        /// </summary>
        private void InitOpponent()
        {
            var allDangrading = CacheFactory.ArenaCache.AllDangrading;

            foreach (var item in allDangrading)
            {
                //获取某一段位的所有对手
                var list = ArenaManagerinfoMgr.RefreshOpponent(item.Idx, _domainId);
                if (list.Count > 0) //根据积分排序
                {
                    list = list.OrderBy(r => r.Integral).ToList();
                }
                var groupNumber = list.Count / 3; //计算每挡多少人
                for (int i = 1; i < 4; i++)       //每个段位分挡    3个对手
                {
                    var opponentList = new List <ArenaManagerinfoEntity>();
                    //把每挡的数据加到集合里
                    for (int j = groupNumber * (i - 1); j < groupNumber * i; j++)
                    {
                        opponentList.Add(list[j]);
                    }
                    //每挡不足5人时增加npc
                    if (opponentList.Count < 5)
                    {
                        var npcList = CacheFactory.ArenaCache.GetNpc(item.Idx, i);
                        if (npcList != null && npcList.Count > 0)
                        {
                            foreach (var npc in npcList)
                            {
                                if (opponentList.Count > 6)
                                {
                                    break;
                                }
                                var entity = new ArenaManagerinfoEntity();
                                entity.DanGrading = item.Idx;
                                entity.IsNpc      = true;
                                entity.ManagerId  = npc.NpcId;
                                var npcInfo = CacheFactory.NpcdicCache.GetNpc(npc.NpcId);
                                if (npcInfo != null)
                                {
                                    entity.ManagerName = npcInfo.Name;
                                    entity.Logo        = npcInfo.Logo.ToString();
                                    entity.Kpi         = npc.Kpi;
                                }
                                entity.IsNpc  = true;
                                entity.Status = 0;
                                opponentList.Add(entity);
                            }
                        }
                    }
                    //根据段位和对手序号获取KEY
                    var key = CacheFactory.ArenaCache.GetKey(item.Idx, i);
                    if (!_OpponentDic.ContainsKey(key))
                    {
                        _OpponentDic.TryAdd(key, new List <ArenaManagerinfoEntity>());
                    }
                    _OpponentDic[key] = opponentList;
                }
            }
        }
        /// <summary>
        /// 将IDataReader的当前记录读取到ArenaManagerinfoEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public ArenaManagerinfoEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new ArenaManagerinfoEntity();

            obj.ManagerId          = (System.Guid)reader["ManagerId"];
            obj.ManagerName        = (System.String)reader["ManagerName"];
            obj.SiteId             = (System.String)reader["SiteId"];
            obj.ZoneName           = (System.String)reader["ZoneName"];
            obj.Logo               = (System.String)reader["Logo"];
            obj.ChampionNumber     = (System.Int32)reader["ChampionNumber"];
            obj.Integral           = (System.Int32)reader["Integral"];
            obj.DanGrading         = (System.Int32)reader["DanGrading"];
            obj.ArenaCoin          = (System.Int32)reader["ArenaCoin"];
            obj.ArenaType          = (System.Int32)reader["ArenaType"];
            obj.Stamina            = (System.Int32)reader["Stamina"];
            obj.MaxStamina         = (System.Int32)reader["MaxStamina"];
            obj.BuyStaminaNumber   = (System.Int32)reader["BuyStaminaNumber"];
            obj.StaminaRestoreTime = (System.DateTime)reader["StaminaRestoreTime"];
            obj.Rank               = (System.Int32)reader["Rank"];
            obj.Status             = (System.Int32)reader["Status"];
            obj.Teammember1Status  = (System.Boolean)reader["Teammember1Status"];
            obj.Teammember2Status  = (System.Boolean)reader["Teammember2Status"];
            obj.Teammember3Status  = (System.Boolean)reader["Teammember3Status"];
            obj.Teammember4Status  = (System.Boolean)reader["Teammember4Status"];
            obj.Teammember5Status  = (System.Boolean)reader["Teammember5Status"];
            obj.UpdateTime         = (System.DateTime)reader["UpdateTime"];
            obj.RowTime            = (System.DateTime)reader["RowTime"];
            obj.Opponent           = (System.Byte[])reader["Opponent"];
            obj.DomainId           = (System.Int32)reader["DomainId"];

            return(obj);
        }
Example #3
0
        /// <summary>
        /// 设置排名
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="integral"></param>
        private void SetRank(Guid managerId, int integral)
        {
            ArenaManagerinfoEntity info = null;

            if (!_RankDic.ContainsKey(managerId))
            {
                info = ArenaManagerinfoMgr.GetById(managerId);
            }
            else
            {
                _RankDic.TryGetValue(managerId, out info);
            }
            if (info == null)
            {
                return;
            }
            if (info.Integral == integral && _RankDic.ContainsKey(managerId))
            {
                return;
            }
            info.Integral   = integral;
            info.UpdateTime = DateTime.Now;
            if (_RankDic.ContainsKey(managerId))
            {
                _RankDic[managerId] = info;
            }
            else
            {
                info.UpdateTime = DateTime.Now;
            }
            _RankDic.TryAdd(managerId, info);
            var list     = _RankDic.Values.OrderByDescending(r => r.Integral).ThenBy(r => r.UpdateTime).ToList();
            var rankDic  = new ConcurrentDictionary <Guid, ArenaManagerinfoEntity>();
            int rank     = 0;
            var rankList = new List <ArenaManagerinfoEntity>();

            foreach (var item in list)
            {
                rank++;
                item.Rank = rank;
                if (item.Rank > 10000)
                {
                    item.Rank = 0;
                }
                if (!rankDic.ContainsKey(item.ManagerId))
                {
                    rankDic.TryAdd(item.ManagerId, item);
                }
                if (item.Rank > 0)
                {
                    rankList.Add(item);
                }
            }
            _RankList = rankList;
            _RankDic  = rankDic;
        }
Example #4
0
        /// <summary>
        /// 将IDataReader的当前记录读取到ArenaManagerinfoEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public ArenaManagerinfoEntity LoadSingleRow1(IDataReader reader)
        {
            var obj = new ArenaManagerinfoEntity();

            obj.ManagerId   = (System.Guid)reader["ManagerId"];
            obj.Integral    = (System.Int32)reader["Integral"];
            obj.Rank        = (System.Int32)reader["Rank"];
            obj.UpdateTime  = (System.DateTime)reader["UpdateTime"];
            obj.Logo        = (System.String)reader["Logo"];
            obj.SiteId      = (System.String)reader["SiteId"];
            obj.ZoneName    = (System.String)reader["ZoneName"];
            obj.ManagerName = (System.String)reader["ManagerName"];
            return(obj);
        }
Example #5
0
        /// <summary>
        /// 获取我的排名详情
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public ArenaManagerinfoEntity GetRankInfo(Guid managerId)
        {
            ArenaManagerinfoEntity info = null;

            if (!_RankDic.ContainsKey(managerId))
            {
                info = ArenaManagerinfoMgr.GetById(managerId);
            }
            _RankDic.TryGetValue(managerId, out info);
            if (info == null)
            {
                return(null);
            }
            return(info);
        }
Example #6
0
        /// <summary>
        /// 获取我的排名
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public int GetRank(Guid managerId)
        {
            if (!_RankDic.ContainsKey(managerId))
            {
                return(0);
            }
            ArenaManagerinfoEntity info = null;

            _RankDic.TryGetValue(managerId, out info);
            if (info == null)
            {
                return(0);
            }
            return(info.Rank);
        }
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/9/1 13:59:50</remarks>
        public bool Update(ArenaManagerinfoEntity entity, DbTransaction trans)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_ArenaManagerinfo_Update");

            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId);
            database.AddInParameter(commandWrapper, "@ManagerName", DbType.AnsiString, entity.ManagerName);
            database.AddInParameter(commandWrapper, "@SiteId", DbType.AnsiString, entity.SiteId);
            database.AddInParameter(commandWrapper, "@ZoneName", DbType.AnsiString, entity.ZoneName);
            database.AddInParameter(commandWrapper, "@Logo", DbType.AnsiString, entity.Logo);
            database.AddInParameter(commandWrapper, "@ChampionNumber", DbType.Int32, entity.ChampionNumber);
            database.AddInParameter(commandWrapper, "@Integral", DbType.Int32, entity.Integral);
            database.AddInParameter(commandWrapper, "@DanGrading", DbType.Int32, entity.DanGrading);
            database.AddInParameter(commandWrapper, "@ArenaCoin", DbType.Int32, entity.ArenaCoin);
            database.AddInParameter(commandWrapper, "@ArenaType", DbType.Int32, entity.ArenaType);
            database.AddInParameter(commandWrapper, "@Stamina", DbType.Int32, entity.Stamina);
            database.AddInParameter(commandWrapper, "@MaxStamina", DbType.Int32, entity.MaxStamina);
            database.AddInParameter(commandWrapper, "@BuyStaminaNumber", DbType.Int32, entity.BuyStaminaNumber);
            database.AddInParameter(commandWrapper, "@StaminaRestoreTime", DbType.DateTime, entity.StaminaRestoreTime);
            database.AddInParameter(commandWrapper, "@Rank", DbType.Int32, entity.Rank);
            database.AddInParameter(commandWrapper, "@Status", DbType.Int32, entity.Status);
            database.AddInParameter(commandWrapper, "@Teammember1Status", DbType.Boolean, entity.Teammember1Status);
            database.AddInParameter(commandWrapper, "@Teammember2Status", DbType.Boolean, entity.Teammember2Status);
            database.AddInParameter(commandWrapper, "@Teammember3Status", DbType.Boolean, entity.Teammember3Status);
            database.AddInParameter(commandWrapper, "@Teammember4Status", DbType.Boolean, entity.Teammember4Status);
            database.AddInParameter(commandWrapper, "@Teammember5Status", DbType.Boolean, entity.Teammember5Status);
            database.AddInParameter(commandWrapper, "@UpdateTime", DbType.DateTime, entity.UpdateTime);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);
            database.AddInParameter(commandWrapper, "@Opponent", DbType.Binary, entity.Opponent);
            database.AddInParameter(commandWrapper, "@DomainId", DbType.Int32, entity.DomainId);


            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));
        }
        /// <summary>
        /// GetChampionMax
        /// </summary>
        /// <param name="domainId">domainId</param>
        /// <returns>ArenaManagerinfoEntity</returns>
        /// <remarks>2016/9/1 13:59:49</remarks>
        public ArenaManagerinfoEntity GetChampionMax(System.Int32 domainId)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("C_ArenaManagerInfo_GetChampionMax");

            database.AddInParameter(commandWrapper, "@DomainId", DbType.Int32, domainId);


            ArenaManagerinfoEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="managerId">managerId</param>
        /// <returns>ArenaManagerinfoEntity</returns>
        /// <remarks>2016/9/1 13:59:49</remarks>
        public ArenaManagerinfoEntity GetById(System.Guid managerId)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("P_ArenaManagerinfo_GetById");

            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, managerId);


            ArenaManagerinfoEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
Example #10
0
        /// <summary>
        /// 计算段位
        /// </summary>
        /// <param name="arenaInfo"></param>
        /// <returns></returns>
        private void CalculateDanGrading(ref ArenaManagerinfoEntity arenaInfo)
        {
            if (arenaInfo == null)
            {
                return;
            }
            int index = 0;

            do
            {
                index++;
                if (arenaInfo.DanGrading == 1)
                {
                    break;
                }
                var dangradingConfig = CacheFactory.ArenaCache.GetDangrading(arenaInfo.DanGrading);
                if (arenaInfo.Integral < dangradingConfig.Integral)
                {
                    break;
                }
                arenaInfo.ArenaCoin += dangradingConfig.PrizeArenaCoin;
                arenaInfo.DanGrading = dangradingConfig.Idx - 1;
            } while (index < 5);
        }
 /// <summary>
 /// Update
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 /// <remarks>2016/9/1 13:59:50</remarks>
 public bool Update(ArenaManagerinfoEntity entity)
 {
     return(Update(entity, null));
 }
 /// <summary>
 /// Insert
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="trans">The trans.</param>
 /// <returns></returns>
 /// <remarks>2016/9/1 13:59:50</remarks>
 public bool Insert(ArenaManagerinfoEntity entity)
 {
     return(Insert(entity, null));
 }
Example #13
0
        /// <summary>
        /// 体力恢复
        /// </summary>
        /// <param name="arenaManagerInfo"></param>
        /// <param name="isUpdate"></param>
        /// <returns></returns>
        public ArenaStamina RestoreStamina(ArenaManagerinfoEntity arenaManagerInfo, bool isUpdate = false)
        {
            ArenaStamina response = new ArenaStamina();
            DateTime     dateTime = DateTime.Now;

            try
            {
                int staminaStartStopHour = 1;
                int staminaEndStopHour   = 8;
                //用于比较的恢复时间截止点
                DateTime restoreTime = dateTime;
                int      hour        = dateTime.Hour;
                response.IsRestoreStamina = true;
                //恢复时间截止1点
                if (hour >= staminaStartStopHour && hour < staminaEndStopHour)
                {
                    restoreTime = dateTime.Date.AddHours(staminaStartStopHour);
                    response.IsRestoreStamina = false;
                }
                if (arenaManagerInfo == null)
                {
                    response.Stamina    = CacheFactory.ArenaCache.ArenaMaxStamina;
                    response.MaxStamina = CacheFactory.ArenaCache.ArenaMaxStamina;
                    return(response);
                }
                var vipLevel = 0;
                var manager  = ManagerCore.Instance.GetManager(arenaManagerInfo.ManagerId, arenaManagerInfo.SiteId);
                if (manager != null)
                {
                    vipLevel = manager.VipLevel;
                }
                //获取多少秒恢复1点体力
                var restoreTimes   = CacheFactory.ArenaCache.StaminaRestoreTime(vipLevel);
                var presentStamina = arenaManagerInfo.Stamina;
                response.Stamina      = presentStamina;
                response.MaxStamina   = arenaManagerInfo.MaxStamina;
                response.Stamina      = arenaManagerInfo.Stamina;
                response.RestoreTimes = restoreTimes;
                if (arenaManagerInfo.Stamina >= arenaManagerInfo.MaxStamina)
                {
                    return(response);
                }

                //每天8点恢复所有体力
                if (hour >= staminaEndStopHour && arenaManagerInfo.StaminaRestoreTime < DateTime.Now.Date.AddHours(staminaEndStopHour))
                {
                    arenaManagerInfo.StaminaRestoreTime = DateTime.Now.AddDays(-1);
                }
                //上次恢复体力距离现在时间
                var lastTime = (int)restoreTime.Subtract(arenaManagerInfo.StaminaRestoreTime).TotalSeconds;
                if (lastTime <= 0)
                {
                    return(response);
                }
                //恢复多少体力
                var stamina = lastTime / restoreTimes;
                if (stamina <= 0)
                {
                    response.NextRestoreStaminaTick =
                        ShareUtil.GetTimeTick(arenaManagerInfo.StaminaRestoreTime.AddSeconds(restoreTimes));
                    return(response);
                }
                arenaManagerInfo.Stamina += stamina;
                if (arenaManagerInfo.Stamina > arenaManagerInfo.MaxStamina)
                {
                    arenaManagerInfo.Stamina = arenaManagerInfo.MaxStamina;
                }
                presentStamina = arenaManagerInfo.Stamina;
                arenaManagerInfo.StaminaRestoreTime = dateTime;
                if (arenaManagerInfo.Stamina < arenaManagerInfo.MaxStamina)
                {
                    //恢复体力后多出来的秒数
                    var surplusTime = lastTime % restoreTimes;
                    arenaManagerInfo.StaminaRestoreTime = dateTime.AddSeconds(-surplusTime);
                    //下次恢复时间
                    response.NextRestoreStaminaTick =
                        ShareUtil.GetTimeTick(arenaManagerInfo.StaminaRestoreTime.AddSeconds(restoreTimes));
                }
                else
                {
                    response.NextRestoreStaminaTick = 0;
                }
                response.Stamina      = presentStamina;
                response.MaxStamina   = arenaManagerInfo.MaxStamina;
                response.Stamina      = arenaManagerInfo.Stamina;
                response.RestoreTimes = restoreTimes;
                if (isUpdate)
                {
                    ArenaManagerinfoMgr.Update(arenaManagerInfo);
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("体力恢复", ex);
            }
            return(response);
        }
        public static bool Update(ArenaManagerinfoEntity arenaManagerinfoEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new ArenaManagerinfoProvider(zoneId);

            return(provider.Update(arenaManagerinfoEntity, trans));
        }