Ejemplo n.º 1
0
 /**
  * Parse a redesign round
  *
  * @return array
  */
 protected function _parseRound()
 {
     $round = new Default_Model_CombatRound();
     // first find the first attacker
     $this->_source = stristr($this->_source, 'Aanvaller');
     /*
      * Aanvaller Touch [2:193:9] Wapens: 110% Schilden: 90% Pantser: 110%
      * Soort 	L. Gevechtsschip 	Kruiser 	Slagschip 	Interceptor.
      * Aantal 	6.531 	1.139 	457 	315
      * Wapens: 	105 	840 	2.100 	1.470
      * Schilden 	19 	95 	380 	760
      * Romp 	840 	5.670 	12.600 	14.700
      *
      *
      * Verdediger Rambi vernietigd.
      */
     // complicated regex that extracts all info from a fleet slot
     $regex = '.*?(Aanvaller|Verdediger) ([^\\n\\r]*?)(\\s*?\\[([0-9]:[0-9]{1,3}:[0-9]{1,2})\\])?' . '(\\s*?Wapens: ([0-9]{0,2})0% Schilden: ([0-9]{0,2})0% Pantser: ([0-9]{0,2})0%)?\\s*' . '(Soort([A-Za-z.-\\s]*)\\s*' . 'Aantal([0-9.\\s]*).*?Wapens' . '|vernietigd.)\\s*' . '.*?(?=Aanvaller|Verdediger)';
     $foundDefender = false;
     $matches = array();
     // loop trough the text until we have found all fleets in the round
     while (preg_match('#' . $regex . '#si', $this->_source, $matches)) {
         // extract the info
         $fleet = new Default_Model_Fleet();
         $fleet->setPlayer($matches[2]);
         if ($matches[9] != 'vernietigd.') {
             $matches[10] = str_replace(array("\n", "\r", "  "), "\t", $matches[10]);
             $matches[11] = str_replace(array("\n", "\r", "  "), "\t", $matches[11]);
             // add the ships info
             $ships = explode("\t", trim($matches[10]));
             $numbers = explode("\t", trim($matches[11]));
             foreach ($ships as $key => $ship) {
                 $fleet->addShip($this->_createShip($ship, $this->_convertToInt($numbers[$key])));
             }
         }
         // check if it is an attacker or a defender
         if (strtolower($matches[1]) == 'aanvaller') {
             if ($foundDefender) {
                 break;
             }
             $round->addAttackingFleet($fleet);
         } else {
             $round->addDefendingFleet($fleet);
             $foundDefender = true;
         }
         $this->_source = substr($this->_source, strlen($matches[0]));
         // always reset this array at the end
         $matches = array();
     }
     return $round;
 }
Ejemplo n.º 2
0
 /**
  * Parse a redesign round
  *
  * @return array
  */
 protected function _parseRound()
 {
     $round = new Default_Model_CombatRound();
     // first find the first attacker
     $this->_source = stristr($this->_source, $this->_regexes['round_start']);
     /*
      * Aanvaller Touch [2:193:9] Wapens: 110% Schilden: 90% Pantser: 110%
      * Soort 	L. Gevechtsschip 	Kruiser 	Slagschip 	Interceptor.
      * Aantal 	6.531 	1.139 	457 	315
      * Wapens: 	105 	840 	2.100 	1.470
      * Schilden 	19 	95 	380 	760
      * Romp 	840 	5.670 	12.600 	14.700
      *
      *
      * Verdediger Rambi vernietigd.
      */
     // complicated regex that extracts all info from a fleet slot
     $regex = $this->_regexes['round_fleet'];
     $foundDefender = false;
     $matches = array();
     // loop trough the text until we have found all fleets in the round
     while (preg_match('#' . $regex . '#si', $this->_source, $matches)) {
         // extract the info
         $fleet = new Default_Model_Fleet();
         $fleet->setPlayer($matches[2]);
         if ($matches[9] != $this->_regexes['battle_end']) {
             $matches[10] = str_replace(array("\n", "\r", "  "), "\t", $matches[10]);
             $matches[11] = str_replace(array("\n", "\r", "  "), "\t", $matches[11]);
             // add the ships info
             $ships = explode("\t", trim($matches[10]));
             $numbers = explode("\t", trim($matches[11]));
             // Fix wierd error
             if (count($ships) == 1 && strlen($ships[0]) > 30) {
                 $ships = explode(" ", $ships[0]);
                 foreach ($ships as $elem) {
                     if (preg_match('/^[A-Z]\\.$/', $elem)) {
                         $concat = $elem;
                         continue;
                     }
                     $result[] = strtolower($concat . $elem);
                     $concat = '';
                 }
                 $ships = $result;
                 $numbers = explode(" ", $numbers[0]);
             }
             foreach ($ships as $key => $ship) {
                 $fleet->addShip($this->_createShip($ship, $this->_convertToInt($numbers[$key])));
             }
         }
         // check if it is an attacker or a defender
         if (strtolower($matches[1]) == $this->_regexes['attacker']) {
             if ($foundDefender) {
                 break;
             }
             $round->addAttackingFleet($fleet);
         } else {
             $round->addDefendingFleet($fleet);
             $foundDefender = true;
         }
         $this->_source = substr($this->_source, strlen($matches[0]));
         // always reset this array at the end
         $matches = array();
     }
     return $round;
 }