Gridarta Editor
TreasureObj.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.treasurelist;
21 
22 import java.io.Serializable;
23 import org.jetbrains.annotations.NotNull;
24 
32 public abstract class TreasureObj implements Serializable {
33 
37  private static final long serialVersionUID = 1L;
38 
42  public static final int UNSET = -1;
43 
48  @NotNull
49  private final String name;
50 
55  private final boolean isTreasureList;
56 
61  private final boolean isRealChild;
62 
67  private int chance;
68 
73  private int nrof;
74 
79  private int magic;
80 
84  private boolean hasLoop;
85 
92  protected TreasureObj(@NotNull final String name, final boolean isTreasureList, final boolean isRealChild) {
93  this.name = name;
94  this.isTreasureList = isTreasureList;
95  this.isRealChild = isRealChild;
96  chance = UNSET;
97  nrof = UNSET;
98  magic = UNSET;
99  hasLoop = false;
100  }
101 
102  @NotNull
103  @Override
104  public String toString() {
105  final StringBuilder sb = new StringBuilder();
106  if (nrof != UNSET) {
107  sb.append(nrof).append(" ");
108  }
109  sb.append(name);
110  appendToString(sb);
111  if (magic != UNSET) {
112  sb.append(" +").append(magic);
113  }
114  if (chance != UNSET) {
115  sb.append(" (").append(chance).append(" %)");
116  }
117  return sb.toString();
118  }
119 
125  protected abstract void appendToString(@NotNull StringBuilder sb);
126 
131  public void setChance(final int value) {
132  chance = value;
133  }
134 
139  public int getChance() {
140  return chance;
141  }
142 
147  public int initChance() {
148  if (chance == UNSET) {
149  chance = 100;
150  }
151  return chance;
152  }
153 
158  public void correctChance(final double corrector) {
159  chance = (int) Math.round((double) chance * corrector);
160  }
161 
166  public void setMagic(final int magic) {
167  this.magic = magic;
168  }
169 
174  public int getMagic() {
175  return magic;
176  }
177 
182  public void setNrof(final int nrof) {
183  this.nrof = nrof;
184  }
185 
190  public boolean hasLoop() {
191  return hasLoop;
192  }
193 
198  public void setHasLoop(final boolean hasLoop) {
199  this.hasLoop = hasLoop;
200  }
201 
208  public boolean isTreasureList() {
209  return isTreasureList;
210  }
211 
216  public boolean isRealChild() {
217  return isRealChild;
218  }
219 
224  @NotNull
225  public String getName() {
226  return name;
227  }
228 
234  public abstract void visit(@NotNull TreasureObjVisitor visitor);
235 
240  public abstract void copyListType(@NotNull TreasureObj treasureObj);
241 
242 }
static final long serialVersionUID
The serial version UID.
boolean hasLoop
Set if thi list contains itself.
void setNrof(final int nrof)
Sets the maximum number of generated items.
String getName()
Returns the name of this treasure object.
boolean isRealChild()
Returns whether this node is no a yes or no node.
final String name
The name of this treasure object.
void setHasLoop(final boolean hasLoop)
Sets whether this treasure object contains itself.
boolean isTreasureList()
Returns whether this treasure object is a "treasure" or "treasureone" object.
abstract void appendToString(@NotNull StringBuilder sb)
Appends a description of this treasure object to a StringBuilder.
boolean hasLoop()
Returns whether this treasure object contains itself.
final boolean isTreasureList
Whether this treasure object is a "treasure" or "treasureone" object.
abstract void visit(@NotNull TreasureObjVisitor visitor)
Calls the TreasureObjVisitor callback function appropriate for this instance.
TreasureObj(@NotNull final String name, final boolean isTreasureList, final boolean isRealChild)
Creates a new instance.
final boolean isRealChild
Set for all except yes or no nodes.
static final int UNSET
Unset values.
void correctChance(final double corrector)
Updates the chance attribute by a corrector factor.
Subclass: UserObject (= content object) for nodes in the CFTreasureListTree These can be either treas...
int getMagic()
Returns the magic attribute.
abstract void copyListType(@NotNull TreasureObj treasureObj)
Copes the list type of a treasureone list.
void setChance(final int value)
Sets the chance attribute.
int getChance()
Returns the chance attribute.
Interface for visitors of TreasureObj instances.
int initChance()
Initializes the chance attribute.
int nrof
The maximum number of generated items.
void setMagic(final int magic)
Sets the magic attribute.