Some fix for storage/get/sell Auto sequences

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

iMikeLance
Moderators
Moderators
Posts: 208
Joined: 01 Feb 2010, 17:37
Noob?: No
Location: Brazil - MG

Some fix for storage/get/sell Auto sequences

#1 Post by iMikeLance »

This patch fixed a very old bug where kore would keep trying to move to a cell already occupied by another actor during storageAuto, getAuto and sellAuto sequences. Implemented random distance between defined values and even if there's a player inside defined cell, kore will ignore that it can't reach that cell and use the nearest available.

Removed old "distance" option from config.txt but maintained it's functionality so it shouldn't break existing configurations (won't have random distance, but won't bug too.)

src/AI/CoreLogic.pm

Code: Select all

 Index: src/AI/CoreLogic.pm
===================================================================
--- src/AI/CoreLogic.pm	(revision 8316)
+++ src/AI/CoreLogic.pm	(working copy)
@@ -1143,13 +1143,21 @@
 				$args->{done} = 1;
 				return;
 			}
-
+			if (!AI::args->{distance}) {
+				# Calculate variable or fixed (old) distance
+				if ($config{'storageAuto_minDistance'} && $config{'storageAuto_maxDistance'}) {
+					AI::args->{distance} = $config{'storageAuto_minDistance'} + round(rand($config{'storageAuto_maxDistance'} - $config{'storageAuto_minDistance'}));
+				} else {
+					AI::args->{distance} = $config{'storageAuto_distance'};
+				}
+			}
+			
 			# Determine whether we have to move to the NPC
 			if ($field->baseName ne $args->{npc}{map}) {
 				$do_route = 1;
 			} else {
-				my $distance = distance($args->{npc}{pos}, $char->{pos_to});
-				if ($distance > $config{'storageAuto_distance'}) {
+				my $distance_from_char = distance($args->{npc}{pos}, $char->{pos_to});
+				if (($distance_from_char > AI::args->{distance}) && !defined($args->{sentStore}) && !defined($ai_v{temp}{storage_opened})) {
 					$do_route = 1;
 				}
 			}
@@ -1173,7 +1181,7 @@
 					message TF("Calculating auto-storage route to: %s(%s): %s, %s\n", $maps_lut{$args->{npc}{map}.'.rsw'}, $args->{npc}{map}, $args->{npc}{pos}{x}, $args->{npc}{pos}{y}), "route";
 					ai_route($args->{npc}{map}, $args->{npc}{pos}{x}, $args->{npc}{pos}{y},
 						 attackOnRoute => 1,
-						 distFromGoal => $config{'storageAuto_distance'});
+						 distFromGoal => AI::args->{distance});
 				}
 			}
 		}
@@ -1431,14 +1439,23 @@
 			$args->{'done'} = 1;
 			return;
 		}
-
+		
+		if (!AI::args->{distance}) {
+			if ($config{'sellAuto_standpoint'}) {
+				AI::args->{distance} = 1;
+			} elsif ($config{'sellAuto_minDistance'} && $config{'sellAuto_maxDistance'}) {
+				AI::args->{distance} = $config{'sellAuto_minDistance'} + round(rand($config{'sellAuto_maxDistance'} - $config{'sellAuto_minDistance'}));
+			} else {
+				AI::args->{distance} = $config{'sellAuto_distance'};
+			}
+		}
+		
 		undef $ai_v{'temp'}{'do_route'};
 		if ($field->baseName ne $args->{'npc'}{'map'}) {
 			$ai_v{'temp'}{'do_route'} = 1;
 		} else {
 			$ai_v{'temp'}{'distance'} = distance($args->{'npc'}{'pos'}, $chars[$config{'char'}]{'pos_to'});
-			$config{'sellAuto_distance'} = 1 if ($config{sellAuto_standpoint});
-			if ($ai_v{'temp'}{'distance'} > $config{'sellAuto_distance'}) {
+			if (($ai_v{'temp'}{'distance'} > AI::args->{distance}) && !defined($args->{sentSell})) { #  && !defined($ai_v{temp}{storage_opened})
 				$ai_v{'temp'}{'do_route'} = 1;
 			}
 		}
@@ -1459,7 +1476,7 @@
 	 			message TF("Calculating auto-sell route to: %s(%s): %s, %s\n", $maps_lut{$ai_seq_args[0]{'npc'}{'map'}.'.rsw'}, $ai_seq_args[0]{'npc'}{'map'}, $ai_seq_args[0]{'npc'}{'pos'}{'x'}, $ai_seq_args[0]{'npc'}{'pos'}{'y'}), "route";
 				ai_route($args->{'npc'}{'map'}, $args->{'npc'}{'pos'}{'x'}, $args->{'npc'}{'pos'}{'y'},
 					attackOnRoute => 1,
-					distFromGoal => $config{'sellAuto_distance'},
+					distFromGoal => AI::args->{distance},
 					noSitAuto => 1);
 			}
 		} else {
@@ -1598,12 +1615,22 @@
 		}
 
 		undef $ai_v{'temp'}{'do_route'};
