refineAuto plugin for Openkore v2.0.0

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

Message
Author
fco2783
Plain Yogurt
Plain Yogurt
Posts: 95
Joined: 05 Apr 2008, 05:15
Noob?: Yes
Location: in place where you cant go
Contact:

refineAuto plugin for Openkore v2.0.0

#1 Post by fco2783 »

Code: Select all

# refineAuto.pl
# 
# Automated Mass Refining
# version 0.0.1
# Openkore 2.0.0

package refineAuto;

use strict;
use Plugins;
use Globals;
use AI;
use Log;
use Actor::Item;
use Network::Send;
use Misc;

# Config keys used:
# refineAuto			enable/disable auto refining
# refineAuto_npc			refiner npc
# refineAuto_distance		distence to stand from npc
# refineAuto_maxRefine		maximum refining rate
# refineAuto_npc_steps		npc talking sequence when refining
# refineAuto_equip		equipment name that will be refined, without +
# refineAuto_useMagnifier	enable item identification with magnifier
# refineAuto_material		materials needed to refine
# refineAuto_minZenny		minimum amount of zenny needed to refine
# refineAuto_getAutoAdjust	automatically adjusts getAuto
# refineAuto_incremental	when incremental refining should start
# refineAuto_dcWhenDone		disconnect if resources are depleted

Plugins::register('autorefine', 'automatic refining', \&unload_callback);
my $plugin_hook = Plugins::addHook("AI_pre", \&autorefine);

sub autorefine {
	# Initiate autorefine, AI must be idle
	if ($config{'refineAuto'} && AI::isIdle) {
		AI::queue('refineAuto');
		Log::message "refineAuto initiated\n";
	} elsif (AI::is('refineAuto')) {
		my $args = AI::args;

		if (!$args->{npc}) {
			$args->{npc} = {};
			main::getNPCInfo($config{refineAuto_npc}, 
					 $args->{npc});
		}
		# Move to NPC if needed
		elsif (($field{name} ne $args->{npc}{map})
			|| ((Utils::distance($args->{npc}{pos}, $char->{pos_to})
			    > $config{refineAuto_distance}))) {
			    
			Log::message "Calculating refineAuto route to: " .
				     "$maps_lut{$args->{npc}{map}.'.rsw'}" .
				     "($args->{npc}{map}): " .
				     "$args->{npc}{pos}{x}, " .
				     "$args->{npc}{pos}{y}\n", "route";
			main::ai_route($args->{npc}{map}, $args->{npc}{pos}{x},
				       $args->{npc}{pos}{y},
				       distFromGoal => 
				       		$config{refineAuto_distance});
		} else {
		# We arrived at refiner
			
			# Check arguments for incremental refining
			# If refineAuto_incremental is invalid or not specified
			# Set refineAuto_incremental to maxRefine

			if (!($config{refineAuto_incremental} > 0
			      && $config{refineAuto_incremental}
			         < $config{refineAuto_maxRefine})) {
				 
				$config{refineAuto_incremental} = 
					$config{refineAuto_maxRefine};
			}
			
			# Equipped and ready to refine
			if ($args->{equip}) {
				refine_item($args);
			}
			
			# Check if we have all the requirements
			elsif (check_requirements($args)) {
				equip_item($args);
			}
		}
	}
}

sub refine_item {
	my $args = shift;

	Log::message "Trying to refine $args->{equip}{name}\n";

	if ($args->{refine} < $config{refineAuto_incremental}) {
		main::ai_talkNPC($args->{npc}{pos}{x}, $args->{npc}{pos}{y},
				 $config{refineAuto_npc_steps});
		Log::message "Refining $args->{equip}{name}\n";
		$args->{equip} = undef;
		$args->{refine} = undef;
	}
}

