Advertisement
Henrybk

InventoryList v1.1 beta

Mar 5th, 2016
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 73.18 KB | None | 0 0
  1. Index: Actor.pm
  2. ===================================================================
  3. --- Actor.pm    (revision 9000)
  4. +++ Actor.pm    (working copy)
  5. @@ -628,7 +628,7 @@
  6.  sub cartActive {
  7.     my ($self) = @_;
  8.    
  9. -   if ($cart{exists} ||
  10. +   if ($self->cart->{exists} ||
  11.         $self->statusActive('EFFECTSTATE_PUSHCART, EFFECTSTATE_PUSHCART2, EFFECTSTATE_PUSHCART3, EFFECTSTATE_PUSHCART4, EFFECTSTATE_PUSHCART5')) {
  12.         return 1;
  13.     }
  14. Index: Actor/You.pm
  15. ===================================================================
  16. --- Actor/You.pm    (revision 9000)
  17. +++ Actor/You.pm    (working copy)
  18. @@ -26,6 +26,9 @@
  19.  use Log qw(message);
  20.  use base qw(Actor);
  21.  use InventoryList;
  22. +use InventoryList::Inventory;
  23. +use InventoryList::Storage;
  24. +use InventoryList::Cart;
  25.  use Network::PacketParser;
  26.  use Translation;
  27.  use Utils;
  28. @@ -71,7 +74,9 @@
  29.  sub new {
  30.     my ($class) = @_;
  31.     my $self = $class->SUPER::new('You');
  32. -   $self->{__inventory} = new InventoryList();
  33. +   $self->{__inventory} = new InventoryList::Inventory();
  34. +   $self->{__storage} = new InventoryList::Storage();
  35. +   $self->{__cart} = new InventoryList::Cart();
  36.     $self->{configPrefix} = '';
  37.     $self->{dcOnEmptyItems} = '';
  38.  
  39. @@ -117,6 +122,24 @@
  40.  }
  41.  
  42.  ##
  43. +# InventoryList $char->storage()
  44. +# Ensures: defined(result)
  45. +#
  46. +# Get the storage list for this character.
  47. +sub storage {
  48. +   return $_[0]->{__storage};
  49. +}
  50. +
  51. +##
  52. +# InventoryList $char->cart()
  53. +# Ensures: defined(result)
  54. +#
  55. +# Get the cart list for this character.
  56. +sub cart {
  57. +   return $_[0]->{__cart};
  58. +}
  59. +
  60. +##
  61.  # float $char->weight_percent()
  62.  #
  63.  # Returns your weight percentage (between 0 and 100).
  64. Index: AI/CoreLogic.pm
  65. ===================================================================
  66. --- AI/CoreLogic.pm (revision 9000)
  67. +++ AI/CoreLogic.pm (working copy)
  68. @@ -981,7 +981,7 @@
  69.         if (!$amount || $amount > $item->{amount}) {
  70.             $amount = $item->{amount};
  71.         }
  72. -       $messageSender->sendStorageGet($item->{index}, $amount) if $storage{opened};
  73. +       $messageSender->sendStorageGet($item->{index}, $amount) if $char->storage->isOpened();
  74.         AI::args->{time} = time;
  75.         AI::dequeue if !@{AI::args->{items}};
  76.     }
  77. @@ -993,14 +993,14 @@
  78.  sub processCartAdd {
  79.     if (AI::action eq "cartAdd" && timeOut(AI::args)) {
  80.         my $item = AI::args->{items}[0];
  81. -       my $i = $item->{index};
  82. -       my $invItem = $char->inventory->get($i);
  83. +       my $index = $item->{index};
  84. +       my $amount = $item->{amount};
  85. +       my $invItem = $char->inventory->getByServerIndex($index);
  86.         if ($invItem) {
  87. -           my $amount = $item->{amount};
  88.             if (!$amount || $amount > $invItem->{amount}) {
  89.                 $amount = $invItem->{amount};
  90.             }
  91. -           $messageSender->sendCartAdd($invItem->{index}, $amount);
  92. +           $messageSender->sendCartAdd($index, $amount);
  93.         }
  94.         shift @{AI::args->{items}};
  95.         AI::args->{time} = time;
  96. @@ -1013,14 +1013,14 @@
  97.  sub processCartGet {
  98.     if (AI::action eq "cartGet" && timeOut(AI::args)) {
  99.         my $item = AI::args->{items}[0];
  100. -       my $i = $item->{index};
  101. -
  102. -       if ($cart{inventory}[$i]) {
  103. -           my $amount = $item->{amount};
  104. -           if (!$amount || $amount > $cart{inventory}[$i]{amount}) {
  105. -               $amount = $cart{inventory}[$i]{amount};
  106. +       my $index = $item->{index};
  107. +       my $amount = $item->{amount};
  108. +       my $cartItem = $char->cart->getByServerIndex($index);
  109. +       if ($cartItem) {
  110. +           if (!$amount || $amount > $cartItem->{amount}) {
  111. +               $amount = $cartItem->{amount};
  112.             }
  113. -           $messageSender->sendCartGet($i, $amount);
  114. +           $messageSender->sendCartGet($index, $amount);
  115.         }
  116.         shift @{AI::args->{items}};
  117.         AI::args->{time} = time;
  118. @@ -1089,7 +1089,7 @@
  119.           && ($config{storageAuto_npc} ne "" || $config{storageAuto_useChatCommand})
  120.           && !$ai_v{sitAuto_forcedBySitCommand}
  121.           && !AI::inQueue("storageAuto")
  122. -         && $char->inventory->size() > 0) {
  123. +         && $char->inventory->isReady()) {
  124.  
  125.         # Initiate autostorage when we're low on some item, and getAuto is set
  126.         my $needitem = "";
  127. @@ -1097,7 +1097,7 @@
  128.         Misc::checkValidity("AutoStorage part 1");
  129.         for ($i = 0; exists $config{"getAuto_$i"}; $i++) {
  130.             next unless ($config{"getAuto_$i"});
  131. -           if ($storage{opened} && findKeyString(\%storage, "name", $config{"getAuto_$i"}) eq '') {
  132. +           if ($char->storage->isOpened() && !$char->storage->getByName($config{"getAuto_$i"})) {
  133.                 foreach (keys %items_lut) {
  134.                     if ((lc($items_lut{$_}) eq lc($config{"getAuto_$i"})) && ($items_lut{$_} ne $config{"getAuto_$i"})) {
  135.                         configModify("getAuto_$i", $items_lut{$_});
  136. @@ -1115,7 +1115,7 @@
  137.                   $amount < $config{"getAuto_${i}_maxAmount"})
  138.                 )
  139.             ) {
  140. -               if ($storage{opened} && findKeyString(\%storage, "name", $config{"getAuto_$i"}) eq '') {
  141. +               if ($char->storage->isOpened() && !$char->storage->getByName($config{"getAuto_$i"})) {
  142.  =pod
  143.                     #This works only for last getAuto item
  144.                     if ($config{"getAuto_${i}_dcOnEmpty"}) {
  145. @@ -1125,7 +1125,7 @@
  146.                     }
  147.  =cut
  148.                 } else {
  149. -                   if ($storage{openedThisSession} && findKeyString(\%storage, "name", $config{"getAuto_$i"}) eq '') {
  150. +                   if ($char->storage->isOpenedThisSession() && !$char->storage->getByName($config{"getAuto_$i"})) {
  151.                     } else {
  152.                             my $sti = $config{"getAuto_$i"};
  153.                             if ($needitem eq "") {
  154. @@ -1143,7 +1143,7 @@
  155.  
  156.         # Only autostorage when we're on an attack route, or not moving
  157.         if ((!defined($routeIndex) || $attackOnRoute > 1) && $needitem ne "" &&
  158. -           $char->inventory->size() > 0 ){
  159. +           $char->inventory->isReady()){
  160.             message TF("Auto-storaging due to insufficient %s\n", $needitem);
  161.             AI::queue("storageAuto");
  162.         }
  163. @@ -1190,7 +1190,7 @@
  164.                 $do_route = 1;
  165.             } else {
  166.                 my $distance_from_char = distance($args->{npc}{pos}, $char->{pos_to});
  167. -               if (($distance_from_char > AI::args->{distance}) && !defined($args->{sentStore}) && !defined($ai_v{temp}{storage_opened})) {
  168. +               if (($distance_from_char > AI::args->{distance}) && !defined($args->{sentStore}) && !$char->storage->isOpened()) {
  169.                     $do_route = 1;
  170.                 }
  171.             }
  172. @@ -1240,7 +1240,7 @@
  173.                     ai_talkNPC($args->{npc}{pos}{x}, $args->{npc}{pos}{y}, $config{'storageAuto_npc_steps'});
  174.                 }
  175.  
  176. -               delete $ai_v{temp}{storage_opened};
  177. +               #delete $ai_v{temp}{storage_opened};
  178.                 $args->{sentStore} = 1;
  179.  
  180.                 # NPC talk retry
  181. @@ -1249,7 +1249,7 @@
  182.                 return;
  183.             }
  184.  
  185. -           if (!defined $ai_v{temp}{storage_opened}) {
  186. +           if (!$char->storage->isOpened()) {
  187.                 # NPC talk retry
  188.                 if (timeOut($AI::Timeouts::storageOpening, 40)) {
  189.                     undef $args->{sentStore};
  190. @@ -1268,7 +1268,7 @@
  191.                 $args->{done} = 1;
  192.                
  193.                 # if storage is full disconnect if it says so in conf
  194. -               if(defined $storage{items_max} && @storageID >= $storage{items_max} && $config{'dcOnStorageFull'}) {
  195. +               if($char->storage->isOpenedThisSession() && $char->storage->checkFull() && $config{'dcOnStorageFull'}) {
  196.                     $messageSender->sendQuit();
  197.                     error T("Auto disconnecting on StorageFull!\n");
  198.                     chatLog("k", T("*** Your storage is full , disconnect! ***\n"));
  199. @@ -1305,8 +1305,8 @@
  200.                 # we don't really need to check if we have a cart
  201.                 # if we don't have one it will not find any items to loop through
  202.                 $args->{cartNextItem} = 0 unless $args->{cartNextItem};
  203. -               for (my $i = $args->{cartNextItem}; $i < @{$cart{inventory}}; $i++) {
  204. -                   my $item = $cart{inventory}[$i];
  205. +               for (my $i = $args->{cartNextItem}; $i < @{$char->cart->getItems()}; $i++) {
  206. +                   my $item = $char->cart->getItems()->[$i];
  207.                     next unless ($item && %{$item});
  208.  
  209.                     my $control = items_control($item->{name});
  210. @@ -1324,7 +1324,7 @@
  211.                         $args->{cartLastIndex} = $item->{index};
  212.                         $messageSender->sendStorageAddFromCart($item->{index}, $item->{amount} - $control->{keep});
  213.                         $timeout{ai_storageAuto}{time} = time;
  214. -                       $args->{cartNextItem} = $i + 1;
  215. +                       $args->{cartNextItem} = $i;
  216.                         return;
  217.                     }
  218.                 }
  219. @@ -1363,12 +1363,14 @@
  220.                         next;
  221.                     }
  222.                     my $invItem = $char->inventory->getByName($itemName);
  223. -                   my $amount = $char->inventory->sumByName($itemName); # total amount of the same name items
  224. +                   my $invAmount = $char->inventory->sumByName($itemName);
  225. +                   my $storeItem = $char->storage->getByName($itemName);
  226. +                   my $storeAmount = $char->storage->sumByName($itemName);
  227.                     $item{name} = $itemName;
  228.                     $item{inventory}{index} = $invItem ? $invItem->{invIndex} : undef;
  229. -                   $item{inventory}{amount} = $invItem ? $amount : 0;
  230. -                   $item{storage}{index} = findKeyString(\%storage, "name", $item{name});
  231. -                   $item{storage}{amount} = ($item{storage}{index} ne "")? $storage{$item{storage}{index}}{amount} : 0;
  232. +                   $item{inventory}{amount} = $invItem ? $invAmount : 0;
  233. +                   $item{storage}{index} = $storeItem ? $storeItem->{invIndex} : undef;
  234. +                   $item{storage}{amount} = $storeItem ? $storeAmount : 0;
  235.                     $item{max_amount} = $config{"getAuto_$args->{index}"."_maxAmount"};
  236.                     $item{amount_needed} = $item{max_amount} - $item{inventory}{amount};
  237.                     $item{dcOnEmpty} = $config{"getAuto_$args->{index}"."_dcOnEmpty"};
  238. @@ -1381,7 +1383,7 @@
  239.                     # Try at most 3 times to get the item
  240.                     if (($item{amount_get} > 0) && ($args->{retry} < 3)) {
  241.                         message TF("Attempt to get %s x %s from storage, retry: %s\n", $item{amount_get}, $item{name}, $ai_seq_args[0]{retry}), "storage", 1;
  242. -                       $messageSender->sendStorageGet($item{storage}{index}, $item{amount_get});
  243. +                       $messageSender->sendStorageGet($storeItem->{index}, $item{amount_get});
  244.                         $timeout{ai_storageAuto}{time} = time;
  245.                         $args->{retry}++;
  246.                         return;
  247. @@ -1494,7 +1496,7 @@
  248.             $ai_v{'temp'}{'do_route'} = 1;
  249.         } else {
  250.             $ai_v{'temp'}{'distance'} = distance($args->{'npc'}{'pos'}, $chars[$config{'char'}]{'pos_to'});
  251. -           if (($ai_v{'temp'}{'distance'} > AI::args->{distance}) && !defined($args->{sentSell})) { #  && !defined($ai_v{temp}{storage_opened})
  252. +           if (($ai_v{'temp'}{'distance'} > AI::args->{distance}) && !defined($args->{sentSell})) {
  253.                 $ai_v{'temp'}{'do_route'} = 1;
  254.             }
  255.         }
  256. @@ -1767,38 +1769,34 @@
  257.         if (timeOut($AI::Timeouts::autoCart, $timeout) && $char->cartActive) {
  258.             my @addItems;
  259.             my @getItems;
  260. -           my $cartInventory = $cart{inventory};
  261.             my $max;
  262.  
  263. -           if ($config{cartMaxWeight} && $cart{weight} < $config{cartMaxWeight}) {
  264. -               foreach my $item (@{$char->inventory->getItems()}) {
  265. -                   next if ($item->{broken} && $item->{type} == 7); # dont auto-cart add pet eggs in use
  266. -                   next if ($item->{equipped});
  267. -                   my $control = items_control($item->{name});
  268. -                   if ($control->{cart_add} && $item->{amount} > $control->{keep}) {
  269. +           if ($config{cartMaxWeight} && $char->cart->{weight} < $config{cartMaxWeight}) {
  270. +               foreach my $invItem (@{$char->inventory->getItems()}) {
  271. +                   next if ($invItem->{broken} && $invItem->{type} == 7); # dont auto-cart add pet eggs in use
  272. +                   next if ($invItem->{equipped});
  273. +                   my $control = items_control($invItem->{name});
  274. +                   if ($control->{cart_add} && $invItem->{amount} > $control->{keep}) {
  275.                         my %obj;
  276. -                       $obj{index} = $item->{invIndex};
  277. -                       $obj{amount} = $item->{amount} - $control->{keep};
  278. +                       $obj{index} = $invItem->{index};
  279. +                       $obj{amount} = $invItem->{amount} - $control->{keep};
  280.                         push @addItems, \%obj;
  281. -                       debug "Scheduling $item->{name} ($item->{invIndex}) x $obj{amount} for adding to cart\n", "ai_autoCart";
  282. +                       debug "Scheduling $invItem->{name} ($invItem->{invIndex}) x $obj{amount} for adding to cart\n", "ai_autoCart";
  283.                     }
  284.                 }
  285.                 cartAdd(\@addItems);
  286.             }
  287.  
  288. -           $max = @{$cartInventory};
  289. -           for (my $i = 0; $i < $max; $i++) {
  290. -               my $cartItem = $cartInventory->[$i];
  291. -               next unless ($cartItem);
  292. +           foreach my $cartItem (@{$char->cart->getItems()}) {
  293.                 my $control = items_control($cartItem->{name});
  294.                 next unless ($control->{cart_get});
  295.  
  296. -               my $item = $char->inventory->getByName($cartItem->{name});
  297. +               my $invItem = $char->inventory->getByName($cartItem->{name});
  298.                 my $amount;
  299. -               if (!$item) {
  300. +               if (!$invItem) {
  301.                     $amount = $control->{keep};
  302. -               } elsif ($item->{amount} < $control->{keep}) {
  303. -                   $amount = $control->{keep} - $item->{amount};
  304. +               } elsif ($invItem->{amount} < $control->{keep}) {
  305. +                   $amount = $control->{keep} - $invItem->{amount};
  306.                 }
  307.                 if ($amount > $cartItem->{amount}) {
  308.                     $amount = $cartItem->{amount};
  309. @@ -1805,10 +1803,10 @@
  310.                 }
  311.                 if ($amount > 0) {
  312.                     my %obj;
  313. -                   $obj{index} = $i;
  314. +                   $obj{index} = $cartItem->{index};
  315.                     $obj{amount} = $amount;
  316.                     push @getItems, \%obj;
  317. -                   debug "Scheduling $cartItem->{name} ($i) x $obj{amount} for getting from cart\n", "ai_autoCart";
  318. +                   debug "Scheduling $cartItem->{name} ($cartItem->{index}) x $obj{amount} for getting from cart\n", "ai_autoCart";
  319.                 }
  320.             }
  321.             cartGet(\@getItems);
  322. @@ -2379,7 +2377,7 @@
  323.                     $timeout{ai_item_use_auto}{time} = time;
  324.                     debug qq~Auto-item use: $item->{name}\n~, "ai";
  325.                     last;
  326. -               } elsif ($config{"useSelf_item_${i}_dcOnEmpty"} && $char->inventory->size() > 0) {
  327. +               } elsif ($config{"useSelf_item_${i}_dcOnEmpty"} && $char->inventory->isReady()) {
  328.                     error TF("Disconnecting on empty %s!\n", $config{"useSelf_item_$i"});
  329.                     chatLog("k", TF("Disconnecting on empty %s!\n", $config{"useSelf_item_$i"}));
  330.                     quit();
  331. Index: Commands.pm
  332. ===================================================================
  333. --- Commands.pm (revision 9000)
  334. +++ Commands.pm (working copy)
  335. @@ -854,66 +854,37 @@
  336.             "You do not have a cart.\n");
  337.         return;
  338.  
  339. -   } elsif (!defined $cart{'inventory'}) {
  340. +   } elsif (!$char->cart->isReady()) {
  341.         error T("Cart inventory is not available.\n");
  342.         return;
  343.  
  344. -   } elsif ($arg1 eq "") {
  345. -       my $msg = center(T(" Cart "), 50, '-') ."\n".
  346. -           T("#  Name\n");
  347. -       for (my $i = 0; $i < @{$cart{'inventory'}}; $i++) {
  348. -           next if (!$cart{'inventory'}[$i] || !%{$cart{'inventory'}[$i]});
  349. -           my $display = "$cart{'inventory'}[$i]{'name'} x $cart{'inventory'}[$i]{'amount'}";
  350. -           $display .= T(" -- Not Identified") if !$cart{inventory}[$i]{identified};
  351. -           $msg .= sprintf("%-2d %-34s\n", $i, $display);
  352. -       }
  353. -       $msg .= TF("\nCapacity: %d/%d  Weight: %d/%d\n",
  354. -           int($cart{'items'}), int($cart{'items_max'}), int($cart{'weight'}), int($cart{'weight_max'}));
  355. -       $msg .= ('-'x50) . "\n";
  356. -       message $msg, "list";
  357. -
  358. +   } elsif ($arg1 eq "" || $arg1 eq "eq" || $arg1 eq "nu" || $arg1 eq "u") {
  359. +       cmdCart_list($arg1);
  360. +      
  361.     } elsif ($arg1 eq "desc") {
  362. -       if (!($arg2 =~ /\d+/)) {
  363. -           error TF("Syntax Error in function 'cart desc' (Show Cart Item Description)\n" .
  364. -               "'%s' is not a valid cart item number.\n", $arg2);
  365. -       } elsif (!$cart{'inventory'}[$arg2]) {
  366. -           error TF("Error in function 'cart desc' (Show Cart Item Description)\n" .
  367. -               "Cart Item %s does not exist.\n", $arg2);
  368. -       } else {
  369. -           printItemDesc($cart{'inventory'}[$arg2]{'nameID'});
  370. -       }
  371. +       cmdCart_desc($arg2);
  372. +      
  373. +   } elsif (($arg1 eq "add" || $arg1 eq "get" || $arg1 eq "release" || $arg1 eq "change") && (!$net || $net->getState() != Network::IN_GAME)) {
  374. +       error TF("You must be logged in the game to use this command '%s'\n", 'cart ' .$arg1);
  375. +           return;
  376.  
  377.     } elsif ($arg1 eq "add") {
  378. -       if (!$net || $net->getState() != Network::IN_GAME) {
  379. -           error TF("You must be logged in the game to use this command '%s'\n", 'cart ' .$arg1);
  380. -           return;
  381. -       }
  382.         cmdCart_add($arg2);
  383.  
  384.     } elsif ($arg1 eq "get") {
  385. -       if (!$net || $net->getState() != Network::IN_GAME) {
  386. -           error TF("You must be logged in the game to use this command '%s'\n", 'cart ' .$arg1);
  387. -           return;
  388. -       }
  389.         cmdCart_get($arg2);
  390.  
  391.     } elsif ($arg1 eq "release") {
  392. -       if (!$net || $net->getState() != Network::IN_GAME) {
  393. -           error TF("You must be logged in the game to use this command '%s'\n", 'cart ' .$arg1);
  394. -           return;
  395. -       }
  396.         $messageSender->sendCompanionRelease();
  397.         message T("Trying to released the cart...\n");
  398. +  
  399.     } elsif ($arg1 eq "change") {
  400. -       if (!$net || $net->getState() != Network::IN_GAME) {
  401. -           error TF("You must be logged in the game to use this command '%s'\n", 'cart ' .$arg1);
  402. -           return;
  403. -       }
  404.         if ($arg2 =~ m/^[1-5]$/) {
  405.             $messageSender->sendChangeCart($arg2);
  406.         } else {
  407.             error T("Usage: cart change <1-5>\n");
  408.         }
  409. +  
  410.     } else {
  411.         error TF("Error in function 'cart'\n" .
  412.             "Command '%s' is not a known command.\n", $arg1);
  413. @@ -920,6 +891,151 @@
  414.     }
  415.  }
  416.  
  417. +sub cmdCart_desc {
  418. +   my $arg = shift;
  419. +   if (!($arg =~ /\d+/)) {
  420. +       error TF("Syntax Error in function 'cart desc' (Show Cart Item Description)\n" .
  421. +           "'%s' is not a valid cart item number.\n", $arg);
  422. +   } else {
  423. +       my $item = $char->cart->get($arg);
  424. +       if (!$item) {
  425. +           error TF("Error in function 'cart desc' (Show Cart Item Description)\n" .
  426. +               "Cart Item %s does not exist.\n", $arg);
  427. +       } else {
  428. +           printItemDesc($item->{nameID});
  429. +       }
  430. +   }
  431. +}
  432. +
  433. +sub cmdCart_list {
  434. +   my $type = shift;
  435. +   message "$type\n";
  436. +
  437. +   my @useable;
  438. +   my @equipment;
  439. +   my @non_useable;
  440. +   my ($i, $display, $index);
  441. +  
  442. +   foreach my $item (@{$char->cart->getItems()}) {
  443. +       if ($item->usable) {
  444. +           push @useable, $item->{invIndex};
  445. +       } elsif ($item->equippable) {
  446. +           my %eqp;
  447. +           $eqp{index} = $item->{index};
  448. +           $eqp{binID} = $item->{invIndex};
  449. +           $eqp{name} = $item->{name};
  450. +           $eqp{amount} = $item->{amount};
  451. +           $eqp{identified} = " -- " . T("Not Identified") if !$item->{identified};
  452. +           $eqp{type} = $itemTypes_lut{$item->{type}};
  453. +           push @equipment, \%eqp;
  454. +       } else {
  455. +           push @non_useable, $item->{invIndex};
  456. +       }
  457. +   }
  458. +
  459. +   my $msg = center(T(" Cart "), 50, '-') ."\n".
  460. +           T("#  Name\n");
  461. +
  462. +   if (!$type || $type eq 'u') {
  463. +       $msg .= T("-- Usable --\n");
  464. +       for (my $i = 0; $i < @useable; $i++) {
  465. +           $index = $useable[$i];
  466. +           my $item = $char->cart->get($index);
  467. +           $display = $item->{name};
  468. +           $display .= " x $item->{amount}";
  469. +           $msg .= swrite(
  470. +               "@<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
  471. +               [$index, $display]);
  472. +       }
  473. +   }
  474. +
  475. +   if (!$type || $type eq 'eq') {
  476. +       $msg .= T("\n-- Equipment --\n");
  477. +       foreach my $item (@equipment) {
  478. +           ## altered to allow for Arrows/Ammo which will are stackable equip.
  479. +           $display = sprintf("%-3d  %s (%s)", $item->{binID}, $item->{name}, $item->{type});
  480. +           $display .= " x $item->{amount}" if $item->{amount} > 1;
  481. +           $display .= $item->{identified};
  482. +           $msg .= sprintf("%-57s\n", $display);
  483. +       }
  484. +   }
  485. +
  486. +   if (!$type || $type eq 'nu') {
  487. +       $msg .= T("\n-- Non-Usable --\n");
  488. +       for (my $i = 0; $i < @non_useable; $i++) {
  489. +           $index = $non_useable[$i];
  490. +           my $item = $char->cart->get($index);
  491. +           $display = $item->{name};
  492. +           $display .= " x $item->{amount}";
  493. +           $msg .= swrite(
  494. +               "@<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
  495. +               [$index, $display]);
  496. +       }
  497. +   }
  498. +
  499. +   $msg .= TF("\nCapacity: %d/%d  Weight: %d/%d\n",
  500. +           $char->cart->{items}, $char->cart->{items_max}, $char->cart->{weight}, $char->cart->{weight_max}).
  501. +           ('-'x50) . "\n";
  502. +   message $msg, "list";
  503. +}
  504. +
  505. +sub cmdCart_add {
  506. +   my ($name) = @_;
  507. +
  508. +   if (!defined $name) {
  509. +       error T("Syntax Error in function 'cart add' (Add Item to Cart)\n" .
  510. +           "Usage: cart add <item>\n");
  511. +       return;
  512. +   }
  513. +
  514. +   my $amount;
  515. +   if ($name =~ /^(.*?) (\d+)$/) {
  516. +       $name = $1;
  517. +       $amount = $2;
  518. +   }
  519. +
  520. +   my $item = Match::inventoryItem($name);
  521. +
  522. +   if (!$item) {
  523. +       error TF("Error in function 'cart add' (Add Item to Cart)\n" .
  524. +           "Inventory Item %s does not exist.\n", $name);
  525. +       return;
  526. +   }
  527. +
  528. +   if (!$amount || $amount > $item->{amount}) {
  529. +       $amount = $item->{amount};
  530. +   }
  531. +   $messageSender->sendCartAdd($item->{index}, $amount);
  532. +}
  533. +
  534. +sub cmdCart_get {
  535. +   my ($name) = @_;
  536. +
  537. +   if (!defined $name) {
  538. +       error T("Syntax Error in function 'cart get' (Get Item from Cart)\n" .
  539. +           "Usage: cart get <cart item>\n");
  540. +       return;
  541. +   }
  542. +
  543. +   my $amount;
  544. +   if ($name =~ /^(.*?) (\d+)$/) {
  545. +       $name = $1;
  546. +       $amount = $2;
  547. +   }
  548. +
  549. +   my $item = Match::cartItem($name);
  550. +   if (!$item) {
  551. +       error TF("Error in function 'cart get' (Get Item from Cart)\n" .
  552. +           "Cart Item %s does not exist.\n", $name);
  553. +       return;
  554. +   }
  555. +
  556. +   if (!$amount || $amount > $item->{amount}) {
  557. +       $amount = $item->{amount};
  558. +   }
  559. +   $messageSender->sendCartGet($item->{index}, $amount);
  560. +}
  561. +
  562.  sub cmdCash {
  563.     my (undef, $args) = @_;
  564.     my ($sub_cmd, $arg) = split(/\s+/,$args, 2);
  565. @@ -1022,63 +1138,6 @@
  566.     }
  567.  }
  568.  
  569. -sub cmdCart_add {
  570. -   my ($name) = @_;
  571. -
  572. -   if (!defined $name) {
  573. -       error T("Syntax Error in function 'cart add' (Add Item to Cart)\n" .
  574. -           "Usage: cart add <item>\n");
  575. -       return;
  576. -   }
  577. -
  578. -   my $amount;
  579. -   if ($name =~ /^(.*?) (\d+)$/) {
  580. -       $name = $1;
  581. -       $amount = $2;
  582. -   }
  583. -
  584. -   my $item = Match::inventoryItem($name);
  585. -
  586. -   if (!$item) {
  587. -       error TF("Error in function 'cart add' (Add Item to Cart)\n" .
  588. -           "Inventory Item %s does not exist.\n", $name);
  589. -       return;
  590. -   }
  591. -
  592. -   if (!$amount || $amount > $item->{amount}) {
  593. -       $amount = $item->{amount};
  594. -   }
  595. -   $messageSender->sendCartAdd($item->{index}, $amount);
  596. -}
  597. -
  598. -sub cmdCart_get {
  599. -   my ($name) = @_;
  600. -
  601. -   if (!defined $name) {
  602. -       error T("Syntax Error in function 'cart get' (Get Item from Cart)\n" .
  603. -           "Usage: cart get <cart item>\n");
  604. -       return;
  605. -   }
  606. -
  607. -   my $amount;
  608. -   if ($name =~ /^(.*?) (\d+)$/) {
  609. -       $name = $1;
  610. -       $amount = $2;
  611. -   }
  612. -
  613. -   my $item = Match::cartItem($name);
  614. -   if (!$item) {
  615. -       error TF("Error in function 'cart get' (Get Item from Cart)\n" .
  616. -           "Cart Item %s does not exist.\n", $name);
  617. -       return;
  618. -   }
  619. -
  620. -   if (!$amount || $amount > $item->{amount}) {
  621. -       $amount = $item->{amount};
  622. -   }
  623. -   $messageSender->sendCartGet($item->{index}, $amount);
  624. -}
  625. -
  626.  sub cmdCharSelect {
  627.     my (undef,$arg1) = @_;
  628.     if (!$net || $net->getState() != Network::IN_GAME) {
  629. @@ -2914,8 +2973,13 @@
  630.     my (undef, $args) = @_;
  631.     my ($arg1) = $args =~ /^(\w+)/;
  632.     my ($arg2) = $args =~ /^\w+ (.+)/;
  633. -
  634. -   if (!$char || $char->inventory->size() == 0) {
  635. +  
  636. +   if (!$char || !$char->inventory->isReady()) {
  637. +       error "Inventory is not available\n";
  638. +       return;
  639. +   }
  640. +  
  641. +   if ($char->inventory->size() == 0) {
  642.         error T("Inventory is empty\n");
  643.         return;
  644.     }
  645. @@ -4552,26 +4616,32 @@
  646.  }
  647.  
  648.  sub cmdStorage {
  649. -   if ($storage{opened} || $storage{openedThisSession}) {
  650. +   if ($char->storage->isOpenedThisSession()) {
  651.         my (undef, $args) = @_;
  652.  
  653.         my ($switch, $items) = split(' ', $args, 2);
  654.         if (!$switch || $switch eq 'eq' || $switch eq 'u' || $switch eq 'nu') {
  655.             cmdStorage_list($switch);
  656. -       } elsif ($switch eq 'add' && $storage{opened}) {
  657. -           cmdStorage_add($items);
  658. -       } elsif ($switch eq 'addfromcart'  && $storage{opened}) {
  659. -           cmdStorage_addfromcart($items);
  660. -       } elsif ($switch eq 'get'  && $storage{opened}) {
  661. -           cmdStorage_get($items);
  662. -       } elsif ($switch eq 'gettocart'  && $storage{opened}) {
  663. -           cmdStorage_gettocart($items);
  664. -       } elsif ($switch eq 'close'  && $storage{opened}) {
  665. -           cmdStorage_close();
  666.         } elsif ($switch eq 'log') {
  667.             cmdStorage_log();
  668.         } elsif ($switch eq 'desc') {
  669.             cmdStorage_desc($items);
  670. +       } elsif ($switch eq 'add' || $switch eq 'addfromcart' || $switch eq 'get' || $switch eq 'gettocart' || $switch eq 'close') {
  671. +           if ($char->storage->isOpened()) {
  672. +               if ($switch eq 'add') {
  673. +                   cmdStorage_add($items);
  674. +               } elsif ($switch eq 'addfromcart') {
  675. +                   cmdStorage_addfromcart($items);
  676. +               } elsif ($switch eq 'get') {
  677. +                   cmdStorage_get($items);
  678. +               } elsif ($switch eq 'gettocart') {
  679. +                   cmdStorage_gettocart($items);
  680. +               } elsif ($switch eq 'close') {
  681. +                   cmdStorage_close();
  682. +               }
  683. +           } else {
  684. +               error T("Cannot get/add/close storage because storage is not opened\n");
  685. +           }
  686.         } else {
  687.             error T("Syntax Error in function 'storage' (Storage Functions)\n" .
  688.                 "Usage: storage [<eq|u|nu>]\n" .
  689. @@ -4635,7 +4705,9 @@
  690.     for my $name (@names) {
  691.         if ($name =~ /^(\d+)\-(\d+)$/) {
  692.             for my $i ($1..$2) {
  693. -               push @items, $storage{$storageID[$i]} if ($storage{$storageID[$i]});
  694. +               my $item = $char->storage->get($i);
  695. +               #push @items, $item->{index} if ($item);
  696. +               push @items, $item if ($item);
  697.             }
  698.  
  699.         } else {
  700. @@ -4644,6 +4716,7 @@
  701.                 error TF("Storage Item '%s' does not exist.\n", $name);
  702.                 next;
  703.             }
  704. +           #push @items, $item->{index};
  705.             push @items, $item;
  706.         }
  707.     }
  708. @@ -5873,23 +5946,22 @@
  709.     my @useable;
  710.     my @equipment;
  711.     my @non_useable;
  712. -
  713. -   for (my $i = 0; $i < @storageID; $i++) {
  714. -       next if ($storageID[$i] eq "");
  715. -       my $item = $storage{$storageID[$i]};
  716. +   my ($i, $display, $index);
  717. +  
  718. +   foreach my $item (@{$char->storage->getItems()}) {
  719.         if ($item->usable) {
  720. -           push @useable, $item;
  721. +           push @useable, $item->{invIndex};
  722.         } elsif ($item->equippable) {
  723.             my %eqp;
  724. -           $eqp{binID} = $i;
  725. +           $eqp{index} = $item->{index};
  726. +           $eqp{binID} = $item->{invIndex};
  727.             $eqp{name} = $item->{name};
  728. -           $eqp{type} = $itemTypes_lut{$item->{type}};
  729. -           ## Add amt so we can give quantities for ammo.
  730.             $eqp{amount} = $item->{amount};
  731.             $eqp{identified} = " -- " . T("Not Identified") if !$item->{identified};
  732. +           $eqp{type} = $itemTypes_lut{$item->{type}};
  733.             push @equipment, \%eqp;
  734.         } else {
  735. -           push @non_useable, $item;
  736. +           push @non_useable, $item->{invIndex};
  737.         }
  738.     }
  739.  
  740. @@ -5898,13 +5970,13 @@
  741.     if (!$type || $type eq 'u') {
  742.         $msg .= T("-- Usable --\n");
  743.         for (my $i = 0; $i < @useable; $i++) {
  744. -           my $item = $useable[$i];
  745. -           my $binID = $item->{binID};
  746. -           my $display = $item->{name};
  747. +           $index = $useable[$i];
  748. +           my $item = $char->storage->get($index);
  749. +           $display = $item->{name};
  750.             $display .= " x $item->{amount}";
  751.             $msg .= swrite(
  752. -               "@<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
  753. -               [$binID, $display]);
  754. +               "@<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
  755. +               [$index, $display]);
  756.         }
  757.     }
  758.  
  759. @@ -5912,13 +5984,10 @@
  760.         $msg .= T("\n-- Equipment --\n");
  761.         foreach my $item (@equipment) {
  762.             ## altered to allow for Arrows/Ammo which will are stackable equip.
  763. -           my $line = sprintf("%-3d  %s (%s)", $item->{binID}, $item->{name}, $item->{type});
  764. -           if ($item->{amount} > 1) {
  765. -               $line .= " x $item->{amount}";
  766. -           } else {
  767. -               $line .= $item->{identified};
  768. -           }
  769. -           $msg .= $line . "\n";
  770. +           $display = sprintf("%-3d  %s (%s)", $item->{binID}, $item->{name}, $item->{type});
  771. +           $display .= " x $item->{amount}" if $item->{amount} > 1;
  772. +           $display .= $item->{identified};
  773. +           $msg .= sprintf("%-57s\n", $display);
  774.         }
  775.     }
  776.  
  777. @@ -5925,17 +5994,17 @@
  778.     if (!$type || $type eq 'nu') {
  779.         $msg .= T("\n-- Non-Usable --\n");
  780.         for (my $i = 0; $i < @non_useable; $i++) {
  781. -           my $item = $non_useable[$i];
  782. -           my $binID = $item->{binID};
  783. -           my $display = $item->{name};
  784. +           $index = $non_useable[$i];
  785. +           my $item = $char->storage->get($index);
  786. +           $display = $item->{name};
  787.             $display .= " x $item->{amount}";
  788.             $msg .= swrite(
  789. -               "@<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
  790. -               [$binID, $display]);
  791. +               "@<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
  792. +               [$index, $display]);
  793.         }
  794.     }
  795.  
  796. -   $msg .= TF("\nCapacity: %d/%d\n", $storage{items}, $storage{items_max}) .
  797. +   $msg .= TF("\nCapacity: %d/%d\n", $char->storage->{items}, $char->storage->{items_max}) .
  798.             ('-'x50) . "\n";
  799.     message $msg, "list";
  800.  }
  801. Index: functions.pl
  802. ===================================================================
  803. --- functions.pl    (revision 9000)
  804. +++ functions.pl    (working copy)
  805. @@ -607,7 +607,9 @@
  806.         delete $char->{warp};
  807.         delete $char->{casting};
  808.         delete $char->{homunculus}{appear_time} if $char->{homunculus};
  809. -       $char->inventory->clear();
  810. +       $char->inventory->onMapChange();
  811. +       $char->cart->onMapChange() if ($char->cartActive());
  812. +       $char->storage->close() if ($char->storage->isOpened());
  813.     }
  814.     $timeout{play}{time} = time;
  815.     $timeout{ai_sync}{time} = time;
  816. @@ -632,11 +634,7 @@
  817.     undef %spells;
  818.     undef %incomingParty;
  819.     undef %talk;
  820. -   $ai_v{cart_time} = time + 60;
  821. -   $ai_v{inventory_time} = time + 60;
  822.     $ai_v{temp} = {};
  823. -   $cart{inventory} = [];
  824. -   delete $storage{opened};
  825.     undef @venderItemList;
  826.     undef $venderID;
  827.     undef $venderCID;
  828. Index: Globals.pm
  829. ===================================================================
  830. --- Globals.pm  (revision 9000)
  831. +++ Globals.pm  (working copy)
  832. @@ -28,7 +28,7 @@
  833.  our %EXPORT_TAGS = (
  834.     config  => [qw(%arrowcraft_items %avoid @chatResponses %cities_lut %config %consoleColors %directions_lut %equipTypes_lut %equipSlot_rlut %equipSlot_lut %haircolors @headgears_lut @msgTable %items_control %items_lut %itemSlotCount_lut %itemsDesc_lut %itemTypes_lut %jobs_lut %maps_lut %masterServers %monsters_lut %npcs_lut %packetDescriptions %portals_lut %responses %sex_lut %shop %skillsDesc_lut %lookHandle %skillsArea %skillsEncore %spells_lut %emotions_lut %timeout $char %mon_control %priority %routeWeights %pickupitems %rpackets %itemSlots_lut %statusHandle %statusName %effectName %portals_los %stateHandle %ailmentHandle %mapTypeHandle %mapPropertyTypeHandle %mapPropertyInfoHandle %elements_lut %mapAlias_lut %quests_lut)],
  835.     ai      => [qw(@ai_seq @ai_seq_args %ai_v $AI $AI_forcedOff %targetTimeout)],
  836. -   state   => [qw($accountID $cardMergeIndex @cardMergeItemsID $charID @chars @chars_old %cart @friendsID %friends %incomingFriend $field %homunculus $itemsList @itemsID %items $monstersList @monstersID %monsters @npcsID %npcs $npcsList @playersID %players @portalsID @portalsID_old %portals %portals_old $portalsList @storeList $currentChatRoom @currentChatRoomUsers @chatRoomsID %createdChatRoom %chatRooms @skillsID %storage @storageID $storageTitle @arrowCraftID %guild %incomingGuild @spellsID %spells @unknownPlayers @unknownNPCs $useArrowCraft %currentDeal %incomingDeal %outgoingDeal @identifyID @partyUsersID %incomingParty @petsID %pets @venderItemList $venderID $venderCID @venderListsID @buyerItemList @selfBuyerItemList $buyerID $buyingStoreID @buyerListsID @articles $articles %venderLists %buyerLists %monsters_old @monstersID_old %npcs_old %items_old %players_old @playersID_old @servers $sessionID $sessionID2 $accountSex $accountSex2 $map_ip $map_port $KoreStartTime $secureLoginKey $initSync $lastConfChangeTime $petsList $playersList $portalsList @playerNameCacheIDs %playerNameCache %pet $pvp @cashList $slavesList @slavesID %slaves %cashShop)],
  837. +   state   => [qw($accountID $cardMergeIndex @cardMergeItemsID $charID @chars @chars_old @friendsID %friends %incomingFriend $field %homunculus $itemsList @itemsID %items $monstersList @monstersID %monsters @npcsID %npcs $npcsList @playersID %players @portalsID @portalsID_old %portals %portals_old $portalsList @storeList $currentChatRoom @currentChatRoomUsers @chatRoomsID %createdChatRoom %chatRooms @skillsID $storageTitle @arrowCraftID %guild %incomingGuild @spellsID %spells @unknownPlayers @unknownNPCs $useArrowCraft %currentDeal %incomingDeal %outgoingDeal @identifyID @partyUsersID %incomingParty @petsID %pets @venderItemList $venderID $venderCID @venderListsID @buyerItemList @selfBuyerItemList $buyerID $buyingStoreID @buyerListsID @articles $articles %venderLists %buyerLists %monsters_old @monstersID_old %npcs_old %items_old %players_old @playersID_old @servers $sessionID $sessionID2 $accountSex $accountSex2 $map_ip $map_port $KoreStartTime $secureLoginKey $initSync $lastConfChangeTime $petsList $playersList $portalsList @playerNameCacheIDs %playerNameCache %pet $pvp @cashList $slavesList @slavesID %slaves %cashShop)],
  838.     network => [qw($remote_socket $net $messageSender $charServer $conState $conState_tries $encryptVal $ipc $bus $masterServer $lastSwitch $packetParser $clientPacketHandler $bytesSent $incomingMessages $outgoingClientMessages $enc_val1 $enc_val2 $captcha_state)],
  839.     interface => [qw($interface)],
  840.     misc    => [qw($quit $reconnectCount @lastpm %lastpm @privMsgUsers %timeout_ex $shopstarted $dmgpsec $totalelasped $elasped $totaldmg %overallAuth %responseVars %talk $startTime_EXP $startingzeny @monsters_Killed $bExpSwitch $jExpSwitch $totalBaseExp $totalJobExp $shopEarned %itemChange $XKore_dontRedirect $monkilltime $monstarttime $startedattack $firstLoginMap $sentWelcomeMessage $versionSearch $monsterBaseExp $monsterJobExp %descriptions %flags %damageTaken $logAppend @sellList $userSeed $taskManager $repairList $mailList $auctionList $questList $hotkeyList $devotionList $cookingList %charSvrSet @deadTime)],
  841. @@ -386,7 +386,6 @@
  842.  our @cardMergeItemsID;
  843.  our @chars;
  844.  our @chars_old;
  845. -our %cart;
  846.  our $field;
  847.  our @friendsID;
  848.  our %friends;
  849. @@ -413,8 +412,6 @@
  850.  our %createdChatRoom;
  851.  our %chatRooms;
  852.  our @skillsID;
  853. -our %storage;
  854. -our @storageID;
  855.  our $storageTitle;
  856.  our @arrowCraftID;
  857.  our %guild;
  858. Index: Interface/Console/Curses.pm
  859. ===================================================================
  860. --- Interface/Console/Curses.pm (revision 9000)
  861. +++ Interface/Console/Curses.pm (working copy)
  862. @@ -592,7 +592,7 @@
  863.         hp       => { title => 'HP',     cur => $char->{hp},        max => $char->{hp_max},     color1 => 'bold|red',  color2 => 'bold|green', threshold => 15 },
  864.         sp       => { title => 'SP',     cur => $char->{sp},        max => $char->{sp_max},     color1 => 'bold|blue', color2 => '',           threshold => 0 },
  865.         weight   => { title => 'Weight', cur => $char->{weight},    max => $char->{weight_max}, color1 => 'cyan',      color2 => 'red',        threshold => 50 },
  866. -       cart     => { title => 'Cart W', cur => $cart{weight},      max => $cart{weight_max},   color1 => 'cyan',      color2 => '',           threshold => 0 },
  867. +       cart     => { title => 'Cart W', cur => $char->cart->{weight},      max => $char->cart->{weight_max},   color1 => 'cyan',      color2 => '',           threshold => 0 },
  868.         hunger   => { title => 'Hunger', cur => $homun->{hunger},   max => 100,                 color1 => 'red',       color2 => 'green',      threshold => 0 },
  869.         intimacy => { title => 'Loyal',  cur => $homun->{intimacy}, max => 1000,                color1 => 'red',       color2 => 'green',      threshold => 10 },
  870.         hom_hp   => { title => 'Hom HP', cur => $homun->{hp},       max => $homun->{hp_max},    color1 => 'bold|red',  color2 => 'bold|green', threshold => 0 },
  871. Index: InventoryList/Cart.pm
  872. ===================================================================
  873. --- InventoryList/Cart.pm   (revision 0)
  874. +++ InventoryList/Cart.pm   (working copy)
  875. @@ -0,0 +1,56 @@
  876. +#########################################################################
  877. +#  OpenKore - Player actor object
  878. +#  Copyright (c) 2005 OpenKore Team
  879. +#
  880. +#  TEST BY HENRYBK
  881. +#
  882. +#########################################################################
  883. +package InventoryList::Cart;
  884. +
  885. +use strict;
  886. +use Globals;
  887. +use InventoryList;
  888. +use base qw(InventoryList);
  889. +
  890. +sub new {
  891. +   my ($class) = @_;
  892. +   my $self = $class->SUPER::new('Cart');
  893. +   $self->{items} = 0;
  894. +   $self->{items_max} = 0;
  895. +   $self->{weight} = 0;
  896. +   $self->{weight_max} = 0;
  897. +   $self->{exists} = 0;
  898. +   return $self;
  899. +}
  900. +
  901. +sub isReady {
  902. +   my ($self) = @_;
  903. +   return $self->{exists};
  904. +}
  905. +
  906. +sub info {
  907. +   my ($self, $args) = @_;
  908. +   $self->{items} = $args->{items};
  909. +   $self->{items_max} = $args->{items_max};
  910. +   $self->{weight} = int($args->{weight} / 10);
  911. +   $self->{weight_max} = int($args->{weight_max} / 10);
  912. +   $self->{exists} = 1 if (!$self->{exists});
  913. +}
  914. +
  915. +sub onMapChange {
  916. +   my ($self) = @_;
  917. +   $self->{exists} = 0;
  918. +   $self->clear();
  919. +}
  920. +
  921. +sub release {
  922. +   my ($self) = @_;
  923. +   $self->{exists} = 0;
  924. +}
  925. +
  926. +sub changeType {
  927. +   my ($self, $args) = @_;
  928. +   $self->{type} = $args;
  929. +}
  930. +
  931. +1;
  932. \ No newline at end of file
  933. Index: InventoryList/Distfiles
  934. ===================================================================
  935. --- InventoryList/Distfiles (revision 0)
  936. +++ InventoryList/Distfiles (working copy)
  937. @@ -0,0 +1,3 @@
  938. +Cart.pm
  939. +Inventory.pm
  940. +Storage.pm
  941. Index: InventoryList/Inventory.pm
  942. ===================================================================
  943. --- InventoryList/Inventory.pm  (revision 0)
  944. +++ InventoryList/Inventory.pm  (working copy)
  945. @@ -0,0 +1,49 @@
  946. +#########################################################################
  947. +#  OpenKore - Player actor object
  948. +#  Copyright (c) 2005 OpenKore Team
  949. +#
  950. +#  TEST BY HENRYBK
  951. +#
  952. +#########################################################################
  953. +package InventoryList::Inventory;
  954. +
  955. +use strict;
  956. +use Globals;
  957. +use InventoryList;
  958. +use base qw(InventoryList);
  959. +
  960. +use constant {
  961. +   MAP_LOADED => 0,
  962. +   RECV_STAT_INFO2 => 1
  963. +};
  964. +
  965. +sub new {
  966. +   my ($class) = @_;
  967. +   my $self = $class->SUPER::new('Inventory');
  968. +   $self->{hooks} = Plugins::addHooks (
  969. +       ['packet/stat_info2',        sub { $self->{state} = RECV_STAT_INFO2; }]
  970. +   );
  971. +   $self->{state} = 0;
  972. +   return $self;
  973. +}
  974. +
  975. +# TEST inventory STATE, isReady
  976. +sub isReady {
  977. +   my ($self) = @_;
  978. +   return $self->{state};
  979. +}
  980. +
  981. +sub onMapChange {
  982. +   my ($self) = @_;
  983. +   $self->{state} = MAP_LOADED;
  984. +   $self->clear();
  985. +}
  986. +
  987. +sub add {
  988. +   my ($self, $item) = @_;
  989. +   my $invIndex = $self->SUPER::add($item);
  990. +   $self->{state} = 1 if (!$self->{state});
  991. +   return $invIndex;
  992. +}
  993. +
  994. +1;
  995. \ No newline at end of file
  996. Index: InventoryList/Storage.pm
  997. ===================================================================
  998. --- InventoryList/Storage.pm    (revision 0)
  999. +++ InventoryList/Storage.pm    (working copy)
  1000. @@ -0,0 +1,56 @@
  1001. +#########################################################################
  1002. +#  OpenKore - Player actor object
  1003. +#  Copyright (c) 2005 OpenKore Team
  1004. +#
  1005. +#  TEST BY HENRYBK
  1006. +#
  1007. +#########################################################################
  1008. +package InventoryList::Storage;
  1009. +
  1010. +use strict;
  1011. +use Globals;
  1012. +use InventoryList;
  1013. +use base qw(InventoryList);
  1014. +
  1015. +sub new {
  1016. +   my ($class) = @_;
  1017. +   my $self = $class->SUPER::new('Storage');
  1018. +   $self->{openedThisSession} = 0;
  1019. +   $self->{opened} = 0;
  1020. +   $self->{items} = 0;
  1021. +   $self->{items_max} = 0;
  1022. +   return $self;
  1023. +}
  1024. +
  1025. +sub isOpenedThisSession {
  1026. +   my ($self) = @_;
  1027. +   return $self->{openedThisSession} == 1;
  1028. +}
  1029. +
  1030. +sub isOpened {
  1031. +   my ($self) = @_;
  1032. +   return $self->{opened} == 1;
  1033. +}
  1034. +
  1035. +sub open {
  1036. +   my ($self, $args) = @_;
  1037. +   $self->{items} = $args->{items};
  1038. +   $self->{items_max} = $args->{items_max};
  1039. +   if (!$self->{opened}) {
  1040. +       $self->{opened} = 1;
  1041. +       $self->{openedThisSession} = 1 if (!$self->{openedThisSession});
  1042. +       Plugins::callHook('packet_storage_open');
  1043. +   }
  1044. +}
  1045. +
  1046. +sub close {
  1047. +   my ($self) = @_;
  1048. +   $self->{opened} = 0;
  1049. +}
  1050. +
  1051. +sub checkFull {
  1052. +   my ($self) = @_;
  1053. +   return $self->{items} >= $self->{items_max};
  1054. +}
  1055. +
  1056. +1;
  1057. \ No newline at end of file
  1058. Index: InventoryList.pm
  1059. ===================================================================
  1060. --- InventoryList.pm    (revision 9000)
  1061. +++ InventoryList.pm    (working copy)
  1062. @@ -76,6 +76,7 @@
  1063.  
  1064.  sub DESTROY {
  1065.     my ($self) = @_;
  1066. +   Plugins::delHook($self->{hook}) if $self->{hook};
  1067.     $self->clear();
  1068.     $self->SUPER::DESTROY();
  1069.  }
  1070. Index: InventoryList/Cart.pm
  1071. ===================================================================
  1072. --- InventoryList/Cart.pm   (revision 0)
  1073. +++ InventoryList/Cart.pm   (working copy)
  1074. @@ -0,0 +1,56 @@
  1075. +#########################################################################
  1076. +#  OpenKore - Player actor object
  1077. +#  Copyright (c) 2005 OpenKore Team
  1078. +#
  1079. +#  TEST BY HENRYBK
  1080. +#
  1081. +#########################################################################
  1082. +package InventoryList::Cart;
  1083. +
  1084. +use strict;
  1085. +use Globals;
  1086. +use InventoryList;
  1087. +use base qw(InventoryList);
  1088. +
  1089. +sub new {
  1090. +   my ($class) = @_;
  1091. +   my $self = $class->SUPER::new('Cart');
  1092. +   $self->{items} = 0;
  1093. +   $self->{items_max} = 0;
  1094. +   $self->{weight} = 0;
  1095. +   $self->{weight_max} = 0;
  1096. +   $self->{exists} = 0;
  1097. +   return $self;
  1098. +}
  1099. +
  1100. +sub isReady {
  1101. +   my ($self) = @_;
  1102. +   return $self->{exists};
  1103. +}
  1104. +
  1105. +sub info {
  1106. +   my ($self, $args) = @_;
  1107. +   $self->{items} = $args->{items};
  1108. +   $self->{items_max} = $args->{items_max};
  1109. +   $self->{weight} = int($args->{weight} / 10);
  1110. +   $self->{weight_max} = int($args->{weight_max} / 10);
  1111. +   $self->{exists} = 1 if (!$self->{exists});
  1112. +}
  1113. +
  1114. +sub onMapChange {
  1115. +   my ($self) = @_;
  1116. +   $self->{exists} = 0;
  1117. +   $self->clear();
  1118. +}
  1119. +
  1120. +sub release {
  1121. +   my ($self) = @_;
  1122. +   $self->{exists} = 0;
  1123. +}
  1124. +
  1125. +sub changeType {
  1126. +   my ($self, $args) = @_;
  1127. +   $self->{type} = $args;
  1128. +}
  1129. +
  1130. +1;
  1131. \ No newline at end of file
  1132. Index: InventoryList/Distfiles
  1133. ===================================================================
  1134. --- InventoryList/Distfiles (revision 0)
  1135. +++ InventoryList/Distfiles (working copy)
  1136. @@ -0,0 +1,3 @@
  1137. +Cart.pm
  1138. +Inventory.pm
  1139. +Storage.pm
  1140. Index: InventoryList/Inventory.pm
  1141. ===================================================================
  1142. --- InventoryList/Inventory.pm  (revision 0)
  1143. +++ InventoryList/Inventory.pm  (working copy)
  1144. @@ -0,0 +1,49 @@
  1145. +#########################################################################
  1146. +#  OpenKore - Player actor object
  1147. +#  Copyright (c) 2005 OpenKore Team
  1148. +#
  1149. +#  TEST BY HENRYBK
  1150. +#
  1151. +#########################################################################
  1152. +package InventoryList::Inventory;
  1153. +
  1154. +use strict;
  1155. +use Globals;
  1156. +use InventoryList;
  1157. +use base qw(InventoryList);
  1158. +
  1159. +use constant {
  1160. +   MAP_LOADED => 0,
  1161. +   RECV_STAT_INFO2 => 1
  1162. +};
  1163. +
  1164. +sub new {
  1165. +   my ($class) = @_;
  1166. +   my $self = $class->SUPER::new('Inventory');
  1167. +   $self->{hooks} = Plugins::addHooks (
  1168. +       ['packet/stat_info2',        sub { $self->{state} = RECV_STAT_INFO2; }]
  1169. +   );
  1170. +   $self->{state} = 0;
  1171. +   return $self;
  1172. +}
  1173. +
  1174. +# TEST inventory STATE, isReady
  1175. +sub isReady {
  1176. +   my ($self) = @_;
  1177. +   return $self->{state};
  1178. +}
  1179. +
  1180. +sub onMapChange {
  1181. +   my ($self) = @_;
  1182. +   $self->{state} = MAP_LOADED;
  1183. +   $self->clear();
  1184. +}
  1185. +
  1186. +sub add {
  1187. +   my ($self, $item) = @_;
  1188. +   my $invIndex = $self->SUPER::add($item);
  1189. +   $self->{state} = 1 if (!$self->{state});
  1190. +   return $invIndex;
  1191. +}
  1192. +
  1193. +1;
  1194. \ No newline at end of file
  1195. Index: InventoryList/Storage.pm
  1196. ===================================================================
  1197. --- InventoryList/Storage.pm    (revision 0)
  1198. +++ InventoryList/Storage.pm    (working copy)
  1199. @@ -0,0 +1,56 @@
  1200. +#########################################################################
  1201. +#  OpenKore - Player actor object
  1202. +#  Copyright (c) 2005 OpenKore Team
  1203. +#
  1204. +#  TEST BY HENRYBK
  1205. +#
  1206. +#########################################################################
  1207. +package InventoryList::Storage;
  1208. +
  1209. +use strict;
  1210. +use Globals;
  1211. +use InventoryList;
  1212. +use base qw(InventoryList);
  1213. +
  1214. +sub new {
  1215. +   my ($class) = @_;
  1216. +   my $self = $class->SUPER::new('Storage');
  1217. +   $self->{openedThisSession} = 0;
  1218. +   $self->{opened} = 0;
  1219. +   $self->{items} = 0;
  1220. +   $self->{items_max} = 0;
  1221. +   return $self;
  1222. +}
  1223. +
  1224. +sub isOpenedThisSession {
  1225. +   my ($self) = @_;
  1226. +   return $self->{openedThisSession} == 1;
  1227. +}
  1228. +
  1229. +sub isOpened {
  1230. +   my ($self) = @_;
  1231. +   return $self->{opened} == 1;
  1232. +}
  1233. +
  1234. +sub open {
  1235. +   my ($self, $args) = @_;
  1236. +   $self->{items} = $args->{items};
  1237. +   $self->{items_max} = $args->{items_max};
  1238. +   if (!$self->{opened}) {
  1239. +       $self->{opened} = 1;
  1240. +       $self->{openedThisSession} = 1 if (!$self->{openedThisSession});
  1241. +       Plugins::callHook('packet_storage_open');
  1242. +   }
  1243. +}
  1244. +
  1245. +sub close {
  1246. +   my ($self) = @_;
  1247. +   $self->{opened} = 0;
  1248. +}
  1249. +
  1250. +sub checkFull {
  1251. +   my ($self) = @_;
  1252. +   return $self->{items} >= $self->{items_max};
  1253. +}
  1254. +
  1255. +1;
  1256. \ No newline at end of file
  1257. Index: Match.pm
  1258. ===================================================================
  1259. --- Match.pm    (revision 9000)
  1260. +++ Match.pm    (working copy)
  1261. @@ -91,18 +91,17 @@
  1262.  #
  1263.  # Find an item in cart.
  1264.  sub cartItem {
  1265. -   my ($name) = @_;
  1266. -
  1267. +   my ($name) = lc shift;
  1268. +   my $item;
  1269.     if ($name =~ /^\d+$/) {
  1270.         # A number was provided
  1271. -       return unless $cart{inventory}[$name] && %{$cart{inventory}[$name]};
  1272. -       return $cart{inventory}[$name];
  1273. +       $item = $char->cart->get($name);
  1274. +   } else {
  1275. +       # A name was provided; match it
  1276. +       $item = $char->cart->getByName($name);
  1277.     }
  1278. -
  1279. -   # A name was provided; match it
  1280. -   my $index = findIndexString_lc($cart{inventory}, 'name', $name);
  1281. -   return unless defined($index);
  1282. -   return $cart{inventory}[$index];
  1283. +   return $item if ($item);
  1284. +   return undef; # Not found
  1285.  }
  1286.  
  1287.  ##
  1288. @@ -113,19 +112,15 @@
  1289.  # Find an item in storage.
  1290.  sub storageItem {
  1291.     my ($name) = lc shift;
  1292. -
  1293. +   my $item;
  1294.     if ($name =~ /^\d+$/) {
  1295.         # A number was provided
  1296. -       return unless defined($storageID[$name]); # Invalid number
  1297. -       return $storage{$storageID[$name]};
  1298. +       $item = $char->storage->get($name);
  1299. +   } else {
  1300. +       # A name was provided; match it
  1301. +       $item = $char->storage->getByName($name);
  1302.     }
  1303. -
  1304. -   # A name was provided; match it
  1305. -   my $index;
  1306. -   for my $ID (@storageID) {
  1307. -       my $item = $storage{$ID};
  1308. -       return $item if lc($item->{name}) eq $name;
  1309. -   }
  1310. +   return $item if ($item);
  1311.     return undef; # Not found
  1312.  }
  1313.  
  1314. Index: Misc.pm
  1315. ===================================================================
  1316. --- Misc.pm (revision 9000)
  1317. +++ Misc.pm (working copy)
  1318. @@ -195,8 +195,6 @@
  1319.     checkSelfCondition
  1320.     checkPlayerCondition
  1321.     checkMonsterCondition
  1322. -   findCartItemInit
  1323. -   findCartItem
  1324.     makeShop
  1325.     openShop
  1326.     closeShop
  1327. @@ -1764,6 +1762,42 @@
  1328.     $itemChange{$item->{name}} -= $amount;
  1329.  }
  1330.  
  1331. +##
  1332. +# storageItemRemoved($invIndex, $amount)
  1333. +#
  1334. +# Removes $amount of $invIndex from $char->{storage}.
  1335. +# Also prints a message saying the item was removed
  1336. +sub storageItemRemoved {
  1337. +   my ($invIndex, $amount) = @_;
  1338. +
  1339. +   return if $amount == 0;
  1340. +   my $item = $char->storage->get($invIndex);
  1341. +   message TF("Storage Item Removed: %s (%d) x %s\n", $item->{name}, $invIndex, $amount), "storage";
  1342. +   $item->{amount} -= $amount;
  1343. +   if ($item->{amount} <= 0) {
  1344. +       $char->storage->remove($item);
  1345. +   }
  1346. +   $itemChange{$item->{name}} -= $amount;
  1347. +}
  1348. +
  1349. +##
  1350. +# cartItemRemoved($invIndex, $amount)
  1351. +#
  1352. +# Removes $amount of $invIndex from $char->{cart}.
  1353. +# Also prints a message saying the item was removed
  1354. +sub cartItemRemoved {
  1355. +   my ($invIndex, $amount) = @_;
  1356. +
  1357. +   return if $amount == 0;
  1358. +   my $item = $char->cart->get($invIndex);
  1359. +   message TF("Cart Item Removed: %s (%d) x %s\n", $item->{name}, $invIndex, $amount), "cart";
  1360. +   $item->{amount} -= $amount;
  1361. +   if ($item->{amount} <= 0) {
  1362. +       $char->cart->remove($item);
  1363. +   }
  1364. +   $itemChange{$item->{name}} -= $amount;
  1365. +}
  1366. +
  1367.  # Resolve the name of a card
  1368.  sub cardName {
  1369.     my $cardID = shift;
  1370. @@ -3150,11 +3184,9 @@
  1371.  
  1372.     if (open($f, ">:utf8", $Settings::storage_log_file)) {
  1373.         print $f TF("---------- Storage %s -----------\n", getFormattedDate(int(time)));
  1374. -       for (my $i = 0; $i < @storageID; $i++) {
  1375. -           next if (!$storageID[$i]);
  1376. -           my $item = $storage{$storageID[$i]};
  1377. +       foreach my $item (@{$char->storage->getItems()}) {
  1378.  
  1379. -           my $display = sprintf "%2d %s x %s", $i, $item->{name}, $item->{amount};
  1380. +           my $display = sprintf "%2d %s x %s", $item->{invIndex}, $item->{name}, $item->{amount};
  1381.             # Translation Comment: Mark to show not identified items
  1382.             $display .= " -- " . T("Not Identified") if !$item->{identified};
  1383.             # Translation Comment: Mark to show broken items
  1384. @@ -3162,7 +3194,7 @@
  1385.             print $f "$display\n";
  1386.         }
  1387.         # Translation Comment: Storage Capacity
  1388. -       print $f TF("\nCapacity: %d/%d\n", $storage{items}, $storage{items_max});
  1389. +       print $f TF("\nCapacity: %d/%d\n", $char->storage->{items}, $char->storage->{items_max});
  1390.         print $f "-------------------------------\n";
  1391.         close $f;
  1392.  
  1393. @@ -3972,6 +4004,7 @@
  1394.     }
  1395.  
  1396.     if ($config{$prefix."_inInventory"}) {
  1397. +       return 0 if (!$char->inventory->isReady());
  1398.         foreach my $input (split / *, */, $config{$prefix."_inInventory"}) {
  1399.             my ($itemName, $count) = $input =~ /(.*?)(?:\s+([><]=? *\d+))?$/;
  1400.             $count = '>0' if $count eq '';
  1401. @@ -3981,12 +4014,12 @@
  1402.     }
  1403.  
  1404.     if ($config{$prefix."_inCart"}) {
  1405. +       return 0 if (!$char->cart->isReady());
  1406.         foreach my $input (split / *, */, $config{$prefix."_inCart"}) {
  1407.             my ($item,$count) = $input =~ /(.*?)(?:\s+([><]=? *\d+))?$/;
  1408.             $count = '>0' if $count eq '';
  1409. -           my $iX = findIndexString_lc($cart{inventory}, "name", $item);
  1410. -           my $item = $cart{inventory}[$iX];
  1411. -           return 0 if !inRange(!defined $iX ? 0 : $item->{amount}, $count);
  1412. +           my $item = $char->cart->getByName($item);
  1413. +           return 0 if !inRange(!$item ? 0 : $item->{amount}, $count);
  1414.         }
  1415.     }
  1416.  
  1417. @@ -4269,45 +4302,6 @@
  1418.  }
  1419.  
  1420.  ##
  1421. -# findCartItemInit()
  1422. -#
  1423. -# Resets all "found" flags in the cart to 0.
  1424. -sub findCartItemInit {
  1425. -   for (@{$cart{inventory}}) {
  1426. -       next unless $_ && %{$_};
  1427. -       undef $_->{found};
  1428. -   }
  1429. -}
  1430. -
  1431. -##
  1432. -# findCartItem($name [, $found [, $nounid]])
  1433. -#
  1434. -# Returns the integer index into $cart{inventory} for the cart item matching
  1435. -# the given name, or undef.
  1436. -#
  1437. -# If an item is found, the "found" value for that item is set to 1. Items
  1438. -# cannot be found again until you reset the "found" flags using
  1439. -# findCartItemInit(), if $found is true.
  1440. -#
  1441. -# Unidentified items will not be returned if $nounid is true.
  1442. -sub findCartItem {
  1443. -   my ($name, $found, $nounid) = @_;
  1444. -
  1445. -   $name = lc($name);
  1446. -   my $index = 0;
  1447. -   for (@{$cart{inventory}}) {
  1448. -       if (lc($_->{name}) eq $name &&
  1449. -           !($found && $_->{found}) &&
  1450. -           !($nounid && !$_->{identified})) {
  1451. -           $_->{found} = 1;
  1452. -           return $index;
  1453. -       }
  1454. -       $index++;
  1455. -   }
  1456. -   return undef;
  1457. -}
  1458. -
  1459. -##
  1460.  # makeShop()
  1461.  #
  1462.  # Returns an array of items to sell. The array can be no larger than the
  1463. @@ -4346,16 +4340,15 @@
  1464.     findCartItemInit();
  1465.     shuffleArray(\@{$shop{items}}) if ($config{'shop_random'} eq "2");
  1466.     for my $sale (@{$shop{items}}) {
  1467. -       my $index = findCartItem($sale->{name}, 1, 1);
  1468. -       next unless defined($index);
  1469. +       my $cart_item = $char->cart->getByName($sale->{name});
  1470. +       next unless ($cart_item);
  1471.  
  1472.         # Found item to vend
  1473. -       my $cart_item = $cart{inventory}[$index];
  1474.         my $amount = $cart_item->{amount};
  1475.  
  1476.         my %item;
  1477.         $item{name} = $cart_item->{name};
  1478. -       $item{index} = $index;
  1479. +       $item{index} = $cart_item->{index};
  1480.             if ($sale->{priceMax}) {
  1481.                 $item{price} = int(rand($sale->{priceMax} - $sale->{price})) + $sale->{price};
  1482.             } else {
  1483. Index: Network/Receive.pm
  1484. ===================================================================
  1485. --- Network/Receive.pm  (revision 9000)
  1486. +++ Network/Receive.pm  (working copy)
  1487. @@ -1645,7 +1645,7 @@
  1488.  
  1489.  # 012B
  1490.  sub cart_off {
  1491. -   undef $cart{exists};
  1492. +   $char->cart->release();
  1493.     message T("Cart released.\n"), "success";
  1494.  }
  1495.  
  1496. @@ -1841,7 +1841,7 @@
  1497.     my ($type, $ID, $tick, $unknown1, $unknown2, $unknown3, $unknown4) = @{$args}{qw(type ID tick unknown1 unknown2 unknown3 unknown4)};
  1498.     my $flag = (exists $args->{flag}) ? $args->{flag} : 1;
  1499.     my $status = defined $statusHandle{$type} ? $statusHandle{$type} : "UNKNOWN_STATUS_$type";
  1500. -   $cart{type} = $unknown1 if ($type == 673 && defined $unknown1 && ($ID eq $accountID)); # for Cart active
  1501. +   $char->cart->changeType($unknown1) if ($type == 673 && defined $unknown1 && ($ID eq $accountID)); # for Cart active
  1502.     $args->{skillName} = defined $statusName{$status} ? $statusName{$status} : $status;
  1503.  #  ($args->{actor} = Actor::get($ID))->setStatus($status, 1, $tick == 9999 ? undef : $tick, $args->{unknown1}); # need test for '08FF'
  1504.     ($args->{actor} = Actor::get($ID))->setStatus($status, $flag, $tick == 9999 ? undef : $tick);
  1505. @@ -2186,4 +2186,210 @@
  1506.     $questList->{$args->{questID}}->{active} = $args->{active};
  1507.  }
  1508.  
  1509. +sub storage_opened {
  1510. +   my ($self, $args) = @_;
  1511. +   $char->storage->open($args);
  1512. +}
  1513. +
  1514. +sub storage_closed {
  1515. +   $char->storage->close();
  1516. +   message T("Storage closed.\n"), "storage";
  1517. +   Plugins::callHook('packet_storage_close');
  1518. +
  1519. +   # Storage log
  1520. +   writeStorageLog(0);
  1521. +
  1522. +   if ($char->{dcOnEmptyItems} ne "") {
  1523. +       message TF("Disconnecting on empty %s!\n", $char->{dcOnEmptyItems});
  1524. +       chatLog("k", TF("Disconnecting on empty %s!\n", $char->{dcOnEmptyItems}));
  1525. +       quit();
  1526. +   }
  1527. +}
  1528. +
  1529. +sub storage_items_stackable {
  1530. +   my ($self, $args) = @_;
  1531. +
  1532. +   $self->_items_list({
  1533. +       class => 'Actor::Item',
  1534. +       hook => 'packet_storage',
  1535. +       debug_str => 'Stackable Storage Item',
  1536. +       items => [$self->parse_items_stackable($args)],
  1537. +       getter => sub { $char->storage->getByServerIndex($_[0]{index}) },
  1538. +       adder => sub { $char->storage->add($_[0]) },
  1539. +       callback => sub {
  1540. +           my ($local_item) = @_;
  1541. +
  1542. +           $local_item->{amount} = $local_item->{amount} & ~0x80000000;
  1543. +       },
  1544. +   });
  1545. +
  1546. +   $storageTitle = $args->{title} ? $args->{title} : undef;
  1547. +}
  1548. +
  1549. +sub storage_items_nonstackable {
  1550. +   my ($self, $args) = @_;
  1551. +
  1552. +   $self->_items_list({
  1553. +       class => 'Actor::Item',
  1554. +       hook => 'packet_storage',
  1555. +       debug_str => 'Non-Stackable Storage Item',
  1556. +       items => [$self->parse_items_nonstackable($args)],
  1557. +       getter => sub { $char->storage->getByServerIndex($_[0]{index}) },
  1558. +       adder => sub { $char->storage->add($_[0]) },
  1559. +   });
  1560. +
  1561. +   $storageTitle = $args->{title} ? $args->{title} : undef;
  1562. +}
  1563. +
  1564. +sub storage_item_added {
  1565. +   my ($self, $args) = @_;
  1566. +
  1567. +   my $index = $args->{index};
  1568. +   my $amount = $args->{amount};
  1569. +
  1570. +   my $item = $char->storage->getByServerIndex($index);
  1571. +   if (!$item) {
  1572. +       $item = new Actor::Item();
  1573. +       $item->{nameID} = $args->{nameID};
  1574. +       $item->{index} = $index;
  1575. +       $item->{amount} = $amount;
  1576. +       $item->{type} = $args->{type};
  1577. +       $item->{identified} = $args->{identified};
  1578. +       $item->{broken} = $args->{broken};
  1579. +       $item->{upgrade} = $args->{upgrade};
  1580. +       $item->{cards} = $args->{cards};
  1581. +       $item->{name} = itemName($item);
  1582. +       $char->storage->add($item);
  1583. +   } else {
  1584. +       $item->{amount} += $amount;
  1585. +   }
  1586. +   my $disp = TF("Storage Item Added: %s (%d) x %d - %s",
  1587. +           $item->{name}, $item->{invIndex}, $amount, $itemTypes_lut{$item->{type}});
  1588. +   message "$disp\n", "drop";
  1589. +  
  1590. +   $itemChange{$item->{name}} += $amount;
  1591. +   $args->{item} = $item;
  1592. +}
  1593. +
  1594. +sub storage_item_removed {
  1595. +   my ($self, $args) = @_;
  1596. +
  1597. +   my ($index, $amount) = @{$args}{qw(index amount)};
  1598. +
  1599. +   my $item = $char->storage->getByServerIndex($index);
  1600. +  
  1601. +   if ($item) {
  1602. +       Misc::storageItemRemoved($item->{invIndex}, $amount);
  1603. +   }
  1604. +}
  1605. +
  1606. +sub cart_items_stackable {
  1607. +   my ($self, $args) = @_;
  1608. +
  1609. +   $self->_items_list({
  1610. +       class => 'Actor::Item',
  1611. +       hook => 'packet_cart',
  1612. +       debug_str => 'Stackable Cart Item',
  1613. +       items => [$self->parse_items_stackable($args)],
  1614. +       getter => sub { $char->cart->getByServerIndex($_[0]{index}) },
  1615. +       adder => sub { $char->cart->add($_[0]) },
  1616. +   });
  1617. +}
  1618. +
  1619. +sub cart_items_nonstackable {
  1620. +   my ($self, $args) = @_;
  1621. +
  1622. +   $self->_items_list({
  1623. +       class => 'Actor::Item',
  1624. +       hook => 'packet_cart',
  1625. +       debug_str => 'Non-Stackable Cart Item',
  1626. +       items => [$self->parse_items_nonstackable($args)],
  1627. +       getter => sub { $char->cart->getByServerIndex($_[0]{index}) },
  1628. +       adder => sub { $char->cart->add($_[0]) },
  1629. +   });
  1630. +}
  1631. +
  1632. +sub cart_item_added {
  1633. +   my ($self, $args) = @_;
  1634. +  
  1635. +   my $index = $args->{index};
  1636. +   my $amount = $args->{amount};
  1637. +
  1638. +   my $item = $char->cart->getByServerIndex($index);
  1639. +   if (!$item) {
  1640. +       $item = new Actor::Item();
  1641. +       $item->{index} = $args->{index};
  1642. +       $item->{nameID} = $args->{nameID};
  1643. +       $item->{amount} = $args->{amount};
  1644. +       $item->{identified} = $args->{identified};
  1645. +       $item->{broken} = $args->{broken};
  1646. +       $item->{upgrade} = $args->{upgrade};
  1647. +       $item->{cards} = $args->{cards};
  1648. +       $item->{type} = $args->{type} if (exists $args->{type});
  1649. +       $item->{name} = itemName($item);
  1650. +       $char->cart->add($item);
  1651. +   } else {
  1652. +       $item->{amount} += $args->{amount};
  1653. +   }
  1654. +   my $disp = TF("Cart Item Added: %s (%d) x %d - %s",
  1655. +           $item->{name}, $item->{invIndex}, $amount, $itemTypes_lut{$item->{type}});
  1656. +   message "$disp\n", "drop";
  1657. +   $itemChange{$item->{name}} += $args->{amount};
  1658. +   $args->{item} = $item;
  1659. +}
  1660. +
  1661. +sub cart_item_removed {
  1662. +   my ($self, $args) = @_;
  1663. +
  1664. +   my ($index, $amount) = @{$args}{qw(index amount)};
  1665. +
  1666. +   my $item = $char->cart->getByServerIndex($index);
  1667. +  
  1668. +   if ($item) {
  1669. +       Misc::cartItemRemoved($item->{invIndex}, $amount);
  1670. +   }
  1671. +}
  1672. +
  1673. +sub cart_info {
  1674. +   my ($self, $args) = @_;
  1675. +   $char->cart->info($args);
  1676. +   debug "[cart_info] received.\n", "parseMsg";
  1677. +}
  1678. +
  1679. +sub cart_add_failed {
  1680. +   my ($self, $args) = @_;
  1681. +
  1682. +   my $reason;
  1683. +   if ($args->{fail} == 0) {
  1684. +       $reason = T('overweight');
  1685. +   } elsif ($args->{fail} == 1) {
  1686. +       $reason = T('too many items');
  1687. +   } else {
  1688. +       $reason = TF("Unknown code %s",$args->{fail});
  1689. +   }
  1690. +   error TF("Can't Add Cart Item (%s)\n", $reason);
  1691. +}
  1692. +
  1693. +sub inventory_items_stackable {
  1694. +   my ($self, $args) = @_;
  1695. +   return unless changeToInGameState();
  1696. +
  1697. +   $self->_items_list({
  1698. +       class => 'Actor::Item',
  1699. +       hook => 'packet_inventory',
  1700. +       debug_str => 'Stackable Inventory Item',
  1701. +       items => [$self->parse_items_stackable($args)],
  1702. +       getter => sub { $char->inventory->getByServerIndex($_[0]{index}) },
  1703. +       adder => sub { $char->inventory->add($_[0]) },
  1704. +       callback => sub {
  1705. +           my ($local_item) = @_;
  1706. +
  1707. +           if (defined $char->{arrow} && $local_item->{index} == $char->{arrow}) {
  1708. +               $local_item->{equipped} = 32768;
  1709. +               $char->{equipment}{arrow} = $local_item;
  1710. +           }
  1711. +       }
  1712. +   });
  1713. +}
  1714. +
  1715.  1;
  1716. Index: Network/Receive/kRO/Sakexe_0.pm
  1717. ===================================================================
  1718. --- Network/Receive/kRO/Sakexe_0.pm (revision 9000)
  1719. +++ Network/Receive/kRO/Sakexe_0.pm (working copy)
  1720. @@ -936,86 +936,6 @@
  1721.     undef $cardMergeIndex;
  1722.  }
  1723.  
  1724. -sub cart_info {
  1725. -   my ($self, $args) = @_;
  1726. -
  1727. -   $cart{items} = $args->{items};
  1728. -   $cart{items_max} = $args->{items_max};
  1729. -   $cart{weight} = int($args->{weight} / 10);
  1730. -   $cart{weight_max} = int($args->{weight_max} / 10);
  1731. -   $cart{exists} = 1;
  1732. -   debug "[cart_info] received.\n", "parseMsg";
  1733. -}
  1734. -
  1735. -sub cart_add_failed {
  1736. -   my ($self, $args) = @_;
  1737. -
  1738. -   my $reason;
  1739. -   if ($args->{fail} == 0) {
  1740. -       $reason = T('overweight');
  1741. -   } elsif ($args->{fail} == 1) {
  1742. -       $reason = T('too many items');
  1743. -   } else {
  1744. -       $reason = TF("Unknown code %s",$args->{fail});
  1745. -   }
  1746. -   error TF("Can't Add Cart Item (%s)\n", $reason);
  1747. -}
  1748. -
  1749. -sub cart_items_nonstackable {
  1750. -   my ($self, $args) = @_;
  1751. -
  1752. -   $self->_items_list({
  1753. -       # TODO: different classes for inventory/cart/storage items
  1754. -       class => 'Actor::Item',
  1755. -       hook => 'packet_cart',
  1756. -       debug_str => 'Non-Stackable Cart Item',
  1757. -       items => [$self->parse_items_nonstackable($args)],
  1758. -       getter => sub { $cart{inventory}[$_[0]{index}] },
  1759. -       adder => sub { $cart{inventory}[$_[0]{index}] = $_[0] },
  1760. -   });
  1761. -
  1762. -   $ai_v{'inventory_time'} = time + 1;
  1763. -   $ai_v{'cart_time'} = time + 1;
  1764. -}
  1765. -
  1766. -sub cart_items_stackable {
  1767. -   my ($self, $args) = @_;
  1768. -
  1769. -   $self->_items_list({
  1770. -       class => 'Actor::Item',
  1771. -       hook => 'packet_cart',
  1772. -       debug_str => 'Stackable Cart Item',
  1773. -       items => [$self->parse_items_stackable($args)],
  1774. -       getter => sub { $cart{inventory}[$_[0]{index}] },
  1775. -       adder => sub { $cart{inventory}[$_[0]{index}] = $_[0] },
  1776. -   });
  1777. -
  1778. -   $ai_v{'inventory_time'} = time + 1;
  1779. -   $ai_v{'cart_time'} = time + 1;
  1780. -}
  1781. -
  1782. -sub cart_item_added {
  1783. -   my ($self, $args) = @_;
  1784. -
  1785. -   my $item = $cart{inventory}[$args->{index}] ||= Actor::Item->new;
  1786. -   if ($item->{amount}) {
  1787. -       $item->{amount} += $args->{amount};
  1788. -   } else {
  1789. -       $item->{index} = $args->{index};
  1790. -       $item->{nameID} = $args->{nameID};
  1791. -       $item->{amount} = $args->{amount};
  1792. -       $item->{identified} = $args->{identified};
  1793. -       $item->{broken} = $args->{broken};
  1794. -       $item->{upgrade} = $args->{upgrade};
  1795. -       $item->{cards} = $args->{cards};
  1796. -       $item->{type} = $args->{type} if (exists $args->{type});
  1797. -       $item->{name} = itemName($item);
  1798. -   }
  1799. -   message TF("Cart Item Added: %s (%d) x %s\n", $item->{name}, $args->{index}, $args->{amount});
  1800. -   $itemChange{$item->{name}} += $args->{amount};
  1801. -   $args->{item} = $item;
  1802. -}
  1803. -
  1804.  sub cash_dealer {
  1805.     my ($self, $args) = @_;
  1806.  
  1807. @@ -1063,21 +983,6 @@
  1808.     debug "$args->{actor} $verb combo delay $args->{delay}\n", "parseMsg_comboDelay";
  1809.  }
  1810.  
  1811. -sub cart_item_removed {
  1812. -   my ($self, $args) = @_;
  1813. -
  1814. -   my ($index, $amount) = @{$args}{qw(index amount)};
  1815. -
  1816. -   my $item = $cart{inventory}[$index];
  1817. -   $item->{amount} -= $amount;
  1818. -   message TF("Cart Item Removed: %s (%d) x %s\n", $item->{name}, $index, $amount);
  1819. -   $itemChange{$item->{name}} -= $amount;
  1820. -   if ($item->{amount} <= 0) {
  1821. -       $cart{'inventory'}[$index] = undef;
  1822. -   }
  1823. -   $args->{item} = $item;
  1824. -}
  1825. -
  1826.  sub change_to_constate25 {
  1827.     $net->setState(2.5);
  1828.     undef $accountID;
  1829. @@ -2626,36 +2531,8 @@
  1830.         Plugins::callHook('packet_inventory', {index => $item->{invIndex}});
  1831.  =cut
  1832.     }
  1833. -
  1834. -   $ai_v{'inventory_time'} = time + 1;
  1835. -   $ai_v{'cart_time'} = time + 1;
  1836.  }
  1837.  
  1838. -sub inventory_items_stackable {
  1839. -   my ($self, $args) = @_;
  1840. -   return unless changeToInGameState();
  1841. -
  1842. -   $self->_items_list({
  1843. -       class => 'Actor::Item',
  1844. -       hook => 'packet_inventory',
  1845. -       debug_str => 'Stackable Inventory Item',
  1846. -       items => [$self->parse_items_stackable($args)],
  1847. -       getter => sub { $char->inventory->getByServerIndex($_[0]{index}) },
  1848. -       adder => sub { $char->inventory->add($_[0]) },
  1849. -       callback => sub {
  1850. -           my ($local_item) = @_;
  1851. -
  1852. -           if (defined $char->{arrow} && $local_item->{index} == $char->{arrow}) {
  1853. -               $local_item->{equipped} = 32768;
  1854. -               $char->{equipment}{arrow} = $local_item;
  1855. -           }
  1856. -       }
  1857. -   });
  1858. -
  1859. -   $ai_v{'inventory_time'} = time + 1;
  1860. -   $ai_v{'cart_time'} = time + 1;
  1861. -}
  1862. -
  1863.  sub item_appeared {
  1864.     my ($self, $args) = @_;
  1865.     return unless changeToInGameState();
  1866. @@ -3110,7 +2987,6 @@
  1867.         delete $char->{permitSkill};
  1868.         delete $char->{encoreSkill};
  1869.     }
  1870. -   $cart{exists} = 0;
  1871.     undef %guild;
  1872.  
  1873.     Plugins::callHook('Network::Receive::map_changed', {
  1874. @@ -5086,115 +4962,6 @@
  1875.     }
  1876.  }
  1877.  
  1878. -sub storage_closed {
  1879. -   message T("Storage closed.\n"), "storage";
  1880. -   delete $ai_v{temp}{storage_opened};
  1881. -   delete $storage{opened};
  1882. -   Plugins::callHook('packet_storage_close');
  1883. -
  1884. -   # Storage log
  1885. -   writeStorageLog(0);
  1886. -
  1887. -   if ($char->{dcOnEmptyItems} ne "") {
  1888. -       message TF("Disconnecting on empty %s!\n", $char->{dcOnEmptyItems});
  1889. -       chatLog("k", TF("Disconnecting on empty %s!\n", $char->{dcOnEmptyItems}));
  1890. -       quit();
  1891. -   }
  1892. -}
  1893. -
  1894. -sub storage_item_added {
  1895. -   my ($self, $args) = @_;
  1896. -
  1897. -   my $index = $args->{index};
  1898. -   my $amount = $args->{amount};
  1899. -
  1900. -   my $item = $storage{$index} ||= Actor::Item->new;
  1901. -   if ($item->{amount}) {
  1902. -       $item->{amount} += $amount;
  1903. -   } else {
  1904. -       binAdd(\@storageID, $index);
  1905. -       $item->{nameID} = $args->{nameID};
  1906. -       $item->{index} = $index;
  1907. -       $item->{amount} = $amount;
  1908. -       $item->{type} = $args->{type};
  1909. -       $item->{identified} = $args->{identified};
  1910. -       $item->{broken} = $args->{broken};
  1911. -       $item->{upgrade} = $args->{upgrade};
  1912. -       $item->{cards} = $args->{cards};
  1913. -       $item->{name} = itemName($item);
  1914. -       $item->{binID} = binFind(\@storageID, $index);
  1915. -   }
  1916. -   message TF("Storage Item Added: %s (%d) x %s\n", $item->{name}, $item->{binID}, $amount), "storage", 1;
  1917. -   $itemChange{$item->{name}} += $amount;
  1918. -   $args->{item} = $item;
  1919. -}
  1920. -
  1921. -sub storage_item_removed {
  1922. -   my ($self, $args) = @_;
  1923. -
  1924. -   my ($index, $amount) = @{$args}{qw(index amount)};
  1925. -
  1926. -   my $item = $storage{$index};
  1927. -   $item->{amount} -= $amount;
  1928. -   message TF("Storage Item Removed: %s (%d) x %s\n", $item->{name}, $item->{binID}, $amount), "storage";
  1929. -   $itemChange{$item->{name}} -= $amount;
  1930. -   $args->{item} = $item;
  1931. -   if ($item->{amount} <= 0) {
  1932. -       delete $storage{$index};
  1933. -       binRemove(\@storageID, $index);
  1934. -   }
  1935. -}
  1936. -
  1937. -sub storage_items_nonstackable {
  1938. -   my ($self, $args) = @_;
  1939. -
  1940. -   $self->_items_list({
  1941. -       class => 'Actor::Item',
  1942. -       hook => 'packet_storage',
  1943. -       debug_str => 'Non-Stackable Storage Item',
  1944. -       items => [$self->parse_items_nonstackable($args)],
  1945. -       adder => sub { $_[0]{binID} = binAdd(\@storageID, $_[0]{index}); $storage{$_[0]{index}} = $_[0] },
  1946. -   });
  1947. -
  1948. -   $storageTitle = exists $args->{title} ? $args->{title} : undef;
  1949. -}
  1950. -
  1951. -sub storage_items_stackable {
  1952. -   my ($self, $args) = @_;
  1953. -
  1954. -   undef %storage;
  1955. -   undef @storageID;
  1956. -
  1957. -   $self->_items_list({
  1958. -       class => 'Actor::Item',
  1959. -       hook => 'packet_storage',
  1960. -       debug_str => 'Stackable Storage Item',
  1961. -       items => [$self->parse_items_stackable($args)],
  1962. -       adder => sub { $_[0]{binID} = binAdd(\@storageID, $_[0]{index}); $storage{$_[0]{index}} = $_[0] },
  1963. -       callback => sub {
  1964. -           my ($local_item) = @_;
  1965. -
  1966. -           $local_item->{amount} = $local_item->{amount} & ~0x80000000;
  1967. -       },
  1968. -   });
  1969. -
  1970. -   $storageTitle = exists $args->{title} ? $args->{title} : undef;
  1971. -}
  1972. -
  1973. -sub storage_opened {
  1974. -   my ($self, $args) = @_;
  1975. -   $storage{items} = $args->{items};
  1976. -   $storage{items_max} = $args->{items_max};
  1977. -
  1978. -   $ai_v{temp}{storage_opened} = 1;
  1979. -   if (!$storage{opened}) {
  1980. -       $storage{opened} = 1;
  1981. -       $storage{openedThisSession} = 1;
  1982. -       message defined $storageTitle ? TF("Storage '%s' opened.\n", $storageTitle) : T("Storage opened.\n"), "storage";
  1983. -       Plugins::callHook('packet_storage_open');
  1984. -   }
  1985. -}
  1986. -
  1987.  sub storage_password_request {
  1988.     my ($self, $args) = @_;
  1989.  
  1990. Index: Network/Receive/ServerType0.pm
  1991. ===================================================================
  1992. --- Network/Receive/ServerType0.pm  (revision 9000)
  1993. +++ Network/Receive/ServerType0.pm  (working copy)
  1994. @@ -1370,86 +1370,6 @@
  1995.     undef $cardMergeIndex;
  1996.  }
  1997.  
  1998. -sub cart_info {
  1999. -   my ($self, $args) = @_;
  2000. -
  2001. -   $cart{items} = $args->{items};
  2002. -   $cart{items_max} = $args->{items_max};
  2003. -   $cart{weight} = int($args->{weight} / 10);
  2004. -   $cart{weight_max} = int($args->{weight_max} / 10);
  2005. -   $cart{exists} = 1;
  2006. -   debug "[cart_info] received.\n", "parseMsg";
  2007. -}
  2008. -
  2009. -sub cart_add_failed {
  2010. -   my ($self, $args) = @_;
  2011. -
  2012. -   my $reason;
  2013. -   if ($args->{fail} == 0) {
  2014. -       $reason = T('overweight');
  2015. -   } elsif ($args->{fail} == 1) {
  2016. -       $reason = T('too many items');
  2017. -   } else {
  2018. -       $reason = TF("Unknown code %s",$args->{fail});
  2019. -   }
  2020. -   error TF("Can't Add Cart Item (%s)\n", $reason);
  2021. -}
  2022. -
  2023. -sub cart_items_nonstackable {
  2024. -   my ($self, $args) = @_;
  2025. -
  2026. -   $self->_items_list({
  2027. -       # TODO: different classes for inventory/cart/storage items
  2028. -       class => 'Actor::Item',
  2029. -       hook => 'packet_cart',
  2030. -       debug_str => 'Non-Stackable Cart Item',
  2031. -       items => [$self->parse_items_nonstackable($args)],
  2032. -       getter => sub { $cart{inventory}[$_[0]{index}] },
  2033. -       adder => sub { $cart{inventory}[$_[0]{index}] = $_[0] },
  2034. -   });
  2035. -
  2036. -   $ai_v{'inventory_time'} = time + 1;
  2037. -   $ai_v{'cart_time'} = time + 1;
  2038. -}
  2039. -
  2040. -sub cart_items_stackable {
  2041. -   my ($self, $args) = @_;
  2042. -
  2043. -   $self->_items_list({
  2044. -       class => 'Actor::Item',
  2045. -       hook => 'packet_cart',
  2046. -       debug_str => 'Stackable Cart Item',
  2047. -       items => [$self->parse_items_stackable($args)],
  2048. -       getter => sub { $cart{inventory}[$_[0]{index}] },
  2049. -       adder => sub { $cart{inventory}[$_[0]{index}] = $_[0] },
  2050. -   });
  2051. -
  2052. -   $ai_v{'inventory_time'} = time + 1;
  2053. -   $ai_v{'cart_time'} = time + 1;
  2054. -}
  2055. -
  2056. -sub cart_item_added {
  2057. -   my ($self, $args) = @_;
  2058. -
  2059. -   my $item = $cart{inventory}[$args->{index}] ||= Actor::Item->new;
  2060. -   if ($item->{amount}) {
  2061. -       $item->{amount} += $args->{amount};
  2062. -   } else {
  2063. -       $item->{index} = $args->{index};
  2064. -       $item->{nameID} = $args->{nameID};
  2065. -       $item->{amount} = $args->{amount};
  2066. -       $item->{identified} = $args->{identified};
  2067. -       $item->{broken} = $args->{broken};
  2068. -       $item->{upgrade} = $args->{upgrade};
  2069. -       $item->{cards} = $args->{cards};
  2070. -       $item->{type} = $args->{type} if (exists $args->{type});
  2071. -       $item->{name} = itemName($item);
  2072. -   }
  2073. -   message TF("Cart Item Added: %s (%d) x %s\n", $item->{name}, $args->{index}, $args->{amount});
  2074. -   $itemChange{$item->{name}} += $args->{amount};
  2075. -   $args->{item} = $item;
  2076. -}
  2077. -
  2078.  sub cash_dealer {
  2079.     my ($self, $args) = @_;
  2080.  
  2081. @@ -1498,21 +1418,6 @@
  2082.     debug "$args->{actor} $verb combo delay $args->{delay}\n", "parseMsg_comboDelay";
  2083.  }
  2084.  
  2085. -sub cart_item_removed {
  2086. -   my ($self, $args) = @_;
  2087. -
  2088. -   my ($index, $amount) = @{$args}{qw(index amount)};
  2089. -
  2090. -   my $item = $cart{inventory}[$index];
  2091. -   $item->{amount} -= $amount;
  2092. -   message TF("Cart Item Removed: %s (%d) x %s\n", $item->{name}, $index, $amount);
  2093. -   $itemChange{$item->{name}} -= $amount;
  2094. -   if ($item->{amount} <= 0) {
  2095. -       $cart{'inventory'}[$index] = undef;
  2096. -   }
  2097. -   $args->{item} = $item;
  2098. -}
  2099. -
  2100.  sub change_to_constate25 {
  2101.     $net->setState(2.5);
  2102.     undef $accountID;
  2103. @@ -2976,36 +2881,8 @@
  2104.             }
  2105.         }
  2106.     });
  2107. -
  2108. -   $ai_v{'inventory_time'} = time + 1;
  2109. -   $ai_v{'cart_time'} = time + 1;
  2110.  }
  2111.  
  2112. -sub inventory_items_stackable {
  2113. -   my ($self, $args) = @_;
  2114. -   return unless changeToInGameState();
  2115. -
  2116. -   $self->_items_list({
  2117. -       class => 'Actor::Item',
  2118. -       hook => 'packet_inventory',
  2119. -       debug_str => 'Stackable Inventory Item',
  2120. -       items => [$self->parse_items_stackable($args)],
  2121. -       getter => sub { $char->inventory->getByServerIndex($_[0]{index}) },
  2122. -       adder => sub { $char->inventory->add($_[0]) },
  2123. -       callback => sub {
  2124. -           my ($local_item) = @_;
  2125. -
  2126. -           if (defined $char->{arrow} && $local_item->{index} == $char->{arrow}) {
  2127. -               $local_item->{equipped} = 32768;
  2128. -               $char->{equipment}{arrow} = $local_item;
  2129. -           }
  2130. -       }
  2131. -   });
  2132. -
  2133. -   $ai_v{'inventory_time'} = time + 1;
  2134. -   $ai_v{'cart_time'} = time + 1;
  2135. -}
  2136. -
  2137.  sub item_appeared {
  2138.     my ($self, $args) = @_;
  2139.     return unless changeToInGameState();
  2140. @@ -3459,7 +3336,6 @@
  2141.         delete $char->{permitSkill};
  2142.         delete $char->{encoreSkill};
  2143.     }
  2144. -   $cart{exists} = 0;
  2145.     undef %guild;
  2146.  
  2147.     Plugins::callHook('Network::Receive::map_changed', {
  2148. @@ -5668,65 +5544,6 @@
  2149.     }
  2150.  }
  2151.  
  2152. -sub storage_closed {
  2153. -   message T("Storage closed.\n"), "storage";
  2154. -   delete $ai_v{temp}{storage_opened};
  2155. -   delete $storage{opened};
  2156. -   Plugins::callHook('packet_storage_close');
  2157. -
  2158. -   # Storage log
  2159. -   writeStorageLog(0);
  2160. -
  2161. -   if ($char->{dcOnEmptyItems} ne "") {
  2162. -       message TF("Disconnecting on empty %s!\n", $char->{dcOnEmptyItems});
  2163. -       chatLog("k", TF("Disconnecting on empty %s!\n", $char->{dcOnEmptyItems}));
  2164. -       quit();
  2165. -   }
  2166. -}
  2167. -
  2168. -sub storage_item_added {
  2169. -   my ($self, $args) = @_;
  2170. -
  2171. -   my $index = $args->{index};
  2172. -   my $amount = $args->{amount};
  2173. -
  2174. -   my $item = $storage{$index} ||= Actor::Item->new;
  2175. -   if ($item->{amount}) {
  2176. -       $item->{amount} += $amount;
  2177. -   } else {
  2178. -       binAdd(\@storageID, $index);
  2179. -       $item->{nameID} = $args->{nameID};
  2180. -       $item->{index} = $index;
  2181. -       $item->{amount} = $amount;
  2182. -       $item->{type} = $args->{type};
  2183. -       $item->{identified} = $args->{identified};
  2184. -       $item->{broken} = $args->{broken};
  2185. -       $item->{upgrade} = $args->{upgrade};
  2186. -       $item->{cards} = $args->{cards};
  2187. -       $item->{name} = itemName($item);
  2188. -       $item->{binID} = binFind(\@storageID, $index);
  2189. -   }
  2190. -   message TF("Storage Item Added: %s (%d) x %s\n", $item->{name}, $item->{binID}, $amount), "storage", 1;
  2191. -   $itemChange{$item->{name}} += $amount;
  2192. -   $args->{item} = $item;
  2193. -}
  2194. -
  2195. -sub storage_item_removed {
  2196. -   my ($self, $args) = @_;
  2197. -
  2198. -   my ($index, $amount) = @{$args}{qw(index amount)};
  2199. -
  2200. -   my $item = $storage{$index};
  2201. -   $item->{amount} -= $amount;
  2202. -   message TF("Storage Item Removed: %s (%d) x %s\n", $item->{name}, $item->{binID}, $amount), "storage";
  2203. -   $itemChange{$item->{name}} -= $amount;
  2204. -   $args->{item} = $item;
  2205. -   if ($item->{amount} <= 0) {
  2206. -       delete $storage{$index};
  2207. -       binRemove(\@storageID, $index);
  2208. -   }
  2209. -}
  2210. -
  2211.  sub character_equip {
  2212.     my ($self, $args) = @_;
  2213.  
  2214. @@ -5756,56 +5573,6 @@
  2215.     message($msg, "list");
  2216.  }
  2217.  
  2218. -sub storage_items_nonstackable {
  2219. -   my ($self, $args) = @_;
  2220. -
  2221. -   $self->_items_list({
  2222. -       class => 'Actor::Item',
  2223. -       hook => 'packet_storage',
  2224. -       debug_str => 'Non-Stackable Storage Item',
  2225. -       items => [$self->parse_items_nonstackable($args)],
  2226. -       adder => sub { $_[0]{binID} = binAdd(\@storageID, $_[0]{index}); $storage{$_[0]{index}} = $_[0] },
  2227. -   });
  2228. -
  2229. -   $storageTitle = $args->{title} ? $args->{title} : undef;
  2230. -}
  2231. -
  2232. -sub storage_items_stackable {
  2233. -   my ($self, $args) = @_;
  2234. -
  2235. -   undef %storage;
  2236. -   undef @storageID;
  2237. -
  2238. -   $self->_items_list({
  2239. -       class => 'Actor::Item',
  2240. -       hook => 'packet_storage',
  2241. -       debug_str => 'Stackable Storage Item',
  2242. -       items => [$self->parse_items_stackable($args)],
  2243. -       adder => sub { $_[0]{binID} = binAdd(\@storageID, $_[0]{index}); $storage{$_[0]{index}} = $_[0] },
  2244. -       callback => sub {
  2245. -           my ($local_item) = @_;
  2246. -
  2247. -           $local_item->{amount} = $local_item->{amount} & ~0x80000000;
  2248. -       },
  2249. -   });
  2250. -
  2251. -   $storageTitle = $args->{title} ? $args->{title} : undef;
  2252. -}
  2253. -
  2254. -sub storage_opened {
  2255. -   my ($self, $args) = @_;
  2256. -   $storage{items} = $args->{items};
  2257. -   $storage{items_max} = $args->{items_max};
  2258. -
  2259. -   $ai_v{temp}{storage_opened} = 1;
  2260. -   if (!$storage{opened}) {
  2261. -       $storage{opened} = 1;
  2262. -       $storage{openedThisSession} = 1;
  2263. -       message defined $storageTitle ? TF("Storage '%s' opened.\n", $storageTitle) : T("Storage opened.\n"), "storage";
  2264. -       Plugins::callHook('packet_storage_open');
  2265. -   }
  2266. -}
  2267. -
  2268.  sub storage_password_request {
  2269.     my ($self, $args) = @_;
  2270.  
  2271. Index: Network/XKore2/MapServer.pm
  2272. ===================================================================
  2273. --- Network/XKore2/MapServer.pm (revision 9000)
  2274. +++ Network/XKore2/MapServer.pm (working copy)
  2275. @@ -20,7 +20,7 @@
  2276.     $portalsList $npcsList $monstersList $playersList $petsList
  2277.     @friendsID %friends %pet @partyUsersID %spells
  2278.     @chatRoomsID %chatRooms @venderListsID %venderLists $hotkeyList
  2279. -   %config $questList %cart $incomingMessages $masterServer $messageSender
  2280. +   %config $questList $incomingMessages $masterServer $messageSender
  2281.     %cashShop
  2282.  );
  2283.  use Base::Ragnarok::MapServer;
  2284. @@ -516,7 +516,7 @@
  2285.  #                  $data .= pack('C2 v a4 C', 0x96, 0x01, $statusID, $char->{ID}, 1);
  2286.                     if ($statusID == 673) {
  2287.                         # for Cart active
  2288. -                       $data .= pack('C2 v a4 C V4', 0x3F, 0x04, $statusID, $char->{ID}, 1, 9999, $cart{type}, 0, 0);
  2289. +                       $data .= pack('C2 v a4 C V4', 0x3F, 0x04, $statusID, $char->{ID}, 1, 9999, $char->cart->{type}, 0, 0);
  2290.                     } elsif ($statusID == 622) {
  2291.                         # sit
  2292.                         $data .= pack('C2 v a4 C V4', 0x3F, 0x04, $statusID, $char->{ID}, 1, 9999, 1, 0, 0);
  2293. @@ -597,16 +597,14 @@
  2294.     my $data = undef;
  2295.     # Send cart information includeing the items
  2296.     if (!$client->{session}{dummy} && $char->cartActive && $RunOnce) {
  2297. -       $data = pack('C2 v2 V2', 0x21, 0x01, $cart{items}, $cart{items_max}, ($cart{weight} * 10), ($cart{weight_max} * 10));
  2298. +       $data = pack('C2 v2 V2', 0x21, 0x01, $char->cart->{items}, $char->cart->{items_max}, ($char->cart->{weight} * 10), ($char->cart->{weight_max} * 10));
  2299.         $client->send($data);
  2300.        
  2301.         my @stackable;
  2302.         my @nonstackable;
  2303.         my $n = 0;
  2304. -       for (my $i = 0; $i < @{$cart{'inventory'}}; $i++) {
  2305. -           next if (!$cart{'inventory'}[$i] || !%{$cart{'inventory'}[$i]});
  2306. -           my $item = $cart{'inventory'}[$i];
  2307. -           $item->{index} = $i;
  2308. +       foreach my $item (@{$char->cart->getItems()}) {
  2309. +           $item->{index} = $i;#TEST
  2310.             if ($item->{type} <= 3 || $item->{type} == 6 || $item->{type} == 10 || $item->{type} == 16 || $item->{type} == 17 || $item->{type} == 19) {
  2311.                 push @stackable, $item;
  2312.             } else {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement