Example #1
0
        /// <summary>
        /// 单位进阶
        /// </summary>
        public int Call_UnitGradeUp(ClazupUnitRequest request)
        {
            ClazupUnitResponse response = new ClazupUnitResponse();

            response.id = request.id;
            var  player = CurrentSession.GetBindPlayer();
            Unit unit   = player.Units.First(x => x.Id == request.id);


            DUnit du = DUnits[unit.Tid];

            int maxClaz = du.grade_max;
            int itemId  = du.grade_item_id;

            if (unit.Grade >= du.grade_max)
            {
                return((int)GameErrorCode.兵种已经最高阶);
            }
            DUnitGradeUp dug = DUnitGrades[du.star][unit.Grade + 1];

            if (unit.Level < dug.min_level)
            {
                return((int)GameErrorCode.兵种不满足升阶等级);;
            }
            int itemCount = dug.item_cnt;

            var    pkgController    = Server.GetController <PkgController>();
            var    playerController = Server.GetController <PlayerController>();
            string reason           = $"兵种进阶{du.tid}";

            if (playerController.IsCurrencyEnough(player, CurrencyType.GOLD, dug.gold))
            {
                if (pkgController.TrySubItem(player, itemId, itemCount, reason, out var item))
                {
                    playerController.AddCurrency(player, CurrencyType.GOLD, -dug.gold, reason);

                    unit.Grade += 1;

                    response.unitInfo = this.ToUnitInfo(unit, du, true);
                    response.gold     = playerController.GetCurrencyValue(player, CurrencyType.GOLD);
                    response.itemId   = itemId;
                    response.count    = item.Count;
                    response.success  = true;

                    _db.SaveChanges();

                    CurrentSession.SendAsync(response);

                    //任务
                    OnUnitGradeUp(new UnitGradeUpEventArgs()
                    {
                        UnitInfo = response.unitInfo,
                        OldGrade = unit.Grade - 1
                    });
                }
            }
            return(0);
        }
Example #2
0
        /// <summary>
        /// 节
        /// </summary>
        public int Call_FbInfo(FBInfoRequest request)
        {
            var sections = CurrentSession.GetBindPlayer().Sections;
            var section  = sections.FirstOrDefault(s => s.Index == request.section && s.Type == request.type);

            if (section == null)
            {
                return((int)GameErrorCode.副本章节还未开启);
            }
            FBInfoResponse response = new FBInfoResponse();

            response.success   = true;
            response.section   = request.section;
            response.type      = request.type;
            response.fbs       = new List <FBInfo>();
            response.receiveds = new List <int>();
            response.id        = section.PlayerId;

            var dds = DDungeons[section.Type][section.Index].Values;

            foreach (var dd in dds)
            {
                FBInfo fi = new FBInfo();
                fi.id            = dd.id;
                fi.type          = dd.type;
                fi.desc          = dd.desc;
                fi.name          = dd.name;
                fi.icon          = dd.icon;
                fi.screen_id     = dd.screen_id;
                fi.level_limit   = dd.level_limit;
                fi.exp           = dd.exp;
                fi.gold          = dd.gold;
                fi.power         = dd.power;
                fi.random_id     = dd.random_id;
                fi.oil_cost      = dd.oil_cost;
                fi.time_limit_1  = dd.time_limit_1;
                fi.time_limit_2  = dd.time_limit_2;
                fi.time_limit_3  = dd.time_limit_3;
                fi.wipe_cost     = dd.wipe_cost;
                fi.map_fighting  = dd.map_fighting;
                fi.map_file_name = dd.map_file_name;
                fi.map_res_name  = dd.map_res_name;
                fi.dropItems     = dd.drop_items.Object;
                fi.fight_times   = dd.fight_times;
                var dungeon = section.Dungeons.FirstOrDefault(d => d.Tid == dd.id);
                if (dungeon != null)
                {
                    fi.star            = dungeon.Star;
                    fi.fid             = dungeon.Id;
                    fi.open            = dungeon.IsOpen;
                    fi.remainTimes     = dd.fight_times - dungeon.FightTimes;
                    fi.resetRemainNumb = 3 - dungeon.ResetNumb;
                }
                response.fbs.Add(fi);
            }
            CurrentSession.SendAsync(response);
            return(0);
        }
Example #3
0
        public override void OnLeave(ClientCloseReason reason)
        {
            base.OnLeave(reason);

            var player = CurrentSession.GetBindPlayer();

            //player.OnlineTime += (DateTime.Now - player.LastLoginTime);

            _db.SaveChanges();
        }
