Jump to content

Mouse Handler


Joseph

Recommended Posts

 
 
import java.util.Random;

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.input.mouse.EntityDestination;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.Condition;
import org.osbot.rs07.utility.ConditionalSleep;

public class MouseHandler {
	/**
	 * I tried to keep hovering and delaying away form each other. 
	 */	
	public static final int SECOND = 1000;	
	public static final int MINUTE = 60 * SECOND;
	
	private Script sI;
	private Random random = new Random();
	
	private boolean multiclicking; 
	private boolean hovering; 
	private boolean delay;		
	
	private long lastUpdated = System.currentTimeMillis();
	private long lastChecked = System.currentTimeMillis();
	private long shouldUpdate = -1;
	
	//add in the string name (OSBot username) boolean so our character has a little profile.
	public MouseHandler(Script sI)	{
		this.sI = sI;
		this.delay = random.nextBoolean(); //shouldAllow(name);
		this.hovering = delay ? false: random.nextBoolean();
		this.multiclicking = random.nextBoolean();
		this.shouldUpdate = this.randomUpdate();
	}
	
	public boolean shouldAllow(String name)	{
		return name.length() % 2 == 0;
	}
	
	public int randomDelay()	{
		return MethodProvider.gRandom(8, 7) * SECOND;
	}
	
	public int randomUpdate()	{
		return MethodProvider.gRandom(40, 20) * MINUTE;
	}
	
	public boolean useDelay()	{
		if (!this.delay)	{	return true;	}
		else{
			new ConditionalSleep(randomDelay())	{
				@Override
				public boolean condition() throws InterruptedException {
					return false;
				}
			}.sleep();
			return true;
		}
	}
	
	public boolean hoverEntity(Entity entity)	{
		if (!hovering)	{
			return true;
		}else{
			if (entity != null)	{
				return entity.hover();
			}else{
				return true;
			}
		}
	}
	
	public boolean multiclicking(Entity entity, final boolean condition)	{
		if (!multiclicking)	{	return true;	}
		else{
			if (entity != null)	{
				return sI.mouse.continualClick(new EntityDestination(sI.bot, entity), 
					new Condition()	{
						@Override
						public boolean evaluate() {
							return condition;
					}});
			}else{
				return true;
			}
		}		
	}
	
	public long getTimeLeft()	{
		long time = this.shouldUpdate - (System.currentTimeMillis() - this.lastUpdated);
		return time > 0 ? time: -1;
	}
	
	public void update()	{
		if (System.currentTimeMillis() - this.lastChecked > MINUTE)	{
			this.lastChecked = System.currentTimeMillis();
			if (getTimeLeft() < 0)	{
				this.hovering = random.nextBoolean();
				this.delay = hovering ? false: random.nextBoolean();
				this.multiclicking = random.nextBoolean();
				this.lastUpdated = System.currentTimeMillis();
				this.shouldUpdate = this.randomUpdate();				
			}
		}
	}
	
	public boolean allowHovering()	{
		return this.hovering;
	}
	
	public boolean allowDelay()	{
		return this.delay;
	}
	
	public boolean allowMulticlicking()	{
		return this.multiclicking;
	}
}

 

Edited by josedpay
  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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