Class Convoy

  • All Implemented Interfaces:
    IConvoy, IGroupableVessel, INavigableVessel

    public class Convoy
    extends java.lang.Object
    implements IConvoy
    Implementation of the Convoy.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2015 Created on Dec 23, 2015
    • Constructor Summary

      Constructors 
      Constructor Description
      Convoy​(IShip orlegShip, boolean publicConvoy)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addShip​(IShip ship)
      Add a ship to the convoy.
      void damage​(int damage, boolean destroyWeapon)
      Apply the damage to all ships.
      java.util.Optional<IShipAutoTrading> getAutotrading()
      Get the auto trading for the ship.
      int getCapacity()
      Available capacity of the ship, this represent the free storage in barrels
      java.util.Map<IPlayer,​java.lang.Integer> getCapacityPerOwner()
      Collect the convoys capacity per player who has ships in the convoy.
      java.util.Optional<ICaptain> getCaptian()
      Retrieve the captain of the Orleg ship.
      double getCurrentSpeed()
      Current top speed of the ship.
      int getDamage()
      Retrieve the damage of the ship that is damaged the most.
      int getLoadableSpace()
      Retrieve the total amount of space that is available to store stuff.
      javafx.beans.binding.IntegerBinding getLoadBinding()
      Retrieve the amount of load in barrels that is loaded in actual wares (no wappen or crew)
      java.util.Set<IWare> getLoadedWares()
      Retrieve a list of all loaded wares
      javafx.geometry.Point2D getLocation()
      Retrieve the location of the ship.
      int getMinNumberOfSailors()
      Retrieve the minimum of sailors needed to operate the ship.
      java.lang.String getName()
      The name of the convoy is the name of the Orleg ship.
      int getNumberOfSailors()
      Retrieve the number of sailors on the ship.
      IShip getOrlegShip()
      Retrieve the lead ship of the convoy.
      IShipOwner getOwner()
      Retrieve the owner of the ship.
      boolean getPirateFlag()
      Indicate if the vessel has hissed the pirate flag (Jolly Roger) and the vessel therefore should be considered a pirate vessel.
      java.util.List<IPlayer> getPlayers()
      Get all players who have a ship in the convoy.
      java.util.List<IShip> getShips()
      Retrieve a list of the ships in the convoy.
      java.util.List<IShip> getShips​(IPlayer player)
      Get all the ships in the convoi that belong to a player.
      int getSize()
      Total capacity of the ship in barrels.
      double getTopSpeed()
      Retrieve the speed of the vessel in kilometer per hour
      java.lang.String getUuid()
      Retrieve a universal unique identifier for the vessel.
      AmountablePrice<IWare> getWare​(IWare ware)
      Retrieve the amount of ware loaded
      int getWeaponAmount​(IWeapon weaponType)
      Retrieve the amount of weapons on the ship
      boolean hasWeapons()
      Though a convoy has always weapons this is only something that is handled on the level of a single ship.
      int load​(IWare ware, int amount, int avgPrice)
      The wares are loaded onto the ships in the convoy in the iteration order.
      javafx.beans.property.BooleanProperty pirateFlagProperty()
      Property defining the pirate activit y of the vessel.
      void removeShip​(IShip ship)
      Remove a ship from the convoy.
      void setAutoTrading​(IShipAutoTrading autoTrading)
      Set the ship auto trading.
      void setLocation​(javafx.geometry.Point2D location)
      Set the location of the ship.
      void togglePirateFlag()
      Hiss or lower the pirate flag (Jolly Roger).
      int unload​(IWare ware, int amount)
      Unload the wares from the ships in the convoy in the iteration order.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Convoy

        public Convoy​(IShip orlegShip,
                      boolean publicConvoy)
    • Method Detail

      • hasWeapons

        public boolean hasWeapons()
        Description copied from interface: IConvoy
        Though a convoy has always weapons this is only something that is handled on the level of a single ship. Therefore this method will always return false.
        Specified by:
        hasWeapons in interface IConvoy
        Returns:
        false
      • getOrlegShip

        public IShip getOrlegShip()
        Description copied from interface: IConvoy
        Retrieve the lead ship of the convoy.
        Specified by:
        getOrlegShip in interface IConvoy
        Returns:
        reference to the orleg ship.
      • getShips

        public java.util.List<IShip> getShips()
        Description copied from interface: IConvoy
        Retrieve a list of the ships in the convoy.
        Specified by:
        getShips in interface IConvoy
        Specified by:
        getShips in interface IGroupableVessel
        Returns:
        list of ships in the convoy.
      • addShip

        public void addShip​(IShip ship)
        Description copied from interface: IConvoy
        Add a ship to the convoy.
        Specified by:
        addShip in interface IConvoy
        Parameters:
        ship - to be added.
      • removeShip

        public void removeShip​(IShip ship)
        Description copied from interface: IConvoy
        Remove a ship from the convoy.
        Specified by:
        removeShip in interface IConvoy
        Parameters:
        ship - to be removed.
      • getSize

        public int getSize()
        Description copied from interface: INavigableVessel
        Total capacity of the ship in barrels.
        Specified by:
        getSize in interface INavigableVessel
        Returns:
        total holding capacity of the vessel in barrels
      • getCapacity

        public int getCapacity()
        Description copied from interface: INavigableVessel
        Available capacity of the ship, this represent the free storage in barrels
        Specified by:
        getCapacity in interface INavigableVessel
        Returns:
        free capacity of the vessel in barrels
      • getName

        public java.lang.String getName()
        The name of the convoy is the name of the Orleg ship.
        Specified by:
        getName in interface INavigableVessel
        Returns:
        name of the orleg ship.
      • load

        public int load​(IWare ware,
                        int amount,
                        int avgPrice)
        The wares are loaded onto the ships in the convoy in the iteration order. There is no guarantee which ware is put on which ship.
        Specified by:
        load in interface INavigableVessel
        Parameters:
        ware - to be loaded
        amount - of items the ware
        avgPrice - average price of one item of the ware
        Returns:
        amount that is loaded.
      • unload

        public int unload​(IWare ware,
                          int amount)
        Unload the wares from the ships in the convoy in the iteration order. There is no guarantee from which ship the ware will be unloaded if thot the compleate loaded amount is unloaded.
        Specified by:
        unload in interface INavigableVessel
        Parameters:
        ware - to be unloaded
        amount - amount of items of ware to unload
        Returns:
        amount of the ware that is actually unloaded.
      • getDamage

        public int getDamage()
        Retrieve the damage of the ship that is damaged the most.
        Specified by:
        getDamage in interface INavigableVessel
        Returns:
        damage of the most damaged ship in range [100,0]
      • damage

        public void damage​(int damage,
                           boolean destroyWeapon)
        Apply the damage to all ships. the actual damage varies based on ship type and some random factor.
        Specified by:
        damage in interface INavigableVessel
        Parameters:
        damage - average damage by ship
        destroyWeapon - flag indicating if weapons may be destroyed.
      • getLoadBinding

        public javafx.beans.binding.IntegerBinding getLoadBinding()
        Description copied from interface: INavigableVessel
        Retrieve the amount of load in barrels that is loaded in actual wares (no wappen or crew)
        Specified by:
        getLoadBinding in interface INavigableVessel
        Returns:
        amount of loaded wares in barrels
      • getNumberOfSailors

        public int getNumberOfSailors()
        Description copied from interface: INavigableVessel
        Retrieve the number of sailors on the ship.
        Specified by:
        getNumberOfSailors in interface INavigableVessel
        Returns:
        number of sailors on the vessel
      • getMinNumberOfSailors

        public int getMinNumberOfSailors()
        Description copied from interface: INavigableVessel
        Retrieve the minimum of sailors needed to operate the ship.
        Specified by:
        getMinNumberOfSailors in interface INavigableVessel
        Returns:
        minimum required amount of sailors.
      • getCaptian

        public java.util.Optional<ICaptain> getCaptian()
        Retrieve the captain of the Orleg ship.
        Specified by:
        getCaptian in interface INavigableVessel
        Returns:
        Optional captain of the orleg ship.
      • getWeaponAmount

        public int getWeaponAmount​(IWeapon weaponType)
        Description copied from interface: INavigableVessel
        Retrieve the amount of weapons on the ship
        Specified by:
        getWeaponAmount in interface INavigableVessel
        Parameters:
        weaponType - any ship weapon or big weapon.
        Returns:
        amount available on the ship
      • getLocation

        public javafx.geometry.Point2D getLocation()
        Description copied from interface: INavigableVessel
        Retrieve the location of the ship.
        Specified by:
        getLocation in interface INavigableVessel
        Returns:
        current location of the vessel.
      • setLocation

        public void setLocation​(javafx.geometry.Point2D location)
        Description copied from interface: INavigableVessel
        Set the location of the ship.
        Specified by:
        setLocation in interface INavigableVessel
        Parameters:
        location - of the ship
      • getOwner

        public IShipOwner getOwner()
        Description copied from interface: INavigableVessel
        Retrieve the owner of the ship. The owner cannot be retrieved if the pirate flag is set.
        Specified by:
        getOwner in interface INavigableVessel
        Returns:
        owner of the vessel.
      • getShips

        public java.util.List<IShip> getShips​(IPlayer player)
        Description copied from interface: IConvoy
        Get all the ships in the convoi that belong to a player.
        Specified by:
        getShips in interface IConvoy
        Parameters:
        player - who owns the ships
        Returns:
        possible empty list of ships.
      • getPlayers

        public java.util.List<IPlayer> getPlayers()
        Description copied from interface: IConvoy
        Get all players who have a ship in the convoy.
        Specified by:
        getPlayers in interface IConvoy
        Returns:
        list of players.
      • getCapacityPerOwner

        public java.util.Map<IPlayer,​java.lang.Integer> getCapacityPerOwner()
        Description copied from interface: IConvoy
        Collect the convoys capacity per player who has ships in the convoy.
        Specified by:
        getCapacityPerOwner in interface IConvoy
        Returns:
        map of IPlayer to capacity.
      • getLoadableSpace

        public int getLoadableSpace()
        Description copied from interface: INavigableVessel
        Retrieve the total amount of space that is available to store stuff. This is the total amount of space minus any space due to upgrades.
        Specified by:
        getLoadableSpace in interface INavigableVessel
        Returns:
        avalable space in barrels
      • getTopSpeed

        public double getTopSpeed()
        Description copied from interface: INavigableVessel
        Retrieve the speed of the vessel in kilometer per hour
        Specified by:
        getTopSpeed in interface INavigableVessel
        Returns:
        speed of the vessel in kilometer per hour.
      • getCurrentSpeed

        public double getCurrentSpeed()
        Description copied from interface: INavigableVessel
        Current top speed of the ship.
        Specified by:
        getCurrentSpeed in interface INavigableVessel
        Returns:
        speed of the vessel in kilometer per hour.
      • getUuid

        public java.lang.String getUuid()
        Description copied from interface: INavigableVessel
        Retrieve a universal unique identifier for the vessel.
        Specified by:
        getUuid in interface INavigableVessel
        Returns:
        UUID as string.
      • getPirateFlag

        public boolean getPirateFlag()
        Description copied from interface: INavigableVessel
        Indicate if the vessel has hissed the pirate flag (Jolly Roger) and the vessel therefore should be considered a pirate vessel.
        Specified by:
        getPirateFlag in interface INavigableVessel
        Returns:
        true if the Jolly Roger is hissed.
      • pirateFlagProperty

        public javafx.beans.property.BooleanProperty pirateFlagProperty()
        Description copied from interface: INavigableVessel
        Property defining the pirate activit y of the vessel.
        Specified by:
        pirateFlagProperty in interface INavigableVessel
        Returns:
        bolean property for the pirate flag.
      • setAutoTrading

        public void setAutoTrading​(IShipAutoTrading autoTrading)
        Description copied from interface: INavigableVessel
        Set the ship auto trading.
        Specified by:
        setAutoTrading in interface INavigableVessel
        Parameters:
        autoTrading - definition of the autorading, may be null to remove auto trading.