forked from popiel/Lacuna-Automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade_building.pl
executable file
·45 lines (37 loc) · 1.2 KB
/
upgrade_building.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl
use strict;
use Client;
use Getopt::Long;
use JSON::PP;
my $config_name = "config.json";
my $body_name;
my $building_name;
my $level;
GetOptions(
"config=s" => \$config_name,
"body=s" => \$body_name,
"building=s" => \$building_name,
"level=i" => \$level,
) or die "$0 --config=foo.json --body=Bar --building=Mine --level=1\n";
my $client = Client->new(config => $config_name);
my $body_id;
if ($body_name) {
my $planets = $client->empire_status->{planets};
for my $id (keys(%$planets)) {
$body_id = $id if $planets->{$id} =~ /$body_name/;
}
die "No matching planet for name $body_name\n" unless $body_id;
} else {
$body_id = $client->empire_status->{home_planet_id};
}
my $result = $client->body_buildings($body_id);
for my $id (keys %{$result->{buildings}}) {
my $building = $result->{buildings}{$id};
if ($building->{name} =~ /$building_name/ &&
(!$level || $building->{level} == $level)) {
my $upgrade = $client->building_upgrade($building->{url}, $id);
print "Upgrade complete at ".Client::format_time(Client::parse_time($upgrade->{building}{pending_build}{end}))."\n";
exit(0);
}
}
die "No matching building for name $building_name level $level\n";