Вход Регистрация
Файл: ewar/class/coliseum.php
Строк: 853
<?php

    
class Coliseum {
    
        
#Konstantos:
        
const TABLE 'coliseum';        #Koliziejaus lentelės pavadinimas duomenų bazėje.
        
        #Ypatybės:
        
private $uid      null;        #Žaidėjo ID.
        
private $dataUid null;        #Žaidėjo duomenys apie koliziejų.
        
private $turn      null;        #Eilė.
        
private $status  null;        #Žaidėjo statusas koliziejuje.
        
private $stars      null;        #Masyvas su žvaigždučių kiekiu perėjimui į kitą rangą.
        
private $fight      null;        #Kovos masyvas.
        
public $uron 0;
        
        
#Metodai:
        
public function __construct($uid null) {
        
            if (
is_null($uid) AND is_null($this -> uid)) {
            
                exit;
            
            }
            
            
$this -> uid $uid;
            
$this -> dataUid();
            
$this -> initStars();
        
        }
        
        public function 
__destruct() {
        
            if (!
is_null($this -> fight)) {
            
                
$this -> updateFight($this -> fight['hash'], $this -> fight);
            
            }
        
        }

        
#Metodas gražinantis raktus iš kešo:
        
private function cacheKey($type$hash '') {
        
            
$keys = array(
                
=> 'coliseum.data.uid'.((!empty($hash)) ? $hash $this -> uid),        #Žaidėjo duomenys apie koliziejų.
                
=> 'coliseum.turn',                                                    #Eilė.
                
=> 'coliseum.hash.uid'.$this -> uid,                                    #Žaidėjo raktas koliziejuje.
                
=> 'coliseum.fight.hash.'.$hash,                                        #Kovos raktas.
            
);
            
            return @
$keys[$type];
        
        }
        
        public function 
setKeyUser($key) {
        
            
$cKey $this -> cacheKey(3);
            
            
writecache($cKey$key);
        
        }
        
        
#Gražina žaidėjo duomenis iš koliziejaus. Imeta į keša $this -> dataUid:
        
public function dataUid() {
        
            if (
is_null($this -> dataUid)) {
            
                
$cKey $this -> cacheKey(1);
                
$this -> dataUid readcache($cKey);
                
                if (
$this -> dataUid === FALSE) {
                
                    
$this -> dataUid mysql_fetch_assoc(mysql_query("SELECT * FROM `".self::TABLE."` WHERE `uid` = ".$this -> uid." LIMIT 1"));
                    
                    if (!
$this -> dataUid) {
                    
                        
$this -> insertDataUid();
                        
$this -> dataUid mysql_fetch_assoc(mysql_query("SELECT * FROM `".self::TABLE."` WHERE `uid` = ".$this -> uid." LIMIT 1"));
                    
                    }
                    
                    
writecache($cKey$this -> dataUid);
                
                }
            
            }
            
            return 
$this -> dataUid;
        
        }
        
        public function 
dataId($id) {
        
            if (
$id == $this -> uid) {
            
                return 
$this -> dataUid;
            
            }
            
            
$cKey $this -> cacheKey(1$id);
            
$data readcache($cKey);
            
            if (
$data === FALSE) {
            
                
$data mysql_fetch_assoc(mysql_query("SELECT * FROM `".self::TABLE."` WHERE `uid` = ".$id." LIMIT 1"));
                
                if (!
$data) {
                
                    
$this -> insertDataUid($id);
                    
$data mysql_fetch_assoc(mysql_query("SELECT * FROM `".self::TABLE."` WHERE `uid` = ".$id." LIMIT 1"));
                
                }
                
                
writecache($cKey$data);
            
            }
            
            return 
$data;
        
        }
        
        public function 
clearData($id false) {
        
            
$uid = (!$id) ? $this -> uid $id;
            
$cKey $this -> cacheKey(1$uid);
            
            
deletecache($cKey);
        
        }
        
        
#Sukuria duomenis apie žaidėją koliziejuje:
        
public function insertDataUid($id false) {
        
            
$uid = (!$id) ? $this -> uid $id;
            
            
mysql_query("INSERT INTO `".self::TABLE."` SET `uid` = ".$uid."");
            
            return 
mysql_insert_id();
        
        }
        
        
#Patikrina ar žaidėjui leidžiama įeiti į koliziejų:
        
public function access($minLevel$usLevel) {
        
            if (
$usLevel $minLevel) {
            
                return 
false;
            
            }
            
            return 
true;
        
        }
        
        
#Gražina žaidėjo žaidimo statusą:
        #1 - eilė
        #3 - kova, gyvas
        #4 - kova, miręs
        #2 - kovos rezultatas
        
public function status() {
        
            
$cKey $this -> cacheKey(3);
            
$hash readcache($cKey);
            
            if (
$hash === FALSE) {
            
                
$this -> status 1;
            
            }
            else
            {
            
                
$this -> initFight($hash);
                
                if (
$this -> fight) {
                
                    if (
$this -> fight['type'] === 'fight') {
                    
                        if (@
$this -> fight['life'][$this -> uid]) {
                        
                            
$this -> status 3;
                        
                        }
                        else
                        {
                        
                            
$this -> status 4;
                        
                        }
                    
                    }
                    else
                    {
                    
                        
$this -> status 2;
                    
                    }
                
                }
                else
                {
                
                    
$this -> status 1;
                    
$this -> deleteHash();
                
                }
            
            }
            
            return 
$this -> status;
        
        }
        
