static internal Garrison ToGarrison(this WCFGarrison o) { Garrison result = new Garrison(); result.Id = o.Id; result.TokenType = o.TokenType; result.Terrain = o.Terrain; result.Strength = o.Strength; return(result); }
public void CopyGarrison(GameInfo gameInfo) { Garrison result = new Garrison(); result.GameInfo = gameInfo; result.Terrain1 = this.Terrain1; result.TokenType1 = this.TokenType1; result.Id = Guid.NewGuid(); result.Step = gameInfo.Step; result.Game = gameInfo.Game; result.TokenType = this.TokenType; result.Terrain = this.Terrain; result.Strength = this.Strength; gameInfo.Garrison.Add(result); }
public int GetStrength(bool isForce = false) { if (!isForce && _IsMath) { return(this.BattleUser.Strength.Value); } this.BattleUser.Strength = 0; //Меч if (this.Raven != null && this.Raven.StepType == "Валирийский_меч") { this.BattleUser.Strength++; } GameUser currentUser = this.GameUser1; Game game = currentUser.Game1; Battle battle = game.GameInfo.Battle; bool isAttackHome = battle.AttackUser == currentUser.Id; Terrain battleTerrain = battle.LocalDefenceTerrain; GameUser opponentUser = isAttackHome ? battle.LocalDefenceUser : battle.LocalAttackUser; //карты перевеса RandomDesk randomCard = this.BattleUser.LocalRandomCard; if (randomCard != null && randomCard.Strength > 0) { this.BattleUser.Strength += randomCard.Strength; } //Сила карты дома if (!string.IsNullOrEmpty(this.BattleUser.HomeCardType)) { if (!BalonGreyjoy(opponentUser)) { this.BattleUser.Strength += this.BattleUser.LocalHomeCardType.Strength; } StannisBaratheon(opponentUser); SerDavosSeaworth(); TheonGreyjoy(isAttackHome, battleTerrain); dragon_Ramsay_Bolton(); dragon_Doran_Martell(); dragon_Quentyn_Martell(); dragon_Euron_Crows_Eye(opponentUser); dragon_Aeron_Damphair(); } //Сила гарнизона if (!isAttackHome) { Garrison garrison = game.GameInfo.Garrison.SingleOrDefault(p => p.Terrain == battleTerrain.Name); if (garrison != null) { this.BattleUser.Strength += garrison.Strength; } } //сила приказа Order sourceOrder = this.GameUserInfo.Order.SingleOrDefault(p => p.Terrain == (isAttackHome ? battle.AttackTerrain : battle.DefenceTerrain)); if (sourceOrder != null && ((isAttackHome && sourceOrder.OrderType.Contains("Поход")) || (!isAttackHome && sourceOrder.OrderType.IndexOf("Оборона") != -1))) { OrderType ordertType = game.DbContext.OrderType.Single(p => p.Name == sourceOrder.OrderType); this.BattleUser.Strength += ordertType.Strength; CatelynStark(sourceOrder, ordertType); } //сила юнитов this.BattleUser.Strength += GetUnitStrength(this.GameUserInfo.Unit.Where(p => p.Terrain == battleTerrain.Name).ToList(), isAttackHome, battleTerrain, opponentUser); //Сила поддержки foreach (var joinTerrain in battleTerrain.TerrainTerrain.Select(p => p.Terrain2)) { //проверка лояльности GameUser holder = game.GetTerrainHolder(joinTerrain); if (holder == null || holder.LastStep.Support == null || holder.LastStep.Support.BattleId != battle.Id || holder.LastStep.Support.SupportUser != currentUser.Id) { continue; } //проверка наличия приказа поддержки Order supportOrder = holder.LastStep.GameUserInfo.Order.SingleOrDefault(p => p.Terrain == joinTerrain.Name); if (supportOrder == null || supportOrder.OrderType.IndexOf("Подмога") == -1) { continue; } //поддержка с земли на воду не оказывается if (joinTerrain.TerrainType == "Земля" && battleTerrain.TerrainType != "Земля") { continue; } //поддержка с порта на землю не оказывается if (joinTerrain.TerrainType == "Порт" && battleTerrain.TerrainType == "Земля") { continue; } IsSupport = true; //подсчёт силы приказа и юнитов OrderType ordertType = game.DbContext.OrderType.Single(p => p.Name == supportOrder.OrderType); int strength = ordertType.Strength; strength += GetUnitStrength(holder.LastStep.GameUserInfo.Unit.Where(p => p.Terrain == joinTerrain.Name).ToList(), isAttackHome, battleTerrain, opponentUser); this.BattleUser.Strength += strength; } if (this.BattleUser != null && this.BattleUser.AdditionalEffect != "Block" && this.BattleUser.HomeCardType == "dragon_Mance_Rayder") { this.BattleUser.Strength = this.GameUser1.Game1.GameInfo.Barbarian; } _IsMath = true; return(this.BattleUser.Strength.Value); }
private static bool Capitulate(Game game, GameUser user) { if (!game.WithoutChange) { return(false); } //помечаем ливера if (game.HomeUsersSL.IndexOf(user) < game.ThroneProgress) { game.ThroneProgress--; } user.IsCapitulated = true; //проверяем конец игры if (game.HomeUsersSL.Count <= 1) { game.TheEnd(); } //кэшируем последний ход ливера WCFStep userStep = user.LastStep.ToWCFStep(); //определяем кто ходил (цепочка событий) if (--game.ThroneProgress < 0) { game.ThroneProgress = game.HomeUsersSL.Count - 1; } GameUser throneUser = game.HomeUsersSL[game.ThroneProgress]; //определяем начало последнего действия и удаляем все ходы после него (откат) WCFStep backStep = throneUser.Step.Last(p => p.StepType == "Замысел" || p.StepType == "Набег" || p.StepType == "Поход" || p.StepType == "Усиление_власти").ToWCFStep(); WCFStep backVesterosStep = game.Vesteros.LastStep.ToWCFStep(); if (backStep.StepType != "Замысел") { IEnumerable <Step> removeSteps = game.AllSteps.Where(p => p.Id >= backStep.Id); game.DbContext.Step.RemoveRange(removeSteps); NewDoStep(game, game.DbContext.DoType.Single(p => p.Name == backStep.StepType), game.ThroneProgress); } else { backStep = game.Vesteros.Step.Last(p => p.StepType == "Замысел").ToWCFStep(); IEnumerable <Step> removeSteps = game.AllSteps.Where(p => p.Id >= backStep.Id); game.DbContext.Step.RemoveRange(removeSteps); game.NewThink(); } //дублируем информируем о ливнувших домах game.GameUser.Where(p => p.IsCapitulated).ToList().ForEach(p => { Step step = p.LastStep.CopyStep("Победа", true); step.NewMessage($"dynamic_leftGame*{p.HomeType}**0"); }); //Состояние Вестероса Step newVesterosStep = game.Vesteros.LastStep.CopyStep(backStep.StepType != "Замысел" ? "Default" : "Замысел", true); game.ResetVesterosDesc(1); game.ResetVesterosDesc(2); game.ResetVesterosDesc(3); game.ResetVesterosDesc(4); //Проверяем наличие гарнизонов предыдущих ливеров foreach (WCFGarrison item in backVesterosStep.GameInfo.Garrison) { if (!newVesterosStep.GameInfo.Garrison.Any(p => p.Terrain == item.Terrain)) { Garrison result = new Garrison { Id = Guid.NewGuid(), Step = newVesterosStep.Id, Game = newVesterosStep.Game, TokenType = "Гарнизон", Terrain = item.Terrain, Strength = item.Strength }; newVesterosStep.GameInfo.Garrison.Add(result); } } //Заменяем войска ливера на гарнизоны foreach (WCFGameUserTerrain item in userStep.GameUserInfo.GameUserTerrain) { int strength = userStep.GameUserInfo.Unit.Where(p => p.Terrain == item.Terrain).Sum(p => game.DbContext.UnitType.First(p1 => p1.Name == p.UnitType).Cost); if (userStep.GameUserInfo.PowerCounter.SingleOrDefault(p => p.Terrain == item.Terrain) != null) { strength++; } if (strength != 0) { Garrison garrison = newVesterosStep.GameInfo.Garrison.SingleOrDefault(p => p.Terrain == item.Terrain); if (garrison != null) { garrison.Strength += strength; } else { Garrison result = new Garrison { Id = Guid.NewGuid(), Step = newVesterosStep.Id, Game = newVesterosStep.Game, TokenType = "Гарнизон", Terrain = item.Terrain, Strength = strength }; newVesterosStep.GameInfo.Garrison.Add(result); } } } int i = 1; foreach (Step item in game.LastHomeSteps.OrderBy(p => p.GameUserInfo.ThroneInfluence)) { if (item.GameUserInfo.ThroneInfluence != i) { Step step = item.CopyStep("Борьба_за_влияние", true); step.NewMessage($"dynamic_voting*voting_Железный_трон*{i}"); step.GameUserInfo.ThroneInfluence = i; } i++; } i = 1; foreach (Step item in game.LastHomeSteps.OrderBy(p => p.GameUserInfo.BladeInfluence)) { if (item.GameUserInfo.BladeInfluence != i) { Step step = item.CopyStep("Борьба_за_влияние", true); step.NewMessage($"dynamic_voting*voting_Вотчины*{i}"); step.GameUserInfo.BladeInfluence = i; } i++; } i = 1; foreach (Step item in game.LastHomeSteps.OrderBy(p => p.GameUserInfo.RavenInfluence)) { if (item.GameUserInfo.RavenInfluence != i) { Step step = item.CopyStep("Борьба_за_влияние", true); step.NewMessage($"dynamic_voting*voting_Королевский_двор*{i}"); step.GameUserInfo.RavenInfluence = i; } i++; } return(true); }