craft objects


/**
* Code used for the crafting skill.
* Crafting requires a blueprint.
*/

echo "
\n";
if($_GET["ACTION"] == "CREATE" && $_GET["ID"] != "")
{
$id=$_GET["ID"]+0;
$r=$db->Execute("SELECT COUNT(OBJECTID) FROM PLAYER_BLUEPRINTS WHERE USERID=$userid AND OBJECTID = $id");
$n=$r->fields[0]+0;
$r->Close();

if($n == 0)
{
echo "You do not have this blueprint. Sorry.
\n";
}
else
{
$r=$db->Execute("SELECT NBTIMES FROM PLAYER_BLUEPRINTS WHERE USERID=$userid AND OBJECTID = $id");
$nbprints=$r->fields[0]+0;
$r->Close();

$isok=true;
$nbtimes=$_GET["NBTIMES"]+0;
if($nbtimes > 20)
$nbtimes=20;
echo "";
echo "\n";
echo "
Result
";
echo "
";

$trial=0;
while($isok && $nbtimes > 0)
{
$nbtimes--;
$trial++;
$r=$db->Execute("SELECT NBITEMS,ITEM FROM OBJECT_FORMULA WHERE OBJECTID = $id AND TYPE = 'C'");
while(!$r->EOF)
{
if(inventory_check($r->fields[1]) < ($r->fields[0]+0))
{
$isok=false;
echo "Trial $trial: Sorry... but you do not have the required materials to create this object.
\n";
break;
}
$r->MoveNext();
}
$r->Close();
if($isok)
{
$r=$db->Execute("SELECT NBITEMS,ITEM FROM OBJECT_FORMULA WHERE OBJECTID = $id AND TYPE = 'C'");
while(!$r->EOF)
{
inventory_add($r->fields[1],-$r->fields[0]);
$r->MoveNext();
}
$r->Close();
$r=$db->Execute("SELECT PRICE FROM OBJECTS WHERE ID = $id");
$price=$r->fields[0]+0;
$r->Close();

//$prob=$uservals["DEXTERITY"]+$uservals["INTELLIGENCE"];
$prob=$uservals["DEXTERITY"]+$uservals["DEXMOD"]+$uservals["TEMP_DEX"]+$uservals["INTELLIGENCE"]+$uservals["INTMOD"]+$uservals["TEMP_INT"];
$perc=ceil($prob/ceil($price/160)*100);
if($perc > 100)
$perc=100;

$didit=false;
if($perc == 100 || mt_rand(0,100) < $perc)
{
inventory_add($id,1);
echo "Trial $trial: You created the object !
\n";
$didit=true;
}
else
{
echo "Trial $trial: You were unable to craft the item and lost all the raw materials used for it.
\n";
}

if($nbprints >= 0 && $didit == true) // Decrease the counter for the number of times the player can still create this object.
{
$nbprints--;
if($nbprints <= 0)
{
$db->Execute("DELETE FROM PLAYER_BLUEPRINTS WHERE USERID=$userid AND OBJECTID = $id");
$isok=false;
}
else
$db->Execute("UPDATE PLAYER_BLUEPRINTS SET NBTIMES = $nbprints WHERE USERID=$userid AND OBJECTID = $id");
}
}
}
echo "

\n";
}
}
$prob=$uservals["DEXTERITY"]+$uservals["DEXMOD"]+$uservals["TEMP_DEX"]+$uservals["INTELLIGENCE"]+$uservals["INTMOD"]+$uservals["TEMP_INT"];
$sql="SELECT OBJECTS.ID,OBJECTS.NAME,OBJECTS.PRICE,PLAYER_BLUEPRINTS.NBTIMES FROM PLAYER_BLUEPRINTS,OBJECTS WHERE PLAYER_BLUEPRINTS.OBJECTID = OBJECTS.ID AND PLAYER_BLUEPRINTS.USERID=$userid";
$r=$db->Execute($sql);
if(!$r->EOF)
{
echo "
\n";
echo "\n";
echo "
";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n";
while(!$r->EOF)
{
echo "";
//echo "\n";
echo "\n";
if(($r->fields[3]+0) > 0)
echo "\n";
else
echo "\n";
$perc=ceil($prob/ceil($r->fields[2]/160)*100);
if($perc > 100)
$perc=100;
echo "\n";
echo "";
echo "\n";
$r->MoveNext();
}
echo "\n";
echo "
Known blueprints
 ObjectProbabilityMaterial needed
[fields[0].">Create]".$r->fields[1]." (".$r->fields[3].")".$r->fields[1]."".$perc."%";
$sql="SELECT OBJECT_FORMULA.NBITEMS,OBJECTS.NAME,OBJECT_FORMULA.ITEM FROM OBJECT_FORMULA,OBJECTS WHERE
OBJECTS.ID = OBJECT_FORMULA.ITEM AND OBJECT_FORMULA.OBJECTID = ".$r->fields[0];
$r2=$db->Execute($sql);
$first=true;
while(!$r2->EOF)
{
if(!$first)
echo ", ";
$r3=$db->Execute("SELECT NBITEMS FROM INVENTORY WHERE USERID=$userid AND OBJECTID=".$r2->fields[2]);
if(($r3->fields[0]+0) < ($r2->fields[0]+0))
echo "";
echo "(".$r2->fields[0]." / ".($r3->fields[0]+0).") ".$r2->fields[1];
if(($r3->fields[0]+0) < ($r2->fields[0]+0))
echo "
";
$r3->Close();
$r2->MoveNext();
$first=false;
}
$r2->Close();
echo "
 Number of trials (max 20):

\n";
echo "[Craft]\n";
}
else
{
echo "";
echo "\n";
echo "
Known blueprints
";
echo "You don't have any blueprints at the moment.\n";
echo "

\n";
}
$r->Close();
echo "[Cancel]\n";
echo "
\n";
?>

Wyszukiwarka

Podobne podstrony:
craft objects
craft objects
stream writer objects
ObjectImpl
function hwapi object remove
110 Amazing Magic Tricks With Everyday Objects
function pg fetch object
Object
subject object questions
Object
bltin code objects
PrettyPrinter Objects
content handler objects
ObjectStreamField
pleasure craft information packdec07 2
hand craft edearrings
event objects

więcej podobnych podstron