Exemplo n.º 1
0
        public async Task <BaseResponseData> OnRoomSellReq()
        {
            RoomSellResult result = new RoomSellResult();

            var user = LogicServer.User;

            var req = await InitHelpers.GetPse().DeserializeAsync <RoomBuyReq>(user.bytes);

            var currRoom = await Data.Helper.RoomData.Instance.GetRoomData();

            //出售后回到最初的住宅
            var roomId = 1;

            //同样的?
            if (roomId == currRoom.RoomId)
            {
                return(result);
            }

            var roleId  = user.role.Id.ToString();
            var newRoom = GetNewRoom(roleId, roomId);//新房间

            if (currRoom == null || newRoom == null)
            {
                result.Result = GameEnum.WsResult.Error;
            }
            else
            {
                result.Result = await ChangeRoom(currRoom, newRoom);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 出售物品
        /// </summary>
        /// <param name="account"></param>
        /// <param name="role"></param>
        /// <param name="sid"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        private static async Task <BaseResponseData> SellItem()
        {
            SellItemResult result = new SellItemResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <SellItemReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var id    = data.ItemId;
            var count = data.Count;

            if (count <= 0)
            {
                result.Result = GameEnum.WsResult.PositiveInteger;
                return(result);
            }

            return(await BagController.Instance.SellItemsAsync(id, count));
        }
Exemplo n.º 3
0
        private static async Task <BaseResponseData> BuyLand()
        {
            BuyLandResult result = new BuyLandResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <BuyLandReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var  landConfig = LandInfo.GetForLevel(data.Level);
            long needMoney  = landConfig.Price.Count;
            var  moneyType  = landConfig.Price.CurrencyID;

            if (needMoney <= 0)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            if (!(BagController.Instance.CheckMoney(needMoney, moneyType)))
            {
                result.Result = GameEnum.WsResult.NotEnoughMoney;
                return(result);
            }
            return(await LandController.Instance.BuyLand(data.Pos, result));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 添加物品
        /// </summary>
        /// <param name="account"></param>
        /// <param name="role"></param>
        /// <param name="sid"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        private static async Task <BaseResponseData> AddItem()
        {
            try
            {
                AddItemResult result = new AddItemResult();
                if (User.bytes == null)
                {
                    result.Result = GameEnum.WsResult.ParamsError;
                    return(result);
                }
                var data = await InitHelpers.GetPse().DeserializeAsync <AddItemReq>(User.bytes);

                if (data == null)
                {
                    result.Result = GameEnum.WsResult.ParamsError;
                    return(result);
                }
                var id    = data.ItemId;
                var count = data.Count;
                return(await BagController.Instance.AddItemToRoleBag(id, count));
            }
            catch (Exception ex)
            {
                //日志
                throw ex;
            }
        }
Exemplo n.º 5
0
        public async Task UpdateBuildInfo(BuildData buildData)
        {
            if (buildData != null)
            {
                TCBuildUpdateResult result = new TCBuildUpdateResult()
                {
                    LandBuildInfo = new LoadBuildInfo()
                    {
                        BuildId           = buildData.Id,
                        BuildType         = buildData.BuildType,
                        CurExtendLv       = buildData.CurExtendLv,
                        CustomerAddtion   = buildData.CustomerAddtion,
                        Employee          = buildData.Employee,
                        GetMoney          = buildData.GetMoney,
                        Level             = buildData.Level,
                        Name              = buildData.Name,
                        Popularity        = buildData.Popularity,
                        Pos               = buildData.Pos,
                        RoleId            = buildData.RoleId,
                        Star              = buildData.Star,
                        TodayCanAdvartise = buildData.TodayCanAdvartise,
                        CostGold          = buildData.CostGold,
                        Income            = buildData.Income
                    }
                };
                var data = await InitHelpers.GetPse().SerializeAsync(result);

                await MsgMaker.SendMessage(WSResponseMsgID.TCBuildUpdateResult, 1, data);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加道具进背包
        /// </summary>
        /// <param name="sm"></param>
        /// <param name="roleId"></param>
        /// <param name="itemId"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public async Task <AddItemResult> AddItemToRoleBag(int itemId, long count)
        {
            var item = GetItemById(itemId);

            if (item == null)
            {
                return(null);
            }
            AddItemResult result = new AddItemResult();

            if (!CheckBagSpace(itemId, count))
            {
                result.Result = GameEnum.WsResult.NotEnoughBagSpace;
                return(result);
            }
            var itemCount = new Dictionary <int, long>();

            itemCount.Add(itemId, count);
            result = await AddItemToRoleBag(itemCount);

            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await MsgMaker.SendMessage(WSResponseMsgID.AddItemResult, 1, data);    //写入队列

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">道具集合</param>
        /// <param name="oldAvatar">key=部位  value=道具id</param>
        /// <returns></returns>
        private async Task UpdateAvaterAsync(int[] id, Dictionary <int, int> oldAvatar)
        {
            var role = LogicServer.User.role;
            UpdateAvatarResult result = new UpdateAvatarResult();

            foreach (var i in oldAvatar)
            {
                foreach (var j in id)
                {
                    var tmp = GetItemById(j);
                    if (tmp.Parts.Contains(i.Key))
                    {
                        role.Avatar.Remove(i.Value);
                        if (!role.Avatar.Contains(j))
                        {
                            role.Avatar.Add(j);
                            result.Id.Add(j);
                        }
                    }
                }
            }
            await RoleDataHelper.Instance.UpdateRoleByRoleIdAsync(role.Id, role);

            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await MsgMaker.SendMessage(WSResponseMsgID.UpdateAvatarResult, 1, data);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 更新身价
        /// </summary>
        /// <param name="income"></param>
        /// <returns></returns>
        public async Task UpdateIncome()
        {
            UpdateShenjiaResult result = new UpdateShenjiaResult();

            result.SocialStatus = LogicServer.User.role.SocialStatus;
            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await MsgMaker.SendMessage(WSResponseMsgID.UpdateShenjiaResult, 1, data);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 金钱变动消息
        /// </summary>
        /// <param name="sm"></param>
        /// <param name="roleId"></param>
        /// <param name="count"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public async Task UpdateGold(int type)
        {
            GoldChangedResult result = new GoldChangedResult()
            {
                GoldType = type
            };
            var bag = LogicServer.User.bag;

            if (bag.Items.TryGetValue(type, out Model.Data.General.Item money))
            {
                result.Count = money.CurCount;
            }
            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await MsgMaker.SendMessage(WSResponseMsgID.GoldChangedResult, 1, data);
        }
Exemplo n.º 10
0
        public async Task FinanceLogUpdate(FinanceLogData log)
        {
            TCFinanceLogChangedResult result = new TCFinanceLogChangedResult()
            {
                FinanceLogInfo = new LoadFinanceLogInfo()
                {
                    Count     = log.Count,
                    EventName = log.EventName,
                    MoneyType = log.MoneyType,
                    Time      = log.Time.ToString(),
                    Type      = (int)log.Type,
                    AorD      = log.AorD
                }
            };
            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await MsgMaker.SendMessage(WSResponseMsgID.TCFinanceLogChangedResult, 1, data);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 更新部门之投资部
        /// </summary>
        /// <param name="department"></param>
        /// <returns></returns>

        public async Task UpdateDepartmentInvestment(Department department)
        {
            TCDepartmentInvestmentResult result = new TCDepartmentInvestmentResult()
            {
                InvestmentInfo = new InvestmentInfo()
                {
                    CurDirectorCounts = department.CurDirectorCounts,
                    CurExtension      = department.CurExtension,
                    CurRealestate     = department.CurRealestate,
                    CurStaff          = department.CurStaff,
                    CurStore          = department.CurStore,
                    Level             = department.Level
                }
            };
            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await MsgMaker.SendMessage(WSResponseMsgID.TCDepartmentInvestmentResult, 1, data);
        }
Exemplo n.º 12
0
        private static async Task <BaseResponseData> DestoryBuild()
        {
            DestoryBuildResult result = new DestoryBuildResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <DestoryBuildReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            return(await BuildController.Instance.DestoryBuild(data.Id, result));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 店铺升级
        /// </summary>
        /// <returns></returns>
        public async Task <BaseResponseData> OnBuildLvUp()
        {
            BuildLvUpResult result = new BuildLvUpResult();

            if (LogicServer.User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <BuildLvUpReq>(LogicServer.User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            return(await BuildLvUp(data.BuildId, result));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 请求地图信息
        /// </summary>
        /// <param name="account"></param>
        /// <param name="role"></param>
        /// <param name="sid"></param>
        /// <param name="bytes">坐标数组</param>
        /// <returns></returns>
        private static async Task <BaseResponseData> GetMapCell()
        {
            GetMapResult result = new GetMapResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <GetMapReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            return(await LandController.Instance.GetLandCell(data.Pos, result));
        }
Exemplo n.º 15
0
        /// <summary>
        /// 换装
        /// </summary>
        /// <param name="account"></param>
        /// <param name="role"></param>
        /// <param name="sid"></param>
        /// <param name="bytes">时装id数组</param>
        /// <returns></returns>
        private static async Task <BaseResponseData> ChangeAvater()
        {
            ChangeAvatarResult result = new ChangeAvatarResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <ChangeAvatarReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var id = data.Id;

            return(await BagController.Instance.ChangeAvatar(id, result));
        }
Exemplo n.º 16
0
        private static async Task <BaseResponseData> DepartmentLvUp()
        {
            DepartmentUpdateResult result = new DepartmentUpdateResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <DepartmentUpdateReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var type = (GameEnum.DepartMentType)data.Type;

            return(await DepartmentController.Instance.DepartmentLvUp(result, type));
        }
Exemplo n.º 17
0
        /// <summary>
        /// 使用道具
        /// </summary>
        /// <param name="account"></param>
        /// <param name="role"></param>
        /// <param name="sid"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        private static async Task <BaseResponseData> UseItem()
        {
            UseItemResult result = new UseItemResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <UseItemReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var id    = data.ItemId;
            var count = data.Count;

            return(await BagController.Instance.UseItemsAsync(_stateManager, User.role.Id, id, count));
        }
Exemplo n.º 18
0
        private static async Task <BaseResponseData> CreateCompany()
        {
            CreateCompanyResult result = new CreateCompanyResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <CreateCompanyReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var name = data.Name;
            var role = LogicServer.User.role;

            return(await CompanyController.Instance.CreateCompany(role.Id, name, result));
        }
Exemplo n.º 19
0
        private static async Task <BaseResponseData> CreateBuild()
        {
            CreateBuildResult result = new CreateBuildResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <CreateBuildReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }



            //检查钱够不够
            var  config    = AutoData.Building.GetForId(data.ShopType);
            long needMoney = config.BuildingCost.Count;
            var  moneyType = config.BuildingCost.GoldType;

            if (needMoney <= 0)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            if (!(BagController.Instance.CheckMoney(needMoney, moneyType)))
            {
                result.Result = GameEnum.WsResult.NotEnoughMoney;
                return(result);
            }

            return(await BuildController.Instance.CreateBuild(data, result));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 对连接服务器请求做出回应  绑定账号 并且给出当前账号下面的角色数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        private static async Task <BaseResponseData> Connecting()//ConnectingReq data, string sessionId)
        {
            ConnectingResult result = new ConnectingResult();
            var data = await InitHelpers.GetPse().DeserializeAsync <ConnectingReq>(User.bytes);

            string sessionId = User.sessionId;
            var    signToken = data.Token;

            if (signToken == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            result.RoleLists = new List <RoleLists>();
            var token = await TokenDataHelper.Instance.GetTokenBySignToken(signToken);

            if (token != null)
            {
                //判断token时效
                if (token.ExpireTime >= DateTime.Now)
                {
                    var account1 = await AccountDataHelper.Instance.GetAccountByUserNameAsync(token.UserPassport);


                    var sid = await SidUidDataHelper.Instance.GetSidByUserNameAsync(token.UserPassport);

                    var act = await SidUidDataHelper.Instance.GetUserNameBySidAsync(sessionId);


                    //检查 账号和上次保存的账号是否匹配
                    if (!string.IsNullOrEmpty(act) && !string.IsNullOrEmpty(sid))
                    {     //都存在
                        if (Command.CheckPassport(act, token.UserPassport) && Command.CheckSession(sessionId, sid))
                        { //都相同
                            //直接给登录
                            //TODO:踢下线 之后直接允许登录  或者允许重连
                            goto EqualsReturn;
                        }
                    }
                    if (!string.IsNullOrEmpty(act)) //表示session下面已经绑定账号了
                    {
                        //找到账号
                        if (!Command.CheckPassport(act, token.UserPassport))
                        {   //账号不相同
                            await SidUidDataHelper.Instance.RemoveUserNameBySidAsync(sessionId);

                            await SidUidDataHelper.Instance.UpdateUserNameBySidAsync(sessionId, token.UserPassport);

                            await SidUidDataHelper.Instance.RemoveSidByUserNameAsync(token.UserPassport);

                            await SidUidDataHelper.Instance.UpdateSidByUserNameAsync(token.UserPassport, sessionId);
                        }
                        else
                        {                                                                                            //账号相同
                            await SidUidDataHelper.Instance.UpdateSidByUserNameAsync(token.UserPassport, sessionId); //更新session

                            if (!string.IsNullOrEmpty(sid))
                            {
                                await SidUidDataHelper.Instance.RemoveUserNameBySidAsync(sid);

                                await SidUidDataHelper.Instance.UpdateUserNameBySidAsync(sessionId, token.UserPassport);
                            }
                        }
                    }
                    else
                    {   //没找到账号
                        //session没绑定账号
                        //查找账号是否绑定session
                        if (!string.IsNullOrEmpty(sid))
                        {
                            //旧session存在  账号已经绑定session
                            await SidUidDataHelper.Instance.RemoveSidByUserNameAsync(token.UserPassport);

                            await SidUidDataHelper.Instance.UpdateSidByUserNameAsync(token.UserPassport, sessionId);

                            await SidUidDataHelper.Instance.UpdateUserNameBySidAsync(sessionId, token.UserPassport);
                        }
                        else
                        {//都不存在 直接绑定
                            await SidUidDataHelper.Instance.UpdateSidByUserNameAsync(token.UserPassport, sessionId);

                            await SidUidDataHelper.Instance.UpdateUserNameBySidAsync(sessionId, token.UserPassport);
                        }
                    }
EqualsReturn:
                    var roles = await RoleListDataHelper.Instance.GetRoleListByAccountIdAsync(account1.AccountID);

                    if (roles != null)
                    {
                        if (roles.Any())
                        {//有角色 构造返回值
                            foreach (var item in roles)
                            {
                                result.RoleLists.Add(new RoleLists()
                                {
                                    Name   = item.Name,
                                    RoleId = item.Id.ToString(),
                                    Sex    = item.Sex
                                });
                            }
                            return(result);
                        }
                        else
                        {
                            result.Result = GameEnum.WsResult.NotRole;
                            //无角色 返回-5
                            return(result);
                        }
                    }
                    else
                    {
                        result.Result = GameEnum.WsResult.NotRole;
                        //无角色 返回-5
                        return(result);
                    }
                    //当用户下线时 删除 token
                }

                else
                {
                    result.Result = GameEnum.WsResult.TokenTimeOut;
                    //token 超时
                    return(result);
                }
            }
            else
            {
                result.Result = GameEnum.WsResult.TokenNotExists;
                //token不存在
                //拒绝连接
                return(result);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 创建新角色
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="name"></param>
        /// <param name="sex"></param>
        /// <returns></returns>
        private static async Task <BaseResponseData> CreateNewRole()//string sessionId, string name, int sex)
        {
            CreateRoleResult result = new CreateRoleResult();
            var account             = User.account;
            var sessionId           = User.sessionId;

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <CreateRoleReq>(User.bytes);

            var name = data.Name;
            var sex  = data.Sex;

            if (string.IsNullOrEmpty(name))
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var allRoles = await RoleListDataHelper.Instance.GetRoleListByAccountIdAsync(account.AccountID);

            if (allRoles != null)
            {
                if (account.RoleNumber >= 10)
                {
                    result.ErrorDesc = "角色数量过多,请删除部分角色再创建";
                    return(result);
                }
                //检查是否重名
                if (await IdRoleDataHelper.Instance.CheckIdRoleByRoleNameAsync(name))
                {
                    result.ErrorDesc = "角色名重复";
                    return(result);  //重名直接返回
                }
                //构造新角色
                UserRole user   = new UserRole(sex, name, account.AccountID);
                IdRole   idRole = new IdRole(user.Name, user.Id);

                await IdRoleDataHelper.Instance.SetIdRoleByRoleNameAsync(name, idRole);

                await RoleDataHelper.Instance.SetRoleByRoleIdAsync(user.Id, user);


                List <UserRole> roles = new List <UserRole>();
                roles.AddRange(allRoles);
                roles.Add(user);
                await RoleListDataHelper.Instance.UpdateRoleListByAccountIdAsync(account.AccountID, roles);

                await RoleDataHelper.Instance.UpdateRoleBySidAsync(sessionId, user);

                result.ErrorDesc = "";
                result.Name      = name;
                result.Sex       = sex;
                result.RoleId    = user.Id.ToString();
            }
            else
            {
                ///没有角色,新增一个
                //检查重名
                if (await IdRoleDataHelper.Instance.CheckIdRoleByRoleNameAsync(name))
                {
                    result.ErrorDesc = "角色名重复";
                    return(result);
                }
                //构造新角色
                UserRole user   = new UserRole(sex, name, account.AccountID);
                IdRole   idRole = new IdRole(user.Name, user.Id);


                await IdRoleDataHelper.Instance.SetIdRoleByRoleNameAsync(name, idRole);

                await RoleDataHelper.Instance.SetRoleByRoleIdAsync(user.Id, user);

                List <UserRole> roles = new List <UserRole>();
                roles.Add(user);

                await RoleListDataHelper.Instance.SetRoleListByAccountIdAsync(user.AccountId, roles);

                await RoleDataHelper.Instance.SetRoleBySidAsync(sessionId, user);

                result.ErrorDesc = "";
                result.Name      = name;
                result.Sex       = sex;
                result.RoleId    = user.Id.ToString();
            }
            return(result);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 进入游戏 初始化角色和场景数据
        /// need TODO 场景数据
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        private static async Task <BaseResponseData> JoinGame()
        {
            var    result    = new JoinGameResult();
            var    data      = new JoinGameReq();
            var    selfUser  = User;
            string sessionId = selfUser.sessionId;

            if (selfUser.bytes != null)
            {
                data = await InitHelpers.GetPse().DeserializeAsync <JoinGameReq>(selfUser.bytes);

                if (data == null)
                {
                    //请求参数为空
                    result.Result = GameEnum.WsResult.RoleIdIsNull;
                    return(result);
                }
            }
            else
            {
                //请求参数为空
                result.Result = GameEnum.WsResult.RoleIdIsNull;
                return(result);
            }
            var roleId = new Guid(data.RoleId);
            var user   = await RoleDataHelper.Instance.GetRoleByRoleIdAsync(roleId);

            if (user != null) //找到角色数据 绑定在线状态  返回数据给用户  设置状态为登录状态
            {
                //查找session用来绑定
                //查找用户是否在线
                var sid = await SidRoleIdDataHelper.Instance.GetSidByRoleIdAsync(roleId); //查找当前连接是否有角色

                if (sid != null)                                                          //有旧的session
                {
                    if (sid.Equals(sessionId))                                            //检查session保存的roleid是不是和新登入的一致
                    {                                                                     //session一致  有可能是断线重连
                    }
                    else
                    {
                        //不一致  可能是从别的地方连接
                        await RoleDataHelper.Instance.RemoveRoleBySidAsync(sid);

                        await RoleDataHelper.Instance.RemoveRoleBySidAsync(sessionId);

                        await RoleDataHelper.Instance.SetRoleBySidAsync(sessionId, user);
                    }
                    //用户已经在线  进行通知处理  匹配 imei处理 预防盗号处理
                    //TODO
                    await SidRoleIdDataHelper.Instance.UpdateSidByRoleIdAsync(roleId, sessionId);
                }
                else
                {   //没有旧的session
                    await RoleDataHelper.Instance.RemoveRoleBySidAsync(sessionId);

                    await RoleDataHelper.Instance.SetRoleBySidAsync(sessionId, user);

                    //切记 下线时候要删除  或者在心跳包收不到的情况下     也要删除
                    await SidRoleIdDataHelper.Instance.SetSidByRoleIdAsync(roleId, sessionId);
                }
                //构造返回值
                List <Model.ResponseData.UserAttr> u = new List <Model.ResponseData.UserAttr>();
                foreach (var item in user.UserAttr)
                {
                    u.Add(new Model.ResponseData.UserAttr()
                    {
                        Count      = item.Count,
                        UserAttrID = item.UserAttrID
                    });
                }
                selfUser.role = user;
                //Load Bag info
                var bagInfo = await BagDataHelper.Instance.GetBagByRoleId(roleId);

                result.CompanyInfo = await CompanyController.Instance.GetCompanyInfoByRoleId(roleId);

                result.DepartInfoInfo = await DepartmentController.Instance.GetDepartmentInfoByRoleId(roleId);

                result.FinanceLogInfo = await FinanceLogController.Instance.GetFinanceLog(roleId);

                result.MapInfo = await LandController.Instance.GetRoleLandShopInfo(roleId);

                result.Room = await RoomController.Instance.GetRoom(user.Id) as RoomResult;

                result.UserAttr        = u;
                result.Affinity        = user.Affinity;
                result.Avatar          = user.Avatar;
                result.Certificates    = user.Certificates;
                result.CertificatesExp = user.CertificatesExp;
                result.Charm           = user.Charm;
                result.Concentration   = user.Concentration;
                result.Constitution    = user.Constitution;
                result.Desc            = user.Desc;
                result.Gold            = user.Gold;
                result.Exp             = user.Exp;
                result.Icon            = user.Icon;
                result.RoleId          = user.Id.ToString();
                result.Intelligence    = user.Intelligence;
                result.Level           = user.Level;
                result.Name            = user.Name;
                result.Sex             = user.Sex;
                result.SocialStatus    = user.SocialStatus;
                result.Type            = user.Type;
                result.VipLevel        = user.VipLevel;
                if (bagInfo != null)
                {
                    result.RoleBag = new BagInfo()
                    {
                        CurUsedCell   = bagInfo.CurUsedCell,
                        MaxCellNumber = bagInfo.MaxCellNumber,
                        Items         = BagController.Instance.GetRoleItems(bagInfo.Items)
                    };
                }
                else
                {
                    bagInfo        = new Bag();
                    result.RoleBag = new BagInfo()
                    {
                        CurUsedCell   = bagInfo.CurUsedCell,
                        MaxCellNumber = bagInfo.MaxCellNumber,
                        Items         = BagController.Instance.GetRoleItems(bagInfo.Items)
                    };
                }
            }
            return(result);
        }
Exemplo n.º 23
0
        public async Task BuildExtendFailed(BuildExtendFailedResult result)
        {
            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await MsgMaker.SendMessage(WSResponseMsgID.BuildExtendFailedResult, 1, data);
        }
Exemplo n.º 24
0
        public static async Task SendMessage(WSResponseMsgID msgId, BaseResponseData result, int roleCount = 1)
        {
            var data = await InitHelpers.GetPse().SerializeAsync(result);

            await SendMessage(msgId, roleCount, data);
        }
Exemplo n.º 25
0
        public async Task <BaseResponseData> OnRoomConfigUpdateReq()
        {
            RoomConfigUpdateResult result = new RoomConfigUpdateResult();
            var user = LogicServer.User;
            var req  = await InitHelpers.GetPse().DeserializeAsync <RoomConfigUpdateReq>(user.bytes);

            if (req.Config == null)
            {
                return(result);
            }

            ///获得原来的家具信息
            ///得到当前更新房间需要购买的新的家具
            ///如果有需要购买的家具,则先进行购买
            ///
            ///购买后开始更换家具
            ///更新掉的家具放到背包中
            ///没有新的家具从背包中移除
            ///更新房间的相应配置
            ///

            //变更了配置的位置
            var changeConfig = new List <int>();

            var room = await Data.Helper.RoomData.Instance.GetRoomData();

            var oldfur = new Dictionary <int, int>();

            //之前的配置家具数量
            foreach (var config in room.Config)
            {
                if (!oldfur.ContainsKey(config.Value))
                {
                    oldfur.Add(config.Value, 0);
                }
                oldfur[config.Value] += 1;
            }
            //新的家具配置数量
            var newfur = new Dictionary <int, int>();

            foreach (var config in req.Config)
            {
                if (!newfur.ContainsKey(config.Value))
                {
                    newfur.Add(config.Value, 0);
                }
                newfur[config.Value] += 1;

                if (config.Value != room.Config[config.Key])
                {
                    changeConfig.Add(config.Key);
                }
            }
            //BagController.Instance.GetMoney()
            var buys  = new Dictionary <int, int>();
            var costs = new Dictionary <int, int>();//购买消耗

            foreach (var kv in newfur)
            {
                var itemId    = kv.Key;
                var count     = kv.Value;
                var baseCount = oldfur.ContainsKey(itemId) ? oldfur[itemId] : 0;
                count = baseCount > count ? 0 : count - baseCount;

                //不足再从背包里找
                if (count > 0)
                {
                    var bagCount = (int)BagController.Instance.GetItemCount(itemId);
                    count = bagCount > count ? 0 : count - bagCount;
                }
                if (count > 0)
                {
                    buys.Add(itemId, count);
                    var itemdata = AutoData.Item.GetForId(itemId);
                    if (itemdata.Cost.CurrencyID != 0)
                    {
                        if (!costs.ContainsKey(itemdata.Cost.CurrencyID))
                        {
                            costs.Add(itemdata.Cost.CurrencyID, 0);
                        }
                        costs[itemdata.Cost.CurrencyID] += itemdata.Cost.Count;
                    }
                }
            }
            ///购买,是否有足够的货币
            foreach (var kv in costs)
            {
                var itemId = kv.Key;
                var count  = kv.Value;
                if (!BagController.Instance.CheckMoney(count, itemId))
                {
                    result.Result = GameEnum.WsResult.NotEnoughMoney;
                    return(result);
                }
            }
            ///消耗货币
            foreach (var kv in costs)
            {
                var itemId = kv.Key;
                var count  = kv.Value;
                await BagController.Instance.UseItemsAsync(SM, user.role.Id, itemId, count);
            }
            ///获得道具
            foreach (var kv in buys)
            {
                await BagController.Instance.AddItemToRoleBag(kv.Key, kv.Value);
            }
            ///更换的道具添加到背包中,其它的直接更新到装配界面中,并从背包中移除
            foreach (var furPoint in changeConfig)
            {
                var old  = room.Config[furPoint];
                var newx = req.Config[furPoint];
                //旧的进背包,
                await BagController.Instance.AddItemToRoleBag(old, 1);

                //新的从背包中移除
                if (!await BagController.Instance.RemoveItemsAsync(newx, 1))
                {
                    result.Result = GameEnum.WsResult.NotEnoughItem;
                    return(result);
                }
            }

            //更新房间配置
            foreach (var config in req.Config)
            {
                room.Config[config.Key] = config.Value;
            }
            await Data.Helper.RoomData.Instance.UpdateRoomData(room);

            result.Config = req.Config;//只返回更新的

            return(result);
        }