Welcome!

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

Sign up now!

Resolved BasicObjectVertex issues

Joined
Sep 30, 2015
Messages
86
More custom web issues. I used Clouds Tutorial.

This is what i'm using to add the vertices:
Code:
    public void addCaveVertices() {
        Caves[] caves = Caves.values();
        for (Caves cave : caves) {
            Coordinate s = cave.getSurfaceObject().getPosition().getPosition();
            Coordinate u = cave.getUnderGroundObject().getPosition();

            WebVertex sNearestVertex = web.getVertexNearestTo(s);
            WebVertex uNearestVertex = web.getVertexNearestTo(u);

            if (sNearestVertex != null && uNearestVertex != null) {
                if (Distance.between(s, sNearestVertex.getPosition()) < 3 || Distance.between(s, uNearestVertex.getPosition()) < 3) {
                    sNearestVertex.addBidirectionalEdge(cave.getSurfaceObject());
                    uNearestVertex.addBidirectionalEdge(cave.getUnderGroundObject());
                    cave.getSurfaceObject().addBidirectionalEdge(cave.getUnderGroundObject());
                    web.addVertices(cave.getSurfaceObject(), cave.getUnderGroundObject());
                    script.debug("[tWeb] [Caves] Added: " + cave.name());
                    debug(sNearestVertex);
                }
            }
        }
    }

Here's the Caves enum:
Code:
package com.twinki.twinkiAPI.rs3.tWeb;

import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.location.navigation.web.vertex_types.objects.BasicObjectVertex;

/**
* @author Twinki
*/

public enum Caves {

    Asgarnian_Ice_Dungeon(new BasicObjectVertex(new Coordinate(3008, 3150, 0), "Trapdoor", "Climb-down"), new BasicObjectVertex(new Coordinate(3008, 9550, 0), "Ladder", "Climb-up")),
    Ice_Mountain_Dwarven_Mine(new BasicObjectVertex(new Coordinate(3019, 3450, 0), "Ladder", " Climb-down"), new BasicObjectVertex(new Coordinate(3019, 9850, 0), "Ladder", "Climb-up"));

    private BasicObjectVertex surfaceObject;
    private BasicObjectVertex underGroundObject;

    Caves(BasicObjectVertex surfaceObject, BasicObjectVertex underGroundObject){
        this.surfaceObject = surfaceObject;
        this.underGroundObject = underGroundObject;
    }

    public BasicObjectVertex getSurfaceObject(){
        return this.surfaceObject;
    }

    public BasicObjectVertex getUnderGroundObject(){
        return this.underGroundObject;
    }

}

Here's what i'm using to walk:
Code:
    public boolean walkToArea(Area area) {
        WebPath pathFail = null;
        if (web != null) {
            pathFail = web.getPathBuilder().buildTo(area.getCenter().getArea().getRandomCoordinate());
            if (pathFail != null)
                pathFail.step();
        }
        debug(pathFail);
        return area.contains(Players.getLocal());
    }

Here's the path debug:
[DEBUG] WebPath[CoordinateVertex(3020, 3451, 0) -> CoordinateVertex(3020, 3450, 0) -> BasicObjectVertex(3019, 3450, 0) -> BasicObjectVertex(3019, 9850, 0) -> CoordinateVertex(3020, 9850, 0) -> CoordinateVertex(3020, 9848, 0) -> CoordinateVertex(3020, 9846, 0) -> CoordinateVertex(3021, 9846, 0)]

It keeps trying to walk to the same coordinate over and over again, even if the player is on the coordinate. The Ice Dungeon worked fine if I offset the coordinate by -1, but the Ice Mountain refuses to work and just gets stuck and generates the same path over and over from the Ladder on the surface.

@Aidden @Arbiter
 
Joined
Sep 30, 2015
Messages
86
Please note I was using this only for "Caves" or "Dungeons" (Objects you'd click on, that'd transport you into a cave or dungeon, I doubt this method will work for surface obstacles like Edgy-GE wall obstacle)

To solve the issue:

When you're adding vertexes (eg WebVertex sNearestVertex = this.web.getVertexNearestTo(ObjectPos1) ) make sure you cache ObjectPos1 with an offset of the Object position where it's right before the object (Where you'd walk to when clicking the object, then using/animating then loading into whatever new plane/region)

Code:
    public void addCaveVertices() {
        Caves[] caves = Caves.values();
        for (Caves cave : caves) {

            BasicObjectVertex surf = cave.getSurfaceObject();
            BasicObjectVertex under = cave.getUnderGroundObject();

            Coordinate sPos = surf.getPosition().derive(cave.getDeriveXsurf(), cave.getDeriveYsurf(), cave.getDerivePlanesurf());
            Coordinate uPos = under.getPosition().derive(cave.getDeriveXunder(), cave.getDeriveYunder(), cave.getDerivePlaneunder());

            WebVertex sNearestVertex = this.web.getVertexNearestTo(sPos);
            WebVertex uNearestVertex = this.web.getVertexNearestTo(uPos);

            if (sNearestVertex != null && uNearestVertex != null) {
                if (Distance.between(sPos, sNearestVertex.getPosition()) < 5 && Distance.between(uPos, uNearestVertex) < 5) {
                    sNearestVertex.addBidirectionalEdge(surf);
                    uNearestVertex.addBidirectionalEdge(under);

                    surf.addBidirectionalEdge(under);
                    this.web.addVertices(surf, under);
                    script.debug("[TwinkiWeb] [Caves] Added: " + cave.name());
                }
            }
        }

That's what I use for adding Caves via enum, each cave I want to add I have to come up with the offset to provide for each entrance/exit.
This is what it one of the Caves enum entries looks like:

Code:
Asgarnian_Ice_Dungeon(new BasicObjectVertex(new Coordinate(3008, 3150, 0), "Trapdoor", "Climb-down"), +1, 0, 0, new BasicObjectVertex(new Coordinate(3008, 9550, 0), "Ladder", "Climb-up"), +1, 0, 0),

Caves(BasicObjectVertex surfaceObject, int deriveXsurf, int deriveYsurf, int derivePlanesurf, BasicObjectVertex underGroundObject, int deriveXunder, int deriveYunder, int derivePlaneunder){

Thanks for the reminder @Arbiter
 
Top