コード例 #1
0
        public static DeckAnalysis Analyse(ObservableDeck deck)
        {
            DeckAnalysis results = new DeckAnalysis();

            results.TotalCards = deck.CardCount();

            for (int i = 0; i <= 10; i++)
            {
                results.CountOfCost.Add(QuantityOfCardsEqualingValue(deck, "Cost", i.ToString()));
            }

            for (int i = 0; i <= 10; i++)
            {
                results.CountOfAttack.Add(QuantityOfCardsEqualingValue(deck, "Attack", i.ToString()));
            }

            results.OneCommandForOneCost = QuantityOfCardsEqualingValue(deck, "Cost", "1", "Command", "1");
            results.TwoCommandForTwoCost = QuantityOfCardsEqualingValue(deck, "Cost", "2", "Command", "2");
            results.TwoCommandForOneCost = QuantityOfCardsEqualingValue(deck, "Cost", "1", "Command", "2");

            results.Shields = AnalyseProperty(deck, "Shield");
            results.Command = AnalyseProperty(deck, "Command");

            return(results);
        }
コード例 #2
0
        public static ObservableDeck AsObservable(this IDeck deck)
        {
            if (deck == null)
            {
                return(null);
            }
            var ret = new ObservableDeck {
                GameId = deck.GameId, IsShared = deck.IsShared, Sections = deck.Sections
            };

            return(ret);
        }
コード例 #3
0
        /// <summary>
        /// This happens when the menu item is clicked.
        /// </summary>
        /// <param name="con"></param>
        public void OnClick(IDeckBuilderPluginController con)
        {
            Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            Log.Info("Starting OnClick");

            ObservableDeck curDeck = (ObservableDeck)con.GetLoadedDeck();

            if (curDeck == null)
            {
                MessageBox.Show("Failed to load Deck");
                return;
            }

            DeckAnalysis results = WH40KCDeckAnalyser.Analyse(curDeck);

            curDeck.Notes = TextAnalysisRenderer.RenderAnalysis(results);
        }
コード例 #4
0
        private static PropertyAnalysis AnalyseProperty(ObservableDeck deck, string propertyName)
        {
            PropertyAnalysis results = new PropertyAnalysis();

            if (deck.CardCount() == 0)
            {
                return(results);
            }

            var cardsWithNonZeroPropertyValue = deck.Sections.SelectMany(x => x.Cards).Where(c =>
                                                                                             !String.IsNullOrWhiteSpace(c.PropertySet().FirstOrDefault(p => p.Key.Name.Equals(propertyName)).Value.ToString()));

            results.CardCount = cardsWithNonZeroPropertyValue.Sum(ps => ps.Quantity);

            results.TotalValue = cardsWithNonZeroPropertyValue.Sum(ps => ps.Quantity *
                                                                   int.Parse(ps.PropertySet().FirstOrDefault(p => p.Key.Name.Equals(propertyName)).Value.ToString()));

            results.AverageValue = ((float)results.TotalValue / (float)deck.CardCount());

            return(results);
        }
コード例 #5
0
        public static ObservableDeck AsObservable(this IDeck deck)
        {
            if (deck == null)
            {
                return(null);
            }
            var ret = new ObservableDeck
            {
                GameId   = deck.GameId,
                IsShared = deck.IsShared,
                Sections = deck.Sections.Select(x => new ObservableSection()
                {
                    Name   = x.Name.Clone() as string,
                    Cards  = x.Cards.Select(y => y.AsObservable()).ToArray(),
                    Shared = x.Shared
                }),
                Notes = deck.Notes.Clone() as string
            };

            return(ret);
        }
