- Joined
- Feb 9, 2019
- Messages
- 44
- Thread Author
- #1
I felt this was more appropriate being on the forums than on discord, since I needed to post a bit of code.
I have created a basic function to add BasicObjectVertex to my own web and it works relatively ok for basic doors and gates. Though I am struggling with the WebRequirement. No matter what requirement I put in, my player still tries to access it even without the approriate level or skill. The below code I know at this stage has "bugs" when interacting with things like ladders, though the above example I thought would've been fine.
Trying to add to the web I have the following 2 examples, the first works fine, but the second that requires the Prince Ali Rescue quest to be completed fails. To be more specific with my test I also tried to enforce an Agility level to the gate for testing reasons.
I am hoping this is something silly I am missing :/
And my function I created for adding the objects.
I have created a basic function to add BasicObjectVertex to my own web and it works relatively ok for basic doors and gates. Though I am struggling with the WebRequirement. No matter what requirement I put in, my player still tries to access it even without the approriate level or skill. The below code I know at this stage has "bugs" when interacting with things like ladders, though the above example I thought would've been fine.
Trying to add to the web I have the following 2 examples, the first works fine, but the second that requires the Prince Ali Rescue quest to be completed fails. To be more specific with my test I also tried to enforce an Agility level to the gate for testing reasons.
I am hoping this is something silly I am missing :/
Code:
//works well without web requirement
WebAddBasicObject(new Coordinate(3014, 3219, 0), "Door", "Open", new Coordinate(3014, 3219, 0), new Coordinate(3014, 3220, 0), Collections.emptyList()); //wizard compton door ardougne
//fails with web reqreuiment
Collection<WebRequirement> c = new ArrayList<WebRequirement>();
//c.add(new QuestRequirement("Prince Ali Rescue", Status.COMPLETE));
SkillRequirement s = new SkillRequirement(Skill.AGILITY, 75);
boolean a = s.isMet();
//debug here and see if 'a' is met. it returns false.
c.add(s);
WebAddBasicObject(new Coordinate(3268, 3227, 0), "Gate", "Pay-toll(10gp)", new Coordinate(3268, 3227, 0), new Coordinate(3267, 3227, 0), c); //Al kharid toll gate
And my function I created for adding the objects.
Code:
private static SerializableWeb webVertexList = ....;
public static boolean WebAddBasicObject(Coordinate object_coordinate, String name, String action, Coordinate outside, Coordinate inside, Collection<WebRequirement> web_req) {
if (!webInitialised) {
System.out.println("Web not initialised");
return false;
}
List<WebVertex> objectCoordinate_ls = webVertexList.getVerticesOn(object_coordinate);
if (objectCoordinate_ls != null) {
for (int i = 0; i < objectCoordinate_ls.size(); i++) {
if (objectCoordinate_ls.get(i) instanceof BasicObjectVertex) {
BasicObjectVertex basicObjVertex_Existing = (BasicObjectVertex)objectCoordinate_ls.get(i);
Pattern pName = basicObjVertex_Existing.getTargetPattern();
Pattern pAction = basicObjVertex_Existing.getActionPattern();
Matcher mName = pName.matcher(name);
Matcher mAction = pAction.matcher(action);
if (mName.matches() && mAction.matches() && object_coordinate.equals(basicObjVertex_Existing.getPosition())) {
System.out.println("BasicObjectVertex ALREADY EXISTS. Name '" + name + "', Action '" + action + "' on" + object_coordinate);
return false;
}
}
}
}
BasicObjectVertex objectVertex = new BasicObjectVertex(object_coordinate, name, action, web_req);
List<WebVertex> outsideVertex_ls = webVertexList.getVerticesOn(outside);
List<WebVertex> insideVertex_ls = webVertexList.getVerticesOn(inside);
if (outsideVertex_ls != null && insideVertex_ls != null) {
CoordinateVertex outsideVertex = null;
CoordinateVertex insideVertex = null;
for (int i = 0; i < outsideVertex_ls.size(); i++) {
if (outsideVertex_ls.get(i) instanceof CoordinateVertex) {
outsideVertex = (CoordinateVertex)outsideVertex_ls.get(i);
}
}
for (int i = 0; i < insideVertex_ls.size(); i++) {
if (insideVertex_ls.get(i) instanceof CoordinateVertex) {
insideVertex = (CoordinateVertex)insideVertex_ls.get(i);
}
}
if (outsideVertex == null || insideVertex == null) {
System.out.println("BasicObjectVertex Not added - Isolated from all others. Name '" + name + "', Action '" + action + "' on" + object_coordinate);
return false;
}
for (WebVertex out : outsideVertex.getOutputs()) {
objectVertex.addDirectedEdge(out);
}
for (WebVertex in : outsideVertex.getInputs()) {
in.addDirectedEdge(objectVertex);
}
objectVertex.addBidirectionalEdge(insideVertex);
webVertexList.addVertices(objectVertex);
System.out.println("BasicObjectVertex ADDED NEW. Name '" + name + "', Action '" + action + "' on" + object_coordinate);
}
return true;
}