protected void collision(PhysicalObject o1, PhysicalObject o2) { float materialConstant = 0.9f; float angleO1 = getAngle(o1.dx, o1.dy); float angleO2 = getAngle(o2.dx, o2.dy); float angleBoth = getAngle(o1.X - o2.X, o1.Y - o2.Y); float velocityBefore1 = (float) Math.sqrt(Math.pow(o1.dx, 2) + Math.pow(o1.dy, 2)); float velocityBefore2 = (float) Math.sqrt(Math.pow(o2.dx, 2) + Math.pow(o2.dy, 2)); float velocityAfter1 = (materialConstant * o2.mass * (velocityBefore2 - velocityBefore1) + o1.mass * velocityBefore1 + o2.mass * velocityBefore2) / (o1.mass + o2.mass); float velocityAfter2 = (materialConstant * o1.mass * (velocityBefore1 - velocityBefore2) + o2.mass * velocityBefore2 + o1.mass * velocityBefore1) / (o2.mass + o1.mass); float massSum = o1.mass + o2.mass; angleO1 = angleBoth + angleO1 * (o1.mass / massSum); angleO2 = angleBoth + angleO2 * (o2.mass / massSum); o1.dx = (float) Math.cos(angleO1) * Math.abs(velocityAfter1); o1.dy = (float) Math.sin(angleO1) * Math.abs(velocityAfter1); o2.dx = -(float) Math.cos(angleO2) * Math.abs(velocityAfter2); o2.dy = (float) Math.sin(angleO2) * Math.abs(velocityAfter2); }
/** * Opens the nearest bank if it is within range to walk to it. It does not generate a path to the * bank, just simply opens the nearest. * * @return True if the bank has been opened. */ public boolean openClosestBank() { PhysicalObject booth = botEnv.objects.getClosestObject(20, BANK_BOOTH_IDS); NPC banker = botEnv.npcs.getClosest(20, BANKER_IDS); PhysicalObject chest = botEnv.objects.getClosestObject(20, BANK_CHEST_IDS); Object targetObject = null; String action = null; if (booth != null) { targetObject = booth; action = "Use-quickly"; } else if (banker != null) { targetObject = banker; action = "Bank banker"; } else if (chest != null) { targetObject = chest; action = "Use"; } if (targetObject != null) { NPC targetNPC = null; PhysicalObject targetPhysObject = null; if (targetObject instanceof NPC) { targetNPC = (NPC) targetObject; } else { targetPhysObject = (PhysicalObject) targetObject; } if (targetNPC != null) { if (botEnv.players.getMyPlayer().distanceTo(targetNPC.getLocation()) > 8) { if (botEnv.walking.walkToMM(targetNPC.getLocation())) { sleep(300, 600); while (botEnv.players.getMyPlayer().isMoving()) sleep(100); } else { return false; } } return targetNPC.doAction(action); } else { if (botEnv.players.getMyPlayer().distanceTo(targetPhysObject.getLocation()) > 8) { if (botEnv.walking.walkToMM(targetPhysObject.getLocation())) { sleep(300, 600); while (botEnv.players.getMyPlayer().isMoving()) sleep(100); } else { return false; } } return targetPhysObject.doAction(action); } } return false; }