From: Stefan F. <ste...@us...> - 2012-09-19 11:54:01
|
src/rails/game/model/SpecialPropertiesModel.java | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) New commits: commit 6040f259cdca8439ff68fca311fee508a92e8439 Author: Stefan Frey <ste...@we...> Date: Wed Sep 19 09:51:56 2012 +0200 fixed issues with 1856 testgames diff --git a/src/rails/game/model/SpecialPropertiesModel.java b/src/rails/game/model/SpecialPropertiesModel.java new file mode 100644 index 0000000..4d3fa5a --- /dev/null +++ b/src/rails/game/model/SpecialPropertiesModel.java @@ -0,0 +1,71 @@ +package rails.game.model; + +import rails.common.LocalText; +import rails.game.Bonus; +import rails.game.Currency; +import rails.game.PublicCompany; +import rails.game.ReportBuffer; +import rails.game.state.Change; +import rails.game.state.Model; +import rails.game.state.Observable; +import rails.game.state.Owner; +import rails.game.state.PortfolioChange; +import rails.game.state.PortfolioSet; +import rails.game.state.Triggerable; +import rails.game.special.LocatedBonus; +import rails.game.special.SpecialProperty; + +public class SpecialPropertiesModel extends Model implements Triggerable { + + public final static String ID = "SpecialPropertiesModel"; + + private final PortfolioSet<SpecialProperty> specialProperties; + + private SpecialPropertiesModel(Owner parent) { + super(parent, ID); + // specialProperties have the Owner as parent directly + specialProperties = PortfolioSet.create(parent, "specialProperties", SpecialProperty.class); + // so make this model updating + specialProperties.addModel(this); + // and add it as triggerable + specialProperties.addTrigger(this); + } + + public static SpecialPropertiesModel create(Owner parent) { + return new SpecialPropertiesModel(parent); + } + + @Override + public Owner getParent() { + return (Owner)super.getParent(); + } + + PortfolioSet<SpecialProperty> getPortfolio() { + return specialProperties; + } + + // triggerable interface + + public void triggered(Observable observable, Change change) { + + // checks if the specialproperty moved into the portfolio carries a LocatedBonus + @SuppressWarnings("rawtypes") + PortfolioChange pchange = (PortfolioChange)change; + if (!pchange.isIntoPortfolio()) return; + + SpecialProperty property = (SpecialProperty)pchange.getItem(); + if (getParent() instanceof PublicCompany && property instanceof LocatedBonus) { + PublicCompany company = (PublicCompany)getParent(); + LocatedBonus locBonus = (LocatedBonus)property; + Bonus bonus = new Bonus(company, locBonus.getId(), locBonus.getValue(), + locBonus.getLocations()); + company.addBonus(bonus); + ReportBuffer.add(LocalText.getText("AcquiresBonus", + getParent().getId(), + locBonus.getName(), + Currency.format(company, locBonus.getValue()), + locBonus.getLocationNameString())); + } + } + +} |