예제 #1
0
 public void LocalizeCards(IEnumerable<CardItem> cards)
 {
     CardSearchParams parameters = new CardSearchParams();
       parameters.Ids = cards.Select(e => e.Id).ToList();
       foreach(CardItem localizedCard in SelectCards(parameters))
       {
     foreach(CardItem c in cards.Where(e => e.Id == localizedCard.Id))
     {
       c.Name = localizedCard.Name;
       c.Text = localizedCard.Text;
       c.FlavorText = localizedCard.FlavorText;
     }
       }
 }
예제 #2
0
        public IEnumerable<CardItem> SelectCards(CardSearchParams parameters)
        {
            SortableList cards = new SortableList(new CardItemComparer(parameters.OrderCriteria), 100000);
              cards.KeepSorted = true;

              System.Collections.IEnumerable cardNodes = null;
              // id
              if(parameters.Ids.Count > 0)
              {
            cardNodes = parameters.Ids.Distinct().Where(e => cardNodesById.ContainsKey(e)).Select(id => cardNodesById[id]);
              }
              else
              {
            StringBuilder xpath = new StringBuilder();
            if(parameters.Sets.Count > 0)
              AddParameter(xpath, "set", parameters.Sets);
            if(parameters.Types.Count > 0)
              AddParameter(xpath, "type", parameters.Types);
            if(parameters.Rarities.Count > 0)
              AddParameter(xpath, "rarity", parameters.Rarities);
            if(!string.IsNullOrEmpty(parameters.Characteristics))
            {
              if(xpath.Length > 0)
            xpath.Append(" and ");
              xpath.Append("contains(characteristics,'");
              xpath.Append(parameters.Characteristics.Trim());
              xpath.Append("')");
            }
            if(xpath.Length > 0)
            {
              xpath.Insert(0, "[");
              xpath.Append("]");
            }
            xpath.Insert(0, "item");
            cardNodes = cardDatabase.DocumentElement.SelectNodes(xpath.ToString(), cardsNsManager);
              }

              foreach(XmlNode cardNode in cardNodes)
              {
            XmlNode langNode = langNodesById[cardNode.SelectSingleNode("id").InnerText];
            bool valid = true;
            if(!string.IsNullOrEmpty(parameters.Name))
            {
              if(parameters.NameExact)
            valid = string.Compare(langNode.SelectSingleNode("name").InnerText, parameters.Name, true) == 0;
              else
            valid = langNode.SelectSingleNode("name").InnerText.IndexOf(parameters.Name, StringComparison.OrdinalIgnoreCase) != -1;
            }
            if(valid && !string.IsNullOrEmpty(parameters.Text))
            {
              valid = langNode.SelectSingleNode("text").InnerText.IndexOf(parameters.Text, StringComparison.OrdinalIgnoreCase) != -1;
            }
            if(valid)
            {
              if(parameters.Colors.Count > 0)
              {
            List<string> colors = new List<string>();
            foreach(XmlNode colorNode in cardNode.SelectNodes("colors/color"))
              colors.Add(colorNode.InnerText);
            valid = parameters.Colors.Any(e => colors.Contains(e));
              }
            }
            if(valid && parameters.Cost.Criteria != CostCriteria.None)
            {
              int cost = cardNode.SelectSingleNode("cost").InnerText.Replace("{", "").Replace("}", "").ToCharArray().Sum(c =>
            char.IsNumber(c) ? Convert.ToInt32(c.ToString()) : 1);
              switch(parameters.Cost.Criteria)
              {
            case CostCriteria.EqualTo: valid = cost == parameters.Cost.Value; break;
            case CostCriteria.LessThan: valid = cost < parameters.Cost.Value; break;
            case CostCriteria.MoreThan: valid = cost > parameters.Cost.Value; break;
              }
            }
            if(valid)
            {
              cards.Add(new CardItem(cardNode, langNode, typesService.GetByCode(cardNode["type"].InnerText)));
            }
              }
              return cards.Cast<CardItem>();
        }
 public CardSearchParams GetCardSearchParams()
 {
     CardSearchParams parameters = new CardSearchParams();
       for(int i = 0; i < listSet.Items.Count; i++)
       {
     if(listSet.GetItemChecked(i))
       parameters.Sets.Add((listSet.Items[i] as ListItem).Value.ToString());
       }
       for(int i = 0; i < listColor.Items.Count; i++)
       {
     if(listColor.GetItemChecked(i))
       parameters.Colors.Add((listColor.Items[i] as ListItem).Value.ToString());
       }
       for(int i = 0; i < listType.Items.Count; i++)
       {
     if(listType.GetItemChecked(i))
       parameters.Types.Add((listType.Items[i] as ListItem).Value.ToString());
       }
       for(int i = 0; i < listRarity.Items.Count; i++)
       {
     if(listRarity.GetItemChecked(i))
       parameters.Rarities.Add((listRarity.Items[i] as ListItem).Value.ToString());
       }
       parameters.Cost.Criteria = CostCriteria.None;
       switch(cbCost.Text.ToString())
       {
     case "<": parameters.Cost.Criteria = CostCriteria.LessThan; break;
     case "=": parameters.Cost.Criteria = CostCriteria.EqualTo; break;
     case ">": parameters.Cost.Criteria = CostCriteria.MoreThan; break;
       }
       parameters.Cost.Value = (int)numCost.Value;
       if(txtName.Text.Trim().Length > 0)
     parameters.Name = txtName.Text;
       if(txtText.Text.Trim().Length > 0)
     parameters.Text = txtText.Text;
       if(txtCharacteristics.Text.Trim().Length > 0)
     parameters.Characteristics = txtCharacteristics.Text;
       parameters.OrderCriteria = new OrderCriteria() { Field = OrderField.Name, Ascending = true };
       return parameters;
 }
