/**
* Code used for the skill mix/cook.
*/
?>
function find_to_mix($obj,&$a,&$b)
{
global $db;
$a=$b=0;
$sql="SELECT ITEM FROM OBJECT_FORMULA WHERE OBJECTID = $obj AND TYPE = 'c'";
$r=$db->Execute($sql);
if(!$r->EOF)
{
$a=$r->fields[0]+0;
$r->MoveNext();
if(!$r->EOF)
$b=$r->fields[0]+0;
}
$r->Close();
if($a != 0 && $b != 0)
return true;
return false;
}
function object_name($id)
{
global $db;
$r=$db->Execute("SELECT NAME FROM OBJECTS WHERE ID = $id");
$n=$r->fields[0];
$r->Close();
return $n;
}
function mix($obj,$name,$nbtimes,$item1,$item2)
{
global $userid,$db;
// Keep the item id of item1 < as item2 to avoid to create 2 different receipts :-)
if(($item1+0) > ($item2+0))
{
$a=$item1;
$item1=$item2;
$item2=$a;
}
$nba=inventory_check($item1);
$nbb=inventory_check($item2);
if($nba == 0) // try to create it... in case we don't have it.
{
$a=$b=0;
if(find_to_mix($item1,$a,$b))
{
$n=object_name($item1);
mix($item1,$n,1,$a,$b);
$nba=inventory_check($item1);
}
}
if($nbb == 0) // try to create it... in case we don't have it.
{
$a=$b=0;
if(find_to_mix($item2,$a,$b))
{
$r=$db->Execute("SELECT NAME FROM OBJECTS WHERE ID = $item2");
$n=$r->fields[0];
$r->Close();
mix($item2,$n,1,$a,$b);
$nbb=inventory_check($item2);
}
}
if($item1 == $item2) // Use twice the same
{
if($nba < $nbtimes*2)
$nbtimes=floor($nba/2);
if($nbtimes <= 0)
return false;
inventory_add($item1,-$nbtimes*2);
inventory_add($obj,$nbtimes);
echo "You just cooked $nbtimes nice $name.
\n";
// Add the mix in the cookbook.
$sql="INSERT INTO PLAYER_COOKBOOK(USERID,OBJECTID,OBJA,OBJB) VALUES($userid,$obj,".$item1.",".$item2.")";
//echo "$sql
\n";
$db->Execute($sql);
}
else
{
if($nba < $nbb && $nbtimes > $nba)
$nbtimes=$nba;
else if($nbb < $nba && $nbtimes > $nbb)
$nbtimes=$nbb;
else if($nbtimes > $nbb)
$nbtimes=$nbb;
if($nbtimes <= 0)
return false;
inventory_add($item1,-$nbtimes);
inventory_add($item2,-$nbtimes);
inventory_add($obj,$nbtimes);
echo "You just cooked $nbtimes nice $name.
\n";
// Add the mix in the cookbook.
$sql="INSERT INTO PLAYER_COOKBOOK(USERID,OBJECTID,OBJA,OBJB) VALUES($userid,$obj,".$item1.",".$item2.")";
$db->Execute($sql);
}
return true;
}
echo "
";
if(count($_POST) > 0)
$_GET=$_POST;
if($_GET["CMD"] == "COOK")
{
$isok=true;
$nbtimes=$_GET["NBTIMES"]+0;
$sql="SELECT OBJECTS.ID,OBJECTS.NAME FROM OBJECTS,OBJECT_FORMULA O1,OBJECT_FORMULA O2
WHERE O1.OBJECTID = OBJECTS.ID AND O2.OBJECTID = OBJECTS.ID
AND O1.ITEM = ".($_GET["ITEM_1"]+0)." AND O2.ITEM = ".($_GET["ITEM_2"]+0)."
AND O1.TYPE = 'c'
AND O2.TYPE = 'c'
AND O1.ITEM <> O2.ITEM
ORDER BY OBJECTS.NAME,OBJECTS.ID";
$r=$db->Execute($sql);
$obj=$r->fields[0]+0;
$name=$r->fields[1];
$r->Close();
echo "
";
echo "Result |
\n";
echo ""; if($obj == 0) { echo "Those ingredients don't seem to mix well.\n"; $isok=false; } else { $item1=$_GET["ITEM_1"]+0; $item2=$_GET["ITEM_2"]+0; if(mix($obj,$name,$nbtimes,$item1,$item2) == false) echo "You don't have enough ingredients"; } echo " |
\n";
}
echo "
\n";
echo "
\n";
echo "\n";
?>
Wyszukiwarka
Podobne podstrony:
cook objectscook objectsstream writer objectsObjectImplfunction hwapi object remove110 Amazing Magic Tricks With Everyday Objectsfunction pg fetch objectObjectCook Wstrząssubject object questionsCook dopuszczalne ryzykoObjectbltin code objectsPrettyPrinter Objectscontent handler objectsObjectStreamFieldwięcej podobnych podstron