From d550e7d6f8cfc518b45694246203402c4df58206 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 12 Sep 2010 16:31:45 -0500 Subject: [PATCH] added prisoner and ship pushing --- docs/Trade.pod | 76 ++++++++++++++++++++++++++++++++--- docs/Transporter.pod | 75 +++++++++++++++++++++++++++++++--- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Spies.pm | 2 +- lib/Lacuna/Role/Trader.pm | 30 ++++++++++++-- 5 files changed, 169 insertions(+), 16 deletions(-) diff --git a/docs/Trade.pod b/docs/Trade.pod index 716e05d4..ddf92db1 100644 --- a/docs/Trade.pod +++ b/docs/Trade.pod @@ -371,7 +371,19 @@ B The list of your planets comes back with every empire status message. =head3 items -An array reference of hash references of items you wish to ship to the target planet. There are three types items that can be shipped via this mechanism. They are resources, glyphs, and plans. +An array reference of hash references of items you wish to ship to the target planet. There are five types of items that can be shipped via this mechanism. They are resources, glyphs, plans, prisoners, and ships. + + [ + { + "type" : "bauxite", + "quantity" : 10000 + }, + { + "type" : "prisoner", + "prisoner_id" : "id-goes-here" + } + ] + =over @@ -388,11 +400,11 @@ The hash reference for resources looks like: =item type -The type of resource you want to ship. Available types are: water, energy, waste, essentia, bean, lapis, potato, apple, root, corn, cider, wheat, bread, soup, chip, pie, pancake, milk, meal, algae, syrup, fungus, burger, shake, beetle, rutile, chromite, chalcopyrite, galena, gold, uraninite, bauxite, goethite, halite, gypsum, trona, kerogen, methane, anthracite, sulfur, zircon, monazite, fluorite, beryl, or magnetite. +The type of resource you want to push. Available types are: water, energy, waste, essentia, bean, lapis, potato, apple, root, corn, cider, wheat, bread, soup, chip, pie, pancake, milk, meal, algae, syrup, fungus, burger, shake, beetle, rutile, chromite, chalcopyrite, galena, gold, uraninite, bauxite, goethite, halite, gypsum, trona, kerogen, methane, anthracite, sulfur, zircon, monazite, fluorite, beryl, or magnetite. =item quantity -The amount of the resource that you want to ship. +The amount of the resource that you want to push. =back @@ -413,13 +425,20 @@ Must be exactly C. =item glyph_id -The unique id of the glyph you want to ship. See the C method for a list of your glyphs. +The unique id of the glyph you want to push. See the C method for a list of your glyphs. =back =item plans +The hash reference for plans looks like: + + { + "type" : "plan", + "plan_id" : "id-goes-here" + } + =over =item type @@ -428,13 +447,60 @@ Must be exactly C. =item plan_id -The unique id of the plan that you want to ship. See the C method for a list of your plans. +The unique id of the plan that you want to push. See the C method for a list of your plans. =back + +=item prisoners + +The hash reference for prisoners looks like: + + { + "type" : "prisoner", + "prisoner_id" : "id-goes-here" + } + +=over + +=item type + +Must be exactly C. + +=item prisoner_id + +The unique id of the spy that you want to push. See the C method for a list of your prisoners. + =back +=item ships + +The hash reference for ships looks like: + + { + "type" : "ship", + "ship_id" : "id-goes-here" + } + +=over + +=item type + +Must be exactly C. + +=item ship_id + +The unique id of the ship that you want to push. See the C method for a list of your prisoners. + +=back + + + +=back + + + diff --git a/docs/Transporter.pod b/docs/Transporter.pod index 22801c11..c46bbb52 100644 --- a/docs/Transporter.pod +++ b/docs/Transporter.pod @@ -379,7 +379,19 @@ B The list of your planets comes back with every empire status message. =head3 items -An array reference of hash references of items you wish to ship to the target planet. There are three types items that can be shipped via this mechanism. They are resources, glyphs, and plans. +An array reference of hash references of items you wish to ship to the target planet. There are five types of items that can be shipped via this mechanism. They are resources, glyphs, plans, prisoners, and ships. + + [ + { + "type" : "bauxite", + "quantity" : 10000 + }, + { + "type" : "prisoner", + "prisoner_id" : "id-goes-here" + } + ] + =over @@ -396,11 +408,11 @@ The hash reference for resources looks like: =item type -The type of resource you want to ship. Available types are: water, energy, waste, essentia, bean, lapis, potato, apple, root, corn, cider, wheat, bread, soup, chip, pie, pancake, milk, meal, algae, syrup, fungus, burger, shake, beetle, rutile, chromite, chalcopyrite, galena, gold, uraninite, bauxite, goethite, halite, gypsum, trona, kerogen, methane, anthracite, sulfur, zircon, monazite, fluorite, beryl, or magnetite. +The type of resource you want to push. Available types are: water, energy, waste, essentia, bean, lapis, potato, apple, root, corn, cider, wheat, bread, soup, chip, pie, pancake, milk, meal, algae, syrup, fungus, burger, shake, beetle, rutile, chromite, chalcopyrite, galena, gold, uraninite, bauxite, goethite, halite, gypsum, trona, kerogen, methane, anthracite, sulfur, zircon, monazite, fluorite, beryl, or magnetite. =item quantity -The amount of the resource that you want to ship. +The amount of the resource that you want to push. =back @@ -421,13 +433,20 @@ Must be exactly C. =item glyph_id -The unique id of the glyph you want to ship. See the C method for a list of your glyphs. +The unique id of the glyph you want to push. See the C method for a list of your glyphs. =back =item plans +The hash reference for plans looks like: + + { + "type" : "plan", + "plan_id" : "id-goes-here" + } + =over =item type @@ -436,10 +455,56 @@ Must be exactly C. =item plan_id -The unique id of the plan that you want to ship. See the C method for a list of your plans. +The unique id of the plan that you want to push. See the C method for a list of your plans. + +=back + + +=item prisoners + +The hash reference for prisoners looks like: + + { + "type" : "prisoner", + "prisoner_id" : "id-goes-here" + } + +=over + +=item type + +Must be exactly C. + +=item prisoner_id + +The unique id of the spy that you want to push. See the C method for a list of your prisoners. + +=back + + +=item ships + +The hash reference for ships looks like: + + { + "type" : "ship", + "ship_id" : "id-goes-here" + } + +=over + +=item type + +Must be exactly C. + +=item ship_id + +The unique id of the ship that you want to push. See the C method for a list of your prisoners. =back + + =back diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 4d30a549..7eac304e 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 2.1900; +our $VERSION = 2.1901; 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')); diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 1935a2c5..3e9930b3 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -109,7 +109,7 @@ sub seconds_remaining_on_assignment { sub is_available { my ($self) = @_; my $task = $self->task; - if ($task ~~ ['Idle','Counter Espionage']) { + if ($task ~~ ['Idle','Counter Espionage','Prisoner Transport']) { return 1; } elsif (DateTime->now > $self->available_on) { diff --git a/lib/Lacuna/Role/Trader.pm b/lib/Lacuna/Role/Trader.pm index ba85159e..ccacde95 100644 --- a/lib/Lacuna/Role/Trader.pm +++ b/lib/Lacuna/Role/Trader.pm @@ -225,15 +225,29 @@ sub structure_push { $space_used += $item->{quantity}; } when ('glyph') { + confess [1002, 'You must specify a glyph_id if you are pushing a glyph.'] unless $item->{glyph_id}; my $glyph = Lacuna->db->resultset('Lacuna::DB::Result::Glyphs')->find($item->{glyph_id}); confess $have_exception unless (defined $glyph && $self->body_id eq $glyph->body_id); $space_used += 100; } when ('plan') { + confess [1002, 'You must specify a plan_id if you are pushing a plan.'] unless $item->{plan_id}; my $plan = Lacuna->db->resultset('Lacuna::DB::Result::Plans')->find($item->{plan_id}); confess $have_exception unless (defined $plan && $self->body_id eq $plan->body_id); $space_used += 10000; } + when ('prisoner') { + confess [1002, 'You must specify a prisoner_id if you are pushing a prisoner.'] unless $item->{prisoner_id}; + my $prisoner = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->find($item->{prisoner_id}); + confess $have_exception unless (defined $prisoner && $self->body_id eq $prisoner->on_body_id && $prisoner->task eq 'Captured'); + $space_used += 350; + } + when ('ship') { + confess [1002, 'You must specify a ship_id if you are pushing a ship.'] unless $item->{ship_id}; + my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($item->{ship_id}); + confess $have_exception unless (defined $ship && $self->body_id eq $ship->body_id && $ship->task eq 'Docked'); + $space_used += 50000; + } } } confess [1011, sprintf($space_exception,$space_used)] unless ($space_used <= $available_cargo_space); @@ -248,19 +262,27 @@ sub structure_push { $payload->{resources}{$item->{type}} += $item->{quantity}; } when ('glyph') { - confess [1002, 'You must specify a glyph_id if you are trading a glyph.'] unless $item->{glyph_id}; my $glyph = Lacuna->db->resultset('Lacuna::DB::Result::Glyphs')->find($item->{glyph_id}); - confess $have_exception unless (defined $glyph && $self->body_id eq $glyph->body_id); $glyph->delete; push @{$payload->{glyphs}}, $glyph->type; } when ('plan') { - confess [1002, 'You must specify a plan_id if you are trading a plan.'] unless $item->{plan_id}; my $plan = Lacuna->db->resultset('Lacuna::DB::Result::Plans')->find($item->{plan_id}); - confess $have_exception unless (defined $plan && $self->body_id eq $plan->body_id); $plan->delete; push @{$payload->{plans}}, { class => $plan->class, level => $plan->level, extra_build_level => $plan->extra_build_level }; } + when ('prisoner') { + my $prisoner = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->find($item->{prisoner_id}); + $prisoner->task('Prisoner Transport'); + $prisoner->update; + push @{$payload->{prisoners}}, $prisoner->id; + } + when ('ship') { + my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($item->{ship_id}); + $ship->task('In Transport'); + $ship->update; + push @{$payload->{ships}}, $ship->id; + } } } return $payload; -- 2.54.0