public function __construct($deck = null) { if (is_string($deck)) { $reg_comment = '/^\\s*\\/\\/(.*)/'; $reg_empty = "/^\\s*\n\$/"; $reg_side = '/^SB:(.*)$/'; $reg_card_mwd = '/(\\d+)\\s*\\[(.*)\\]\\s*(.+)$/'; $reg_card_apr = '/(\\d+)\\s*(.+)$/'; $lines = explode("\n", $deck); // Cut file content in lines $notfound = 0; foreach ($lines as $value) { // Parse lines one by one // Not a card line if (preg_match($reg_comment, $value, $matches)) { // Comment line continue; } if (preg_match($reg_empty, $value, $matches)) { // Empty line continue; } // Sideboard if ($side = preg_match($reg_side, $value, $matches)) { $value = $matches[1]; } // Search $card = null; if (preg_match($reg_card_mwd, $value, $matches)) { // MWS list($line, $nb, $ext, $name) = $matches; $card = Card::get(trim($name), $ext); } else { if (preg_match($reg_card_apr, $value, $matches)) { // Aprentice list($line, $nb, $name) = $matches; $card = Card::get(trim($name)); } } // (not) Found if ($card == null) { if (++$notfound > 3) { echo "Too many cards not found, deck parsing canceled\n"; return false; } } else { if ($notfound > 0) { $notfound--; } for ($i = 0; $i < $nb; $i++) { if ($side) { $this->side[] = $card; } else { $this->main[] = $card; } } } } } }
public function get_content($content) { global $db_cards; $this->fullcontent = array(); foreach ($content as $card) { $this->fullcontent[] = Card::get($card->name, $card->ext, property_exists($card, 'nb') ? $card->nb : 0); } $this->summarize(); }
private function get_cards() { // Import card list from DB and dispatch by rarity/transformability if (count($this->cards) > 0) { return false; } if ($this->get_data('all', false)) { $this->cards = Card::$cache; $this->cards_rarity['C'] = $this->cards; //$cards = $db_cards->select("SELECT `card`.`name` FROM `card` ORDER BY `card`.`id` ASC") ; } else { echo 'Cache not fill'; global $db_cards; $cards = $db_cards->select("SELECT `card`.`name`\n\t\t\tFROM `card_ext`, `card`\n\t\t\tWHERE\n\t\t\t\t`card_ext`.`card` = `card`.`id` AND\n\t\t\t\t`card_ext`.`ext` = {$this->id}\n\t\t\tORDER BY `card`.`id` ASC"); foreach ($cards as $card) { $this->add_card(Card::get($card->name, $this->se)); } } }
protected function recieve($user, $data) { switch ($data->type) { case 'recieve': $user->game->recieveAction($data->id); break; case 'mojosto': switch ($user->player_id) { case $user->game->creator_id: $zone = 'game.creator.battlefield'; break; case $user->game->joiner_id: $zone = 'game.joiner.battlefield'; break; default: die('Player not creator nor joiner'); } $param = json_decode($data->param); $target = isset($param->target) ? $param->target : null; $cards = mojosto($param->avatar, $param->cc); if (count($cards) == 0) { $user->sendString('{"type": "msg", "sender": "", "param": {"text": "' . $param->avatar . ' can\'t cast anything with cc=' . $param->cc . '"}}'); } else { foreach ($cards as $card) { $card->zone = $zone; if ($param->avatar == 'stonehewer' && $target != null) { $card->target = $target; } $action = $user->game->addAction($user->player_id, 'mojosto', json_encode($card)); $this->broadcast(json_encode($action), $user->game); } } break; case 'focus': case 'blur': $user->focused = $data->type == 'focus'; $data->sender = $user->player_id; $this->broadcast(json_encode($data), $user->game, $user); break; case 'land': $param = json_decode($data->param); $land = Card::get($param->name); if ($user->game->isCreator($user->player_id)) { $zone = 'game.creator.library'; } else { if ($user->game->isJoiner($user->player_id)) { $zone = 'game.joiner.library'; } else { $this->observer->say('Land : nor creator nor joiner'); return false; } } $land->zone = $zone; $action = $user->game->addAction($user->player_id, 'card', json_encode($land)); $this->broadcast(json_encode($action), $user->game); break; default: $action = $user->game->addAction($user->player_id, $data->type, $data->param, $data->local_index); if ($action == null) { $user->sendString('{"type": "msg", "sender": "", "param": {"text": "You can\'t send ' . $data->type . '"}}'); } else { // Send back to sender if containing a callback ID if (isset($data->callback)) { $action->callback = $data->callback; } $this->broadcast(json_encode($action), $user->game, isset($action->callback) ? null : $user); } } }
public function add($name, $nb) { for ($i = 0; $i < $nb; $i++) { $card = Card::get($name); if ($card != null) { $this->deck_obj->main[] = $card; } } $this->summarize(); }