Jump to content

Moving away from npc


sp3cpk

Recommended Posts

        Area small = entity.getArea(2);
        Area big = entity.getArea(3);
        
        List<Position> positions = big.getPositions();        
        
        if(positions.removeAll(small.getPositions())) {
            Position position = positions.get(new Random().nextInt((positions.size() - 1)));
            if (position != null) {
                WalkingEvent event = new WalkingEvent(position);
                event.setMiniMapDistanceThreshold(0);
                event.setMinDistanceThreshold(0);
                event.setBreakCondition(new Condition() {
                    @Override
                    public boolean evaluate() {
                        return entity.getPosition().distance(myPosition()) >= 3;
                    }
                });
                execute(event);
            }
        }

? I think... ? I have a hunch I over complicated it

Edited by Isolate
Link to comment
Share on other sites

40 minutes ago, Isolate said:

        Area small = entity.getArea(2);
        Area big = entity.getArea(3);
        
        List<Position> positions = big.getPositions();        
        
        if(positions.removeAll(small.getPositions())) {
            Position position = positions.get(new Random().nextInt((positions.size() - 1)));
            if (position != null) {
                WalkingEvent event = new WalkingEvent(position);
                event.setMiniMapDistanceThreshold(0);
                event.setMinDistanceThreshold(0);
                event.setBreakCondition(new Condition() {
                    @Override
                    public boolean evaluate() {
                        return entity.getPosition().distance(myPosition()) >= 3;
                    }
                });
                execute(event);
            }
        }

? I think... ? I have a hunch I over complicated it

It will fail if the position which was chosen at random is unreachable; in both WebWalkEvent or WalkingEvent.

 

WalkingEvent event = new WalkingEvent(Entity entity).setDistanceThreshold(1);
execute(event);

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...