Exemple #1
0
        public static bool SaveManagerData(NbManagerEntity manager, NbManagerextraEntity extra, bool openTask = true,
                                           DbTransaction transaction = null, string zoneId = "")
        {
            try
            {
                var functionList = manager.FunctionList;
                if (manager.IsLevelup)
                {
                    var function = CacheFactory.ManagerDataCache.GetFunctionList(manager.Level);
                    if (function != null)
                    {
                        if (function.FunctionId > 0)
                        {
                            manager.AddOpenFunc(function.FunctionId);
                        }
                        functionList = function.FunctionList;
                        if (extra != null)
                        {
                            extra.FunctionList = functionList;
                        }
                    }
                }
                int returnCode        = -2;
                var levelGiftExpired  = ShareUtil.BaseTime;
                var levelGiftExpired2 = ShareUtil.BaseTime;
                var levelGiftExpired3 = ShareUtil.BaseTime;
                int step = 0;
                if (manager.IsLevelup)
                {
                    step = CacheFactory.ManagerDataCache.GetLevelgiftStep(manager.Level);
                    if (step > 0)
                    {
                        manager.OpenLevelGift = true;
                        switch (step)
                        {
                        case 1:
                            levelGiftExpired = DateTime.Now.AddHours(72);
                            break;

                        case 2:
                            levelGiftExpired2 = DateTime.Now.AddHours(72);
                            break;

                        case 3:
                            levelGiftExpired3 = DateTime.Now.AddHours(72);
                            break;
                        }
                        if (extra != null)
                        {
                            extra.LevelGiftExpired  = levelGiftExpired;
                            extra.LevelGiftExpired2 = levelGiftExpired2;
                            extra.LevelGiftExpired3 = levelGiftExpired3;
                            extra.LevelGiftStep     = step;
                        }
                    }
                }
                NbManagerMgr.Save(manager.Idx, manager.Level, manager.EXP, manager.Sophisticate, manager.Score, manager.Coin,
                                  manager.Reiki, manager.TeammemberMax, manager.TrainSeatMax, manager.VipLevel,
                                  functionList, levelGiftExpired, levelGiftExpired2, levelGiftExpired3, step, manager.RowVersion, ref returnCode, transaction, zoneId);
                if (returnCode != 0)
                {
                    return(false);
                }
                manager.FunctionList = functionList;

                try
                {
                    if (manager.IsLevelup)
                    {
                        var code = SkillCardRules.SetSkillMapByManagerLevel(manager, transaction);
                        if (code != MessageCode.Success)
                        {
                            return(false);
                        }

                        var addSkillPoint = CacheFactory.ManagerDataCache.GetAddSkillPointByLevel(manager.Level);
                        if (extra != null)
                        {
                            extra.SkillPoint += addSkillPoint;
                        }
                        else
                        {
                            if (!NbManagerextraMgr.AddSkillPoint(manager.Idx, addSkillPoint, transaction))
                            {
                                return(false);
                            }
                        }

                        CalCurrentStamina(extra, manager.Level, manager.VipLevel);
                        if (extra == null)
                        {
                            extra = ManagerCore.Instance.GetManagerExtra(manager.Idx);
                            if (extra.Stamina < extra.StaminaMax)
                            {
                                extra.Stamina = extra.StaminaMax;
                                // extra.Stamina += ManagerLevelupAddStamina;
                                //if (extra.Stamina > extra.StaminaMax)
                                //    extra.Stamina = extra.StaminaMax;
                                extra.ResumeStaminaTime = DateTime.Now;
                                NbManagerextraMgr.Update(extra, transaction);
                            }
                        }
                        else
                        {
                            if (extra.Stamina < extra.StaminaMax)
                            {
                                extra.Stamina           = extra.StaminaMax;
                                extra.ResumeStaminaTime = DateTime.Now;
                            }
                        }

                        //if (TaskCore.Instance.CheckOpenDailyTask(manager.Level))
                        //{
                        //    var daily = TaskDailyrecordMgr.GetById(manager.Idx, zoneId);
                        //    if (daily == null)
                        //    {
                        //        var entity = TaskCore.Instance.CreateDailyTask(manager.Idx);
                        //        if (!TaskDailyrecordMgr.Insert(entity, transaction, zoneId))
                        //            return false;
                        //    }
                        //}
                        if (openTask)
                        {
                            List <TaskRecordEntity> newTasks = new List <TaskRecordEntity>();
                            TaskCore.Instance.GetLevelOpenTasks(manager.Idx, manager.Level, ref newTasks, zoneId);
                            if (newTasks.Count > 0)
                            {
                                foreach (var entity in newTasks)
                                {
                                    TaskCore.Instance.HandleOpenTaskStatus(entity, zoneId);
                                    if (!TaskRecordMgr.Add(entity, transaction, zoneId))
                                    {
                                        return(false);
                                    }
                                }
                                manager.HasOpenTask = true;
                            }
                        }
                        //如果等级为15级 向竞技场注册用户
                        //获取竞技场等级限制
                        //if (manager.Level == level.Values)
                        //{

                        //}
                    }
                }
                catch (Exception ex)
                {
                    SystemlogMgr.ErrorByZone("SaveManagerData Task pending", ex, zoneId);
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                SystemlogMgr.ErrorByZone("SaveManagerData", ex, zoneId);
                return(false);
            }
            finally
            {
                ManagerCore.Instance.DeleteCache(manager.Idx);
            }
        }