From 8f5c96c70e89d7077c8ac370da9c58069dc8bcd9 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 18 Oct 2010 11:00:32 -0500 Subject: [PATCH] got started with missions --- .../DB/Result/Building/MissionCommand.pm | 23 + lib/Lacuna/DB/Result/Mission.pm | 97 ++++ lib/Lacuna/RPC/Building/MissionCommand.pm | 11 + var/upgrades/add_missions.sql | 9 + var/www/public/api/api.css | 429 ------------------ var/www/public/api/index.html | 8 - var/www/public/resources.json | 2 +- 7 files changed, 141 insertions(+), 438 deletions(-) create mode 100644 lib/Lacuna/DB/Result/Mission.pm create mode 100644 var/upgrades/add_missions.sql delete mode 100644 var/www/public/api/api.css delete mode 100644 var/www/public/api/index.html diff --git a/lib/Lacuna/DB/Result/Building/MissionCommand.pm b/lib/Lacuna/DB/Result/Building/MissionCommand.pm index c04c829b..09fb714b 100644 --- a/lib/Lacuna/DB/Result/Building/MissionCommand.pm +++ b/lib/Lacuna/DB/Result/Building/MissionCommand.pm @@ -41,6 +41,29 @@ use constant water_consumption => 10; use constant waste_production => 2; +sub get_missions { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my @missions; + my $missions = $building->missions; + while (my $mission = $missions->next) { + next if $mission->params->max_university_level < $empire->university_level; + push @missions, { + id => $mission->id, + name => $mission->name, + description => $mission->description, + objectives => $mission->format_objectives, + rewards => $mission->format_rewards, + }; + } + return { + status => $self->format_status($empire, $building->body), + missions => \@missions, + }; +} + +__PACKAGE__->register_rpc_method_names(qw(get_missions)); no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Mission.pm b/lib/Lacuna/DB/Result/Mission.pm new file mode 100644 index 00000000..e41e965d --- /dev/null +++ b/lib/Lacuna/DB/Result/Mission.pm @@ -0,0 +1,97 @@ +package Lacuna::DB::Result::Mission; + +use Moose; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result'; +use Lacuna::Util qw(format_date); +use UUID::Tiny ':std'; +use Config::JSON; +use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); + +__PACKAGE__->table('mission'); +__PACKAGE__->add_columns( + mission_file_name => { data_type => 'varchar', size => 100, is_nullable => 0 }, + zone => { data_type => 'varchar', size => 16, is_nullable => 0 }, + date_posted => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, +); + +has params => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + return Config::JSON->new('/data/Lacuna-Server/var/missions/'. $self->mission_file_name); + }, +); + +sub format_objectives { + my $self = shift; + my $objectives = $self->params->get('mission_objective'); + my @objectives; + + # essentia + push @objectives, sprintf('Provide %d essentia.', $objectives->{essentia}) if ($objectives->{essentia}); + + # resources + my @resources; + foreach my $resource (keys %{ $objectives->{resources}}) { + push @resources, sprintf('%d %s', $objectives->{resources}{$resource}); + } + push @objectives, $self->format_list(@resources); + + # ships + my @ships; + my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships'); + foreach my $stats (@{ $objectives->{ships}}) { + my $ship = $ships->new({type=>$stats->{type}}); + push @ships, sprintf('%s (speed: %d, stealth: %d, hold size: %d)', $ship->name, $stats->{speed}, $stats->{stealth}, $stats->{hold_size}); + } + push @objectives, $self->format_list(@ships); + + # plans + my @plans; + foreach my $stats (@{ $objectives->{plans}}) { + push @plans, sprintf('%s (%s)', $stats); + } + push @objectives, $self->format_list(@plans); + + + return \@objectives; +} + +sub format_list { + my ($self, @list) = @_; + my @out; + if (scalar(@list) == 1) { + push @out, sprintf('Provide %s.', $list[0]); + } + elsif (scalar(@list) > 1) { + my $last = pop @list; + push @out, sprintf('Provide %s and %s', join(',', @list), $last); + } + return @out; +} + +sub sqlt_deploy_hook { + my ($self, $sqlt_table) = @_; + $sqlt_table->add_index(name => 'idx_zone_date_posted', fields => ['zone','date_posted']); +} + +sub date_posted_formatted { + my $self = shift; + return format_date($self->date_posted); +} + +sub feed_url { + my ($class, $zone) = @_; + my $config = Lacuna->config; + Lacuna->config->get('feeds/url').$class->feed_filename($zone); +} + +sub feed_filename { + my ($class, $zone) = @_; + return 'missioncommand/'.create_uuid_as_string(UUID_MD5, $zone.Lacuna->config->get('feeds/bucket')).'.rss'; +} + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/MissionCommand.pm b/lib/Lacuna/RPC/Building/MissionCommand.pm index 201e2c49..c2e1c2b2 100644 --- a/lib/Lacuna/RPC/Building/MissionCommand.pm +++ b/lib/Lacuna/RPC/Building/MissionCommand.pm @@ -12,6 +12,17 @@ sub model_class { return 'Lacuna::DB::Result::Building::MissionCommand'; } +sub missions { + my ($self) = @_; + return Lacuna->db->resultset('Lacuna::DB::Result::Mission')->search({ + zone => $self->body->zone, + },{ + order_by => 'date_posted', + }); +} + + + no Moose; __PACKAGE__->meta->make_immutable; diff --git a/var/upgrades/add_missions.sql b/var/upgrades/add_missions.sql new file mode 100644 index 00000000..260b92e3 --- /dev/null +++ b/var/upgrades/add_missions.sql @@ -0,0 +1,9 @@ +CREATE TABLE `mission` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `mission_file_name` varchar(100) NOT NULL, + `zone` varchar(16) NOT NULL, + `date_posted` datetime NOT NULL, + `max_university_level` tinyint NOT NULL, + PRIMARY KEY (`id`), + KEY `idx_zone_date_posted` (`zone`,`date_posted`) +); \ No newline at end of file diff --git a/var/www/public/api/api.css b/var/www/public/api/api.css deleted file mode 100644 index 3e83ae3f..00000000 --- a/var/www/public/api/api.css +++ /dev/null @@ -1,429 +0,0 @@ -BODY, .logo { background: white; } - -BODY { - color: black; - font-family: arial,sans-serif; - margin: 0; - padding: 1ex; -} - -TABLE { - border-collapse: collapse; - border-spacing: 0; - border-width: 0; - color: inherit; -} - -IMG { border: 0; } -FORM { margin: 0; } -input { margin: 2px; } - -.logo { - float: left; - width: 264px; - height: 77px; -} - -.front .logo { - float: none; - display:block; -} - -.front .searchbox { - margin: 2ex auto; - text-align: center; -} - -.front .menubar { - text-align: center; -} - -.menubar { - background: #006699; - margin: 1ex 0; - padding: 1px; -} - -.menubar A { - padding: 0.8ex; - font: bold 10pt Arial,Helvetica,sans-serif; -} - -.menubar A:link, .menubar A:visited { - color: white; - text-decoration: none; -} - -.menubar A:hover { - color: #ff6600; - text-decoration: underline; -} - -A:link, A:visited { - background: transparent; - color: #006699; -} - -A[href="#POD_ERRORS"] { - background: transparent; - color: #FF0000; -} - -TD { - margin: 0; - padding: 0; -} - -DIV { - border-width: 0; -} - -DT { - margin-top: 1em; -} - -.credits TD { - padding: 0.5ex 2ex; -} - -.huge { - font-size: 32pt; -} - -.s { - background: #dddddd; - color: inherit; -} - -.s TD, .r TD { - padding: 0.2ex 1ex; - vertical-align: baseline; -} - -TH { - background: #bbbbbb; - color: inherit; - padding: 0.4ex 1ex; - text-align: left; -} - -TH A:link, TH A:visited { - background: transparent; - color: black; -} - -.box { - border: 1px solid #006699; - margin: 1ex 0; - padding: 0; -} - -.distfiles TD { - padding: 0 2ex 0 0; - vertical-align: baseline; -} - -.manifest TD { - padding: 0 1ex; - vertical-align: top; -} - -.l1 { - font-weight: bold; -} - -.l2 { - font-weight: normal; -} - -.t1, .t2, .t3, .t4, .t5 { - background: #006699; - color: white; -} -.t4 { - padding: 0.2ex 0.4ex; -} -.t1, .t2, .t3 { - padding: 0.5ex 1ex; -} - -/* IE does not support .box>.t1 Grrr */ -.box .t1, .box .t2, .box .t3, .box .t5 { - margin: 0; -} - -.t1 { - font-size: 1.4em; - font-weight: bold; - text-align: center; -} - -.t2 { - font-size: 1.0em; - font-weight: bold; - text-align: left; -} - -.t3 { - font-size: 1.0em; - font-weight: normal; - text-align: left; -} - -.t5 { - font-size: 0.8em; - font-weight: normal; - text-align: center; -} - -/* width: 100%; border: 0.1px solid #FFFFFF; */ /* NN4 hack */ - -.datecell { - text-align: center; - width: 17em; -} - -.cell { - padding: 0.2ex 1ex; - text-align: left; -} - -.label { - background: #aaaaaa; - color: black; - font-weight: bold; - padding: 0.2ex 1ex; - text-align: right; - white-space: nowrap; - vertical-align: baseline; -} - -.categories { - border-bottom: 3px double #006699; - margin-bottom: 1ex; - padding-bottom: 3ex; - padding-top: 2ex; -} - -.categories TABLE { - margin: auto; -} - -.categories TD { - padding: 0.5ex 1ex; - vertical-align: baseline; -} - -.path A { - background: transparent; - color: #006699; - font-weight: bold; -} - -.pages { - background: #dddddd; - color: #006699; - padding: 0.2ex 0.4ex; -} - -.path { - background: #dddddd; - border-bottom: 1px solid #006699; - color: #006699; - /* font-size: 1.4em;*/ - margin: 1ex 0; - padding: 0.5ex 1ex; -} - -.menubar TD { - background: #006699; - color: white; -} - -.menubar { - background: #006699; - color: white; - margin: 1ex 0; - padding: 1px; -} - -.menubar .links { - background: transparent; - color: white; - padding: 0.2ex; - text-align: left; -} - -.menubar .searchbar { - background: black; - color: black; - margin: 0px; - padding: 2px; - text-align: right; -} - -A.m:link, A.m:visited { - background: #006699; - color: white; - font: bold 10pt Arial,Helvetica,sans-serif; - text-decoration: none; -} - -A.o:link, A.o:visited { - background: #006699; - color: #ccffcc; - font: bold 10pt Arial,Helvetica,sans-serif; - text-decoration: none; -} - -A.o:hover { - background: transparent; - color: #ff6600; - text-decoration: underline; -} - -A.m:hover { - background: transparent; - color: #ff6600; - text-decoration: underline; -} - -table.dlsip { - background: #dddddd; - border: 0.4ex solid #dddddd; -} - -.pod, .manifest { margin-right: 20ex; } - -.pod PRE { - background: #eeeeee; - border: 1px solid #888888; - color: black; - padding: 1em; - white-space: pre; -} - -.pod H1 { - background: transparent; - color: #006699; - font-size: xx-large; -} - -.pod H1 A { text-decoration: none; } -.pod H2 A { text-decoration: none; } -.pod H3 A { text-decoration: none; } -.pod H4 A { text-decoration: none; } - -.pod H2 { - background: transparent; - color: #006699; - font-size: x-large; -} - -.pod H3 { - background: transparent; - color: #006699; - font-size: large; - font-style: italic; -} - -.pod H4 { - background: transparent; - color: #006699; - font-size: medium; - font-weight: normal; -} - -.pod IMG { - vertical-align: top; -} - -.pod .toc A { - text-decoration: none; -} - -.pod .toc LI { - line-height: 1.2em; - list-style-type: none; -} - -.faq DT { - font-size: 1.4em; - font-weight: bold; -} - -.chmenu { - background: black; - color: red; - font: bold 1.1em Arial,Helvetica,sans-serif; - margin: 1ex auto; - padding: 0.5ex; -} - -.chmenu TD { - padding: 0.2ex 1ex; -} - -.chmenu A:link, .chmenu A:visited { - background: transparent; - color: white; - text-decoration: none; -} - -.chmenu A:hover { - background: transparent; - color: #ff6600; - text-decoration: underline; -} - -.column { - padding: 0.5ex 1ex; - vertical-align: top; -} - -.datebar { - margin: auto; - width: 14em; -} - -.date { - background: transparent; - color: #008000; -} - -.footer { - margin-top: 1ex; - text-align: right; - color: #006699; - font-size: x-small; - border-top: 1px solid #006699; - line-height: 120%; -} - -.front .footer { - border-top: none; -} - -#permalink { - float: right -} - -#permalink A { - font-size: small; -} - -.sr { - font-size: inherit; - margin: 0; -} - -.cpanstats { - float: left; - text-align: left; - color: #bbb; - white-space: pre; -} - -form.tool { - margin: 1ex; -} diff --git a/var/www/public/api/index.html b/var/www/public/api/index.html deleted file mode 100644 index 8d7593d5..00000000 --- a/var/www/public/api/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - -If this page does not automatically redirect, click here. - - diff --git a/var/www/public/resources.json b/var/www/public/resources.json index 9b7350b1..974c0449 100644 --- a/var/www/public/resources.json +++ b/var/www/public/resources.json @@ -17,7 +17,7 @@ "/volcano" : { "description" : "A natural source of ore.", "wiki" : "http://community.lacunaexpanse.com/wiki/volcano" }, "/luxuryhousing" : { "description" : "Produces more happiness than the Entertainment District, but costs more too.", "wiki" : "http://community.lacunaexpanse.com/wiki/luxury-housing" }, "/pilottraining" : { "description" : "Increases speed and stealth of new ships, and enables building Fighters.", "wiki" : "http://community.lacunaexpanse.com/wiki/pilot-training-facility" }, - "/missioncommand" : { "description" : "Lists available missions in your zone.", "wiki" : "http://community.lacunaexpanse.com/wiki/mission-command" }, + "/missioncommand" : { "description" : "Lists available missions in your zone. You can view one mission per level of the Mission Command.", "wiki" : "http://community.lacunaexpanse.com/wiki/mission-command" }, "/cloakinglab" : { "description" : "Increases the stealth of new ships.", "wiki" : "http://community.lacunaexpanse.com/wiki/cloaking-lab" }, "/munitionslab" : { "description" : "Enables you to build the Detonator, Snark, and Seeker robotic war ships.", "wiki" : "http://community.lacunaexpanse.com/wiki/munitions-lab" }, "/crater" : { "description" : "Decoration for your planet.", "wiki" : "http://community.lacunaexpanse.com/wiki/crater" }, -- 2.51.2