It is currently 09 Sep 2025, 17:53
   
Text Size

Fixed - Quest Import

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Fixed - Quest Import

Postby mtgrares » 22 Apr 2010, 19:11

This code fixes the problem when trying to import a deck into a quest. Technically it would import the deck and then throw an exception when you tried to edit the deck. This code solves that problem because the cards are added player's cardpool by QuestData.addCard().

On a side now, the quest objects are really messy. I didn't realize that I was writing spaghetti code. This "small" change probably took me two hours.

AND you can delete the code for "Cheat - Add Card". I actually got that code working but since Forge has so many cards just looking at the cards in a dialog box was painful, so that is why I fixed quest's import.

One more note, I have no real idea what quest's export does and it probably doesn't really work. It is the same code as the regular export. (I envisioned people uploading their draft picks or sealed cardpool and asking for help but it isn't that hard to beat the AI.)

Thanks to Dennis or whoever makes these changes for me. :D

Changes:
1. Add method to QuestData.
2. Overwrite Gui_Quest_DeckEditor_Menu.importDeck() with the code below.

QuestData - add this method

public void addCard(String cardName)
{
cardPool.add(cardName);
}

---------------------------------------
Explanation:
These are the 2 new lines. I also added brackets around the for loop.

if(isHumanDeck)
questData.addCard(deck.getMain(i));

And technically I added final, importDeck(final boolean isHumanDeck).
(Adding final doesn't really change anything, I just don't want to accidentally change it.)

Code: Select all
  private void importDeck(final boolean isHumanDeck)
  {
    File file = getImportFilename();

    if(file == null)
      return;

    Object check = null;

    try{
      ObjectInputStream in = new ObjectInputStream(
                             new FileInputStream(file));
      check = in.readObject();

      in.close();
    }
    catch(Exception ex)
    {
      JOptionPane.showMessageDialog(null, "Sorry there has been an error - " +ex.getMessage());

      throw new RuntimeException("Gui_Quest_DeckEditor_Menu : importDeck() error, " +ex);
    }

    Deck deck = (Deck) check;
    deckDisplay.setTitle(deckEditorName +" - " +deck.getName());

    CardList cardpool;

    if(isHumanDeck)
    {
      questData.addDeck(deck);

      //convert ArrayList of card names (Strings), into Card objects
      cardpool = new CardList();
      ArrayList list = questData.getCardpool();

      for(int i = 0; i < list.size(); i++)
        cardpool.add(AllZone.CardFactory.getCard(list.get(i).toString(), ""));
    }
    else
    {
      questData.ai_addDeck(deck);
      cardpool = AllZone.CardFactory.getAllCards();
    }

    //convert Deck main to CardList
    CardList deckList = new CardList();
    for(int i = 0; i < deck.countMain(); i++)
    {
      deckList.add(AllZone.CardFactory.getCard(deck.getMain(i), ""));

      //add card to player's card pool
      //this has to be done otherwise there is an error
      //"This card isn't in CardList"
      if(isHumanDeck)
        questData.addCard(deck.getMain(i));
    }

    //update gui
    deckDisplay.updateDisplay(cardpool, deckList);

  }//importDeck()
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Re: Fixed - Quest Import

Postby DennisBergkamp » 22 Apr 2010, 20:06

Cool! I'll make this fix for the next release :)
User avatar
DennisBergkamp
AI Programmer
 
Posts: 2602
Joined: 09 Sep 2008, 15:46
Has thanked: 0 time
Been thanked: 0 time

Re: Fixed - Quest Import

Postby mtgrares » 23 Apr 2010, 16:19

Thanks. :wink:
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 53 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 53 users online :: 0 registered, 0 hidden and 53 guests (based on users active over the past 10 minutes)
Most users ever online was 7303 on 15 Jul 2025, 20:46

Users browsing this forum: No registered users and 53 guests

Login Form