Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Adding BasicObjectVertex with requirements

Joined
Feb 9, 2019
Messages
44
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 :/

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;
}
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
I'm going to go out on a limb and say you somehow corrupted your local cache containing cached quest states (for quests with undocumented varp states). Or it could have failed to open the quest tab to get information about a quest without varp/varbit state information.
 
Joined
Feb 9, 2019
Messages
44
I don't believe so. The only reason is, that I have also changed the WebRequirement to be something as simple as
Code:
SkillRequirement s = new SkillRequirement(Skill.AGILITY, 75);
and it still passes.

To confirm my WebRequirement was correct, I did the following:
- serialised
- restarted bot
- deserialised
- getVerticesOn(coord)
- cast to basicObject
- get requirement
- cast to SkillRequirement
test the following conditions
Code:
        boolean a = s.isMet();

        boolean b = s.isAlternativeMet(); //depreciated...testing only
        boolean d = s.isMet0();
each of the conditions return false, but the basicObject is still used in the web. If I remove this specific object, then the web does what i would expect and walk around the outside. I did the same tests for the QuestRequirement, they all return false, but the gate is still interacted with.

Final question, does the WebRequirement work with CoordinateVerticies as well? Or anything but?
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
You have to provide the Collection of WebRequirements to the vertex itself during creation. The vertices get added to the web and you then establish edges. Then you serialize the web,, which handles serializing all the vertices, edges, requirements, and so forth. When you deserialize it, all the information is preserved. Requirements work with any type of vertex.
 
Joined
Feb 9, 2019
Messages
44
Sorry to reiterate again.

In the first set of sample code in the first post, the final line (12) shows that I parse in the WebRequirement and it it added the to the BasicObjectVertex upon creation. Following your possible issue with the questing, I mentioned that I changed this to a SkillRequirement instead of a QuestRequirement. The issue was still present.

In my second post I was trying to show my testing regime. That is that the basic object generated originally has been serialised with the WebRequirement in it.

The second post was used to identify the way I confirmed that the requirment was added into the object.

I hope the below will try to be more explicit.
Code:
SerializableWeb webVertexList = SerializableWeb.deserialize(Files.readAllBytes(path));
List<WebVertex> tmpList = webVertexList.getVerticesOn(new Coordinate(3268, 3227, 0));
System.out.println("Collection: " + tmpList);
for (WebVertex v : tmpList) {
    if (v instanceof BasicObjectVertex) {
        BasicObjectVertex basic = (BasicObjectVertex)v;
        Collection<WebRequirement> reqList = basic.getRequirements();
        for (WebRequirement req : reqList) {
            if (req instanceof SkillRequirement) {
                SkillRequirement skillReq = (SkillRequirement)req;
                System.out.println(skillReq.isMet());
                System.out.println(skillReq.isAlternativeMet()); //depreciated...testing only
                System.out.println(skillReq.isMet0());
            }
        }
    }
}

This code prints:
Code:
Collection size: [BasicObjectVertex(^Gate$, ^Pay-toll\(10gp\)$, 3268, 3227, 0, behavior: UNDEFINED)]
false
false
false

But the BasicObjectVertex is still interacted with when building a web.
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
It's going to come down to the edges and vertices all co-existing properly, although I can double check skill requirement for you :), you should define the behavior while you're at it though. And regardless of what I find regrading SkillRequirement, you should still debug the edges.
 
Top