public static List <YGOPROCard> query_ygopro_ids_from_names(List <string> card_names, String ygopro_path) { List <YGOPROCard> cards = new List <YGOPROCard>(); List <int> ids = new List <int>(); try { using (SQLiteConnection connect = new SQLiteConnection("Data Source=" + ygopro_path)) { connect.Open(); foreach (string name in card_names) { String new_name = name.Replace("'", "''"); using (SQLiteCommand fmd = connect.CreateCommand()) { fmd.CommandText = "SELECT id from texts where name is '" + new_name + "'"; fmd.CommandType = CommandType.Text; SQLiteDataReader r = fmd.ExecuteReader(); try { if (r.Read()) { int a = r.GetInt32(0); ids.Add(a); } else { fmd.CommandText = "SELECT id from texts where name like '%" + new_name + "%'"; fmd.CommandType = CommandType.Text; r = fmd.ExecuteReader(); if (r.Read()) { int a = r.GetInt32(0); //ids.Add(a); ids.Add(a); } } } catch { } } } } } catch { } for (int idx = 0; idx < ids.Count; idx++) { int id = ids[idx]; YGOPROCard card = QueryFromID(id, ygopro_path); cards.Add(card); } return(cards); }
public static YGOPROCard getFromIDAndSetRarity(String rarity, int id, string card_cdb_path) { YGOPROCard card; card = YGOPROCard.QueryFromID(id, card_cdb_path); card.m_rarity = rarity; return(card); }
private YGOPROCard getFromIDAndSetRarity(String rarity, int id) { YGOPROCard card; card = YGOPROCard.QueryFromID(id, ygopro_db_path); card.m_rarity = rarity; return(card); }
public void getDraftCardsFromIds() { lock (card_modify_mutex) { foreach (int id in m_ygopro_ids) { draft_cards.Add(YGOPROCard.QueryFromID(id, ygopro_db_path)); } } }
private void ConfigurePackBtn_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Choose .ydk (YGOPRO Deck) File to convert!"; ofd.ShowDialog(); SaveFileDialog sfd = new SaveFileDialog(); sfd.RestoreDirectory = true; sfd.InitialDirectory = ygopro_db_path; sfd.Title = "Save your resulting pack file!"; sfd.ShowDialog(); List <String> lines = new List <string>(); lines.AddRange(File.ReadAllLines(ofd.FileName)); List <YGOJSONStruct> output_json = new List <YGOJSONStruct>(); String rarity = "Common"; foreach (String line in lines) { String card = line.TrimEnd(new char[] { '\n', '\r', '\t', ' ' }); YGOPROCard card_obj = null; if (line.Contains("!side")) { rarity = "Rare"; continue; } else if (line.Contains("#")) { continue; } else { int id = Int32.Parse(card); card_obj = getFromIDAndSetRarity(rarity, id); } YGOJSONStruct output_json_struct = new YGOJSONStruct(); output_json_struct.name = card_obj.m_card_name; output_json_struct.rarity = card_obj.m_rarity; output_json_struct.set_number = "Created-From-YDK-To-JSON"; output_json.Add(output_json_struct); } String json = JsonConvert.SerializeObject(output_json, Formatting.Indented); File.WriteAllText(sfd.FileName, json); }
/// <summary> /// Parses a deck list containing main/extra/side decks from a YGOPRO file. Uses YGOPRO cards.cdb with SQLITE to lookup card data. /// Uses cards_not_available_filename to prevent cards which do not exist in LOTD from being added /// </summary> /// <param name="fileName">YGOPRO deck filename</param> /// <param name="card_db_filename">cards.db location/filename</param> /// <param name="cards_not_available_filename">location of cards_not_available.txt</param> /// <returns>List of main/extra/side decks as YGOPROCard</returns> private static List <List <YGOPROCard> > parseCardListMainExtraSideFromYDKFile(string fileName, string card_db_filename, string cards_not_available_filename) { List <YGOPROCard> cards = new List <YGOPROCard>(); List <List <YGOPROCard> > decks = new List <List <YGOPROCard> >(); decks.Add(new List <YGOPROCard>()); decks.Add(new List <YGOPROCard>()); decks.Add(new List <YGOPROCard>()); int deck_idx = 0; try { List <String> lines = new List <string>(); lines.AddRange(File.ReadAllLines(fileName)); String rarity = "Common"; foreach (String line in lines) { String card = line.TrimEnd(new char[] { '\n', '\r', '\t', ' ' }); YGOPROCard card_obj = null; if (line.Contains("!side") || line.Contains("#extra")) { deck_idx++; continue; } else if (line.Contains("#")) { //Comment continue; } else { int id = Int32.Parse(card); card_obj = YGOPROCard.getFromIDAndSetRarity(rarity, id, card_db_filename); decks[deck_idx].Add(card_obj); } } } catch (Exception ex) { //I don't care about anything } var card_names_not_available = File.ReadAllLines(cards_not_available_filename); decks[0].RemoveAll(card => card_names_not_available.Contains(card.m_card_name)); decks[1].RemoveAll(card => card_names_not_available.Contains(card.m_card_name)); decks[2].RemoveAll(card => card_names_not_available.Contains(card.m_card_name)); return(decks); }
void switchCardToSide(int x, int y, bool main) { lock (card_modify_mutex) { YGOPROCard chosen_card = null; if (main) { foreach (YGOPROCard card in main_deck) { if (card.isInRect(x, y)) { chosen_card = card; break; } } } else { foreach (YGOPROCard card in extra_deck) { if (card.isInRect(x, y)) { chosen_card = card; break; } } } if (chosen_card == null) { return; } chosen_card.m_drawing_rect = new Rectangle(); if (main) { main_deck.Remove(chosen_card); side_deck.Add(chosen_card); renderDraftCards(null, panelMainDeck, main_deck, -1, -1); renderDraftCards(chosen_card, panelSideDeck, side_deck, -1, -1); } else { extra_deck.Remove(chosen_card); side_deck.Add(chosen_card); renderDraftCards(null, panelMainDeck, main_deck, -1, -1); renderDraftCards(chosen_card, panelSideDeck, side_deck, -1, -1); } } }
/// <summary> /// Converts a YDC/LOTD binary deck file to lists (main/extra/side) of YGOPROCards /// </summary> /// <param name="ydc_binary">all bytes containing the ydc binary</param> /// <param name="LOTD_ID_to_card_name">dictionary mapping from LOTD ID to card name</param> /// <param name="card_db_filename">cards.cdb file location (from YGOPRO to look up card data)</param> /// <returns></returns> public static List <List <YGOPROCard> > YDCToYGOPRODeck(byte[] ydc_binary, Dictionary <string, string> LOTD_ID_to_card_name, string card_db_filename) { List <List <YGOPROCard> > cards = new List <List <YGOPROCard> >(); //cards.Add(new List<YGOPROCard>()); //cards.Add(new List<YGOPROCard>()); //cards.Add(new List<YGOPROCard>()); List <string> card_names = new List <string>(); using (var MemReader = new MemoryStream(ydc_binary)) { using (var Reader = new BinaryReader(MemReader)) { //Read LOTD IDs from ydc_binary //Read Header Reader.ReadInt64(); //Iterate over main/extra/side for (int deck_index = 0; deck_index < 3; deck_index++) { int num_main_cards = Reader.ReadInt16(); for (int i = 0; i < num_main_cards; i++) { try { //cards[deck_index].Add() card_names.Add(LOTD_ID_to_card_name[Reader.ReadInt16().ToString()]); } catch (Exception ex) { } } cards.Add(YGOPROCard.query_ygopro_ids_from_names(card_names, card_db_filename)); } } } return(cards); }
public void UpdateCardDetailedInfo(YGOPROCard my_card) { if (my_card == null) { return; } if (InvokeRequired) { this.BeginInvoke(new Action <YGOPROCard>(UpdateCardDetailedInfo), new object[] { my_card }); return; } cardShowPanel.BackgroundImage = my_card.m_card_image; //cardShowPanel.Size = my_card.m_card_image.Size; cardShowPanel.Refresh(); labelCardAtk.Text = "ATK: " + my_card.m_card_atk; labelCardAttr.Text = "Attibute: " + my_card.m_card_attr; labelCardDef.Text = "DEF: " + my_card.m_card_def; labelCardDescription.Text = my_card.m_card_desc; labelCardLevel.Text = "Level " + my_card.m_card_level; labelCardName.Text = my_card.m_card_name; labelCardRace.Text = my_card.m_card_race; labelCardType.Text = my_card.m_card_type; }
public static YGOPROCard QueryFromID(int id, String ygopro_path) { YGOPROCard ret_card = new YGOPROCard(); ret_card.m_ygopro_id = id; try { using (SQLiteConnection connect = new SQLiteConnection("Data Source=" + ygopro_path)) { connect.Open(); using (SQLiteCommand fmd = connect.CreateCommand()) { fmd.CommandText = "SELECT name, desc from texts where id = " + id; fmd.CommandType = CommandType.Text; SQLiteDataReader r = fmd.ExecuteReader(); try { if (r.Read()) { ret_card.m_card_name = r.GetString(0); ret_card.m_card_desc = r.GetString(1); } } catch { } } using (SQLiteCommand fmd = connect.CreateCommand()) { fmd.CommandText = "SELECT type, atk, def, level, race, attribute from datas where id = " + id; fmd.CommandType = CommandType.Text; SQLiteDataReader r = fmd.ExecuteReader(); try { if (r.Read()) { if (CARD_TYPE_MAP.ContainsKey(r.GetInt32(0))) { ret_card.m_card_type = CARD_TYPE_MAP[r.GetInt32(0)]; } else { ret_card.m_card_type = "UNKNOWN"; } ret_card.m_card_atk = r.GetInt32(1); ret_card.m_card_def = r.GetInt32(2); ret_card.m_card_level = r.GetInt32(3); int test = r.GetInt32(0); ret_card.m_card_extra = (r.GetInt32(0) & YGOPROCard.ygoproIsExtraDeck) > 1; if (CARD_RACE_MAP.ContainsKey(r.GetInt32(4))) { ret_card.m_card_race = CARD_RACE_MAP[r.GetInt32(4)]; } else { ret_card.m_card_race = "UNKNOWN"; } if (CARD_ATTR_MAP.ContainsKey(r.GetInt32(5))) { ret_card.m_card_attr = CARD_ATTR_MAP[r.GetInt32(5)]; } else { ret_card.m_card_attr = "UNKNOWN"; } } } catch { } } } } catch { } //get img from ygopro path //String trimmed = ygopro_path.TrimEnd("cards.cdb".ToCharArray()); //ret_card.m_card_image = Image.FromFile(trimmed +"\\pics\\" + id.ToString() + ".jpg"); return(ret_card); }
/// <summary> /// Reads a pack .json file, returning a list of YGOPROCard /// </summary> /// <param name="JSONFileName">file location of the .json file</param> /// <returns></returns> public static List <YGOPROCard> cardsFromJSON(string JSONFileName, string card_db_filename, bool use_rarity_simulation) { String json = System.IO.File.ReadAllText(JSONFileName); //TODO: read JSON List <YGOJSONStruct> json_list = JsonConvert.DeserializeObject <List <YGOJSONStruct> >(json); List <string> card_names = new List <string>(); foreach (YGOJSONStruct json_struct in json_list) { card_names.Add(json_struct.name); } List <YGOPROCard> cards = YGOPROCard.query_ygopro_ids(json_list, card_db_filename); if (use_rarity_simulation) { List <YGOPROCard> rarity_adjusted_cards = new List <YGOPROCard>(); foreach (YGOPROCard card_obj in cards) { if (card_obj.m_rarity.ToLower().Contains("common")) { rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); } else if (card_obj.m_rarity.ToLower().Contains("secret rare")) { rarity_adjusted_cards.Add(card_obj); } else if (card_obj.m_rarity.ToLower().Contains("ultra rare")) { rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); } else if (card_obj.m_rarity.ToLower().Contains("super rare")) { rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); } else if (card_obj.m_rarity.ToLower().Contains("rare")) { rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); rarity_adjusted_cards.Add(card_obj); } else { rarity_adjusted_cards.Add(card_obj); } } return(rarity_adjusted_cards); } return(cards); }
// Bitmap draftPanelBuffer = null; public void renderDraftCards(YGOPROCard focused_card, Panel draw_panel, List <YGOPROCard> cards, int xMouse, int yMouse) { if (cards == null) { return; } if (panelDraftCards.InvokeRequired) { this.BeginInvoke(new Action <YGOPROCard, Panel, List <YGOPROCard>, int, int>(renderDraftCards), new object[] { focused_card, draw_panel, cards, xMouse, yMouse }); return; } //if (cards.Count == 0) // return; lock (card_modify_mutex) { int width = draw_panel.Width; int height = draw_panel.Height; // if (draftPanelBuffer == null) Bitmap draftPanelBuffer = new Bitmap(width, height); int spacing = small_card_spacing; int card_width = 40; int card_height = small_card_height; int num_per_row = width / (card_width + spacing); Graphics gr = Graphics.FromImage(draftPanelBuffer); int x = spacing; int y = 0; int max_y = cards.Count / num_per_row * (card_height + spacing) + card_height; //calc y offset if (scroll_val_map[draw_panel] != SIGNATURE_SCROLL_VAL) { if (scroll_val_map[draw_panel] < 0) { //cards scrolling up, neg delta y += scroll_val_map[draw_panel]; if (max_y < height) { y = spacing; scroll_val_map[draw_panel] = 0; } else if (y < height - max_y) { y = height - max_y; scroll_val_map[draw_panel] = height - max_y; } // scroll_val_map[draw_panel] = SIGNATURE_SCROLL_VAL; } else if (scroll_val_map[draw_panel] > 0) { //cards scrolling down. -> pos delta y += scroll_val_map[draw_panel]; if (max_y < height) { y = spacing; scroll_val_map[draw_panel] = 0; } else if (y > spacing) { y = spacing; scroll_val_map[draw_panel] = y; } // scroll_val_map[draw_panel] = SIGNATURE_SCROLL_VAL; } else { y = spacing; } } gr.Clear(Color.DarkGray); foreach (YGOPROCard card in cards) { if (card.isInRect(xMouse, yMouse)) { focused_card = card; } if (card != focused_card) { card.m_drawing_rect = new Rectangle(x, y, card_width, card_height); gr.DrawImage(card.m_card_image, card.m_drawing_rect); } else { card.m_drawing_rect = new Rectangle(x - spacing / 2, y - spacing / 2, card_width + spacing, card_height + spacing); gr.DrawImage(card.m_card_image, card.m_drawing_rect); } x += card_width + spacing; if (x + card_width > width) { x = spacing; y += card_height + spacing; } } draw_panel.BackgroundImage = draftPanelBuffer; draw_panel.Invalidate(); gr.Dispose(); } UpdateCardDetailedInfo(focused_card); }
void selectCardForDeck(int x, int y, bool left_mouse_button) { lock (card_modify_mutex) { YGOPROCard chosen_card = null; foreach (YGOPROCard card in draft_cards) { if (card.isInRect(x, y)) { chosen_card = card; break; } } if (chosen_card == null) { return; } chosen_card.m_drawing_rect = new Rectangle(); if (!left_mouse_button) { side_deck.Add(chosen_card); renderDraftCards(chosen_card, panelSideDeck, side_deck, -1, -1); } else { if (chosen_card.m_card_extra) { extra_deck.Add(chosen_card); renderDraftCards(chosen_card, panelExtraDeck, extra_deck, -1, -1); } else { main_deck.Add(chosen_card); renderDraftCards(chosen_card, panelMainDeck, main_deck, -1, -1); } } draft_cards.Remove(chosen_card); if ((chosen_card.m_raw_type & 0x01) != 0) { //monster monsters++; } else if ((chosen_card.m_raw_type & 0x02) != 0) { spells++; } else if ((chosen_card.m_raw_type & 0x04) != 0) { traps++; } updateCardCountLabel(); m_ygopro_ids.Remove(chosen_card.m_ygopro_id); // m_ygopro_ids.Remove(chosen_card.) sendCardIds("CONTINUEDRAFT"); draft_cards.Clear(); m_ygopro_ids.Clear(); } }