예제 #1
0
파일: Event.php 프로젝트: CCOSTREL/ArenaWeb
 public function addEvent($eventType, $nameNewFighter = null)
 {
     App::uses('CakeSession', 'Model/Datasource');
     $idFighter = CakeSession::read('User.fighter');
     $fighterModel = new Fighter();
     $fighter = $fighterModel->findById($idFighter)["Fighter"];
     if ($eventType == "creation") {
         $cooX = $fighterModel->find('first', array("conditions" => array("Fighter.name" => $nameNewFighter)))["Fighter"]["coordinate_x"];
         $cooY = $fighterModel->find('first', array("conditions" => array("Fighter.name" => $nameNewFighter)))["Fighter"]["coordinate_y"];
         $newEvent = array("name" => $nameNewFighter . " : " . $eventType . ".", "date" => date("Y-m-d H:i:s"), "coordinate_x" => $cooX, "coordinate_y" => $cooY);
     } else {
         $newEvent = array("name" => $fighter["name"] . " : " . $eventType . ".", "date" => date("Y-m-d H:i:s"), "coordinate_x" => $fighter["coordinate_x"], "coordinate_y" => $fighter["coordinate_y"]);
     }
     $this->create($newEvent);
     $this->save();
 }
 public function run($args)
 {
     $mongo = new Mongo();
     $collection = $mongo->mma->fighters;
     $cursor = $collection->find()->sort(array("date_import" => 1))->limit(20000);
     foreach ($cursor as $item) {
         $item['date_import'] = time();
         //$collection->update(array('_id' => $item['_id']), $item);
         $fighter = Fighter::model()->findByAttributes(array('sherdog_id' => $item['id']));
         if ($fighter) {
             $fighter->date_update = new CDbExpression('NOW()');
         } else {
             $fighter = new Fighter();
             $fighter->sherdog_id = $item['id'];
         }
         $image = trim($item['image']);
         if ($image && !$fighter->image) {
             $fighter->image = $image;
         }
         $fighter->name = trim($item['name']);
         $fighter->nickname = trim($item['nickname']);
         $fighter->birthdate = trim($item['birthdate']);
         $fighter->city = trim($item['city']);
         $fighter->height = $item['height'] ? number_format($item['height'] * 30.48, 1) : null;
         $fighter->weight = $item['weight'] ? number_format($item['weight'] * 0.45359237, 1) : null;
         $fighter->class = trim($item['class']);
         $fighter->association = trim($item['association']);
         $fighter->wins = trim($item['wins']) ?: 0;
         $fighter->losses = trim($item['losses']) ?: 0;
         $fighter->win_ko = trim($item['win_ko']);
         $fighter->win_submissions = trim($item['win_submissions']);
         $fighter->win_decisions = trim($item['win_decisions']);
         $fighter->loss_ko = trim($item['loss_ko']);
         $fighter->loss_submissions = trim($item['loss_submissions']);
         $fighter->loss_decisions = trim($item['loss_decisions']);
         $is_new = $fighter->isNewRecord;
         if ($fighter->save()) {
             $msg = $is_new ? "Добавлен боец  {$fighter->link}" : "Обновлен боец {$fighter->link}";
             $this->log($msg);
         } else {
             $this->log("Ошибка сохранения: " . $fighter->errors_str);
         }
     }
 }
예제 #3
0
파일: Tool.php 프로젝트: ClMatthey/ArenaWeb
 public function dropTool($toolToDrop)
 {
     App::uses('CakeSession', 'Model/Datasource');
     $idFighterSelected = CakeSession::read('User.fighter')['id'];
     $toolToDrop["fighter_id"] = null;
     $this->save($toolToDrop);
     $fighterModel = new Fighter();
     $currentFighter = $fighterModel->find("first", array("conditions" => array("Fighter.id" => $idFighterSelected)))["Fighter"];
     $toolType = $toolToDrop["type"];
     $toolBonus = $toolToDrop["bonus"];
     if ($toolType == "sightUp") {
         $currentFighter["skill_sight"] -= $toolBonus;
     } elseif ($toolType == "strengthUp") {
         $currentFighter["skill_strength"] -= $toolBonus;
     } elseif ($toolType == "healthUp") {
         $currentFighter["skill_health"] -= $toolBonus;
     }
     $fighterModel->save($currentFighter);
 }
