Beispiel #1
0
        public static bool TryGetCardFromZip(string name, ref MagicCard c)
        {
            string cfn        = name.Substring(0, 1).ToLower() + "/" + name.Trim().Replace(' ', '_').Replace("\'", string.Empty).ToLower() + ".txt";
            Stream cardStream = GetCardDataStream(cfn);

            if (cardStream == null)
            {
                return(false);
            }

            try {
                MemoryStream ms = new MemoryStream();
                cardStream.CopyTo(ms);
                ms.Seek(0, SeekOrigin.Begin);
                c = LoadCardData(ms);
                cardStream.Seek(0, SeekOrigin.Begin);
                using (StreamReader tr = new StreamReader(cardStream)){
                    c.RawCardData = tr.ReadToEnd();
                }
            } catch (Exception ex) {
                Debug.WriteLine(ex.ToString());
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public CardInstance AddCardForeignToHand(MagicCard mc)
        {
            CardInstance ci = Deck.AddCard(mc);

            ci.Controler = this;
            ci.ResetPositionAndRotation();
            ci.yAngle = MathHelper.Pi;
            Hand.AddCard(ci, true);
            return(ci);
        }
Beispiel #3
0
        public CardInstance AddCard(MagicCard mc, string edition = "")
        {
            CardInstance tmp = new CardInstance(mc)
            {
                Edition = edition
            };

            Cards.Add(tmp);
            return(tmp);
        }
Beispiel #4
0
        static void PictureDownloader()
        {
            while (true)
            {
                int count = 0;
                lock (MissingPicToDownload)
                {
                    count = MissingPicToDownload.Count;
                }
                if (count == 0)
                {
                    Thread.Sleep(30000);
                }
                else
                {
                    MagicCard mc   = null;
                    string    path = "";
                    string    name = "";
                    lock (MissingPicToDownload)
                    {
                        mc = MissingPicToDownload[0];
                        MissingPicToDownload.RemoveAt(0);
                    }

                    lock (mc)
                    {
                        path = mc.picturePath;
                        name = mc.Name;
                        mc.DownloadingTextureInProgress = true;
                        mc.DownloadingTryCount++;
                    }

                    Debug.WriteLine("downloading:" + "http:" + path);
                    WebClient webClient = new WebClient();
                    string    localPath = System.IO.Path.Combine(cardsArtPath, name + ".full.jpg");
                    try
                    {
                        webClient.DownloadFile("http:" + path, localPath);
                        Debug.WriteLine("->ok");
                    }
                    catch (Exception)
                    {
                        if (File.Exists(localPath))
                        {
                            File.Delete(localPath);
                        }
                    }
                    lock (mc)
                    {
                        mc.DownloadingTextureInProgress = false;
                    }
                }
            }
        }
Beispiel #5
0
        void onReparse(object sender, MouseButtonEventArgs e)
        {
            MagicCard c = this;
            string    n = Name;

            reset();
            if (!MagicData.TryGetCardFromZip(n, ref c))
            {
                Debug.WriteLine("DCK: {0} => Card not found: {1}", Name, n);
                return;
            }
        }
Beispiel #6
0
        public static void CacheCard(MagicCard c)
        {
            if (!Directory.Exists(cachingPath))
            {
                Directory.CreateDirectory(cachingPath);
            }
            string cardPath = System.IO.Path.Combine(cachingPath, c.Name + ".bin");

            using (FileStream ms = new FileStream(cardPath, FileMode.Create)) {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(ms, c);
            }
        }
Beispiel #7
0
        static bool tryGetCardFromCache(string name, ref MagicCard c)
        {
            string cardPath = System.IO.Path.Combine(cachingPath, name + ".bin");

            if (!File.Exists(cardPath))
            {
                return(false);
            }
            using (Stream stream = GGL.FileSystemHelpers.GetStreamFromPath(cardPath)) {
                BinaryFormatter formatter = new BinaryFormatter();
                c = (MagicCard)formatter.Deserialize(stream);
            }
            return(true);
        }
Beispiel #8
0
 public void CacheAllCards()
 {
     foreach (MainLine l in CardEntries)
     {
         MagicCard c = l.Card;
         if (c == null)
         {
             Debug.WriteLine("DCK: {0} => Card not found: {1}", Name, l.name);
         }
         else
         {
             MagicData.CacheCard(c);
         }
     }
 }
Beispiel #9
0
        void onAddCardToHand(object sender, MouseButtonEventArgs e)
        {
            string cardInfos = (((sender as GraphicObject).Parent.Parent.Parent as GraphicObject).
                                FindByName("cardEntries") as CardDataGrid).SelectedItem as string;
            MagicCard mc = null;

            MagicData.TryLoadCard(cardInfos, ref mc);

            CardInstance tmp = Players[0].Deck.AddCard(mc);

            tmp.CreateGLCard();

            tmp.Controler = Players[0];
            tmp.ResetPositionAndRotation();
            tmp.yAngle = MathHelper.Pi;
            tmp.Controler.Hand.AddCard(tmp, true);
        }
Beispiel #10
0
 public void LoadCards()
 {
     foreach (MainLine l in inputDck.CardEntries)
     {
         MagicCard c = null;
         if (!MagicData.TryLoadCard(l.name, ref c))
         {
             Debug.WriteLine("DCK: {0} => Card not found: {1}", inputDck.Name, l.name);
             continue;
         }
         for (int i = 0; i < l.count; i++)
         {
             AddCard(c, l.code);
         }
         Player.ProgressValue++;
     }
     inputDck = null;
 }
Beispiel #11
0
        public static MagicCard LoadCardData(Stream s)
        {
            MagicCard c = new MagicCard();

            using (StreamReader sr = new StreamReader(s))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();

                    string[] tmp = line.Split(new char[] { ':' });

                    switch (tmp[0].ToLower())
                    {
                    case "name":
                        c.Name = tmp [1];
                        break;

                    case "manacost":
                        c.Cost = Mana.Parse(tmp[1]);
                        break;

                    case "types":
                        string[] types = tmp[1].Split(new char[] { ' ' });
                        foreach (string t in types)
                        {
                            if (string.IsNullOrEmpty(t))
                            {
                                continue;
                            }
                            string tt = t.Replace('\'', '_');
                            tt       = tt.Replace('-', '_');
                            c.Types += (CardTypes)Enum.Parse(typeof(CardTypes), tt, true);
                        }
                        break;

                    case "a":
                        c.Abilities.Add(Ability.Parse(tmp[1]));
                        break;

                    case "oracle":
                        c.Oracle = string.Join("\n", tmp.ToList().GetRange(1, tmp.Length - 1).ToArray());
                        break;

                    case "pt":
                        string[] pt = tmp[1].Split(new char[] { '/' });

                        int intPT;

                        if (int.TryParse(pt[0], out intPT))
                        {
                            c.Power = intPT;
                        }
                        else
                        {
                            Debug.WriteLine("power:" + pt[0]);
                        }

                        if (int.TryParse(pt[1], out intPT))
                        {
                            c.Toughness = intPT;
                        }
                        else
                        {
                            Debug.WriteLine("toughness:" + pt[1]);
                        }
                        break;

                    case "s":
//							Ability aa = c.Abilities.FirstOrDefault ();
//							if (aa == null) {
//								aa = new Ability ();
//								c.Abilities.Add (aa);
//							} else
//								Debugger.Break;

                        c.SpellEffects.Add(EffectGroup.Parse(tmp[1]));
                        break;

                    case "t":
                        c.Triggers.Add(Trigger.Parse(tmp[1]));
                        break;

                    case "svar":

                        if (SVarToResolve.TryToParseAndSetValue(tmp [1], tmp [2]))
                        {
                            break;
                        }

                        switch (tmp[1].ToLower())
                        {
                        case "darkeffect":
                            break;

                        case "darkpower":
                            break;

                        case "darkmana":
                            break;

                        case "picture":
                            c.picturePath = tmp[3];
                            break;

                        case "remaideck":
                            break;

                        case "piccount":
                            c.nbrImg = int.Parse(tmp[2]);
                            break;

                        default:
                            Debug.WriteLine("Unknow SVAR: " + tmp[1]);
                            break;
                        }
                        break;

                    case "k":
                        Ability a = Ability.ParseKeyword(tmp[1], c);
                        if (a != null)
                        {
                            c.Abilities.Add(a);
                        }
                        break;

                    case "r":
                        c.R.Add(tmp[1]);
                        break;

                    case "deckneeds":
                        c.DeckNeeds.Add(tmp[1]);
                        break;

                    case "text":
                        c.TextField.Add(tmp[1]);
                        break;

                    case "alternatemode":
                        c.AlternateMode = tmp[1];
                        break;

                    case "alternate":
                        c.Alternate = true;
                        break;

                    case "colors":
                        c.Colors += (ManaTypes)Enum.Parse(typeof(ManaTypes), tmp[1], true);
                        break;

                    case "loyalty":
                        c.Loyalty = tmp[1];
                        break;

                    case "handlifemodifier":
                        c.HandLifeModifier = tmp[1];
                        break;

                    case "deckhints":
                        c.DeckHints = tmp[1];
                        break;

                    case "var":
                        Debug.WriteLine("var: {0} {1} {2}", c.Name, tmp[1], tmp[2]);
                        break;

                    default:
                        if (tmp[0].StartsWith("#"))
                        {
                            c.Comments.Add(tmp[0]);
                        }
                        else if (!string.IsNullOrEmpty(tmp[0]))
                        {
                            string txt = "";
                            for (int i = 0; i < tmp.Length; i++)
                            {
                                txt += ":" + tmp[i];
                            }

                            Debug.WriteLine("? => {0} {1}", c.Name, txt);
                        }
                        break;
                    }
                }
                SVarToResolve.UnresolvedSVars.Clear();
            }

            #region add mana ability to basic lands
            if (c.Types == CardTypes.Land)
            {
                if (c.Abilities.Count == 0)
                {
                    Mana m = null;
                    switch (c.Name.ToLower())
                    {
                    case "plains":
                    case "snow-covered plains":
                        m = ManaTypes.White;
                        break;

                    case "mountain":
                    case "snow-covered mountain":
                        m = ManaTypes.Red;
                        break;

                    case "swamp":
                    case "snow-covered swamp":
                        m = ManaTypes.Black;
                        break;

                    case "forest":
                    case "snow-covered forest":
                        m = ManaTypes.Green;
                        break;

                    case "island":
                    case "snow-covered island":
                        m = ManaTypes.Blue;
                        break;
                    }
                    if (m != null)
                    {
                        c.Abilities.Add(
                            new Ability(new ManaEffect(m))
                        {
                            ActivationCost = CostTypes.Tap
                        });
                    }
                }
            }
            #endregion

            return(c);
        }