        public function 
deleteHash() {
        
            
$cKey $this -> cacheKey(3);
            
            
deletecache($cKey);
        
        }
        
        
#Gražina masyvą su žvaigždučių kiekiu perėjimui į kitą rangą.
        
public function initStars() {
        
            if (
is_null($this -> stars)) {
            
                
$this -> start = array();
                
                for(
$rang 1$rang <= 20$rang ++) {
                
                    if (
$rang <= 20 AND $rang >= 16) {
                    
                        
$this -> stars[$rang] = 3;
                    
                    }
                    else if (
$rang <= 15 AND $rang >= 11) {
                    
                        
$this -> stars[$rang] = 4;
                    
                    }
                    else if (
$rang <= 10 AND $rang >= 6) {
                    
                        
$this -> stars[$rang] = 5;
                    
                    }
                    else if (
$rang <= AND $rang >= 3) {
                    
                        
$this -> stars[$rang] = 5;
                    
                    }
                    else if (
$rang === 2) {
                    
                        
$this -> stars[$rang] = 6;
                    
                    }
                    else
                    {
                    
                        
$this -> stars[$rang] = 7;
                    
                    }
                
                }
            
            }
        
        }

        public function 
upDownRang() {
        
            
$myStars  $this -> dataUid['star'];
            
$myRang   $this -> dataUid['rang'];
            
$upRang   $myRang 1;
            
$downRang $myRang 1;
            
$minRang $this -> dataUid['minRang'];
            
$upStars = @$this -> stars[$upRang];
            
$downStars = @$this -> stars[$downRang];
            
            if (
$myRang == 20 AND $myStars 0) {
            
                
mysql_query("UPDATE `".self::TABLE."` SET star = 0 WHERE `uid` = ".$this -> uid." LIMIT 1");
                
                
$this -> clearData($this -> uid);
            
            }
            
            if (
$myRang == AND $myStars 7) {
            
                
mysql_query("UPDATE `".self::TABLE."` SET star = 7 WHERE `uid` = ".$this -> uid." LIMIT 1");
                
                
$this -> clearData($this -> uid);
            
            }
            
            if (
$upStars AND $myStars $upStars) {
            
                
$nMinRang = ($minRang $upRang) ? $upRang $minRang;
                
$rewardGold = ($minRang $upRang) ? 10 0;
                
                
mysql_query("UPDATE `".self::TABLE."` SET star = ".($this -> dataUid['star'] - $upStars).", rang = ".$upRang.", minRang = ".$nMinRang." WHERE `uid` = ".$this -> uid." LIMIT 1");
                
                if (
$rewardGold 0) {
                
                    
mysql_query("UPDATE `vartotojai` SET g = g+10 WHERE `id` = ".$this -> uid." LIMIT 1");
                
                }
                
                
$this -> clearData($this -> uid);
                
                return array(
'up' => true'down' => false'gold' => $rewardGold);
            
            }
            
            if (
$downStars AND $myStars 0) {
            
                
mysql_query("UPDATE `".self::TABLE."` SET rang = ".$downRang.", star = ".($downStars $myStars)." WHERE `uid` = ".$this -> uid." LIMIT 1");
                
                
$this -> clearData($this -> uid);
                
                return array(
'up' => false'down' => true);
            
            }
            
            return 
false;
        
        }
        
        
#Gražina masyvą su žvaigždučių kiekiu perėjimui į kitą lygį:
        
public function countStars($rang false$star false) {
        
            
$rangId = ($rang) ? $rang $this -> dataUid['rang'];
            
$stars  = ($star) ? $star $this -> dataUid['star'];
            
            if (
$rangId == 1) {
            
                
$cStarsUp 7;
            
            }
            else
            {
            
                
$cStarsUp $this -> stars[$rangId 1];
            
            }
            
            
$myStars $stars;
            
$list = array();
            
            for(
$i 1$i <= $cStarsUp$i ++) {
            
                if (
$myStars >= 1) {
                
                    
$list[] = 1;
                    
$myStars --;
                
                }
                else if (
$myStars >= 0.5) {
                
                    
$list[] = 0.5;
                    
$myStars $myStars 0.5;
                
                }
                else
                {
                
                    
$list[] = 0;
                
                }
            
            }
            
            return 
$list;
        
        }
        
        
#Eilės inicializacija:
        
public function initTurn() {
        
            if (
is_null($this -> turn)) {
            
                
$cKey $this -> cacheKey(2);
                
$this -> turn readcache($cKey);
                
                if (
$this -> turn === FALSE) {
                
                    
$this -> turn = array();
                    
                    for(
$rang 1$rang <= 20$rang ++) {
                    
                        
$this -> turn['players'][$rang] = array();
                        
$this -> turn['timer'][$rang] = time();
                    
                    }
                    
                    
writecache($cKey$this -> turn);
                
                }
            
            }
        
        }
        
        
#Patikrina ar žaidėjas eilėje:
        
public function checkTurnUid() {
        
            if (
is_null($this -> turn)) {
            
                
$this -> initTurn();
            
            }
            
            if (
in_array($this -> uid$this -> turn['players'][$this -> dataUid['rang']])) {
            
                return 
true;
            
            }
            else
            {
            
                return 
false;
            
            }
        
        }
        
        
#Gražina žaidėjų kiekį su tokiu pačių žvaigždučių kiekiu kaip žaidėjas:
        
public function countTurnPlayers() {
        
            if (
is_null($this -> turn)) {
            
                
$this -> initTurn();
            
            }
            
            
$count count($this -> turn['players'][$this -> dataUid['rang']]);
            
            return 
$count;
        
        }
        
        
#Įrašymas į eilę:
        
public function addTurn($timer) {
        
            if (
is_null($this -> turn)) {
            
                
$this -> initTurn();
            
            }
            
            
$count $this -> countTurnPlayers();
            
            if (
$count == 0) {
            
                
$this -> turn['players'][$this -> dataUid['rang']][] = $this -> uid;
                
$this -> turn['timer'][$this -> dataUid['rang']] = time() + $timer;
            
            }
            else
            {
            
                
$this -> turn['players'][$this -> dataUid['rang']][] = $this -> uid;
            
            }
            
            
$this -> updateTurn($this -> turn);
        
        }
        
        
#Gražina eilės taimerį:
        
public function getTurnTimer() {
        
            if (
is_null($this -> turn)) {
            
                
$this -> initTurn();
            
            }
            
            return @
$this -> turn['timer'][$this -> dataUid['rang']];
        
        }
        
        
#Atnaujina eilę:
        
public function updateTurn($turn) {
        
            
$cKey $this -> cacheKey(2);
            
            
writecache($cKey$turn);
        
        }
        
        
#Startuoja kova, jeigu yra žaidėjai arba baigėsi laukimo laikas:
        
public function startFight($dm) {
        
            
$myRang $this -> dataUid['rang'];
            
$countPlayers $this -> countTurnPlayers();
            
$timer $this -> getTurnTimer();
            
            if (
$countPlayers >= OR ($timer time()) <= AND $countPlayers 0) {
            
                
$fight_hash $this -> generateHash();
                
$stats = array('str' => 0'def' => '0''hp' => 0'agi' => 0);
                
$playId 0;
                
$newBot = ($countPlayers 5) ? $countPlayers;
                
$newBot $countPlayers;
                
$fight = array(
                    
'type'    => 'fight',
                    
'hash'    => $fight_hash,
                    
'life'    => array(),
                    
'dead'    => array(),
                    
'target'  => array(),
                    
'journal' => array(),
                    
'damage'  => array(),
                    
'time'       => time() + 300
                
);
                
                foreach(
$this -> turn['players'][$myRang] as $k => $uid) {
                
                    if (
$uid == $this -> uid) {
                    
                        
$users $dm;
                    
                    }
                    else
                    {
                    
                        
$users mysql_fetch_assoc(mysql_query("SELECT * FROM `vartotojai` WHERE `id` = '$uid' LIMIT 1"));
                    
                    }

                    
$this -> uid $uid;
                    
$this -> dataUid null;
                    
$this -> setKeyUser($fight_hash);
                    
$coliseum $this -> dataUid();
                    
                    unset(
$this -> turn['players'][$myRang][$k]);
                    
                    
$fight['target'][$uid] = null;
                    
$fight['journal'][$uid] = array();
                    
$fight['damage'][$uid] = 0;
                    
$mctime1 explode(' 'microtime());
                    
$mctime1[1] = $mctime1[1] - 5;
                    
$fight['life'][$uid] = array(
                        
'id'         => $uid,
                        
'battle_hp'     => $users['vit'] * 2,
                        
'other_hp'     => $users['vit'] * 2,
                        
'str'         => $users['str'],
                        
'def'         => $users['def'],
                        
'agi'         => $users['agi'],
                        
'name'         => $users['nick'],
                        
'statusas'     => $users['statusas'],
                        
'akmuo_time' => $users['akmuo_time'],
                        
'zole_time'     => $users['zole_time'],
                        
'microtime'     => ($mctime1[0].' '.$mctime1[1]),
                        
'uron'         => false,
                        
'uvorot'     => time(),
                        
'nastroyka'  => time(),
                        
'life'         => true,
                        
'bot'          => false,
                        
'level'         => $users['level'],
                        
'ability_1'  => $users['ability_1'],
                        
'ability_2'  => $users['ability_2'],
                        
'ability_3'  => $users['ability_3'],
                        
'ability_4'  => $users['ability_4'],
                        
'ability_5'  => $users['ability_5'],
                        
'ability_1_quality' => $users['ability_1_quality'],
                        
'ability_2_quality' => $users['ability_2_quality'],
                        
'ability_3_quality' => $users['ability_3_quality'],
                        
'ability_4_quality' => $users['ability_4_quality'],
                        
'ability_5_quality' => $users['ability_5_quality'],
                        
'skills'     => array(),
                        
'my_user_add_hp'    => 0
                    
);
                    
                    
$stats['str'] = $stats['str'] + $fight['life'][$uid]['str'];
                    
$stats['hp'] = $stats['hp'] + $fight['life'][$uid]['battle_hp'];
                    
$stats['agi'] = $stats['agi'] + $fight['life'][$uid]['agi'];
                    
$stats['def'] = $stats['def'] + $fight['life'][$uid]['def'];
                    
$playId ++;
                
                }
                
                if (
$newBot 0) {
                
                    foreach(
$stats as $key => $prms) {
                    
                        
$stats[$key] = (int) ($stats[$key] / $playId);
                    
                    }
                    
                    for(
$i 1$i <= $newBot$i ++) {
                    
                        
$this -> generateBot($fight['life'], $stats$myRang);
                    
                    }
                
                }
                
                foreach(
$fight['life'] as $keyId => $play) {
                
                    
$fight['target'][$keyId] = null;
                    
$fight['damage'][$keyId] = 0;
                    
$fight['journal'][$keyId] = array();
                
                }
                
                
$this -> updateTurn($this -> turn);
                
$this -> fight $fight;
                
                foreach(
$fight['life'] as $keyId => $play) {
                
                    
$this -> addJournal('<span class="lime">[kova_prasidejo*]</span>'$keyId);
                
                }
                
                return 
true;
            
            }
            
            return 
false;
        
        }
        