sub equip_item {
	my $args = shift;
	my $i;
	my $item;
	my $type;
	my $refine;

	$args->{equip} = undef;
	$args->{refine} = undef;

	for ($i = 0; $i < @{$char->{inventory}}; $i++) {
		$item = $char->{inventory}[$i];
		next unless $item && %{$item};

		$type = $item->{type};
		# Check if it is an equipment, refer to tables/itemtypes.txt
		if ($type == 4 || $type == 5 || $type == 11 || $type == 8
		 || $type == 9) {
		 	# Check if it is the right equipment
			if ($item->{name} =~ 
			    m/(\Q$config{refineAuto_equip}\E)/) {
				
				Log::message "Trying to equip $1\n";
				# Check its current refine rate
				$refine = $item->{name} =~ m/^\+(\d)/ ? $1 : 0;
				if ($refine < $config{refineAuto_incremental}) {
					identify_item($item);
					
					# If this doesn't work, just sendEquip
					$item->equip;

					$args->{equip} = $item;
					$args->{refine} = $refine;
					
					Log::message "Item equipped\n";
					return;
				}
			}
		}
	}
}

# Assumes proper configuration
sub identify_item {
	my $item = shift;
	
	# Check if the item is already Identified
	if ($item->{identified}) {
		return;
	}
}

sub check_requirements {
	my $args = shift;
	
	$args->{retry} = 0 unless defined $args->{retry};
	$args->{getPlus} = 0 unless defined $args->{getPlus};
	
	# Item shortage after 3 retries
	if ($args->{retry} > 3) {
		if ($config{refineAuto_incremental} > 0
		    && $config{refineAuto_incremental}
		       < $config{refineAuto_maxRefine}) {
		       $args->{retry} = 0;
		       $config{refineAuto_incremental} += 1;
		} else {
			done_refine();
		}
	}
	
	# Automatic getAuto adjustment, only done when storage auto failed
	if ($config{refineAuto_getAutoAdjust} == 1 && $args->{retry} > 1
	    && $args->{getPlus} < $config{refineAuto_incremental}) {
		# Look for getAuto index to adjust
		my $i = 0;
		my $done = 0;
		while ($config{"getAuto_$i"} ne "") {
			if ($config{"getAuto_$i"} =~ 
				m/(\Q$config{refineAuto_equip}\E)/) {
				
				my $prefix = ($args->{getPlus} == 0) ? 
					     "" : "+$args->{getPlus} ";
					
				$config{"getAuto_$i"} = $prefix .
						$config{refineAuto_equip};
				Log::message 'getAuto adjusted\n';
				$args->{getPlus} += 1;
				$args->{retry} = 0;
				$done = 1;
			}
			last if $done;
			$i++;
		}
	}
	
	# Check for config
	if ($config{refineAuto_equip}
	    && $config{refineAuto_material}
	    && $config{refineAuto_minZenny}) {
	    	my $material = Actor::Item::get($config{refineAuto_material}, 0, 1);
		my $equip = undef;
		my $want_magnifier = undef;
		my $plus;
		
		# Check for equipment, starting from +0 to max
		for ($plus = 0; 
		     $plus < $config{refineAuto_incremental}; $plus++) {
			my $prefix = ($plus == 0) ? "" : "+$plus ";
			$equip = Actor::Item::get($prefix .
					   $config{refineAuto_equip}, 0, 0);
			last if defined $equip;
		}
		
		if ($config{refineAuto_useMagnifier}) {
			if (!defined Actor::Item::get("Magnifier", 0, 1)) {
				$want_magnifier = 1;
			}
		} elsif ($char->{skills}{MC_IDENTIFY}{lv} != 1) {
			Log::message "No Identify skill, magnifier is needed";
			$config{refineAuto_useMagnifier} = 1;
			return 0;
		}
		
		if (defined $material
		    && defined $equip
		    && $char->{zenny} >= $config{refineAuto_minZenny}
		    && !$want_magnifier) {
		    	$args->{retry} = 0;
		    	return 1;
		} elsif ($char->{zenny} < $config{refineAuto_minZenny}) {
			done_refine();
		} elsif ($args->{retry} > 0 && !defined $material) {
			done_refine();
		} else {
			if ($config{refineAuto_visitStorage} != 0) {
				AI::queue("storageAuto");
			}
			$args->{retry} += 1;
		}


	} else {
		Log::message "Incomplete configuration for refineAuto\n";
	}
	return 0;   
}

