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 Modifier and Type Field Description private IBalanceSheet
balanceLastWeek
private int
baseValue
Value of the building (building costsprivate BuildingProperties
buildingProperties
private javafx.beans.property.IntegerProperty
capacity
private ICity
city
Reference to the city the trading office is located inprivate IBalanceSheet
currentWeek
private Date
date
private java.time.LocalDateTime
establishedDate
private IAutomatedTrading
officeTrading
private IPlayer
owner
Reference to the playerprivate DependentPropertyInitializer
propertyInitializer
private int
propertyTax
private javafx.beans.property.ObjectProperty<ISteward>
steward
private IStorage
storage
private javafx.beans.binding.BooleanBinding
storageManagerPresent
private IWeaponStorage
weaponStorage
Weapons storage-
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 private void
bindWares()
javafx.beans.property.IntegerProperty
capacityProperty()
Retrieve the storage capacity of the trading office and all other storages in the same cityprotected int
computeAVGPrice(IWare ware, int amount)
Compute the average price for ware that is to be purchased in the specified amount.void
destroy()
Execute when the building is destroyed.java.util.Optional<ISteward>
getSteward()
Retrieve the steward of the trading office (manager).int
getValue()
Retrieve the value of the buildingboolean
hasWeapons()
check if there are any weapons in storageprivate void
init()
private void
initWares()
Init the amount of wares available in the city This method is protected so it can be overriden by subclasses for testingint
move(IWare ware, int amount)
Add or remove ware from the storage.int
move(IWare ware, int amount, int avgPrice)
Move the ware into/from the storage with a price attached.int
move(IWeapon weapon, int amount)
/** Add or remove weapon from the storage.void
replaceBalanceSheet(IBalanceSheet newWeek)
Replace the last weeks balance sheet with the current week and set the new balance sheet for this week.void
setOwner(IPlayer newOwner)
Some buildings may be sold to other players.void
setSteward(ISteward steward)
Setting the steward.javafx.beans.property.ObjectProperty<ISteward>
stewardProperty()
Property holding the steward.javafx.beans.binding.BooleanBinding
storageManagerPresentBinding()
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
-
-
-
-
Field Detail
-
owner
private final IPlayer owner
Reference to the player
-
city
private final ICity city
Reference to the city the trading office is located in
-
baseValue
private final int baseValue
Value of the building (building costs
-
weaponStorage
@Autowired private IWeaponStorage weaponStorage
Weapons storage
-
propertyTax
@DependentValue("propertytax.tradingoffice") private int propertyTax
-
storage
private IStorage storage
-
steward
private javafx.beans.property.ObjectProperty<ISteward> steward
-
balanceLastWeek
private IBalanceSheet balanceLastWeek
-
currentWeek
private IBalanceSheet currentWeek
-
establishedDate
private java.time.LocalDateTime establishedDate
-
officeTrading
@Autowired private IAutomatedTrading officeTrading
-
propertyInitializer
@Autowired private DependentPropertyInitializer propertyInitializer
-
date
@Autowired private Date date
-
buildingProperties
@Autowired private BuildingProperties buildingProperties
-
capacity
private javafx.beans.property.IntegerProperty capacity
-
storageManagerPresent
private javafx.beans.binding.BooleanBinding storageManagerPresent
-
-
Constructor Detail
-
TradingOffice
public TradingOffice(IPlayer player, ICity city, int value, IStorage storage, IBalanceSheet lastWeek, IBalanceSheet thisWeek)
-
-
Method Detail
-
init
@PostConstruct private void init()
-
destroy
@PreDestroy public void destroy()
Description copied from interface:IBuilding
Execute when the building is destroyed.
-
initWares
private void initWares()
Init the amount of wares available in the city This method is protected so it can be overriden by subclasses for testing
-
bindWares
private void bindWares()
-
capacityProperty
public javafx.beans.property.IntegerProperty capacityProperty()
Description copied from interface:ITradingOffice
Retrieve the storage capacity of the trading office and all other storages in the same city- Specified by:
capacityProperty
in interfaceITradingOffice
- Returns:
- storage capacity in barrels
-
hasWeapons
public boolean hasWeapons()
Description copied from interface:ITradingOffice
check if there are any weapons in storage- Specified by:
hasWeapons
in 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:
move
in interfaceITradingOffice
- Parameters:
weapon
- weapon that should be movedamount
- ofweapons
that should be moved- Returns:
- actual amount moved
-
computeAVGPrice
protected int computeAVGPrice(IWare ware, int amount)
Description copied from class:WareHolding
Compute 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:
computeAVGPrice
in classWareHolding
- Parameters:
ware
- for which the average price is to be computedamount
- amount that is bought- Returns:
- average price for the
amount
ofware
.
-
move
public int move(IWare ware, int amount, int avgPrice)
Move the ware into/from the storage with a price attached.- Specified by:
move
in interfaceITradingOffice
- Parameters:
ware
- to be movedamount
- amount to be moved. Negative values indicate removal of theware
from the trading office.avgPrice
- average price to use on the amount of ware- Returns:
- the amount that was actually moved. If the
ware
was to be removed the returned value is <= 0.
-
getSteward
public java.util.Optional<ISteward> getSteward()
Description copied from interface:ITradingOffice
Retrieve the steward of the trading office (manager). May be null if no manager is employed- Specified by:
getSteward
in interfaceITradingOffice
- Returns:
- Optional steward. Empty if none is hired.
-
setSteward
public void setSteward(ISteward steward)
Description copied from interface:ITradingOffice
Setting the steward. May be null to indicate firing the steward- Specified by:
setSteward
in interfaceITradingOffice
- Parameters:
steward
- to set/unset (null)
-
stewardProperty
public javafx.beans.property.ObjectProperty<ISteward> stewardProperty()
Description copied from interface:ITradingOffice
Property holding the steward.- Specified by:
stewardProperty
in interfaceITradingOffice
- Returns:
- object property for the steward
-
replaceBalanceSheet
public void replaceBalanceSheet(IBalanceSheet newWeek)
Description copied from interface:ITradingOffice
Replace the last weeks balance sheet with the current week and set the new balance sheet for this week.- Specified by:
replaceBalanceSheet
in interfaceITradingOffice
- Parameters:
newWeek
- balance sheet to replace the old one.
-
move
public int move(IWare ware, int amount)
Description copied from interface:ITradingOffice
Add 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:
move
in interfaceITradingOffice
- Parameters:
ware
- to be moved in/out of the trading officeamount
- ofware
to be moved.- Returns:
- amount that is acctualy moved
-
getValue
public int getValue()
Description copied from interface:IBuilding
Retrieve the value of the building
-
storageManagerPresentBinding
public javafx.beans.binding.BooleanBinding storageManagerPresentBinding()
Description copied from interface:ITradingOffice
Binding indicating the presence of a steward.- Specified by:
storageManagerPresentBinding
in interfaceITradingOffice
- Returns:
- boolean binding for the presence of a steward.
-
-