Example #4
0
        public int Call_FriendList(FriendListRequest request)
        {
            FriendListResponse response = new FriendListResponse();

            response.success = true;
            var player = CurrentSession.GetBindPlayer();

            response.pid         = player.Id;
            response.oilTimes    = player.FriendList.RecvTimes;
            response.maxOilTimes = 5;

            //FriendListResponse response = JsonConvert.DeserializeObject<FriendListResponse>("{\"oilTimes\":0,\"friends\":[],\"success\":true,\"maxOilTimes\":10}");
            CurrentSession.SendAsync(response);
            return(0);
        }
Example #5
0
        public int Call_LotteryInfo(GetLotteryInfoRequest request)
        {
            GetLotteryInfoResponse response = new GetLotteryInfoResponse();
            var player  = CurrentSession.GetBindPlayer();
            var lottery = player.Lottery;

            response.success             = true;
            response.goldUsedNumb        = lottery.GoldUsedNumb;                  //今日金币抽次数
            response.goldFreeNextTime    = lottery.GoldFreeNextTime.ToUnixTime(); //下次免费金币抽刷新时间
            response.goldBaseNumb        = lottery.GoldBaseNumb;                  //剩余出金币抽保底奖励的次数
            response.goldFreeNumb        = lottery.GoldFreeNumb;
            response.diamondUsedNumb     = lottery.DmdUsedNumb;                   //今日钻石抽次数
            response.diamondFreeNextTime = lottery.DmdFreeNextTime.ToUnixTime();  //下次免费钻石抽时间
            response.diamondBaseNumb     = lottery.DmdBaseNumb;                   //剩余出钻石保底奖励的次数
            response.diamondFreeNumb     = lottery.DmdFreeNumb;
            CurrentSession.SendAsync(response);
            return(0);
        }
Example #6
0
        /// <summary>
        /// 章
        /// </summary>
        public int Call_SectionInfo(SectionInfoRequest request)
        {
            var sections = CurrentSession.GetBindPlayer().Sections;
            SectionInfoResponse response = new SectionInfoResponse();

            response.success  = true;
            response.id       = this.CurrentSession.UserId;
            response.sections = new List <SectionInfo>();
            foreach (var section in sections)
            {
                SectionInfo si = new SectionInfo();
                si.id   = section.Index;
                si.type = section.Type;
                si.open = true;
                si.name = "初临战场";
                response.sections.Add(si);
            }

            //var response = JsonConvert.DeserializeObject<SectionInfoResponse>("{\"id\":\"10000f3\",\"sections\":[{\"name\":\"初临战场\",\"id\":1,\"type\":1,\"open\":true},{\"name\":\"初临战场\",\"id\":1,\"type\":2,\"open\":false},{\"name\":\"激烈交战\",\"id\":2,\"type\":1,\"open\":false},{\"name\":\"激烈交战\",\"id\":2,\"type\":2,\"open\":false},{\"name\":\"白色方案\",\"id\":3,\"type\":1,\"open\":false},{\"name\":\"白色方案\",\"id\":3,\"type\":2,\"open\":false},{\"name\":\"闪电战\",\"id\":4,\"type\":1,\"open\":false},{\"name\":\"闪电战\",\"id\":4,\"type\":2,\"open\":false},{\"name\":\"西线战场\",\"id\":5,\"type\":1,\"open\":false},{\"name\":\"西线战场\",\"id\":5,\"type\":2,\"open\":false},{\"name\":\"北非战场\",\"id\":6,\"type\":1,\"open\":false},{\"name\":\"北非战场\",\"id\":6,\"type\":2,\"open\":false},{\"name\":\"巴巴罗萨计划\",\"id\":7,\"type\":1,\"open\":false},{\"name\":\"巴巴罗萨计划\",\"id\":7,\"type\":2,\"open\":false},{\"name\":\"霸王行动\",\"id\":8,\"type\":1,\"open\":false},{\"name\":\"霸王行动\",\"id\":8,\"type\":2,\"open\":false},{\"name\":\"突破包围网\",\"id\":9,\"type\":1,\"open\":false},{\"name\":\"突破包围网\",\"id\":9,\"type\":2,\"open\":false},{\"name\":\"帝国的毁灭\",\"id\":10,\"type\":1,\"open\":false},{\"name\":\"帝国的毁灭\",\"id\":10,\"type\":2,\"open\":false},{\"name\":\"斩首行动\",\"id\":11,\"type\":1,\"open\":false},{\"name\":\"斩首行动\",\"id\":11,\"type\":2,\"open\":false},{\"name\":\"殊死一战\",\"id\":12,\"type\":1,\"open\":false},{\"name\":\"殊死一战\",\"id\":12,\"type\":2,\"open\":false}],\"success\":true}");
            this.CurrentSession.SendAsync(response);
            return(0);
        }