예제 #4
0
 public function findFighterByUrlId($url_id)
 {
     $url = explode('-', $url_id);
     $id = array_pop($url);
     if (!$id) {
         $this->pageNotFound();
     }
     $fighter = Fighter::model()->findByPk($id);
     if (!$fighter || $fighter->url_id != $url_id) {
         $this->pageNotFound();
     }
     return $fighter;
 }
예제 #5
0
파일: test1.php 프로젝트: samiateber/42
 public function __construct()
 {
     parent::__construct("assassin");
 }
예제 #6
0
 public function run()
 {
     $this->log('Начинаем парсить бойцов');
     $letters = range('a', 'z');
     $cache = Yii::app()->cache->get('last_fighter_parse');
     if ($cache) {
         $c = file_get_contents($this->getUrlByLetterAndPage($cache['letter'], $cache['page']));
         $doc = new DOMDocument();
         @$doc->loadHTML($c);
         $xpath = new DOMXPath($doc);
         $next = $xpath->query('//span[@class="pagination"]//a[contains(text(), "Next")]')->item(0);
         if ($next) {
             preg_match('|SearchTxt=([a-z])&page=([0-9]+)|', $next->getAttribute('href'), $data);
             $letter = $data[1];
             $page = $data[2];
         } else {
             $key = array_search($cache['letter'], $letters);
             if (array_key_exists(++$key, $letters)) {
                 $letter = $letters[$key];
                 $page = 1;
             } else {
                 $letter = 'a';
                 $page = 1;
             }
         }
     } else {
         $letter = 'a';
         $page = '1';
     }
     Yii::app()->cache->set('last_fighter_parse', array('letter' => $letter, 'page' => $page));
     $this->log("Парсим буква ({$letter}) страница ({$page})");
     $c = file_get_contents($this->getUrlByLetterAndPage($letter, $page));
     $doc = new DOMDocument();
     @$doc->loadHTML($c);
     $xpath = new DOMXPath($doc);
     $links = $xpath->query('//a[contains(@href, "/fighter/")]');
     $this->log("Найдено страниц: " . count($links));
     foreach ($links as $link) {
         $href = $link->getAttribute('href');
         if (mb_substr($href, 0, 4, 'utf-8') != 'http') {
             $href = 'http://www.sherdog.com' . $href;
             $source_url = $href;
         } else {
             $source_url = str_replace('http://www.sherdog.com', '', $href);
         }
         //$href = 'http://www.sherdog.com/fighter/Fedor-Emelianenko-1500';
         $c = file_get_contents($href);
         $doc = new DOMDocument();
         @$doc->loadHTML($c);
         $xpath = new DOMXPath($doc);
         $name = $this->xpathQuery($xpath, '//span[@class="fn"]');
         if (!$name) {
             $this->log('Не найдено имя бойца. url: ' . $href, CLogger::LEVEL_WARNING);
             continue;
         }
         $nickname = $this->xpathQuery($xpath, '//span[@class="nickname"]');
         if ($nickname) {
             $nickname = trim(str_replace('"', '', $nickname));
         }
         $birthday = $this->xpathQuery($xpath, '//span[@itemprop="birthDate"]');
         $country = $this->xpathQuery($xpath, '//strong[@itemprop="nationality"]');
         $association = $this->xpathQuery($xpath, '//span[@itemprop="name"]');
         $height = $this->xpathQuery($xpath, '//span[@class="item height"]');
         if ($height) {
             preg_match('/([0-9\\.]+) cm/', $height, $height);
             $height = $height[1];
         }
         $weight = $this->xpathQuery($xpath, '//span[@class="item weight"]');
         if ($weight) {
             preg_match('/([0-9\\.]+) kg/', $weight, $weight);
             $weight = $weight[1];
         }
         $image = $xpath->query('//img[@itemprop="image"]')->item(0);
         if ($image) {
             $src = $image->getAttribute('src');
             $image = pathinfo($src, PATHINFO_BASENAME);
             $path = Fighter::getPhotosDir() . $image;
             if (!file_exists($path)) {
                 if (file_put_contents($path, file_get_contents($src))) {
                     chmod($path, 0777);
                 } else {
                     $image = null;
                     $this->log("Не могу сохранить фото бойца");
                 }
             }
         }
         $fighter = Fighter::model()->findByAttributes(array('source_url' => $source_url));
         if (!$fighter) {
             $fighter = new Fighter();
             $fighter->source_name = 'sherdog.com';
             $fighter->source_url = $source_url;
             $fighter->source_path = $letter . $page;
             $this->log("Добавление нового бойца");
         } else {
             $this->log("Обновляем бойца " . $fighter->id);
         }
         $fighter->name = $name;
         $fighter->nickname = $nickname;
         $fighter->birthday = $birthday;
         $fighter->country = $country;
         $fighter->association = $association;
         $fighter->height = $height;
         $fighter->weight = $weight;
         $fighter->image = $image;
         if ($fighter->save()) {
             $this->log("Боец сохранен ID: " . $fighter->id);
         } else {
             $this->log("Ошибка сохранения бойца: " . print_r($fighter->errors_flat_array, 1));
         }
     }
 }
