Class TradingOffice
- java.lang.Object
-
- ch.sahits.game.openpatrician.model.impl.WareHolding
-
- ch.sahits.game.openpatrician.model.building.impl.TradingOffice
-
- All Implemented Interfaces:
IBuilding,ITradingOffice
public class TradingOffice extends WareHolding implements ITradingOffice
Implementation of the trading office- Author:
- Andi Hotz, (c) Sahits GmbH, 2011 Created on Dec 17, 2011
-
-
Field Summary
-
Fields inherited from class ch.sahits.game.openpatrician.model.impl.WareHolding
computablePrice
-
-
Constructor Summary
Constructors Constructor Description TradingOffice(IPlayer player, ICity city, int value, IStorage storage, IBalanceSheet lastWeek, IBalanceSheet thisWeek)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javafx.beans.property.IntegerPropertycapacityProperty()Retrieve the storage capacity of the trading office and all other storages in the same cityprotected intcomputeAVGPrice(IWare ware, int amount)Compute the average price for ware that is to be purchased in the specified amount.voiddestroy()Execute when the building is destroyed.java.util.Optional<ISteward>getSteward()Retrieve the steward of the trading office (manager).intgetValue()Retrieve the value of the buildingbooleanhasWeapons()check if there are any weapons in storageintmove(IWare ware, int amount)Add or remove ware from the storage.intmove(IWare ware, int amount, int avgPrice)Move the ware into/from the storage with a price attached.intmove(IWeapon weapon, int amount)/** Add or remove weapon from the storage.voidreplaceBalanceSheet(IBalanceSheet newWeek)Replace the last weeks balance sheet with the current week and set the new balance sheet for this week.voidsetOwner(IPlayer newOwner)Some buildings may be sold to other players.voidsetSteward(ISteward steward)Setting the steward.javafx.beans.property.ObjectProperty<ISteward>stewardProperty()Property holding the steward.javafx.beans.binding.BooleanBindingstorageManagerPresentBinding()Binding indicating the presence of a steward.-
Methods inherited from class ch.sahits.game.openpatrician.model.impl.WareHolding
addNewWare, bindStoredAmount, containsWare, getOccupiedSpace, getWare, move, occupiedSpaceProperty, setOccupiedSpace, storedAmountBinding, unbindAllAmounts
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ch.sahits.game.openpatrician.model.building.IBuilding
getOwner, getPropertyTax
-
Methods inherited from interface ch.sahits.game.openpatrician.model.building.ITradingOffice
getBalanceLastWeek, getCity, getCurrentWeek, getEstablishedDate, getOccupiedSpace, getOfficeTrading, getStorage, getWare, getWeaponStorage, setOccupiedSpace, storedAmountBinding
-
-
-
-
Constructor Detail
-
TradingOffice
public TradingOffice(IPlayer player, ICity city, int value, IStorage storage, IBalanceSheet lastWeek, IBalanceSheet thisWeek)
-
-
Method Detail
-
destroy
@PreDestroy public void destroy()
Description copied from interface:IBuildingExecute when the building is destroyed.
-
capacityProperty
public javafx.beans.property.IntegerProperty capacityProperty()
Description copied from interface:ITradingOfficeRetrieve the storage capacity of the trading office and all other storages in the same city- Specified by:
capacityPropertyin interfaceITradingOffice- Returns:
- storage capacity in barrels
-
hasWeapons
public boolean hasWeapons()
Description copied from interface:ITradingOfficecheck if there are any weapons in storage- Specified by:
hasWeaponsin interfaceITradingOffice- Returns:
- true if weapons are stored.
-
move
public int move(IWeapon weapon, int amount)
/** Add or remove weapon from the storage. If the amount is negative it will be removed. If the full amount is not available only the available will be moved and returned. The amount is in the ware specific size. This method is thread save.- Specified by:
movein interfaceITradingOffice- Parameters:
weapon- weapon that should be movedamount- ofweaponsthat should be moved- Returns:
- actual amount moved
-
computeAVGPrice
protected int computeAVGPrice(IWare ware, int amount)
Description copied from class:WareHoldingCompute the average price for ware that is to be purchased in the specified amount. The additional variable of the available amount is supplied byWareHolding.getWare(IWare). Subclasses may override this method.- Overrides:
computeAVGPricein classWareHolding- Parameters:
ware- for which the average price is to be computedamount- amount that is bought- Returns:
- average price for the
amountofware.
-
move
public int move(IWare ware, int amount, int avgPrice)
Move the ware into/from the storage with a price attached.- Specified by:
movein interfaceITradingOffice- Parameters:
ware- to be movedamount- amount to be moved. Negative values indicate removal of thewarefrom the trading office.avgPrice- average price to use on the amount of ware- Returns:
- the amount that was actually moved. If the
warewas to be removed the returned value is <= 0.
-
getSteward
public java.util.Optional<ISteward> getSteward()
Description copied from interface:ITradingOfficeRetrieve the steward of the trading office (manager). May be null if no manager is employed- Specified by:
getStewardin interfaceITradingOffice- Returns:
- Optional steward. Empty if none is hired.
-
setSteward
public void setSteward(ISteward steward)
Description copied from interface:ITradingOfficeSetting the steward. May be null to indicate firing the steward- Specified by:
setStewardin interfaceITradingOffice- Parameters:
steward- to set/unset (null)
-
stewardProperty
public javafx.beans.property.ObjectProperty<ISteward> stewardProperty()
Description copied from interface:ITradingOfficeProperty holding the steward.- Specified by:
stewardPropertyin interfaceITradingOffice- Returns:
- object property for the steward
-
replaceBalanceSheet
public void replaceBalanceSheet(IBalanceSheet newWeek)
Description copied from interface:ITradingOfficeReplace the last weeks balance sheet with the current week and set the new balance sheet for this week.- Specified by:
replaceBalanceSheetin interfaceITradingOffice- Parameters:
newWeek- balance sheet to replace the old one.
-
move
public int move(IWare ware, int amount)
Description copied from interface:ITradingOfficeAdd or remove ware from the storage. If the amount is negative it will be removed. If the full amount is not available only the available will be moved and returned. The amount is in the ware specific size. The price of the wares is computed based on the amount- Specified by:
movein interfaceITradingOffice- Parameters:
ware- to be moved in/out of the trading officeamount- ofwareto be moved.- Returns:
- amount that is acctualy moved
-
getValue
public int getValue()
Description copied from interface:IBuildingRetrieve the value of the building
-
storageManagerPresentBinding
public javafx.beans.binding.BooleanBinding storageManagerPresentBinding()
Description copied from interface:ITradingOfficeBinding indicating the presence of a steward.- Specified by:
storageManagerPresentBindingin interfaceITradingOffice- Returns:
- boolean binding for the presence of a steward.
-
-