22 package com.realtime.crossfire.jxclient.items;
27 import org.jetbrains.annotations.NotNull;
41 private final int tag;
171 public CfItem(
final int location,
final int tag,
final int flags,
final int weight, @NotNull
final Face face, @NotNull
final String name, @NotNull
final String namePl,
final int anim,
final int animSpeed,
final int nrof,
final int type) {
190 if (this.flags != flags) {
201 if (this.weight != weight) {
212 if (this.face != face) {
223 private void setName(@NotNull
final String name, @NotNull
final String namePl) {
224 if (!this.name.equals(name) || !this.namePl.equals(namePl)) {
236 if (this.anim != anim) {
247 if (this.animSpeed != animSpeed) {
258 if (this.nrof != nrof) {
319 return (flags&F_APPLIED) != 0;
327 return (flags&F_UNIDENTIFIED) != 0;
335 return (flags&F_BLESSED) != 0;
343 return (flags&F_UNPAID) != 0;
351 return (flags&F_MAGIC) != 0;
359 return (flags&F_CURSED) != 0;
367 return (flags&F_DAMNED) != 0;
375 return (flags&F_OPEN) != 0;
383 return (flags&F_NOPICK) != 0;
391 return (flags&F_LOCKED) != 0;
422 public void update(
final int updateFlags,
final int flags,
final int weight, @NotNull
final Face face, @NotNull
final String name, @NotNull
final String namePl,
final int anim,
final int animSpeed,
final int nrof) {
457 listener.itemModified();
467 listeners.
add(listener);
475 listeners.
remove(listener);
487 final StringBuilder sb =
new StringBuilder(tooltipText1);
488 if (!tooltipText2.isEmpty()) {
490 sb.append(tooltipText2);
492 if (!tooltipText3.isEmpty()) {
494 sb.append(tooltipText3);
496 return sb.toString();
514 final int totalWeight = nrof > 0 ? weight*
nrof :
weight;
515 if (totalWeight <= 0) {
518 if (totalWeight < 1000) {
519 return totalWeight+
" g";
521 if (totalWeight < 10000) {
522 final int tmp = (totalWeight+50)/100;
523 return tmp/10+
"."+tmp%10+
" kg";
525 final int tmp = (totalWeight+500)/1000;
535 final StringBuilder sb =
new StringBuilder();
536 appendFlag(sb, F_UNIDENTIFIED,
"unidentified");
542 return sb.toString();
551 private void appendFlag(@NotNull
final StringBuilder sb,
final int flag, @NotNull
final String ident) {
552 if ((flags&flag) != 0) {
565 return flags == 0 && weight == -1 && nrof == 0 && type == 0 && name.startsWith(
"Click here to see ");
void setFlags(final int flags)
Updates the flags.
boolean isUnpaid()
Returns whether this item is unpaid.
String getTooltipText1()
Returns the first line of the tooltip text.
boolean isLocked()
Returns whether this item is locked.
boolean isMagic()
Returns whether this item is magical.
String getTooltipText()
Returns a description suitable for a tooltip text.
static final int F_UNPAID
The flags value for unpaid items.
void setFace(@NotNull final Face face)
Updates the face.
CfItem(final int location, final int tag, final int flags, final int weight, @NotNull final Face face, @NotNull final String name, @NotNull final String namePl, final int anim, final int animSpeed, final int nrof, final int type)
Creates a new instance.
int UPD_FACE
The update flags value for face updates.
A list of event listeners.
String getTooltipText3()
Returns the third line of the tooltip text.
static final int F_NOPICK
The flags value for non-pickable items.
int UPD_ANIMSPEED
The update flags value for animation speed updates.
void setName(@NotNull final String name, @NotNull final String namePl)
Updates the name.
int getType()
Returns the type.
static final int F_OPEN
The flags value for opened items.
boolean isCursed()
Returns whether this item is cursed.
int nrof
The number of objects in the stack.
int UPD_FLAGS
The update flags value for flags updates.
void addCfItemModifiedListener(@NotNull final CfItemListener listener)
Add a.
Manages image information ("faces") needed to display the map view, items, and spell icons...
int getNrOf()
Returns the number of objects in this item stack.
int getLocation()
Returns the location.
boolean isNoPick()
Returns whether this item cannot be picked up.
int UPD_NAME
The update flags value for name updates.
Face getFace()
Returns the face.
boolean isDamned()
Returns whether this item is damned.
static final int F_BLESSED
The flags value for blessed items.
void setAnim(final int anim)
Updates the animation.
boolean isUnidentified()
Returns whether this item is unidentified.
void removeCfItemModifiedListener(@NotNull final CfItemListener listener)
Remove a.
void setNrOf(final int nrof)
Updates the number of objects in the stack.
String getName()
Returns the name.
static final int F_UNIDENTIFIED
The flags value for unidentified items.
int animSpeed
The animation speed.
final EventListenerList2< CfItemListener > listeners
The listeners to be notified.
boolean isItemGroupButton()
Returns whether this object is a fake object for selecting object groups in the ground view...
void update(final int updateFlags, final int flags, final int weight, @NotNull final Face face, @NotNull final String name, @NotNull final String namePl, final int anim, final int animSpeed, final int nrof)
Processes an "upditem" command.
void setWeight(final int weight)
Updates the weight.
void add(@NotNull final T listener)
Adds a listener.
int getTag()
Returns the tag.
String name
The singular name.
String getTooltipText2()
Returns the second line of the tooltip text.
int getWeight()
Returns the weight.
Interface for listeners for attribute changes of CfItems.
void appendFlag(@NotNull final StringBuilder sb, final int flag, @NotNull final String ident)
Appends "(<ident>)" if this item has the flag.
void setLocation(final int location)
Updates the location.
static final int F_APPLIED
The flags mask for applied states.
Interface defining constants for the "upditem" Crossfire protocol message.
boolean isBlessed()
Returns whether this item is blessed.
int location
The location.
int UPD_ANIM
The update flags value for animation updates.
int UPD_NROF
The update flags value for nrof updates.
void setAnimSpeed(final int animSpeed)
Updates the animation speed.
int UPD_WEIGHT
The update flags value for weight updates.
static final int F_MAGIC
The flags value for magical items.
The representation of a Crossfire Item, client-side.
void remove(@NotNull final T listener)
Removes a listener.
boolean modified
Set if any attribute has changed since the last time listeners were notified.
static final int F_LOCKED
The flags value for locked items.
static final int F_CURSED
The flags value for cursed items.
String namePl
The plural name.
boolean isApplied()
Returns whether this item is applied.
void fireModified()
Notify all listener.
static final int F_DAMNED
The flags value for damned items.
boolean isOpen()
Returns whether this item is an opened container.