<?php
class Tender{
static private $instance = NULL;
public $data = array();
public $dataTender = array();
public $userData = array();
public $userDataOld = array();
public $count;
static function a($data){
if(self::$instance==NULL)self::$instance=new Tender($data);
return self::$instance;
}
public function __construct($data){
$this->userData = $data;
$this->data[1]= array( "name" =>"Экстремальные аттракционы",
"count"=>5,
"text"=>"Каждые три дня Министерство культуры проводит конкурс между компаниями.В этот раз одержат победу 10 компаний,которые больше других примут клиентов в Экстремальных аттракционах");
$this->data[]= array( "name" =>"Семейные аттракционы",
"count"=>2,
"text"=>"Каждые три дня Министерство культуры проводит конкурс между компаниями.В этот раз одержат победу 10 компаний,которые больше других примут клиентов на Семейных аттракционах");
$this->data[]= array( "name" =>"Детские аттракционы",
"count"=>8,
"text"=>"Каждые три дня Министерство культуры проводит конкурс между компаниями.В этот раз одержат победу 10 компаний,которые больше других примут клиентов на Детских аттракционах");
$this->data[]= array( "name" =>"Водные аттракционы",
"count"=>3,
"text"=>"Каждые три дня Министерство культуры проводит конкурс между компаниями.В этот раз одержат победу 10 компаний,которые больше других примут клиентов на Водных аттракционах");
$this->data[]= array( "name" =>"Скоростные аттракционы",
"count"=>3,
"text"=>"Каждые три дня Министерство культуры проводит конкурс между компаниями.В этот раз одержат победу 10 компаний,которые больше других примут клиентов на Скоростных аттракционах");
$this->data[]= array( "name" =>"Воздушные аттракционы",
"count"=>4,
"text"=>"Каждые три дня Министерство культуры проводит конкурс между компаниями.В этот раз одержат победу 10 компаний,которые больше других примут клиентов на Воздушных аттракционах");
$this->data[]= array( "name" =>"Подземные аттракционы",
"count"=>6,
"text"=>"Каждые три дня Министерство культуры проводит конкурс между компаниями.В этот раз одержат победу 10 компаний,которые больше других примут клиентов на Подземных аттракционах");
/*Тендер*/
if(User::a()->user['dataTender'] == '' || User::a()->user['timeTender']<time() || User::a()->user['thisTender']!=User::a()->user['idTender'])
{
/*id-> id тендера,s-> шаг,t-> время*/
$tender = $this->userData['idTender'];
$dataT = $this->data[$tender];
for($i=1;$i<=$dataT['count'];$i++){
$this->dataTender[$i] = array("id" => $tender, "s" => 0 , "t" => time()+900);
}
if($this->userData['id'] == User::a()->user['id']){
User::a()->user['thisTender']=User::a()->user['idTender'];
$this->update();
}
}
else{
$this->dataTender = json_decode($this->userData['dataTender'],TRUE);
foreach($this->dataTender AS $key => $value)
{
if($value['t'] < time())$this->count = '<span class="minor">(*)</span>';
}
}
}
public function allCount() {
$data = array("step1"=>0,"step2"=>0);
foreach($this->dataTender as $value){
if($value['s']==0 && $value['t']<time())$data['step1']++;
if($value['s']==1 && $value['t']<time())$data['step0']++;
}
return $data;
}
/*Получение ссылки или инфы о доходе и ремонте*/
public function getLink($number) {
$tech = json_decode($this->userData['dataShop'],true);
if($this->dataTender[$number]['s']==0){
if($this->dataTender[$number]['t']>time()){
$link = "<span class='small minor'>Запустить аттракционы через ".atime($this->dataTender[$number]['t']-time())."</span><br>";
}else{
$link = "<a class='link4' href=/Tender/".$number."/Action/><img src='/img/shop/pusk_small.png' style='margin-right:2px;width:14px'>Запустить аттракционы</a>";
}
}else{
if($this->dataTender[$number]['t']>time()){
$link = "<span class='small minor'>Принять посетителей через ".atime($this->dataTender[$number]['t']-time())."</span><br>";
}else{
$link = "<a class='link4' href=/Tender/".$number."/Action/><img src='/img/shop/plos_small.png' style='margin-right:2px;width:14px'>Принять посетителей</a>";
}
}
return $link;
}
public function selectAll() {
$rat=0;
$tech = json_decode($this->userData['dataShop'],true);
foreach($this->dataTender as $key=>$value){
if($this->dataTender[$key]['s']==0 && $this->dataTender[$key]['t']<time()){
$rating= $this->userData['level']*100;
if($this->userData['doubleDay'] == date('l')) {
$rating = $rating * 2;
}
$rating = floor($rating + ($rating*Shop::a()->data[$tech['pusk']['id']]['effect'][$tech['pusk']['level']]));
$rat+=$rating;
Jobs::a($this->userData)->searchJob('Получить опыт','Любой',$rating);
User::a()->user['rating']+= $rating;
User::a()->user['tRating']+= $rating/10000000000;
User::a()->user['cRating']+= $rating;
User::a()->user['cRatingWeek']+= $rating;
$this->dataTender[$key]['t'] = time()+900;
$this->dataTender[$key]['s'] = 1;
}
}
if($this->userData['IdCompany']!=0){
DB::a()->d->query("UPDATE `Company` SET `companyRating` = `companyRating` + '".$rat."' WHERE `cid` = '".$this->userData['IdCompany']."' LIMIT 1");
}
$this->update();
return $rat;
}
public function actionAll() {
$people=0;
$tech = json_decode($this->userData['dataShop'],true);
foreach($this->dataTender as $key=>$value){
if($this->dataTender[$key]['s']==1 && $this->dataTender[$key]['t']<time()){
$peoples= Shop::a()->data[$tech['plos']['id']]['effect'][$tech['plos']['level']]+1;
$people+= $peoples;
Jobs::a($this->userData)->searchJob('Посетители тендер','Любой',$peoples);
$this->dataTender[$key]['t'] = time()+900;
$this->dataTender[$key]['s'] = 0;
}
}
/*Диплом Торговца*/
if(User::a()->user['DocTender']>0){
$people = $people + floor($people*User::a()->user['DocTender']/20);
}
User::a()->user['cRatingTender']+= $people;
if($this->userData['IdCompany']!=0){
DB::a()->d->query("UPDATE `Company` SET `companyTender` = `companyTender` + '".$people."'WHERE `cid` = '".$this->userData['IdCompany']."' LIMIT 1");
}
$this->update();
return $people;
}
public function action($number) {
if(!array_key_exists($number,$this->dataTender))return false;
if($this->dataTender[$number]['t']>time())return false;
$tech = json_decode($this->userData['dataShop'],true);
$rating = $this->userData['level']*100;
$rating = floor($rating + ($rating*Shop::a()->data[$tech['pusk']['id']]['effect'][$tech['pusk']['level']]));
$peoples = Shop::a()->data[$tech['plos']['id']]['effect'][$tech['plos']['level']]+1;
/*Диплом Торговца*/
if(User::a()->user['DocTender']>0){
$peoples = $peoples + floor($peoples*User::a()->user['DocTender']/20);
}
/*Техника*/
$tech = json_decode($this->userData['dataShop'],true);
/*Двойной опыт*/
if($this->userData['doubleDay'] == date('l')) {
$rating = $rating * 2;
}
if($this->dataTender[$number]['s']==0){
$type = 'rating';
$count = $rating;
Jobs::a($this->userData)->searchJob('Получить опыт','Любой',$rating);
User::a()->user['rating']+= $rating;
User::a()->user['tRating']+= $rating/10000000000;
User::a()->user['cRating']+= $rating;
User::a()->user['cRatingWeek']+= $rating;
$this->dataTender[$number]['t'] = time()+900;
$this->dataTender[$number]['s'] = 1;
$_SESSION['info'] = "Награда <img src='/img/icons/xp.png' style='margin-right:2px;width:14px'>".$rating;
/*Если в компании*/
if($this->userData['IdCompany']!=0){
DB::a()->d->query("UPDATE `Company` SET `companyRating` = `companyRating` + '".$rating."' WHERE `cid` = '".$this->userData['cid']."' LIMIT 1");
}
$this->update();
}else{
$type = 'peoples';
$count = $peoples;
Jobs::a($this->userData)->searchJob('Посетители тендер','Любой',$peoples);
User::a()->user['cRatingTender']+= $peoples;
$this->dataTender[$number]['t'] = time()+900;
$this->dataTender[$number]['s'] = 0;
$_SESSION['info'] = "Принято <img src='/img/icons/family.png' style='margin-right:2px;width:14px'>".$peoples." клиентов";
/*Если в компании*/
if($this->userData['IdCompany']!=0){
DB::a()->d->query("UPDATE `Company` SET `companyTender` = `companyTender` + '".$peoples."' WHERE `cid` = '".$this->userData['cid']."' LIMIT 1");
}
$this->update();
}
return array("type"=>$type,'count'=>$count);
}
public function workerUprav(){
$this->actionAll();
}
public function workerSmotrit(){
$this->selectAll();
}
public function update() {
User::a()->user['dataTender'] = json_encode($this->dataTender);
}
}