work like ezza's items transfer macro.
but it's have 2 function in 1 plugin. each of function start by command
reciever use "itemx recieve"
sender use "itemx send"
requirement
- use same storageAuto_npc, storageAuto_npc_type, storageAuto_npc_steps config
- use dealAuto_names config for master name (sender)
itemsTransfer.txt file format
Code: Select all
//Name<TAB>Weight
Aloe 1
Clover 1
Four Leaf Clover 1
Large Jellopy 1
Code: Select all
#########################################################################
# This software is open source, licensed under the GNU General Public
# License, version 2.
# Basically, this means that you're allowed to modify and distribute
# this software. However, if you distribute modified versions, you MUST
# also distribute the source code.
# See http://www.gnu.org/licenses/gpl.html for the full license.
#########################################################################
# Items Transfer
# d3fc0n 1/05/2008
#########################################################################
package itemsTransfer;
use strict;
use Plugins;
use AI;
use Globals qw($char $conState $messageSender $playersList %config %currentDeal %storage %timeout @storageID);
use Log qw(error message);
use Misc qw(deal dealAddItem getNPCInfo);
use Utils qw(distance timeOut);
Plugins::register('itemsTransfer', 'Items Transfer.', \&on_unload);
my $hooks = Plugins::addHooks(
['AI_pre', \&AI_pre]
);
my $cmd = Commands::register(
['itemx', 'Items Transfer.', \&initial]
);
sub on_unload {
Plugins::delHook($hooks);
Commands::unregister($cmd);
}
sub initial {
my (undef, $switch) = @_;
return if (!$switch);
my %args;
$args{npc} = {};
getNPCInfo($config{'storageAuto_npc'}, $args{npc});
if (defined($args{npc}{ok})) {
$config{sellAuto} = 0;
$config{storageAuto} = 0;
parseTransferList("$Plugins::current_plugin_folder/itemsTransfer.txt", \%{$args{list}});
$args{state} = 0;
if ($switch eq 'send') {
$config{dealAuto} = 0;
$args{type} = 0;
} elsif ($switch eq 'recieve') {
$config{dealAuto} = 3;
$args{type} = 1;
} else {
return;
}
AI::queue('itemsTransfer', \%args);
}
}
sub AI_pre {
return unless (($conState == 5) && (AI::action eq 'itemsTransfer'));
my $args = AI::args;
if (distance($args->{npc}{pos}, $char->{pos_to}) > 2) {
$args->{state} = 1;
message "route\n";
ai_route(
$args->{npc}{map},
($args->{type} == 0) ? $args->{npc}{pos}{x} - 1 : $args->{npc}{pos}{x} + 1,
$args->{npc}{pos}{y} - 1,
attackOnRoute => 1
);
return;
}
if (!$storage{opened} && timeOut($timeout{ai_storageAuto_giveup})) {
$timeout{ai_storageAuto_giveup}{time} = time;
$timeout{ai_storageAuto}{time} = time;
if ($config{'storageAuto_npc_type'} eq "" || $config{'storageAuto_npc_type'} eq "1") {
$config{'storageAuto_npc_steps'} = "c r1 n";
} elsif ($config{'storageAuto_npc_type'} eq "2") {
$config{'storageAuto_npc_steps'} = "c c r1 n";
} elsif ($config{'storageAuto_npc_type'} eq "3") {
message T("Using storage steps defined in config.\n"), "info";
} else {
error T("Wrong storageAuto_npc_type.\n");
AI::dequeue();
}
$args->{state} = 2;
message "open store\n";
ai_talkNPC(
$args->{npc}{pos}{x},
$args->{npc}{pos}{y},
$config{'storageAuto_npc_steps'}
);
return;
}
if ($args->{type} == 0) {
if ($storage{opened} && ($args->{state} <= 2) && timeOut($timeout{ai_storageAuto})) {
$timeout{ai_dealAutoCancel}{time} = time;
$timeout{ai_storageAuto}{time} = time;
message "get store\n";
for (my $i = 0; $i < @storageID; $i++) {
next if ($storageID[$i] eq "");
my $item = $storage{$storageID[$i]};
next if (!defined $args->{list}{$item->{name}});
my $amount = int((($char->{'weight_max'} * 90 / 100) - $char->{'weight'}) / $args->{list}{$item->{name}});
if ($amount > 0) {
if ($amount > $item->{amount}) {
$amount = $item->{amount};
}
$messageSender->sendStorageGet($item->{index}, $amount);
return;
} else {
$args->{state} = 3;
$args->{more} = 1;
message "full inv\n";
return;
}
}
message "empty store\n";
$args->{state} = 3;
$args->{more} = 0;
return;
}
if (!%currentDeal && ($args->{state} == 3) && timeOut($timeout{ai_dealAutoCancel})) {
$timeout{ai_dealAutoCancel}{time} = time;
$timeout{ai_dealAuto}{time} = time;
foreach my $pl (@{$playersList->getItems()}) {
if ($pl->{name} eq $config{dealAuto_names}) {
deal($pl);
message "deal start\n";
return;
}
}
return;
}
if (%currentDeal && ($args->{state} == 3) && timeOut($timeout{ai_dealAuto})) {
$timeout{ai_dealAuto}{time} = time;
$timeout{ai_storageAuto}{time} = time;
message "deal add\n";
if ($currentDeal{you_items} < 10) {
for (my $i = 0; $i < @{$char->inventory->getItems()}; $i++) {
my $item = $char->inventory->getItems()->[$i];
next if (!defined $args->{list}{$item->{name}});
next if $item->{equipped};
next if ($item->{broken} && $item->{type} == 7);
dealAddItem($item, $item->{amount});
return;
}
if ($currentDeal{you_items} >= 1) {
$args->{state} = 4;
$messageSender->sendDealFinalize();
message "deal final\n";
return;
} else {
$args->{state} = 2;
$messageSender->sendCurrentDealCancel();
message "deal cancle\n";
if ($args->{more} == 0) {
AI::dequeue();
}
return;
}
} else {
$args->{state} = 4;
$messageSender->sendDealFinalize();
message "deal final\n";
return;
}
}
if ($currentDeal{'you_finalize'} && $currentDeal{'other_finalize'} && ($args->{state} == 4) && timeOut($timeout{ai_dealAuto})) {
$timeout{ai_dealAutoCancel}{time} = time;
$timeout{ai_dealAuto}{time} = time;
$args->{state} = 3;
$messageSender->sendDealTrade();
message "deal end\n";
return;
}
}
if (($args->{type} == 1) && $storage{opened} && timeOut($timeout{ai_storageAuto})) {
$timeout{ai_storageAuto}{time} = time;
if(@storageID >= 300 && $config{'dcOnStorageFull'}) {
error T("Storage is full!\n");
AI::dequeue();
}
foreach my $item (@{$char->inventory->getItems()}) {
next if (!defined $args->{list}{$item->{name}});
next if ($item->{equipped});
next if ($item->{broken} && ($item->{type} == 7));
$messageSender->sendStorageAdd($item->{index}, $item->{amount});
return;
}
return;
}
}
sub parseTransferList {
my ($file, $r_hash) = @_;
undef %{$r_hash};
my $reader = new Utils::TextReader($file);
while (!$reader->eof()) {
my $line = $reader->readLine();
next if ($line =~ /^#/);
$line =~ s/[\r\n\x{FEFF}]//g;
next if (length($line) == 0 || $line =~ /^\/\//);
my ($name, $weight) = split /\t+/, $line, 2;
if (($name ne "") && ($weight ne "")) {
$r_hash->{$name} = $weight;
}
}
return 1;
}
return 1;