RuneHive-Game
Loading...
Searching...
No Matches
House.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.construction;
2
3import com.runehive.game.Animation;
4import com.runehive.game.world.World;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.entity.mob.player.profile.ProfileRepository;
7import com.runehive.game.world.entity.skill.Skill;
8import com.runehive.game.world.items.Item;
9import com.runehive.game.world.object.CustomGameObject;
10import com.runehive.game.world.object.GameObject;
11import com.runehive.game.world.object.ObjectDirection;
12import com.runehive.game.world.object.ObjectType;
13import com.runehive.game.world.position.Position;
14import com.runehive.net.packet.out.SendMessage;
15import com.runehive.net.packet.out.SendMinimapState;
16import com.runehive.net.packet.out.SendMinimapState.MinimapState;
17import com.runehive.net.packet.out.SendString;
18import com.runehive.util.MessageColor;
19import com.runehive.util.Utility;
20
21import java.util.ArrayList;
22import java.util.List;
23
24public class House {
25
26 private Player player;
27
29
30 private List<ConstructionObject> OBJECT = new ArrayList<ConstructionObject>();
31
32 private boolean inside;
33
34 private int height;
35
37 this.player = player;
38 this.height = /* player.getPlayerAssistant().instance() */0;
39 }
40
41 public void purchase() {
42 if (map != null) {
43 player.dialogueFactory.sendStatement("You already have a house purchased!").execute();
44 return;
45 }
46
47 if (!player.inventory.contains(new Item(995, 1000000))) {
48 player.dialogueFactory.sendStatement("You need 1,000,000 royale tokens to purchase a house.").execute();
49 return;
50 }
51
53 player.inventory.remove(new Item(995, 1000000));
54 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();
55 }
56
57 public void location(BuildableMap newMap) {
58 if (map == null) {
59 player.dialogueFactory.sendStatement("Please purchase a house first.").execute();
60 return;
61 }
62
63 if (map == newMap) {
64 player.dialogueFactory.sendStatement("Your house is already set to this location.").execute();
65 return;
66 }
67
68 if (player.skills.getLevel(Skill.CONSTRUCTION) < newMap.getLevel()) {
69 player.dialogueFactory.sendStatement("You need a construction level of " + newMap.getLevel() + " to build this.").execute();
70 return;
71 }
72
73 if (!player.inventory.contains(new Item(995, newMap.getCost()))) {
74 player.dialogueFactory.sendStatement("You need " + newMap.getCost() + " royale tokens to purchase this map.").execute();
75 return;
76 }
77
78 map = newMap;
79 OBJECT.clear();
80 player.inventory.remove(new Item(995, newMap.getCost()));
81 player.dialogueFactory.sendStatement("You have successfully purchased the " + newMap.getName() + " map.").execute();
82 }
83
84 public void enter() {
85 if (map == null) {
86 player.dialogueFactory.sendStatement("You need to purchase a house first.", "Speak to the agent to purchase one.").execute();
87 return;
88 }
89
90 player.send(new SendString("Please wait as your house data is loaded...", 12285));
92 player.interfaceManager.open(12283);
93 player.move(new Position(map.getPosition().getX(), map.getPosition().getY(), height));
94 map.execute(player);
95
96 for (ConstructionObject aOBJECT : OBJECT) {
97 new CustomGameObject(aOBJECT.getObject(), aOBJECT.getPosition()).register();
98 }
99
100 World.schedule(2500, () -> {
102 player.interfaceManager.close();
103 player.send(new SendMessage("Welcome to your house! To start building please click on the world map to enter the", MessageColor.DARK_GREEN));
104 player.send(new SendMessage("Construction Builder itemcontainer. To leave your house please click on the portal.", MessageColor.DARK_GREEN));
105 player.send(new SendString("[CONSTRUCTION_MAP]", 0));
106 });
107
108 inside = true;
109 }
110
111 public void enter(String name) {
112 if (!ProfileRepository.exist(name)) {
113 player.dialogueFactory.sendStatement("According to our data base, this player does not exist.").execute();
114 return;
115 }
116
117 if (!World.search(name).isPresent()) {
118 player.dialogueFactory.sendStatement(Utility.formatName(name) + " is not currently online.").execute();
119 return;
120 }
121
122 Player other = World.search(name).get();
123 House otherHouse = other.house;
124
125 if (otherHouse.getMap() == null) {
126 player.dialogueFactory.sendStatement(Utility.formatName(name) + " does not have a house for you to visit.").execute();
127 return;
128 }
129
130 if (!otherHouse.isInside()) {
131 player.dialogueFactory.sendStatement(Utility.formatName(name) + " must be in their house for you to visit.").execute();
132 }
133
134 player.send(new SendString("Please wait as your friend's house data is loaded...", 12285));
136 player.interfaceManager.open(12283);
137 player.move(new Position(other.house.getMap().getPosition().getX(), otherHouse.getMap().getPosition().getY(), otherHouse.getHeight()));
138 otherHouse.getMap().execute(player);
139
140 for (int index = 0; index < otherHouse.getObjects().size(); index++) {
141 new CustomGameObject(otherHouse.getObjects().get(index).getObject(), otherHouse.getObjects().get(index).getPosition()).register();
142 }
143
144 World.schedule(2500, () -> {
146 player.interfaceManager.close();
147 player.send(new SendMessage("Welcome to your friend's house.", MessageColor.DARK_GREEN));
148 });
149
150 inside = true;
151 }
152
153 public void leave() {
154 if (inside) {
155 inside = false;
156 player.move(new Position(3079, 3484, 0));
157 player.send(new SendString("[NORMAL_MAP]", 0));
158 }
159 }
160
161 public boolean toolkit(GameObject object) {
162 if (!inside) {
163 return false;
164 }
165
166 ConstructionObject constructionObject = null;
167
168 for (int index = 0; index < OBJECT.size(); index++) {
169 if (OBJECT.get(index).getObject() == object.getId() && OBJECT.get(index).getPosition().equals(object.getPosition())) {
170 constructionObject = new ConstructionObject(object.getId(), OBJECT.get(index).getRotation(), object.getPosition());
171 break;
172 }
173 }
174
175 if (constructionObject == null) {
176 return false;
177 }
178
179 player.dialogueFactory.sendOption("Remove object", () -> {
180 // OBJECT.withdraw(constructionObject);
181 object.unregister();
182 }, "Change rotation", () -> {
183 player.dialogueFactory.onAction(() -> {
184 player.dialogueFactory.sendStatement("Please select the rotation direction").sendOption("North", () -> {
185 object.unregister();
186 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.NORTH, ObjectType.GENERAL_PROP).register();
187 }, "East", () -> {
188 object.unregister();
189 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.EAST, ObjectType.GENERAL_PROP).register();
190 }, "West", () -> {
191 object.unregister();
192 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.WEST, ObjectType.GENERAL_PROP).register();
193 }, "South", () -> {
194 object.unregister();
195 new CustomGameObject(object.getId(), object.getPosition(), ObjectDirection.SOUTH, ObjectType.GENERAL_PROP).register();
196 }, "Nevermind", () -> {
197 player.interfaceManager.close();
198 }).execute();
199
200 });
201 }, "Nevermind", () -> {
202 player.interfaceManager.close();
203 }).execute();
204 return true;
205 }
206
207 public void construct() {
208 BuildableObject object = player.attributes.get("CONSTRUCTION_BUILDOBJECT_KEY", BuildableObject.class);
209
210 if (player.skills.getLevel(Skill.CONSTRUCTION) < object.getLevel()) {
211 player.send(new SendMessage("You need a construction level of " + object.getLevel() + " to build this."));
212 return;
213 }
214
215 // if (!player.inventory.contains(object.getItems())) {
216 // player.send(new SendMessage("You do not have the required item to
217 // build this."));
218 // return;
219 // }
220
221 player.interfaceManager.close();
222 player.animate(new Animation(898));
223 player.inventory.removeAll(object.getItems());
224 CustomGameObject gameObject = new CustomGameObject(object.getObject(), player.getPosition().copy());
225
226 World.schedule(5, () -> {
227 gameObject.register();
228 player.skills.addExperience(Skill.CONSTRUCTION, object.getExperience());
229 OBJECT.add(new ConstructionObject(gameObject.getId(), 0, gameObject.getPosition()));
230 player.send(new SendMessage("You have successfully constructed " + Utility.getAOrAn(gameObject.getName()) + " " + gameObject.getName() + "."));
231 });
232 }
233
235 return map;
236 }
237
238 public void setMap(BuildableMap map) {
239 this.map = map;
240 }
241
242 public List<ConstructionObject> getObjects() {
243 return OBJECT;
244 }
245
246 public void setObject(List<ConstructionObject> object) {
247 OBJECT = object;
248 }
249
250 public boolean isInside() {
251 return inside;
252 }
253
254 public int getHeight() {
255 return height;
256 }
257}
List< ConstructionObject > getObjects()
Definition House.java:242
void setObject(List< ConstructionObject > object)
Definition House.java:246
Class that models a single animation used by an entity.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
static Optional< Player > search(String name)
Gets a player by name.
Definition World.java:147
This class represents a character controlled by a player.
Definition Player.java:125
Handles the profile repository, used for gathering important information for all created profiles.
static boolean exist(String name)
Checks if a profile is registered to the parameter.
Represents a trainable and usable skill.
Definition Skill.java:18
static final int CONSTRUCTION
The construction skill id.
Definition Skill.java:84
The container class that represents an item that can be interacted with.
Definition Item.java:21
Represents a static game object loaded from the map fs.
String getName()
Gets the name of this entity.
void register()
Registers an entity to the World.
Represents a single tile on the game world.
Definition Position.java:14
int getY()
Gets the absolute y coordinate.
Definition Position.java:46
int getX()
Gets the absolute x coordinate.
Definition Position.java:41
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatName(final String input)
Definition Utility.java:645
static String getAOrAn(String nextWord)
A or an.
Definition Utility.java:116
The enumerated type whose elements represent the directions for objects.
The enumerated type whose elements represent all of the object types.
GENERAL_PROP
Represents all kinds of objects, trees, statues, signs, fountains etc.
NORMAL
The default state where the map is visible and clicking is enabled.
HIDDEN
The state where the map is pitch black, and clicking is disabled.
Holds an enum of colors for ease.
default int getId()
Gets the object id.