        public function 
initFight($hash false) {
        
            if (
is_null($this -> fight) AND $hash) {
            
                
$cKey $this -> cacheKey(4$hash);
                
$this -> fight readcache($cKey);
            
            }
            
            return 
$this -> fight;
        
        }
        
        public function 
updateFight($hash$fight) {
        
            
$cKey $this -> cacheKey(4$hash);
            
$this -> fight $fight;
            
            
writecache($cKey$fight);
        
        }
        
        
#Generuoja unikalų kėšą komandai kovoje:
        
public function generateHash() {
        
            
$array = array(1,2,3,4,5,6,7,8,9,0,'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','z','x','c','v','b','n','m');
            
$rand  rand(10,20);
            
$hash  microtime();
            
            for(
$i 1$i $rand$i ++) {
            
                
$key array_rand($array);
                
$hash .= $array[$key];
            
            }
            
            return 
md5($hash);
        
        }
        
        public function 
generateNameBot() {
        
            
$array  = array('q','w','r','t','p','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m');
            
$array2 = array('e','y','u','i','o','a');
            
$strlen rand(5,6);
            
$name     '';
            
            for(
$i 1$i <= $strlen$i ++) {
            
                if (
$i == 1) {
                
                    
$key array_rand($array);
                    
$name .= $array[$key];
                
                }
                elseif (
$i == 2) {
                
                    
$key array_rand($array2);
                    
$name .= $array2[$key];
                
                }
                elseif (
$i <= 4) {
                
                    
$key array_rand($array);
                    
$name .= $array[$key];
                
                }
                elseif (
$i == 5) {
                
                    
$key array_rand($array2);
                    
$name .= $array2[$key];
                
                }
                else
                {
                
                    
$key array_rand($array);
                    
$name .= $array[$key];
                
                }
            
            }
            
            
$name mb_convert_case($nameMB_CASE_TITLE"UTF-8");
            
            return 
$name;
        
        }
        
