RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
House.java
1package com.osroyale.content.skill.impl.construction;
2
3import com.osroyale.game.Animation;
4import com.osroyale.game.world.World;
5import com.osroyale.game.world.entity.mob.player.Player;
6import com.osroyale.game.world.entity.mob.player.profile.ProfileRepository;
7import com.osroyale.game.world.entity.skill.Skill;
8import com.osroyale.game.world.items.Item;
9import com.osroyale.game.world.object.CustomGameObject;
10import com.osroyale.game.world.object.GameObject;
11import com.osroyale.game.world.object.ObjectDirection;
12import com.osroyale.game.world.object.ObjectType;
13import com.osroyale.game.world.position.Position;
14import com.osroyale.net.packet.out.SendMessage;
15import com.osroyale.net.packet.out.SendMinimapState;
16import com.osroyale.net.packet.out.SendMinimapState.MinimapState;
17import com.osroyale.net.packet.out.SendString;
18import com.osroyale.util.MessageColor;
19import com.osroyale.util.Utility;
20
21import java.util.ArrayList;
22import java.util.List;
23
55
56public class House {
57
58 private Player player;
59
60 private BuildableMap map;
61
62 private List<ConstructionObject> OBJECT = new ArrayList<ConstructionObject>();
63
64 private boolean inside;
65
66 private int height;
67
68 public House(Player player) {
69 this.player = player;
70 this.height = /* player.getPlayerAssistant().instance() */0;
71 }
72
73 public void purchase() {
74 if (map != null) {
75 player.dialogueFactory.sendStatement("You already have a house purchased!").execute();
76 return;
77 }
78
79 if (!player.inventory.contains(new Item(995, 1000000))) {
80 player.dialogueFactory.sendStatement("You need 1,000,000 royale tokens to purchase a house.").execute();
81 return;
82 }
83
84 map = BuildableMap.SMALL_CAVE;
85 player.inventory.remove(new Item(995, 1000000));
86 player.dialogueFactory.sendStatement("You have successfully purchased a house for 1,000,000 royale tokens.", "Your house has been set to the default location.").execute();
87 }
88
89 public void location(BuildableMap newMap) {
90 if (map == null) {
91 player.dialogueFactory.sendStatement("Please purchase a house first.").execute();
92 return;
93 }
94
95 if (map == newMap) {
96 player.dialogueFactory.sendStatement("Your house is already set to this location.").execute();
97 return;
98 }
99
100 if (player.skills.getLevel(Skill.CONSTRUCTION) < newMap.getLevel()) {
101 player.dialogueFactory.sendStatement("You need a construction level of " + newMap.getLevel() + " to build this.").execute();
102 return;
103 }
104
105 if (!player.inventory.contains(new Item(995, newMap.getCost()))) {
106 player.dialogueFactory.sendStatement("You need " + newMap.getCost() + " royale tokens to purchase this map.").execute();
107 return;
108 }
109
110 map = newMap;
111 OBJECT.clear();
112 player.inventory.remove(new Item(995, newMap.getCost()));
113 player.dialogueFactory.sendStatement("You have successfully purchased the " + newMap.getName() + " map.").execute();
114 }
115
116 public void enter() {
117 if (map == null) {
118 player.dialogueFactory.sendStatement("You need to purchase a house first.", "Speak to the agent to purchase one.").execute();
119 return;
120 }
121
122 player.send(new SendString("Please wait as your house data is loaded...", 12285));
123 player.send(new SendMinimapState(MinimapState.HIDDEN));
124 player.interfaceManager.open(12283);
125 player.move(new Position(map.getPosition().getX(), map.getPosition().getY(), height));
126 map.execute(player);
127
128 for (ConstructionObject aOBJECT : OBJECT) {
129 new CustomGameObject(aOBJECT.getObject(), aOBJECT.getPosition()).register();
130 }
131
132 World.schedule(2500, () -> {
133 player.send(new SendMinimapState(MinimapState.NORMAL));
134 player.interfaceManager.close();
135 player.send(new SendMessage("Welcome to your house! To start building please click on the world map to enter the", MessageColor.DARK_GREEN));
136 player.send(new SendMessage("Construction Builder itemcontainer. To leave your house please click on the portal.", MessageColor.DARK_GREEN));
137 player.send(new SendString("[CONSTRUCTION_MAP]", 0));
138 });
139
140 inside = true;
141 }
142
143 public void enter(String name) {
144 if (!ProfileRepository.exist(name)) {
145 player.dialogueFactory.sendStatement("According to our data base, this player does not exist.").execute();
146 return;
147 }
148
149 if (!World.search(name).isPresent()) {
150 player.dialogueFactory.sendStatement(Utility.formatName(name) + " is not currently online.").execute();
151 return;
152 }
153
154 Player other = World.search(name).get();
155 House otherHouse = other.house;
156
157 if (otherHouse.getMap() == null) {
158 player.dialogueFactory.sendStatement(Utility.formatName(name) + " does not have a house for you to visit.").execute();
159 return;
160 }
161
162 if (!otherHouse.isInside()) {
163 player.dialogueFactory.sendStatement(Utility.formatName(name) + " must be in their house for you to visit.").execute();
164 }
165
166 player.send(new SendString("Please wait as your friend's house data is loaded...", 12285));
167 player.send(new SendMinimapState(MinimapState.HIDDEN));
168 player.interfaceManager.open(12283);
169 player.move(new Position(other.house.getMap().getPosition().getX(), otherHouse.getMap().getPosition().getY(), otherHouse.getHeight()));
170 otherHouse.getMap().execute(player);
171
172 for (int index = 0; index < otherHouse.getObjects().size(); index++) {
173 new CustomGameObject(otherHouse.getObjects().get(index).getObject(), otherHouse.getObjects().get(index).getPosition()).register();
174 }
175
176 World.schedule(2500, () -> {
177 player.send(new SendMinimapState(MinimapState.NORMAL));
178 player.interfaceManager.close();
179 player.send(new SendMessage("Welcome to your friend's house.", MessageColor.DARK_GREEN));
180 });
181
182 inside = true;
183 }
184
185 public void leave() {
186 if (inside) {
187 inside = false;
188 player.move(new Position(3079, 3484, 0));
189 player.send(new SendString("[NORMAL_MAP]", 0));
190 }
191 }
192
193 public boolean toolkit(GameObject object) {
194 if (!inside) {
195 return false;
196 }
197
198 ConstructionObject constructionObject = null;
199
200 for (int index = 0; index < OBJECT.size(); index++) {
201 if (OBJECT.get(index).getObject() == object.getId() && OBJECT.get(index).getPosition().equals(object.getPosition())) {
202 constructionObject = new ConstructionObject(object.getId(), OBJECT.get(index).getRotation(), object.getPosition());
203 break;
204 }
205 }
206
207 if (constructionObject == null) {
208 return false;
209 }
210
211 player.dialogueFactory.sendOption("Remove object", () -> {
212 // OBJECT.withdraw(constructionObject);
213 object.unregister();
214 }, "Change rotation", () -> {
215 player.dialogueFactory.onAction(() -> {
216 player.dialogueFactory.sendStatement("Please select the rotation direction").sendOption("North", () -> {
217 object.unregister();
218 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.NORTH, ObjectType.GENERAL_PROP).register();
219 }, "East", () -> {
220 object.unregister();
221 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.EAST, ObjectType.GENERAL_PROP).register();
222 }, "West", () -> {
223 object.unregister();
224 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.WEST, ObjectType.GENERAL_PROP).register();
225 }, "South", () -> {
226 object.unregister();
227 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.SOUTH, ObjectType.GENERAL_PROP).register();
228 }, "Nevermind", () -> {
229 player.interfaceManager.close();
230 }).execute();
231
232 });
233 }, "Nevermind", () -> {
234 player.interfaceManager.close();
235 }).execute();
236 return true;
237 }
238
239 public void construct() {
240 BuildableObject object = player.attributes.get("CONSTRUCTION_BUILDOBJECT_KEY", BuildableObject.class);
241
242 if (player.skills.getLevel(Skill.CONSTRUCTION) < object.getLevel()) {
243 player.send(new SendMessage("You need a construction level of " + object.getLevel() + " to build this."));
244 return;
245 }
246
247 // if (!player.inventory.contains(object.getItems())) {
248 // player.send(new SendMessage("You do not have the required item to
249 // build this."));
250 // return;
251 // }
252
253 player.interfaceManager.close();
254 player.animate(new Animation(898));
255 player.inventory.removeAll(object.getItems());
256 CustomGameObject gameObject = new CustomGameObject(object.getObject(), player.getPosition().copy());
257
258 World.schedule(5, () -> {
259 gameObject.register();
260 player.skills.addExperience(Skill.CONSTRUCTION, object.getExperience());
261 OBJECT.add(new ConstructionObject(gameObject.getId(), 0, gameObject.getPosition()));
262 player.send(new SendMessage("You have successfully constructed " + Utility.getAOrAn(gameObject.getName()) + " " + gameObject.getName() + "."));
263 });
264 }
265
266 public BuildableMap getMap() {
267 return map;
268 }
269
270 public void setMap(BuildableMap map) {
271 this.map = map;
272 }
273
274 public List<ConstructionObject> getObjects() {
275 return OBJECT;
276 }
277
278 public void setObject(List<ConstructionObject> object) {
279 OBJECT = object;
280 }
281
282 public boolean isInside() {
283 return inside;
284 }
285
286 public int getHeight() {
287 return height;
288 }
289}
static Optional< Player > search(String name)
Definition World.java:184
static void schedule(Task task)
Definition World.java:284
static String getAOrAn(String nextWord)
Definition Utility.java:153