Esempio n. 1
0
 function set_macros()
 {
     global $config, $request;
     $i = 1;
     while ($name = $request->variable('macroName_' . $i, '')) {
         $def = $request->variable('macroDef_' . $i, '');
         // $request->variable() is being 'helpful'
         $def = html_entity_decode($def);
         $dice = new \hanelyp\fancydice\fancydice(false);
         $res = $dice->roll($def);
         //echo "$name => $def<br />";
         if (!$dice) {
             trigger_error($user->lang('ACP_FANCYDICE_DEF_ERROR') . $name . '=>' . $def . adm_back_link($this->u_action));
         }
         //echo json_encode(array($name=>$def),JSON_HEX_TAG),'<br />';
         $config->set('fancyDiceMacro_' . $i, json_encode(array($name => $def), 0));
         //$config->set('fancyDiceMacro_'.$i, $name.':'.$def);
         $i++;
     }
 }
Esempio n. 2
0
<?php

require "fancydice.php";
// macro 'd' to implement common dice notation
$macros = array('d' => '@[1_>]', 'p' => '@["*", "**", "***", "****", "*****","******"]', 'ef' => '@["⚫","⚫","⚫","⚫","⚫","⚫","⚫⚫","O","O","O","OO","OO"]', 'ea' => '@[".","ⵜ","ⵜ","ⵜⵜ","⚚","⚚","ⵜ⚚","⚚⚚"]', 'ep' => '@[".","ⵜ","ⵜ","ⵜⵜ","ⵜⵜ","ⵜ⚚","ⵜ⚚","ⵜ⚚","⚚","⚚⚚","⚚⚚","ⴲ"]', 'eb' => '@[".",".","ⵜ","⚚","⚚⚚","ⵜ⚚"]', 'ed' => '@[".","☠","☠","☠","☠☠","☠/","/","⁄⁄"]', 'ec' => '@[".","/","/","//","//","☠/","☠/","☠","☠","☠☠","☠☠","ⵁ"]', 'es' => '@[".",".","☠","☠","/","/"]', 'nbb' => '[0,1]?(1,nb)', 'nb' => '[0,(1,nbb)]', 'coin' => '[0,1]');
/*	$macros = array(
		'sm' => 'smilie [smtag]',
		'next' => '>',
		'smilie' => '"<img src=&quot;./images/smilies/icon_>.gif&quot;&gt;"',
		'smtag' =>	'["e_biggrin","e_sad","evil","lol","cool","e_smile","e_wink","mad","e_geek","mrgreen"]',
	); // */
$fancydice = new hanelyp\fancydice\fancydice($macros, rand());
//$fancydice = new fancydice();
//$fancydice->debug = true;
$tests = array("3D6", "13/3", "10*3-12", '5p', '[1_5]', '["a","b","c"]', 'broken', "1eA 1eP 1eD 1eC 1eB 1eS 4eF", '6@nb', '6>@1');
/*	$tests = array(
		'sm'
	); // */
foreach ($tests as $dice) {
    echo "test {$dice}\n";
    $roll = $fancydice->roll($dice);
    echo join("\t", $roll) . "\n";
    // $roll contains 3 random #s in 1..6
    $total = $fancydice->sum($roll);
    $total = preg_replace(array('#&gt;#', '#&quot;#'), array('>', '"'), $total);
    echo "total => {$total}\n";
}
//echo '"ⵁ ⴲ ⵜ /⁄⁄ ☠ ⚚"';
Esempio n. 3
0
 public function bb_replace_dice($spec, $seed, $secure)
 {
     //return
     //debug_print_backtrace(0,2);
     $securesplit = explode('_', $secure);
     //echo "$spec - $seed - $secure - ".$this->validate($seed, $spec, $securesplit[1])."<br />";
     // validate seed against secure
     $validate = $this->validate($seed, $spec, $securesplit[1]);
     //$spec);
     $valid = $validate == $secure ? '' : $this->user->lang('FANCYDICE_FIDDLED');
     //' invalid';
     /*		if (strlen($valid) > 0)
     		{
     			echo "$spec - $seed - $secure - $validate<br />";
     			//debug_print_backtrace(0,4);
     			//echo '<br />';
     		} // */
     $dice = new \hanelyp\fancydice\fancydice($this->get_macros(), $seed, $this->user);
     //$dice->debug = true;
     $roll = $dice->roll($spec);
     $total = $dice->sum($roll);
     $roll1 = join(', ', $roll);
     $roll1 = preg_replace(array('#&gt;#', '#&quot;#'), array('>', '"'), $roll1);
     $total = preg_replace(array('#&gt;#', '#&quot;#'), array('>', '"'), $total);
     //return '<div class="dicebox">'.$spec.' => '.join(', ', $roll).' => '.$total.$valid.'</div>';
     $pattern = $this->config['fancyDicePresent'];
     return preg_replace(array('#{spec}#iu', '#{dice}#iu', '#{total}#iu', '#{valid}#iu', '#{sum}#iu', '#{count}#iu'), array($spec, $roll1, $total, $valid, $dice->numsum, $securesplit[1]), $pattern);
     // */
     //return $pattern;
 }