        public function 
generateBot(&$players$params = array(), $rang) {
        
            
$id rand(23534234,218123123);
            
            if (
$rang <= 2) {
            
                
$percent_par = array('min' => 160'max' => 200);
                
$percent_hp = array('min' => 180'max' => 220);
            
            }
            elseif (
$rang AND $rang <= 5) {
            
                
$percent_par = array('min' => 120'max' => 160);
                
$percent_hp = array('min' => 140'max' => 180);
            
            }
            elseif (
$rang AND $rang <= 10) {
            
                
$percent_par = array('min' => 80'max' => 120);
                
$percent_hp = array('min' => 100'max' => 140);
            
            }
            elseif (
$rang 10 AND $rang <= 15) {
            
                
$percent_par = array('min' => 40'max' => 80);
                
$percent_hp = array('min' => 60'max' => 100);
            
            }
            else
            {
            
                
$percent_par = array('min' => 30'max' => 40);
                
$percent_hp = array('min' => 50'max' => 60);
            
            }
            
            
$players[$id] = array(
                
'id' => $id,
                
'life' => true,
                
'name' => $this -> generateNameBot(),
                
'str'  => rand( ((int)(($params['str'] / 100) * $percent_par['min'])) , ((int)(($params['str'] / 100) * $percent_par['max'])) ),
                
'def'  => rand( ((int)(($params['def'] / 100) * $percent_par['min'])) , ((int)(($params['def'] / 100) * $percent_par['max'])) ),
                
'agi'  => rand( ((int)(($params['agi'] / 100) * $percent_par['min'])) , ((int)(($params['agi'] / 100) * $percent_par['max'])) ),
                
'other_hp' => rand( ((int)(($params['hp'] / 100) * $percent_hp['min'])) , ((int)(($params['hp'] / 100) * $percent_hp['max'])) ),
                
'bot'    => true,
                
'microtime'     => microtime(),
                
'life'    => true
            
);
            
            
$players[$id]['battle_hp'] = $players[$id]['other_hp'];
        
        }
        
        public function 
generateTarget($id false) {
        
            
$tId = ($id) ? $id $this -> uid;
            
            if (@
$this -> fight['target'][$tId] AND !is_null($this -> fight['target'][$tId])) {
            
                return 
$this -> fight['target'][$tId];
            
            }
            else
            {
            
                
$players $this -> fight['life'];
                
                unset(
$players[$tId]);
                
                
$rand array_rand($players);
                
$this -> fight['target'][$tId] = $rand;
                
                return 
$this -> fight['target'][$tId];
            
            }
        
        }
        
        public function 
targetRefresh($myId false) {
        
            
$id = ($myId) ? $myId $this -> uid;
            
$players $this -> fight['life'];
            
            unset(
$players[$id]);
            
            
$rand array_rand($players);
            
$this -> fight['target'][$id] = $rand;
        
        }
        
        public function 
opponent($myId false) {
        
            
$id = (!$myId) ? $this -> uid $myId;
            
$targetId $this -> generateTarget($id);
            
            if (!isset(
$this -> fight['target'][$id]) OR is_null($this -> fight['target'][$id])) {
            
                
$this -> fight['target'][$id] = $targetId;
            
            }
            
            if (!isset(
$this -> fight['life'][$targetId]) OR !$this -> fight['life'][$targetId]) {
            
                
$targetId $this -> targetRefresh($id);
                
$this -> fight['target'][$id] = $targetId;
            
            }
            
            return @
$this -> fight['life'][$targetId];
        
        }
        
        public function 
getMyParams($life false) {
        
            if (
$this -> fight) {
            
                if (@
$this -> fight['life'][$this -> uid]) {
                
                    return 
$this -> fight['life'][$this -> uid];
                
                }
                else if (
$life) {
                
                    return 
$this -> fight['dead'][$this -> uid];
                
                }
            
            }
            
            return 
false;
        
        }
        
        public function 
countFightPlayers() {
        
            return 
count($this -> fight['life']);
        
        }
        
        public function 
fightTime() {
        
            return 
$this -> fight['time'];
        
        }
        
        public function 
autoFightBot() {
        
            
$count $this -> countFightPlayers();
        
            if (
$count 1) {
            
                foreach(
$this -> fight['life'] as $bId => $players) {
                
                    if (
$players['bot'] == TRUE) {
                    
                        
$explode_mctime explode(' '$players['microtime']);
                        
                        if (
$explode_mctime[1] < (time() - 3)) {
                        
                            
$countAttack = (int) ((time() - $explode_mctime[1]) / rand(4,5));
                            
                            for(
$attack 1$attack <= $countAttack$attack ++) {
                            
                                
$rMtime = ($attack == $countAttack) ? true false;
                                
$this -> fight $this -> attack($bId$rMtime);
                            
                            }
                        
                        }
                    
                    }
                
                }
            
            }
        
        }
        