コード例 #6
0
ファイル: DeckExtensionMethods.cs プロジェクト: wlk0/OCTGN
        public static ObservableDeck AsObservable(this IDeck deck)
        {
            if (deck == null)
            {
                return(null);
            }
            var ret = new ObservableDeck();

            ret.GameId   = deck.GameId;
            ret.IsShared = deck.IsShared;
            ret.Sleeve   = (ISleeve)deck.Sleeve?.Clone();
            if (deck.Sections == null)
            {
                ret.Sections = new List <ObservableSection>();
            }
            else
            {
                ret.Sections = deck.Sections
                               .Where(x => x != null)
                               .Select(
                    x =>
                {
                    var sret  = new ObservableSection();
                    sret.Name = (x.Name ?? "").Clone() as string;
                    if (x.Cards == null)
                    {
                        sret.Cards = new List <ObservableMultiCard>();
                    }
                    else
                    {
                        sret.Cards = x.Cards.Where(y => y != null).Select(y => y.AsObservable()).ToArray();
                    }
                    sret.Shared = x.Shared;
                    return(sret);
                });
            }
            ret.Notes = (deck.Notes ?? "").Clone() as string;
            return(ret);
        }
コード例 #7
0
 private static int QuantityOfCardsEqualingValue(ObservableDeck deck, string propertyOneName, string propertyOneValue, string propertyTwoName, string propertyTwoValue)
 {
     return(deck.Sections.SelectMany(x => x.Cards).Where(c => c.PropertySet().FirstOrDefault(p => p.Key.Name.Equals(propertyOneName)).Value.ToString().Equals(propertyOneValue))
            .Where(c => c.PropertySet().FirstOrDefault(p => p.Key.Name.Equals(propertyTwoName)).Value.ToString().Equals(propertyTwoValue))
            .Select(x => x.Quantity).Sum(x => x));
 }
コード例 #8
0
        public GameEngine(Game def, string nickname, bool specator, string password = "", bool isLocal = false)
        {
            History = new JodsEngineHistory(def.Id);
            if (Program.IsHost)
            {
                History.Name = Program.CurrentOnlineGameName;
            }

            ReplayWriter = new ReplayWriter();

            LoadedCards          = new ObservableDeck();
            LoadedCards.Sections = new ObservableCollection <ObservableSection>();

            DeckStats = new DeckStatsViewModel();

            Spectator = specator;
            Program.GameMess.Clear();
            if (def.ScriptVersion.Equals(new Version(0, 0, 0, 0)))
            {
                Program.GameMess.Warning("This game doesn't have a Script Version specified. Please contact the game developer.\n\n\nYou can get in contact of the game developer here {0}", def.GameUrl);
                def.ScriptVersion = new Version(3, 1, 0, 0);
            }
            if (Versioned.ValidVersion(def.ScriptVersion) == false)
            {
                Program.GameMess.Warning(
                    "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}",
                    def.ScriptVersion, def.GameUrl);
                def.ScriptVersion = Versioned.LowestVersion;
            }
            else
            {
                var vmeta = Versioned.GetVersion(def.ScriptVersion);
                if (vmeta.DeleteDate <= DateTime.Now)
                {
                    Program.GameMess.Warning("This game requires an API version {0} which is no longer supported by OCTGN.\nYou can still play, however some aspects of the game may no longer function as expected, and it may be removed at any time.\nYou may want to contact the developer of this game and ask for an update.\n\nYou can find more information about this game at {1}."
                                             , def.ScriptVersion, def.GameUrl);
                }
            }
            //Program.ChatLog.ClearEvents();
            IsLocal       = isLocal;
            this.Password = password;
            Definition    = def;
            _table        = new Table(def.Table);
            if (def.Phases != null)
            {
                byte PhaseId = 1;
                _allPhases = def.Phases.Select(x => new Phase(PhaseId++, x)).ToList();
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Key, varDef.Value.Value);
            }
            ScriptApi     = Versioned.Get <ScriptApi>(Definition.ScriptVersion);
            this.Nickname = nickname;
            while (String.IsNullOrWhiteSpace(this.Nickname))
            {
                this.Nickname = Prefs.Nickname;
                if (string.IsNullOrWhiteSpace(this.Nickname))
                {
                    this.Nickname = Randomness.GrabRandomNounWord() + new Random().Next(30);
                }
                var retNick = this.Nickname;
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var i   = new InputDlg("Choose a nickname", "Choose a nickname", Nickname);
                    retNick = i.GetString();
                });
                this.Nickname = retNick;
            }
            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            if (Definition.GameBoards.ContainsKey(""))
            {
                GameBoard = Definition.GameBoards[""];
            }
            ActivePlayer = null;

            foreach (var size in Definition.CardSizes)
            {
                var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front));
                var back  = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back));
                _cardFrontsBacksCache.Add(size.Value.Name, new Tuple <BitmapImage, BitmapImage>(front, back));
            }
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                // clear any existing players
                Play.Player.All.Clear();
                Player.Spectators.Clear();
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition, IsReplay);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Player(Definition, this.Nickname, Program.UserId, 255, Crypto.ModExp(Prefs.PrivateKey), specator, true, IsReplay);
            }));
        }
