From 9d6c8e9eb4e18c1ed3125661774714c525e813fb Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Sun, 17 Nov 2013 17:06:25 -0700 Subject: [PATCH] BHG and Spies worked on. --- docs/Archaeology.pod | 1 + lib/Lacuna/DB/Result/Excavators.pm | 7 +- lib/Lacuna/DB/Result/Spies.pm | 16 +- lib/Lacuna/RPC/Building/Archaeology.pm | 2 + lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 174 +++++++++++++++++- var/messages/bhg_sabotage_them.txt | 7 + var/messages/bhg_sabotage_us.txt | 7 + var/upgrades/3.0895.sql | 2 + var/www/public/changes.txt | 3 + 9 files changed, 208 insertions(+), 11 deletions(-) create mode 100644 var/messages/bhg_sabotage_them.txt create mode 100644 var/messages/bhg_sabotage_us.txt create mode 100644 var/upgrades/3.0895.sql diff --git a/docs/Archaeology.pod b/docs/Archaeology.pod index 74eb4def..14a2ceaf 100644 --- a/docs/Archaeology.pod +++ b/docs/Archaeology.pod @@ -150,6 +150,7 @@ Returns a list of the excavator sites currently controlled by this ministry. "glyph" : 30, "plan" : 7, "resource" : 53 + "date_landed" : Date excav started at location }, ... ] diff --git a/lib/Lacuna/DB/Result/Excavators.pm b/lib/Lacuna/DB/Result/Excavators.pm index d3b533b1..d3ef0ecb 100644 --- a/lib/Lacuna/DB/Result/Excavators.pm +++ b/lib/Lacuna/DB/Result/Excavators.pm @@ -7,9 +7,10 @@ extends 'Lacuna::DB::Result'; __PACKAGE__->table('excavators'); __PACKAGE__->add_columns( - planet_id => { data_type => 'int', size => 11, is_nullable => 0 }, - body_id => { data_type => 'int', size => 11, is_nullable => 0 }, - empire_id => { data_type => 'int', size => 11, is_nullable => 0 }, + planet_id => { data_type => 'int', size => 11, is_nullable => 0 }, + body_id => { data_type => 'int', size => 11, is_nullable => 0 }, + empire_id => { data_type => 'int', size => 11, is_nullable => 0 }, + date_started => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, ); __PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Map::Body', 'body_id'); diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 423ef253..76592f95 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -171,6 +171,11 @@ sub offensive_assignments { recovery => $self->recovery_time(60 * 60 * 8), skill => 'mayhem', }, + { + task =>'Sabotage BHG', + recovery => 0, + skill => 'mayhem', + }, { task =>'Assassinate Operatives', recovery => $self->recovery_time(60 * 60 * 8), @@ -240,7 +245,7 @@ sub get_possible_assignments { my $self = shift; # can't be assigned anything right now - unless ($self->task ~~ ['Counter Espionage','Idle']) { + unless ($self->task ~~ ['Counter Espionage','Idle','Sabotage BHG']) { return [{ task => $self->task, recovery => $self->seconds_remaining_on_assignment }]; } @@ -319,7 +324,7 @@ sub tick_all_spies { sub is_available { my ($self) = @_; my $task = $self->task; - if ($task ~~ ['Idle','Counter Espionage']) { + if ($task ~~ ['Idle','Counter Espionage','Sabotage BHG']) { return 1; } elsif ($task eq 'Mercenary Transport') { @@ -381,6 +386,7 @@ use constant assignments => ( 'Sabotage Resources', 'Appropriate Resources', 'Sabotage Infrastructure', + 'Sabotage BHG', 'Assassinate Operatives', 'Incite Mutiny', 'Abduct Operatives', @@ -411,7 +417,7 @@ sub assign { $self->available_on(DateTime->now->add(seconds => $mission->{recovery})); # run mission - if ($assignment ~~ ['Idle','Counter Espionage']) { + if ($assignment ~~ ['Idle','Counter Espionage','Sabotage BHG']) { $self->update; return {result => 'Accepted', reason => random_element(['I am ready to serve.','I\'m on it.','Consider it done.','Will do.','Yes.','Roger.'])}; } @@ -1558,8 +1564,8 @@ sub steal_planet { my $defender_capitol_id = $self->on_body->empire->home_planet_id; Lacuna->db->resultset('Spies')->search({ - from_body_id => $self->on_body_id, on_body_id => $self->on_body_id, task => 'Training', - })->delete_all; # All spies in training are executed + on_body_id => $self->on_body_id, task => 'Training', + })->delete_all; # All spies in training are executed including those training in intel,mayhem,politics, and theft my $spies = Lacuna->db->resultset('Spies') ->search({from_body_id => $self->on_body_id}); diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 9042d9f4..d402cef3 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -143,6 +143,7 @@ sub view_excavators { glyph => $chances->{glyph}, plan => $chances->{plan}, resource => $chances->{resource}, + date_landed => $building->date_created, }; my $excavators = $building->excavators; my $travel = Lacuna->db->resultset('Lacuna::DB::Result::Ships') @@ -157,6 +158,7 @@ sub view_excavators { glyph => $chances->{glyph}, plan => $chances->{plan}, resource => $chances->{resource}, + date_landed => $excav->date_landed, }; } return { diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 47ec9bc6..c2cb8571 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -540,7 +540,6 @@ sub generate_singularity { } $chance->{success} = 100; } - # Check Target Status my $btype; my $tempire; @@ -703,12 +702,181 @@ sub generate_singularity { } $body->spend_waste($task->{waste_cost})->update; -# $building->start_work({}, $task->{recovery})->update; my $work_ends = DateTime->now; $work_ends->add(seconds => $task->{recovery}); $building->reschedule_work($work_ends); $building->update; - # Pass the basic checks + # Passed basic checks +#Check for enemy spies. + my $lock_down = Lacuna + ->db + ->resultset('Spies') + ->search( + { on_body_id => $body->id, + empire_id => { '!=' => $body->empire_id }, + task => 'Sabotage BHG' }, + { rows => 1, order_by => 'rand()' } + )->single; + if (defined $lock_down) { + my $power = $lock_down->mayhem_xp + $lock_down->offensive + my $defense = 0; + my $hq = $body->get_building_of_class('Lacuna::DB::Result::Building::Security'); + if (defined $hq) { + $defense = int($hq->level * $hq->efficiency /2 + 0.5); + } + my $breakthru = int(($power - $defense + $lock_down->luck)/100 + 0.5); + $breakthru = 5 if $breakthru < 5; + $breakthru = 95 if $breakthru > 95; + my $failure = 0; + my $spy_cond; +#See if spy successfully blocks BHG. + if (randint(0,99) < $breakthru) { # Success! + $subsidize = 0; # Turn off E cost + $chance->{success} = 0; + $failure = 1; + } + else { + $breakthru = $breaktru/2; + } + my $caught = randint(0,99); + if ($caught > $breakthru) { + if (randint(0,2) == 0) { + $spy_cond = "Killed"; + } + else { + $spy_cond = "Captured"; + } + } + elsif ($breakthru - $caught < 10) { + my $rand = randint(0,4); + if ($rand == 0) { + $spy_cond = "Killed"; + } + elsif ($rand < 3) { + $spy_cond = "Captured"; + } + else { + $spy_cond = "Squeek"; + } + } + else { + my $rand = randint(0,9); + if ($rand == 0) { + $spy_cond = "Killed"; + } + elsif ($rand < 3) { + $spy_cond = "Unconscious"; + } + else { + $spy_cond = "Escaped"; + } + } +#Post news +#Send emails + my $o_message; + my $e_message; + my $add_skill = 6; + if ($failure == 1) { + $add_skill = 10; + $lock_down->offense_mission_successes($lock_down->offense_mission_successes + 1 ); + $body->add_news(100, 'Enemy agents prevented the Black Hole Generator on %s to be used!', + $body->name); + if ($spy_cond eq "Killed") { + $o_message = sprintf("We had a security breach with our BHG on %s, causing a misfire, we killed the enemy agent responsible.", + $body->name); + $e_message = sprintf("%s was successful on %s in preventing the BHG to be used, but was killed trying to escape.", + $lock_down->name, $body->name); + } + elsif ($spy_cond eq "Captured") { + $o_message = sprintf("We had a security breach with our BHG on %s, causing a misfire, but we caught %s before they could get away.", + $body->name, $lock_down->name); + $e_message = sprintf("%s was successful on %s in preventing the BHG to be used, but was captured.", + $lock_down->name, $body->name); + } + elsif ($spy_cond eq "Squeek") { + $o_message = sprintf("We had a security breach with our BHG on %s, causing a misfire, the agent responsible got away.", + $body->name); + $e_message = sprintf("%s was successful on %s in preventing the BHG to be used, but was spotted getting away.", + $lock_down->name, $body->name); + } + elsif ($spy_cond eq "Escaped") { + $o_message = sprintf("Our BHG on %s misfired today. We suspect enemy action.", + $body->name); + $e_message = sprintf("%s was successful on %s in preventing the BHG to be used, %s suspect nothing.", + $lock_down->name, $body->name, $body->empire->name); + } + elsif ($spy_cond eq "Unconscious") { + $o_message = sprintf("Our BHG on %s misfired today causing many of our scientists to be sent to the hospital.", + $body->name); + $e_message = sprintf("%s was successful on %s in preventing the BHG to be used, but has not reported back. He may be in the hospital.", + $lock_down->name, $body->name); + } + } + else { + if ($spy_cond eq "Killed") { + $o_message = sprintf("Our security spotted an enemy agent before he could cause a problem on %s. He was shot trying to resist arrest.", + $body->name); + $e_message = sprintf("%s was killed trying to stop the BHG on %s.", + $lock_down->name, $body->name); + } + elsif ($spy_cond eq "Captured") { + $o_message = sprintf("Our security spotted an enemy agent before they could cause a problem on %s. They are currently under going interrogation.", + $body->name); + $e_message = sprintf("%s was captured trying to stop the BHG on %s.", + $lock_down->name, $body->name); + } + elsif ($spy_cond eq "Squeek") { + $o_message = sprintf("Our security spotted an enemy agent before they could cause a problem on %s. Regrettfully, they got away.", + $body->name); + $e_message = sprintf("%s was almost captured trying to stop the BHG on %s.", + $lock_down->name, $body->name); + } + elsif ($spy_cond eq "Escaped") { + $o_message = sprintf("We noticed an odd power fluctuation with our BHG on %s, but everything worked as expected.", + $body->name); + $e_message = sprintf("%s was almost captured trying to stop the BHG on %s.", + $lock_down->name, $body->name); + } + elsif ($spy_cond eq "Unconscious") { + $o_message = sprintf("We need to have a meeting about safety concerns at the BHG on %s. We found another unconsious worker there.", + $body->name); + $e_message = sprintf("%s was knocked out trying to sabotage the BHG on %s.", + $lock_down->name, $body->name); + } + } + $body->empire->send_predefined_message( + tags => ['Spies','Alert'], + filename => 'bhg_sabotage_us.txt', + params => [$o_message], + ); + $lock_down->empire->send_predefined_message( + tags => ['Spies','Alert'], + filename => 'bhg_sabotage_them.txt', + params => [$o_message], + ); + if ($spy_cond eq "Killed") { + $lock_down->available_on(DateTime->now->add(years => 5)); + $lock_down->task('Killed In Action'); + } + elsif ($spy_cond eq "Captured") { + $lock_down->available_on(DateTime->now->add(days=>7)); + $lock_down->task('Captured'); + $lock_down->started_assignment(DateTime->now); + $lock_down->times_captured( $self->times_captured + 1 ); + } + elsif ($spy_cond eq "Squeek" or $spy_cond eq "Escaped") { + } + elsif ($spy_cond eq "Unconscious") { + $lock_down->available_on(DateTime->now->add(seconds => randint(120, 60 * 60 * 48))); + $lock_down->task('Unconscious'); + } + my $off_skill = $lock_down->mayhem_xp + $add_skill; + $off_skill = 2600 if ($off_skill > 2600); + $lock_down->mayhem_xp($off_skill); + $lock_down->offense_mission_count( $lock_down->offense_mission_count + 1); + $lock_down->update; + } +### # Check for startup failure my $roll = randint(0,99); if ($roll >= $chance->{success}) { diff --git a/var/messages/bhg_sabotage_them.txt b/var/messages/bhg_sabotage_them.txt new file mode 100644 index 00000000..775e09c6 --- /dev/null +++ b/var/messages/bhg_sabotage_them.txt @@ -0,0 +1,7 @@ +BHG Sabotage Results +~~~ +%s + +Regards, + +Your Humble Assistant diff --git a/var/messages/bhg_sabotage_us.txt b/var/messages/bhg_sabotage_us.txt new file mode 100644 index 00000000..335a3cf6 --- /dev/null +++ b/var/messages/bhg_sabotage_us.txt @@ -0,0 +1,7 @@ +BHG Sabotaged! +~~~ +%s + +Regards, + +Your Humble Assistant diff --git a/var/upgrades/3.0895.sql b/var/upgrades/3.0895.sql new file mode 100644 index 00000000..c1131bc9 --- /dev/null +++ b/var/upgrades/3.0895.sql @@ -0,0 +1,2 @@ + +alter table excavators add column `date_landed` datetime NOT NULL default '2013-11-09 07:05:03'; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 6122113f..17d731a8 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,6 +1,9 @@ 3.0895: - Fix: Bad error message when not enough glyphs for a mission fixed. - Fix: Fetch Spies exploit filled in. + - Fix: BHG Sabotage option available + - Add: Date Landed returned from excavation sites. + - Fix: All spies in training on a planet are executed on new management. 3.0894: - API: repair_list checks number of fed building ids, rejection of call if over max building count. -- 2.51.2