diff --git a/lib/Lacuna/DB/Result/Building/MunitionsLab.pm b/lib/Lacuna/DB/Result/Building/MunitionsLab.pm index 3e053b87..1900df14 100644 --- a/lib/Lacuna/DB/Result/Building/MunitionsLab.pm +++ b/lib/Lacuna/DB/Result/Building/MunitionsLab.pm @@ -51,6 +51,14 @@ use constant water_consumption => 20; use constant waste_production => 15; +after finish_upgrade => sub { + my $self = shift; + my $empire = $self->body->empire; + if ($empire->is_isolationist) { + $empire->is_isolationist(0); + $empire->update; + } +}; no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/t/TestHelper.pm b/t/TestHelper.pm index 5d00a00d..1e9d28ca 100644 --- a/t/TestHelper.pm +++ b/t/TestHelper.pm @@ -170,6 +170,7 @@ sub build_infrastructure { $home->energy_stored(50000000); $home->water_stored(50000000); $home->add_happiness(50000000); + $home->monazite_stored(5000000); } else { $home->algae_stored(100_000); diff --git a/t/bugs/0003_PurchaseTooManyShips.t b/t/bugs/0003_PurchaseTooManyShips.t index 5125f425..5eac881d 100644 --- a/t/bugs/0003_PurchaseTooManyShips.t +++ b/t/bugs/0003_PurchaseTooManyShips.t @@ -26,9 +26,12 @@ $trader->empire->add_essentia(100, 'testing transporter')->update; my $tester_spaceport = $tester->build_building('Lacuna::DB::Result::Building::SpacePort', 2); my $tester_shipyard = $tester->build_building('Lacuna::DB::Result::Building::Shipyard', 2); my $tester_transporter = $tester->build_building('Lacuna::DB::Result::Building::Transporter', 10); -my $trader_spaceport = $trader->build_building('Lacuna::DB::Result::Building::SpacePort', 2); -my $trader_shipyard = $trader->build_building('Lacuna::DB::Result::Building::Shipyard', 2); +my $tester_trade = $tester->build_building('Lacuna::DB::Result::Building::Trade', 10); + +my $trader_spaceport = $trader->build_building('Lacuna::DB::Result::Building::SpacePort', 8); +my $trader_shipyard = $trader->build_building('Lacuna::DB::Result::Building::Shipyard', 8); my $trader_transporter = $trader->build_building('Lacuna::DB::Result::Building::Transporter', 10); +my $trader_trade = $trader->build_building('Lacuna::DB::Result::Building::Trade', 20); # build just under the max ships the tester space port can hold for ( 0 .. 2 ) { @@ -40,28 +43,44 @@ $tester->finish_ships($tester_shipyard->id); # build some ships for the trader to trade my @ships; -for ( 0 .. 3 ) { +for ( 0 .. 7 ) { my $dory = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->new({type=>'dory'}); $trader_shipyard->build_ship($dory); push @ships, $dory; } +my $freighter = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->new({type=>'freighter'}); +$trader_shipyard->build_ship($freighter); + $trader->finish_ships($trader_shipyard->id); -# Trader puts 4 ships on the SST -my $result = $trader->post('transporter', 'add_to_market', [$trader_session_id, $trader_transporter->id, [ +# Trader puts 4 ships on the Trade ministry +my $result = $trader->post('trade', 'add_to_market', [$trader_session_id, $trader_trade->id, [ { type => 'ship', ship_id => $ships[0]->id}, { type => 'ship', ship_id => $ships[1]->id}, { type => 'ship', ship_id => $ships[2]->id}, { type => 'ship', ship_id => $ships[3]->id}, +], 1, { ship_id => $freighter->id}]); +my $trade_trade_id = $result->{result}{trade_id}; +ok($trade_trade_id, 'there is a trade on the Trade Ministry'); + +# Trader puts 4 ships on the SST +$result = $trader->post('transporter', 'add_to_market', [$trader_session_id, $trader_transporter->id, [ + { type => 'ship', ship_id => $ships[4]->id}, + { type => 'ship', ship_id => $ships[5]->id}, + { type => 'ship', ship_id => $ships[6]->id}, + { type => 'ship', ship_id => $ships[7]->id}, ], 1]); -my $trade_id = $result->{result}{trade_id}; -ok($trade_id, 'there is a trade'); +my $transporter_trade_id = $result->{result}{trade_id}; +ok($transporter_trade_id, 'there is a trade on the Transporter'); Lacuna->cache->set('captcha', $tester_session_id, { guid => 1111, solution => 1111 }, 60 * 15 ); $tester->post('captcha', 'solve', [$tester_session_id, 1111, 1111]); -$result = $tester->post('transporter', 'accept_from_market', [$tester_session_id, $tester_transporter->id, $trade_id]); -is($result->{error}{code}, 1009, 'Cannot accept more ships than the space port can accept'); +$result = $tester->post('transporter', 'accept_from_market', [$tester_session_id, $tester_transporter->id, $transporter_trade_id]); +is($result->{error}{code}, 1009, 'Cannot accept more ships than the space port can accept via Transporter'); + +$result = $tester->post('trade', 'accept_from_market', [$tester_session_id, $tester_trade->id, $trade_trade_id]); +is($result->{error}{code}, 1009, 'Cannot accept more ships than he space port can accept via Trade'); diff --git a/t/bugs/0009_MunitionsDoesNotBreakIsolation.t b/t/bugs/0009_MunitionsDoesNotBreakIsolation.t new file mode 100644 index 00000000..07b4f3a8 --- /dev/null +++ b/t/bugs/0009_MunitionsDoesNotBreakIsolation.t @@ -0,0 +1,50 @@ +use lib '..','../../lib'; +use Test::More tests => 2; +use Test::Deep; +use 5.010; + +use strict; +use warnings; + +use TestHelper; +TestHelper->clear_all_test_empires; + +# BUG Building a Munitions does not break isolationism + +my $tester = TestHelper->new({ big_producer => 1 })->generate_test_empire->build_infrastructure; +my $tester_session_id = $tester->session->id; +my $empire = $tester->empire; +my $home = $empire->home_planet; + +$tester->find_empty_plot; +my $result = $tester->post('munitionslab', 'build', [$tester_session_id, $home->id, $tester->x, $tester->y]); +my $munitions = $tester->get_building($result->{result}{building}{id}); +$munitions->finish_upgrade; +$home->tick; + +$empire->discard_changes; + +is($empire->is_isolationist, 0, 'Empire is now isolationist after building munitions'); + +$empire->is_isolationist(1); +$empire->update; + +$tester->find_empty_plot; +$result = $tester->post('intelligence', 'build', [$tester_session_id, $home->id, $tester->x, $tester->y]); +my $intelligence = $tester->get_building($result->{result}{building}{id}); +$intelligence->finish_upgrade; + +$tester->find_empty_plot; +$result = $tester->post('espionage', 'build', [$tester_session_id, $home->id, $tester->x, $tester->y]); +my $espionage = $tester->get_building($result->{result}{building}{id}); +$espionage->finish_upgrade; +$home->tick; + +$empire->discard_changes; + +is($empire->is_isolationist, 0, 'Empire is now isolationist after building espionage'); + + +END { +# TestHelper->clear_all_test_empires; +}