<?php
require'fun.php';
require'f_conectare.php';
conectare('grajd (triburile v2)','triburile2-grajd');
$titlu='Grajd - Triburile V2';
$back[1]='<a href="/triburile2">'.img('triburile.gif',1).'Triburi</a>';
require'f_sus.php';
require'triburile2_nicu1.php';
require'f_ramas.php';
$msg='';
if($go=='recruteaza')
{
$spio=$_POST['spio'];
$cvus=$_POST['cvus'];
$cvgr=$_POST['cvgr'];
if($spio>0)
{
$nr=$spio;
$tip=4;
$lvlgrj=$conn->query('SELECT`lvlcal`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$foo=$conn->query('SELECT`cant`FROM`t2_grajd`WHERE`lvl`="'.$lvlgrj[0].'"')->fetch_row();
$tmp=($foo[0]+20)*$nr;
}
if($cvus>0)
{
$nr=$cvus;
$tip=5;
$lvlgrj=$conn->query('SELECT`lvlcal`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$foo=$conn->query('SELECT`cant`FROM`t2_grajd`WHERE`lvl`="'.$lvlgrj[0].'"')->fetch_row();
$tmp=($foo[0]+38)*$nr;
}
if($cvgr>0)
{
$nr=$cvgr;
$tip=6;
$lvlgrj=$conn->query('SELECT`lvlcal`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$foo=$conn->query('SELECT`cant`FROM`t2_grajd`WHERE`lvl`="'.$lvlgrj[0].'"')->fetch_row();
$tmp=($foo[0]+57)*$nr;
}
$tl[1]=50;
$ta[1]=30;
$tp[1]=10;
$tl[2]=30;
$ta[2]=30;
$tp[2]=90;
$tl[3]=60;
$ta[3]=30;
$tp[3]=40;
$tl[4]=60;
$ta[4]=60;
$tp[4]=60;
$tl[5]=80;$ta[5]=90;$tp[5]=80;
$tl[6]=120;
$ta[6]=130;
$tp[6]=110;
$ggo1=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`,`poptot`,`lvlfrm`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$poptot=$conn->query('SELECT`cant`FROM`t2_ferma`WHERE`lvl`="'.$ggo1[6].'"')->fetch_row();
$lmn=$ggo1[0]-$tl[$tip]*$nr;
$arg=$ggo1[1]-$ta[$tip]*$nr;
$ptr=$ggo1[2]-$tp[$tip]*$nr;
$pop=$ggo1[3]+$nr;
$pct=$ggo1[4]+$nr;
$lmn1=$tl[$tip] *$nr;
$arg1=$ta[$tip] *$nr;
$ptr1=$tp[$tip] *$nr;
if(preg_match('/[^0-9]/',$spio)||preg_match('/[^0-9]/',$cvus)||preg_match('/[^0-9]/',$cvgr)||mb_strlen($spio)>4||mb_strlen($cvus)>4||mb_strlen($cvgr)>4)
{
$conn->query('INSERT INTO`jurnal_admini`SET`nume`="Excrocherii (triburile v2)",`de`="'.$de.'",`text`="a încercat să recruteze urmatoarele unitati:[br/]'.$spio.' spioni[br/]'.$cvus.' cavalerie usoara[br/]'.$cvgr.' cavalerie grea",`data`="'.$_SERVER['REQUEST_TIME'].'"');
$msg.=$div[7].'Nu ai voie sa faci asta!'.$div[0];
}
elseif($poptot[0]<$pop)
$msg.=$div[7].'Nu poți avea în sat mai mult de <strong>'.$pop.'</strong> persoane!<br />Ridica nivelul fermei!'.$div[0];
elseif($ggo1[0]<$lmn1)
$msg.=$div[7].'Nu ai destul lemn!'.$div[0];
elseif($ggo1[1]<$arg1)
$msg.=$div[7].'Nu ai destula argila!'.$div[0];
elseif($ggo1[2]<$ptr1)
$msg.=$div[7].'Nu ai destul fier!'.$div[0];
else
{
$no1=$conn->query('UPDATE`t2_membrii`SET`lmn`="'.$lmn.'",`arg`="'.$arg.'",`ptr`="'.$ptr.'",`pop`="'.$pop.'",`pct`="'.$pct.'"WHERE`de`="'.$de.'"');
$toy=$conn->query('SELECT COUNT(*)FROM`t2_armata`WHERE`de`="'.$de.'"')->fetch_row();
if($toy[0])
{
$topt=$conn->query('SELECT`timp`,`data`FROM`t2_armata`WHERE`de`="'.$de.'"ORDER BY`id`DESC LIMIT 1 ')->fetch_row();
$timpe=$topt[0]+$topt[1];
}
else
$timpe=$_SERVER['REQUEST_TIME'];
$no=$conn->query('INSERT INTO`t2_armata`SET`de`="'.$de.'",`tip`="'.$tip.'",`data`="'.$timpe.'",`timp`="'.$tmp.'",`nr`="'.$nr.'"');
if($no1&&$no)
$msg=$div[6].'Comanda acceptata!'.$div[0];
else
$msg=$div[7].'Eroare!'.$div[0];
}
}
if(isset($_GET['pid']))
{
$tl[1]=50;
$ta[1]=30;
$tp[1]=10;
$tl[2]=30;
$ta[2]=30;
$tp[2]=90;
$tl[3]=60;
$ta[3]=30;
$tp[3]=40;
$tl[4]=60;
$ta[4]=60;
$tp[4]=60;
$tl[5]=80;
$ta[5]=90;
$tp[5]=80;
$tl[6]=120;
$ta[6]=130;
$tp[6]=110;
$tir=$conn->query('SELECT COUNT(*)FROM`t2_armata`WHERE`id`="'.$pid.'"')->fetch_row();
if($tir[0])
{
$tiu=$conn->query('SELECT`nr`,`tip`FROM`t2_armata`WHERE`id`="'.$pid.'"')->fetch_row();
$lol=$conn->query('SELECT COUNT(*),`id`FROM`t2_armata`WHERE`de`="'.$de.'"&&`tip`="'.$tiu[1].'"')->fetch_row();
if($lol[0])
{
$lot=$conn->query('SELECT`id`,`nr`,`tip`FROM`t2_armata`WHERE`id`="'.$lol[1].'"')->fetch_row();
$tot=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$lmn=$tot[0]+$tl[$tiu[1]]*$tiu[0];
$arg=$tot[1]+$ta[$tiu[1]]*$tiu[0];
$ptr=$tot[2]+$tp[$tiu[1]]*$tiu[0];
$pop=$tot[3]-$tiu[0];
$pct=$tot[4]-$tiu[0];
$conn->query('UPDATE`t2_membrii`SET`lmn`="'.$lmn.'",`arg`="'.$arg.'",`ptr`="'.$ptr.'",`pop`="'.$pop.'",`pct`="'.$pct.'"WHERE`de`="'.$de.'"');
$conn->query('DELETE FROM`t2_armata`WHERE`id`="'.$lot[0].'"');
}
}
}
$proces=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`tip`="9"&&`de`="'.$de.'"')->fetch_row();
if($proces[0]<2)
{
if($go!='')
{
$ggo=$conn->query('SELECT COUNT(*)FROM`t2_grajd`WHERE`lvl`="'.$go.'"')->fetch_row();
$ggoe=$conn->query('SELECT`lvlcal`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$fot=$ggoe[0]+1;
$fe=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="9"')->fetch_row();
if($fe[0])
{
$fe=$conn->query('SELECT`lvl`FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="9"')->fetch_row();
$fot=$fe[0]+1;
}
if($ggo[0]&&($go==$fot))
{
$ggo=$conn->query('SELECT`lmn`,`arg`,`ptr`,`timp`,`pop`FROM`t2_grajd`WHERE`lvl`="'.$go.'"')->fetch_row();
$ggo1=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`,`poptot`,`lvlfrm`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$poptot=$conn->query('SELECT`cant`FROM`t2_ferma`WHERE`lvl`="'.$ggo1[6].'"')->fetch_row();
$lmn=$ggo1[0]-$ggo[0];
$arg=$ggo1[1]-$ggo[1];
$ptr=$ggo1[2]-$ggo[2];
$pop=$ggo1[3]+$ggo[4];
$pct=$ggo1[4]+$ggo[4];
if($poptot[0]<$pop)
$msg.=$div[7].'Nu poți avea în sat mai mult de <strong>'.$pop.'</strong> persoane!<br />Ridica nivelul fermei!'.$div[0];
elseif($ggo1[0]<$ggo[0])
$msg.=$div[7].'Nu ai destul lemn!'.$div[0];
elseif($ggo1[1]<$ggo[1])
$msg.=$div[7].'Nu ai destula argila!'.$div[0];
elseif($ggo1[2]<$ggo[2])
$msg.=$div[7].'Nu ai destul fier!'.$div[0];
else
{
$no1=$conn->query('UPDATE`t2_membrii`SET`lmn`="'.$lmn.'",`arg`="'.$arg.'",`ptr`="'.$ptr.'",`pop`="'.$pop.'",`pct`="'.$pct.'"WHERE`de`="'.$de.'"');
$toy=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"')->fetch_row();
if($toy[0])
{
$topt=$conn->query('SELECT`timp`,`data`FROM`t2_procese`WHERE`de`="'.$de.'"ORDER BY`id`DESC LIMIT 1 ')->fetch_row();
$timpe=$topt[0]+$topt[1];
}
else
$timpe=$_SERVER['REQUEST_TIME'];
$no=$conn->query('INSERT INTO`t2_procese`SET`de`="'.$de.'",`tip`="9",`data`="'.$timpe.'",`timp`="'.$ggo[3].'",`lvl`="'.$go.'"');
if($no1&&$no)
$msg=$div[6].'Comanda acceptata!'.$div[0];
else
$msg=$div[7].'Eroare!'.$div[0];
}
}
else
$msg=$div[7].'Eroare!'.$div[0];
}
}
echo$msg;
require'triburile2_nicu2.php';
echo$div[4].'<img src="'.$domenii_statice[2].'triburile2/stable1.png" alt="" />Grajd (nivel '.$if[8].')'.$div[5].$div[10].'In grajd îți poți instrui calareti.<br />Cu cat este mai inalt nivelul grajdului, cu atat mai repede îți poți instrui trupele.'.$div[0];
$lvlcal=$if[8];
$fe=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="9"')->fetch_row();
if($fe[0])
{
$fe=$conn->query('SELECT`lvl`FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="9"ORDER BY`id`DESC LIMIT 1')->fetch_row();
$lvlcal=$fe[0];
}
if($lvlcal==$conn->query('SELECT COUNT(*)FROM`t2_grajd`')->fetch_row()[0])
echo$div[6].'Cladire complet terminata!'.$div[0];
else
{
$lvl=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`timp`FROM`t2_grajd`WHERE`lvl`="'.$lvlcal.'"')->fetch_row();
echo$div[7].'Nivelul '.++$lvlcal.' costă: <img src="'.$domenii_statice[2].'triburile2/lemne.png" alt="lemn" />'.$lvl[0].'<img src="'.$domenii_statice[1].'triburile2/argila.png" alt="argile" />'.$lvl[1].'<img src="'.$domenii_statice[1].'triburile2/piatra.png" alt="piatra" />'.$lvl[2].'<br /><img src="'.$domenii_statice[2].'triburile2/populatie.png" alt="populatie" />'.$lvl[3].'<img src="'.$domenii_statice[2].'triburile2/clock.png" alt="ceas" />'.ramas($lvl[4]).$div[0];
$ggo=$conn->query('SELECT`lmn`,`arg`,`ptr`,`timp`,`pop`FROM`t2_grajd`WHERE`lvl`="'.$lvlcal.'"')->fetch_row();
$ggo1=$conn->query('SELECT`lmn`,`arg`,`ptr`,`pop`,`pct`,`poptot`FROM`t2_membrii`WHERE`de`="'.$de.'"')->fetch_row();
$lmn=$ggo1[0]-$ggo[0];
$arg=$ggo1[1]-$ggo[1];
$ptr=$ggo1[2]-$ggo[2];
$pop=$ggo1[3]+$ggo[4];
$pct=$ggo1[4]+$ggo[4];
$te=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"')->fetch_row();
$fef=$conn->query('SELECT COUNT(*)FROM`t2_procese`WHERE`de`="'.$de.'"&&`tip`="9"')->fetch_row();
if($ggo1[0]>$ggo[0]&&$ggo1[1]>$ggo[1]&&$ggo1[2]>$ggo[2])
{
if($fef[0]>=2)
echo$div[7].'Nu poți da mai mult de 2 nivele de constructii pe aceeas cladire!'.$div[0];
elseif($te[0]<2||$if[13]==1)
{
if($te[0]<=7)
{
if($lvlcal-1==0)
echo$div[1].'<a href="/triburile2-grajd/tip/'.$lvlcal.'">Construire</a>'.$div[0];
else
echo$div[1].'<a href="/triburile2-grajd/tip/'.$lvlcal.'">Extindere nivel '.$lvlcal.'</a>'.$div[0];
}
else
echo$div[7].'Numarul maxim de constructii pe cont Premium!'.$div[0];
}
elseif($te[0]>=2)
echo$div[7].'Trebuie să ai cont Premium pentru mai mult de 2 nivele de constructie!'.$div[0];
}
else
echo$div[7].'Nu ai suficienta materie!'.$div[0];
}
$items=$conn->query('SELECT`de`,`tip`,`nr`,`data`,`timp`,`id`FROM`t2_armata`WHERE`de`="'.$de.'"&&(`tip`="4"||`tip`="5"||`tip`="6")ORDER BY`id`ASC');
$cou=0;
echo$div[4].'Recrutare:'.$div[5].'<table columns="5"><tr><th><strong>Instructie</strong></th><th><strong>Numar</strong></th><th><strong>Timp</strong></th><th><strong>Term</strong></th><th><strong>[X]</strong></th></tr>';
require'f_data.php';
while($item=$items->fetch_row())
{
$cou++;
$term=$item[4]+$item[3];
echo'<tr><td>'.['','Lancieri','Luptator cu spada','Luptator cu toporul','Spion','Cavalerie usoara','Cavalerie grea'][$item[1]].'</td><td>'.$item[2].'</td><td>'.($cou==1?ramas($term-$_SERVER['REQUEST_TIME']):ramas($item[4])).'</td><td><small>'.data($term).'</small></td><td><a href="/triburile2-grajd/id/'.$item[5].'"><img src="'.$domenii_statice[2].'sterge.png" alt="" width="16" height="16" /></a></td></tr>';
}
echo'</table>'.$div[1].'<a href="/triburile2-recruteaza-grajd">Recruteaza</a>'.$div[0];
require'f_jos.php';