quests util





PHPXRef 0.7 : NEABExplorer : /libs/quests_util.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]
/libs/ -> quests_util.php (source)

[Summary view]
[Print]
[Text view]


1 <?PHP
2 /**
3 * Utility package to deal with quests.
4 */
5
6 /**
7 * Error handler used with the dialogs
8 *
9 * @param integer $errno
10 * @param integer $errmsg
11 * @param string $filename
12 * @param integer $linenum
13 * @param array $vars
14 */
15 function quest_error($errno, $errmsg, $filename, $linenum, $vars)
16 {
17 global $macroname;
18
19 if($errno == 8)
20 return;
21
22 echo "<B><FONT COLOR=#E00000>Error in the quest macro: '$macroname'.</FONT><BR>You should check if you provide all the needed parameters.</B><BR>\n";
23 }
24
25 /**
26 * Evaluate a PHP code (runs with some global variable accessible)
27 *
28 * @param string $code
29 */
30 function my_eval($code)
31 {
32 global $username,$db,$userid,$uservals;
33
34 eval($code);
35 }
36
37 /**
38 * Show a dialog.
39 */
40 function do_discussion()
41 {
42 global $db,$uservals,$quest,$userid,$titles,$basedir;
43 global $macroname;
44 global $havequery;
45 global $dialog,$npc;
46
47 include_once "$basedir/combat/combats_util.php";
48
49 $todebug=false;
50 $havequery=false;
51
52 $r=$db->Execute("SELECT MANAGER,NAME,EDITGROUP FROM LOCATIONS WHERE ID = ".$uservals["LOCATION"]);
53 $manager=$r->fields[0];
54 $locname=$r->fields[1];
55 $editgroup=$r->fields[2];
56 $r->Close();
57
58 $canedit=false;
59 if($manager == $userid)
60 $canedit=true;
61 else if($manager != 0 && $editgroup != 0)
62 {
63 $r=$db->Execute("SELECT USERID FROM EDITORS WHERE USERID=$userid AND EDITGROUP=".$editgroup);
64 if(!$r->EOF)
65 $canedit=true;
66 $r->Close();
67 }
68
69 $npc=$_GET["TALK"];
70 $dialog=$_GET["DIALOG"]+0;
71 if($dialog == 0)
72 $uservals["PREVDIALOG"]=0;
73
74 if($userid != 1)
75 $old_error_handler = set_error_handler("quest_error");
76
77 $hasright=true;
78
79 $r=$db->Execute("SELECT COUNT(USERID) FROM DIALOGACCESS WHERE USERID = $userid AND DIALOGID = $dialog");
80 $nb=$r->fields[0]+0;
81 $r->Close();
82
83 // Check if the user have the right to excute this dialog
84
85 if($dialog != 0 && $nb < 1 && $uservals["ONFINISH"] == "" && count($_POST) == 0)
86 {
87 if($todebug)
88 echo "No lines in the dialogaccess table<BR>\n";
89 if($canedit)
90 echo "<B><FONT COLOR=#E00000>Warning: you access this dialog either from a link with a wrong \"TO ID\" or you did some other strange things as no actions will be executed on this dialog (due to security restrictions).</FONT></B><BR>\n";
91 $hasright=false;
92 }
93
94 if(count($_POST) > 0)
95 $hasright=true;
96
97 if($userid == 1 && $todebug == true)
98 echo "Hasright: ".($hasright==true?"True":"False")."<BR>\n";
99
100 $uservals["PREVDIALOG"]=$dialog;
101 $db->Execute("UPDATE PLAYER SET PREVDIALOG=$dialog,ONFINISH='' WHERE ID = $userid");
102 $db->Execute("DELETE FROM DIALOGACCESS WHERE USERID = $userid");
103
104 // Main text and code
105 $r=$db->Execute("SELECT CONTENT, DOCODE FROM DIALOGS WHERE NPC = ".$db->qstr($npc)." AND DIALOGID = $dialog AND LOCATION = {$uservals['LOCATION']}");
106 if($r->EOF)
107 {
108 $r->Close();
109 echo "Wrong dialog info<BR>\n";
110 return;
111 }
112
113 if($_GET["INMAP"] == "TRUE")
114 {
115 echo "<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 BGCOLOR=#000000 WIDTH=100% ALIGN=CENTER>";
116 echo "<TR><TH><B><FONT COLOR=#FFFFFF>".$locname."</FONT></B></TH></TR>\n";
117 echo "</TABLE>\n";
118 }
119 else
120 {
121 echo "<BR><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2 BGCOLOR=#000000 WIDTH=95% ALIGN=CENTER>";
122 echo "<TR><TH><B><FONT COLOR=#FFFFFF>".$locname."</FONT></B></TH></TR>\n";
123 echo "<TR VALIGN=TOP><TD BGCOLOR=#E0E0E0>";
124 }
125
126 if($uservals["SEX"] == 'F')
127 echo preg_replace('/(\W+)[sS]ir(\W+)/','\1Dame\2',str_replace(array('$NAME','$TITLE'),array($uservals["USERNAME"],$titles[$uservals['SEX']][$uservals['TITLE']]),$r->fields[0]))."<BR>\n";
128 else
129 echo str_replace(array('$NAME','$TITLE'),array($uservals["USERNAME"],$titles[$uservals['SEX']][$uservals['TITLE']]),$r->fields[0])."<BR>\n";
130 if($r->fields[1] != "" && $hasright == true)
131 my_eval($r->fields[1]);
132
133 $r->Close();
134
135 $needtostop=false;
136
137 if($hasright)
138 {
139 // Eval code from the attached table
140 $sql="SELECT DIALOGCODE.LINE,DIALOGCOMMANDS.CODE,
141 DIALOGCODE.PARAM1,DIALOGCODE.PARAM2,
142 DIALOGCODE.PARAM3,DIALOGCODE.PARAM4,
143 DIALOGCOMMANDS.TYPE, DIALOGCOMMANDS.NAME
144 FROM DIALOGCODE,DIALOGCOMMANDS WHERE DIALOGCODE.LOCATION={$uservals['LOCATION']}
145 AND DIALOGCODE.NPC = ".$db->qstr($npc)." AND DIALOGCODE.DIALOGID = $dialog
146 AND DIALOGCODE.COMMAND = DIALOGCOMMANDS.ID ORDER BY DIALOGCODE.LINE";
147
148 $r=$db->Execute($sql);
149 while(!$r->EOF)
150 {
151 if($canedit == false || $r->fields[6] != "N")
152 {
153 $macroname=$r->fields[7];
154
155 $code=str_replace(array("@1","@2","@3","@4"),array(str_replace("\"","\\\"",$r->fields[2]),str_replace("\"","\\\"",$r->fields[3]),str_replace("\"","\\\"",$r->fields[4]),str_replace("\"","\\\"",$r->fields[5])),$r->fields[1]);
156 if($userid == 1 && $todebug == true)
157 echo "$code<BR>\n";
158 eval($code);
159 if($r->fields[6] == "S" && count($_POST) == 0)
160 {
161 $needtostop=true;
162 if($userid == 1 && $todebug == true)
163 echo "Need to stop...<BR>\n";
164 }
165 }
166 $r->MoveNext();
167 }
168 $r->Close();
169 }
170
171 if($needtostop)
172 {
173 return;
174 }
175
176 if($havequery)
177 {
178 echo "</TD></TR></TABLE>\n";
179 if($userid != 1)
180 set_error_handler($old_error_handler);
181 }
182 // Dialog choices
183 echo "<UL>\n";
184 $r=$db->Execute("SELECT IFCODE,LINKTEXT,LINK,DIALOGTO FROM DIALOGLINKS WHERE NPC =".$db->qstr($npc)." AND DIALOGFROM = $dialog AND LOCATION = {$uservals['LOCATION']} ORDER BY POS");
185 while(!$r->EOF)
186 {
187 // Eval code from the attached table
188 if($r->fields[0] != "")
189 {
190 $res=false;
191 $code='if ('.$r->fields[0].') $res=true;';
192 eval($code);
193 }
194 else
195 $res=macro_check("DIALOGIF","DIALOGIF.LOCATION={$uservals['LOCATION']}
196 AND DIALOGIF.NPC = ".$db->qstr($npc)." AND DIALOGIF.DIALOGFROM = $dialog
197 AND DIALOGIF.DIALOGTO = ".$r->fields[3]);
198
199 if($res)
200 {
201 if($_GET["INMAP"] == "TRUE" && strpos($r->fields[2],"NEWLOC=") !== false)
202 echo "<LI><A TARGET=_parent HREF=\"".$r->fields[2]."\">".$r->fields[1]."</A></LI>\n";
203 else if($_GET["INMAP"] == "TRUE" && strpos($r->fields[2],"?") !== false)
204 echo "<LI><A HREF=\"".$r->fields[2]."&INMAP=TRUE\">".$r->fields[1]."</A></LI>\n";
205 else if($_GET["INMAP"] == "TRUE")
206 echo "<LI><A HREF=\"".$r->fields[2]."?INMAP=TRUE\">".$r->fields[1]."</A></LI>\n";
207 else
208 echo "<LI><A HREF=\"".$r->fields[2]."\">".$r->fields[1]."</A></LI>\n";
209
210 if($hasright)
211 {
212 $sql="INSERT INTO DIALOGACCESS(USERID,DIALOGID) VALUES($userid,".$r->fields[3].")";
213 $db->Execute($sql);
214 if($userid == 1 && $todebug == true)
215 echo "$sql<BR>\n";
216 }
217 }
218 $r->MoveNext();
219 }
220 $r->Close();
221 echo "</UL>\n";
222 if($_GET["INMAP"] != "TRUE")
223 echo "</TD></TR></TABLE>\n";
224 if($userid != 1)
225 set_error_handler($old_error_handler);
226 }
227
228 /**
229 * Checks if a quest condition is met or not.
230 *
231 * @param string $table
232 * @param string $where
233 * @return boolean
234 */
235 function macro_check($table,$where)
236 {
237 global $db,$userid,$uservals;
238
239 // Eval code from the attached table
240 $sql="SELECT DIALOGCHECKS.CODE,DIALOGCHECKS.CODE,
241 $table.PARAM1,$table.PARAM2,
242 $table.PARAM3,$table.PARAM4, DIALOGCHECKS.NAME
243 FROM $table,DIALOGCHECKS WHERE $table.COMMAND = DIALOGCHECKS.ID AND $where";
244
245 $code="";
246 $macroname="";
247 $r2=$db->Execute($sql);
248 while(!$r2->EOF)
249 {
250 if($code != "")
251 {
252 $code.=" && ";
253 $macroname.=" AND ";
254 }
255 $macroname.=$r2->fields[6];
256 $code.=str_replace(array("@1","@2","@3","@4"),array($r2->fields[2],$r2->fields[3],$r2->fields[4],$r2->fields[5]),$r2->fields[1]);
257 $r2->MoveNext();
258 }
259 $r2->Close();
260
261 if($code != "")
262 {
263 $res=false;
264 $code='if ('.$code.') $res=true;';
265 if($uservals["USERNAME"] == "test")
266 echo "$code<BR>\n";
267 eval($code);
268 }
269 else
270 $res=true;
271
272 return $res;
273 }
274
275 /**
276 * Deprecated function.
277 *
278 * @param unknown_type $quest
279 * @param unknown_type $var
280 * @param unknown_type $part
281 * @param unknown_type $val
282 */
283 function set_qv_part($quest,$var,$part,$val)
284 {
285 $str=get_quest_variable($quest,$var);
286 $str=set_quest_var_part($str,$part,$val);
287 set_quest_variable($quest,$var,$str);
288 }
289
290 /**
291 * Deprecated function
292 *
293 * @param unknown_type $quest
294 * @param unknown_type $var
295 * @param unknown_type $part
296 * @return unknown
297 */
298 function get_qv_part($quest,$var,$part)
299 {
300 $str=get_quest_variable($quest,$var);
301 return get_quest_var_part($str,$part);
302 }
303
304 /**
305 * Deprecated function
306 *
307 * @param unknown_type $var
308 * @param unknown_type $part
309 * @param unknown_type $val
310 * @return unknown
311 */
312 function set_quest_var_part($var,$part,$val)
313 {
314 if($part == 0)
315 return $val.substr($var,$part+1);
316 else if($part >= strlen($var))
317 {
318 $var=str_pad($var,$part,"0");
319 return substr($var,0,$part).$val.substr($var,$part+1);
320 }
321 else
322 return substr($var,0,$part).$val.substr($var,$part+1);
323 }
324
325 /**
326 * Deprecated function
327 *
328 * @param unknown_type $var
329 * @param unknown_type $part
330 * @return unknown
331 */
332 function get_quest_var_part($var,$part)
333 {
334 return substr($var,$part,1);
335 }
336
337 /**
338 * Set the experience, level
339 *
340 * @param integer $exp
341 */
342 function macro_gain_experience($exp)
343 {
344 global $db,$uservals,$basedir;
345
346 $r=$db->Execute("SELECT IP,USERNAME,LOCATIONS.MANAGER FROM PLAYER,LOCATIONS WHERE LOCATIONS.MANAGER=PLAYER.ID AND LOCATIONS.ID = ".$uservals["LOCATION"]);
347 $fromip=$r->fields[0];
348 $fromname=$r->fields[1];
349 $fromid=$r->fields[2];
350 $r->Close();
351
352 if($fromip == $uservals["IP"] && $fromip != "")
353 $db->Execute("INSERT INTO CROSS_EXPLOIT(FROMPLAYER,TOPLAYER,MESSAGE) VALUES($userid,$fromid,".$db->qstr("$username received via a quest managed by $fromname $exp Exp ( both using IP $fromip ).").")");
354
355 $l=$uservals['LEVEL']+0;
356 include "$basedir/libs/level_rules.php";
357
358 $dif=$max-$min;
359
360 if($exp > $dif/2 && $exp > 5000)
361 $exp=ceil($dif/2);
362 if(($exp+0) > 0)
363 echo "<B>You gained $exp EXP.</B><BR>\n";
364 else
365 echo "<B>You lost ".(-$exp)." EXP.</B><BR>\n";
366 gain_experience($exp);
367 }
368
369 /**
370 * Give some experience to a player
371 *
372 * @param integer $exp
373 * @param bool $display
374 * @return string
375 */
376 function gain_experience($exp,$display=true)
377 {
378 global $db,$uservals,$userid,$basedir;
379
380 $res="";
381
382 $uservals["EXPERIENCE"]+=$exp;
383 if($uservals["EXPERIENCE"] < 0)
384 $uservals["EXPERIENCE"]=0;
385
386 $levelchaned=false;
387 while(true)
388 {
389 $l=$uservals['LEVEL']+0;
390 include "$basedir/libs/level_rules.php";
391
392 if(($uservals["EXPERIENCE"]+0) < $min)
393 {
394 $uservals["LEVEL"]--;
395 $res.="<B>You lost a level ! You are now level ".$uservals["LEVEL"].".</B><BR>";
396 continue;
397 }
398 else if(($uservals["EXPERIENCE"]+0) >= $max)
399 {
400 $uservals["LEVEL"]++;
401 $res.="<B>You gained a level ! You are now level ".$uservals["LEVEL"].".</B><BR>";
402 $levelchanged=true;
403 continue;
404 }
405 else
406 break;
407 }
408 if($levelchanged)
409 {
410 $red.="As your level increases, remember to assign stats points to your different stats.<BR>";
411 }
412 $db->Execute("UPDATE PLAYER SET EXPERIENCE=".$uservals["EXPERIENCE"].", LEVEL=".$uservals["LEVEL"].", GOLD=".$uservals["GOLD"]." WHERE ID = $userid");
413
414 if($display)
415 echo "$res\n";
416
417 return $res;
418 }
419
420 /**
421 * Give some experience to a player
422 *
423 * @param integer $userid
424 * @param integer $exp
425 */
426 function gain_user_experience($userid,$exp)
427 {
428 global $db,$basedir;
429
430 $uservals=read_db_entry($db,"SELECT * FROM PLAYER WHERE ID = $userid AND AUTHORIZED = 'Y'");
431
432 $uservals["EXPERIENCE"]+=$exp;
433 if($uservals["EXPERIENCE"] < 0)
434 $uservals["EXPERIENCE"]=0;
435
436 $levelchaned=false;
437 while(true)
438 {
439 $l=$uservals['LEVEL']+0;
440 //$min=($l-1)*($l-1)*($l-1)*100+($l-1)*200+round(floor(($l-1)/20)*($l-1)*($l-1)*1000*(($l-1)-20)/1.8);
441 //$max=(($l*$l*$l)*100)+$l*200+round(floor($l/20)*$l*$l*1000*($l-20)/1.8);
442 include "$basedir/libs/level_rules.php";
443
444 if(($uservals["EXPERIENCE"]+0) < $min)
445 {
446 $uservals["LEVEL"]--;
447 continue;
448 }
449 else if(($uservals["EXPERIENCE"]+0) >= $max)
450 {
451 $uservals["LEVEL"]++;
452 continue;
453 }
454 else
455 break;
456 }
457 $db->Execute("UPDATE PLAYER SET EXPERIENCE=".$uservals["EXPERIENCE"].", LEVEL=".$uservals["LEVEL"].", GOLD=".$uservals["GOLD"].",LASTACTION = LASTACTION WHERE ID = $userid");
458 }
459
460 /**
461 * Gives some gold to the player. Limited to 200'000
462 *
463 * @param integer $gold
464 */
465 function gain_gold($gold)
466 {
467 global $db,$userid,$uservals;
468 global $dialog,$npc;
469
470 $r=$db->Execute("SELECT IP,USERNAME,LOCATIONS.MANAGER FROM PLAYER,LOCATIONS WHERE LOCATIONS.MANAGER=PLAYER.ID AND LOCATIONS.ID = ".$uservals["LOCATION"]);
471 $fromip=$r->fields[0];
472 $fromname=$r->fields[1];
473 $fromid=$r->fields[2];
474 $r->Close();
475
476 if($gold > 200000)
477 $gold=200000;
478
479 if($fromip == $uservals["IP"] && $fromip != "")
480 $db->Execute("INSERT INTO CROSS_EXPLOIT(FROMPLAYER,TOPLAYER,MESSAGE) VALUES($userid,$fromid,".$db->qstr("$username received via a quest managed by $fromname $gold Gold ( both using IP $fromip ).").")");
481
482 if(($gold+0) > 0)
483 echo "<B>You received $gold Gold.</B><BR>\n";
484 else
485 echo "<B>You lost ".(-$gold)." Gold.</B><BR>\n";
486
487 $uservals["GOLD"]+=$gold;
488 $db->Execute("UPDATE PLAYER SET GOLD=".$uservals["GOLD"]." WHERE ID = $userid");
489 }
490
491 /**
492 * Add a journal entry.
493 *
494 * @param integer $quest
495 * @param string $entry
496 */
497 function add_journal($quest,$entry)
498 {
499 global $db,$userid,$uservals;
500
501 echo "<B>Journal updated.</B><BR>\n";
502 $db->Execute("INSERT INTO JOURNAL(QUEST,USERID,LOCATION,ENTRY) VALUES($quest,$userid,".$uservals["LOCATION"].",".$db->qstr($entry).")");
503 }
504
505 /**
506 * Define a given quest as finished.
507 *
508 * @param integer $quest
509 */
510 function finish_quest($quest)
511 {
512 global $db,$userid;
513
514 $db->Execute("INSERT INTO FINISHEDQUESTS(USERID,QUESTID) VALUES($userid,$quest)");
515 }
516
517 /**
518 * Check if a quest as been started.
519 *
520 * @param integer $quest
521 * @return boolean
522 */
523 function is_quest_started($quest)
524 {
525 global $db,$userid;
526
527 $r=$db->Execute("SELECT COUNT(ENTRY) FROM JOURNAL WHERE QUEST = $quest AND USERID = $userid");
528 $nb=$r->fields[0]+0;
529 $r->Close();
530
531 if($nb == 0)
532 {
533 $r=$db->Execute("SELECT COUNT(VARID) FROM QUESTVARIABLES WHERE QUESTID = $quest AND USERID = $userid");
534 $nb+=$r->fields[0]+0;
535 $r->Close();
536 }
537
538 if($nb > 0)
539 return true;
540 else
541 return false;
542 }
543
544 /**
545 * Checks if a quest has been finished.
546 *
547 * @param integer $quest
548 * @return boolean
549 */
550 function is_quest_finished($quest)
551 {
552 global $db,$userid;
553
554 $r=$db->Execute("SELECT COUNT(QUESTID) FROM FINISHEDQUESTS WHERE QUESTID = $quest AND USERID = $userid");
555 $nb=$r->fields[0]+0;
556 $r->Close();
557
558 if($nb == 0)
559 return false;
560 else
561 return true;
562 }
563
564 /**
565 * Returns true on the first call, and then false;
566 * Used to show only 1 of the dialog link.
567 *
568 * @return boolean
569 */
570 function first_item()
571 {
572 static $firstitem=true;
573
574 if($firstitem)
575 {
576 $firstitem=false;
577 return true;
578 }
579 return false;
580 }
581
582 /**
583 * Returns a number between 0-100. On mulitple runs it will return the same number.
584 *
585 * @return integer
586 */
587 function random_number()
588 {
589 static $firstitem=true;
590 static $rand=0;
591
592 if($firstitem)
593 {
594 $firstitem=false;
595 $rand=mt_rand(0,100);
596 }
597 return $rand;
598 }
599
600 /**
601 * Returns the count of the monster of this type killed by the player.
602 *
603 * @param integer $monsterid
604 * @return integer
605 */
606 function monster_kills($monsterid)
607 {
608 global $db,$userid;
609
610 $r=$db->Execute("SELECT NB FROM TABLE_HUNTING WHERE USERID = $userid AND MONSTERID = $monsterid");
611 $nb=$r->fields[0]+0;
612 $r->Close();
613
614 return $nb;
615 }
616
617 /**
618 * Change player alignement.
619 *
620 * @param integer $val
621 */
622 function change_alignement($val)
623 {
624 global $db,$userid,$uservals;
625
626 $uservals["ALIGNEMENT"]+=$val;
627 if($uservals["ALIGNEMENT"] < 0)
628 $uservals["ALIGNEMENT"]=0;
629 if($uservals["ALIGNEMENT"] > 80)
630 $uservals["ALIGNEMENT"]=80;
631
632 $db->Execute("UPDATE PLAYER SET ALIGNEMENT = ".$uservals["ALIGNEMENT"]." WHERE ID = ".$userid);
633 }
634
635 /**
636 * Transfer the player to a new location.
637 *
638 * @param integer $loc
639 */
640 function change_location($loc)
641 {
642 global $db,$userid,$uservals;
643
644 $uservals["LOCATION"]=$loc;
645 $db->Execute("UPDATE PLAYER SET LOCATION = ".$uservals["LOCATION"]." WHERE ID = ".$userid);
646 }
647
648 /**
649 * Changes player HP.
650 *
651 * @param integer $nb
652 */
653 function add_hp($nb)
654 {
655 global $db,$userid,$uservals;
656
657 if(($nb+0) > 0)
658 echo "<B>You recovered $nb HP.</B><BR>\n";
659 else
660 echo "<B>You lost $nb HP.</B><BR>\n";
661 $uservals["HP"]+=$nb;
662 if($uservals["HP"] > ($uservals["MAXHP"]+$uservals["HPMOD"]+$uservals["TEMP_HP"]))
663 $uservals["HP"]=($uservals["MAXHP"]+$uservals["HPMOD"]+$uservals["TEMP_HP"]);
664 if($uservals["HP"] < 1)
665 {
666 $uservals["HP"]=1;
667 echo "<B>You died.</B><BR>\n";
668 $db->Execute("UPDATE PLAYER SET LOCATION = RESURECT WHERE ID = ".$userid);
669 }
670 $db->Execute("UPDATE PLAYER SET HP = ".$uservals["HP"]." WHERE ID = ".$userid);
671 }
672
673 /**
674 * Changes the player MP.
675 *
676 * @param integer $nb
677 */
678 function add_mp($nb)
679 {
680 global $db,$userid,$uservals;
681
682 if(($nb+0) > 0)
683 echo "<B>You recovered $nb MP.</B><BR>\n";
684 $uservals["MP"]+=$nb;
685 if($uservals["MP"] > ($uservals["MAXMP"]+$uservals["MPMOD"]+$uservals["TEMP_MP"]))
686 $uservals["MP"]=($uservals["MAXMP"]+$uservals["MPMOD"]+$uservals["TEMP_MP"]);
687 if($uservals["MP"] < 0)
688 $uservals["MP"]=0;
689 $db->Execute("UPDATE PLAYER SET MP = ".$uservals["MP"]." WHERE ID = ".$userid);
690 }
691
692 /**
693 * Kills the player.
694 */
695 function kill_player()
696 {
697 global $db,$userid,$uservals;
698
699 echo "<B>You died.</B><BR>\n";
700 $uservals["HP"]=1;
701 $db->Execute("UPDATE PLAYER SET HP = 1, LOCATION = RESURECT WHERE ID = ".$userid);
702 }
703
704 /**
705 * Start a combat with the specified monster.
706 * The $onfinish parameter will be used as "callback"
707 * link once the combat is finished.
708 *
709 * @param integer $monster
710 * @param string $onfinish
711 */
712 function monster_combat($monster,$onfinish)
713 {
714 global $db,$userid,$uservals,$basedir;
715
716 ob_end_clean();
717 ob_start();
718 include_once "$basedir/libs/combats_util.php";
719
720 $db->Execute("UPDATE PLAYER SET ONFINISH = ".$db->qstr($onfinish)." WHERE ID = $userid");
721 start_combat($monster);
722 }
723
724 /**
725 * Ask a question during a dialog.
726 *
727 * @param string $str
728 * @param integer $id
729 */
730 function add_query_box($str,$id)
731 {
732 global $havequery;
733
734 if($_POST["ANSWER"] <> "")
735 return;
736
737 echo "<FORM METHOD=POST ACTION=game.php?DIALOG=$id&TALK=".urlencode(str_replace(" ","_",$_GET["TALK"])).">\n";
738 echo "<B>$str:</B> <INPUT TYPE=TEXT NAME=ANSWER> <INPUT TYPE=SUBMIT VALUE=Submit><BR>\n";
739 echo "</FORM>\n";
740 $havequery=true;
741 }
742
743 /**
744 * Changes the "sickness" of a player
745 *
746 * @param integer $s
747 */
748 function change_sickness($s)
749 {
750 global $db,$userid,$uservals;
751
752 if(($s+0) < 0)
753 $s=0;
754 if(($s+0) > 200)
755 $s=200;
756
757 $db->Execute("UPDATE PLAYER SET SICKNESS=$s WHERE ID = $userid");
758 }
759
760 /**
761 * Gives a blueprint to the player.
762 *
763 * @param integer $id object ID
764 */
765 function blueprint_add($id)
766 {
767 global $db,$userid;
768
769 if(is_craftable($id))
770 $db->Execute("INSERT INTO PLAYER_BLUEPRINTS(USERID,OBJECTID) VALUES($userid,$id)");
771 }
772
773 /**
774 * Checks if the player is member of a given clan.
775 *
776 * @param integer $id
777 * @return boolean
778 */
779 function is_member($id)
780 {
781 global $db,$userid;
782
783 $r=$db->Execute("SELECT ROLE FROM CLAN_MEMBERS WHERE USERID = $userid AND CLANID = $id");
784 if ($r->fields[0]=="")
785 $role=-1;
786 else
787 $role=$r->fields[0]+0;
788 $r->Close();
789
790 if($role >= 0)
791 return true;
792 else
793 return false;
794 }
795
796 /**
797 * Blocks most of the menu options.
798 *
799 */
800 function block_gui()
801 {
802 global $db,$userid,$uservals;
803
804 $db->Execute("UPDATE PLAYER SET GUIBLOCKED='Y' WHERE ID=$userid");
805 $uservals["GUIBLOCKED"]="Y";
806 }
807
808 /**
809 * Unblocks the menu.
810 *
811 */
812 function unblock_gui()
813 {
814 global $db,$userid,$uservals;
815
816 $db->Execute("UPDATE PLAYER SET GUIBLOCKED='N' WHERE ID=$userid");
817 $uservals["GUIBLOCKED"]="N";
818 }
819
820 /**
821 * Checks if a date is between a specified dd/mm
822 *
823 * @param integer $ds
824 * @param integer $ms
825 * @param integer $de
826 * @param integer $me
827 * @return boolean
828 */
829 function is_date_in_between($ds,$ms,$de,$me)
830 {
831 $now=getdate();
832 $cur=$now["mon"]*31+$now["mday"];
833 $s=$ds+$ms*31;
834 $e=$de+$me*31;
835 if($cur >= $s && $cur <= $e)
836 return true;
837 return false;
838 }
839
840 /**
841 * Check if the date is exactly at a specified dd/mm
842 *
843 * @param unknown_type $d
844 * @param unknown_type $m
845 * @return unknown
846 */
847 function is_date($d,$m)
848 {
849 $now=getdate();
850 if($now["mon"]*31+$now["mday"] == $d+$m*31)
851 return true;
852 return false;
853 }
854 ?>



FUNC_DATA={
'is_quest_started': ['is_quest_started', 'Check if a quest as been started. ', [['libs','quests_util.php',517]], 0],
'set_quest_variable': ['set_quest_variable', 'Stores a quest variable ', [['libs','misc_util.php',54]], 1],
'get_quest_variable': ['get_quest_variable', 'Retreives a quest variable ', [['libs','misc_util.php',27]], 5],
'start_combat': ['start_combat', '', [['combat','combats_util.php',721]], 3],
'movenext': ['movenext', '', [['libs','db_conn_5.php',89],['libs','db_conn_4.php',89]], 104],
'block_gui': ['block_gui', 'Blocks most of the menu options. ', [['libs','quests_util.php',796]], 0],
'is_date_in_between': ['is_date_in_between', 'Checks if a date is between a specified dd/mm ', [['libs','quests_util.php',820]], 0],
'blueprint_add': ['blueprint_add', 'Gives a blueprint to the player. ', [['libs','quests_util.php',760]], 0],
'change_alignement': ['change_alignement', 'Change player alignement. ', [['libs','quests_util.php',617]], 0],
'set_quest_var_part': ['set_quest_var_part', 'Deprecated function ', [['libs','quests_util.php',304]], 1],
'is_craftable': ['is_craftable', 'Checks if an item is craftable ', [['libs','objects_util.php',42]], 5],
'read_db_entry': ['read_db_entry', '', [['locations_modules/2dmap','minimap.php',10],['libs','misc_util.php',71]], 27],
'unblock_gui': ['unblock_gui', 'Unblocks the menu. ', [['libs','quests_util.php',808]], 0],
'monster_kills': ['monster_kills', 'Returns the count of the monster of this type killed by the player. ', [['libs','quests_util.php',600]], 0],
'qstr': ['qstr', '', [['libs','db_conn_5.php',45],['libs','db_conn_4.php',45]], 122],
'gain_gold': ['gain_gold', 'Gives some gold to the player. Limited to 200\'000 ', [['libs','quests_util.php',460]], 0],
'add_query_box': ['add_query_box', 'Ask a question during a dialog. ', [['libs','quests_util.php',724]], 0],
'is_member': ['is_member', 'Checks if the player is member of a given clan. ', [['libs','quests_util.php',773]], 0],
'change_sickness': ['change_sickness', 'Changes the "sickness" of a player ', [['libs','quests_util.php',743]], 0],
'monster_combat': ['monster_combat', 'Start a combat with the specified monster. The $onfinish parameter will be used as "callback" link once the combat is finished. ', [['libs','quests_util.php',704]], 0],
'gain_experience': ['gain_experience', 'Give some experience to a player ', [['libs','quests_util.php',369]], 2],
'change_location': ['change_location', 'Transfer the player to a new location. ', [['libs','quests_util.php',635]], 0],
'first_item': ['first_item', 'Returns true on the first call, and then false; Used to show only 1 of the dialog link. ', [['libs','quests_util.php',564]], 0],
'macro_check': ['macro_check', 'Checks if a quest condition is met or not. ', [['libs','quests_util.php',228]], 3],
'finish_quest': ['finish_quest', 'Define a given quest as finished. ', [['libs','quests_util.php',505]], 0],
'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],
'random_number': ['random_number', 'Returns a number between 0-100. On mulitple runs it will return the same number. ', [['libs','quests_util.php',582]], 0],
'is_quest_finished': ['is_quest_finished', 'Checks if a quest has been finished. ', [['libs','quests_util.php',544]], 0],
'gain_user_experience': ['gain_user_experience', 'Give some experience to a player ', [['libs','quests_util.php',420]], 0],
'my_eval': ['my_eval', 'Evaluate a PHP code (runs with some global variable accessible) ', [['libs','quests_util.php',25]], 1],
'get_qv_part': ['get_qv_part', 'Deprecated function ', [['libs','quests_util.php',290]], 0],
'get_quest_var_part': ['get_quest_var_part', 'Deprecated function ', [['libs','quests_util.php',325]], 1],
'kill_player': ['kill_player', 'Kills the player. ', [['libs','quests_util.php',692]], 0],
'quest_error': ['quest_error', 'Error handler used with the dialogs ', [['libs','quests_util.php',6]], 0],
'add_mp': ['add_mp', 'Changes the player MP. ', [['libs','quests_util.php',673]], 0],
'macro_gain_experience': ['macro_gain_experience', 'Set the experience, level ', [['libs','quests_util.php',337]], 0],
'execute': ['execute', '', [['libs','db_conn_5.php',37],['libs','db_conn_4.php',37]], 652],
'is_date': ['is_date', 'Check if the date is exactly at a specified dd/mm ', [['libs','quests_util.php',840]], 0],
'add_journal': ['add_journal', 'Add a journal entry. ', [['libs','quests_util.php',491]], 0],
'add_hp': ['add_hp', 'Changes player HP. ', [['libs','quests_util.php',648]], 0],
'do_discussion': ['do_discussion', 'Show a dialog. ', [['libs','quests_util.php',37]], 3],
'set_qv_part': ['set_qv_part', 'Deprecated function. ', [['libs','quests_util.php',275]], 0],
'urlencode': ['urlencode', '', [], 34],
'substr': ['substr', '', [], 91],
'mt_rand': ['mt_rand', '', [], 102],
'ob_start': ['ob_start', '', [], 5],
'strpos': ['strpos', '', [], 28],
'getdate': ['getdate', '', [], 7],
'set_error_handler': ['set_error_handler', '', [], 5],
'exp': ['exp', '', [], 1],
'count': ['count', '', [], 113],
'str_replace': ['str_replace', '', [], 44],
'ob_end_clean': ['ob_end_clean', '', [], 6],
'ceil': ['ceil', '', [], 66],
'preg_replace': ['preg_replace', '', [], 1],
'str_pad': ['str_pad', '', [], 11]};
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:
quests util
quests util
Util js
group util ?lay
TSM UTIL
java util MissingResourceException
java util Properties
java util ListResourceBundle
map util
Package java util zip
java util zip Adler32
java util zip ZipInputStream
java util zip DeflaterOutputStream
image map util
java util zip InflaterInputStream
java util zip GZIPOutputStream
java util Vector
java util NoSuchElementException
java util zip CheckedOutputStream

więcej podobnych podstron