Example #7
0
        private void UpdateMaxPower()
        {
            var player = CurrentSession.GetBindPlayer();
            var team   = player.Teams.FirstOrDefault(x => x.IsSelected);

            if (team != null)
            {
                int power = player.Units.Where(x => team.Units.Object.Contains(x.Id)).Sum(x => x.Power);
                if (player.MaxPower < power)
                {
                    player.MaxPower = power;
                    _db.SaveChanges();
                    //最大战力改变了
                    _logger.LogDebug($"玩家{player.Id}:{player.NickName}最大战力改变{player.MaxPower}");

                    MaxPowerChangeNotify notify = new MaxPowerChangeNotify()
                    {
                        Power   = (int)player.MaxPower,
                        success = true,
                    };
                    CurrentSession.SendAsync(notify);
                }
            }
        }
Example #8
0
        public int Call_UseItem(UseItemRequest request)
        {
            int itemCnt = 1;

            if (request.cnt > itemCnt)
            {
                itemCnt = request.cnt;
            }
            var player = CurrentSession.GetBindPlayer();
            var item   = player.Items.FirstOrDefault(x => x.Id == request.id);

            if (item == null)
            {
                return((int)GameErrorCode.道具并不存在);
            }

            if (item.Count < itemCnt)
            {
                return((int)GameErrorCode.道具不足);
            }

            DItem di = _ditems[item.Tid];

            if (!di.useable)
            {
                return((int)GameErrorCode.道具不可使用);
            }

            UseItemResponse response = new UseItemResponse();

            response.id      = request.id;
            response.success = true;
            int    unitId = di.breakUnitId;//使用后解锁的兵种id
            string reason = $"使用道具{di.tid}";

            if (unitId > 0)
            {
                var      campController = Server.GetController <CampController>();
                UnitInfo ui             = campController.UnlockUnit(player, unitId);
                response.unitInfo = ui;
            }
            else if (di.breakRandomId > 0)//使用后可以获得随机库
            {
                RewardInfo reward = this.RandomReward(player, di.breakRandomId, reason);
                response.rewardInfo = reward;
            }
            else if (di.breakCount > 0)//资源
            {
                var playerController = Server.GetController <PlayerController>();
                playerController.AddCurrency(player, di.type, di.breakCount, reason);
                response.rewardInfo     = new RewardInfo();
                response.rewardInfo.res = new List <ResInfo>()
                {
                    new ResInfo()
                    {
                        type = di.type, count = di.breakCount
                    }
                };
            }
            //else if (di.type == 18)
            //{
            //    //后勤基地工人+1
            //    //        int maxCnt = engine.getInt(Application.systemFile, "worker_max_cnt");
            //    //        Industry industry = Spring.bean(IndustryService.class).getIndustry(item.getPid());
            //    //        if (industry.getTotalWorkers() + cnt > maxCnt) {
            //    //            response.setInfo(Spring.errCode("item_use_fail_workersmax"));
            //    //            return response;
            //    //        }
            //    //        industry.setIdleWorkers(industry.getIdleWorkers() + cnt);
            //    //        industry.setTotalWorkers(industry.getTotalWorkers() + cnt);
            //    //        rojo.updateAndFlush(industry, "idleWorkers", "totalWorkers");
            //    //        BuyWorkerResponse resp = new BuyWorkerResponse();
            //    //resp.setSuccess(true);
            //    //        resp.setIdleWorkers(industry.getIdleWorkers());
            //    //        resp.setTotalWorkers(industry.getTotalWorkers());
            //    //        Support su = Spring.bean(PlayerService.class).getSupport(item.getPid());
            //    //    resp.setDiamond((int) su.getDiamond());
            //    //        Context.getContextServer().send(resp, item.getPid());
            //    //    response.setSuccess(true);
            //}


            item.Count -= itemCnt;//减少堆叠
            if (item.Count <= 0)
            {
                _db.Items.Remove(item);
                //player.Items.Remove(item);
            }
            _db.SaveChanges();
            response.lap = item.Count;
            CurrentSession.SendAsync(response);
            return(0);
        }