예제 #4
0
 void consoleView_LinkClicked(object sender, LinkClickedEventArgs e)
 {
     try
       {
     CardSearchParams searchParams = new CardSearchParams();
     searchParams.Ids = Enumerable.Repeat(e.LinkText.Split('#').Last(), 1).ToList();
     var card = Program.LogicHandler.ServicesProvider.CardsService.SelectCards(searchParams).FirstOrDefault();
     if(card != null)
       ShowCardMagnification(card);
       }
       catch(Exception ex)
       {
     HandleException(ex);
       }
 }
예제 #5
0
        void ImportMwsDeck(GameInfoItem gameItem, DeckItem deck, string text, CodesMapService mappingManager, Dictionary<string, string> discardedLines)
        {
            ServicesProvider engServicesProvider = servicesProvider;
              if(engServicesProvider.GameLanguageCode != "eng")
              {
            engServicesProvider = new ServicesProvider("eng", "eng");
            engServicesProvider.LoadGame(gameItem);
              }
              discardedLines.Clear();
              foreach(string line in text.Split(new string[] {Environment.NewLine}, StringSplitOptions.None).
            Select(e => e.Trim()).Where(e => e.Length > 0 && !e.StartsWith("//")))
              {
            string[] lineParts = line.Split(' ');
            if(lineParts.Length < 3)
              continue;

            try
            {
              var cardList = deck.MainCards;
              int partIndex = 0;
              if(lineParts[0] == "SB:")
              {
            partIndex++;
            cardList = deck.SideboardCards;
              }
              int amount;
              if(int.TryParse(lineParts[partIndex++], out amount))
              {
            string mwsSetCode = string.Empty;
            try
            {
              mwsSetCode = lineParts[partIndex++].Replace("[", string.Empty).Replace("]", string.Empty);
            }
            catch
            {
              throw new Exception("Cannot read set code on this line: " + line);
            }
            string cardName = string.Empty;
            try
            {
              cardName = string.Concat(
                lineParts.Skip(partIndex).Where(e => e != "(1)" && e != "(2)" && e != "(3)" && e != "(4)").Select(
                e => string.Concat(e, " ")).ToArray()).TrimEnd();
              cardName = cardName.Split(new string[] { "--" }, StringSplitOptions.None).First();
            }
            catch
            {
              throw new Exception("Cannot read card name on this line: " + line);
            }
            string internalSetCode = mappingManager.GetCode(mwsSetCode);
            if(string.IsNullOrEmpty(internalSetCode))
              throw new Exception("Set code unknown: " + mwsSetCode);
            CardSearchParams p = new CardSearchParams();
            p.Sets.Add(internalSetCode);
            p.Name = cardName;
            p.Language = "ENG";
            p.NameExact = true;

            CardItem cardItem = engServicesProvider.CardsService.SelectCards(p).FirstOrDefault();
            if(cardItem == null)
              throw new Exception("Card name unknown: " + cardName);
            for(int i = 0; i < amount; i++)
              cardList.Add(cardItem.Clone());
              }
              else
              {
            throw new Exception("Cannot read card amount on this line: " + line);
              }
            }
            catch(Exception ex)
            {
              discardedLines.Add(line, ex.Message);
            }
              }
        }
예제 #6
0
 void FillDeck(ObservableCollection<CardItem> list, XmlNode deckNode, string language)
 {
     XmlNodeList cardNodes = deckNode.SelectNodes("card");
       CardSearchParams searchParams = new CardSearchParams();
       foreach(XmlNode cardNode in cardNodes)
     searchParams.Ids.Add(cardNode.Attributes["id"].Value);
       if(searchParams.Ids.Count > 0)
       {
     searchParams.Language = language;
     Dictionary<string, CardItem> cardDataById = servicesProvider.CardsService.SelectCards(searchParams).ToDictionary(e => e.Id);
     foreach(XmlNode cardNode in cardNodes)
       for(int i = 0; i < Convert.ToInt32(cardNode.Attributes["count"].Value); i++)
     list.Add(cardDataById[cardNode.Attributes["id"].Value].Clone());
       }
 }