Jump to content

Combat script overflowing


Athylus

Recommended Posts

Not sure what is happening here. My RAM is filling up and processor usage is skyrocketing. What is going wrong here?

public class Combat extends Script {
	
	private Player me; 
	private boolean changeToAttack = true;
	private boolean changeToDefence = true;
	
	private enum State {
		ATTACK, EAT
	}
	
	private State getState() {
		if (getSkills().getDynamic(Skill.HITPOINTS) < 4) {
			return State.EAT;
		} else if (!getCombat().isFighting()) {
			return State.ATTACK;
		} else {
			return null;
		}
	}
	
	@Override
    public void onStart() {
    	log("Welcome!");
    	me = getPlayers().myPlayer();
    }

    @Override
    public void onExit() {
        
    }
    
	@Override
	public int onLoop() throws InterruptedException {
		
		switch(getState()) {
		case ATTACK:
			Attack();
			break;
		case EAT:
			Eat();
			break;
		default:
			break;
		}
		return 225;
	}
	
	
	
	private void Eat() {
		// TODO Auto-generated method stub
		
	}

	private void Attack() {
		
		/*
		if (changeToAttack) {
			if (getSkills().getStatic(Skill.STRENGTH) > 9) {
				if (getWidgets().interact(548, 48, null)) {
					if (getWidgets().interact(593, 3, null)) {
						changeToAttack = false;
					}
				}
			} 
		}
		
		if (changeToDefence) {
			if (getSkills().getStatic(Skill.STRENGTH) > 9 && getSkills().getStatic(Skill.ATTACK) > 9) {
				if (getWidgets().interact(548, 48, null)) {
					if (getWidgets().interact(593, 15, null)) {
						changeToDefence = false;
					}
				}
			} 
		}
		*/
		
		@SuppressWarnings("unchecked")
		NPC monster = getNpcs().closest(new Filter<NPC>() {
			@Override
			public boolean match(NPC npc) {
				 return npc != null && npc.getName().equals("Chicken") && npc.exists()
	                        && getMap().canReach(npc) && npc.getHealthPercent() > 0 && npc.getInteracting() == null;
			}
		});
		
		if (monster.isVisible()) {
			if (monster.hasAction("Attack")) {
				if (monster.interact("Attack")) {
					try {
						Thread.sleep(3000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

	@Override
	public void onPaint(Graphics2D g) {
		
		/*
		List<Position> areaList = choppingArea.getPositions();

		g.setColor(Color.GREEN);
		for (int i = 0; i < areaList.size(); i++) {
			g.draw(areaList.get(i).getPolygon(getBot()));
		}
		*/

	}
}

 

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...