diff --git a/docs/HallsOfVrbansk.pod b/docs/HallsOfVrbansk.pod index c7b7f5b4..19805821 100644 --- a/docs/HallsOfVrbansk.pod +++ b/docs/HallsOfVrbansk.pod @@ -4,4 +4,55 @@ Halls Of Vrbansk is accessible via the URL C. The list of methods below represents changes and additions to the methods that all L share. + +=head2 get_upgradable_buildings ( session_id, building_id ) + +Returns a list of buildings that can be upgraded by the Halls of Vrbansk. + + { + "status" : { ... }, + "buildings" : [ + { + "name" : "Oracle of Anid", + "id" : "id-goes-here", + "x" : -3, + "y" : 2, + "image" : "oracleanid1", + "level" : 1 + }, + ... + ] + } + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the Halls of Vrbansk. + + +=head2 sacrifice_to_upgrade ( session_id, building_id, upgrade_building_id ) + +Sacrifices a number of the Halls of Vrbansk to upgrade a building. + + { + "status" : { ... } + } + +B In all likelyhood the Halls of Vrbansk that the player is looking at when they call this method will be destroyed. The building will return a status, but then you should close whatever screen you have open for it and refresh the planet surface. The C flag will be set in the body status on the return. You should wait for the return to close the building though, in case of an exception. + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the Halls of Vrbansk. + +=head3 upgrade_building_id + +The unique id of the building you wish to upgrade. + =cut \ No newline at end of file diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 2ec5b8fc..e78bdb58 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 2.3600; +our $VERSION = 2.3700; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm index b6692edd..f190cd60 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/HallsOfVrbansk.pm @@ -31,6 +31,21 @@ after finish_upgrade => sub { $self->body->add_news(30, sprintf('The ancient wisdom of the Great Race is still alive on %s.', $self->body->name)); }; +sub get_halls { + my $self = shift; + return $self->body->get_buildings_of_class('Lacuna::DB::Result::DB::Building::Permanent::HallsOfVrbansk'); +} + +sub get_upgradable_buildings { + my ($self) = @_; + my @halls = $self->get_halls->get_column('id')->all; + return $self->body->buildings-search({ + level => { '<' => scalar @halls}, + class => { like => 'Lacuna::DB::Result::Building::Permanent::%' }, + id => { 'not in' => \@halls }, + }); +} + use constant name => 'Halls of Vrbansk'; use constant time_to_build => 0; diff --git a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm index c064a3f1..50ae5fc0 100644 --- a/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm +++ b/lib/Lacuna/RPC/Building/HallsOfVrbansk.pm @@ -13,6 +13,50 @@ sub model_class { return 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk'; } +sub get_upgradable_buildings { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my @buildings; + my $upgradable = $building->get_upgradable_buildings; + while (my $building = $upgradable->next) { + push @buildings, { + id => $building->id, + name => $building->name, + x => $building->x, + y => $building->y, + level => $building->level, + image => $building->image_level, + }; + } + return { + buildings => \@buildings, + status => $self->format_status($empire, $building->body), + }; +} + +sub sacrifice_to_upgrade { + my ($self, $session_id, $building_id, $upgrade_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my $upgrade = $self->get_building($empire, $upgrade_id); + my @upgradable = $building->get_upgradable_buildings->get_column('id')->all; + unless ($upgrade->id ~~ \@upgradable) { + confess [1009, 'The Halls of Vrbansk do not have the knowledge necessary to upgrade the '.$upgrade->name]; + } + $upgrade->start_upgrade; + my $halls = $building->get_halls; + foreach (1..$upgrade->level + 1) { + $halls->next->delete; + } + my $body = $building->body; + $body->needs_surface_refresh(1); + $body->update; + return { status => $self->format_status($empire, $body) }; +} + +__PACKAGE__->register_rpc_method_names(qw(get_upgradable_buildings sacrifice_to_upgrade)); + no Moose; __PACKAGE__->meta->make_immutable; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index e2065d5f..017bc228 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,7 @@ +2.3700 + - Fixed pagination in mission curator panel. + - Added exposed API for Halls of Vrbansk. + 2.3600 - Added alliance stash methods to the embassy. - Added mission curator panel.