コード例 #9
0
        public GameEngine(ReplayEngine replayEngine, Game def, string nickname)
        {
            ReplayEngine = replayEngine;
            IsReplay     = true;

            LoadedCards          = new ObservableDeck();
            LoadedCards.Sections = new ObservableCollection <ObservableSection>();

            DeckStats = new DeckStatsViewModel();

            Spectator = false;
            Program.GameMess.Clear();
            if (def.ScriptVersion.Equals(new Version(0, 0, 0, 0)))
            {
                Program.GameMess.Warning("This game doesn't have a Script Version specified. Please contact the game developer.\n\n\nYou can get in contact of the game developer here {0}", def.GameUrl);
                def.ScriptVersion = new Version(3, 1, 0, 0);
            }
            if (Versioned.ValidVersion(def.ScriptVersion) == false)
            {
                Program.GameMess.Warning(
                    "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}",
                    def.ScriptVersion, def.GameUrl);
                def.ScriptVersion = Versioned.LowestVersion;
            }
            else
            {
                var vmeta = Versioned.GetVersion(def.ScriptVersion);
                if (vmeta.DeleteDate <= DateTime.Now)
                {
                    Program.GameMess.Warning("This game requires an API version {0} which is no longer supported by OCTGN.\nYou can still play, however some aspects of the game may no longer function as expected, and it may be removed at any time.\nYou may want to contact the developer of this game and ask for an update.\n\nYou can find more information about this game at {1}."
                                             , def.ScriptVersion, def.GameUrl);
                }
            }
            //Program.ChatLog.ClearEvents();
            IsLocal    = true;
            Definition = def;
            Password   = string.Empty;
            _table     = new Table(def.Table);
            if (def.Phases != null)
            {
                byte PhaseId = 1;
                _allPhases = def.Phases.Select(x => new Phase(PhaseId++, x)).ToList();
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Name, varDef.DefaultValue);
            }
            ScriptApi     = Versioned.Get <ScriptApi>(Definition.ScriptVersion);
            this.Nickname = nickname;

            // Load all game markers
            foreach (DataNew.Entities.Marker m in Definition.GetAllMarkers())
            {
                if (!_markersById.ContainsKey(m.Id))
                {
                    _markersById.Add(m.Id, m);
                }
            }

            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            GameBoard       = Definition.GameBoards["Default"];
            ActivePlayer    = null;

            foreach (var size in Definition.CardSizes)
            {
                var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front));
                var back  = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back));
                _cardFrontsBacksCache.Add(size.Key, new Tuple <BitmapImage, BitmapImage>(front, back));
            }
            Application.Current.Dispatcher.Invoke(new Action(() => {
                // clear any existing players
                Play.Player.All.Clear();
                Player.Spectators.Clear();
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition, IsReplay);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Player(Definition, this.Nickname, Program.UserId, 255, Crypto.ModExp(Prefs.PrivateKey), false, true, IsReplay);

                IsConnected = true;
            }));
        }