Incorrect Amount of Inventory Items with same name

This place is for Closed bug reports only. NOT for asking help!

Moderators: Moderators, Developers

sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

Incorrect Amount of Inventory Items with same name

#1 Post by sofax222 »

When some multi items with same name in inventory, openkore will get the incrrect amount of item.

Thers 3 bluks of code / 2 files of .pm should be change:
In src/InventoryList.pm, should add a "sumByName" sub at the bottom of src/InventoryList.pm.

Code: Select all

// total amount of the same name items
sub sumByName {
	my ($self, $name) = @_;
	assert(defined $name) if DEBUG;
	my $sum = 0;
	foreach my $item (@{$self->getItems()}) {
		if ($item->{name} eq $name) {
			$sum = $sum + $item->{amount};
		}
	}

	return $sum;
}
In src/AI/CoreLogic.pm, should change the codes for :
1. check the "minAmount" of "getAuto" of inventory item for auto-storaging.
Original Code

Code: Select all

.....
			my $item = $char->inventory->getByName($config{"getAuto_$i"});
			if ($config{"getAuto_${i}_minAmount"} ne "" &&
			    $config{"getAuto_${i}_maxAmount"} ne "" &&
			    !$config{"getAuto_${i}_passive"} &&
			    (!$item ||
				 ($item->{amount} <= $config{"getAuto_${i}_minAmount"} &&
				  $item->{amount} < $config{"getAuto_${i}_maxAmount"})
			    )
			) {
.....
New Code

Code: Select all

.....
			my $item = $char->inventory->getByName($config{"getAuto_$i"});
			my $amount = $char->inventory->sumByName($config{"getAuto_$i"}); // total amount of the same name items
			if ($config{"getAuto_${i}_minAmount"} ne "" &&
			    $config{"getAuto_${i}_maxAmount"} ne "" &&
			    !$config{"getAuto_${i}_passive"} &&
			    (!$item ||
				 ($amount <= $config{"getAuto_${i}_minAmount"} &&
				  $amount < $config{"getAuto_${i}_maxAmount"})
			    )
			) {
.....
2. Taking items from storage, check the "maxAmount" of "getAuto" of inventory item.
Original Code

Code: Select all

.....
					my $invItem = $char->inventory->getByName($itemName);
					$item{name} = $itemName;
					$item{inventory}{index} = $invItem ? $invItem->{invIndex} : undef;
					$item{inventory}{amount} = $invItem ? $invItem->{amount} : 0;
.....
New Code

Code: Select all

.....
					my $invItem = $char->inventory->getByName($itemName);
					my $amount = $char->inventory->sumByName($itemName); // total amount of the same name items
					$item{name} = $itemName;
					$item{inventory}{index} = $invItem ? $invItem->{invIndex} : undef;
					$item{inventory}{amount} = $invItem ? $amount : 0;
.....
Change in SVN 7701
taberu999
Noob
Noob
Posts: 2
Joined: 22 Mar 2011, 08:28
Noob?: Yes

Re: Incorrect Amount of Inventory Items with same name

#2 Post by taberu999 »

i got this updated but still kore does not work..

i get this..

Bareword found where operator expected at src/InventoryList.pm line 352, near "/
/ total"
(Missing operator before total?)
syntax error at src/InventoryList.pm line 352, near "// total amount "
Can't use global @_ in "my" at src/InventoryList.pm line 354, near "= @_"
syntax error at src/InventoryList.pm line 364, near "}"
Compilation failed in require at src/Actor/You.pm line 28.
BEGIN failed--compilation aborted at src/Actor/You.pm line 28.
Compilation failed in require at src/Misc.pm line 45.
BEGIN failed--compilation aborted at src/Misc.pm line 45.
Compilation failed in require at src/Network/Receive.pm line 36.
BEGIN failed--compilation aborted at src/Network/Receive.pm line 36.
Compilation failed in require at openkore.pl line 59.
BEGIN failed--compilation aborted at openkore.pl line 59.

Press ENTER to exit.
sofax222
Developers
Developers
Posts: 214
Joined: 24 Nov 2010, 03:08
Noob?: Yes

Re: Incorrect Amount of Inventory Items with same name

#3 Post by sofax222 »

taberu999 wrote:i got this updated but still kore does not work..

i get this..

Bareword found where operator expected at src/InventoryList.pm line 352, near "/
/ total"
(Missing operator before total?)
syntax error at src/InventoryList.pm line 352, near "// total amount "
Can't use global @_ in "my" at src/InventoryList.pm line 354, near "= @_"
syntax error at src/InventoryList.pm line 364, near "}"
Compilation failed in require at src/Actor/You.pm line 28.
BEGIN failed--compilation aborted at src/Actor/You.pm line 28.
Compilation failed in require at src/Misc.pm line 45.
BEGIN failed--compilation aborted at src/Misc.pm line 45.
Compilation failed in require at src/Network/Receive.pm line 36.
BEGIN failed--compilation aborted at src/Network/Receive.pm line 36.
Compilation failed in require at openkore.pl line 59.
BEGIN failed--compilation aborted at openkore.pl line 59.

Press ENTER to exit.
Sorry, this bug what you said is fixed in SVN 7702