Class FMDB

java.lang.Object
moe.maika.ygofm.gamedata.FMDB

public class FMDB extends Object
The entry point for querying FM game data. This class is a singleton and should be accessed via the getInstance() method.

Use this class to instantiate Card and Duelist objects.

This class is thread-safe. All classes in this library are thread-safe unless otherwise noted, even if they do not explicitly state they are thread-safe.
  • Field Details

  • Method Details

    • getCard

      public Card getCard(int id)
      Gets a card by its id.
      Parameters:
      id - a card id
      Returns:
      the card with the given id, or null if no such card exists
    • getAllCards

      public Set<Card> getAllCards()
      Gets all FM cards.
      Returns:
      all cards in the game
    • getDuelist

      public Duelist getDuelist(Duelist.Name name)
      Gets a duelist by name.
      Parameters:
      name - a duelist name
      Returns:
      the duelist with the given name, never null
      Throws:
      IllegalArgumentException - if name is null
    • getDuelist

      public Duelist getDuelist(int id)
      Gets a duelist by id. Consider using getDuelist(Duelist.Name) instead.
      Parameters:
      id - the id of a duelist as specified by the FM database
      Returns:
      the duelist with the given id, or null if no such duelist exists
    • getAllDuelists

      public Set<Duelist> getAllDuelists()
      Gets all FM duelists.
      Returns:
      all duelists in the game
    • fuse

      public Card fuse(Card firstCard, Card secondCard)
      Performs a fusion or returns the second card if no fusion is possible. This behavior mirrors the in-game mechanic when selecting two cards to fuse.
      Parameters:
      firstCard - the first card of the fusion
      secondCard - the second card of the fusion
      Returns:
      the result of fusing the two cards, or the second card if no fusion is possible, never null
      Throws:
      IllegalArgumentException - if either card is null
    • fuseOrNull

      public Card fuseOrNull(Card firstCard, Card secondCard)
      Performs a fusion or returns null if no fusion is possible.
      Parameters:
      firstCard - the first card of the fusion
      secondCard - the second card of the fusion
      Returns:
      the result of fusing the two cards, or null if no fusion is possible
    • isEquippable

      public boolean isEquippable(Card monster, Card equip)
      Determines whether a monster can be equipped with an equip card. Consider using Card.equips(Card) or Card.canBeEquippedWith(Card) instead to avoid parameter-ordering errors.
      Parameters:
      monster - the monster to equip
      equip - the equip card
      Returns:
      true if the monster can be equipped with the equip
      Throws:
      IllegalArgumentException - the first card is not a monster card, or the second card is not an equip card, or either card is null
    • getRitual

      public Ritual getRitual(int ritualCardId)
      Returns the Ritual that is activated by the given ritual card id.
      Parameters:
      ritualCardId - the id of the ritual card
      Returns:
      the ritual, or null if ritualCardId is not a ritual card id
    • getRitual

      public Ritual getRitual(Card ritualCard)
      Returns the Ritual that is activated by the given ritual card.
      Parameters:
      ritualCard - the ritual card
      Returns:
      the ritual, or null if ritualCard is not a ritual card
      Throws:
      IllegalArgumentException - if ritualCard is null
    • getAllRituals

      public Set<Ritual> getAllRituals()
      Returns all rituals in the game.
      Returns:
      all rituals in the game
    • getInstance

      public static FMDB getInstance()
      Gets the singleton instance of FMDB. If the database has not been loaded yet, this method will load it.

      This method can safely be called from any thread; initialization is synchronized and will only occur once. Access after initialization does not incur any synchronization overhead since the double-checked locking optimization idiom is used internally.

      Returns:
      the singleton instance of FMDB