コード例 #1
0
ファイル: MsgSender.cs プロジェクト: chenhongyi/Server
        public async Task BuildLvUpFailed(BuildLvUpFailedResult failed)
        {
            var data = await InitHelpers.GetPse().SerializeAsync(failed);

            await MsgMaker.SendMessage(WSResponseMsgID.BuildLvUpFailedResult, 1, data);
        }
コード例 #2
0
        private async Task <LoadBuildInfo> BuildLvUp(string id)
        {
            var role = LogicServer.User.role;
            BuildLvUpFailedResult failed = new BuildLvUpFailedResult();

            failed.BuildId = id;
            var build = await BuildDataHelper.Instance.GetBuildByBuildId(id);

            if (build == null)
            {
                failed.Result = GameEnum.WsResult.BuildIsNotExists;
                await MsgSender.Instance.BuildLvUpFailed(failed);

                return(null);
            }
            if (!build.RoleId.Equals(role.Id.ToString()))
            {
                failed.Result = GameEnum.WsResult.BuildIdNotOwnRole;
                await MsgSender.Instance.BuildLvUpFailed(failed);

                return(null);
            }
            var config = AutoData.BuildingLevel.GetForId(build.Level);

            if (config == null)
            {
                failed.Result = GameEnum.WsResult.ConfigErr;
                await MsgSender.Instance.BuildLvUpFailed(failed);

                return(null);
            }
            var bag = LogicServer.User.bag;

            if (!BagController.Instance.CheckMoney(config.UpgradeCost.Count, config.UpgradeCost.CurrencyID))
            {
                failed.Result = GameEnum.WsResult.NotEnoughMoney;
                await MsgSender.Instance.BuildLvUpFailed(failed);

                return(null);
            }
            var extendConfig = AutoData.Extension.GetForId(build.CurExtendLv + 1); //取扩建等级下一级的 needlv的值 作为升级上限

            if (build.Level + 1 > extendConfig.NeedLv)
            {
                failed.Result = GameEnum.WsResult.NeedExtendLevel;
                await MsgSender.Instance.BuildLvUpFailed(failed);

                return(null);
            }
            build.CustomerAddtion += config.CustomerAddtion;
            build.Employee        += config.ClerkNums;
            build.Popularity      += config.Popularity;
            build.Income          += config.Income;
            build.Level++;
            role.SocialStatus += config.Income;

            //升级
            using (var tx = LogicServer.Instance.StateManager.CreateTransaction())
            {
                await BagDataHelper.Instance.DecGold(config.UpgradeCost.Count, config.UpgradeCost.CurrencyID, tx); //扣钱

                await BuildDataHelper.Instance.UpdateBuildByBuildId(build, tx);                                    //更新店铺

                await RoleDataHelper.Instance.UpdateRoleByRoleIdAsync(role.Id, role, tx);                          //更新身价

                await tx.CommitAsync();
            }
            await MsgSender.Instance.UpdateIncome();

            await MsgSender.Instance.UpdateGold(config.UpgradeCost.CurrencyID);

            LoadBuildInfo info = new LoadBuildInfo()
            {
                BuildId           = build.Id,
                BuildType         = build.BuildType,
                CustomerAddtion   = build.CustomerAddtion,
                Employee          = build.Employee,
                GetMoney          = build.GetMoney,
                Level             = build.Level,
                Name              = build.Name,
                Popularity        = build.Popularity,
                Pos               = build.Pos,
                RoleId            = build.RoleId,
                Star              = build.Star,
                TodayCanAdvartise = build.TodayCanAdvartise,
                CurExtendLv       = build.CurExtendLv,
                CostGold          = build.CostGold,
                Income            = build.Income
            };

            return(info);
        }