Beispiel #1
0
        public WCFStep ToWCFStep()
        {
            WCFStep result = new WCFStep();

            result.Id       = this.Id;
            result.Game     = this.Game;
            result.StepType = this.StepType;
            result.IsFull   = this.IsFull;
            result.GameUser = this.GameUser;

            result.Message = new List <string>();
            foreach (var item in this.Message)
            {
                result.Message.Add(item.Value);
            }

            result.GameInfo     = this.GameInfo == null ? null : this.GameInfo.ToWCFGameInfo();
            result.GameUserInfo = this.GameUserInfo == null ? null : this.GameUserInfo.ToWCFGameUserInfo();

            result.Raven          = this.Raven == null ? null : this.Raven.ToWCFRaven();
            result.BattleUser     = this.BattleUser == null ? null : this.BattleUser.ToWCFBattleUser();
            result.Support        = this.Support == null ? null : this.Support.ToWCFSupport();
            result.Raid           = this.Raid == null ? null : this.Raid.ToWCFRaid();
            result.March          = this.March == null ? null : this.March.ToWCFMarch();
            result.Voting         = this.Voting == null ? null : this.Voting.ToWCFVoting();
            result.VesterosAction = this.VesterosAction == null ? null : this.VesterosAction.ToWCFVesterosAction();
            result.ArrowModelList = this.Arrow.ToList().Select(p => p.ToArrowModel()).ToList();

            return(result);
        }
Beispiel #2
0
        public WCFStep ToWCFStep()
        {
            WCFStep result = new WCFStep
            {
                Id       = this.Id,
                Game     = this.Game,
                StepType = this.StepType,
                IsFull   = this.IsFull,
                GameUser = this.GameUser,

                Message = new List <string>()
            };

            foreach (var item in this.Message)
            {
                result.Message.Add(item.Value);
            }

            result.GameInfo     = this.GameInfo?.ToWCFGameInfo();
            result.GameUserInfo = this.GameUserInfo?.ToWCFGameUserInfo();

            result.Raven          = this.Raven?.ToWCFRaven();
            result.BattleUser     = this.BattleUser?.ToWCFBattleUser();
            result.Support        = this.Support?.ToWCFSupport();
            result.Raid           = this.Raid?.ToWCFRaid();
            result.March          = this.March?.ToWCFMarch();
            result.Voting         = this.Voting?.ToWCFVoting();
            result.VesterosAction = this.VesterosAction?.ToWCFVesterosAction();
            result.ArrowModelList = this.Arrow.ToList().Select(p => p.ToArrowModel()).ToList();


            return(result);
        }
Beispiel #3
0
        public void SendStep(WCFStep wcfStep)
        {
            TaskFactory.StartNew(() =>
            {
#if DEBUG
                /*var xml = new PublicFileJson<WCFStep>("SendStep.txt");
                 * xml.Value = wcfStep;
                 * xml.Write();*/
#endif
                try
                {
                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        var user             = dbContext.GameUser.Single(p => p.Id == wcfStep.GameUser);
                        user.Game1.DbContext = dbContext;
                        user.Game1.GameHost  = this;

                        Step serverStep = user.Game1.HomeUsersSL.Select(p => p.LastStep).Single(p => p.Id == wcfStep.Id);
                        wcfStep.Update(serverStep);

                        if (user.Game1.HomeUsersSL.SelectMany(p => p.Step).All(p => p.IsFull))
                        {
                            NextStage(user.Game1);
                        }

                        ArrowsData.AddToDbContext(user.Game1);
                        dbContext.SaveChanges();
                    }
                }
                catch (TheEndException) { }
                catch (AntiCheatException) { }
                catch (Exception exp) { GameException.NewGameException(wcfStep.Game, string.Format("Не удалось обработать ход (Failed to process the step): {0}", wcfStep != null ? wcfStep.StepType : "пустой ход"), exp, true); }
            });
        }
Beispiel #4
0
        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);
        }