Skip to content

Commit

Permalink
First attempt at fissure API
Browse files Browse the repository at this point in the history
  • Loading branch information
icydee committed Apr 12, 2013
1 parent 3ce6eb0 commit bdc1f33
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 8 deletions.
59 changes: 57 additions & 2 deletions docs/Map.pod
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Returns a chunk of the map as an array of hashes.
"orbit" : 1,
"x" : -40,
"y" : 29,
"type" : "habitable planet",
"image" : "p13",
"size" : 58,
"empire" {
Expand All @@ -68,13 +69,14 @@ Returns a chunk of the map as an array of hashes.
}
},
{
"name" : "Venus",
"name" : "Vesta",
"id" : 346,
"orbit" : 2,
"x" : -39,
"y" : 28,
"type" : "asteroid",
"image" : "p33",
"size" : 34
"size" : 3
},
...
]
Expand Down Expand Up @@ -344,6 +346,59 @@ A session id.
A partial name of a star. Case insensitive. Must be at least 3 characters.


=head2 probe_summary_fissures

Obtain a summary of all bodies with fissures, known to yours, or your alliances probes within a specified zone.

This takes named arguments only

{
"session_id" : "1234-0A34-333F-21",
"zone" : "0|0",
}

=head3 session_id

A session id.

=head3 zone

A string defining the zone, e.g "-1|0", "5|-5" or "0|0"

=head3 RESPONSE

{
"fissures" : [
{
{
"name" : "Mercury",
"id" : 345,
"orbit" : 1,
"x" : -40,
"y" : 29,
"type" : "habitable planet",
"image" : "p13",
"size" : 58,
"empire" {
"id" : 945,
"name" : "Earthlings",
"alignment" : "ally",
"is_isolationist" : 1
}
},
},
{
...
}
]
}

Brief information about each body in the zone which contains a fissure (or two) is returned in a list.

If there are no fissures on any of the bodies which you have probed then an empty list is returned;

If the body is occupied then enough information to identify the empire is returned.


=head1 FAQ

Expand Down
42 changes: 36 additions & 6 deletions lib/Lacuna/RPC/Map.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sub check_star_for_incoming_probe {
my $empire = $self->get_empire_by_session($session_id);
my $date = 0;
my @bodies = $empire->planets->get_column('id')->all;
my $incoming = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({foreign_star_id=>$star_id, task=>'Travelling', type=>'probe', body_id => {in => \@bodies }}, {rows=>1})->single;
my $incoming = Lacuna->db->resultset('Ships')->search({foreign_star_id=>$star_id, task=>'Travelling', type=>'probe', body_id => {in => \@bodies }}, {rows=>1})->single;
if (defined $incoming) {
$date = $incoming->date_available_formatted;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ sub get_stars {
confess [1003, 'Requested area too large.'];
}
my $empire = $self->get_empire_by_session($session_id);
my $stars = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->search({y=> {between => [$starty, $endy]}, x=>{between => [$startx, $endx]}});
my $stars = Lacuna->db->resultset('Map::Star')->search({y=> {between => [$starty, $endy]}, x=>{between => [$startx, $endx]}});
my @out;
while (my $star = $stars->next) {
push @out, $star->get_status($empire);
Expand All @@ -87,7 +87,7 @@ sub get_stars {
sub get_star {
my ($self, $session_id, $star_id) = @_;
my $empire = $self->get_empire_by_session($session_id);
my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->find($star_id);
my $star = Lacuna->db->resultset('Map::Star')->find($star_id);
unless (defined $star) {
confess [1002, "Couldn't find a star."];
}
Expand All @@ -97,7 +97,7 @@ sub get_star {
sub get_star_by_name {
my ($self, $session_id, $star_name) = @_;
my $empire = $self->get_empire_by_session($session_id);
my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->search({name => $star_name}, {rows=>1})->single;
my $star = Lacuna->db->resultset('Map::Star')->search({name => $star_name}, {rows=>1})->single;
unless (defined $star) {
confess [1002, "Couldn't find a star."];
}
Expand All @@ -107,7 +107,7 @@ sub get_star_by_name {
sub get_star_by_xy {
my ($self, $session_id, $x, $y) = @_;
my $empire = $self->get_empire_by_session($session_id);
my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->search({x=>$x, y=>$y}, {rows=>1})->single;
my $star = Lacuna->db->resultset('Map::Star')->search({x=>$x, y=>$y}, {rows=>1})->single;
unless (defined $star) {
confess [1002, "Couldn't find a star."];
}
Expand All @@ -121,13 +121,42 @@ sub search_stars {
}
my $empire = $self->get_empire_by_session($session_id);
my @out;
my $stars = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->search({name => { like => $name.'%' }},{rows => 25});
my $stars = Lacuna->db->resultset('Map::Star')->search({name => { like => $name.'%' }},{rows => 25});
while (my $star = $stars->next) {
push @out, $star->get_status; # planet data left out on purpose
}
return { stars => \@out , status => $self->format_status($empire) };
}

sub probe_summary_fissures {
my ($self, $args) = @_;

my $empire = $self->get_empire_by_session($args->{session_id});
my $zone = $args->{zone};
unless (defined $zone) {
confess [1009, "You must specify a zone."];
}
my $fissure_rs = Lacuna->db->resultset('Building')->search({
'me.class' => 'Lacuna::DB::Result::Building::Permanent::Fissure',
'star.zone' => $zone,
'probes.alliance_id' => $empire->alliance_id,
},{
prefetch => [
{ body => { star => 'probes'} },
]
}
);
my @fissures;
while (my $fissure = $fissure_rs->next) {
my $row = {
id => $fissure->id,
};
push @fissures, $row;
}
return { fissures => \@fissures};
}


__PACKAGE__->register_rpc_method_names(qw(
get_star_map
get_body_status
Expand All @@ -137,6 +166,7 @@ __PACKAGE__->register_rpc_method_names(qw(
get_star_by_xy
search_stars
check_star_for_incoming_probe
probe_summary_fissures
));

no Moose;
Expand Down
22 changes: 22 additions & 0 deletions t/530_probe_summary.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use lib '../lib';
use Test::More tests => 14;
use Test::Deep;
use Data::Dumper;
use 5.010;
use DateTime;

use TestHelper;

my $tester = TestHelper->new({empire_name => 'icydee'});

$tester->use_existing_test_empire;
diag("tester = [$tester]");

my $session_id = $tester->session->id;
my $empire = $tester->empire;
my $home = $empire->home_planet;


$result = $tester->post('map', 'probe_summary_fissures', [{session_id => $session_id, zone => '0|0'}]);


0 comments on commit bdc1f33

Please sign in to comment.