Exemple #1
0
 public function generate($ext, $upool)
 {
     // Creation by daemon
     // Generate content
     $ext_obj = Extension::get($ext);
     if ($ext_obj == null) {
         $this->tournament->say("Extension {$ext} not found in booster generation");
         return false;
     }
     $this->fullcontent = $ext_obj->booster($upool);
     $this->summarize();
     $this->insert();
 }
Exemple #2
0
 /**
  * Register component
  */
 public function register($base_path)
 {
     if (!file_exists($base_path) && !is_dir($base_path)) {
         throw new ExtensionException(sprintf('path %s not exists', $base_path));
     }
     if (!isset($this->base_path)) {
         $this->base_path = $base_path;
     }
     $this->component = basename($base_path);
     $this->component_name = $this->component;
     $this->registerLanguage();
     $this->registerFiles(['model', 'view', 'controller', 'table'], $base_path);
     $this->registerRoutes();
     $this->includeInitialize();
     if ($this->base_path == $base_path) {
         $pluginArchitecture = Extension::get('plugin');
         $pluginArchitecture->register($this->base_path);
     }
     $hmvc_base_path = $base_path . DIRECTORY_SEPARATOR . 'components';
     if (file_exists($hmvc_base_path) && is_dir($hmvc_base_path)) {
         $this->register($hmvc_base_path);
     }
 }
Exemple #3
0
 public function booster(&$upool)
 {
     $this->get_cards();
     $nb_c = $this->get_data('c', 0);
     $nb_u = $this->get_data('u', 0);
     $nb_r = $this->get_data('r', 0);
     $nb_l = $this->get_data('l', 0);
     $result = array();
     // Booster is generated in reverse order, as foils or transform take a common slot
     // land
     if (array_key_exists('L', $this->cards_rarity)) {
         for ($i = 0; $i < $nb_l; $i++) {
             $this->rand_card($this->cards_rarity['L'], $result, $upool);
         }
     } else {
         $nb_c += $nb_l;
     }
     // foil (break unicity)
     global $proba_foil;
     if ($nb_c > 0 && !$this->get_data('uniq', false) && rand(1, $proba_foil) == 1) {
         $nb_c--;
         $this->rand_card($this->cards, $result, $upool);
     }
     // timeshifted (for TSP)
     if ($nb_c > 0 && $this->get_data('timeshift', false)) {
         $ext = Extension::get('TSB');
         $ext->get_cards();
         if (array_key_exists('S', $ext->cards_rarity)) {
             $nb_c--;
             $this->rand_card($ext->cards_rarity['S'], $result, $upool);
         } else {
             echo "No timeShift found";
         }
     }
     // transformable (for ISD/DKA)
     if ($nb_c > 0 && $this->get_data('transform', false)) {
         $r = '';
         // Transform rarity
         $n = rand(1, 14);
         if ($n > 13) {
             $r = Extension::r_or_m($this->cards_tr);
         } elseif ($n > 10) {
             $r = 'U';
         } else {
             $r = 'C';
         }
         if (array_key_exists($r, $this->cards_tr)) {
             $nb_c--;
             $this->rand_card($this->cards_tr[$r], $result, $upool);
         }
     }
     // rare or mythic
     if (array_key_exists('R', $this->cards_rarity) || array_key_exists('M', $this->cards_rarity)) {
         for ($i = 0; $i < $nb_r; $i++) {
             $this->rand_card($this->cards_rarity[Extension::r_or_m($this->cards_rarity)], $result, $upool);
         }
     } else {
         $nb_c += $nb_r;
     }
     // uncommons
     if (array_key_exists('U', $this->cards_rarity)) {
         for ($i = 0; $i < $nb_u; $i++) {
             $this->rand_card($this->cards_rarity['U'], $result, $upool);
         }
     } else {
         $nb_c += $nb_u;
     }
     // commons (after all other exceptions have been managed)
     if (array_key_exists('C', $this->cards_rarity) && count($this->cards_rarity['C']) >= $nb_c) {
         for ($i = 0; $i < $nb_c; $i++) {
             $this->rand_card($this->cards_rarity['C'], $result, $upool);
         }
     } else {
         if ($nb_c > 0) {
             echo 'Not enough commons leftin ext ' . $ext . " ({$nb_c}/" . count($cards['C']) . ")\n";
         }
     }
     return $result;
 }
 public function begin()
 {
     // Launch first step for tournament (draft, build ...)
     // DB
     shuffle($this->players);
     // Give random numbers to players
     foreach ($this->players as $i => $player) {
         $player->insert($i);
     }
     // And store them now we're sure to start
     // TS3
     if ($this->observer->ts3) {
         ts3_co();
         $cid = ts3_chan('Tournament ' . $this->id, $this->name);
         // Create chan
         ts3_invite($this->players, $cid);
         // Move each tournament's player to chan
         ts3_disco();
     }
     // Unicity
     $upool = array();
     // All cards in current tournament's players pools
     //that comes from a "uniq" extension
     switch ($this->format) {
         case 'draft':
             $number = 0;
             foreach ($this->data->boosters as $ext) {
                 $number++;
                 // Number of current booster in draft for player
                 //$booster = null ;
                 foreach ($this->players as $player) {
                     //if ( ( $booster == null ) || ! $this->data->clone_sealed ) {
                     $booster = new Booster($this, $player->order, $number);
                     $booster->generate($ext, $upool);
                     /*} else {
                     			$boost = new Booster($this, $player->order, $number) ;
                     			$boost->get_content($booster->content) ;
                     			$boost->insert() ;
                     		}*/
                     $this->boosters[] = $booster;
                 }
             }
             $this->set_status(3);
             $this->timer_goon(Tournament::draft_time());
             $this->log('', 'draft', '');
             break;
         case 'sealed':
             foreach ($this->data->boosters as $ext) {
                 $ext_obj = Extension::get($ext);
                 if ($ext_obj == null) {
                     $this->say("Extension {$ext} not found in sealed generation");
                     continue;
                 }
                 $booster = null;
                 foreach ($this->players as $player) {
                     if ($booster == null || !$this->data->clone_sealed) {
                         $booster = $ext_obj->booster($upool);
                     }
                     // Only need object in memory for sealed
                     foreach ($booster as $card) {
                         $player->pick($card);
                     }
                 }
             }
             foreach ($this->players as $player) {
                 $player->summarize(true);
             }
             $this->build();
             break;
         default:
             $this->start();
     }
 }
Exemple #5
0
 static function fill_cache()
 {
     Card::$cache = array();
     global $db_cards;
     $raw = $db_cards->select("SELECT * FROM `card` ORDER BY `id` DESC");
     $links = 0;
     foreach ($raw as $card) {
         $card = new Card($card);
         foreach ($card->extensions as $ext) {
             $links++;
             $extension = Extension::get($ext->se);
             if ($extension == null) {
                 echo "Extension {$ext->se} not found for {$card->name}\n";
             } else {
                 $extension->add_card($card, $ext->rarity);
             }
         }
         Card::$cache[] = $card;
     }
     return $links;
 }