Class Market

All Implemented Interfaces:
Killer, Cloneable, Iterable<String>, Serializable

public class Market extends PassiveEntity
A Market handles sales offers of players. Players can place offers or accept offers to buy a desired item. Offers last only for a certain amount of time before they expire and can be prolonged. Expired Offers get removed permanently from the market after another period of time. When an offer has been accepted, the offering Player can come and fetch his earnings for that sale.
Author:
madmetzger, kiheru
  • Field Details

    • MARKET_RPCLASS_NAME

      public static final String MARKET_RPCLASS_NAME
      the RPClass name for the market
      See Also:
      Constant Field Values
    • EARNINGS_SLOT_NAME

      public static final String EARNINGS_SLOT_NAME
      the name of the slot where the earnings are stored
      See Also:
      Constant Field Values
    • OFFERS_SLOT_NAME

      public static final String OFFERS_SLOT_NAME
      the name of the slot where the offers are stored
      See Also:
      Constant Field Values
    • EXPIRED_OFFERS_SLOT_NAME

      public static final String EXPIRED_OFFERS_SLOT_NAME
      the name of the slot where the expired offers are stored
      See Also:
      Constant Field Values
  • Constructor Details

    • Market

      public Market(RPObject object)
      Creates a new Market from an RPObject
      Parameters:
      object -
  • Method Details

    • generateRPClass

      public static void generateRPClass()
      Generate the RPClass for the Market
    • createShop

      public static Market createShop()
      Factory method for the market
      Returns:
      a new Market
    • createOffer

      public Offer createOffer(Player offerer, Item item, Integer money, Integer number)
      creates a new offer at the market
      Parameters:
      offerer - offering player
      item - item to sell
      money - price for the item
      number - number of items to sell
      Returns:
      the new created offer
    • acceptOffer

      public boolean acceptOffer(Offer offer, Player acceptingPlayer)
      Completes a trade of an offer by transferring item to accepting player and taking the money from him
      Parameters:
      offer -
      acceptingPlayer -
      Returns:
      true if the trade was done, false on failure
    • fetchEarnings

      public Set<Earning> fetchEarnings(Player earner)
      The earnings for complete trades are paid to the player.
      Parameters:
      earner - the player fetching his earnings
      Returns:
      the fetched earnings
    • removeEarnings

      public void removeEarnings(Iterable<Earning> earningsToRemove)
      Remove a set of earnings.
      Parameters:
      earningsToRemove - The earnings to be removed
    • countOffersOfPlayer

      public int countOffersOfPlayer(Player offerer)
      counts the number of offers, a player has placed
      Parameters:
      offerer -
      Returns:
      the number of offers
    • removeOffer

      public void removeOffer(Offer o, Player p)
      removes an offer from the market and returns the item to the user
      Parameters:
      o - the offer to remove
      p - the removing player
    • expireOffer

      public void expireOffer(Offer o)
      expires an offer and removes it from the available offers
      Parameters:
      o - the offer to expire
    • getExpiredOffers

      public List<Offer> getExpiredOffers()
      Returns:
      all currently expired offers in the market
    • removeExpiredOffer

      public void removeExpiredOffer(Offer offerToRemove)
      removes an expired offer permanently from the market
      Parameters:
      offerToRemove -
    • prolongOffer

      public Offer prolongOffer(Offer offer)
      prolongs an offer in the market to make it available again
      Parameters:
      offer - the offer to prolong
      Returns:
      the prolonged offer
    • getOffersOlderThan

      public List<Offer> getOffersOlderThan(int seconds)
      Get a list of offers whose timestamp is older than specified.
      Parameters:
      seconds - age of offers in seconds
      Returns:
      list of offers that are older than the specified time
    • getExpiredOffersOlderThan

      public List<Offer> getExpiredOffersOlderThan(int seconds)
      Get a list of expired offers whose timestamp is older than specified.
      Parameters:
      seconds - age of offers in seconds
      Returns:
      list of expired offers that are older than the specified time
    • getEarningsOlderThan

      public List<Earning> getEarningsOlderThan(int seconds)
      Get a list of earnings whose timestamp is older than specified.
      Parameters:
      seconds - age of offers in seconds
      Returns:
      list of earnings that are older than the specified time
    • contains

      public boolean contains(Offer o)
      Parameters:
      o -
      Returns:
      true iff the Offer o is in this market's offers
    • hasEarningsFor

      public boolean hasEarningsFor(Player player)
      Parameters:
      player -
      Returns:
      true iff there are earnings for this player in the market