Advertisement
jargon

Roe Web Builder - Stat Sheets 100% OK

Oct 16th, 2021
1,435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.51 KB | None | 0 0
  1. <?php
  2.  
  3. const LONGSTATS = [
  4.  
  5.     'hp' => 'health',
  6.     'str' => 'stamina',
  7.     'ess' => 'essence',
  8.  
  9.         'cur' => 'current',
  10.         'max' => 'maximum',
  11.         'spd' => 'recovery',
  12.  
  13.     'skil' => 'skill',
  14.         'lv' => 'level',
  15.         'exp' => 'experience',
  16.         'valu' => 'appraisal',
  17.  
  18.     'cmbt' => 'combat',
  19.         'pirc' => 'piercing',
  20.         'armr' => 'armored',
  21.         'evad' => 'evasion',
  22.  
  23.     'team' => 'affinity',
  24.         'idty' => 'identity'
  25. ];
  26.  
  27. const CONVERTSTATS = [
  28.    
  29.     'spd' => 'str.spd',
  30.  
  31.     'hp' => 'hp.cur',
  32.     'str' => 'str.cur',
  33.     'ess' => 'ess.cur',
  34.  
  35.     'hpcur' => 'hp.cur',
  36.     'hpspd' => 'hp.spd',
  37.     'hpmax' => 'hp.max',
  38.  
  39.     'strcur' => 'str.cur',
  40.     'strspd' => 'str.spd',
  41.     'strmax' => 'str.max',
  42.    
  43.     'ess' => 'ess.cur',
  44.     'esscur' => 'ess.cur',
  45.     'essspd' => 'ess.spd',
  46.     'essmax' => 'ess.max',
  47.  
  48.     'lv'=>'skil.lv',
  49.     'exp'=>'skil.exp',
  50.     'valu'=>'skil.valu',
  51.  
  52.     'pirc'=>'cmbt.pirc',
  53.     'armr'=>'cmbt.armr',
  54.     'evad'=>'cmbt.evad',
  55.  
  56.     'idty' => 'team.idty'
  57. ];
  58.  
  59.  
  60. $teststats='CASE "plyr"\r\n
  61.   prflidty$ = "Poindexter"\r\n
  62.   prflactn$ = "wstf"\r\n
  63.   prflgpic$ = "plyr"\r\n
  64.   prflidty! = 5\r\n
  65.   prflhp! = 30\r\n
  66.   prflstr! = 90\r\n
  67.   prfless! = 0\r\n
  68.   prflspd! = 3\r\n
  69.   prflarmr! = 2\r\n
  70.   prflexp! = 10\r\n
  71.   prflvalu! = 15\r\n
  72.   prflpirc! = 2\r\n
  73.   prfllv! = 1\r\n
  74.   prflhpmax! = 30\r\n
  75.   prflstrmax! = 90\r\n
  76.   prflessmax! = 30\r\n
  77.   prflessspd! = .1\r\n
  78.   prflevad! = .07\r\n
  79. ';
  80.  
  81. echo '<html><head><title>mk45 CARDS OUT TEST</title></head><body>'.str_replace('\r\n','<br>',htmlentities($teststats)).'<br>'.gen_collectorcard( renderstats( gen_statsheet( $teststats, array() ) ) ).'</body></html>';
  82.  
  83. function longhand_stat(string $longstats):string {
  84.     return LONGSTATS[$longstats] ?? '';
  85. }
  86.  
  87. function convert_stat(string $convertstats):string {
  88.     return CONVERTSTATS[$convertstats] ?? '';
  89. }
  90.  
  91. function default_stats()
  92. {
  93.     return array(
  94.    
  95.         'hp' => array(
  96.             'cur' => floatval( 0 ),
  97.             'max' => floatval( 0 ),
  98.             'spd' => floatval( 0 )
  99.         ),
  100.        
  101.         'str' => array(
  102.             'cur' => floatval( 0 ),
  103.             'max' => floatval( 0 ),
  104.             'spd' => floatval( 0 )
  105.         ),
  106.        
  107.         'ess' => array(
  108.             'cur' => floatval( 0 ),
  109.             'max' => floatval( 0 ),
  110.             'spd' => floatval( 0 )
  111.         ),
  112.  
  113.         'skil' => array(
  114.             'lv' => floatval( 0 ),
  115.             'exp' => floatval( 0 ),
  116.             'valu' => floatval( 0 )
  117.         ),
  118.  
  119.         'cmbt' => array(
  120.             'pirc' => floatval( 0 ),
  121.             'armr' => floatval( 0 ),
  122.             'evad' => floatval( 0 )
  123.         ),
  124.  
  125.         'team' => array(
  126.             'idty' => floatval( 0 )
  127.         )
  128.     );
  129. }
  130.  
  131. function load_stats( $crtn = '____' )
  132. {
  133.     if( !is_file( $_SERVER[ 'DOCUMENT_ROOT' ].  '/Roe Web Builder/cards out data/'. $crtn. '.dat' ) )
  134.     {
  135.         return '';
  136.     }
  137.    
  138.     $page = file_get_contents( $_SERVER[ 'DOCUMENT_ROOT' ].  '/Roe Web Builder/cards out data/'. $crtn. '.dat' );
  139.    
  140.     return $page;
  141. }
  142.  
  143. function gen_statsheet( $page = '', $info = array() )
  144. {
  145.     if( strlen( $page ) === 0)
  146.     {
  147.         $page = load_stats( '____' );
  148.     }
  149.     elseif( strlen( $page ) === 4 )
  150.     {
  151.         $page = load_stats( $page );
  152.     }
  153.    
  154.     $pattern =    '/(?:prfl(?<stat>[a-z]+)!) = (?<value>[\.\d]+)/';
  155.    
  156.     while( preg_match( $pattern, $page, $matches, PREG_UNMATCHED_AS_NULL ) )
  157.     {
  158.         if( isset( $matches[ 'stat' ] ) and isset( $matches[ 'value' ] ) )
  159.         {
  160.             if( !is_null( $matches[ 'stat' ] ) and !is_null( $matches[ 'value' ] ) )
  161.             {
  162.                 $info[ convert_stat( $matches[ 'stat' ] ) ] = floatval( $matches[ 'value' ] );
  163.                 $page = str_replace( $matches[0], '', $page );
  164.             }
  165.         }
  166.     }
  167.    
  168.     return $info;
  169. }
  170.  
  171. function renderstats( $info = array() )
  172. {
  173.     $about = array();
  174.    
  175.     $about = renderminors( $info, $about, array('hp','str','ess'), array('max','spd','cur') );
  176.     $about = renderminors( $info, $about, 'cmbt', array('armr','pirc','evad') );
  177.     $about = renderminors( $info, $about, 'skil', array('lv','valu','exp') );
  178.     $about = renderminors( $info, $about, 'team', array('idty') );
  179.    
  180.     return $about;
  181. }
  182.  
  183. function rendermajors( $info = array(), $about = array(), $major = array(), $minor = array() )
  184. {
  185.  
  186.     $pattern = '/(?<major>'.implode('|',$major).')\.(?<minor>'.implode('|',$minor).')/m';
  187.    
  188.     foreach( $info as $stat => $value )
  189.     {
  190.         if( preg_match( $pattern, $stat, $matches ) )
  191.         {
  192.             if( isset( $matches[ 'major' ] ) and isset( $matches[ 'minor' ] ) )
  193.             {
  194.                 if( !is_null( $matches[ 'major' ] ) and !is_null( $matches[ 'minor' ] ) )
  195.                 {
  196.                     if( strlen( $matches[ 'minor' ] ) === 0 )
  197.                     {
  198.                         $matches[ 'minor' ] = 'cur';
  199.                     }
  200.                     $about[ $matches[ 'major' ] ][ $matches[ 'minor' ] ] = floatval($value);
  201.                 }
  202.             }
  203.         }
  204.     }
  205.  
  206.     return $about;
  207. }
  208.  
  209. function renderminors( $info = array(), $about = array(), $major = '', $minor = array() )
  210. {
  211.     if( is_array( $major ) )
  212.     {
  213.         $about = rendermajors( $info, $about, $major, $minor );
  214.         return $about;
  215.     }
  216.    
  217.     $pattern = '/(?<minor>'.implode('|',$minor).')/m';
  218.  
  219.     foreach( $info as $stat => $value )
  220.     {
  221.         if( preg_match( $pattern, $stat, $matches ) )
  222.         {
  223.             if( isset( $matches[ 'minor' ] ) )
  224.             {
  225.                 if( !is_null( $matches[ 'minor' ]  ) )
  226.                 {
  227.                     $about[ $major ][ $matches[ 'minor' ] ] = floatval($value);
  228.                 }
  229.             }
  230.         }
  231.     }
  232.                
  233.     return $about;
  234. }
  235.  
  236. function gen_collectorcard( $about = array() )
  237. {
  238.     $return = '';
  239.    
  240.     $default = default_stats();
  241.  
  242.     $box = array();
  243.    
  244.     foreach( $default as $major => $intermediate )
  245.     {
  246.         $box[ $major ] = '';
  247.         if( !isset( $about[ $major ] ) )
  248.         {
  249.             $about[ $major ] = $default[ $major ];
  250.         }
  251.  
  252.         $box[$major] .= '<tr><td colspan="2" style="vertical-align:top;text-align:left;">'. longhand_stat( $major ). '</td></tr>';
  253.         foreach( $intermediate as $minor => $value )
  254.         {
  255.             if( !isset( $about[ $major ][ $minor ] ) )
  256.             {
  257.                 $about[ $major ][ $minor ] = floatval( $value );
  258.             }
  259.  
  260.            
  261.             $box[$major] .= '<tr><td colspan="1" style="width:100%;vertical-align:top;text-align:left;">'.  longhand_stat( $minor ). '</td><td colspan="1" style="width:100%;vertical-align:top;text-align:left;">'. floatval( $about[ $major ][ $minor ] ). '</td></tr>';
  262.         }
  263.         $box[$major] = '<table>'. $box[$major]. '</table>';
  264.     }
  265.    
  266.     $return .=
  267.     '<tr><td style="vertical-align:top;text-align:left;">'. $box['hp'].
  268.     '</td><td style="vertical-align:top;text-align:left;">'. $box['str'].
  269.     '</td><td style="vertical-align:top;text-align:left;">'. $box['ess'].
  270.     '</td>'.
  271.     '</tr>'.
  272.     '<tr><td style="vertical-align:top;text-align:left;">'. $box['cmbt'].
  273.     '</td><td style="vertical-align:top;text-align:left;">'. $box['skil'].
  274.     '</td><td style="vertical-align:top;text-align:left;">'. $box['team'].
  275.     '</td>'.
  276.     '</tr>';
  277.     $return = '<table style="vertical-align:top;text-align:left;">'. $return. '</table>';
  278.     return $return;
  279. }
  280.  
  281. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement