srand(); $msg = "ƒƒ^•ΆŽšFdragon‚c•‚c[]//\d\w()‚ ‚ΖD6‚Ζ3D6‚ΖD6+10‚Ζ3d6+10‚Ζ1+d4‚Ζ6+3d6‚Ζ1+d4+1‚Ζ2+3d6+4‚Ε‚·"; $msg =~ s/\+/@/g; while($msg =~ /(\d*@?\d*d\d+@?\d*)/){ $msg = &dice_roll($msg); } $msg =~ s/@/\+/g; $msg =~ s/‚c‚c‚c/d/g; print $msg."\n"; #print "x= $x , y= $y , z= $z \n , roll= $roll"; sub dice_roll{ local($msg)=@_; local($w,$x,$y,$z,$d,$roll,$tot); $msg =~ /(\d*@?\d*d\d+@?\d*)/; $dcode=$1; $x = $1 if $dcode =~ /(\d+)d/; $x = 1 if $dcode !~ /(\d+)d/; $dcode =~ /d(\d+)/; $y = $1; $z = 0; $z = $1 if $dcode =~ /@(\d+)$/; $w = 0; $w = $1 if $dcode =~ /^(\d+)@[d\d]/; $roll = $dcode." ="; $roll .= " ".$w." @" if $w != 0; $roll .= " \["; $roll =~ s/d/‚c‚c‚c/; $tot = 0; for(1..$x){ $d = int(rand()*$y+1); $roll .= " ".$d if $tot == 0; $roll .= " @ ".$d if $tot != 0; $tot += $d; } $roll .= " \]"; $roll .= " @ ".$z if $z != 0; $tot += $w; $tot += $z; $roll .= " = $tot<\/strong>"; $msg =~ s/(\d*@?\d*d\d+@?\d*)/$roll/; return($msg); }