Class ShipyardState

  • All Implemented Interfaces:
    IShipyard

    @Component
    @Scope("prototype")
    public class ShipyardState
    extends java.lang.Object
    implements IShipyard
    Implementation of the shipyard model.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2013 Created on Mar 9, 2013
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • buildTimeSnaikka

        @DependentValue("shipyard.build.time.snaikka")
        private int buildTimeSnaikka
      • buildTimeCrayer

        @DependentValue("shipyard.build.time.crayer")
        private int buildTimeCrayer
      • buildTimeCog

        @DependentValue("shipyard.build.time.cog")
        private int buildTimeCog
      • buildTimeHolk

        @DependentValue("shipyard.build.time.holk")
        private int buildTimeHolk
      • repairTimeSnaikka

        @DependentValue("shipyard.repair.time.snaikka")
        private int repairTimeSnaikka
      • repairTimeCrayer

        @DependentValue("shipyard.repair.time.crayer")
        private int repairTimeCrayer
      • repairTimeCog

        @DependentValue("shipyard.repair.time.cog")
        private int repairTimeCog
      • repairTimeHolk

        @DependentValue("shipyard.repair.time.holk")
        private int repairTimeHolk
      • experience

        private double experience
        Value between 0 and 1 detailing the experience of the ship yard crew (the higher the better)
      • date

        @Autowired
        private Date date
      • rnd

        @Autowired
        private java.util.Random rnd
      • city

        private final ICity city
      • map

        @Autowired
        private IMap map
    • Constructor Detail

      • ShipyardState

        public ShipyardState​(ICity city)
    • Method Detail

      • initializeExperience

        @PostConstruct
        public void initializeExperience()
      • getShipBuildingList

        public java.util.List<IShipDueDate> getShipBuildingList()
        Description copied from interface: IShipyard
        Retrieve an immutable list of the ships that are ordered to be built on this shipyard.
        Specified by:
        getShipBuildingList in interface IShipyard
        Returns:
        immutable list of ship due dates.
      • getShipUpgradeList

        public java.util.List<IShipDueDate> getShipUpgradeList()
        Description copied from interface: IShipyard
        Retrieve the list of all ships that are to be upgraded.
        Specified by:
        getShipUpgradeList in interface IShipyard
        Returns:
        immutable list of all the upgrading ships
      • addShipBuildingOrder

        public void addShipBuildingOrder​(IShipDueDate dueDate,
                                         java.util.Optional<TimedTask> task)
        Description copied from interface: IShipyard
        Add an order for building a new ship to the list.
        Specified by:
        addShipBuildingOrder in interface IShipyard
        Parameters:
        dueDate - when the ship is finished building
        task - that is executed on completion.
      • cancelShipBuildingOrder

        public void cancelShipBuildingOrder​(java.time.LocalDateTime finish)
        Description copied from interface: IShipyard
        Cancel the order of the building, finished on the given date.
        Specified by:
        cancelShipBuildingOrder in interface IShipyard
        Parameters:
        finish - date
      • getShipRepairList

        public java.util.List<IShipDueDate> getShipRepairList()
        Description copied from interface: IShipyard
        Retrieve the list of all ships that are to be repaired.
        Specified by:
        getShipRepairList in interface IShipyard
        Returns:
        immutable list of all the repairing ships
      • addShipRepairOrder

        public void addShipRepairOrder​(IShipDueDate dueDate,
                                       java.util.Optional<TimedTask> task)
        Description copied from interface: IShipyard
        Add an order for repairing a ship to the list.
        Specified by:
        addShipRepairOrder in interface IShipyard
        Parameters:
        dueDate - when the ship is finished repairing
        task - that is executed on completion.
      • calculateRepairMaterialCosts

        public int calculateRepairMaterialCosts​(IShip ship,
                                                int damage)
        Description copied from interface: IShipyard
        Calculate the material costs for the repair.
        Specified by:
        calculateRepairMaterialCosts in interface IShipyard
        Parameters:
        ship - for which to calculate the material costs.
        damage - of the ship
        Returns:
        total material costs.
      • getShipSize

        private double getShipSize​(IShip ship)
      • calculateRepairCosts

        public int calculateRepairCosts​(int repairTime,
                                        int materialCosts)
        Description copied from interface: IShipyard
        Calculate the repair costs.
        Specified by:
        calculateRepairCosts in interface IShipyard
        Parameters:
        repairTime - number of days it takes for the repair
        materialCosts - costs of material that are required to be bought
        Returns:
        total cost of the repair.
      • calculateSaleryPerDay

        private int calculateSaleryPerDay()
        Salery is defined by the experiance
        Returns:
        salery per day.
      • cancelRepair

        public void cancelRepair​(IShip ship)
        Description copied from interface: IShipyard
        Cancel the repair of the ship. No damage will be repaired
        Specified by:
        cancelRepair in interface IShipyard
        Parameters:
        ship - which's repair order is to be canceled
      • addShipRefitOrder

        public void addShipRefitOrder​(IShipDueDate dueDate,
                                      java.util.Optional<TimedTask> task)
        Description copied from interface: IShipyard
        Add an order for refitting a ship to the list.
        Specified by:
        addShipRefitOrder in interface IShipyard
        Parameters:
        dueDate - when the ship is refitted
        task - that is executed on completion.
      • calculateRefitTime

        public int calculateRefitTime​(EShipType type)
        Description copied from interface: IShipyard
        Calculate the time in days it takes for refitting.
        Specified by:
        calculateRefitTime in interface IShipyard
        Parameters:
        type - destination level
        Returns:
        time in days.
      • getBuildCompleteDate

        public java.time.LocalDateTime getBuildCompleteDate​(EShipType type)
        Description copied from interface: IShipyard
        Retrieve the date when the building of a new ship will be finished.
        Specified by:
        getBuildCompleteDate in interface IShipyard
        Parameters:
        type - of the ship to be built
        Returns:
        end date of the building
      • calculateBuildTime

        public int calculateBuildTime​(EShipType type)
        Description copied from interface: IShipyard
        Calculate the build time for the ship of type.
        Specified by:
        calculateBuildTime in interface IShipyard
        Parameters:
        type - ship type
        Returns:
        total build time for a ship of type type
      • calculateRepairTime

        public int calculateRepairTime​(EShipType type)
        Description copied from interface: IShipyard
        Calculate the repair time for the ship of type.
        Specified by:
        calculateRepairTime in interface IShipyard
        Parameters:
        type - ship type
        Returns:
        total repair time for a ship of type type
      • getBaseRepairTime

        private int getBaseRepairTime​(EShipType type)
      • calculateRefitCosts

        public int calculateRefitCosts​(EShipType type,
                                       int levels)
        Description copied from interface: IShipyard
        Calculate the labor costs for the refit based on the ship type and how many levels should be upgraded.
        Specified by:
        calculateRefitCosts in interface IShipyard
        Parameters:
        type - ship type that should be upgraded
        levels - number of upgrade levels
        Returns:
        total work costs for the refit.
      • calculateConstructionCosts

        public int calculateConstructionCosts​(EShipType type)
        Description copied from interface: IShipyard
        Calculate the labor costs for building a new ship of the indicated type.
        Specified by:
        calculateConstructionCosts in interface IShipyard
        Parameters:
        type - of the ship
        Returns:
        costs.
      • getBuildableShipTypes

        public EShipType[] getBuildableShipTypes()
        Description copied from interface: IShipyard
        Retrieve a list of all the types of ships this yard can build.
        Specified by:
        getBuildableShipTypes in interface IShipyard
        Returns:
        array of ship types that can be constructed.
      • removeCompletedRepair

        public void removeCompletedRepair​(IShip ship)
        Description copied from interface: IShipyard
        Remove the repair entry once it is completed.
        Specified by:
        removeCompletedRepair in interface IShipyard
        Parameters:
        ship - that is to be repaired.
      • removeCompletedConstruction

        public void removeCompletedConstruction​(IShip ship)
        Description copied from interface: IShipyard
        Remove the build entry once it is completed.
        Specified by:
        removeCompletedConstruction in interface IShipyard
        Parameters:
        ship - that is to be built.
      • removeCompletedUpgrade

        public void removeCompletedUpgrade​(IShip ship)
        Description copied from interface: IShipyard
        Remove the upgrade entry once it is completed.
        Specified by:
        removeCompletedUpgrade in interface IShipyard
        Parameters:
        ship - that is to be upgraded.