diff --git a/bin/clean_up_battle_log.pl b/bin/clean_up_battle_log.pl index b510c8ba..ece54b09 100644 --- a/bin/clean_up_battle_log.pl +++ b/bin/clean_up_battle_log.pl @@ -16,7 +16,7 @@ GetOptions( out('Started'); my $start = time; -my $date_ended = DateTime->now->subtract( days => 7 ); +my $date_ended = DateTime->now->subtract( days => 30 ); out('Loading DB'); our $db = Lacuna->db; diff --git a/lib/Lacuna/DB/Result/Log/Battles.pm b/lib/Lacuna/DB/Result/Log/Battles.pm index 5e4b5989..8ee37525 100644 --- a/lib/Lacuna/DB/Result/Log/Battles.pm +++ b/lib/Lacuna/DB/Result/Log/Battles.pm @@ -14,12 +14,14 @@ __PACKAGE__->add_columns( attacking_body_name => { data_type => 'varchar', size => 30, is_nullable => 0 }, attacking_unit_name => { data_type => 'varchar', size => 60, is_nullable => 0 }, attacking_type => { data_type => 'varchar', size => 60, is_nullable => 0 }, + attacking_number => { data_type => 'int', size => 11, is_nullable => 0 }, defending_empire_id => { data_type => 'int', size => 11, is_nullable => 1 }, defending_empire_name => { data_type => 'varchar', size => 30, is_nullable => 1 }, defending_body_id => { data_type => 'int', size => 11, is_nullable => 0 }, defending_body_name => { data_type => 'varchar', size => 30, is_nullable => 0 }, defending_unit_name => { data_type => 'varchar', size => 60, is_nullable => 0 }, defending_type => { data_type => 'varchar', size => 60, is_nullable => 0 }, + defending_number => { data_type => 'int', size => 11, is_nullable => 0 }, victory_to => { data_type => 'varchar', size => 8, is_nullable => 0 }, attacked_body_id => { data_type => 'int', size => 11, is_nullable => 0 }, attacked_body_name => { data_type => 'varchar', size => 30, is_nullable => 0 }, @@ -59,8 +61,10 @@ after insert => sub { defense_victories => 0, }); } - $ai_battle_summary->attack_victories($ai_battle_summary->attack_victories + 1) if $self->victory_to eq 'attacker'; - $ai_battle_summary->defense_victories($ai_battle_summary->defense_victories + 1) if $self->victory_to eq 'defender'; + $ai_battle_summary->attack_victories($ai_battle_summary->attack_victories + $self->attacking_number) + if $self->victory_to eq 'attacker'; + $ai_battle_summary->defense_victories($ai_battle_summary->defense_victories + $self->defending_number) + if $self->victory_to eq 'defender'; $ai_battle_summary->update; }; diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 95c7e185..a19557f6 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -458,10 +458,6 @@ sub send_fleet { } my @fleet; my $speed = 999999999; - my $distance = $self->body->calculate_distance_to_target($target); - my $max_speed = $distance * 12; # Minimum time to arrive is five minutes - my $min_speed = int($distance/1440 + 0.5); # Max time to arrive is two months - $min_speed = 1 if $min_speed < 1; my $excavator = 0; for my $ship_id (@$ship_ids) { @@ -478,6 +474,14 @@ sub send_fleet { $speed = $ship->speed if ( $speed > $ship->speed ); push @fleet, $ship_id; } + + my $tmp_ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($fleet[0]); + my $body = $tmp_ship->body; + my $distance = $body->calculate_distance_to_target($target); + my $max_speed = $distance * 12; # Minimum time to arrive is five minutes + my $min_speed = int($distance/1440 + 0.5); # Max time to arrive is two months + $min_speed = 1 if $min_speed < 1; + unless ($excavator <= 1) { confess [1010, 'Only one Excavator may be sent to a body by this empire.']; } @@ -487,12 +491,14 @@ sub send_fleet { unless ($set_speed >= 0) { confess [1009, 'Set speed cannot be less than zero.']; } - unless ($set_speed >= $min_speed) { - confess [1009, 'Set speed cannot be set so that ships arrive after 60 days.']; - } #If time to target is longer than 60 days, fail. $speed = $set_speed if ($set_speed > 0 && $set_speed < $speed); $speed = $max_speed if ($speed > $max_speed); + + unless ($speed >= $min_speed) { + confess [1009, 'Set speed cannot be set so that ships arrive after 60 days.']; + } + my @ret; my $captcha_check = 1; diff --git a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm index 79e8d71f..1add1a9b 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DamageBuilding.pm @@ -17,9 +17,7 @@ after handle_arrival_procedures => sub { # check if reasonable to assume zero out everything on planet (depends on type, etc...) # if not, go thru an attack for each. # else return and go to next step -# 1) Group of snarks? -# 2) How many target buildings? -# 3) See if reasonable that buildings get zeroed? + my %snarks = ( snarks => { count => 0, @@ -82,17 +80,17 @@ after handle_arrival_procedures => sub { } } if ($snarkit) { - my $snark_impacts = 0; + my $snark_ships = 0; for my $key (keys %del_keys) { delete $payload->{fleet}->{$key}; - $snark_impacts += $del_keys{$key}; + $snark_ships += $del_keys{$key}; } $self->payload($payload); - $self->number_of_docks($self->number_of_docks - $snark_impacts); + $self->number_of_docks($self->number_of_docks - $snark_ships); $self->update; } else { - return unless $snarkit; + return; } } else { @@ -232,21 +230,23 @@ after handle_arrival_procedures => sub { date_stamp => DateTime->now, attacking_empire_id => $self->body->empire_id, attacking_empire_name => $self->body->empire->name, - attacking_body_id => $self->body_id, + attacking_body_id => $self->body->id, attacking_body_name => $self->body->name, - attacking_unit_name => $self->name, - attacking_type => $self->type_formatted, - defending_empire_id => $body_attacked->empire_id, - defending_empire_name => $body_attacked->empire->name, + attacking_unit_name => "Snarks", + attacking_type => $self->type, + attacking_number => $snarks{snarks}->{count} + $snarks{security_ministry_seeker} + $snarks{observatory_seeker} + $snarks{spaceport_seeker}, + defending_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, + defending_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", defending_body_id => $body_attacked->id, defending_body_name => $body_attacked->name, - defending_unit_name => sprintf("%s (%d,%d)", "ouch", 0, 0), - defending_type => "building_name", - attacked_empire_id => $body_attacked->empire_id, - attacked_empire_name => $body_attacked->empire->name, + defending_unit_name => "Buildings", + defending_type => "building", + defending_number => scalar @all_builds, + victory_to => "attacker", + attacked_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, + attacked_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", attacked_body_id => $body_attacked->id, attacked_body_name => $body_attacked->name, - victory_to => 'attacker', }); $log->insert; diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployBleeder.pm b/lib/Lacuna/Role/Ship/Arrive/DeployBleeder.pm index db03de06..3c016554 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployBleeder.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployBleeder.pm @@ -78,21 +78,23 @@ after handle_arrival_procedures => sub { date_stamp => DateTime->now, attacking_empire_id => $self->body->empire_id, attacking_empire_name => $self->body->empire->name, - attacking_body_id => $self->body_id, + attacking_body_id => $self->body->id, attacking_body_name => $self->body->name, - attacking_unit_name => $self->name, - attacking_type => $self->type_formatted, - defending_empire_id => $body_attacked->empire_id, - defending_empire_name => $body_attacked->empire->name, + attacking_unit_name => "Bleeder", + attacking_type => $self->type, + attacking_number => $bleeders, + defending_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, + defending_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", defending_body_id => $body_attacked->id, defending_body_name => $body_attacked->name, - defending_unit_name => '', - defending_type => '', - attacked_empire_id => $body_attacked->empire_id, - attacked_empire_name => $body_attacked->empire->name, + defending_unit_name => "", + defending_type => "", + defending_number => 0, + victory_to => "attacker", + attacked_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, + attacked_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", attacked_body_id => $body_attacked->id, attacked_body_name => $body_attacked->name, - victory_to => 'attacker', })->insert; if ($done_after) { diff --git a/lib/Lacuna/Role/Ship/Arrive/DeploySmolderingCrater.pm b/lib/Lacuna/Role/Ship/Arrive/DeploySmolderingCrater.pm index ad7cfcf3..68f513fb 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeploySmolderingCrater.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeploySmolderingCrater.pm @@ -75,7 +75,7 @@ after handle_arrival_procedures => sub { } # notify attacked - unless ($craters > 0 and $body_attacked->empire_id && $body_attacked->empire->skip_attack_messages) { + if ($craters > 0 and $body_attacked->empire_id && !$body_attacked->empire->skip_attack_messages) { $body_attacked->empire->send_predefined_message( tags => ['Attack','Alert'], filename => 'thud_hit_us.txt', @@ -91,16 +91,17 @@ after handle_arrival_procedures => sub { attacking_empire_name => $self->body->empire->name, attacking_body_id => $self->body_id, attacking_body_name => $self->body->name, - attacking_unit_name => $self->name, + attacking_unit_name => "Thuds", attacking_type => $self->type_formatted, - defending_empire_id => $body_attacked->empire_id, - defending_empire_name => $body_attacked->empire->name, + attacking_number => $craters, + defending_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, + defending_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", defending_body_id => $body_attacked->id, defending_body_name => $body_attacked->name, defending_unit_name => '', defending_type => '', - attacked_empire_id => $body_attacked->empire_id, - attacked_empire_name => $body_attacked->empire->name, + attacked_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, + attacked_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", attacked_body_id => $body_attacked->id, attacked_body_name => $body_attacked->name, victory_to => 'attacker', diff --git a/lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm b/lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm index de52880a..2e5d1951 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm @@ -41,12 +41,14 @@ after handle_arrival_procedures => sub { attacking_body_name => $self->body->name, attacking_unit_name => $self->name, attacking_type => $self->type_formatted, + attacking_number => 1, defending_empire_id => $empire->id, defending_empire_name => $empire->name, defending_body_id => $body_attacked->id, defending_body_name => $body_attacked->name, defending_unit_name => 'Mining Platform', defending_type => 'Mining Platform', + defending_number => 1, attacked_empire_id => $empire->id, attacked_empire_name => $empire->name, attacked_body_id => $body_attacked->id, @@ -78,12 +80,14 @@ after handle_arrival_procedures => sub { attacking_body_name => $self->body->name, attacking_unit_name => $self->name, attacking_type => $self->type_formatted, + attacking_number => 1, defending_empire_id => $empire->id, defending_empire_name => $empire->name, defending_body_id => $body_attacked->id, defending_body_name => $body_attacked->name, defending_unit_name => 'Excavator', defending_type => 'Excavator', + defending_number => 1, attacked_empire_id => $empire->id, attacked_empire_name => $empire->name, attacked_body_id => $body_attacked->id, diff --git a/lib/Lacuna/Role/Ship/Arrive/DestroyMiningPlatforms.pm b/lib/Lacuna/Role/Ship/Arrive/DestroyMiningPlatforms.pm index b749724a..80081513 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DestroyMiningPlatforms.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DestroyMiningPlatforms.pm @@ -39,12 +39,14 @@ after handle_arrival_procedures => sub { attacking_body_name => $self->body->name, attacking_unit_name => $self->name, attacking_type => $self->type_formatted, + attacking_number => 1, defending_empire_id => $empire->id, defending_empire_name => $empire->name, defending_body_id => $body_attacked->id, defending_body_name => $body_attacked->name, defending_unit_name => 'Mining Platform', defending_type => 'Mining Platform', + defending_number => 1, attacked_empire_id => $empire->id, attacked_empire_name => $empire->name, attacked_body_id => $body_attacked->id, diff --git a/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm b/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm index 13f937b1..0c4955ed 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DumpWaste.pm @@ -52,35 +52,15 @@ after handle_arrival_procedures => sub { $body_attacked->add_news(30, sprintf('%s is so polluted that waste seems to be falling from the sky.', $body_attacked->name)); - my $logs = Lacuna->db->resultset('Lacuna::DB::Result::Log::Battles'); - $logs->new({ - date_stamp => DateTime->now, - attacking_empire_id => $self->body->empire_id, - attacking_empire_name => $self->body->empire->name, - attacking_body_id => $self->body_id, - attacking_body_name => $self->body->name, - attacking_unit_name => $self->name, - attacking_type => $self->type_formatted, - defending_empire_id => $body_attacked->empire_id, - defending_empire_name => $body_attacked->empire->name, - defending_body_id => $body_attacked->id, - defending_body_name => $body_attacked->name, - defending_unit_name => '', - defending_type => '', - attacked_empire_id => $body_attacked->empire_id, - attacked_empire_name => $body_attacked->empire->name, - attacked_body_id => $body_attacked->id, - attacked_body_name => $body_attacked->name, - victory_to => 'attacker', - })->insert; - # all pow my $done_after = 1; + my $number_of_scows = 0; if ($self->type eq "attack_group") { my @trim; for my $key ( keys %{$payload->{fleet}}) { if ( grep { $payload->{fleet}->{$key}->{type} eq $_ } ("scow", "scow_fast", "scow_large", "scow_mega")) { push @trim, $key; + $number_of_scows += $payload->{fleet}->{$key}->{quantity}; } else { $done_after = 0; @@ -91,10 +71,38 @@ after handle_arrival_procedures => sub { for my $key (@trim) { delete $payload->{fleet}->{$key}; } + $self->number_of_docks($self->number_of_docks - $number_of_scows); $self->payload($payload); $self->update; } } + else { + $number_of_scows = 1; + } + my $logs = Lacuna->db->resultset('Lacuna::DB::Result::Log::Battles'); + $logs->new({ + date_stamp => DateTime->now, + attacking_empire_id => $self->body->empire_id, + attacking_empire_name => $self->body->empire->name, + attacking_body_id => $self->body_id, + attacking_body_name => $self->body->name, + attacking_unit_name => "Scows", + attacking_type => $self->type_formatted, + attacking_number => $number_of_scows, + defending_empire_id => $body_attacked->empire_id, + defending_empire_name => $body_attacked->empire->name, + defending_body_id => $body_attacked->id, + defending_body_name => $body_attacked->name, + defending_unit_name => '', + defending_type => '', + defending_type => 0, + attacked_empire_id => $body_attacked->empire_id, + attacked_empire_name => $body_attacked->empire->name, + attacked_body_id => $body_attacked->id, + attacked_body_name => $body_attacked->name, + victory_to => 'attacker', + })->insert; + if ($done_after) { $self->delete; confess [-1]; diff --git a/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm b/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm index 7550061a..6b5b30bc 100644 --- a/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm +++ b/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm @@ -93,8 +93,9 @@ after handle_arrival_procedures => sub { attacking_empire_name => $self->body->empire->name, attacking_body_id => $self->body_id, attacking_body_name => $self->body->name, - attacking_unit_name => $self->name, + attacking_unit_name => "Scanner", attacking_type => $self->type_formatted, + attacking_number => 1, defending_empire_id => $body_attacked->empire_id && defined $body_attacked->empire ? $body_attacked->empire_id : undef, defending_empire_name => $body_attacked->empire_id && @@ -103,6 +104,7 @@ after handle_arrival_procedures => sub { defending_body_name => $body_attacked->name, defending_unit_name => '', defending_type => '', + defending_number => 0, attacked_empire_id => $body_attacked->empire_id && defined $body_attacked->empire ? $body_attacked->empire_id : undef, attacked_empire_name => $body_attacked->empire_id && diff --git a/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm b/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm index a5e7224d..e477bc8a 100644 --- a/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm +++ b/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm @@ -102,8 +102,9 @@ after handle_arrival_procedures => sub { attacking_empire_name => $self->body->empire->name, attacking_body_id => $self->body_id, attacking_body_name => $self->body->name, - attacking_unit_name => $self->name, + attacking_unit_name => "Surveyor", attacking_type => $self->type_formatted, + attacking_number => 1, defending_empire_id => $body_attacked->empire_id && defined $body_attacked->empire ? $body_attacked->empire_id : undef, defending_empire_name => $body_attacked->empire_id && @@ -112,6 +113,7 @@ after handle_arrival_procedures => sub { defending_body_name => $body_attacked->name, defending_unit_name => '', defending_type => '', + defending_number => 0, attacked_empire_id => $body_attacked->empire_id && defined $body_attacked->empire ? $body_attacked->empire_id : undef, attacked_empire_name => $body_attacked->empire_id && diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index 5e3c759c..1140345f 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -72,8 +72,8 @@ sub citadel_interaction { } } my $max_add = 3600 - $cooldown; - my $max_mult = 1 + ($max_add * $citadel->effective_efficiency * $citadel->effective_level)/3_600_000; - # Mult will between 1 and 4 + my $max_mult = 1 + ($max_add * $citadel->effective_efficiency * $citadel->effective_level)/5_400_000; + # Mult will between 1 and 3 return ($max_mult * $combat_def) if $no_add; my $threshold = $combat_att/10; @@ -159,38 +159,58 @@ sub damage_in_combat { } sub log_attack { - my ($attacker, $defender, $victor) = @_; - my $body_attacked = $attacker->foreign_body; - my $logs = Lacuna->db->resultset('Lacuna::DB::Result::Log::Battles'); - $logs->new({ - date_stamp => DateTime->now, - attacking_empire_id => $attacker->body->empire_id, - attacking_empire_name => $attacker->body->empire->name, - attacking_body_id => $attacker->body_id, - attacking_body_name => $attacker->body->name, - attacking_unit_name => - $attacker->isa('Lacuna::DB::Result::Building') ? - sprintf("%s (%d,%d)", $attacker->name, $attacker->x, $attacker->y) : - $attacker->name, - attacking_type => - $attacker->isa('Lacuna::DB::Result::Building') ? - $attacker->name : $attacker->type_formatted, - defending_empire_id => $defender->body->empire_id, - defending_empire_name => $defender->body->empire->name, - defending_body_id => $defender->body->id, - defending_body_name => $defender->body->name, - defending_unit_name => $defender->isa('Lacuna::DB::Result::Building') ? - sprintf("%s (%d,%d)", $defender->name, $defender->x, $defender->y) : - $defender->name, - defending_type => - $defender->isa('Lacuna::DB::Result::Building') ? - $defender->name : $defender->type_formatted, - victory_to => $victor, - attacked_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, - attacked_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", - attacked_body_id => $body_attacked->id, - attacked_body_name => $body_attacked->name, - })->insert; + my ($self, $defense_stat, $attack_stat) = @_; + + my $body_attacked = $self->foreign_body; + + my $bare_hash = { + date_stamp => DateTime->now, + attacking_empire_id => $self->body->empire_id, + attacking_empire_name => $self->body->empire->name, + attacking_body_id => $self->body->id, + attacking_body_name => $self->body->name, + + attacked_empire_id => defined($body_attacked->empire) ? $body_attacked->empire_id : 0, + attacked_empire_name => defined($body_attacked->empire) ? $body_attacked->empire->name : "", + attacked_body_id => $body_attacked->id, + attacked_body_name => $body_attacked->name, + victory_to => "defender", + }; + + for my $dbid (keys %{$defense_stat}) { + for my $dtype (keys %{$defense_stat->{$dbid}}) { + my $new_hash = {}; + %{$new_hash} = %{$bare_hash}; + $new_hash->{attacking_unit_name} = ""; + $new_hash->{attacking_type} = ""; + $new_hash->{attacking_number} = ""; + $new_hash->{defending_empire_id} = $defense_stat->{$dbid}->{$dtype}->{emp_id}, + $new_hash->{defending_empire_name} = $defense_stat->{$dbid}->{$dtype}->{emp_name}, + $new_hash->{defending_body_id} = $dbid, + $new_hash->{defending_body_name} = $defense_stat->{$dbid}->{$dtype}->{body_name}, + $new_hash->{defending_unit_name} = $dtype, + $new_hash->{defending_type} = $dtype, + $new_hash->{defending_number} = $defense_stat->{$dbid}->{$dtype}->{number}, + my $log = Lacuna->db->resultset('Log::Battles')->new($new_hash)->insert; + } + } + for my $abid (keys %{$attack_stat}) { + for my $atype (keys %{$attack_stat->{$abid}}) { + my $new_hash = {}; + %{$new_hash} = %{$bare_hash}; + $new_hash->{attacking_unit_name} = $atype, + $new_hash->{attacking_type} = $atype, + $new_hash->{attacking_number} = $attack_stat->{$abid}->{$atype}->{number}, + $new_hash->{defending_empire_id} = "", + $new_hash->{defending_empire_name} = "", + $new_hash->{defending_body_id} = 0, + $new_hash->{defending_body_name} = "", + $new_hash->{defending_unit_name} = "", + $new_hash->{defending_type} = "", + $new_hash->{defending_number} = 0, + my $log = Lacuna->db->resultset('Log::Battles')->new($new_hash)->insert; + } + } } sub ship_to_ship_combat { @@ -365,11 +385,7 @@ sub system_saw_combat { my $defending_bodies = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body') ->search({ - 'me.star_id' => $attacked_body->star_id, - 'empire.alliance_id' => { '!=' => $ship_aid }, - }, - { - join => 'empire', + star_id => $attacked_body->star_id, }); # Here's where we get total number of defending SAWs # 1) Get all Saws and total combat value @@ -380,13 +396,17 @@ sub system_saw_combat { my $defense_stat; while (my $dbody = $defending_bodies->next) { + next unless $dbody->empire; next unless $dbody->isa('Lacuna::DB::Result::Map::Body::Planet'); + if ($attack_aid) { + next if ($dbody->empire->alliance_id && $dbody->empire->alliance_id == $attack_aid); + } my ($saws, $combat) = saw_stats($dbody); next unless $combat > 0; my $dbid = $dbody->id; $def_cnt++; $combat *= 1.55 if ($dbid == $attacked_body->id); - $combat *= 1.55 if ($dbody->empire_id == $attacked_body->empire_id); + $combat *= 1.55 if ($dbody->empire_id == $defend_eid); $combat *= 1.55 if (($dbody->empire->alliance and $defend_aid != 0) and ($dbody->empire->alliance_id == $defend_aid)); $combat = citadel_interaction($dbody, $combat, $self->combat, 0); @@ -425,6 +445,7 @@ sub notify_battle_results { my ($self, $defense_stat, $attack_stat) = @_; my $report; + my %def_eid; for my $dbid (keys %{$defense_stat}) { for my $dtype (keys %{$defense_stat->{$dbid}}) { push @{$report}, [ @@ -436,6 +457,7 @@ sub notify_battle_results { $defense_stat->{$dbid}->{$dtype}->{number}, $defense_stat->{$dbid}->{$dtype}->{debug}, ]; + $def_eid{$defense_stat->{$dbid}->{$dtype}->{emp_id}} = 1; } } unshift @{$report}, (['Defenders','','','','',''],['ID','Planet','EID','Empire','Type','Number','Debug']); @@ -453,16 +475,21 @@ sub notify_battle_results { ]; } } - - unless ($self->foreign_body->empire_id && $self->foreign_body->empire->skip_attack_messages) { - $self->foreign_body->empire->send_predefined_message( - tags => ['Attack'], - filename => 'attack_summary.txt', - params => [$self->foreign_body->id, - $self->foreign_body->name, - ], - attachments => { table => $report }, - ); + $self->log_attack($defense_stat, $attack_stat); + + for my $deid (keys %def_eid) { + my $empire = Lacuna->db->resultset('Empire')->find($deid); + next unless $empire; + unless ($empire->skip_attack_messages) { + $empire->send_predefined_message( + tags => ['Attack'], + filename => 'attack_summary.txt', + params => [$self->foreign_body->id, + $self->foreign_body->name, + ], + attachments => { table => $report }, + ); + } } unless ($self->body->empire_id && $self->body->empire->skip_attack_messages) { $self->body->empire->send_predefined_message( @@ -503,7 +530,7 @@ sub saw_stats { for my $saw (@planet_saws) { $cnt++; $planet_combat += int($saw->effective_level * $saw->effective_efficiency * - (1.75 ** ($saw->effective_level/2)) + 0.5); + (1.55 ** ($saw->effective_level/2)) + 0.5); push @defending_saws, $saw; last if $cnt >= 10; } diff --git a/var/upgrades/3.0909.sql b/var/upgrades/3.0909.sql index c6b1a4ea..c40ced24 100644 --- a/var/upgrades/3.0909.sql +++ b/var/upgrades/3.0909.sql @@ -1,2 +1,4 @@ alter table ships add column number_of_docks int default 1; alter table ships modify hold_size bigint; +alter table battle_log add column attacking_number int default 1; +alter table battle_log add column defending_number int default 1;