Last active
February 14, 2017 11:20
-
-
Save Mortimal/1892a240b7964fc25d66178e87b37b88 to your computer and use it in GitHub Desktop.
bulkbuyer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################################### | |
# 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. | |
######################################################################### | |
# list former for buying items bulk from same npc | |
# Mortimal 13.02.2017 | |
######################################################################### | |
# Manual: | |
# Edit CoreLogic.pm -> sub processAutoBuy {...} | |
# | |
# Remove: | |
# | |
# $messageSender->sendBuyBulk([{itemID => $args->{itemID}, amount => ($maxbuy > $needbuy) ? $needbuy : $maxbuy}]); | |
# | |
# Put instead: | |
# | |
# my @bulkitemlist; | |
# push (@bulkitemlist,{itemID => $args->{itemID}, amount => ($maxbuy > $needbuy) ? $needbuy : $maxbuy}); | |
# Plugins::callHook( 'buy_ready', { items => \@bulkitemlist , index => $args->{index}}); | |
# $messageSender->sendBuyBulk(\@bulkitemlist); | |
######################################################################### | |
package bulkbuyer; | |
use Globals qw($char %config %items_lut); | |
use Plugins; | |
use Log qw(warning); | |
use Translation qw(T TF); | |
return unless | |
Plugins::register('bulkbuyer', 'Buying bulk from the same npc', \&on_unload); | |
my $hooks = Plugins::addHooks( | |
['buy_ready', \&onBuyReady], | |
); | |
sub on_unload { | |
Plugins::delHook($hooks); | |
} | |
sub onBuyReady{ | |
my $bulkhash = $_[1]->{items}; | |
my $exstitemid = $_[1]->{index}; | |
my $zenyleft = $char->{zeny} - (@$bulkhash[0]->{amount} * $config{"buyAuto_$exstitemid"."_price"}); | |
for (my $i = 1; exists $config{"buyAuto_$i"}; $i++) | |
{ | |
my $item = $char->inventory->getByName($config{"buyAuto_$i"}); | |
if ($i != $exstitemid | |
&& $config{"buyAuto_$exstitemid"."_npc"} eq $config{"buyAuto_$i"."_npc"} | |
&& $config{"buyAuto_$i"."_minAmount"} ne "" | |
&& $config{"buyAuto_$i"."_maxAmount"} ne "" | |
&& $config{"buyAuto_$i"."_disabled"} != 1 | |
&& !exists($bulkhash{index}->{$config{"buyAuto_$i"}}) | |
&& (!$item | |
|| ($item->{amount} <= $config{"buyAuto_$i"."_minAmount"} | |
&& $item->{amount} < $config{"buyAuto_$i"."_maxAmount"} | |
) | |
) | |
) | |
{ | |
my $maxbuy = ($config{"buyAuto_$i"."_price"}) ? int($zenyleft/$config{"buyAuto_$i"."_price"}) : 30000; | |
my $needbuy = $config{"buyAuto_$i"."_maxAmount"}; | |
$needbuy -= $item->{amount} if ($item); | |
my $sendamount = ($maxbuy > $needbuy) ? $needbuy : $maxbuy; | |
if ($sendamount > 0) | |
{ | |
$zenyleft -= $sendamount * $config{"buyAuto_$i"."_price"}; | |
my $buyindex; | |
my $counter = 0; | |
if ($item) | |
{ | |
$buyindex = $item->{index}; | |
} else | |
{ | |
foreach (keys %items_lut) | |
{ | |
if (lc($items_lut{$_}) eq lc($config{"buyAuto_$i"})) | |
{ | |
$buyindex = $_; | |
$counter++; | |
} | |
} | |
} | |
if (!$buyindex) | |
{ | |
warning TF("No item id '%s' exists in items.txt. Not buying.\n", $config{"buyAuto_$i"}); | |
} elsif ($counter > 1) | |
{ | |
warning TF("More than one item id '%s' exists in items.txt. Not buying.\n", $config{"buyAuto_$i"}); | |
} else | |
{ | |
push (@$bulkhash, {itemID => $buyindex, amount => $sendamount}); | |
} | |
} else | |
{ | |
warning TF("No zeny to buy even 1 '%s'. Skiped.\n", $config{"buyAuto_$i"}); | |
} | |
} | |
} | |
return 1; | |
} | |
return 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment