cook objects





PHPXRef 0.7 : NEABExplorer : /skills/cook_objects.php source









[ Index ]


PHP Cross Reference of NEABExplorer














if (gwGetCookie('xrefnav')=='off')
document.write('[ Show Explorer ]');
else
document.write('[ Hide Explorer ]');



[ Show Explorer ]
[ Hide Navbar ]





titleBody[close]
/skills/ -> cook_objects.php (source)

[Summary view]
[Print]
[Text view]


1 <?php
2 /**
3 * Code used for the skill mix/cook.
4 */
5 ?>
6
7 <SCRIPT>
8 var items=new Array();
9
10 function item(id,info,desc)
11 {
12 this.id=id;
13 this.info=info;
14 this.desc=desc;
15 }
16
17 function add_item_info(id,info,desc)
18 {
19 items[items.length]=new item(id,unescape(info),unescape(desc));
20 }
21
22 function show_item_info(e,id)
23 {
24 for(var i=0;i < items.length;i++)
25 {
26 if(items[i].id == id)
27 {
28 if(items[i].info == "")
29 return;
30
31 var html=items[i].desc+"<BR><BR><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 BGCOLOR=#000000 WIDTH=100%>";
32 html+="<TR><TH COLSPAN=3 BGCOLOR=#000000 class='smalltext'><FONT COLOR=#FFFFFF><B>Object information:</B></FONT></TH></TR>\n";
33 html+="<TR><TD><table border=0 cellpadding=2 cellspacing=0 BGCOLOR=#F0F0F0 WIDTH=100%>\n";
34 html+=items[i].info;
35 html+="</TABLE></TD></TR></TABLE>";
36
37 show_help_box(e,html);
38 return;
39 }
40 }
41 }
42 </SCRIPT>
43
44 <?PHP
45 function find_to_mix($obj,&$a,&$b)
46 {
47 global $db;
48
49 $a=$b=0;
50 $sql="SELECT ITEM FROM OBJECT_FORMULA WHERE OBJECTID = $obj AND TYPE = 'c'";
51 $r=$db->Execute($sql);
52 if(!$r->EOF)
53 {
54 $a=$r->fields[0]+0;
55 $r->MoveNext();
56 if(!$r->EOF)
57 $b=$r->fields[0]+0;
58 }
59 $r->Close();
60 if($a != 0 && $b != 0)
61 return true;
62 return false;
63 }
64
65 function object_name($id)
66 {
67 global $db;
68
69 $r=$db->Execute("SELECT NAME FROM OBJECTS WHERE ID = $id");
70 $n=$r->fields[0];
71 $r->Close();
72
73 return $n;
74 }
75
76 function mix($obj,$name,$nbtimes,$item1,$item2)
77 {
78 global $userid,$db;
79
80 // Keep the item id of item1 < as item2 to avoid to create 2 different receipts :-)
81 if(($item1+0) > ($item2+0))
82 {
83 $a=$item1;
84 $item1=$item2;
85 $item2=$a;
86 }
87
88 $nba=inventory_check($item1);
89 $nbb=inventory_check($item2);
90
91 if($nba == 0) // try to create it... in case we don't have it.
92 {
93 $a=$b=0;
94 if(find_to_mix($item1,$a,$b))
95 {
96 $n=object_name($item1);
97 mix($item1,$n,1,$a,$b);
98 $nba=inventory_check($item1);
99 }
100 }
101
102 if($nbb == 0) // try to create it... in case we don't have it.
103 {
104 $a=$b=0;
105 if(find_to_mix($item2,$a,$b))
106 {
107 $r=$db->Execute("SELECT NAME FROM OBJECTS WHERE ID = $item2");
108 $n=$r->fields[0];
109 $r->Close();
110 mix($item2,$n,1,$a,$b);
111 $nbb=inventory_check($item2);
112 }
113 }
114
115 if($item1 == $item2) // Use twice the same
116 {
117 if($nba < $nbtimes*2)
118 $nbtimes=floor($nba/2);
119
120 if($nbtimes <= 0)
121 return false;
122
123 inventory_add($item1,-$nbtimes*2);
124 inventory_add($obj,$nbtimes);
125 echo "You just cooked $nbtimes nice $name.<BR>\n";
126 // Add the mix in the cookbook.
127 $sql="INSERT INTO PLAYER_COOKBOOK(USERID,OBJECTID,OBJA,OBJB) VALUES($userid,$obj,".$item1.",".$item2.")";
128 //echo "$sql<BR>\n";
129 $db->Execute($sql);
130 }
131 else
132 {
133 if($nba < $nbb && $nbtimes > $nba)
134 $nbtimes=$nba;
135 else if($nbb < $nba && $nbtimes > $nbb)
136 $nbtimes=$nbb;
137 else if($nbtimes > $nbb)
138 $nbtimes=$nbb;
139
140 if($nbtimes <= 0)
141 return false;
142
143 inventory_add($item1,-$nbtimes);
144 inventory_add($item2,-$nbtimes);
145 inventory_add($obj,$nbtimes);
146 echo "You just cooked $nbtimes nice $name.<BR>\n";
147 // Add the mix in the cookbook.
148 $sql="INSERT INTO PLAYER_COOKBOOK(USERID,OBJECTID,OBJA,OBJB) VALUES($userid,$obj,".$item1.",".$item2.")";
149 $db->Execute($sql);
150 }
151 return true;
152 }
153
154 echo "<BR><DIV ALIGN=CENTER>";
155
156 if(count($_POST) > 0)
157 $_GET=$_POST;
158
159 if($_GET["CMD"] == "COOK")
160 {
161 $isok=true;
162 $nbtimes=$_GET["NBTIMES"]+0;
163
164 $sql="SELECT OBJECTS.ID,OBJECTS.NAME FROM OBJECTS,OBJECT_FORMULA O1,OBJECT_FORMULA O2
165 WHERE O1.OBJECTID = OBJECTS.ID AND O2.OBJECTID = OBJECTS.ID
166 AND O1.ITEM = ".($_GET["ITEM_1"]+0)." AND O2.ITEM = ".($_GET["ITEM_2"]+0)."
167 AND O1.TYPE = 'c'
168 AND O2.TYPE = 'c'
169 AND O1.ITEM <> O2.ITEM
170 ORDER BY OBJECTS.NAME,OBJECTS.ID";
171
172 $r=$db->Execute($sql);
173 $obj=$r->fields[0]+0;
174 $name=$r->fields[1];
175 $r->Close();
176
177 echo "<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=1 BGCOLOR=#000000 WIDTH=400>";
178 echo "<TR><TH><B><FONT COLOR=#FFFFFF>Result</FONT></B></TH></TR>\n";
179 echo "<TR><TD BGCOLOR=#E0E0E0>";
180
181 if($obj == 0)
182 {
183 echo "Those ingredients don't seem to mix well.\n";
184 $isok=false;
185 }
186 else
187 {
188 $item1=$_GET["ITEM_1"]+0;
189 $item2=$_GET["ITEM_2"]+0;
190
191 if(mix($obj,$name,$nbtimes,$item1,$item2) == false)
192 echo "You don't have enough ingredients";
193 }
194 echo "</TD></TR></TABLE><BR>\n";
195 }
196
197 echo "<FORM METHOD=POST ACTION=game.php NAME=COOK>\n";
198 echo "<INPUT TYPE=HIDDEN NAME=CMD VALUE=COOK>\n";
199
200 $sql="SELECT OBJECTS.ID,OBJECTS.NAME,INVENTORY.NBITEMS FROM INVENTORY,OBJECTS,
201 OBJECT_FORMULA WHERE INVENTORY.OBJECTID = OBJECTS.ID
202 AND INVENTORY.USERID = $userid AND OBJECT_FORMULA.ITEM = OBJECTS.ID
203 AND OBJECT_FORMULA.TYPE = 'c' ORDER BY OBJECTS.NAME,OBJECTS.ID";
204 $r=$db->Execute($sql);
205 $objs=array();
206 while(!$r->EOF)
207 {
208 $objs[$r->fields[0]]="(".$r->fields[2].") ".$r->fields[1];
209 $r->MoveNext();
210 }
211 $r->Close();
212
213 echo "<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER BGCOLOR=#000000 WIDTH=100%>\n";
214 echo "<TR><TH><FONT COLOR=#FFFFFF><B>You can cook/mix the following ingredients:</B></FONT></TH></TR>\n";
215 echo "<TR><TD><TABLE BORDER=0 WIDTH=100% CELLSPACING=0 CELLPADDING=2 BGCOLOR=#F0F0F0>\n";
216
217 if(count($objs) == 0)
218 {
219 echo "<TR><TD>You don't have ingredients which can be cooked or mixed together.</TD></TR>\n";
220 }
221 else
222 {
223 echo "<TR><TD WIDTH=40%><SELECT NAME=ITEM_1 STYLE='width: 90%'>\n";
224 foreach($objs as $k => $v)
225 {
226 if($k == $_GET["ITEM_1"])
227 echo "<OPTION SELECTED VALUE=$k>$v</OPTION>\n";
228 else
229 echo "<OPTION VALUE=$k>$v</OPTION>\n";
230 }
231 echo "</SELECT></TD>\n";
232 echo "<TD WIDTH=40%><SELECT NAME=ITEM_2 STYLE='width: 90%'>\n";
233 foreach($objs as $k => $v)
234 {
235 if($k == $_GET["ITEM_2"])
236 echo "<OPTION SELECTED VALUE=$k>$v</OPTION>\n";
237 else
238 echo "<OPTION VALUE=$k>$v</OPTION>\n";
239 }
240 echo "</SELECT></TD>\n";
241 echo "<TD WIDTH=20% ALIGN=RIGHT><B>Total:</B> <INPUT TYPE=TEXT NAME=NBTIMES VALUE=1 SIZE=4></TD></TR>\n";
242 }
243 echo "</TABLE></TR></TD></TABLE>\n";
244
245 echo "<BR>[<A HREF=# OnClick='document.forms[\"COOK\"].submit();return false;'>Cook/mix them</A>]\n";
246 echo "[<A HREF=game.php?PHPCODE=NONE>Cancel</A>]<BR><BR>\n";
247
248 echo "<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0 ALIGN=CENTER WIDTH=100% BGCOLOR=#000000>\n";
249 echo "<TR><TH><FONT COLOR=#FFFFFF><B>Known mix:</B></FONT></TH></TR>\n";
250 echo "<TR><TD BGCOLOR=#FFFFFF>";
251 echo "<DIV STYLE='width:100%; height:300; overflow:auto;'>";
252
253 $sql="SELECT MAIN.NAME,A.NAME,B.NAME,MAIN.ID,A.ID,B.ID
254 FROM OBJECTS AS MAIN,OBJECTS AS A,OBJECTS AS B,PLAYER_COOKBOOK AS CB
255 WHERE CB.USERID=$userid AND MAIN.ID = CB.OBJECTID AND A.ID = CB.OBJA AND B.ID = CB.OBJB
256 ORDER BY MAIN.NAME";
257
258 $script="";
259
260 $i=0;
261 $r=$db->Execute($sql);
262 if($r->EOF)
263 {
264 echo "You don't know any mixing formula yet.<BR>\n
265 To discover formulas, you have to choose some ingredients on top and click the \"Cook/mix them\" link.";
266 }
267 else
268 {
269 echo "<TABLE BORDER=0 WIDTH=100% CELLSPACING=0 CELLPADDING=2 BGCOLOR=#F0F0F0>\n";
270 echo "<TR BGCOLOR=#000000>";
271 echo "<TD><FONT COLOR=#FFFFFF><B>To create</B></FONT></TD>\n";
272 echo "<TD><FONT COLOR=#FFFFFF><B>You need</B></FONT></TD>\n";
273 echo "<TD><FONT COLOR=#FFFFFF><B>And</B></FONT></TD>\n";
274 echo "</TR>";
275 while(!$r->EOF)
276 {
277 $obj=object_info($r->fields[3]);
278 $inf="";
279 $c=1;
280 $l=0;
281 foreach($obj as $k => $v)
282 {
283 if($k == "PHPCODE" || $k == "NAME" || $k == "MANAGER" || $k == "ID" || ($k == "HANDS" && $v == "1") || $v == 0 || $k == 'SPECIAL' || $k == 'NPCSHOPS')
284 continue;
285 if($c == 0)
286 {
287 if(($l%2) != 0)
288 $inf.="<TR BGCOLOR=#E0E0E0>";
289 else
290 $inf.="<TR>";
291 }
292 $v=number_format($v, 0, '', "'");
293 if($k == "PRICE")
294 $v="$v Gold";
295 else if(($v+0) > 0)
296 $v="+$v";
297 $inf.="<TD class='smalltext' WIDTH=80><B>".ucfirst(strtolower($k)).":</B></TD><TD class='smalltext' WIDTH=100 ALIGN=RIGHT>$v&nbsp;</TD>";
298 $c++;
299 if($c > 1)
300 {
301 $inf.="</TR>\n";
302 $c=0;
303 $l++;
304 }
305 }
306 if($c != 0)
307 $inf.="<TD>&nbsp;</TD><TD>&nbsp;</TD></TR>\n";
308 $script.="add_item_info(".$r->fields[3].",'".rawurlencode($inf)."','".rawurlencode($obj["DESCRIPTION"])."');\n";
309
310 if(($i%2) == 0)
311 echo "<TR OnMouseOver='show_item_info(event,".$r->fields[3].");' OnMouseOut='hide_help_box()'>";
312 else
313 echo "<TR BGCOLOR=#C0C0C0 OnMouseOver='show_item_info(event,".$r->fields[3].");' OnMouseOut='hide_help_box()'>";
314 echo "<TD><A HREF=game.php?CMD=COOK&NBTIMES=1&ITEM_1=".$r->fields[4]."&ITEM_2=".$r->fields[5]."><FONT class=smalltext>(".inventory_check($r->fields[3]).")</FONT> ".$r->fields[0]."</A></TD>\n";
315 echo "<TD><FONT class=smalltext>(".inventory_check($r->fields[4]).")</FONT> ".$r->fields[1]."</TD>\n";
316 echo "<TD><FONT class=smalltext>(".inventory_check($r->fields[5]).")</FONT> ".$r->fields[2]."</TD>\n";
317 for($j=0;$j < 3;$j++)
318 echo "</TR>\n";
319 $r->MoveNext();
320 $i++;
321 }
322 echo "</TABLE>\n";
323 }
324 $r->Close();
325
326 echo "</DIV></TD></TR>";
327 echo "</TABLE>\n";
328
329 echo "<BR>\n";
330
331 echo "</FORM>\n";
332
333 echo "</DIV>\n";
334 echo "<SCRIPT>$script</SCRIPT>\n";
335 ?>



