Class Item

    • Field Detail

      • DEBUG

        protected static boolean DEBUG
        Debug flag.
      • DEFAULT_ITEM_PAINTERCLASS

        public static final java.lang.String DEFAULT_ITEM_PAINTERCLASS
        Default class for item painting.
        See Also:
        Constant Field Values
      • pointBonus

        protected int pointBonus
        The point bonus for this item when picked up.
      • user

        protected Figure user
        The user of this item
      • pickupText

        protected java.lang.String pickupText
        Text, that is displayed, when the item is picked up.
      • pickupClip

        protected java.lang.String pickupClip
        Sound Clip if item is picked up.
      • useClip

        protected java.lang.String useClip
        Sound clip if item is used.
      • isBomb

        protected boolean isBomb
        Flag, if this item is a bomb. False as default.
      • affectsBlue

        protected boolean affectsBlue
        Flag, if item affects blue points.
      • isWeapon

        protected boolean isWeapon
        Flag, if this item is a weapon. Relevant for ComputerFigure item rating. Set this to true for own item implementations, that are weapons but no permanent items.
      • dieReason

        protected DieReason dieReason
        The reason why this item dies.
      • category

        protected ItemCategory category
        A category this item belongs to. Default is Misc.
    • Constructor Detail

      • Item

        protected Item()
        Creates a new item. To create items during game, use Game.createItem()-methods.
    • Method Detail

      • retrieveState

        protected ItemState retrieveState​(ItemState state,
                                          AnimationInfo animation)
        Retrieves this things state. Call this from subclasses to store common thing properties in specialized state object.
        Parameters:
        state - The state object to store information in.
        animation - The AnimationInfo.
        Returns:
        state.
      • getItemRating

        public int getItemRating()
        Returns an item value for ComputerFigures rating in the items category. Default implementation returns the value of getPointBonus(). Should be overridden in subclasses. Should return a value between -1.000.000 and 1.000.000 to work with the ComputerFrigures other rating mechanisms.
        Returns:
        An item rating
      • getItemRating

        public int getItemRating​(ItemCategory category)
        Returns an item value for ComputerFigures rating in the given category. Default implementation returns the value of getItemRating(), if the Category equals the return value of getItemCategory(), getPointValue() for Score-Category or 0 otherwise. Might be overridden in subclasses if item has a value for more than one category. Should return a value between -100000 and 100000 to work with the ComputerFrigures other rating mechanisms.
        Parameters:
        category - Item category.
        Returns:
        An item rating.
      • getName

        public java.lang.String getName()
        Returns a display name for the thing.
        Specified by:
        getName in class Thing
        Returns:
        Display name.
      • onEnemyKilled

        public void onEnemyKilled​(Figure enemy,
                                  int round,
                                  DieReason reason,
                                  AnimationInfo animation)
        Called, if the thing killed an enemy. If this items user is not null, its onEnemyKilled method is called
        Overrides:
        onEnemyKilled in class Thing
        Parameters:
        enemy - The killed enemy
        round - The round count.
        reason - The die reason.
        animation - The AnimationInfo.
      • toString

        public java.lang.String toString()
        Returns a string representation of this item
        Overrides:
        toString in class java.lang.Object
        Returns:
        String representation.
      • updateThing

        protected final void updateThing​(AnimationInfo animation)
        Updates the item after each round.
        Overrides:
        updateThing in class Thing
        Parameters:
        animation - The AnimationInfo.
      • updateExplodingStatus

        protected void updateExplodingStatus​(AnimationInfo animation)
        Handles the items status during update phase of the round when thing is exploding. Sets the status to destroyed after 4 rounds.
        Specified by:
        updateExplodingStatus in class Thing
        Parameters:
        animation - The AnimationInfo.
      • doSpecialUpdate

        protected void doSpecialUpdate​(AnimationInfo animation)
        Performs the update in each round in overridden classes. Does nothing per default.
        Parameters:
        animation - The AnimationInfo.
      • bePickedUp

        public final boolean bePickedUp​(Figure picker,
                                        AnimationInfo animation)
        This method is called, when the item is picked up by a figure. If this item is exploding and the picker can pick explosives, the items energy is set to 20, and the firePickesUpExplosiveEvent()-method is called on the picker. If this item is exploding and the picker cannot pick explosives, the picker explodes, if none of the listeners intervenes (but anyhow, the item is not picked up). If this item is a bomb, the PickUpBomb-Event is fired on the picker, and if no listener cancels the action, the picker explodes (and false is returned). If every thing is ok with the item, its point bonus is added, the pickup sound is played and the item pickup text is displayed. The return value of onBePickedUp() is returned to indicate whether the item is carried around or disappears after an immediate effect.
        Parameters:
        picker - The figure who picked up the item
        animation - The animation
        Returns:
        true, if the item can be carried around, false otherwise (default is true).
      • beUsed

        public final boolean beUsed​(Figure user,
                                    AnimationInfo animation)
        This method is called when the item is used by a figure. If this item is OK, the items user is set, a clip is inserted, if the getUseClip()-method is overridden, and true is returned, otherwise false.
        Parameters:
        user - The figure using the item
        animation - The AnimationInfo.
        Returns:
        If true is returned, the item is kept after usage - returns the return value of onBeUsed by default, if the item is ok, false otherwise
      • onBeUsed

        protected boolean onBeUsed​(Figure user,
                                   AnimationInfo animation)
        Should be overridden in subclasses for implementing the behaviour when being used.
        Parameters:
        user - The user.
        animation - The Animation
        Returns:
        Returns false by default, to indicate that the item is lost after usage. If true is returned by subclasses, the item is kept as item.
      • onBePickedUp

        protected boolean onBePickedUp​(Figure picker,
                                       AnimationInfo animation)
        Should be overridden in subclasses to implement the pick up behaviour. The method is called, if a user picks up an item, after checking if item is exploding, is a bomb etc. If implementing a subclass, that has an immediate effect when picked up, override this method and return false, to indicate that the item is not kept after being picked up. Subclasses for items that can be carried around and be used by the player on demand do not need to override onBePickedUp, but should override onBeUsed.
        Parameters:
        picker - The picker.
        animation - The AnimationInfo.
        Returns:
        Returns true by default, so the item is be kept as figures item to be used later.
      • performFieldEffect

        protected void performFieldEffect​(AnimationInfo animation)
        Called each round if the item lies on the field. Override in special item classes to e.g. move item around, perform special actions... Does nothing by default.
        Parameters:
        animation - The AnimationInfo.
      • onDrop

        public void onDrop​(Figure oldOwner,
                           AnimationInfo animation)
        Called if the item is lost.
        Parameters:
        oldOwner - The old owner of the item.
        animation - AnimationInfo.
      • onHitItem

        public boolean onHitItem​(Item rammedItem,
                                 AnimationInfo animation)
        Method called if this item moves and hits another item.
        Parameters:
        rammedItem - The rammed item
        animation - The AnimationInfo.
        Returns:
        true, if this item is placed on the rammed items point. True by default.
      • onBeHitByItem

        public boolean onBeHitByItem​(Thing rammer,
                                     AnimationInfo animation)
        Method called if another item moves to this items point (e.g. rockets). Returns true by default.
        Parameters:
        rammer - The ramming item
        animation - The AnimationInfo.
        Returns:
        true, if this item should die and be replaced by the other item. false, if this item should stay and the rammer die.
      • onBeforeDie

        protected void onBeforeDie​(Thing source,
                                   DieReason reason,
                                   AnimationInfo animation)
        Called, before the item dies. Override in subclasses to implement special die behaviour.
        Parameters:
        source - The death source. Might be null if dying e.g. because of energy losses by gray points.
        reason - The death reason.
        animation - The AnimationInfo.
      • onLevelFinished

        protected void onLevelFinished()
        Called after a level was finished. Does nothing by default. Override this in item classes that need to do special cleanup after a level is finished.
      • die

        public void die​(Thing source,
                        DieReason reason,
                        AnimationInfo animation)
        Calls the onBeforeDie()-method of subclasses. Sets the status of the thing to exploding (if it is not invulnerabe) afterwards and plays an explosion sound with strength 2.
        Overrides:
        die in class Thing
        Parameters:
        source - The death source.
        reason - The death reason.
        animation - The AnimationInfo
      • getPointBonus

        public int getPointBonus()
        Gets the bonus, when the item is picked up.
        Returns:
        The point bonus.
      • getCategory

        public ItemCategory getCategory()
        Returns the items category.
        Returns:
        the category.
      • getDieReason

        public DieReason getDieReason()
        Gets a reason, why this item dies.
        Returns:
        The die reason.
      • getPickupText

        public java.lang.String getPickupText()
        Gets the text, if the item is picked up.
        Returns:
        Value of pickupText.
      • getPickUpClip

        protected java.lang.String getPickUpClip()
        Gets the name of the .wav file relative to the sound dir. Override this method in special item classes and return a clip name for automatically inserting a clip when the bePickedUp-method is called. Returning "item_xy" would search file "item_xy.wav" in the sound-dir, "../ownSounds/myitemound" the wav file "myitemound.wav" in a directory "ownSounds" in the starpoint main directory.
        Returns:
        null per default
      • getUseClip

        protected java.lang.String getUseClip()
        Gets the name of the .wav file relative to the sound dir. Override this method in special item classes and return a clip name for automatically inserting a clip when the beUsed-method is called. Returning "item_xy" would search file "item_xy.wav" in the sound-dir, "../ownSounds/myitemound" the wav file "myitemound.wav" in a directory "ownSounds" in the starpoint main directory.
        Returns:
        null per default
      • getPainterClassname

        public java.lang.String getPainterClassname()
        Gets the fully qualified classname of the Painter to use for this item (in 2D game). The default implementation (com.starpoints.painter.arena2D.PainterItem) paints the image as returned by getImageName(AnimationInfo), energy- and explosion fx depending on the item state. To implement special paint behaviour, a fully-qualified classname of a subclass of PainterItem can be provided.
        Returns:
        "com.starpoints.painter.arena2D.PainterItem"
      • getDrawText

        public java.lang.String getDrawText()
        Returns a display string for UI. Might be null
        Returns:
        null as default.
      • getUser

        public Figure getUser()
        Returns:
        the user
      • setUser

        public void setUser​(Figure user)
        Parameters:
        user - the user to set
      • isBomb

        public boolean isBomb()
        Checks, if the item is a bomb.
        Returns:
        Value of isBomb.
      • affectsBlue

        public boolean affectsBlue()
        Checks, if this item affects blue points.
        Overrides:
        affectsBlue in class Thing
        Returns:
        Value of affectsBlue.
      • isWeapon

        public boolean isWeapon()
        Checks, if this item is a weapon.
        Returns:
        Value of isWeapon.
      • is3DItem

        public boolean is3DItem()
        Checks, if this item is only for 3D gaming.
        Returns:
        false as default.
      • isAvailableInEditor

        public boolean isAvailableInEditor()
        Checks, if this item is available in level editor.
        Returns:
        true as default.
      • getMoveAnimationLength

        public int getMoveAnimationLength()
        Method that can be overwritten by moving item subclasses, in case move animation should not last for default of 4 update cycles.
        Returns:
        4 by default.
      • isRocketTarget

        public boolean isRocketTarget()
        Checks, if this item is a rocket target.
        Returns:
        false as default.
      • killedEnemy

        public void killedEnemy​(Figure f,
                                Figure enemy,
                                DieReason reason,
                                AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        enemy - The enemy.
        reason - The reason.
        animation - AnimationInfo.
      • gainsEnergy

        public int gainsEnergy​(Figure f,
                               int energyChange,
                               AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        energyChange - The original energy change.
        animation - AnimationInfo.
        Returns:
        The original energy change.
      • losesEnergy

        public int losesEnergy​(Figure f,
                               int energyChange,
                               DieReason reason,
                               AnimationInfo animation)
        Called, if the figure loses energy. The figures energy value has not yet changed, when this method is called. If a value different to energyChange is returned, this value is removed instead. If more listeners change the energy loss for the figure, the effect is cumulative.
        Parameters:
        f - The figure.
        energyChange - The original energy change.
        reason - The reason.
        animation - AnimationInfo.
        Returns:
        The original energy change.
      • gainsSlots

        public int gainsSlots​(Figure f,
                              int slots,
                              AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        slots - The number of slots.
        animation - AnimationInfo.
        Returns:
        The original number of slots.
      • pointsChange

        public int pointsChange​(Figure f,
                                int pointChange,
                                AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        pointChange - The original point change.
        animation - AnimationInfo.
        Returns:
        The original point change.
      • explodes

        public boolean explodes​(Figure f,
                                Thing source,
                                DieReason reason,
                                AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure
        source - The source of the explosion.
        reason - The reason for the explosion.
        animation - AnimationInfo
        Returns:
        true, if figure really explodes. true by default.
      • startsHovering

        public int startsHovering​(Figure f,
                                  int rounds,
                                  AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure
        rounds - The original number of rounds.
        animation - AnimationInfo
        Returns:
        The original number of rounds.
      • removeAfterLevel

        public boolean removeAfterLevel()
        Default figure listener method. Checks, if the listener wants to be removed after level has finished
        Returns:
        true by default.
      • pickesUpBomb

        public boolean pickesUpBomb​(Figure f,
                                    Item explosive,
                                    AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure
        explosive - The explosive item
        animation - AnimationInfo
        Returns:
        true to indicate that figure will be destroyed.
      • pointSumChanges

        public int pointSumChanges​(Figure f,
                                   int pointChange)
        Empty figure listener method.
        Parameters:
        f - The figure
        pointChange - The original point change.
        Returns:
        The original point change.
      • getRamPower

        public int getRamPower​(Figure f,
                               Figure rammer,
                               int initialRamPower)
        Empty figure listener method.
        Parameters:
        f - The figure.
        rammer - The figure that is rammed.
        initialRamPower - The original ramPower.
        Returns:
        The original ram power.
      • isRammed

        public int isRammed​(Figure f,
                            Figure rammer,
                            int ramPower,
                            AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        rammer - The rammer.
        ramPower - The ram power.
        animation - AnimationInfo
        Returns:
        The original ram power.
      • isStunned

        public int isStunned​(Figure f,
                             int rounds,
                             AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        rounds - The stun duration.
        animation - AnimationInfo
        Returns:
        The original rounds.
      • losesPermanentItem

        public boolean losesPermanentItem​(Figure f,
                                          Item i,
                                          AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        i - The item.
        animation - AnimationInfo
        Returns:
        true to indicate that figure loses the item.
      • lostPermanentItem

        public void lostPermanentItem​(Figure f,
                                      Item i,
                                      AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        i - The item.
        animation - The AnimationInfo.
      • losesItem

        public boolean losesItem​(Figure f,
                                 Item i,
                                 AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        i - The item.
        animation - AnimationInfo
        Returns:
        true to indicate that figure loses the item.
      • pickesUpItem

        public boolean pickesUpItem​(Figure f,
                                    Item i,
                                    AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        i - The item.
        animation - AnimationInfo
        Returns:
        true to indicate that figure can pick the item.
      • usesItem

        public boolean usesItem​(Figure f,
                                Item i,
                                AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        i - The item.
        animation - AnimationInfo
        Returns:
        true to indicate that figure can use the item.
      • gainsPermanentItem

        public boolean gainsPermanentItem​(Figure f,
                                          Item i,
                                          AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        i - The item.
        animation - AnimationInfo
        Returns:
        true to indicate that figure can add the permanent item to its inventory.
      • visibilityChanges

        public boolean visibilityChanges​(Figure f,
                                         boolean visibility,
                                         AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        visibility - The new flag.
        animation - AnimationInfo
        Returns:
        true to indicate that figure will become visible.
      • pickesUpExplosive

        public boolean pickesUpExplosive​(Figure f,
                                         Item i,
                                         AnimationInfo animation)
        Empty figure listener method.
        Parameters:
        f - The figure.
        i - The item.
        animation - AnimationInfo
        Returns:
        true to indicate that the Explosive thing affects the figure.
      • heatChanges

        public int heatChanges​(Figure f,
                               boolean internal,
                               int heat,
                               AnimationInfo animation)
        Empty figure listener method if the heat of a figure changes.
        Parameters:
        f - The figure.
        internal - Flag, if heat gain is internal.
        heat - The heat gain.
        animation - AnimationInfo
        Returns:
        The original heat gain.
      • isAffectedByColor

        public boolean isAffectedByColor​(Figure f,
                                         int c)
        Called, if the figure enters a black, blue or gray point.
        Parameters:
        f - The figure.
        c - The color.
        Returns:
        true to indicate the color affects the figure.
      • entersColor

        public boolean entersColor​(Figure f,
                                   int c,
                                   AnimationInfo animation)
        Called, if the figure enters a point.
        Parameters:
        f - The figure.
        c - The color.
        animation - AnimationInfo
        Returns:
        true to indicate the color affects the figure.
      • staysOnColor

        public boolean staysOnColor​(Figure f,
                                    int c,
                                    AnimationInfo animation)
        Called, if the figure stays on a point.
        Parameters:
        f - The figure.
        c - The color.
        animation - AnimationInfo
        Returns:
        true to indicate the color affects the figure.
      • rocketStarted

        public void rocketStarted​(ItemRocket r,
                                  AnimationInfo animation)
        Method that is called when a rocket is started on the field.
        Parameters:
        r - The starting rocket.
        animation - AnimationInfo
      • bombPlaced

        public void bombPlaced​(ItemBigMine b,
                               AnimationInfo animation)
        Method that is called when a bigmine is placed on the field.
        Parameters:
        animation - AnimationInfo
        b - The bigmine