cook objects


/**
* 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 "\n";
echo "
Result
";

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";

$sql="SELECT OBJECTS.ID,OBJECTS.NAME,INVENTORY.NBITEMS FROM INVENTORY,OBJECTS,
OBJECT_FORMULA WHERE INVENTORY.OBJECTID = OBJECTS.ID
AND INVENTORY.USERID = $userid AND OBJECT_FORMULA.ITEM = OBJECTS.ID
AND OBJECT_FORMULA.TYPE = 'c' ORDER BY OBJECTS.NAME,OBJECTS.ID";
$r=$db->Execute($sql);
$objs=array();
while(!$r->EOF)
{
$objs[$r->fields[0]]="(".$r->fields[2].") ".$r->fields[1];
$r->MoveNext();
}
$r->Close();

echo "\n";
echo "\n";
echo "
You can cook/mix the following ingredients:
\n";

if(count($objs) == 0)
{
echo "\n";
}
else
{
echo "\n";
echo "\n";
echo "\n";
}
echo "
You don't have ingredients which can be cooked or mixed together.
Total:
\n";

echo "
[Cook/mix them]\n";
echo "[Cancel]

\n";

echo "\n";
echo "\n";
echo "";
echo "
Known mix:
";
echo "
";

$sql="SELECT MAIN.NAME,A.NAME,B.NAME,MAIN.ID,A.ID,B.ID
FROM OBJECTS AS MAIN,OBJECTS AS A,OBJECTS AS B,PLAYER_COOKBOOK AS CB
WHERE CB.USERID=$userid AND MAIN.ID = CB.OBJECTID AND A.ID = CB.OBJA AND B.ID = CB.OBJB
ORDER BY MAIN.NAME";

$script="";

$i=0;
$r=$db->Execute($sql);
if($r->EOF)
{
echo "You don't know any mixing formula yet.
\n
To discover formulas, you have to choose some ingredients on top and click the \"Cook/mix them\" link.";
}
else
{
echo "\n";
echo "";
echo "\n";
echo "\n";
echo "\n";
echo "";
while(!$r->EOF)
{
$obj=object_info($r->fields[3]);
$inf="";
$c=1;
$l=0;
foreach($obj as $k => $v)
{
if($k == "PHPCODE" || $k == "NAME" || $k == "MANAGER" || $k == "ID" || ($k == "HANDS" && $v == "1") || $v == 0 || $k == 'SPECIAL' || $k == 'NPCSHOPS')
continue;
if($c == 0)
{
if(($l%2) != 0)
$inf.="";
else
$inf.="";
}
$v=number_format($v, 0, '', "'");
if($k == "PRICE")
$v="$v Gold";
else if(($v+0) > 0)
$v="+$v";
$inf.="";
$c++;
if($c > 1)
{
$inf.="\n";
$c=0;
$l++;
}
}
if($c != 0)
$inf.="\n";
$script.="add_item_info(".$r->fields[3].",'".rawurlencode($inf)."','".rawurlencode($obj["DESCRIPTION"])."');\n";

if(($i%2) == 0)
echo "";
else
echo "";
echo "\n";
echo "\n";
echo "\n";
for($j=0;$j < 3;$j++)
echo "\n";
$r->MoveNext();
$i++;
}
echo "
To createYou needAnd
".ucfirst(strtolower($k)).":$v 
  
fields[4]."&ITEM_2=".$r->fields[5].">(".inventory_check($r->fields[3]).") ".$r->fields[0]."(".inventory_check($r->fields[4]).") ".$r->fields[1]."(".inventory_check($r->fields[5]).") ".$r->fields[2]."
\n";
}
$r->Close();

echo "
\n";

echo "
\n";

echo "
\n";

echo "
\n";
echo "\n";
?>


Wyszukiwarka

Podobne podstrony:
cook objects
cook objects
stream writer objects
ObjectImpl
function hwapi object remove
110 Amazing Magic Tricks With Everyday Objects
function pg fetch object
Object
Cook Wstrząs
subject object questions
Cook dopuszczalne ryzyko
Object
bltin code objects
PrettyPrinter Objects
content handler objects
ObjectStreamField

więcej podobnych podstron