+		if (!AI::args->{distance}) {
+			# Calculate variable or fixed (old) distance
+			if ($config{"buyAuto_$args->{index}"."_standpoint"}) {
+				AI::args->{distance} = 1;
+			} elsif ($config{"buyAuto_".$args->{index}."_minDistance"} && $config{"buyAuto_".$args->{index}."_maxDistance"}) {
+				AI::args->{distance} = $config{"buyAuto_$args->{index}"."_minDistance"} + round(rand($config{"buyAuto_$args->{index}"."_maxDistance"} - $config{"buyAuto_$args->{index}"."_minDistance"}));
+			} else {
+				AI::args->{distance} = $config{"buyAuto_$args->{index}"."_distance"};
+			}
+		}
+		
 		if ($field->baseName ne $args->{'npc'}{'map'}) {
 			$ai_v{'temp'}{'do_route'} = 1;
 		} else {
 			$ai_v{'temp'}{'distance'} = distance($args->{'npc'}{'pos'}, $chars[$config{'char'}]{'pos_to'});
-			$config{"buyAuto_$args->{index}"."_distance"} = 1 if ($config{"buyAuto_$args->{index}"."_standpoint"});
-			if ($ai_v{'temp'}{'distance'} > $config{"buyAuto_$args->{index}"."_distance"}) {
+			if (($ai_v{'temp'}{'distance'} > AI::args->{distance}) && !defined($args->{sentBuy})) {
 				$ai_v{'temp'}{'do_route'} = 1;
 			}
 		}
@@ -1632,7 +1659,7 @@
  				message TF($msgneeditem."Calculating auto-buy route to: %s (%s): %s, %s\n", $maps_lut{$args->{npc}{map}.'.rsw'}, $args->{npc}{map}, $args->{npc}{pos}{x}, $args->{npc}{pos}{y}), "route";
 				ai_route($args->{npc}{map}, $args->{npc}{pos}{x}, $args->{npc}{pos}{y},
 					attackOnRoute => 1,
-					distFromGoal => $config{"buyAuto_$args->{index}"."_distance"});
+					distFromGoal => AI::args->{distance});
 			}
 		} else {
 			if ($args->{lastIndex} eq "" || $args->{lastIndex} != $args->{index}) {
control/config.txt

Code: Select all

Index: config.txt
===================================================================
--- config.txt	(revision 8316)
+++ config.txt	(working copy)
@@ -622,7 +622,8 @@
 buyAuto {
 	npc
 	standpoint
-	distance 5
+	minDistance 3
+	maxDistance 7
 	price
 	minAmount 2
 	maxAmount 3
@@ -631,11 +632,13 @@
 sellAuto 0
 sellAuto_npc
 sellAuto_standpoint
-sellAuto_distance 5
+sellAuto_minDistance 3
+sellAuto_maxDistance 7
 
 storageAuto 0
 storageAuto_npc
-storageAuto_distance 5
+storageAuto_minDistance 3
+storageAuto_maxDistance 7
 storageAuto_npc_type 1
 storageAuto_npc_steps
 storageAuto_password
Patched files: https://www.dropbox.com/s/c6acxvwtxuckk ... ces_v2.exe
flashdbest
Plain Yogurt
Plain Yogurt
Posts: 61
Joined: 12 Nov 2012, 09:22
Noob?: Yes

Re: Some fix for storage/get/sell Auto sequences

#2 Post by flashdbest »

Hi mike,

wouldn't it be better it we have just one minDistance / maxDistance for all NPC interactions? :)

well just a suggestion :P
iMikeLance
Moderators
Moderators
Posts: 208
Joined: 01 Feb 2010, 17:37
Noob?: No
Location: Brazil - MG

Re: Some fix for storage/get/sell Auto sequences

#3 Post by iMikeLance »

flashdbest wrote:Hi mike,

wouldn't it be better it we have just one minDistance / maxDistance for all NPC interactions? :)

well just a suggestion :P
We could have a global one but we still need to keep specific distance for these sequences. There are different NPCs and places where you could need a different distance for each sequence.
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: Some fix for storage/get/sell Auto sequences

#4 Post by EternalHarvest »

iMikeLance wrote:We could have a global one but we still need to keep specific distance for these sequences. There are different NPCs and places where you could need a different distance for each sequence.
Yeah, for example, each portal NPC possibly needs its own distance or standpoint.

But it's a good idea to have a default min/max distance, and to override it where needed.