rolldice.php

<? include 'xmlheader.php'?>
<?
echo "<?xml version=\"1.0\" ?>";?>
<root>
<?php
    
include 'include.php';

    
openDatabase();

    
$gameid getGameId();

     
$sGetDiceQuery "SELECT rerollablediceawarded, singlerolldiceawarded, rerollablesuccesses, singlerollsuccesses, rerolls, singlerollfailures FROM game WHERE `gameid` = ".$gameid;

     
$rowReturn queryDatabaseForSingleRow($sGetDiceQuery);

     
$rerollablediceawarded $rowReturn["rerollablediceawarded"];
     
$singlerolldiceawarded $rowReturn["singlerolldiceawarded"];
     
$rerollablesuccesses $rowReturn["rerollablesuccesses"];
     
$singlerollsuccesses $rowReturn["singlerollsuccesses"];
     
$rerolls $rowReturn["rerolls"];
     
$singlerollfailures $rowReturn["singlerollfailures"];

     while(
$rerollablediceawarded 0)
     {
         if (
rand(16) > 4)
         {
             
$rerollablesuccesses ++;
         }
         else
         {
             
$rerolls ++;
         }

         
$rerollablediceawarded --;
     }

     while(
$singlerolldiceawarded 0)
     {
         if (
rand(16) > 4)
         {
             
$singlerollsuccesses ++;
         }
         else
         {
             
$singlerollfailures ++;
         }

         
$singlerolldiceawarded --;
     }

    
$sUpdateQuery "UPDATE game SET bonusdicetoaward = 0, rerollablediceawarded = ".$rerollablediceawarded.", singlerolldiceawarded = ".$singlerolldiceawarded.", singlerollsuccesses = ".$singlerollsuccesses.", rerollablesuccesses = ".$rerollablesuccesses.", rerolls = ".$rerolls.", singlerollfailures = ".$singlerollfailures." WHERE gameid = ".$gameid;

    
updateDatabase($sUpdateQuery);

    echo 
"<bonusdicetoaward>0</bonusdicetoaward>";
    echo 
"<rerollablediceawarded>".$rerollablediceawarded."</rerollablediceawarded>";
    echo 
"<singlerolldiceawarded>".$singlerolldiceawarded."</singlerolldiceawarded>";
    echo 
"<singlerollsuccesses>".$singlerollsuccesses."</singlerollsuccesses>";
    echo 
"<rerollablesuccesses>".$rerollablesuccesses."</rerollablesuccesses>";
    echo 
"<rerolls>".$rerolls."</rerolls>";
    echo 
"<singlerollfailures>".$singlerollfailures."</singlerollfailures>";

    
closeDatabase();
?>
</root>