        public function 
uvorot() {
        
            if (
$this -> fight['life'][$this -> uid]['uvorot'] < time() AND isset($this->fight['life'][$this->uid])) {
            
                
$this -> fight['life'][$this -> uid]['uvorot'] = time() + 20;
                
                foreach(
$this -> fight['target'] as $key => $value) {
                
                    if (
$value == $this -> uid) {
                    
                        
$this -> fight['target'][$key] = null;
                    
                    }
                
                }
            
            }
        
        }
        
        public function 
nast() {
        
            if (
$this -> fight['life'][$this -> uid]['nastroyka'] < time() AND isset($this->fight['life'][$this->uid])) {
            
                
$this -> fight['life'][$this -> uid]['nastroyka'] = time() + 60;
                
$this -> fight['life'][$this -> uid]['battle_hp'] = $this -> fight['life'][$this -> uid]['other_hp'];
            
            }
        
        }

        public function 
akmuo() {
        
            if (
$this -> fight['life'][$this -> uid]['akmuo_time'] < time() AND isset($this->fight['life'][$this->uid])) {
            
                
$this -> fight['life'][$this -> uid]['akmuo_time'] = time() + 60;
                
$this -> addJournal('<span class="bold yellow">[tu_aktyvavai_akmeni*]</span>'$this -> uid);
                
                
mysql_query("UPDATE `vartotojai` SET akmuo = akmuo-1 WHERE `id` = ".$this -> uid." LIMIT 1");
                
                return 
true;
            
            }
            
            return 
false;
        
        }
        
        public function 
zole() {
        
            if (
$this -> fight['life'][$this -> uid]['zole_time'] < time() AND isset($this->fight['life'][$this->uid])) {
            
                
$this -> fight['life'][$this -> uid]['zole_time'] = time() + 60;
                
$this -> addJournal('<span class="bold yellow">[tu_aktyvavai_zole*]</span>'$this -> uid);
                
                
mysql_query("UPDATE `vartotojai` SET zole = zole-1 WHERE `id` = ".$this -> uid." LIMIT 1");
                
                return 
true;
            
            }

            return 
false;
        
        }
        
        public function 
rewardStar($dead) {
        
            if (
$dead == 5) {
            
                return -
1;
            
            }
            
            if (
$dead == 4) {
            
                return -
0.5;
            
            }
            
            if (
$dead == 3) {
            
                return 
0;
            
            }
            
            if (
$dead == 2) {
            
                return 
0.5;
            
            }
            
            if (
$dead == 1) {
            
                return 
1;
            
            }
        
        }
        
        public function 
rewardStar2($dead) {
        
            if (
$dead == 5) {
            
                return 
"- 1<img src="img/coliseum/stars/1.png" alt="*"/>";
            
            }
            
            if (
$dead == 4) {
            
                return 
"- &#189;<img src="img/coliseum/stars/0.5.png" alt="*"/>";
            
            }
            
            if (
$dead == 3) {
            
                return 
"+ 0<img src="img/coliseum/stars/0.png" alt="*"/>";
            
            }
            
            if (
$dead == 2) {
            
                return 
"+ &#189;<img src="img/coliseum/stars/0.5.png" alt="*"/>";
            
            }
            
            if (
$dead == 1) {
            
                return 
"+ 1<img src="img/coliseum/stars/1.png" alt="*"/>";
            
            }
        
        }
        
        public function 
rewardExp($dead$level 1) {
        
            if (
$dead == 1) {
            
                return 
25 $level;
            
            }
            
            if (
$dead == 2) {
            
                return 
20 $level;
            
            }
            
            if (
$dead == 3) {
            
                return 
15 $level;
            
            }
            
            if (
$dead == 4) {
            
                return 
10 $level;
            
            }
            
            if (
$dead == 5) {
            
                return 
$level;
            
            }
        
        }

        public function 
rewardSilver($dead$level 1) {
        
            if (
$dead == 1) {
            
                return 
100 $level;
            
            }
            
            if (
$dead == 2) {
            
                return 
80 $level;
            
            }
            
            if (
$dead == 3) {
            
                return 
60 $level;
            
            }
            
            if (
$dead == 4) {
            
                return 
40 $level;
            
            }
            
            if (
$dead == 5) {
            
                return 
20 $level;
            
            }
        
        }

