Package ch.sahits.game.graphic.display.dialog

Source Code of ch.sahits.game.graphic.display.dialog.Ship2CityAction

package ch.sahits.game.graphic.display.dialog;

import ch.sahits.game.graphic.display.model.ICityPlayerProxy;
import ch.sahits.game.openpatrician.model.product.IWare;

/**
* Action of selling stuff to the city from the ship
* @author Andi Hotz, (c) Sahits GmbH, 2011
* Created on Nov 23, 2011
*
*/
class Ship2CityAction implements Runnable{
  private final IWare ware;
  private final ITransferable dialog;
//  private static final Logger logger = Logger.getLogger(Ship2CityAction.class.getName());

  public Ship2CityAction(IWare ware, ITransferable dialog) {
    super();
    this.ware = ware;
    this.dialog=dialog;
  }

  @Override
  public void run() {
    ICityPlayerProxy city = dialog.getCityPlayerProxy();
    int amountOnShip = city.getActiveShip().getWare(ware).getAmount();
    if (amountOnShip>0){
      int availableAmountCity = city.getCity().getWare(ware).getAmount();
      int amount2Move = dialog.getAmount(amountOnShip);
      final int avgPrice;
      if (dialog.getMovableAmount()==ETransferAmount.MAX){
        avgPrice = ware.getMaxValueSell();
      } else {
        avgPrice = ware.computeSellPrice(availableAmountCity, amount2Move);
      }
      city.getCity().move(ware, amount2Move,city.getPlayer()); // The price here is irrelevant
      int sold = city.getActiveShip().unload(ware, -amount2Move);
      city.getPlayer().updateCash(avgPrice*sold);
    }
  }
TOP

Related Classes of ch.sahits.game.graphic.display.dialog.Ship2CityAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.