Beispiel #12
0
 public static bool TryLoadCard(string name, ref MagicCard c)
 {
     return
         (tryGetCardFromCache(name, ref c) ? true :
          TryGetCardFromZip(name, ref c));
 }
Beispiel #13
0
        void MainWin_KeyboardKeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
        {
            switch (e.Key)
            {
            case OpenTK.Input.Key.KeypadEnter:
                engine.ip.PhaseDone = true;
//				if (engine.pp == engine.ip && engine.cp != engine.pp)
//					engine.GivePriorityToNextPlayer ();
                break;

            case OpenTK.Input.Key.Escape:
                closeCurrentGame();
                break;

                        #if DEBUG
            case OpenTK.Input.Key.F1:
                if (CardInstance.selectedCard == null)
                {
                    break;
                }
                loadWindow("#MagicCrow.ui.cardInstanceView.iml");
                NotifyValueChanged("SelectedCardInstance", null);
                NotifyValueChanged("SelectedCardInstance", SelectedCardInstance);
                break;

            case OpenTK.Input.Key.F2:
                if (CardInstance.selectedCard == null)
                {
                    break;
                }
                loadWindow("#MagicCrow.ui.cardView.iml");
                NotifyValueChanged("SelectedCardModel", SelectedCardModel);
                break;

            case OpenTK.Input.Key.F3:
                loadWindow("#MagicCrow.ui.MagicStackView.iml");
                break;

            case OpenTK.Input.Key.F4:
                loadWindow("#MagicCrow.ui.decks.iml");
                break;

            case OpenTK.Input.Key.F6:
                loadWindow("#MagicCrow.ui.MemberView.crow");
                break;

            case OpenTK.Input.Key.F7:
                loadWindow("#MagicCrow.ui.cardList.iml");
                break;

            case OpenTK.Input.Key.Space:
                Players [0].DrawOneCard();
                break;

            case OpenTK.Input.Key.H:
                if (e.Control)
                {
                }
                else
                {
                    CardInstance.selectedCard?.ChangeZone(CardGroupEnum.Hand);
                }
                break;

            case OpenTK.Input.Key.E:
                if (e.Control)
                {
                    foreach (CardInstance ci in Players[0].Deck.Cards.Where
                                 (c => c.CurrentGroup.GroupName == CardGroupEnum.Library && c.Effects?.Count > 0))
                    {
                        ci.ChangeZone(CardGroupEnum.Hand);
                    }
                }
                break;

            case OpenTK.Input.Key.D:
                if (e.Control)
                {
                    foreach (CardInstance ci in Players[0].Deck.Cards.Where(c => c.CurrentGroup.GroupName == CardGroupEnum.Hand))
                    {
                        ci.ChangeZone(CardGroupEnum.Library);
                    }
                }
                break;

            case OpenTK.Input.Key.L:
                if (e.Control)
                {
                    foreach (CardInstance ci in Players[0].Deck.Cards.Where(c => c.HasType(CardTypes.Land) && c.CurrentGroup.GroupName != CardGroupEnum.InPlay).Take(5))
                    {
                        ci.ChangeZone(CardGroupEnum.InPlay);
                    }
                }
                else
                {
                    Players [0].Library.RevealToUIPlayer();
                }
                break;

            case OpenTK.Input.Key.O:
                engine.ip.Opponent.Hand.RevealToUIPlayer();
                break;

            case OpenTK.Input.Key.U:
                if (e.Control)
                {
                    foreach (CardInstance ci in Players[0].Deck.Cards.Where(c => c.HasType(CardTypes.Land) && c.CurrentGroup.GroupName == CardGroupEnum.InPlay))
                    {
                        ci.tappedWithoutEvent = false;
                    }
                }
                if (CardInstance.selectedCard == null)
                {
                    return;
                }
                CardInstance.selectedCard.tappedWithoutEvent = false;
                break;

            case OpenTK.Input.Key.Delete:
                if (CardInstance.selectedCard == null)
                {
                    return;
                }
                CardInstance.selectedCard.Reset();
                CardInstance.selectedCard.ChangeZone(CardGroupEnum.Hand);
                break;

            case OpenTK.Input.Key.KeypadPlus:
                engine.ip.AllowedLandsToBePlayed++;
                break;

            case OpenTK.Input.Key.N:
                CardInstance nextInvalid = Players [0].Library.Cards.Where(c => !c.Model.IsOk).FirstOrDefault();
                Players [0].Library.RemoveCard(nextInvalid);
                Players [0].Hand.AddCard(nextInvalid);
                break;

            case OpenTK.Input.Key.T:
                foreach (CardInstance ci in Players[0].Library.Cards.Where(c => c.HasEffect(EffectType.Token)))
                {
                    ci.ChangeZone(CardGroupEnum.Hand);
                }
                break;

            case OpenTK.Input.Key.C:
                foreach (CardInstance ci in Players[0].Library.Cards.Where(c => c.HasType(CardTypes.Creature)))
                {
                    ci.ChangeZone(CardGroupEnum.InPlay);
                }
                break;

            case OpenTK.Input.Key.R:
                MagicCard mc = null;
                MagicData.TryLoadCard(Crow.Configuration.Get <String> ("LastPointedCardForDebug"), ref mc);
                mc.AddCardToHand();
                break;

            case OpenTK.Input.Key.M:
                Players[0].ManaPool += new Mana(10, ManaTypes.White);
                Players[0].ManaPool += new Mana(10, ManaTypes.Blue);
                Players[0].ManaPool += new Mana(10, ManaTypes.Red);
                Players[0].ManaPool += new Mana(10, ManaTypes.Black);
                Players[0].ManaPool += new Mana(10, ManaTypes.Green);

                break;
                        #endif
            }
        }