        public function 
finalFight() {
        
            if (
$this -> fight) {
            
                
$countPlayers $this -> countFightPlayers();
                
                if (
$countPlayers <= OR $this -> fight['time'] <= time()) {
                
                    
$result = array();
                    
                    if (
$countPlayers <= 1) {
                    
                        
$players $this -> fight['life'] + $this -> fight['dead'];
                        
                        foreach(
$players as $pId => $gamer) {
                        
                            
$dead = ((@$gamer['dead']) ? $gamer['dead'] : 1);
                            
$_exp $this -> rewardExp(((@$gamer['dead']) ? $gamer['dead'] : 1), (($gamer['bot'] == false) ? $gamer['level'] : 1));
                            
                            if (
$gamer['bot'] == false) {
                            
                                
$db_user mysql_fetch_assoc(mysql_query("SELECT premium,effect1,effect2,effect3 FROM vartotojai WHERE id='$pId' LIMIT 1"));
                                
$clan_memb mysql_fetch_assoc(mysql_query("SELECT * FROM clan_memb WHERE user = '$pId'"));
                                
                                if (
$clan_memb) {
                                
                                    if (
$clan_memb['v'] > 0) {
                                    
                                        
$_exp += round($_exp 100 $clan_memb['v']);
                                    
                                    }
                                    
                                    
$clan mysql_fetch_assoc(mysql_query('SELECT * FROM clans WHERE id = "'.$clan_memb['clan'].'"'));
                                
                                }
                                
                                if (
$db_user['premium'] > time()) {
                                
                                    
$_exp += round($_exp 100 25);
                                
                                }
                                
                                if (
$db_user['effect1'] > time()) {
                                
                                    
$_exp += round($_exp 100 25);
                                
                                }
                                
                                if (
$db_user['effect2'] > time()) {
                                
                                    
$_exp += round($_exp 100 25);
                                
                                }
                                
                                if (
$db_user['effect3'] > time()) {
                                
                                    
$_exp += round($_exp 100 25);
                                
                                }
                                
                                if (
$clan) {
                                
                                    
mysql_query('UPDATE `clans`     SET `exp` = `exp` + '.$_exp.' WHERE `id` = "'.$clan['id'].'"');
                                    
mysql_query('UPDATE `clan_memb` SET `exp` = `exp` + '.$_exp.' WHERE `clan` = "'.$clan['id'].'" AND `user` = "'.$pId.'"');
                                
                                }
                            
                            }
                            
                            
$result[$dead] = array(
                                
'id'     => $pId,
                                
'exp'    => $_exp,
                                
'silver' => $this -> rewardSilver(((@$gamer['dead']) ? $gamer['dead'] : 1), (($gamer['bot'] == false) ? $gamer['level'] : 1)),
                                
'dead'   => ((@$gamer['dead']) ? $gamer['dead'] : 1),
                                
'star'     => $this -> rewardStar(((@$gamer['dead']) ? $gamer['dead'] : 1)),
                                
'star2'     => $this -> rewardStar2(((@$gamer['dead']) ? $gamer['dead'] : 1)),
                                
'bot'     => $gamer['bot']
                            );
                        
                        }
                    
                    }
                    else if (
$this -> fight['time'] <= time()) {
                    
                        
$dead 1;
                        
                        
arsort($this -> fight['damage']);
                        
                        foreach(
$this -> fight['damage'] as $pId => $damage) {
                        
                            
$gamer = @$this -> fight['life'][$pId];
                            
                            if (!
$gamer) {
                            
                                
$gamer = @$this -> fight['dead'][$pId];
                            
                            }
                            
                            if (
$gamer) {
                            
                                
$_exp $this -> rewardExp($dead, (($gamer['bot'] == false) ? $gamer['level'] : 1));
                                
                                if (
$gamer['bot'] == false) {
                                
                                    
$db_user mysql_fetch_assoc(mysql_query("SELECT premium,effect1,effect2,effect3 FROM vartotojai WHERE id='$pId' LIMIT 1"));
                                    
$clan_memb mysql_fetch_assoc(mysql_query("SELECT * FROM clan_memb WHERE user = '$pId'"));
                                    
                                    if (
$clan_memb) {
                                    
                                        if (
$clan_memb['v'] > 0) {
                                        
                                            
$_exp += round($_exp 100 $clan_memb['v']);
                                        
                                        }
                                        
                                        
$clan mysql_fetch_assoc(mysql_query('SELECT * FROM clans WHERE id = "'.$clan_memb['clan'].'"'));
                                    
                                    }
                                    
                                    if (
$db_user['premium'] > time()) {
                                    
                                        
$_exp += round($_exp 100 25);
                                    
                                    }
                                    
                                    if (
$db_user['effect1'] > time()) {
                                    
                                        
$_exp += round($_exp 100 25);
                                    
                                    }
                                    
                                    if (
$db_user['effect2'] > time()) {
                                    
                                        
$_exp += round($_exp 100 25);
                                    
                                    }
                                    
                                    if (
$db_user['effect3'] > time()) {
                                    
                                        
$_exp += round($_exp 100 25);
                                    
                                    }
                                    
                                    if (
$clan) {
                                    
                                        
mysql_query('UPDATE `clans`     SET `exp` = `exp` + '.$_exp.' WHERE `id` = "'.$clan['id'].'"');
                                        
mysql_query('UPDATE `clan_memb` SET `exp` = `exp` + '.$_exp.' WHERE `clan` = "'.$clan['id'].'" AND `user` = "'.$pId.'"');
                                    
                                    }
                                
                                }
                                
                                
$result[$dead] = array(
                                    
'id'     => $pId,
                                    
'exp'    => $_exp,
                                    
'silver' => $this -> rewardSilver($dead, (($gamer['bot'] == false) ? $gamer['level'] : 1)),
                                    
'dead'   => $dead,
                                    
'star'     => $this -> rewardStar($dead),
                                    
'star2'     => $this -> rewardStar2($dead),
                                    
'bot'     => $gamer['bot']
                                );
                                
                                
$dead ++;
                            
                            }
                        
                        }
                    
                    }
                    
                    foreach(
$result as $pId => $value) {
                    
                        if (
$value['bot'] == false) {
                        
                            
$data $this -> dataId($value['id']);
                            
                            
$gold = ($value['dead'] == 1) ? 0;
                            
$gold = ($data['rang'] == AND $data['star'] >= 7) ? $gold;
                            
                            
mysql_query("UPDATE `".self::TABLE."` SET playGame = playGame+1, star = star+".$value['star']." WHERE `uid` = ".$value['id']." LIMIT 1");
                            
mysql_query("UPDATE vartotojai SET g = g+".$gold.",s = s+".$value['silver'].", exp = exp+".$value['exp']."  WHERE id = ".$value['id']." LIMIT 1");
                            
                            
$this -> clearData($value['id']);
                        
                        }
                    
                    }
                    
                    
$this -> fight['type'] = 'result';
                    
$this -> fight['result'] = $result;
                    
                    return 
true;
                
                }
            
            }
            
            return 
false;
        
        }
        
        public function 
getResult() {
        
            return 
$this -> fight['result'];
        
        }
        
        public function 
getPlayers() {
        
            return 
$this -> fight['life'] + $this -> fight['dead'];
        
        }
        