예제 #7
0
 public function __construct($name, $level = 0)
 {
     parent::__construct($name);
     $this->level = $level;
 }
예제 #8
0
파일: test2.php 프로젝트: samiateber/42
 public function __construct()
 {
     parent::__construct("crippled soldier");
 }
예제 #9
0
    if (count($rings) == 0) {
        return;
    }
    $newring = array_shift($rings);
    getRingSets($comb, $rings);
    $comb[] = $newring;
    getRingSets($comb, $rings);
}
foreach ($weapons as $weapon) {
    foreach ($armors as $armor) {
        foreach ($ringsets as $ringset) {
            $players[] = new Player($weapon, $armor, $ringset[0], $ringset[1]);
        }
    }
}
function sortByCost(Player $a, Player $b)
{
    return $b->getCost() - $a->getCost();
}
usort($players, "sortByCost");
//echo count($players);
//var_dump($players);
$boss = new Character(109, 8, 2);
$fighter = new Fighter($boss);
foreach ($players as $player) {
    $fighter->setPlayer($player);
    if (!$fighter->fight()) {
        var_dump($fighter);
        exit;
    }
}
예제 #10
0
 function skillUp($skill, $id)
 {
     parent::check();
     if (self::$allowed) {
         if (strcmp($skill, "health")) {
             $sql = "update fighters set skill_" . $skill . " = skill_" . $skill . "+ 3 where id = " . $id . ";";
             if (parent::$link->query($sql) == FALSE) {
                 echo "Error: " . parent::$link->error;
                 return false;
             }
         } else {
             if (strcmp($skill, "strenght")) {
                 $sql = "update fighters set skill_" . $skill . " = skill_" . $skill . "+1 where id = " . $id . ";";
                 if (parent::$link->query($sql) == FALSE) {
                     echo "Error: " . parent::$link->error;
                     return false;
                 }
             } else {
                 if (strcmp($skill, "sight")) {
                     $sql = "update fighters set skill_" . $skill . " = skill_" . $skill . "+1 where id = " . $id . ";";
                     if (parent::$link->query($sql) == FALSE) {
                         echo "Error: " . parent::$link->error;
                         return false;
                     }
                 }
             }
         }
         self::$allowed = false;
         return true;
     }
     return false;
 }