Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="point3"></param>
        /// <param name="point4"></param>
        /// <param name="point5"></param>
        /// <param name="point6"></param>
        /// <param name="point7"></param>
        /// <param name="point8"></param>
        /// <param name="beforeUpdate"></param>
        /// <returns></returns>
        //public void TryUpdateUserPoint(int point1, int point2, int point3, int point4, int point5, int point6, int point7, int point8, TryUpdateUserPointCallback beforeUpdate)
        //{
        //    if (IsExecutorLogin)
        //    {
        //        lock (this.GetUser(ExecutorID))
        //        {
        //            //TODO:实现功能  如果有一个积分达到了下限 其它积分也都不更新 并抛错

        //            bool updatePoint = false;
        //            beforeUpdate(TryUpdateUserPointState.CheckSucceed,out updatePoint);
        //        }
        //    }
        //    else
        //    {
        //        //beforeUpdate(TryUpdateUserPointState.NeedLogin);
        //    }

        //}


        public static Dictionary <UserPoint, int> GetActionUserPointValue <T>(int userId, string type, T actionType, int nodeID)
        {
            int[] points = null;

            PointAction pointAction = AllSettings.Current.PointActionSettings.PointActions.GetPointAction(type, nodeID);

            if (pointAction == null)
            {
                pointAction = AllSettings.Current.PointActionSettings.PointActions.GetPointAction(type, 0);
            }

            points = pointAction.GetPoints(actionType.ToString(), userId);
            //foreach (PointAction pointAction in AllSettings.Current.PointActionSettings.PointActions)
            //{
            //    if (string.Compare(pointAction.Type, type) == 0)
            //    {
            //        points = pointAction.GetPoints(actionType.ToString(), userId);
            //        break;
            //    }
            //}
            //if (points == null)
            //    return new Dictionary<UserPoint, int>();

            Dictionary <UserPoint, int> userPoints = new Dictionary <UserPoint, int>();

            foreach (UserPoint userPoint in AllSettings.Current.PointSettings.EnabledUserPoints)
            {
                int pointID = (int)userPoint.Type;
                if (points.Length > pointID && points[pointID] != 0)
                {
                    userPoints.Add(userPoint, points[pointID]);
                }
            }
            return(userPoints);
        }
Exemple #2
0
        public static bool UpdateUserPoint <T>(int userID, string type, T actionType, int count, bool isNormal, int nodeId, TryUpdateUserPointCallback beforeUpdate) where T : struct
        {
            if (userID == 0)//游客  不操作积分
            {
                if (beforeUpdate != null)
                {
                    beforeUpdate(TryUpdateUserPointState.CheckSucceed);
                }

                return(true);
            }

            int[]       points      = null;
            PointAction pointAction = AllSettings.Current.PointActionSettings.PointActions.GetPointAction(type, nodeId);

            //foreach (PointAction pointAction in AllSettings.Current.PointActionSettings.PointActions)
            //{
            //    if (string.Compare(pointAction.Type, type) == 0)
            //    {
            //        points = pointAction.GetPoints(actionType.ToString(), userID);
            //        break;
            //    }
            //}
            points = pointAction.GetPoints(actionType.ToString(), userID);
            if (points == null)
            {
                if (beforeUpdate != null)
                {
                    beforeUpdate(TryUpdateUserPointState.CheckSucceed);
                }
                return(true);
            }
            if (isNormal == false)//取相反的值
            {
                for (int i = 0; i < points.Length; i++)
                {
                    points[i] = -points[i];
                }
            }
            return(UpdateUserPoints <T>(type, actionType, false, userID, points, count, beforeUpdate));
        }
Exemple #3
0
        /*
         * public static bool UpdateUsersPointWithNoTrans<T>(Dictionary<int, T> userActions, string type, int count, int nodeID, TryUpdateUserPointCallback beforeUpdate) where T : struct
         * {
         *
         *  List<int> userIDs = new List<int>();
         *  foreach (KeyValuePair<int, T> pair in userActions)
         *  {
         *      userIDs.Add(pair.Key);
         *  }
         *  //先缓存一下用户
         *  UserBO.Instance.GetUsers(userIDs);
         *
         *  bool success = true;
         *  foreach (KeyValuePair<int, T> pair in userActions)
         *  {
         *      if (pair.Key == 0)//游客
         *          continue;
         *
         *      success = CheckPoints(pair.Key, type, pair.Value, 1, true, nodeID);
         *      if (success == false)
         *          break;
         *  }
         *
         *  if (success == false)
         *  {
         *      beforeUpdate(TryUpdateUserPointState.CheckFailed);
         *      return false;
         *  }
         *
         *  success = beforeUpdate(TryUpdateUserPointState.CheckSucceed);
         *
         *  //TODO:更新积分
         *  return success;
         *  //if (success)
         *  //{
         *  //    foreach (KeyValuePair<int, T> pair in userActions)
         *  //    {
         *  //        UserBO.Instance.UpdateUserPoints(
         *  //    }
         *  //}
         * }
         */
        private static bool CheckPoints <T>(int userID, string type, T actionType, int count, bool isNormal, int nodeID) where T : struct
        {
            int[]       points      = null;
            PointAction pointAction = AllSettings.Current.PointActionSettings.PointActions.GetPointAction(type, nodeID);

            points = pointAction.GetPoints(actionType.ToString(), userID);
            if (points == null)
            {
                return(true);
            }
            if (isNormal == false)//取相反的值
            {
                for (int i = 0; i < points.Length; i++)
                {
                    points[i] = -points[i];
                }
            }

            User user = UserBO.Instance.GetUser(userID);

            if (user == null)//可能该主题用户已被删除  但是不影响回复的人更新积分
            {
                return(true);
            }

            PointActionItemAttribute attribute = GetPointActionItemAttribute(type, actionType, false);

            if (attribute == null)
            {
                return(false);
            }

            lock (user.UpdateUserPointLocker)
            {
                //int[] userPoints;
                //bool success = PointActionManager.CheckPoints(attribute.ThrowOverMaxValue, attribute.ThrowOverMinValue, userID, points, out userPoints);
                bool success = UserBO.Instance.CheckUserPoint(userID, attribute.ThrowOverMinValue, attribute.ThrowOverMaxValue, points);
                return(success);
            }
        }
Exemple #4
0
        protected int[] GetPoints(string actionType)
        {
            string key = actionType;

            int[] tempPoints;
            if (points.TryGetValue(key, out tempPoints) == false)
            {
                PointAction pointAction = AllSettings.Current.PointActionSettings.PointActions.GetPointAction(PointActionType.Type, NodeID);

                if (pointAction == null)
                {
                    pointAction = AllSettings.Current.PointActionSettings.PointActions.GetPointAction(PointActionType.Type, NodeID);
                }

                tempPoints = pointAction.GetPoints(actionType, MyUserID);
                if (tempPoints == null)
                {
                    tempPoints = new int[8];
                }

                points.Add(key, tempPoints);
            }
            return(tempPoints);
        }