FUNC_DATA={
'item': ['item', '', [['player_tools/inventory','inventory.js',17],['skills','cook_objects.php',10]], 2],
'movenext': ['movenext', '', [['libs','db_conn_5.php',89],['libs','db_conn_4.php',89]], 104],
'show_help_box': ['show_help_box', '', [['libs','help_ballon.js',58]], 22],
'hide_help_box': ['hide_help_box', '', [['libs','help_ballon.js',130]], 31],
'inventory_add': ['inventory_add', 'Adds an item to the inventory. (no message) ', [['libs','objects_util.php',359]], 49],
'close': ['close', '', [['libs','db_conn_5.php',35],['libs','db_conn_5.php',87],['libs','db_conn_4.php',35],['libs','db_conn_4.php',87]], 380],
'show_item_info': ['show_item_info', '', [['skills','cook_objects.php',22]], 2],
'inventory_check': ['inventory_check', 'Checks if the player have this item. ', [['libs','objects_util.php',425]], 44],
'find_to_mix': ['find_to_mix', '', [['skills','cook_objects.php',45]], 2],
'mix': ['mix', '', [['skills','cook_objects.php',76]], 3],
'execute': ['execute', '', [['libs','db_conn_5.php',37],['libs','db_conn_4.php',37]], 652],
'object_info': ['object_info', 'Retreive the information about an object. ', [['libs','objects_util.php',457]], 20],
'object_name': ['object_name', '', [['skills','cook_objects.php',65]], 1],
'add_item_info': ['add_item_info', '', [['skills','cook_objects.php',17]], 1],
'floor': ['floor', '', [], 45],
'strtolower': ['strtolower', '', [], 16],
'count': ['count', '', [], 113],
'rawurlencode': ['rawurlencode', '', [], 14],
'number_format': ['number_format', '', [], 13],
'ucfirst': ['ucfirst', '', [], 5]};
CLASS_DATA={
};
CONST_DATA={
};

titleDescriptionBody
titleDescriptionBody
titleDescriptionBody
titleBody



Generated: Sun Jul 8 18:11:25 2007
Cross-referenced by PHPXref 0.7





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