1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Adding BasicObjectVertex with requirements

Discussion in 'Developer Support' started by lb25, Jan 17, 2020.

  1. lb25

    Joined:
    Feb 9, 2019
    Messages:
    44
    Likes Received:
    3
    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 (Text):
    1. //works well without web requirement
    2. WebAddBasicObject(new Coordinate(3014, 3219, 0), "Door", "Open", new Coordinate(3014, 3219, 0), new Coordinate(3014, 3220, 0), Collections.emptyList());    //wizard compton door ardougne
    3.  
    4. //fails with web reqreuiment
    5. Collection<WebRequirement> c = new ArrayList<WebRequirement>();
    6. //c.add(new QuestRequirement("Prince Ali Rescue", Status.COMPLETE));
    7. SkillRequirement s = new SkillRequirement(Skill.AGILITY, 75);
    8. boolean a = s.isMet();
    9. //debug here and see if 'a' is met. it returns false.      
    10. c.add(s);
    11.  
    12. 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 (Text):
    1. private static SerializableWeb webVertexList = ....;
    2. public static boolean WebAddBasicObject(Coordinate object_coordinate, String name, String action, Coordinate outside, Coordinate inside, Collection<WebRequirement> web_req) {
    3.     if (!webInitialised) {
    4.         System.out.println("Web not initialised");
    5.         return false;
    6.     }
    7.  
    8.     List<WebVertex> objectCoordinate_ls = webVertexList.getVerticesOn(object_coordinate);
    9.  
    10.     if (objectCoordinate_ls != null) {
    11.         for (int i = 0; i < objectCoordinate_ls.size(); i++) {
    12.             if (objectCoordinate_ls.get(i) instanceof BasicObjectVertex) {
    13.                 BasicObjectVertex basicObjVertex_Existing = (BasicObjectVertex)objectCoordinate_ls.get(i);
    14.  
    15.                 Pattern pName = basicObjVertex_Existing.getTargetPattern();
    16.                 Pattern pAction = basicObjVertex_Existing.getActionPattern();
    17.                 Matcher mName = pName.matcher(name);
    18.                 Matcher mAction = pAction.matcher(action);
    19.  
    20.                 if (mName.matches() && mAction.matches() && object_coordinate.equals(basicObjVertex_Existing.getPosition())) {
    21.                     System.out.println("BasicObjectVertex ALREADY EXISTS. Name '" + name + "', Action '" + action + "' on" + object_coordinate);
    22.                     return false;
    23.                 }
    24.             }
    25.         }
    26.     }
    27.  
    28.     BasicObjectVertex objectVertex = new BasicObjectVertex(object_coordinate, name, action, web_req);
    29.     List<WebVertex> outsideVertex_ls = webVertexList.getVerticesOn(outside);
    30.     List<WebVertex> insideVertex_ls = webVertexList.getVerticesOn(inside);
    31.  
    32.     if (outsideVertex_ls != null && insideVertex_ls != null) {
    33.         CoordinateVertex outsideVertex = null;
    34.         CoordinateVertex insideVertex = null;
    35.  
    36.         for (int i = 0; i < outsideVertex_ls.size(); i++) {
    37.             if (outsideVertex_ls.get(i) instanceof CoordinateVertex) {
    38.                 outsideVertex = (CoordinateVertex)outsideVertex_ls.get(i);
    39.             }
    40.         }
    41.  
    42.         for (int i = 0; i < insideVertex_ls.size(); i++) {
    43.             if (insideVertex_ls.get(i) instanceof CoordinateVertex) {
    44.                 insideVertex = (CoordinateVertex)insideVertex_ls.get(i);
    45.             }
    46.         }
    47.  
    48.         if (outsideVertex == null || insideVertex == null) {
    49.             System.out.println("BasicObjectVertex Not added - Isolated from all others. Name '" + name + "', Action '" + action + "' on" + object_coordinate);
    50.             return false;
    51.         }
    52.        
    53.  
    54.         for (WebVertex out : outsideVertex.getOutputs()) {
    55.             objectVertex.addDirectedEdge(out);
    56.         }
    57.  
    58.         for (WebVertex in : outsideVertex.getInputs()) {
    59.             in.addDirectedEdge(objectVertex);
    60.         }
    61.  
    62.  
    63.         objectVertex.addBidirectionalEdge(insideVertex);
    64.         webVertexList.addVertices(objectVertex);
    65.         System.out.println("BasicObjectVertex ADDED NEW. Name '" + name + "', Action '" + action + "' on" + object_coordinate);
    66.     }
    67.    
    68.     return true;
    69. }
     
  2. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    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.
     
  3. lb25

    Joined:
    Feb 9, 2019
    Messages:
    44
    Likes Received:
    3
    I don't believe so. The only reason is, that I have also changed the WebRequirement to be something as simple as
    Code (Text):
    1. 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 (Text):
    1.         boolean a = s.isMet();
    2.  
    3.         boolean b = s.isAlternativeMet(); //depreciated...testing only
    4.         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?
     
  4. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    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.
     
  5. lb25

    Joined:
    Feb 9, 2019
    Messages:
    44
    Likes Received:
    3
    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 (Text):
    1.  
    2. SerializableWeb webVertexList = SerializableWeb.deserialize(Files.readAllBytes(path));
    3. List<WebVertex> tmpList = webVertexList.getVerticesOn(new Coordinate(3268, 3227, 0));
    4. System.out.println("Collection: " + tmpList);
    5. for (WebVertex v : tmpList) {
    6.     if (v instanceof BasicObjectVertex) {
    7.         BasicObjectVertex basic = (BasicObjectVertex)v;
    8.         Collection<WebRequirement> reqList = basic.getRequirements();
    9.         for (WebRequirement req : reqList) {
    10.             if (req instanceof SkillRequirement) {
    11.                 SkillRequirement skillReq = (SkillRequirement)req;
    12.                 System.out.println(skillReq.isMet());
    13.                 System.out.println(skillReq.isAlternativeMet()); //depreciated...testing only
    14.                 System.out.println(skillReq.isMet0());
    15.             }
    16.         }
    17.     }
    18. }
    19.  
    This code prints:
    Code (Text):
    1. Collection size: [BasicObjectVertex(^Gate$, ^Pay-toll\(10gp\)$, 3268, 3227, 0, behavior: UNDEFINED)]
    2. false
    3. false
    4. false
    But the BasicObjectVertex is still interacted with when building a web.
     
  6. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    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.
     

Share This Page

Loading...