Package com.starpoints.game
Class ItemPermanent
- java.lang.Object
-
- com.starpoints.game.Thing
-
- com.starpoints.game.Item
-
- com.starpoints.game.ItemPermanent
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
ItemAbstractChrystal,ItemAntiKill,ItemBlackBlocker,ItemBlasterGenerator,ItemBombKit,ItemCoolGenerator,ItemDarkRedBlocker,ItemECM,ItemEnergyPlusSuper,ItemEnergyTransformer,ItemFireExtinguisher,ItemFlameThrowerGenerator,ItemGrayBlocker,ItemHoverPower,ItemMagentaDouble,ItemRamGenerator,ItemRamPower,ItemRocketGenerator,ItemRocketGeneratorBoost,ItemRocketGeneratorBoostFast,ItemShielding,ItemStabilizerDevice
public abstract class ItemPermanent extends Item
Abstract superclass for items with a permanent effect. Overriding subclasses should override onAddedAsPermanentItem(), if special behaviour is needed when being added to the users inventory. The method performPermanentEffect() is called at the end of each round (before energy changes are handled) - override to implement some permanent behavour. If subclasses implement one of the listener interfaces from com.starpoints.game.event, they are automatically added when being added to the inventory (as well as reregistered as FieldListener if a new level is entered).- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandisplayInSlotFlag, if item has an image to display on the figure in 2Dprotected booleandrawDurationFlag, if the duration should be drawn on game display (or cockpit).protected intdurationThe duration.protected intenergyFactorUsed for default duration calculation.protected booleanisPermanentlyActiveFlag, if the item should be updated, when on a figures permanent items list.protected booleanuniqueFlag, if only one item of this kind can be owned.protected booleanusesUpFlag, if item is used up by the time.protected java.lang.StringuseTextThe text displayed if the item is used.-
Fields inherited from class com.starpoints.game.Item
affectsBlue, category, DEBUG, DEFAULT_ITEM_PAINTERCLASS, dieReason, isBomb, isWeapon, pickupClip, pickupText, pointBonus, useClip, user
-
Fields inherited from class com.starpoints.game.Thing
energy, energyFx, energyMaxSoundPlayed, energyModifications, explosionCounter, game, imageName, innerColor, invulnCount, isAffectedByBlack, isAffectedByGray, level, MAX_TEXTPAINT, maxEnergy, nextID, outerColor, p, shieldCount, status, text
-
-
Constructor Summary
Constructors Constructor Description ItemPermanent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanbeforePickup(Figure picker, AnimationInfo animation)Called befor picking up a permanent item.protected intcalculateDuration()Calculates the duration.ThingStatecreateState(AnimationInfo animation)Creates a state object for this item.voiddie(Thing source, DieReason reason, AnimationInfo animation)Removes the item as listener.booleandisplayInSlot()Called to determine if item has an image to display on the figure in 2D display.protected voiddoSpecialUpdate(AnimationInfo animation)Performs the update in each round in overridden classes.intgetDuration()Gets this item duration.java.lang.StringgetFigureOverlayImageName(AnimationInfo animation)Gets an image name for painting on the figure.java.lang.StringgetSlotImageName()Returns an image name for slot display.java.lang.StringgetUseText()Gets a text to display when used.protected booleanisAddingEnergy()Should return true for permanent items, that add energy to an already existing item, if this is unique.booleanisDrawingDuration()Checks, if item duration should be drawn.booleanisPermanentlyActive()Returns true, if the item should be updated, when on a figures permanent items list.booleanisUnique()Checks, if this permament item is unique in the players inventory.booleanisUsingUp()Checks, if this item uses up.protected voidonAddedAsPermanentItem(Figure user, AnimationInfo animation)Should register this item as listener for events when used.protected voidonBeLost(Figure oldOwner, AnimationInfo animation)Should be overridden in subclasses to unregister figure listeners added in the registerListeners-method.booleanonBePickedUp(Figure picker, AnimationInfo animation)This method is called, when the item is picked up by a figure.protected booleanonBeUsed(Figure user, AnimationInfo animation)If the user user this permanent item, it is added to the permanent item list of the user.protected voidonDropPermanent(Figure oldOwner, AnimationInfo animation)Called if the item is lost.protected voidonReinitForNewLevel(Figure user)Called after a level, if this item is stored in a permanent slot of the figure.voidperformPermanentEffect(Figure owner, AnimationInfo animation)Performs the permanent effect of the item, if it can be carried wround permanently.voidsetDrawDuration(boolean drawDuration)Sets the draw duration flag.voidsetDuration(int duration, AnimationInfo animation)Sets the duration for this item.voidsetIsUsingUp(boolean usesUp)voiduseUp(AnimationInfo animation)Uses this item up by removing the energy factor from the items energy.-
Methods inherited from class com.starpoints.game.Item
affectsBlue, bePickedUp, beUsed, bombPlaced, entersColor, explodes, gainsEnergy, gainsPermanentItem, gainsSlots, getCategory, getDieReason, getDrawText, getItemRating, getItemRating, getMoveAnimationLength, getName, getPainterClassname, getPickUpClip, getPickupText, getPointBonus, getRamPower, getUseClip, getUser, heatChanges, is3DItem, isAffectedByColor, isAvailableInEditor, isBomb, isRammed, isRocketTarget, isStunned, isWeapon, killedEnemy, losesEnergy, losesItem, losesPermanentItem, lostPermanentItem, onBeforeDie, onBeHitByItem, onDrop, onEnemyKilled, onHitItem, onLevelFinished, performFieldEffect, pickesUpBomb, pickesUpExplosive, pickesUpItem, pointsChange, pointSumChanges, removeAfterLevel, retrieveState, rocketStarted, setUser, startsHovering, staysOnColor, toString, updateExplodingStatus, updateThing, usesItem, visibilityChanges
-
Methods inherited from class com.starpoints.game.Thing
addEnergy, addShielding, addStateProperties, clearTexts, displayText, displayText, entersColor, equals, getColor, getEnergy, getEnergyMaxCount, getExplosionCounter, getField, getGame, getID, getImageName, getInnerColor, getInvulnerableRounds, getLevel, getMaxEnergy, getNextID, getOuterColor, getPoint, getShadowColor, getShield, getStateObject, getStatus, getText, getTextColor, getTextPaintCount, getX, getY, hashCode, invulnerable, isAffectedByBlack, isAffectedByGray, isDestroyed, isExploding, isInvulnerable, isOK, isShowingEnergyFx, onExplode, removeEnergy, retrieveState, setEnergy, setEnergyMaxCount, setGame, setMaxEnergy, setPoint, setStatus, staysOnColor, stepText, updateEnergy
-
-
-
-
Field Detail
-
duration
protected int duration
The duration. Initially set to 0.
-
drawDuration
protected boolean drawDuration
Flag, if the duration should be drawn on game display (or cockpit).
-
unique
protected boolean unique
Flag, if only one item of this kind can be owned.
-
displayInSlot
protected boolean displayInSlot
Flag, if item has an image to display on the figure in 2D
-
isPermanentlyActive
protected boolean isPermanentlyActive
Flag, if the item should be updated, when on a figures permanent items list.
-
usesUp
protected boolean usesUp
Flag, if item is used up by the time. This is set to false for the ComputerFigures internal equipment
-
useText
protected java.lang.String useText
The text displayed if the item is used.
-
energyFactor
protected int energyFactor
Used for default duration calculation. Energy is divided by this factor, to determine items duration. Default is 1. Set to individual factor in constructor of overriding classes.
-
-
Method Detail
-
onBePickedUp
public final boolean onBePickedUp(Figure picker, AnimationInfo animation)
This method is called, when the item is picked up by a figure. If item can be picked up, a check is performed, if this item is unique and already present, if yes, false is returned, true otherwise- Overrides:
onBePickedUpin classItem- Parameters:
picker- The figure who picked up the item.animation- The AnimationInfo.- Returns:
- true, if the item can be carried around, false otherwise.
-
isAddingEnergy
protected boolean isAddingEnergy()
Should return true for permanent items, that add energy to an already existing item, if this is unique. Not needed for non unique items.- Returns:
- true by default.
-
beforePickup
protected boolean beforePickup(Figure picker, AnimationInfo animation)
Called befor picking up a permanent item.- Parameters:
picker- The figure picking the item.animation- The AnimationInfo.- Returns:
- true, if the item can be picked up (either if item is unique or picker still has free slots).
-
onBeUsed
protected final boolean onBeUsed(Figure user, AnimationInfo animation)
If the user user this permanent item, it is added to the permanent item list of the user.
-
calculateDuration
protected int calculateDuration()
Calculates the duration. Called after energy changes.- Returns:
- The duration.
-
useUp
public void useUp(AnimationInfo animation)
Uses this item up by removing the energy factor from the items energy.- Parameters:
animation- The AnimationInfo.
-
doSpecialUpdate
protected void doSpecialUpdate(AnimationInfo animation)
Performs the update in each round in overridden classes. Recalculates duration.- Overrides:
doSpecialUpdatein classItem- Parameters:
animation- The AnimationInfo.
-
getUseText
public java.lang.String getUseText()
Gets a text to display when used.- Returns:
- null as default.
-
isPermanentlyActive
public boolean isPermanentlyActive()
Returns true, if the item should be updated, when on a figures permanent items list.- Returns:
- true as default.
-
getSlotImageName
public java.lang.String getSlotImageName()
Returns an image name for slot display.- Returns:
- getImageName()+"_slot"
-
displayInSlot
public boolean displayInSlot()
Called to determine if item has an image to display on the figure in 2D display. If true is returned, an image with filename getImageName()+"_slot" is searched and displayed on the figure in 2D display.- Returns:
- Value of displayInSlot
-
isDrawingDuration
public boolean isDrawingDuration()
Checks, if item duration should be drawn.- Returns:
- true, if duration should be drawn.
-
setDrawDuration
public void setDrawDuration(boolean drawDuration)
Sets the draw duration flag.- Parameters:
drawDuration- true, if duration should be drawn.
-
getDuration
public int getDuration()
Gets this item duration.- Returns:
- The duration.
-
setDuration
public void setDuration(int duration, AnimationInfo animation)Sets the duration for this item. If the item uses up and duration is 0 or below, this item dies.- Parameters:
duration- The new duration.animation- The AnimationInfo.
-
die
public void die(Thing source, DieReason reason, AnimationInfo animation)
Removes the item as listener.
-
performPermanentEffect
public void performPermanentEffect(Figure owner, AnimationInfo animation)
Performs the permanent effect of the item, if it can be carried wround permanently. Does nothing.- Parameters:
owner- The figure that owns this item.animation- The Animationinfo.
-
onDropPermanent
protected final void onDropPermanent(Figure oldOwner, AnimationInfo animation)
Called if the item is lost.- Parameters:
oldOwner- The old owner of the item.animation- The Animationinfo.
-
onAddedAsPermanentItem
protected void onAddedAsPermanentItem(Figure user, AnimationInfo animation)
Should register this item as listener for events when used. Is called during the beUsed. Item subclasses overriding registerListeners() should override unregisterListeners() as well, to unregister when dying. Does nothing by default.- Parameters:
user- The figure using the item.animation- The Animationinfo.
-
onBeLost
protected void onBeLost(Figure oldOwner, AnimationInfo animation)
Should be overridden in subclasses to unregister figure listeners added in the registerListeners-method. Does nothing by default- Parameters:
oldOwner- The old owner of the item.animation- The Animationinfo.
-
isUsingUp
public boolean isUsingUp()
Checks, if this item uses up.- Returns:
- Flag, if item uses Up
-
setIsUsingUp
public void setIsUsingUp(boolean usesUp)
- Parameters:
usesUp- the usesUp to set
-
getFigureOverlayImageName
public java.lang.String getFigureOverlayImageName(AnimationInfo animation)
Gets an image name for painting on the figure. Returns null by default for no overlay image.- Parameters:
animation- The AnimationInfo.- Returns:
- The overlay image name or null for no overlay.
-
onReinitForNewLevel
protected void onReinitForNewLevel(Figure user)
Called after a level, if this item is stored in a permanent slot of the figure. Does nothing by default.- Parameters:
user- The user
-
isUnique
public boolean isUnique()
Checks, if this permament item is unique in the players inventory.- Returns:
- true, if unique.
-
createState
public ThingState createState(AnimationInfo animation)
Creates a state object for this item.- Overrides:
createStatein classItem
-
-