RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
RequestManager.java
1package com.osroyale.game.world.entity.mob.player.requests;
2
3import com.osroyale.net.packet.out.SendMessage;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.game.world.region.Region;
6import com.osroyale.util.Utility;
7
45
46public class RequestManager {
47
49 private Player player;
50
52 private RequestState state = RequestState.NORMAL;
53
55 private RequestType requestType;
56
58 private Player acquaintance;
59
66 public RequestManager(Player player) {
67 this.player = player;
68 }
69
79 public boolean request(Player other, RequestType type) {
80 if (!validate(player) || !validate(other)) {
81 return false;
82 }
83
84 if (!Utility.withinDistance(other, player, Region.VIEW_DISTANCE)) {
85 player.send(new SendMessage("Unable to find " + Utility.formatName(other.getName()) + "."));
86 return false;
87 }
88
89 RequestManager otherManager = other.requestManager;
90
91 if (state == RequestState.PARTICIPATING || otherManager.state == RequestState.PARTICIPATING) {
92 return false;
93 }
94
95 requestType = type;
96 acquaintance = other;
97 state = RequestState.REQUESTED;
98
99 if (mutualRequest(otherManager)) {
101 otherManager.state = RequestState.PARTICIPATING;
102 return true;
103 }
104
105 return false;
106 }
107
115 private boolean validate(Player entity) {
116 return entity != null && !entity.positionChange;
117 }
118
126 private boolean mutualRequest(RequestManager otherManager) {
127 boolean otherRequested = otherManager.state == RequestState.REQUESTED;
128 boolean sameRequestType = requestType == otherManager.requestType;
129 boolean mutualAcquantances = player.equals(otherManager.acquaintance);
130 return otherRequested && sameRequestType && mutualAcquantances;
131 }
132
134 private void reset() {
135 requestType = null;
136 acquaintance = null;
137 state = RequestState.NORMAL;
138 }
139
141 public void close() {
142 reset();
143 }
144
145}