X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FRaids.pm;h=6b4f16c3081a96527a4c89284af2035ed2ea5f16;hb=2a703f7250ea25f2f556eb25b644dcb7268f92ce;hp=d13b6704895b533fddf03e6ae9e6298c7dc6e2ae;hpb=4f142aefe97e62d8510e8f4c69e18cdad8766d13;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Raids.pm b/lib/NDWeb/Controller/Raids.pm index d13b670..6b4f16c 100644 --- a/lib/NDWeb/Controller/Raids.pm +++ b/lib/NDWeb/Controller/Raids.pm @@ -3,8 +3,10 @@ package NDWeb::Controller::Raids; use strict; use warnings; use parent 'Catalyst::Controller'; +use feature ':5.10'; use POSIX qw/floor pow/; +use List::Util qw/min/; use NDWeb::Include; use ND::Include; @@ -30,8 +32,11 @@ sub index :Path :Args(0) { my $dbh = $c->model; my $launched = 0; - my $query = $dbh->prepare(q{SELECT r.id,released_coords AS releasedcoords,tick,waves*COUNT(DISTINCT rt.id) AS waves, - COUNT(rc.uid) AS claims, COUNT(nullif(rc.launched,false)) AS launched,COUNT(NULLIF(rc.uid > 0,true)) AS blocked + my $query = $dbh->prepare(q{ + SELECT r.id,released_coords AS releasedcoords,tick + ,waves*COUNT(DISTINCT rt.id) AS waves,COUNT(rc.uid) AS claims + ,COUNT(nullif(rc.launched,false)) AS launched + ,COUNT(NULLIF(rc.uid > 0 OR rc.wave > r.waves,true)) AS blocked FROM raids r JOIN raid_targets rt ON r.id = rt.raid LEFT OUTER JOIN raid_claims rc ON rt.id = rc.target WHERE open AND not removed AND r.id @@ -49,8 +54,11 @@ sub index :Path :Args(0) { $c->stash(raids => \@raids); if ($c->check_user_roles(qw/raids_info/)){ - my $query = $dbh->prepare(q{SELECT r.id,open ,tick,waves*COUNT(DISTINCT rt.id) AS waves, - COUNT(rc.uid) AS claims, COUNT(nullif(rc.launched,false)) AS launched ,COUNT(NULLIF(uid > 0,true)) AS blocked + my $query = $dbh->prepare(q{ + SELECT r.id,open ,tick + ,waves*COUNT(DISTINCT rt.id) AS waves,COUNT(rc.uid) AS claims + ,COUNT(nullif(rc.launched,false)) AS launched + ,COUNT(NULLIF(uid > 0 OR rc.wave > r.waves,true)) AS blocked FROM raids r JOIN raid_targets rt ON r.id = rt.raid LEFT OUTER JOIN raid_claims rc ON rt.id = rc.target WHERE not removed AND (not open @@ -68,8 +76,11 @@ sub index :Path :Args(0) { $c->stash(closedraids => \@raids); - $query = $dbh->prepare(q{SELECT r.id,tick,waves*COUNT(DISTINCT rt.id) AS waves, - COUNT(rc.uid) AS claims, COUNT(nullif(rc.launched,false)) AS launched ,COUNT(NULLIF(uid > 0,true)) AS blocked + $query = $dbh->prepare(q{ + SELECT r.id,tick,waves*COUNT(DISTINCT rt.id) AS waves + ,COUNT(rc.uid) AS claims + ,COUNT(nullif(rc.launched,false)) AS launched + ,COUNT(NULLIF(uid > 0 OR rc.wave > r.waves,true)) AS blocked FROM raids r JOIN raid_targets rt ON r.id = rt.raid LEFT OUTER JOIN raid_claims rc ON rt.id = rc.target WHERE removed @@ -96,8 +107,6 @@ sub view : Local { $c->forward('findRaid'); $raid = $c->stash->{raid}; - $c->stash(comma => \&comma_value); - $c->stash(raid => $raid->{id}); my $planet; if ($c->user->planet){ @@ -132,10 +141,11 @@ sub view : Local { if ($planet->{x} == $target->{x}){ $target->{style} = 'incluster'; } - $target->{scorebash} = 'bash' if ($target->{score}/$planet->{score} < 0.4); + $target->{cap} = min(0.25,0.25 * pow($target->{value}/$planet->{value} , 0.5)); + $target->{scorebash} = 'bash' if ($target->{score}/$planet->{score} < 0.6); $target->{valuebash} = 'bash' if ($target->{value}/$planet->{value} < 0.4); - #next if ($target->{score}/$planet->{score} < 0.4) && ($target->{value}/$planet->{value} < 0.4); } + $target->{cap} //= 0.25; my $unitscans = $dbh->prepare(q{ SELECT DISTINCT ON (name) fid, name, tick, amount @@ -166,8 +176,8 @@ ORDER BY name,tick DESC my @claims; my $size = $target->{size}; for (my $i = 1; $i <= $raid->{waves}; $i++){ - my $roids = floor(0.25*$size); - $size -= $roids; + my $roids = floor($target->{cap}*$size); + $size -= floor(0.25*$size); my $xp = 0; if ($planet && $planet->{score}){ $xp = pa_xp($roids,$planet->{score},$planet->{value},$target->{score},$target->{value}); @@ -237,7 +247,8 @@ sub edit : Local { } my $targetquery = $dbh->prepare(qq{SELECT r.id,coords(x,y,z),comment,size - ,score,value,race,planet_status,relationship,comment,r.planet, s.scans + ,score,value,race,planet_status,relationship,r.planet, s.scans + ,COALESCE(max(rc.wave),0) AS waves FROM raid_targets r JOIN current_planet_stats p ON p.id = r.planet LEFT OUTER JOIN ( SELECT planet, array_accum(s::text) AS scans @@ -248,7 +259,11 @@ sub edit : Local { ) s GROUP BY planet ) s ON s.planet = r.planet + LEFT OUTER JOIN raid_claims rc ON r.id = rc.target WHERE r.raid = ? + GROUP BY r.id,x,y,z,comment,size,score,value,race + ,planet_status,relationship,comment,r.planet, s.scans + ,sizerank,scorerank,xprank,valuerank ORDER BY $order }); my $claims = $dbh->prepare(q{ SELECT username,launched FROM raid_claims @@ -258,7 +273,10 @@ sub edit : Local { my @targets; while (my $target = $targetquery->fetchrow_hashref){ my @waves; - for my $i (1 .. $raid->{waves}){ + if ($target->{waves} < $raid->{waves}){ + $target->{waves} = $raid->{waves} + } + for my $i (1 .. $target->{waves}){ $claims->execute($target->{id},$i); my $claimers; if ($claims->rows != 0){ @@ -528,7 +546,6 @@ sub targetlist : Local { my ($self, $c, $alliances, $order) = @_; my $dbh = $c->model; - $c->stash(comma => \&comma_value); $c->stash(allies => $alliances); $alliances ||= ''; my @alliances = split /,/, $alliances; @@ -576,7 +593,7 @@ sub targetcalc : Local { my ($self, $c, $target) = @_; my $dbh = $c->model; - my $target = $dbh->selectrow_hashref(q{ + $target = $dbh->selectrow_hashref(q{ SELECT p.id,p.value,p.score,metal_roids, crystal_roids, eonium_roids, ds.total, race FROM raids r JOIN raid_targets rt ON r.id = rt.raid