コード例 #1
0
ファイル: DecksManager.cs プロジェクト: knight00/windbot
        public static void Init()
        {
            _decks = new Dictionary <string, DeckInstance>();
            _rand  = new Random();

            Assembly asm = Assembly.GetExecutingAssembly();

            Type[] types = asm.GetTypes();

            foreach (Type type in types)
            {
                MemberInfo info       = type;
                object[]   attributes = info.GetCustomAttributes(false);
                foreach (object attribute in attributes)
                {
                    if (attribute is DeckAttribute)
                    {
                        DeckAttribute deck = (DeckAttribute)attribute;
                        _decks.Add(deck.Name, new DeckInstance(deck.File, type, deck.Level));
                    }
                }
            }
            try
            {
                string[] files = Directory.GetFiles(Path.Combine(Program.AssetPath, "Executors"), "*.dll", SearchOption.TopDirectoryOnly);
                foreach (string file in files)
                {
                    Assembly assembly = Assembly.LoadFrom(file);
                    Type[]   types2   = assembly.GetTypes();
                    foreach (Type type in types2)
                    {
                        try
                        {
                            MemberInfo info       = type;
                            object[]   attributes = info.GetCustomAttributes(false);
                            foreach (object attribute in attributes)
                            {
                                if (attribute is DeckAttribute)
                                {
                                    DeckAttribute deck = (DeckAttribute)attribute;
                                    _decks.Add(deck.Name, new DeckInstance(deck.File, type, deck.Level));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.WriteErrorLine("Executor loading (" + file + ") error: " + ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            _list = new List <DeckInstance>();
            _list.AddRange(_decks.Values);

            Logger.WriteLine("Decks initialized, " + _decks.Count + " found.");
        }
コード例 #2
0
 public static IEnumerable <DeckClass> FindClassByAttribute(DeckAttribute filter)
 {
     return(FindClassByAttribute(new List <DeckAttribute>()
     {
         filter
     }));
 }
コード例 #3
0
        public void FilterDeckListTest002_FilterByOneAttribute()
        {
            DeckAttribute filterAttrib    = DeckAttribute.Strength;
            DeckClass?    selectedClass   = null;
            var           filteredClasses = new ObservableCollection <DeckClass>(
                ClassAttributesHelper.FindClassByAttribute(filterAttrib)
                );

            Mock <IDeckTypeSelectorViewModel> typeSelector = GetFullTypeFilter();

            int expectedCount = 3 + //random data - archer i battlemage y strength
                                5;  //one for every class

            DeckListViewModel model = new DeckListViewModel();

            IEnumerable <Deck> result = model.FilterDeckList(
                DeckBase,
                null,
                false,
                false,
                selectedClass,
                filteredClasses,
                null);

            Assert.AreEqual(expectedCount, result.Count());
            Assert.IsTrue(result.All(r => { return(Utils.ClassAttributesHelper.Classes[r.Class.Value].Contains(filterAttrib)); }));
        }
        private void CreateOpponentHeatMapData(IEnumerable <DeckStatsDataRecord> totalOpponents)
        {
            opponentClassHeatMap = new ChartValues <HeatPoint>();

            foreach (var r in totalOpponents)
            {
                DeckClass dc = (DeckClass)Enum.Parse(typeof(DeckClass), r.Opp);
                DataModel.DeckAttributes da  = ClassAttributesHelper.Classes[dc];
                DeckAttribute            da1 = da[0];
                DeckAttribute            da2 = (da.Count > 1 ? da[1] : da[0]);
                opponentClassHeatMap.Add(new HeatPoint((int)da1, (int)da2, Int32.Parse(r.Win)));
            }
        }
コード例 #5
0
        public TriggerChanceUpdater(ObservableCollection <CardInstance> cards, HashSet <CardInstance> to_update = null)
        {
            int total = 0;

            foreach (var itr in cards)
            {
                total += itr.Least;
            }

            foreach (var itr in cards)
            {
                switch (itr.Card.TriggerType)
                {
                case "ally":
                {
                    DeckAttribute color = itr.Card.Attributes.First();
                    int           count = 0;
                    foreach (var jtr in cards)
                    {
                        if (jtr.Card.Attributes.Contains(color))
                        {
                            count += jtr.Least;
                        }
                    }
                    itr.TriggerChance = Math.Round(count * 100.0f / total, 2).ToString();
                    if (to_update != null)
                    {
                        to_update.Add(itr);
                    }
                    break;
                }

                case "prophecy":
                {
                    itr.TriggerChance = Math.Round(itr.Least * 100.0f / total, 2).ToString();
                    if (to_update != null)
                    {
                        to_update.Add(itr);
                    }
                    break;
                }

                case "action_draw":
                {
                    int count = 0;
                    foreach (var jtr in cards)
                    {
                        if (jtr.Card.Type == CardType.Action)
                        {
                            count += jtr.Least;
                        }
                    }

                    itr.TriggerChance = Math.Round(count * 100.0f / total, 2).ToString();
                    break;
                }

                default: break;
                }
            }
        }