From 39d4e820ea24bb1407c18a676a292b2570142b85 Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Thu, 8 Aug 2013 23:05:00 -0600 Subject: [PATCH] repair_list api call added to Body --- docs/Body.pod | 18 +++++++++++++ lib/Lacuna/RPC/Body.pm | 53 +++++++++++++++++++++++++++++++++++++- var/www/public/changes.txt | 2 ++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/docs/Body.pod b/docs/Body.pod index 099e37d9..22d37bd3 100644 --- a/docs/Body.pod +++ b/docs/Body.pod @@ -160,6 +160,24 @@ A session id. The id of the body you wish to retrieve the buildings on. +=head2 repair_list ( session_id, body_id, building_ids) + +Repairs buildings in order of ids gived in array. + +Returns similar output to get_buildings, but only ones identified in building_ids + +=head3 session_id + +A session id. + +=head3 body_id + +The id of the body you wish to retrieve the buildings on. + +=head3 building_ids + +An array reference to a list of building ids to be repaired. + =head2 rearrange_buildings ( session_id, body_id, arrangement) Rearranges all buildings to the coordinates supplied via the arrangment array of hashes. diff --git a/lib/Lacuna/RPC/Body.pm b/lib/Lacuna/RPC/Body.pm index eb016bba..0322badd 100644 --- a/lib/Lacuna/RPC/Body.pm +++ b/lib/Lacuna/RPC/Body.pm @@ -122,11 +122,62 @@ sub get_buildings { end => $building->work_ends_formatted, }; } + if ($building->efficiency < 100) { + $out{$building->id}{repair_costs} = $building->get_repair_costs; + } } return {buildings=>\%out, body=>{surface_image => $body->surface}, status=>$self->format_status($empire, $body)}; } +sub repair_list { + my ($self, $session_id, $body_id, $building_ids) = @_; + + my $empire = $self->get_empire_by_session($session_id); + my $body = $self->get_body($empire, $body_id); + + if ($body->needs_surface_refresh) { + $body->needs_surface_refresh(0); + $body->update; + } + my @buildings = @{$body->building_cache}; + + my %out; + for my $bld_id (@{$building_ids}) { + my ( $building ) = grep { $_->id == $bld_id } @buildings; + next unless $building; + next unless $building->efficiency < 100; + my $return; + my $ok = eval { $return = $building->repair }; + $out{$building->id} = { + url => $building->controller_class->app_url, + image => $building->image_level, + name => $building->name, + x => $building->x, + y => $building->y, + level => $building->level, + efficiency => $building->efficiency, + }; + if ($building->is_upgrading) { + $out{$building->id}{pending_build} = $building->upgrade_status; + } + if ($building->is_working) { + $out{$building->id}{work} = { + seconds_remaining => $building->work_seconds_remaining, + start => $building->work_started_formatted, + end => $building->work_ends_formatted, + }; + } + if ($building->efficiency < 100) { + $out{$building->id}{repair_costs} = $building->get_repair_costs; + } + } + return { + buildings=>\%out, + status=>$self->format_status($empire, $body) + }; +} + sub rearrange_buildings { my ($self, $session_id, $body_id, $arrangement) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -457,7 +508,7 @@ sub get_buildable { } -__PACKAGE__->register_rpc_method_names(qw(abandon rename get_buildings get_buildable get_status get_body_status rearrange_buildings)); +__PACKAGE__->register_rpc_method_names(qw(abandon rename get_buildings get_buildable get_status get_body_status repair_list rearrange_buildings)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index e66dfaec..87b0e108 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -7,6 +7,8 @@ - Mod: If alliance leader quits game, alliance leadership is transferred. - Mod: If a member of an alliance leaves, space stations of member turned over to leader of alliance. - Fix: BHG cooldown time of 5 minutes during warmup. + - API: get_buildings now returns repair costs if building is damaged. + - API: Api call repair_list from Body will attempt to repair buildings supplied to function in order of list. 3.0892: - Fix: Fix schedule to remove past jobs when rescheduling. -- 2.51.2