static public Guid GetRandomCardId(this List <RandomDesk> o) { int rndIndex = GameHost.Rnd.Next(o.Count); RandomDesk result = o[rndIndex]; result.PlayCount++; o.RemoveAt(rndIndex); return(result.Id); }
static public WCFRandomDesk ToWCFRandomDesk(this RandomDesk o) { return(new WCFRandomDesk() { Id = o.Id, Strength = o.Strength, Attack = o.Attack, Defence = o.Defence, Skull = o.Skull, fileName = o.fileName }); }
static public Guid GetRandomCardId(this List <RandomDesk> o) { //#if DEBUG // return o.First(p => p.Skull).Id; //#endif int rndIndex = GameHost.Rnd.Next(o.Count); RandomDesk result = o[rndIndex]; result.PlayCount++; o.RemoveAt(rndIndex); return(result.Id); }
public void UpdateBattle() { BattleUsers.ForEach(p => p.LastStep.CopyStep("Сражение", true)); //До боя if (TyrionLannister() || dragon_Queen_of_Thorns() || AeronDamphair() || dragon_Aeron_Damphair() || dragon_Qyburn() || DoranMartell() || QueenofThornes()) { BattleUsers.ForEach(p => p.LastStep.GetStrength()); return; } MaceTyrell(); dragon_Stannis_Baratheon(); dragon_Walder_Frey(); //Меч и карты перевеса GameUser bladeUser = BattleUsers.SingleOrDefault(p => p.LastStep.GameUserInfo.BladeInfluence == 1); if (bladeUser != null) { if (!Blade(bladeUser)) { return; } } else { Random(); } SalladhorSaan(); BattleUsers.ForEach(p => p.LastStep.GetStrength(true)); dragon_Margaery_Tyrell(); //определяем победителя и проигравшего _BattleUsers = BattleUsers.OrderByDescending(p => p.LastStep.BattleUser.Strength.Value).ThenBy(p => p.LastStep.GameUserInfo.BladeInfluence).ToList(); foreach (var item in BattleUsers) { item.LastStep.BattleUser.IsWinner = item == BattleUsers[0]; } #region потери и ранения //Карты домов int killedUserCount = 0; HomeCardType winHomeCard = BattleUsers[0].LastStep.BattleUser.LocalHomeCardType; if (winHomeCard != null) { killedUserCount += winHomeCard.Attack; } HomeCardType losHomeCard = BattleUsers[1].LastStep.BattleUser.LocalHomeCardType; if (losHomeCard != null) { killedUserCount -= losHomeCard.Defence; } //карты перевеса RandomDesk winRandomCard = BattleUsers[0].LastStep.BattleUser.LocalRandomCard; if (winRandomCard != null) { if (winRandomCard.Attack) { killedUserCount++; } } RandomDesk losRandomCard = BattleUsers[1].LastStep.BattleUser.LocalRandomCard; if (losRandomCard != null) { if (losRandomCard.Defence) { killedUserCount--; } } //специализация NymeriaSand(ref killedUserCount); SerDavosSeaworth(ref killedUserCount); TheonGreyjoy(ref killedUserCount); AshaGreyjoy(ref killedUserCount); TheBlackfish(ref killedUserCount); dragon_Ramsay_Bolton(ref killedUserCount); dragon_Doran_Martell(ref killedUserCount); UpdateUsedHomeCard(); bool isAutoRetreat = false; List <Unit> loserUnit = BattleUsers[1].LastStep.GameUserInfo.Unit.Where(p => p.Terrain == this.DefenceTerrain).OrderBy(p => p.UnitType1.Strength).ToList(); foreach (var item in loserUnit) { if (item.IsWounded || item.UnitType == "Осадная_башня") { BattleUsers[1].LastStep.GameUserInfo.Unit.Remove(item); BattleUsers[1].LastStep.NewMessage(string.Format("dynamic_unitRemove0*unitType_{0}*unitRemoveType_{1}", item.UnitType, item.IsWounded ? "finished" : "thrown")); } else { if (killedUserCount > 0) { BattleUsers[1].LastStep.GameUserInfo.Unit.Remove(item); BattleUsers[1].LastStep.NewMessage(string.Format("dynamic_unitRemove0*unitType_{0}*unitRemoveType_destroyed", item.UnitType)); killedUserCount--; } else { item.IsWounded = true; } } } //Черепа if (winRandomCard != null && winRandomCard.Skull && (losHomeCard == null || LoserUser.LastStep.BattleUser.AdditionalEffect == "Block" || losHomeCard.Name != "Бринден_Чёрная_Рыба")) { Unit skullUnite = BattleUsers[1].LastStep.GameUserInfo.Unit.Where(p => p.Terrain == (isAutoRetreat ? this.AttackTerrain : this.DefenceTerrain)).OrderBy(p => p.UnitType1.Strength).FirstOrDefault(); if (skullUnite != null) { BattleUsers[1].LastStep.GameUserInfo.Unit.Remove(skullUnite); BattleUsers[1].LastStep.NewMessage(string.Format("dynamic_unitRemove1*unitType_{0}*unitRemoveType_destroyed*text_skull", skullUnite.UnitType)); } } if (losRandomCard != null && losRandomCard.Skull && (winHomeCard == null || WinnerUser.LastStep.BattleUser.AdditionalEffect == "Block" || winHomeCard.Name != "Бринден_Чёрная_Рыба")) { Unit skullUnite = BattleUsers[0].LastStep.GameUserInfo.Unit.Where(p => p.Terrain == this.DefenceTerrain).OrderBy(p => p.UnitType1.Strength).FirstOrDefault(); if (skullUnite != null) { BattleUsers[0].LastStep.GameUserInfo.Unit.Remove(skullUnite); BattleUsers[0].LastStep.NewMessage(string.Format("dynamic_unitRemove1*unitType_{0}*unitRemoveType_destroyed*text_skull", skullUnite.UnitType)); } } #endregion TywinLannister(); dragon_Qarl_the_Maid(); if (!ArianneMartell()) { SerLorasTyrell(); } //Удаляем отыгравшие приказы и гарнизон this.LocalAttackUser.LastStep.GameUserInfo.Order.Remove(this.LocalAttackUser.LastStep.GameUserInfo.Order.SingleOrDefault(p => p.Terrain == this.AttackTerrain)); BattleUsers[1].LastStep.GameUserInfo.Order.Remove(BattleUsers[1].LastStep.GameUserInfo.Order.SingleOrDefault(p => p.Terrain == this.DefenceTerrain)); if (BattleUsers[1] == this.LocalDefenceUser) { if (_Game.GameInfo.Garrison.Any(p => p.Terrain1 == this.LocalDefenceTerrain)) { Step newVesterosStep = _Game.Vesteros.LastStep.CopyStep("Default", true); newVesterosStep.NewMessage("dynamic_garrisonRemove*terrain_" + this.DefenceTerrain); _Game.GameInfo.Garrison.Remove(_Game.GameInfo.Garrison.Single(p => p.Terrain1 == this.LocalDefenceTerrain)); } } //Автоматическое отступление оставшихся неудачников (Робб перехватывает отступление противника) if ((WinnerUser.LastStep.BattleUser.AdditionalEffect == "Block" || BattleUsers[0].LastStep.BattleUser.HomeCardType != "Робб_Старк") && BattleUsers[1] == this.LocalAttackUser) { foreach (var item in BattleUsers[1].LastStep.GameUserInfo.Unit.Where(p => p.Terrain == this.DefenceTerrain).OrderByDescending(p => p.UnitType1.Strength).ToList()) { AutoRetreatUnit(BattleUsers[1], item, this.LocalAttackTerrain); } } //Смена владений TerrainHold(BattleUsers[0], this.LocalDefenceTerrain); TerrainHold(this.LocalAttackUser, this.LocalAttackTerrain); if (_Game.LastHomeSteps.All(p => p.IsFull)) { AfterBattle(); } else { _Game.LastHomeSteps.Where(p => !p.IsFull && p.StepType == "Роспуск_войск").ToList().ForEach(p => p.March.SourceOrder = "AfterBattle"); } }
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); }