sub done_refine {
	if ($config{refineAuto_dcWhenDone}) {
		Misc::quit();
	} else {
		AI::dequeue();
	}
}

sub unload_callback {
}

return 1;
Usage
refineAuto 1
refineAuto_npc alberta_in 28 58
refineAuto_distance 5
refineAuto_maxRefine 7
refineAuto_npc_steps r5 r0 r0
refineAuto_equip Boots [1]
refineAuto_material Elunium
refineAuto_minZenny 2000
refineAuto_incremental 4
refineAuto_getAutoAdjust 0
refineAuto_dcWhenDone 0
refineAuto_visitStorage 0
Last edited by fco2783 on 26 Apr 2008, 22:43, edited 1 time in total.

rayz3r
Noob
Noob
Posts: 15
Joined: 08 Apr 2008, 01:09

Re: refineAuto plugin

#2 Post by rayz3r »

can u post the same thing without ID passes as a file available for download???

i know the NPC configs that aint a problem but the others are..m not so good @ plugins...

Thanks :)
ImageImageImage

]-[ëàVén Ðóé$ñT wäñt më , ]-[ëll Fëàя$ I'll Ŧáќё Övėя

jones2323
Human
Human
Posts: 26
Joined: 07 Apr 2008, 02:55
Noob?: Yes
Location: Under the bridge

Re: refineAuto plugin

#3 Post by jones2323 »

@fco2783
Has the plugin you placed here been tested on 2.0.5.1, or is this the original one that if im not mistaken worked last with 1.9.4(or was it 1.9.3?)
Image

acemg
Noob
Noob
Posts: 9
Joined: 08 Apr 2008, 22:36

Re: refineAuto plugin

#4 Post by acemg »

No questions about it, works perfectly with my 2.0.5.1.

jones2323
Human
Human
Posts: 26
Joined: 07 Apr 2008, 02:55
Noob?: Yes
Location: Under the bridge

Re: refineAuto plugin

#5 Post by jones2323 »

Cool. Thanks
Image

micram
Noob
Noob
Posts: 7
Joined: 06 Apr 2008, 19:58

Re: refineAuto plugin

#6 Post by micram »

my fella what will i put in my config.txt im having difficulty in using it.

jones2323
Human
Human
Posts: 26
Joined: 07 Apr 2008, 02:55
Noob?: Yes
Location: Under the bridge

Re: refineAuto plugin

#7 Post by jones2323 »

the main code (the 1st code) you put in the plugins folder with the .pl extension, the second code you use in you config.txt
Image

gabby
Noob
Noob
Posts: 6
Joined: 07 Apr 2008, 09:23

Re: refineAuto plugin

#8 Post by gabby »

correct me if im wrong... this plugin will refine an equipment to +7 straight.. so if i change the refineAuto_maxRefine to 5, then it will stop at 5...
EDIT:

i figure it out... hehe... but it shows me some error... the console quickly exits upon initialization of plugin... ill troubleshoot this first myself... if i cant ill post it here... ^^

eunice101
Noob
Noob
Posts: 11
Joined: 09 Apr 2008, 04:03
Noob?: Yes
Location: phils!

Re: refineAuto plugin

#9 Post by eunice101 »

excuse me.. exactlky what's wrong with what i did?

i copied 1st code to plugins folder (yes I used .pl)

then the 2nd code to my config..

when openkore starts..it says the plugin initiated something(refineauto)
but then do nothing...the bot doesnt start talking to the refiner.. why?...

++ do i still have to edit the code? the .pl one?
Image

Image

jones2323
Human
Human
Posts: 26
Joined: 07 Apr 2008, 02:55
Noob?: Yes
Location: Under the bridge

Re: refineAuto plugin

#10 Post by jones2323 »

Im guessing you directly copy pasted the second code in config.txt and didnt bother configuring it. you have to edit the .pl one in anyway
Image

Post Reply