        public function 
attack($myId false$rMctime false) {
        
            
$id = ($myId) ? $myId $this -> uid;
            
$us = @$this -> fight['life'][$id];
            
$opponent = @$this -> opponent($id);
            
            if (
$us AND $opponent) {
            
                
$zenklas = @zenklas($us['statusas']);
                
                if (
$us['bot'] == false) {
                
                    
$mSkills skills($us['ability_1'],$us['ability_2'],$us['ability_3'],$us['ability_4'],$us['ability_5']);
                
                }
                else
                {
                
                    
$mSkills = array();
                
                }
                
                if (
$opponent['bot'] == false) {
                
                    
$oSkills skills($opponent['ability_1'],$opponent['ability_2'],$opponent['ability_3'],$opponent['ability_4'],$opponent['ability_5']);
                
                }
                else
                {
                
                    
$oSkills = array();
                
                }
                
                
$this -> fight['life'][$us['id']]['my_user_add_hp'] = 0;
                
$usr_params = array('str' => $us['str'], 'agi' => $us['agi'], 'def' => $us['def'], 'akmuo_time' => @$us['akmuo_time']);
                
$opponent_params = array('def' => $opponent['def'], 'zole_time' => @$opponent['zole_time'], 'skills' => array(=> @$oSkills[2], => @$oSkills[4]));
                
$info genUron(2$us['microtime'], $usr_params$opponent_params$mSkills);
                
$log_crit $info[1];
                
                
$zenklas2 = @zenklas($opponent['statusas']);
                
                if (
count($mSkills) > 0) {
                
                    
$this -> fight['life'][$us['id']]['skills'] = array();
                    
                    if (
$mSkills[1]['active'] == true) {
                    
                        
$this -> addJournal('<span class="small yellow">[tu_panaudojai*] <img src='img/items/quality/'.$us['ability_1_quality'].'.png'> <span class='quality-'.$us['ability_1_quality'].''>[titano_ituzis*]</span>.</span>'$us['id']);
                        
$this -> fight['life'][$us['id']]['skills'][1] = $this -> fight['life'][$us['id']]['ability_1_quality'];
                    
                    }
                    
                    if (
$mSkills[3]['active'] == true && $log_crit == true) {
                    
                        
$this -> addJournal('<span class="small yellow">[tu_panaudojai*] <img src='img/items/quality/'.$us['ability_3_quality'].'.png'> <span class='quality-'.$us['ability_3_quality'].''>[kritu_viesulas*]</span>.</span>'$us['id']);
                        
$this -> fight['life'][$us['id']]['skills'][3] = $this -> fight['life'][$us['id']]['ability_3_quality'];
                    
                    }
                    
                    if (
$mSkills[5]['active'] == true && $info[0] > 0) {
                    
                        
$kiek round(($this -> fight['life'][$opponent['id']]['battle_hp'] / 100) * $mSkills[5]['bonus']);
                        
$this -> fight['life'][$us['id']]['battle_hp'] = $this -> fight['life'][$us['id']]['battle_hp'] + $kiek;
                        
                        if (
$this -> fight['life'][$us['id']]['battle_hp'] > $this -> fight['life'][$us['id']]['other_hp']) {
                        
                            
$this -> fight['life'][$us['id']]['battle_hp'] = $this -> fight['life'][$us['id']]['other_hp'];
                            
$kiek $this -> fight['life'][$us['id']]['other_hp'] - $this -> fight['life'][$us['id']]['battle_hp'];
                        
                        }
                        
                        
$this -> fight['life'][$opponent['id']]['battle_hp'] = $this -> fight['life'][$opponent['id']]['battle_hp'] - $kiek;
                        
$this -> fight['life'][$us['id']]['my_user_add_hp'] = $kiek;
                        
                        
$this -> addJournal('<span class="small yellow">[tu_panaudojai*] <img src='img/items/quality/'.$us['ability_5_quality'].'.png'> <span class='quality-'.$us['ability_5_quality'].''>[vampyrizmas*]</span>.</span>'$us['id']);
                        
$this -> fight['life'][$us['id']]['skills'][5] = $this -> fight['life'][$us['id']]['ability_5_quality'];
                    
                    }
                
                }
                
                if (
count($oSkills) > 0) {
                
                    if (
$oSkills[2]['active'] == true) {
                    
                        
$this -> addJournal('<span class="small yellow"><span class="lime">'.$zenklas2.''.$opponent['name'].'</span> [panaudojo*] <img src='img/items/quality/'.$opponent['ability_2_quality'].'.png'> <span class='quality-'.$opponent['ability_2_quality'].''>[galinga_gynyba*]</span>.</span>'$us['id']);
                    
                    }
                    
                    if (
$oSkills[4]['active'] == true && $log_crit == true) {
                    
                        
$this -> addJournal('<span class="small yellow"><span class="lime">'.$zenklas2.''.$opponent['name'].'</span> [panaudojo*] <img src='img/items/quality/'.$opponent['ability_4_quality'].'.png'> <span class='quality-'.$opponent['ability_4_quality'].''>[apsaugine_stovesena*]</span>.</span>'$us['id']);
                    
                    }
                
                }
                
                if (
$info[0] > $this -> fight['life'][$opponent['id']]['battle_hp']) {
                
                    
$info[0] = $this -> fight['life'][$opponent['id']]['battle_hp'];
                
                }
                
                
$this -> addJournal('<span class="small yellow">[tu_smogei*] <span class="lime"><img src="img/icons/player.png" alt="*"/> '.$zenklas2.''.$opponent['name'].'</span> [su*] <span class="bold">'.$info[0].'</span> [zala*]'.(($info[1]) ? ' [krit*].' '.').'</span>'$us['id']);
                
$this -> addJournal('<span class="small yellow"><span class="lime"><img src="img/icons/player.png" alt="*"/> '.$zenklas.''.$us['name'].'</span> [smoge_tau*] [su*] <span class="bold">'.$info[0].'</span> [zala*]'.(($info[1]) ? ' [krit*].' '.').'</span>'$opponent['id']);
                
                
$this -> fight['life'][$opponent['id']]['battle_hp'] -= $info[0];
                
$this -> fight['life'][$opponent['id']]['uron'] = $info[0];
                
                if (
$rMctime) {
                
                    
$this -> fight['life'][$us['id']]['microtime'] = microtime();
                
                }
                
                
$this -> fight['damage'][$us['id']] = @$this -> fight['damage'][$us['id']] + $info[0];
                
                if (
$this -> fight['life'][$opponent['id']]['battle_hp'] <= 0) {
                
                    foreach(
$this->fight['journal'] as $key => $value) {
                    
                        if (
$key == $us['id']) {
                        
                            
$this -> addJournal('<span class="small yellow">[tu_nuzudei*] <span class="lime"><img src="img/icons/player.png" alt="*"/> '.$zenklas2.''.$opponent['name'].'</span>.</span>'$key);
                        
                        }
                        elseif (
$key == $opponent['id']) {
                        
                            
$this -> addJournal('<span class="small yellow"><span class="lime"><img src="img/icons/player.png" alt="*"/> '.$zenklas.''.$us['name'].'</span> [nuzude_tave*]</span>'$key);
                        
                        }
                        else
                        {
                        
                            
$this -> addJournal('<span class="small yellow"><span class="lime"><img src="img/icons/player.png" alt="*"/> '.$zenklas.''.$us['name'].'</span> [nuzude*] <span class="lime"><img src="img/icons/player.png" alt="*"/> '.$zenklas2.''.$opponent['name'].'</span>.</span>'$key);
                        
                        }
                    
                    }
                    
                    
$this -> fight['dead'][$opponent['id']] = $this -> fight['life'][$opponent['id']];
                    
$this -> fight['dead'][$opponent['id']]['life'] = false;
                    
$this -> fight['dead'][$opponent['id']]['dead'] = $this -> countFightPlayers();
                    
$this -> fight['target'][$us['id']] = null
                    
                    unset(
$this -> fight['life'][$opponent['id']]);
                
                }
            
            }

            return 
$this -> fight;
        
        }
        
