/// <summary> /// 获取兵种信息 /// </summary> public int Call_UnitList(UnitListRequest request) { UnitListResponse response = new UnitListResponse(); response.success = true; response.pid = CurrentSession.UserId; response.units = new List <UnitInfo>(); var units = this.CurrentSession.GetBindPlayer().Units; foreach (var unit in units) { var u = this.ToUnitInfo(unit); response.units.Add(u); } CurrentSession.SendAsync(response); return(0); }
public int Call_FightEnd(FBFightResultRequest request) { if (request.token == null) { UnitListResponse er = new UnitListResponse(); er.success = false; er.info = GameErrorCode.副本战斗令牌错误或战斗已经失效.ToString(); CurrentSession.SendAsync(er); //return (int)GameErrorCode.副本战斗令牌错误或战斗已经失效; } //Battle battle; //if (!this._battles.TryGetValue(request.token, out battle) || battle.PlayerId != CurrentSession.UserId || battle.Dungeon.Id != request.id) //{ // return (int)GameErrorCode.副本战斗令牌错误或战斗已经失效; //} //_battles.Remove(battle.Id); FBFightResultResponse response = new FBFightResultResponse(); response.win = request.win; response.id = request.id; response.success = true; if (request.win) { var player = this.CurrentSession.GetBindPlayer(); //Dungeon dungeon = battle.Dungeon; Dungeon dungeon = player.Sections.Select(x => x.Dungeons.FirstOrDefault(d => d.Id == request.id)).First(x => x != null); DDungeon ddungeon = DDungeons[dungeon.Type][dungeon.Section][dungeon.Mission]; string reason = $"副本{ddungeon.id}:{ddungeon.name}战斗胜利"; dungeon.FightTimes += 1; //副本评星 int uscnt = 0; int living = 0; if (request.units != null) { foreach (FightUnitInfo u in request.units) { if (string.IsNullOrEmpty(u.unitId)) { uscnt += 1; if (!u.dead) { living += 1; } } } } int star = 1; if (living != 0) { star = _stars[uscnt - 1][living - 1]; } if (dungeon.Star == 0) //第一次通关 { if (dungeon.Next != 0) //开启下一关 { var ddnext = DDungeons[dungeon.Type][dungeon.Section][dungeon.Mission + 1]; var section = player.Sections.First(s => s.Id == dungeon.SectionId); var dnext = this.MakeDungeon(player, ddnext, section); section.Dungeons.Add(dnext); } else//开启下一章 { if (dungeon.Type == 1)//普通副本直接开启下一章,尝试打开精英副本当前章 { Section secionNext = new Section() { Id = Guid.NewGuid().ToString("D"), PlayerId = player.Id, Index = dungeon.Section + 1, Type = dungeon.Type, Dungeons = new List <Dungeon>() }; player.Sections.Add(secionNext); var dd = DDungeons[dungeon.Type][secionNext.Index][1]; var dnext = this.MakeDungeon(player, dd, secionNext); secionNext.Dungeons.Add(dnext); //检查精英副本是否已经通关上一章 bool preExSectionPassed = this.CheckPassedSection(player, 2, dungeon.Section - 1); if (preExSectionPassed) { Section secionEx = new Section() { Id = Guid.NewGuid().ToString("D"), PlayerId = player.Id, Index = dungeon.Section, Type = 2, Dungeons = new List <Dungeon>() }; player.Sections.Add(secionEx); var ddEx = DDungeons[2][secionEx.Index][1]; var dnextEx = this.MakeDungeon(player, ddEx, secionEx); secionEx.Dungeons.Add(dnextEx); } } else//精英副本检查普通本是否通关下一章,通关则开启下一章 { bool nextNormalSectionPassed = this.CheckPassedSection(player, 1, dungeon.Section + 1); if (nextNormalSectionPassed) { Section secionEx = new Section() { Id = Guid.NewGuid().ToString("D"), PlayerId = player.Id, Index = dungeon.Section + 1, Type = 2, Dungeons = new List <Dungeon>() }; player.Sections.Add(secionEx); var ddEx = DDungeons[2][secionEx.Index][1]; var dnextEx = this.MakeDungeon(player, ddEx, secionEx); secionEx.Dungeons.Add(dnextEx); } } } } if (dungeon.Star < star) { dungeon.Star = star; } //派发奖励 var playerController = this.Server.GetController <PlayerController>(); //扣体力 playerController.AddCurrency(player, CurrencyType.OIL, -ddungeon.oil_cost, reason); playerController.AddExp(player, ddungeon.exp, reason); //发放兵种经验 response.units = new List <UnitInfo>(); var campController = this.Server.GetController <CampController>(); var team = player.Teams.FirstOrDefault(t => t.IsSelected); if (team != null) { foreach (var unit in player.Units.Where(u => team.Units.Object.Contains(u.Id))) { UnitInfo ui = campController.AddUnitExp(player, unit, ddungeon.exp_element, false, true, reason); response.units.Add(ui); } } var pkgController = this.Server.GetController <PkgController>(); RewardInfo reward = pkgController.RandomReward(player, ddungeon.random_id, reason); _db.SaveChanges(); reward.exp = ddungeon.exp; response.reward = reward; response.lv = player.Level; response.exp = player.Exp; response.star = dungeon.Star; } else { response.units = null; } response.id = request.id; response.win = request.win; CurrentSession.SendAsync(response); return(0); }
public UnitListResponse1(UnitListResponse unitListResponse) => UnitListResponse = unitListResponse;