RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
StaticGameObject.java
1package com.osroyale.game.world.object;
2
3import com.osroyale.game.world.World;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.game.world.pathfinding.TraversalMap;
6import com.osroyale.game.world.position.Position;
7import com.osroyale.game.world.region.Region;
8import com.osroyale.net.packet.out.SendAddObject;
9import com.osroyale.net.packet.out.SendRemoveObject;
10import com.osroyale.util.Utility;
11import com.osroyale.util.generic.GenericAttributes;
12
13import java.util.Objects;
14
15import static com.osroyale.game.world.object.ObjectDirection.*;
16
58
59public class StaticGameObject implements GameObject {
60
62 private GameObjectDefinition definition;
63
65 private GenericAttributes genericAttributes;
66
68 private final Position position;
69
71 private ObjectType type;
72
74 private ObjectDirection direction;
75
77 public StaticGameObject(GameObjectDefinition definition, Position position, ObjectType type, ObjectDirection direction) {
78 this.definition = definition;
79 this.position = position;
80 this.type = type;
81 this.direction = direction;
82 }
83
84 @Override
86 if (genericAttributes == null) {
87 genericAttributes = new GenericAttributes();
88 }
89 return genericAttributes;
90 }
91
92 @Override
94 return definition;
95 }
96
97 @Override
99 return position;
100 }
101
102 @Override
103 public int width() {
104 if (direction == NORTH || direction == SOUTH) {
105 return definition.getLength();
106 }
107 return definition.getWidth();
108 }
109
110 @Override
111 public int length() {
112 if (direction == NORTH || direction == SOUTH) {
113 return definition.getWidth();
114 }
115 return definition.getLength();
116 }
117
118 @Override
119 public int distance() {
120 return definition.getDistance();
121 }
122
123 @Override
125 return type;
126 }
127
128 @Override
130 return direction;
131 }
132
133 @Override
134 public void register() {
135 Region objectRegion = getPosition().getRegion();
136 if (!objectRegion.containsObject(getHeight(), this)) {
137 TraversalMap.markObject(objectRegion, this, true, true);
138 for (Region region : World.getRegions().getSurroundingRegions(getPosition())) {
139 for (Player other : region.getPlayers(getHeight())) {
140 if (other.instance != getInstancedHeight())
141 continue;
142 if (Utility.withinViewingDistance(this, other, Region.VIEW_DISTANCE)) {
143 other.send(new SendAddObject(this));
144 }
145 }
146 }
147 }
148 }
149
150 @Override
151 public void unregister() {
152 Region objectRegion = getPosition().getRegion();
153 if (objectRegion.containsObject(getHeight(), this)) {
154 TraversalMap.markObject(objectRegion, this, false, true);
155 for (Region region : World.getRegions().getSurroundingRegions(getPosition())) {
156 for (Player other : region.getPlayers(getHeight())) {
157 if (other.instance != getInstancedHeight())
158 continue;
159 if (Utility.withinViewingDistance(this, other, Region.VIEW_DISTANCE)) {
160 other.send(new SendRemoveObject(this));
161 }
162 }
163 }
164 }
165 }
166
167 @Override
168 public void transform(int id) {
169 unregister();
170 definition = GameObjectDefinition.forId(id);
171 register();
172 }
173
174 @Override
175 public void rotate(ObjectDirection direction) {
176 unregister();
177 this.direction = direction;
178 register();
179 }
180
181 @Override
182 public boolean active() {
183 return getPosition().getRegion().containsObject(getHeight(), this);
184 }
185
186 @Override
187 public int hashCode() {
188 return Objects.hash(definition.getId(), position);
189 }
190
191 @Override
192 public boolean equals(Object obj) {
193 if (obj == this) return true;
194 if (obj instanceof StaticGameObject) {
196 return definition == other.definition && position.equals(other.position);
197 }
198 return false;
199 }
200
201 @Override
202 public String toString() {
203 return String.format("StaticGameObject[id=%s, loc=%s, width=%s, len=%s, rot=%s, type=%s]", getId(), getPosition(), width(), length(), getDirection(), getObjectType());
204 }
205}
StaticGameObject(GameObjectDefinition definition, Position position, ObjectType type, ObjectDirection direction)
static void markObject(Region region, GameObject object, boolean add, boolean list)
boolean containsObject(int height, GameObject object)
Definition Region.java:205
Region[] getSurroundingRegions(Position position)