RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Cannon.java
1package com.osroyale.content.combat.cannon;
2
3import com.osroyale.content.combat.cannon.CannonManager.Rotation;
4import com.osroyale.content.combat.cannon.CannonManager.Setup;
5import com.osroyale.game.world.entity.Entity;
6import com.osroyale.game.world.entity.EntityType;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.object.CustomGameObject;
9import com.osroyale.game.world.position.Position;
10import com.osroyale.game.world.region.Region;
11import com.osroyale.net.packet.out.SendAddObject;
12import com.osroyale.net.packet.out.SendRemoveObject;
13
54
55public class Cannon extends Entity {
56
57 private final String owner;
58
59 private final Position position;
60
61 private CustomGameObject object;
62
63 private int ammunition;
64
65 private boolean firing;
66
67 private Setup stage;
68
69 private Rotation rotation;
70
71 public Cannon(String owner, Position position) {
72 super(position);
73 this.owner = owner;
74 this.position = position;
75 this.ammunition = 0;
76 this.firing = false;
77 this.stage = Setup.NO_CANNON;
78 this.rotation = Rotation.NORTH;
79 this.object = new CustomGameObject(8, position);
80 }
81
82 public String getOwner() {
83 return owner;
84 }
85
87 return position;
88 }
89
90 public int getAmmunition() {
91 return ammunition;
92 }
93
94 public void setAmmunition(int ammunition) {
95 this.ammunition = ammunition;
96 }
97
98 public boolean isFiring() {
99 return firing;
100 }
101
102 public void setFiring(boolean firing) {
103 this.firing = firing;
104 }
105
106 public Setup getStage() {
107 return stage;
108 }
109
110 public void setStage(Setup stage) {
111 this.stage = stage;
112 }
113
114 public CustomGameObject getObject() {
115 return object;
116 }
117
118 public void setObject(CustomGameObject object) {
119 this.object = object;
120 }
121
122 public Rotation getRotation() {
123 return rotation;
124 }
125
126 public void setRotation(Rotation rotation) {
127 this.rotation = rotation;
128 }
129
130 @Override
131 public void register() {
132 if (!isRegistered()) {
133 Region region = getRegion();
134 setRegistered(true);
135
136 if (region == null) {
137 setPosition(getPosition());
138 } else if (!region.containsObject(getHeight(), object)) {
139 addToRegion(region);
140 }
141 }
142 }
143
144 @Override
145 public void unregister() {
146 if (isRegistered()) {
147 destroy();
148 }
149 }
150
151 @Override
152 public void addToRegion(Region region) {
153 region.getPlayers(getHeight()).stream().filter(Player::isValid).forEach(player -> player.send(new SendAddObject(object)));
154 }
155
156 @Override
157 public void removeFromRegion(Region region) {
158 region.getPlayers(getHeight()).stream().filter(Player::isValid).forEach(player -> player.send(new SendRemoveObject(object)));
159 }
160
161 @Override
162 public String getName() {
163 return "Dwarf cannon";
164 }
165
166 @Override
168 return EntityType.DWARF_CANNON;
169 }
170
171 @Override
172 public boolean equals(Object obj) {
173 return false;
174 }
175
176 @Override
177 public int hashCode() {
178 return 0;
179 }
180}
boolean containsObject(int height, GameObject object)
Definition Region.java:205
Collection< Player > getPlayers(int height)
Definition Region.java:142