From 0f877068a3220e846cbf5646e2db988771f0fb89 Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Thu, 25 Dec 2014 18:06:42 -0700 Subject: [PATCH] More futzing --- bin/util/christmas_2014.pl | 92 ++++++++++++++++++++++++ lib/Lacuna/DB/Result/Ships.pm | 13 ++-- lib/Lacuna/RPC/Building/SpacePort.pm | 1 - lib/Lacuna/Role/Container.pm | 15 ++++ lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm | 5 +- 5 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 bin/util/christmas_2014.pl diff --git a/bin/util/christmas_2014.pl b/bin/util/christmas_2014.pl new file mode 100644 index 00000000..923d5c92 --- /dev/null +++ b/bin/util/christmas_2014.pl @@ -0,0 +1,92 @@ +use 5.010; +use strict; +use lib '/data/Lacuna-Server/lib'; +use Lacuna::DB; +use Lacuna; +use Lacuna::Util qw(randint format_date); +use Getopt::Long; +$|=1; +our $quiet; +our $all; +GetOptions( + 'quiet' => \$quiet, + 'all' => \$all, +); + + +out('Started'); +my $start = time; + +out('Loading DB'); +our $db = Lacuna->db; +my $empires = $db->resultset('Empire'); + +my $lec = $empires->find(1); + +if (not $all) { + $empires = $empires->search({ is_admin => 1 }); +} + +$empires = $empires->search({ id => {'>' => 1}}); + +my $message = q{As it is approaching what your Species calls 'Christmas' it seems that it is now traditional to send gifts to each other at this time. + +In order to foster good will between all species we have taken the liberty of sending you two plans for Sub Space Depots, a plan for a sculpture, and increased your boost time by one of your traditional months. + +How you use the the plans is up to you. You may use them yourselves, perhaps on one of your new colonies. Some of the more mature species may decide that at your level of technology you have little use for them yourselves, in which case you may wish to extend the hand/tenticle/pseudopod (delete as appropriate) of friendship and share them with some of the less developed empires. + +In any case, we wish you well for your next solar orbital period. + +Your Trading Partner, + +Tou Re Ell + +Lacuna Expanse Corp}; + +out('Sending Messages'); +while (my $empire = $empires->next) { + my $home = $empire->home_planet; + next unless defined $home; + out('Sending message to '.$empire->name); + $empire->send_message( + tag => 'Correspondence', + subject => 'A Gift.', + from => $lec, + body => $message, + ); + + my $btype = $home->get_type; + unless ($btype eq 'habitable planet' or $btype eq 'gas giant') { + out('Home planet type is '.$btype.'! Skipping.'); + next; + } + $home->add_plan('Lacuna::DB::Result::Building::SubspaceSupplyDepot', 1, 0, 2); + $home->add_plan('Lacuna::DB::Result::Building::Permanent::JunkHengeSculpture', 1, 0, 1); + + for my $boost ('ore_boost','water_boost','energy_boost','food_boost','happiness_boost','storage_boost','building_boost','spy_training_boost') { + my $start = DateTime->now; + $start = $empire->$boost if ($empire->$boost > $start); + $start->add(days=>30); + $empire->planets->update({needs_recalc=>1, boost_enabled=>1}); + $empire->$boost($start); + $empire->update; + } +} + +my $finish = time; +out('Finished'); +out((($finish - $start)/60)." minutes have elapsed"); + + +############### +## SUBROUTINES +############### + +sub out { + my $message = shift; + unless ($quiet) { + say format_date(DateTime->now), " ", $message; + } +} + + diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index fbf8cb20..72c46a01 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -404,12 +404,11 @@ sub send { my %ag_hash = map { $_ => $cnt++ } @ag_list; my $now = DateTime->now; - my $time2arrive = $now->subtract_datetime_absolute($self->date_available); - my $seconds = $time2arrive->seconds; - if ($seconds > 1200 && grep { $self->type eq $_ } @ag_list) { #Don't try to consolidate if ships will be hitting in 20 minutes + my $seconds2arrive = $self->seconds_remaining; + if ($seconds2arrive > 1200 && grep { $self->type eq $_ } @ag_list) { # Only consolidate if ships take longer than 20 minutes my $dtf = Lacuna->db->storage->datetime_parser; - my $start_range = DateTime->now->add(seconds => ($seconds - 900)); - my $end_range = DateTime->now->add(seconds => ($seconds + 900)); + my $start_range = $now->add(seconds => ($seconds2arrive - 900)); + my $end_range = $now->add(seconds => ($seconds2arrive + 900)); my $ships_rs = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $self->body_id, foreign_body_id => $self->foreign_body_id, @@ -419,7 +418,7 @@ sub send { date_available => { between => [ $dtf->format_datetime($start_range), $dtf->format_datetime($end_range) ] }, }); - my $payload = {}; + my $payload; if ($self->type eq "attack_group") { #Turn ship into attack group if not already one $payload = $self->payload; } @@ -483,7 +482,7 @@ sub send { } else { my $key = sprintf("%02d:%s:%05d:%05d:%05d:%09d", - $ag_hash{$self->type}, + $ag_hash{$ship->type}, $ship->type, $ship->speed, $ship->combat, diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index e0ca1584..5dc5c91e 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -350,7 +350,6 @@ sub send_ship_types { number_of_docks => 0, }; my $payload; - $payload->{fleet} = {}; foreach my $ship (values %$ship_ref) { if (grep { $ship->type eq $_ } @ag_list) { diff --git a/lib/Lacuna/Role/Container.pm b/lib/Lacuna/Role/Container.pm index 7391fefe..8c8d6c03 100644 --- a/lib/Lacuna/Role/Container.pm +++ b/lib/Lacuna/Role/Container.pm @@ -131,6 +131,21 @@ sub format_description_of_payload { } push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); + #fleets + undef $scratch; + foreach my $fleet (sort keys %{$payload->{fleet}}) { + my $pattern = '%s (speed: %s, stealth: %s, hold size: %s, combat: %s #: %d)' ; + push @{$scratch}, + sprintf($pattern, + $payload->{fleet}->{$fleet}->{type}, + commify($payload->{fleet}->{$fleet}->{speed}), + commify($payload->{fleet}->{$fleet}->{stealth}), + commify($payload->{fleet}->{$fleet}->{hold_size}), + commify($payload->{fleet}->{$fleet}->{combat}), + commify($payload->{fleet}->{$fleet}->{quantity})); + } + push @{$item_arr}, @{consolidate_items($scratch)} if (defined($scratch)); + # plans undef $scratch; foreach my $stats (@{ $payload->{plans}}) { diff --git a/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm b/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm index 53085a71..ee11eb7f 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm @@ -104,6 +104,7 @@ after send => sub { $room = $hold_size - $payload->{resources}->{waste}; } else { + $payload->{resources}->{waste} = 0; $room = $hold_size; } if ($self->body->waste_stored < $room) { @@ -112,7 +113,7 @@ after send => sub { else { $waste_sent = $room; } - $payload->{resources}->{waste} = $waste_sent; + $payload->{resources}->{waste} += $waste_sent; $self->payload($payload); } else { @@ -122,7 +123,7 @@ after send => sub { else { $waste_sent = $self->hold_size; } - $self->payload({ resources => { waste => $waste_sent } }); + $self->payload({ resources => { waste => $waste_sent }, test => { spam => 1 }}); } $self->body->spend_waste($waste_sent)->update; $self->update; -- 2.51.2