diff --git a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm index 3d0581e6..e49cf4ef 100644 --- a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm +++ b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm @@ -7,28 +7,56 @@ extends 'Lacuna::DB::Result::Propositions'; before pass => sub { my ($self) = @_; - my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($self->scratch->{body_id}); + my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($self->scratch->{body_id}); + my $station = $self->station; + my $parl = $station->parliament; + if (defined $body && $body->isa('Lacuna::DB::Result::Map::Body::Planet')) { if (eval {$self->station->in_jurisdiction($body)}) { - if (defined $body->empire_id && $body->empire_id) { - foreach my $building (@{$body->building_cache}) { - next unless ('Infrastructure' ~~ [$building->build_tags]); - next if ( $building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' ); - $building->efficiency(0); - $building->update; + my $costs = { + food => 1e6, + energy => 10e6, + ore => 100e6, + water => 10e6, + }; + if (eval { $station->has_resources_to_build($parl, $costs); 1}) + { + $station->spend_food($costs->{food}, 0); + $station->spend_water($costs->{water}); + $station->spend_ore($costs->{ore}); + $station->spend_energy($costs->{energy}); + $station->needs_recalc(1); + $station->update; + + if (defined $body->empire_id && $body->empire_id) { + foreach my $building (@{$body->building_cache}) { + next unless ('Infrastructure' ~~ [$building->build_tags]); + next if ( $building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' ); + $building->efficiency(0); + $building->update; + } + $body->needs_recalc(1); + $body->needs_surface_refresh(1); + $body->update; + $body->add_news(99, sprintf('The parliament of %s has fired their BFG at %s, devastating the surface.', $self->station->name, $body->name)); + $body->empire->send_message( + subject => 'BFG Damage', + body => "The parliament of ".$self->station->name." has fired their BFG at ".$body->name.". The planet has been devastated, and I doubt it's repairable.\n\nRegards,\n\nYour Humble Assistant", + tag => 'Alert', + ); + } + else { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the planet was no longer occupied.'); } - $body->needs_recalc(1); - $body->needs_surface_refresh(1); - $body->update; - $body->add_news(99, sprintf('The parliament of %s has fired their BFG at %s, devastating the surface.', $self->station->name, $body->name)); - $body->empire->send_message( - subject => 'BFG Damage', - body => "The parliament of ".$self->station->name." has fired their BFG at ".$body->name.". The planet has been devastated, and I doubt it's repairable.\n\nRegards,\n\nYour Humble Assistant", - tag => 'Alert', - ); } else { - $self->pass_extra_message('Unfortunately, by the time the proposition passed, the planet was no longer occupied.'); + $parl->level($parl->level - 1); + $parl->efficiency($parl->efficiency - 25); + $parl->update; + $self->station->update; + + $self->station->add_news(49, sprintf('The parliament of %s suffered a malfunction today while trying to fire their BFG.', $self->station->name)); + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the station no longer had sufficient resources to fire with.'); } } else { diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index bd4d6a67..d0ea344e 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -178,6 +178,9 @@ sub propose_fire_bfg { unless ($building->effective_level >= 25) { confess [1013, 'Parliament must be level 25 to propose using the BFG.',25]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } Lacuna::Verify->new(content=>\$reason, throws=>[1005,'Reason cannot be empty.',$reason])->not_empty; Lacuna::Verify->new(content=>\$reason, throws=>[1005,'Reason cannot contain HTML tags or entities.',$reason])->no_tags; Lacuna::Verify->new(content=>\$reason, throws=>[1005,'Reason cannot contain profanity.',$reason])->no_profanity; @@ -219,6 +222,9 @@ sub propose_writ { unless ($building->effective_level >= 4) { confess [1013, 'Parliament must be level 4 to propose a writ.',4]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } Lacuna::Verify->new(content=>\$title, throws=>[1005,'Title cannot be empty.',$title])->not_empty; Lacuna::Verify->new(content=>\$title, throws=>[1005,'Title cannot contain any of these characters: {}<>&;@',$title])->no_restricted_chars; Lacuna::Verify->new(content=>\$title, throws=>[1005,'Title must be less than 30 characters.',$title])->length_lt(30); @@ -251,6 +257,9 @@ sub propose_transfer_station_ownership { unless ($building->effective_level >= 6) { confess [1013, 'Parliament must be level 6 to transfer station ownership.',6]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($to_empire_id) { confess [1002, 'Must specify an empire id to transfer the station to.']; } @@ -290,6 +299,9 @@ sub propose_seize_star { unless ($building->effective_level >= 7) { confess [1013, 'Parliament must be level 7 to seize control of a star.',7]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($star_id) { confess [1002, 'Must specify a star id to seize.']; } @@ -344,6 +356,9 @@ sub propose_repeal_law { unless ($building->effective_level >= 5) { confess [1013, 'Parliament must be level 5 to repeal a law.',5]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($law_id) { confess [1002, 'Must specify a law id to repeal.']; } @@ -377,6 +392,9 @@ sub propose_rename_star { unless ($building->effective_level >= 8) { confess [1013, 'Parliament must be level 8 to rename a star.',8]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($star_id) { confess [1002, 'Must specify a star id to rename.']; } @@ -420,6 +438,9 @@ sub propose_broadcast_on_network19 { unless ($building->effective_level >= 9) { confess [1013, 'Parliament must be level 9 to propose a broadcast.',9]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } Lacuna::Verify->new(content=>\$message, throws=>[1005,'Message cannot be empty.',$message])->not_empty; Lacuna::Verify->new(content=>\$message, throws=>[1005,'Message cannot contain any of these characters: {}<>&;@',$message])->no_restricted_chars; Lacuna::Verify->new(content=>\$message, throws=>[1005,'Message must be less than 141 characters.',$message])->length_lt(141); @@ -451,6 +472,9 @@ sub propose_rename_asteroid { unless ($building->effective_level >= 12) { confess [1013, 'Parliament must be level 12 to rename an asteroid.',12]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($asteroid_id) { confess [1002, 'Must specify a asteroid id to rename.']; } @@ -494,6 +518,9 @@ sub propose_rename_uninhabited { unless ($building->effective_level >= 17) { confess [1013, 'Parliament must be level 17 to rename an uninhabited planet.',17]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($planet_id) { confess [1002, 'Must specify a planet id to rename.']; } @@ -540,6 +567,9 @@ sub propose_members_only_mining_rights { unless ($building->effective_level >= 13) { confess [1013, 'Parliament must be level 13 to propose members only mining rights.',13]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ type => 'MembersOnlyMiningRights', name => 'Members Only Mining Rights', @@ -565,6 +595,9 @@ sub propose_members_only_excavation { unless ($building->effective_level >= 20) { confess [1013, 'Parliament must be level 20 to propose members only excavation rights.',20]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ type => 'MembersOnlyExcavation', name => 'Members Only Excavation', @@ -590,6 +623,9 @@ sub propose_members_only_colonization { unless ($building->effective_level >= 18) { confess [1013, 'Parliament must be level 18 to propose members only colonization.',18]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ type => 'MembersOnlyColonization', name => 'Members Only Colonization', @@ -615,6 +651,9 @@ sub propose_neutralize_bhg { unless ($building->effective_level >= 23) { confess [1013, 'Parliament must be level 23 to propose to neutralize black hole generators.',23]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ type => 'BHGNeutralized', name => 'BHG Neutralized', @@ -640,6 +679,9 @@ sub propose_evict_mining_platform { unless ($building->effective_level >= 14) { confess [1013, 'Parliament must be level 14 to evict a mining platform.',14]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($platform_id) { confess [1002, 'You must specify a mining platform id.']; } @@ -676,6 +718,9 @@ sub propose_evict_excavator { unless ($building->effective_level >= 21) { confess [1013, 'Parliament must be level 21 to evict an excavator.',21]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($excav_id) { confess [1002, 'You must specify an excavator id.']; } @@ -712,6 +757,9 @@ sub propose_elect_new_leader { unless ($building->effective_level >= 11) { confess [1013, 'Parliament must be level 11 to elect a new alliance leader.',11]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($to_empire_id) { confess [1002, 'Must specify an empire id to elect a new alliance leader.']; } @@ -748,6 +796,9 @@ sub propose_induct_member { unless ($building->effective_level >= 10) { confess [1013, 'Parliament must be level 10 to induct a new alliance member.',10]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } my $alliance = $building->body->alliance; my $count = $alliance->members->count; $count += $alliance->invites->count; @@ -791,6 +842,9 @@ sub propose_expel_member { unless ($building->effective_level >= 10) { confess [1013, 'Parliament must be level 10 to expel an alliance member.',10]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($empire_id) { confess [1002, 'Must specify an empire id to expel an alliance member.']; } @@ -830,6 +884,9 @@ sub propose_taxation { unless ($building->effective_level >= 15) { confess [1013, 'Parliament must be level 15 to propose taxation.',15]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($taxes =~ /^\d+$/ && $taxes > 0 ) { confess [1009, 'Taxes must be an integer greater than 0.']; @@ -860,6 +917,9 @@ sub propose_foreign_aid { unless ($building->effective_level >= 16) { confess [1013, 'Parliament must be level 16 to send out foreign aid packages.',16]; } + unless ($building->effective_level > 0 and $building->effective_efficiency == 100) { + confess [1003, "You must have a functional Parliament!"]; + } unless ($planet_id) { confess [1002, 'You must specify a planet id.']; }