rollcompatibilitydice.php

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

     
openDatabase();

     
$gameid getGameId();
     
$compatibilityid getAndCheckParameter("compatibilityid"PATTERN_NUMERIC"There has been a database error");

     
$sGetDiceQuery "SELECT compatibilitydicetoaward, singlerollsuccesses, singlerollfailures FROM game INNER JOIN compatibility ON game.gameid = compatibility.gameid WHERE compatibility.compatibilityid = ".$compatibilityid;

     
$row queryDatabaseForSingleRow($sGetDiceQuery);

     
$compatibilitydicetoaward $row["compatibilitydicetoaward"];
     
$singlerollsuccesses $row["singlerollsuccesses"];
     
$singlerollfailures $row["singlerollfailures"];

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

          
$compatibilitydicetoaward--;
     }

    
$sUpdateGameQuery "UPDATE game SET singlerollsuccesses = ".$singlerollsuccesses.", singlerollfailures = ".$singlerollfailures." WHERE gameid = ".$gameid;

    echo 
$sUpdateGameQuery ;

    
updateDatabase($sUpdateGameQuery);

    
$sUpdateCompatibilityQuery "UPDATE compatibility SET compatibilitydicetoaward = 0, invocationstatus = 'available' WHERE compatibilityid = ".$compatibilityid;

    echo 
$sUpdateCompatibilityQuery;

    
updateDatabase($sUpdateCompatibilityQuery);

    
outputCompatibilities();

    
$sReturnQuery "SELECT singlerollsuccesses, singlerollfailures FROM game WHERE gameid = ".$gameid;

    
$rowReturn queryDatabaseForSingleRow($sReturnQuery);

    
outputRowAsXml($rowReturn);

    
closeDatabase();
?>
</root>