RuneHive-Game
Loading...
Searching...
No Matches
StaticGameObject.java
Go to the documentation of this file.
1package com.runehive.game.world.object;
2
3import com.runehive.game.world.World;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.pathfinding.TraversalMap;
6import com.runehive.game.world.position.Position;
7import com.runehive.game.world.region.Region;
8import com.runehive.net.packet.out.SendAddObject;
9import com.runehive.net.packet.out.SendRemoveObject;
10import com.runehive.util.Utility;
11import com.runehive.util.generic.GenericAttributes;
12
13import java.util.Objects;
14
15import static com.runehive.game.world.object.ObjectDirection.*;
16
17/**
18 * Represents a static game object loaded from the map fs.
19 *
20 * @author Michael | Chex
21 */
22public class StaticGameObject implements GameObject {
23
24 /** The object definition. */
26
27 /** The generic attributes. */
29
30 /** The object position coordinates. */
31 private final Position position;
32
33 /** The object type. */
35
36 /** A byte holding the object rotation. */
38
39 /** Creates the game object. */
41 this.definition = definition;
42 this.position = position;
43 this.type = type;
44 this.direction = direction;
45 }
46
47 @Override
54
55 @Override
57 return definition;
58 }
59
60 @Override
62 return position;
63 }
64
65 @Override
66 public int width() {
67 if (direction == NORTH || direction == SOUTH) {
68 return definition.getLength();
69 }
70 return definition.getWidth();
71 }
72
73 @Override
74 public int length() {
75 if (direction == NORTH || direction == SOUTH) {
76 return definition.getWidth();
77 }
78 return definition.getLength();
79 }
80
81 @Override
82 public int distance() {
83 return definition.getDistance();
84 }
85
86 @Override
88 return type;
89 }
90
91 @Override
93 return direction;
94 }
95
96 @Override
97 public void register() {
98 Region objectRegion = getPosition().getRegion();
99 if (!objectRegion.containsObject(getHeight(), this)) {
100 TraversalMap.markObject(objectRegion, this, true, true);
102 for (Player other : region.getPlayers(getHeight())) {
103 if (other.instance != getInstancedHeight())
104 continue;
106 other.send(new SendAddObject(this));
107 }
108 }
109 }
110 }
111 }
112
113 @Override
114 public void unregister() {
115 Region objectRegion = getPosition().getRegion();
116 if (objectRegion.containsObject(getHeight(), this)) {
117 TraversalMap.markObject(objectRegion, this, false, true);
119 for (Player other : region.getPlayers(getHeight())) {
120 if (other.instance != getInstancedHeight())
121 continue;
123 other.send(new SendRemoveObject(this));
124 }
125 }
126 }
127 }
128 }
129
130 @Override
131 public void transform(int id) {
132 unregister();
134 register();
135 }
136
137 @Override
139 unregister();
140 this.direction = direction;
141 register();
142 }
143
144 @Override
145 public boolean active() {
146 return getPosition().getRegion().containsObject(getHeight(), this);
147 }
148
149 @Override
150 public int hashCode() {
151 return Objects.hash(definition.getId(), position);
152 }
153
154 @Override
155 public boolean equals(Object obj) {
156 if (obj == this) return true;
157 if (obj instanceof StaticGameObject) {
159 return definition == other.definition && position.equals(other.position);
160 }
161 return false;
162 }
163
164 @Override
165 public String toString() {
166 return String.format("StaticGameObject[id=%s, loc=%s, width=%s, len=%s, rot=%s, type=%s]", getId(), getPosition(), width(), length(), getDirection(), getObjectType());
167 }
168}
Represents the game world.
Definition World.java:46
static RegionManager getRegions()
Definition World.java:552
This class represents a character controlled by a player.
Definition Player.java:125
static GameObjectDefinition forId(int id)
Gets an object definition by its id.
GameObjectDefinition getDefinition()
Gets the object definition.
GenericAttributes getGenericAttributes()
Gets the generic attributes.
final Position position
The object position coordinates.
GenericAttributes genericAttributes
The generic attributes.
boolean active()
Determines if this object is active on the world.
ObjectDirection direction
A byte holding the object rotation.
ObjectType getObjectType()
Gets the object type.
GameObjectDefinition definition
The object definition.
ObjectDirection getDirection()
Gets the rotation.
void unregister()
Unregisters the game object.
Position getPosition()
Gets the regional location.
StaticGameObject(GameObjectDefinition definition, Position position, ObjectType type, ObjectDirection direction)
Creates the game object.
Contains traversal data for a set of regions.
static void markObject(Region region, GameObject object, boolean add, boolean list)
Marks a GameObject with the specified attributes on the specified Position to the TraversalMap.
Represents a single tile on the game world.
Definition Position.java:14
Represents a single region.
Definition Region.java:21
boolean containsObject(int height, GameObject object)
Definition Region.java:168
Region[] getSurroundingRegions(Position position)
Gets the regions surrounding a position.
Handles miscellaneous methods.
Definition Utility.java:27
static boolean withinViewingDistance(Interactable source, Interactable target, int radius)
Definition Utility.java:755
The enumerated type whose elements represent the directions for objects.
The enumerated type whose elements represent all of the object types.
default int getId()
Gets the object id.