package com.lucasdnd.ags.gameplay; import java.util.ArrayList; import java.util.Random; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; import org.newdawn.slick.Sound; import org.newdawn.slick.state.StateBasedGame; import com.lucasdnd.ags.gameplay.market.Market; import com.lucasdnd.ags.gameplay.market.MarketAsset; import com.lucasdnd.ags.gameplay.market.MarketGame; import com.lucasdnd.ags.system.Camera; import com.lucasdnd.ags.system.GameSystem; import com.lucasdnd.ags.system.MainState; import com.lucasdnd.ags.system.ResourceLoader; import com.lucasdnd.ags.ui.ViewGamesList; /** * Controls the whole business of the Player. This is the main gameplay class, holding all the player info. * @author tulio * */ public class Business { // Sounds private Sound coinSound; private Sound cashRegisterSound; // Money private int money; // Current amount of money the player has. Since it is an integer, 1 = 1 cent. 100 = $1. private boolean needsToPayTheBills; // Indicates if it's time for the player to pay the bills this month // Tile prices private int tilePrice; // Tracks the total amount of money spent and earned. // Each item in these Lists sum the values in a month. Every new month, a new item is added to them. The current // working index is given by the length of the List - 1. private ArrayList<Integer> buyingGamesCosts, buyingConsolesCosts, buyingAssetsCosts, buyingMapCosts, billsCosts, researchCosts, movingCosts; private ArrayList<Integer> salesReceipt, rentReceipt, playsReceipt, disposalReceipt; /** * Calculated based on: * * 1. Number of games in collection * 2. Number of consoles * 3. TV ratings * 4. Store size * * This rating will provide an steady generation of customers over time. */ private int businessRating; // Activity category public static final int BUYING_GAME = 0; public static final int BUYING_CONSOLE = 1; public static final int BUYING_ASSET = 2; public static final int PAYING_BILLS = 3; public static final int BUYING_MAP = 4; public static final int SELLING_GAME = 5; public static final int RENTING_GAME = 6; public static final int PLAYING_GAME = 7; public static final int DISPOSING = 8; public static final int EMPTY = 9; // Empty space public static final int TOTAL = 10; // The Store private Store store; // Should update the UI? // The Business class is a common messenger for several objects. It can exchange information between them private boolean updateGamesList; /** * Starts the Business. Call this in the Main State when starting a new game * @throws SlickException */ public Business(GameSystem game) throws SlickException { // Set basic attributes needsToPayTheBills = false; // Difficulty settings System.out.println("difficulty: " + game.getDifficulty()); if (game.getDifficulty() == GameSystem.Difficulty.EASY) { money = 200000; tilePrice = 10000; } else if (game.getDifficulty() == GameSystem.Difficulty.MEDIUM) { money = 150000; tilePrice = 15000; } else { // game.getDifficulty() == GameSystem.Difficulty.HARD money = 100000; tilePrice = 20000; } // Get the sounds coinSound = ResourceLoader.getInstance().coinSound; cashRegisterSound = ResourceLoader.getInstance().cashRegisterSound; buyingGamesCosts = new ArrayList<Integer>(); buyingConsolesCosts = new ArrayList<Integer>(); buyingAssetsCosts = new ArrayList<Integer>(); buyingMapCosts = new ArrayList<Integer>(); billsCosts = new ArrayList<Integer>(); researchCosts = new ArrayList<Integer>(); movingCosts = new ArrayList<Integer>(); salesReceipt = new ArrayList<Integer>(); rentReceipt = new ArrayList<Integer>(); playsReceipt = new ArrayList<Integer>(); disposalReceipt = new ArrayList<Integer>(); // Add 6 empty months so the Finances screen shows up ok (last one is the current month) for(int i = 0; i < 9; i++) { this.startNewMonthCounts(); } } /** * Controls the Business */ public void update(GameContainer container, StateBasedGame game, int delta, Input input, boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY, int currentMode, Asset placingAsset, Camera camera, MainState mainState, boolean isShiftDown, ViewGamesList viewGamesList, int simulationSpeed, Market market, int month) throws SlickException { // Updates the Store store.update(container, game, delta, input, leftMouseClicked, leftMouseDown, mouseX, mouseY, currentMode, this, placingAsset, camera, mainState, isShiftDown, viewGamesList, simulationSpeed, market, month); } /** * Monthly update (finances) */ public void monthUpdate(GameSystem game) { // Total expenses int billsCosts = calculateBills(game); // Pay! makeBusiness( - billsCosts, PAYING_BILLS, false); this.startNewMonthCounts(); } /** * Starts a new month in the money count stuff */ private void startNewMonthCounts() { buyingGamesCosts.add(0); buyingConsolesCosts.add(0); buyingAssetsCosts.add(0); buyingMapCosts.add(0); billsCosts.add(0); researchCosts.add(0); movingCosts.add(0); salesReceipt.add(0); rentReceipt.add(0); playsReceipt.add(0); disposalReceipt.add(0); } private int calculateBills(GameSystem game) { // Store running costs: each tile costs $1.50 int utilities = store.getMap().getAmountOfPlayableTiles() * 150; // Console running costs: each costs $5 int consoleCosts = store.getConsoles().size() * 500; // Random modifier, ranging from $0 to $5 int randomModifier = new Random().nextInt(500) + 1; // Difficulty modifier float difficultyModifier = 1f; switch (game.getDifficulty()) { case GameSystem.Difficulty.EASY: difficultyModifier = 1f; break; case GameSystem.Difficulty.MEDIUM: difficultyModifier = 1.33f; break; case GameSystem.Difficulty.HARD: difficultyModifier = 2f; break; default: difficultyModifier = 1f; } // Total return (int)((utilities + consoleCosts + randomModifier) * difficultyModifier); } /** * This is called when the player tries to buy a Game for his store * @param marketGame * @param currentStoreId */ public void buyGame(MarketGame marketGame) { // First, we check if the player has money if(money >= marketGame.getPrice()) { // Then, we check if he has storage space if(store.getGameStorageLimit() > store.getGames().size()) { this.makeBusiness( - marketGame.getPrice(), BUYING_GAME, true); store.getGames().add(new Game(marketGame)); // ...add the game to his inventory... marketGame.setUnlocked(true); // ...and unlock its rating! } } } /** * Player is disposing a game * @param game */ public void removeGame(Game game) { store.getGames().remove(game); } /** * Buying an Asset * @param marketAsset */ public boolean buyAsset(MarketAsset marketAsset) { // First, we check if the player has money if(money >= marketAsset.getPrice()) { this.makeBusiness( - marketAsset.getPrice(), BUYING_ASSET, true); return true; } return false; } /** * Makes money * @param profit */ public void makeBusiness(int value, int category, boolean playSound) { this.money += value; if(playSound) { if(value < 0) { cashRegisterSound.play(); } else { coinSound.play(); } } // Add it to the right category switch(category) { case BUYING_GAME: buyingGamesCosts.set(buyingGamesCosts.size() - 1, buyingGamesCosts.get(buyingGamesCosts.size() - 1) + value); break; case BUYING_CONSOLE: buyingConsolesCosts.set(buyingConsolesCosts.size() - 1, buyingConsolesCosts.get(buyingConsolesCosts.size() - 1) + value); break; case BUYING_ASSET: buyingAssetsCosts.set(buyingAssetsCosts.size() - 1, buyingAssetsCosts.get(buyingAssetsCosts.size() - 1) + value); break; case BUYING_MAP: buyingMapCosts.set(buyingMapCosts.size() - 1, buyingMapCosts.get(buyingMapCosts.size() - 1) + value); break; case PAYING_BILLS: billsCosts.set(billsCosts.size() - 1, billsCosts.get(billsCosts.size() - 1) + value); break; case SELLING_GAME: salesReceipt.set(salesReceipt.size() - 1, salesReceipt.get(salesReceipt.size() - 1) + value); break; case RENTING_GAME: rentReceipt.set(rentReceipt.size() - 1, rentReceipt.get(rentReceipt.size() - 1) + value); break; case PLAYING_GAME: playsReceipt.set(playsReceipt.size() - 1, playsReceipt.get(playsReceipt.size() - 1) + value); break; case DISPOSING: disposalReceipt.set(disposalReceipt.size() - 1, disposalReceipt.get(disposalReceipt.size() - 1) + value); break; default: break; } } public int getMoney() { return money; } public boolean isNeedsToPayTheBills() { return needsToPayTheBills; } public void setNeedsToPayTheBills(boolean needsToPayTheBills) { this.needsToPayTheBills = needsToPayTheBills; } public Store getStore() { return store; } public void setStore(Store store) { this.store = store; } public boolean shouldUpdateGamesList() { return updateGamesList; } public void setUpdateGamesList(boolean updateGamesList) { this.updateGamesList = updateGamesList; } public ArrayList<Integer> getBuyingGamesCosts() { return buyingGamesCosts; } public ArrayList<Integer> getBuyingConsolesCosts() { return buyingConsolesCosts; } public ArrayList<Integer> getBuyingAssetsCosts() { return buyingAssetsCosts; } public ArrayList<Integer> getBillsCosts() { return billsCosts; } public ArrayList<Integer> getResearchCosts() { return researchCosts; } public ArrayList<Integer> getMovingCosts() { return movingCosts; } public ArrayList<Integer> getSalesReceipt() { return salesReceipt; } public ArrayList<Integer> getRentReceipt() { return rentReceipt; } public ArrayList<Integer> getPlaysReceipt() { return playsReceipt; } public ArrayList<Integer> getDisposalReceipt() { return disposalReceipt; } public ArrayList<Integer> getBuyingMapCosts() { return buyingMapCosts; } public int getTilePrice() { return tilePrice; } public int getBusinessRating() { return businessRating; } public void setBusinessRating(int businessRating) { this.businessRating = businessRating; } }