コード例 #1
0
    public static async Task SaveImageFiles(string path, ScryfallApiClient client, IEnumerable <Deck> decks)
    {
        var sort         = new CardSort();
        var webClient    = new WebClient();
        var invalidChars = Path.GetInvalidFileNameChars();

        foreach (var deck in decks)
        {
            var deckName = Path.GetFileNameWithoutExtension(deck.FilePath);
            var deckPath = Path.Combine(path, "Downloaded", deckName);

            Directory.CreateDirectory(deckPath);

            foreach (var card in deck.Cards)
            {
                var name = new string(card.Name.Where(x => !invalidChars.Contains(x)).ToArray());

                var filePath = Path.Combine(deckPath, name + " (" + card.Quantity + ").jpg");

                if (File.Exists(filePath))
                {
                    continue;
                }

                Console.WriteLine("Downloading " + deckName + ": " + card.Name + "...");

                var data = await GetCard(card, client, sort);

                var images = data.ImageUris;

                if (images != null)
                {
                    var imageUri = images["border_crop"];

                    webClient.DownloadFile(imageUri.ToString(), filePath);
                }
                else
                {
                    Console.WriteLine("Multiple faces...");

                    webClient.DownloadFile(data.CardFaces[0].ImageUris["border_crop"].ToString(), filePath);

                    var facePath = Path.Combine(deckPath, name + " (" + card.Quantity + ")");
                    Directory.CreateDirectory(facePath);

                    int i = 1;
                    foreach (var face in data.CardFaces)
                    {
                        filePath = Path.Combine(facePath, i++ + ".jpg");

                        var imageUri = face.ImageUris["border_crop"];

                        webClient.DownloadFile(imageUri.ToString(), filePath);
                    }
                }
            }
        }
    }
コード例 #2
0
    List <Unit> CalculateThreat()
    {
        for (int y = 0; y < 7; y++)
        {
            for (int x = 0; x < 7; x++)
            {
                float num = 0;
                for (int i = 0; i < field.cards.Count; i++)
                {
                    if (field.cards[i].playerOwned)
                    {
                        num += field.cards[i].value / Vector2.Distance(field.cards[i].GetComponent <Unit>().position, field.tiles[y, x].GetComponent <TileScript>().position) + 1.0f;
                    }
                    else
                    {
                        num -= field.cards[i].value / Vector2.Distance(field.cards[i].GetComponent <Unit>().position, field.tiles[y, x].GetComponent <TileScript>().position) + 1.0f;
                    }
                }
                //num = field.tiles[x, y].GetComponent<TileScript>().position.x * field.tiles[x, y].GetComponent<TileScript>().position.y;
                field.tiles[y, x].GetComponent <TileScript>().threat = num / 5.0f;
            }
        }

        for (int i = 0; i < playerUnits.Count; i++)
        {
            playerUnits[i].threat = playerUnits[i].value * Mathf.Pow((7 - playerUnits[i].position.y), 2);
            float dist = 0;
            for (int j = 0; j < ownUnits.Count; j++)
            {
                dist = Mathf.Pow(10 - Vector2.Distance(playerUnits[i].position, ownUnits[j].position), 1.15f);
                playerUnits[i].threat -= dist; //plus ownUnits[j].value modified by some value
            }

            /*
             * if (playerUnits[i].threat > targetThreat) {
             *  target = playerUnits[i];
             *  targetThreat = target.threat;
             * }
             */
        }

        List <Unit> rtn = CardSort.QuickSort(playerUnits.ConvertAll(x => (Card)x), 0, playerUnits.Count - 1).ConvertAll(x => (Unit)x);

        return(rtn);
    }
コード例 #3
0
ファイル: Cards.cs プロジェクト: Gonkers/Scryfall-API-Client
 public Task <ResultList <Card> > Search(string query, int page, CardSort sort) =>
 Search(query, page, new SearchOptions {
     Sort = sort
 });
コード例 #4
0
ファイル: Cards.cs プロジェクト: euronay/Scryfall-API-Client
 public async Task <ResultList <Card> > Search(string query, int page, CardSort sort) => await GetAsync <ResultList <Card> >($"/cards/search?q={query}&page={page}&sort={sort}");
コード例 #5
0
    private static async Task <ScryfallApi.Client.Models.Card> GetCard(CardEntry card, ScryfallApiClient client, CardSort sort)
    {
        if (card.ScryfallId != null)
        {
            try {
                return(await client.Cards.GetById(card.ScryfallId));
            }
            catch (Exception) {
                Console.Error.WriteLine("Could not get data by id, trying by name instead...");
            }
        }

        var results = (await client.Cards.Search(card.Name, 0, sort)).Data;

        return(results.FirstOrDefault(x => x.Name == card.Name) ?? results.First());
    }