RuneHive-Game
Loading...
Searching...
No Matches
GameObjectDefinition.java
Go to the documentation of this file.
1package com.runehive.game.world.object;
2
3/**
4 * Represents a single type of object.
5 *
6 * @author Graham Edgecombe
7 */
8public class GameObjectDefinition {
9
10 /** The maximum number of object definitions */
11 public static final int MAX_DEFINITIONS = 47501;
12
13 /** The definitions array. */
15
16 /**
17 * Adds a definition. TODO better way?
18 *
19 * @param def
20 * The definition.
21 */
22
23
24 public static void addDefinition(GameObjectDefinition def) {
25 definitions[def.getId()] = def;
26 }
27
28 /**
29 * Gets an object definition by its id.
30 *
31 * @param id
32 * The id.
33 * @return The definition.
34 */
35 public static GameObjectDefinition forId(int id) {
36 if (id < 0 || id >= definitions.length) {
37 return null;
38 }
39 return definitions[id];
40 }
41
42 /** The id. */
43 private int id;
44
45 /** The name. */
46 private String name;
47
48 /** The description. */
49 private String desc;
50
51 /** X size. */
52 private int width;
53
54 /** Y size. */
55 private int length;
56 /**
57 * Custom distance check
58 */
59 private int distance = 1;
60
61 /** Solid flag. */
62 private boolean solid;
63
64 /** Walkable flag. */
65 private boolean impenetrable;
66
67 /** 'Has actions' flag. */
68 private boolean hasActions;
69
70 /** The wall flag, {@code false} by default. */
71 private final boolean wall;
72
73 /** The decoration flag, {@code false} by default. */
74 private final boolean decoration;
75
76 private final int walkingFlag;
77
78 /** Creates the definition. */
79 public GameObjectDefinition(int id, String name, String desc, int width, int length, int distance, boolean solid, boolean impenetrable, boolean hasActions, boolean wall, boolean decoration, int walkingFlag) {
80 this.id = id;
81 this.name = name;
82 this.desc = desc;
83 this.width = width;
84 this.length = length;
85 this.distance = distance;
86 this.solid = solid;
87 this.impenetrable = impenetrable;
88 this.hasActions = hasActions;
89 this.wall = wall;
90 this.decoration = decoration;
91 this.walkingFlag = walkingFlag;
92 }
93
94 /** @return The id. */
95 public int getId() {
96 return this.id;
97 }
98
99 /** @return The name. */
100 public String getName() {
101 return name;
102 }
103
104 /** @return The description. */
105 public String getDescription() {
106 return desc;
107 }
108
109 /** @return The x size. */
110 public int getWidth() {
111 return width;
112 }
113
114 /** @return The y size. */
115 public int getLength() {
116 return length;
117 }
118
119 public int getDistance() {
120 return distance;
121 }
122
123 /** @return The solid flag. */
124 public boolean isSolid() {
125 return solid;
126 }
127
128 /** @return The impenetrable flag. */
129 public boolean isImpenetrable() {
130 return impenetrable;
131 }
132
133 /** @return A flag indicating that this object has some actions. */
134 public boolean hasActions() {
135 return hasActions;
136 }
137
138 public boolean isWall() {
139 return wall;
140 }
141
142 public boolean isDecoration() {
143 return decoration;
144 }
145
146 public int getWalkingFlag() {
147 return walkingFlag;
148 }
149
150 @Override
151 public String toString() {
152 return String.format("[id=%s, name=%s, width=%s, length=%s, distance=%s, wall=%s, impenetrable=%s, solid=%s", id, name, width, length, distance, wall, impenetrable, solid);
153 }
154}
final boolean wall
The wall flag, false by default.
static final GameObjectDefinition[] definitions
The definitions array.
GameObjectDefinition(int id, String name, String desc, int width, int length, int distance, boolean solid, boolean impenetrable, boolean hasActions, boolean wall, boolean decoration, int walkingFlag)
Creates the definition.
static final int MAX_DEFINITIONS
The maximum number of object definitions.
static void addDefinition(GameObjectDefinition def)
Adds a definition.
static GameObjectDefinition forId(int id)
Gets an object definition by its id.
final boolean decoration
The decoration flag, false by default.