        public function 
addJournal($journal$id false) {
        
            
$jId = ($id) ? $id $this -> uid;
            
            if (isset(
$this -> fight['journal'][$jId])) {
            
                
array_unshift($this -> fight['journal'][$jId], $journal);
                
                if (
count($this -> fight['journal'][$jId]) > 15) {
                
                    for(
$i 16$i count($this -> fight['journal'][$jId]); $i ++) {
                    
                        unset(
$this -> fight['journal'][$jId][$i]);
                    
                    }
                
                }
            
            }
        
        }
        
        public function 
getJournal($id false) {
        
            
$jId = ($id) ? $id $this -> uid;
            
            return 
$this -> fight['journal'][$jId];
        
        }
        
        public function 
getUron($id false) {
        
            
$uId = ($id) ? $id $this -> uid;
            
            if (isset(
$this -> fight['life'][$uId]['uron'])) {
            
                return 
$this -> fight['life'][$uId]['uron'];
            
            }
            else
            {
            
                return 
0;
            
            }
        
        }
        
        public function 
clearUron($id false) {
        
            
$uId = ($id) ? $id $this -> uid;
            
            if (@
$this -> fight['life'][$uId]) {
            
                
$this -> fight['life'][$uId]['uron'] = 0;
            
            }
        
        }
        
        public function 
c_journal(array $journal) {
        
            global 
$language;
            
            foreach(
$journal as $value) {
            
                
$value str_replace('[kova_prasidejo*]',$language['kova_prasidejo'],$value);
                
$value str_replace('[tu_aktyvavai_akmeni*]',$language['tu_aktyvavai_akmeni'],$value);
                
$value str_replace('[tu_aktyvavai_zole*]',$language['tu_aktyvavai_zole'],$value);
                
$value str_replace('[tu_panaudojai*]',$language['tu_panaudojai'],$value);
                
$value str_replace('[titano_ituzis*]',$language['titano_ituzis'],$value);
                
$value str_replace('[galinga_gynyba*]',$language['galinga_gynyba'],$value);
                
$value str_replace('[kritu_viesulas*]',$language['kritu_viesulas'],$value);
                
$value str_replace('[apsaugine_stovesena*]',$language['apsaugine_stovesena'],$value);
                
$value str_replace('[vampyrizmas*]',$language['vampyrizmas'],$value);
                
$value str_replace('[tu_smogei*]',$language['tu_smogei'],$value);
                
$value str_replace('[su*]',$language['su'],$value);
                
$value str_replace('[zala*]',$language['zala'],$value);
                
$value str_replace('[krit*]',$language['krit'],$value);
                
$value str_replace('[smoge_tau*]',$language['smoge_tau'],$value);
                
$value str_replace('[tu_nuzudei*]',$language['tu_nuzudei'],$value);
                
$value str_replace('[nuzude_tave*]',$language['nuzude_tave'],$value);
                
$value str_replace('[nuzude*]',$language['nuzude'],$value);
                
$value str_replace('[panaudojo*]',$language['panaudojo'],$value);
                
                echo 
$value."<br/>";
            
            }
        
        }
        
        public function 
getRatings() {
        
            
$key 'coliseum.ratings';
            
$ratings readcache($key);
            
            if (!
$ratings) {
            
                
$ratings $this -> setRatings();
            
            }
            
            return 
$ratings;
        
        }
        
        public function 
setRatings() {
        
            
$ratings = array();
            
            for(
$rang 1$rang <= 20$rang ++) {
            
                
$query mysql_query("SELECT `uid` FROM `coliseum` WHERE `rang` = ".$rang." ORDER BY `star` DESC");
                
$i 1;
                
                while(
$assoc mysql_fetch_assoc($query)) {
                
                    
$ratings[$rang][$i] = $assoc['uid'];
                    
                    
$i ++;
                
                }
            
            }
            
            
writecache('coliseum.ratings'$ratings);
            
            return 
$ratings;
        
        }
    
    }

?>
Онлайн: 0
Реклама