Class CaptainState

  • All Implemented Interfaces:
    ICaptain, IPerson

    @Component
    @Scope("prototype")
    public class CaptainState
    extends java.lang.Object
    implements ICaptain
    Implementation of the captain.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2013 Created on Jan 26, 2013
    • Field Detail

      • date

        @Autowired
        private Date date
      • rnd

        @Autowired
        private java.util.Random rnd
      • birthDate

        private java.time.LocalDateTime birthDate
      • name

        private java.lang.String name
      • salary

        private int salary
      • tradingSkill

        private int tradingSkill
      • navigationSkill

        private int navigationSkill
      • fightingSkill

        private int fightingSkill
      • totalProfit

        private int totalProfit
      • sailedDistance

        private long sailedDistance
      • wonFights

        private int wonFights
      • ship

        private java.util.Optional<IShip> ship
      • skillRange

        private static final com.google.common.collect.Range<java.lang.Integer> skillRange
      • UPGRADE_NAVIGATION_LIMIT_LEVEL

        private static final java.util.Map<java.lang.Integer,​java.lang.Integer> UPGRADE_NAVIGATION_LIMIT_LEVEL
        Limits for the level that have to be reached before upgrading navigation skill.
      • UPGRADE_FIGHT_LIMIT_LEVEL

        private static final java.util.Map<java.lang.Integer,​java.lang.Integer> UPGRADE_FIGHT_LIMIT_LEVEL
        Limits for the level that have to be reached before upgrading fighting skill.
      • UPGRADE_TRADE_LIMIT_LEVEL

        private static final java.util.Map<java.lang.Integer,​java.lang.Integer> UPGRADE_TRADE_LIMIT_LEVEL
        Limits for the level that have to be reached before upgrading.
    • Constructor Detail

      • CaptainState

        public CaptainState()
    • Method Detail

      • init

        @PostConstruct
        private void init()
      • getAge

        public int getAge()
        Description copied from interface: ICaptain
        Current age of the captain
        Specified by:
        getAge in interface ICaptain
        Returns:
        age of the captain
      • getName

        public java.lang.String getName()
        Description copied from interface: ICaptain
        Retrieve the name of the captain
        Specified by:
        getName in interface ICaptain
        Returns:
        name of the captain
      • getSalary

        public int getSalary()
        Description copied from interface: ICaptain
        Retrieve the salary per day.
        Specified by:
        getSalary in interface ICaptain
        Returns:
        salaray of the captain
      • getTradingSkillLevel

        public int getTradingSkillLevel()
        Description copied from interface: ICaptain
        Retrieve the level in trading between [0,5]
        Specified by:
        getTradingSkillLevel in interface ICaptain
        Returns:
        trading skill of the captain.
      • getNavigationSkillLevel

        public int getNavigationSkillLevel()
        Description copied from interface: ICaptain
        Retrieve the level in navigation between [0,5]
        Specified by:
        getNavigationSkillLevel in interface ICaptain
        Returns:
        navigation skill of the captain
      • getFightSkillLevel

        public int getFightSkillLevel()
        Description copied from interface: ICaptain
        Retrieve the level in sea fights between [0,5]
        Specified by:
        getFightSkillLevel in interface ICaptain
        Returns:
        fighting skill of the captain.
      • setTradingSkillLevel

        private void setTradingSkillLevel​(int level)
        Set the new trading skill level between [0..5]
        Parameters:
        level - trade skill level
      • setNavigationSkillLevel

        private void setNavigationSkillLevel​(int level)
        Set the new navigation skill level between [0..5]
        Parameters:
        level - navigation skill level
      • setFightSkillLevel

        private void setFightSkillLevel​(int level)
        Set the new fight skill level between [0..5]
        Parameters:
        level - fight skill level
      • setSalary

        public void setSalary​(int salary)
        Set the new salary
        Parameters:
        salary - salary of the captain.
      • assignToShip

        public void assignToShip​(IShip ship)
        Description copied from interface: ICaptain
        Assign a captain to a ship.
        Specified by:
        assignToShip in interface ICaptain
        Parameters:
        ship - to which the captain is assigned.
      • getAssignedShip

        public java.util.Optional<IShip> getAssignedShip()
        Get the ship the captain is assigned to.
        Specified by:
        getAssignedShip in interface ICaptain
        Returns:
        absent if the captain is not assigned to any ship.
      • upgradeToNextTradeLevel

        public boolean upgradeToNextTradeLevel()
        Description copied from interface: ICaptain
        Increase the experiance level by one. The highest level i 5.
        Specified by:
        upgradeToNextTradeLevel in interface ICaptain
        Returns:
        true if upgrade happened.
      • updateProfit

        public void updateProfit​(int profit)
        Description copied from interface: ICaptain
        Add the profit the total profit.
        Specified by:
        updateProfit in interface ICaptain
        Parameters:
        profit - additional profit
      • updatedSailedDistance

        public void updatedSailedDistance​(int distance)
        Description copied from interface: ICaptain
        Add the sailed distance to the total
        Specified by:
        updatedSailedDistance in interface ICaptain
        Parameters:
        distance - additional distance
      • upgradeToNextNavigationLevel

        public boolean upgradeToNextNavigationLevel()
        Description copied from interface: ICaptain
        If possible upgrade the captain to the next level on navigation skill.
        Specified by:
        upgradeToNextNavigationLevel in interface ICaptain
        Returns:
        true if upgrade happened
      • updateFightWon

        public void updateFightWon()
        Description copied from interface: ICaptain
        Increase the number of won fights.
        Specified by:
        updateFightWon in interface ICaptain
      • upgradeToNextFightingLevel

        public boolean upgradeToNextFightingLevel()
        Description copied from interface: ICaptain
        If possible upgrade the captain fight skill to the next level.
        Specified by:
        upgradeToNextFightingLevel in interface ICaptain
        Returns:
        true if an upgrade happened