while (my $target = $targets->fetchrow_hashref){
my %target;
$target{Id} = $target->{id};
- $target{Coords} = $target->{id};
my @waves;
for (my $i = 1; $i <= $raid->{waves}; $i++){
my %wave;
$claimers = join '/', @claimers;
if ($owner){
$wave{Command} = 'Unclaim';
- if ($raid->{released_coords}){
- $target{Coords} = $DBH->selectrow_array('SELECT coords(x,y,z) FROM current_planet_stats WHERE id = ?',undef,$target->{planet});
- }
}elsif ($joinable){
$wave{Command} = 'Join';
}else{
my @targets;
while (my $target = $targetquery->fetchrow_hashref){
my %target;
+ if ($planet){
+ if ($planet->{x} == $target->{x}){
+ $target{style} = 'incluster';
+ }
+ $target{ScoreBash} = 'bash' if ($target->{score}/$planet->{score} < 0.4);
+ $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{Id} = $target->{id};
$target{Race} = $target->{race};
my $num = pow(10,length($target->{score})-2);
}
$target{Scans} = \@scans;
- if ($planet){
- if ($planet->{x} == $target->{x}){
- $target{style} = 'incluster';
- }
- $target{ScoreBash} = 'bash' if ($target->{score}/$planet->{score} < 0.4);
- $target{ValueBash} = 'bash' if ($target->{value}/$planet->{value} < 0.4);
- }
my @roids;
my @claims;
for (my $i = 1; $i <= $raid->{waves}; $i++){
my $roids = floor(0.25*$size);
$size -= $roids;
- my $xp;
+ my $xp = 0;
if ($planet){
- $xp = max(0,floor($roids * 10 * (min(2,$target{Score}/$planet->{score}) + min(2,$target{Value}/$planet->{value})-1)));
+ $xp = pa_xp($roids,$planet->{score},$planet->{value},$target{Score},$target{Value});
}
push @roids,{Wave => $i, Roids => $roids, XP => $xp};
if ($self->{AJAX}){
$BODY->param(Targets => \@targets);
}else{#list raids if we haven't chosen one yet
- my $query = $DBH->prepare(q{SELECT id,released_coords FROM raids WHERE open AND not removed AND
- id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)});
+ my $launched = 0;
+ my $query = $DBH->prepare(q{SELECT r.id AS raid,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
+ 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
+ IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)
+ GROUP BY r.id,released_coords,tick,waves});
$query->execute($ND::UID);
my @raids;
while (my $raid = $query->fetchrow_hashref){
- push @raids,{Raid => $raid->{id}, ReleasedCoords => $raid->{released_coords}};
+ $raid->{waves} -= $raid->{blocked};
+ $raid->{claims} -= $raid->{blocked};
+ delete $raid->{blocked};
+ $launched += $raid->{launched};
+ push @raids,$raid;
}
$BODY->param(Raids => \@raids);
if ($self->isBC){
$BODY->param(isBC => 1);
- my $query = $DBH->prepare(q{SELECT id,open FROM raids WHERE not removed AND (not open
- OR id NOT IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?))});
+ my $query = $DBH->prepare(q{SELECT r.id AS raid,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
+ 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
+ OR r.id NOT IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?))
+ GROUP BY r.id,open,tick,waves});
$query->execute($ND::UID);
my @raids;
while (my $raid = $query->fetchrow_hashref){
- push @raids,{Raid => $raid->{id}, Open => $raid->{open}};
+ $raid->{waves} -= $raid->{blocked};
+ $raid->{claims} -= $raid->{blocked};
+ delete $raid->{blocked};
+ $launched += $raid->{launched};
+ push @raids,$raid;
}
$BODY->param(ClosedRaids => \@raids);
+
+
+ $query = $DBH->prepare(q{SELECT r.id AS raid,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
+ 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
+ GROUP BY r.id,tick,waves});
+ $query->execute;
+ my @oldraids;
+ while (my $raid = $query->fetchrow_hashref){
+ $raid->{waves} -= $raid->{blocked};
+ $raid->{claims} -= $raid->{blocked};
+ delete $raid->{blocked};
+ $launched += $raid->{launched};
+ push @oldraids,$raid;
+ }
+ $BODY->param(RemovedRaids => \@oldraids);
+ $BODY->param(Launched => $launched);
}
}
return $BODY;