Exemplo n.º 1
0
        PenaltykickManagerEntity GetManager(Guid managerId)
        {
            var      info = PenaltykickManagerMgr.GetById(managerId);
            DateTime date = DateTime.Now;

            if (info == null)
            {
                if (IsActivity)
                {
                    //默认1次免费次数,每天最多产出5个
                    info = new PenaltykickManagerEntity(managerId, 0, 1, 0, 5, 0, 0, 0, 0, "", 0, 0, RefreshExChange(),
                                                        0, 0,
                                                        false, date, date, date, date);
                    PenaltykickManagerMgr.Insert(info);
                }
                else
                {
                    info = new PenaltykickManagerEntity(managerId, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, 0, RefreshExChange(),
                                                        0, 0,
                                                        false, date, date, date, date);
                }
            }
            //每天补充免费次数
            if (info.RefreshDate.Date != date.Date)
            {
                if (IsActivity)
                {
                    info.FreeNumber          = 1;
                    info.DayProduceLuckyCoin = 5;
                    info.RefreshDate         = date;
                    PenaltykickManagerMgr.Update(info);
                }
            }
            return(info);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 刷新点球兑换
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public PenaltyKickExChangeResponse RefreshExChange(Guid managerId)
        {
            PenaltyKickExChangeResponse response = new PenaltyKickExChangeResponse();

            response.Data = new PenaltyKickExChange();
            try
            {
                var info = GetManager(managerId);
                if (info == null)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.MissManager));
                }
                var point = PayCore.Instance.GetPoint(managerId);
                if (point < _refreshExChangePoint)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.NbPointShortage));
                }
                info.ExChangeString = RefreshExChange();
                var exList = GetExChangeEntity(info.ExChangeString);
                info.ExChangeString = SetExChangeString(exList);
                info.UpdateTime     = DateTime.Now;
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    var messageCode = MessageCode.NbUpdateFail;
                    do
                    {
                        messageCode = PayCore.Instance.GambleConsume(managerId, _refreshExChangePoint, ShareUtil.GenerateComb(),
                                                                     EnumConsumeSourceType.AdTopScoreResetExchange, transactionManager.TransactionObject);
                        if (messageCode != MessageCode.Success)
                        {
                            break;
                        }
                        messageCode = MessageCode.NbUpdateFail;
                        if (!PenaltykickManagerMgr.Update(info, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messageCode = MessageCode.Success;
                    } while (false);
                    if (messageCode != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <PenaltyKickExChangeResponse>(messageCode));
                    }
                    transactionManager.Commit();
                }
                response.Data.AvailableScore = info.AvailableScore;
                response.Data.ExChangeList   = exList;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("刷新点球兑换", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 积分兑换
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="itemCode"></param>
        /// <returns></returns>
        public PenaltyKickExChangeResponse ExChange(Guid managerId, int itemCode)
        {
            PenaltyKickExChangeResponse response = new PenaltyKickExChangeResponse();

            response.Data = new PenaltyKickExChange();
            try
            {
                var info = GetManager(managerId);
                if (info == null)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.MissManager));
                }
                var exList = GetExChangeEntity(info.ExChangeString);
                if (exList == null)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.NbParameterError));
                }
                //获取要兑换的物品
                var exItem = exList.Find(r => r.ItemCode == itemCode);
                if (exItem == null)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.ExChangeItemNot));
                }
                //已经兑换过
                if (exItem.Status == 1)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.RepeatExChange));
                }
                //积分不足
                if (info.AvailableScore < exItem.Price)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.LadderExchangeScoreShortage));
                }
                info.AvailableScore = info.AvailableScore - exItem.Price;
                exItem.Status       = 1;
                //所有物品都兑换完了  自动刷新
                if (!exList.Exists(r => r.Status == 0))
                {
                    info.ExChangeString = RefreshExChange();
                    exList = GetExChangeEntity(info.ExChangeString);
                }
                else
                {
                    info.ExChangeString = SetExChangeString(exList);
                }

                info.UpdateTime = DateTime.Now;
                var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.AdTopScorerKeep);
                if (package == null)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(MessageCode.NbParameterError));
                }
                var messageCode = package.AddItem(exItem.ItemCode);
                if (messageCode != MessageCode.Success)
                {
                    return(ResponseHelper.Create <PenaltyKickExChangeResponse>(messageCode));
                }
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    messageCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (!package.Save(transactionManager.TransactionObject))
                        {
                            break;
                        }
                        if (!PenaltykickManagerMgr.Update(info, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messageCode = MessageCode.Success;
                    } while (false);
                    if (messageCode != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <PenaltyKickExChangeResponse>(messageCode));
                    }
                    transactionManager.Commit();
                    package.Shadow.Save();
                }
                response.Data.AvailableScore = info.AvailableScore;
                response.Data.ExChangeList   = exList;
                response.Data.ItemCode       = exItem.ItemCode;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("点球积分兑换", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 开始射门
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public PenaltyKickShootResponse Shoot(Guid managerId)
        {
            var response = new PenaltyKickShootResponse();

            response.Data = new PenaltyKickShoot();
            try
            {
                if (!IsActivity)
                {
                    return(ResponseHelper.Create <PenaltyKickShootResponse>(MessageCode.AdMissSeason));
                }
                var info = GetManager(managerId);
                if (info == null)
                {
                    return(ResponseHelper.Create <PenaltyKickShootResponse>(MessageCode.MissManager));
                }
                if (info.Status != 1)
                {
                    return(ResponseHelper.Create <PenaltyKickShootResponse>(MessageCode.GameEnd));
                }
                if (info.ShootLog.Length > 0)
                {
                    var shootList = info.ShootLog.Split(',');
                    if (shootList.Length >= 5)
                    {
                        return(ResponseHelper.Create <PenaltyKickShootResponse>(MessageCode.GameEnd));
                    }
                }
                //背包满了  不让踢球
                var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.AdTopScorerKeep);
                if (package == null)
                {
                    return(ResponseHelper.Create <PenaltyKickShootResponse>(MessageCode.NbParameterError));
                }
                if (package.IsFull)
                {
                    return(ResponseHelper.Create <PenaltyKickShootResponse>(MessageCode.ItemPackageFull));
                }
                //射门结果
                var shootResult = GetShootResult(info.ShooterAttribute);
                //射门结果处理
                Shoot(info, shootResult.IsGoals);
                int score = 0;
                //进球了才有奖励
                var prizeList = new List <PrizeEntity>();
                if (shootResult.IsGoals)
                {
                    score++; //每进一球加一点
                    prizeList = GetPrize(info.ShootLog, info.MaxCombGoals);
                    foreach (var item in prizeList)
                    {
                        switch (item.ItemType)
                        {
                        case 3:     //物品
                            var code = package.AddItems(item.ItemCode, item.ItemCount);
                            if (code != MessageCode.Success)
                            {
                                return(ResponseHelper.Create <PenaltyKickShootResponse>(code));
                            }
                            break;

                        case 5:     //积分
                            score += item.ItemCount;
                            break;
                        }
                    }
                    info.AvailableScore += score;
                    info.TotalScore     += score;
                    info.ScoreChangeTime = DateTime.Now;
                }
                info.UpdateTime = DateTime.Now;
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    var messageCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (shootResult.IsGoals)
                        {
                            if (!package.Save(transactionManager.TransactionObject))
                            {
                                break;
                            }
                        }
                        if (!PenaltykickManagerMgr.Update(info, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messageCode = MessageCode.Success;
                    } while (false);
                    if (messageCode != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <PenaltyKickShootResponse>(messageCode));
                    }
                    transactionManager.Commit();
                    package.Shadow.Save();
                }

                response.Data.Info        = GetManagerInfoResponse(info);
                response.Data.ShootResult = shootResult;
                response.Data.ItemList    = prizeList;
                //更新排名信息
                UpdateRank(info);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("点球射门", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 开始游戏
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public GetPenaltyKickInfoResponse Join(Guid managerId)
        {
            var response = new GetPenaltyKickInfoResponse();

            response.Data = new GetPenaltyKickInfo();
            try
            {
                //不在活动时间内
                if (!IsActivity)
                {
                    return(ResponseHelper.Create <GetPenaltyKickInfoResponse>(MessageCode.AdMissSeason));
                }
                var manager = ManagerCore.Instance.GetManager(managerId);
                if (null == manager)
                {
                    return(ResponseHelper.Create <GetPenaltyKickInfoResponse>(MessageCode.MissManager));
                }
                var info = GetManager(managerId);
                if (info == null)
                {
                    return(ResponseHelper.Create <GetPenaltyKickInfoResponse>(MessageCode.MissManager));
                }
                //游戏还未结束
                if (info.Status == 1)
                {
                    return(ResponseHelper.Create <GetPenaltyKickInfoResponse>(MessageCode.GameNotEnd));
                }
                bool isfree = false;
                if (info.FreeNumber > 0)
                {
                    info.FreeNumber--;
                    isfree = true;
                }
                else
                {
                    if (info.GameCurrency <= 0)
                    {
                        return(ResponseHelper.Create <GetPenaltyKickInfoResponse>(MessageCode.GameCurrencyNumberNot));
                    }
                    info.GameCurrency--;
                }
                info.Status = 1;
                //获取踢球球员属性
                var shooterAttribute = GetShooterId(managerId);
                if (shooterAttribute == 0)
                {
                    return(ResponseHelper.Create <GetPenaltyKickInfoResponse>(MessageCode.NbParameterError));
                }
                info.ShooterAttribute = shooterAttribute;
                info.ShootNumber++;
                info.ShootLog     = "";
                info.CombGoals    = 0;
                info.MaxCombGoals = 0;
                info.UpdateTime   = DateTime.Now;
                if (!PenaltykickManagerMgr.Update(info))
                {
                    return(ResponseHelper.Create <GetPenaltyKickInfoResponse>(MessageCode.NbUpdateFail));
                }
                //插入消费记录
                PenaltykickManagerMgr.InsertRecord(managerId, 1, isfree);
                response.Data = GetManagerInfoResponse(info);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("点球开始游戏", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Exemplo n.º 6
0
        private MessageCode SendPrize(PenaltykickSeasonEntity seasonInfo)
        {
            if (seasonInfo.Idx == 0)
            {
                return(MessageCode.Success);
            }
            PenaltykickManagerMgr.SetRank();
            var prizeList = PenaltykickManagerMgr.GetNotPrize(seasonInfo.Idx);

            seasonInfo.IsPrize   = true;
            seasonInfo.PrizeTime = DateTime.Now;
            foreach (var item in prizeList)
            {
                if (item.IsPrize || item.TotalScore < 500)
                {
                    continue;
                }
                item.IsPrize = true;
                //排名奖励
                var prize = CacheFactory.AdCache.GetPrize(3, item.Rank);
                if (prize == null || prize.Count == 0)
                {
                    continue;
                }
                //邮件
                var mail = new MailBuilder(item.Rank, item.ManagerId);
                foreach (var p in prize)
                {
                    switch (p.ItemType)
                    {
                    case 3:    //暂时只有物品奖励
                        mail.AddAttachment(p.ItemCount, p.ItemCode, false, 1);
                        break;

                    case 10:    //金条
                        mail.AddAttachment(EnumCurrencyType.GoldBar, p.ItemCount);
                        break;
                    }
                }
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    var messageCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (!PenaltykickManagerMgr.Update(item, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        if (!mail.Save(transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messageCode = MessageCode.Success;
                    } while (false);
                    if (messageCode != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                    }
                    transactionManager.Commit();
                }
            }
            PenaltykickSeasonMgr.Update(seasonInfo);
            return(MessageCode.Success);
        }