Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using OcgWrapper;
  4. using OcgWrapper.Enums;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace YgoCore
  8. {
  9.     public class Deck
  10.     {
  11.         public IList<int> Main { get; private set; }
  12.         public IList<int> Extra { get; private set; }
  13.         public IList<int> Side { get; private set; }
  14.         static List<string> OwnedSkinsList;
  15.  
  16.         public Deck()
  17.         {
  18.             Main = new List<int>();
  19.             Extra = new List<int>();
  20.             Side = new List<int>();
  21.         }
  22.  
  23.         public void AddMain(int cardId)
  24.         {
  25.             Card card = Card.Get(cardId);
  26.             if (card == null)
  27.                 return;
  28.             if ((card.Type & (int)CardType.Token) != 0)
  29.                 return;
  30.             if ((card.Type & 0x802040) != 0)
  31.             {
  32.                 if (Extra.Count < 15)
  33.                     Extra.Add(cardId);
  34.             }
  35.             else
  36.             {
  37.                 if (Main.Count < 60)
  38.                     Main.Add(cardId);
  39.             }
  40.         }
  41.  
  42.         public void AddSide(int cardId)
  43.         {
  44.             Card card = Card.Get(cardId);
  45.             if (card == null)
  46.                 return;
  47.             if ((card.Type & (int)CardType.Token) != 0)
  48.                 return;
  49.             if (Side.Count < 15)
  50.                 Side.Add(cardId);
  51.         }
  52.  
  53.         public int Check(Banlist ban, bool ocg, bool tcg, string ownedSkins = "")
  54.         {
  55.             if (Main.Count < 40 || Main.Count > 60 || Extra.Count > 15 || Side.Count > 15)
  56.                 return 1;
  57.  
  58.             OwnedSkinsList = new List<string>();
  59.             if (ownedSkins != "" && ownedSkins != null)
  60.             {
  61.                 string[] cardSkinParts = Regex.Split(ownedSkins, ",");
  62.                 foreach (string cardSkinPart in cardSkinParts)
  63.                     OwnedSkinsList.Add(cardSkinPart);
  64.             }
  65.  
  66.             IDictionary<int, int> cards = new Dictionary<int, int>();
  67.  
  68.             IList<int>[] stacks = { Main, Extra, Side };
  69.             foreach (IList<int> stack in stacks)
  70.             {
  71.                 foreach (int id in stack)
  72.                 {
  73.                     Card card = Card.Get(id);
  74.  
  75.                     if (card.Id >= 800000000 && card.Id < 900000000)
  76.                     {
  77.                         if (!OwnedSkinsList.Contains(card.Id.ToString()))
  78.                             return card.Id;
  79.                     }
  80.  
  81.                     AddToCards(cards, card);
  82.                     if (!ocg && card.Ot == 1 || !tcg && card.Ot == 2)
  83.                         return id;
  84.                 }
  85.             }
  86.  
  87.             if (ban == null)
  88.                 return 0;
  89.  
  90.             foreach (KeyValuePair<int, int> pair in cards)
  91.             {
  92.                 int max = ban.GetQuantity(pair.Key);
  93.                 if (pair.Value > max)
  94.                     return pair.Key;
  95.             }
  96.  
  97.             return 0;
  98.         }
  99.  
  100.         public bool Check(Deck deck)
  101.         {
  102.             if (deck.Main.Count != Main.Count || deck.Extra.Count != Extra.Count)
  103.                 return false;
  104.  
  105.             IDictionary<int, int> cards = new Dictionary<int, int>();
  106.             IDictionary<int, int> ncards = new Dictionary<int, int>();
  107.             IList<int>[] stacks = { Main, Extra, Side };
  108.             foreach (IList<int> stack in stacks)
  109.             {
  110.                 foreach (int id in stack)
  111.                 {
  112.                     if (!cards.ContainsKey(id))
  113.                         cards.Add(id, 1);
  114.                     else
  115.                         cards[id]++;
  116.                 }
  117.             }
  118.             stacks = new[] { deck.Main, deck.Extra, deck.Side };
  119.             foreach (IList<int> stack in stacks)
  120.             {
  121.                 foreach (int id in stack)
  122.                 {
  123.                     if (!ncards.ContainsKey(id))
  124.                         ncards.Add(id, 1);
  125.                     else
  126.                         ncards[id]++;
  127.                 }
  128.             }
  129.             foreach (KeyValuePair<int, int> pair in cards)
  130.             {
  131.                 if (!ncards.ContainsKey(pair.Key))
  132.                     return false;
  133.                 if (ncards[pair.Key] != pair.Value)
  134.                     return false;
  135.             }
  136.             return true;
  137.         }
  138.  
  139.         private static void AddToCards(IDictionary<int, int> cards, Card card)
  140.         {
  141.             int id = card.Id;
  142.             if (card.Alias != 0)
  143.                 id = card.Alias;
  144.             if (cards.ContainsKey(id))
  145.                 cards[id]++;
  146.             else
  147.                 cards.Add(id, 1);
  148.         }
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement