Your browser must have JavaScript enabled in order to view this page.
 >  >
 
Welcome Guest#213 Login/register    Go to Bottom
Go to Top

Source for file drunk.php

Documentation is available at drunk.php

  1. <?php
  2. /**
  3.  * 'Drunk' class to create a drunk man carrying a golden key
  4.  *
  5.  * DutchPIPE version 0.4; PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
  8.  * If you did not receive a copy of the DutchPIPE license, you can obtain one at
  9.  * http://dutchpipe.org/license/1_0.txt or by sending a note to
  10.  * license@dutchpipe.org, in which case you will be mailed a copy immediately.
  11.  *
  12.  * @package    DutchPIPE
  13.  * @subpackage dpuniverse_npc
  14.  * @author     Lennert Stock <ls@dutchpipe.org>
  15.  * @copyright  2006, 2007 Lennert Stock
  16.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  17.  * @version    Subversion: $Id: drunk.php 308 2007-09-02 19:18:58Z ls $
  18.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  19.  * @see        DpNpc
  20.  */
  21.  
  22. /**
  23.  * Builts upon the standard DpNpc class
  24.  */
  25. inherit(DPUNIVERSE_STD_PATH 'DpNpc.php');
  26.  
  27. /**
  28.  * Gets event constants
  29.  */
  30. inherit(DPUNIVERSE_INCLUDE_PATH 'events.php');
  31.  
  32. /**
  33.  * A drunk man carrying a golden key
  34.  *
  35.  * @package    DutchPIPE
  36.  * @subpackage dpuniverse_npc
  37.  * @author     Lennert Stock <ls@dutchpipe.org>
  38.  * @copyright  2006, 2007 Lennert Stock
  39.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  40.  * @version    Release: 0.2.1
  41.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  42.  * @see        DpNpc
  43.  */
  44. final class Drunk extends DpNpc
  45. {
  46.     /**
  47.      * Array to be filled with chat lines
  48.      */
  49.     private $mChat;
  50.  
  51.     /**
  52.      * Key object
  53.      */
  54.     private $mrGoldenKeyObj;
  55.  
  56.     /**
  57.      * Array of livings that gave us non-beer objects
  58.      */
  59.     public $mGiven = array();
  60.  
  61.     /**
  62.      * Sets up the NPC at object creation time
  63.      */
  64.     public function createDpNpc()
  65.     {
  66.         // Standard setup calls:
  67.         $this->addId(explode('#'dp_text('drunk#man')));
  68.         $this->title dp_text('drunk man');
  69.         $this->titleDefinite dp_text('the drunk man');
  70.         $this->titleIndefinite dp_text('a drunk man');
  71.         $this->titleImg DPUNIVERSE_IMAGE_URL 'drunk.gif';
  72.         $this->titleImgWidth 60;
  73.         $this->titleImgHeight 100;
  74.  
  75.         $this->body '<img src="' DPUNIVERSE_IMAGE_URL
  76.             . 'drunk_body.gif" width="120" height="200" border="0" alt="" '
  77.             . 'align="left" style="margin-right: 15px" />'
  78.             . dp_text('A drunk man. He looks thirsty.<br />');
  79.  
  80.         // Sets up chat lines:
  81.         $this->mChat array(
  82.             dp_text('The drunk man says: *hIc* hEelLo thERe! *BuUrp*<br />'),
  83.             dp_text('The drunk man says: whAaaT I *HiC* NEed iS a dRInK!<br />'),
  84.             dp_text('The drunk man says: raaAAaH!<br />'));
  85.     }
  86.  
  87.     /**
  88.      * Called at regular intervals
  89.      */
  90.     public function resetDpNpc()
  91.     {
  92.         if (is_null($this->mrGoldenKeyObj)
  93.                 || !$this->isPresent($this->mrGoldenKeyObj)) {
  94.             // Creates a golden key based on the standard DpObject, moves it
  95.             // here:
  96.             $this->mrGoldenKeyObj get_current_dpuniverse()->newDpObject(
  97.                 DPUNIVERSE_STD_PATH 'DpObject.php');
  98.             $this->mrGoldenKeyObj->addId(dp_text('key'));
  99.             $this->mrGoldenKeyObj->title dp_text('golden key');
  100.             $this->mrGoldenKeyObj->titleDefinite dp_text('the golden key');
  101.             $this->mrGoldenKeyObj->titleIndefinite dp_text('a golden key');
  102.             $this->mrGoldenKeyObj->titleImg DPUNIVERSE_IMAGE_URL
  103.                 . 'golden_key.png';
  104.             $this->mrGoldenKeyObj->titleImgWidth 44;
  105.             $this->mrGoldenKeyObj->titleImgHeight 46;
  106.             $this->mrGoldenKeyObj->body '<img src="' DPUNIVERSE_IMAGE_URL
  107.                 . 'golden_key.png" width="44" height="46" border="0" '
  108.                 . 'alt="" align="left" style="margin-right: 15px" />'
  109.                 . dp_text('A golden key.<br />You wonder what it can unlock...');
  110.             $this->mrGoldenKeyObj->value 180;
  111.             $this->mrGoldenKeyObj->coinherit(DPUNIVERSE_STD_PATH 'mass.php');
  112.             $this->mrGoldenKeyObj->weight 1;
  113.             $this->mrGoldenKeyObj->volume 1;
  114.             $this->mrGoldenKeyObj->isNoStore new_dp_property(TRUE);
  115.             $this->mrGoldenKeyObj->moveDpObject($this);
  116.         }
  117.     }
  118.  
  119.  
  120.     /**
  121.      * Called each 'heartbeat', randomly chat and perform actions
  122.      */
  123.     function timeoutHeartBeat()
  124.     {
  125.         if (== mt_rand(17&& FALSE !== ($env $this->getEnvironment())) {
  126.             $env->tell($this->mChat[mt_rand(0sizeof($this->mChat1)]);
  127.         }
  128.  
  129.         DpNpc::timeoutHeartBeat();
  130.     }
  131.  
  132.    function eventDpNpc($name)
  133.     {
  134.         // Do something when someone drops an empty glass on this page:
  135.         if (EVENT_ENTERED_INV === $name{
  136.             $ob func_get_arg(1);
  137.             if ($ob->isId(dp_text('glass')) && TRUE === $ob->isFull{
  138.                 $this->setTimeout('timeoutCheckInventory'4);
  139.             else {
  140.                 $from func_get_arg(2);
  141.                 $this->mGiven[array($ob$from);
  142.                 $this->setTimeout('timeoutDrop'4);
  143.             }
  144.         }
  145.     }
  146.  
  147.     function timeoutCheckInventory()
  148.     {
  149.         if (FALSE === ($inv $this->getInventory())) {
  150.             return;
  151.         }
  152.         $inv $this->getInventory();
  153.         $count 0;
  154.         foreach ($inv as &$ob{
  155.             if ($ob->isId(dp_text('glass')) && TRUE === $ob->isFull{
  156.                 $this->performAction(dp_text('drink beer'));
  157.                 if (!$ob->isFull{
  158.                     $this->performAction(
  159.                         dp_text('say thAT\'S muCH *Hic* BEtTer!'));
  160.                     $this->setTimeout('timeoutDropKey'4);
  161.                 }
  162.             }
  163.         }
  164.     }
  165.  
  166.     function timeoutDropKey()
  167.     {
  168.         if ($this->isPresent(dp_text('golden key'))) {
  169.             $this->performAction(
  170.                 dp_text('say pErhAPs yOU hAvE a *BuUURp* USe foR thIS?'));
  171.             $this->performAction(dp_text('drop golden key'));
  172.         }
  173.     }
  174.  
  175.     function timeoutDrop()
  176.     {
  177.         foreach ($this->mGiven as $item_data{
  178.             $ob $item_data[0];
  179.             $from $item_data[1];
  180.  
  181.             if ($this->getEnvironment()->isPresent($from)
  182.                     && $this->isPresent($ob)) {
  183.                 $this->performAction(
  184.                     dp_text('say tHanX *bUUrp* bUu-UUUt I doN\'T NEed tHaT! *hIC*'));
  185.                 $this->performAction(sprintf(dp_text("give %s to %s"),
  186.                     $ob->getTitle(DPUNIVERSE_TITLE_TYPE_NAME),
  187.                     $from->getTitle(DPUNIVERSE_TITLE_TYPE_NAME)));
  188.            }
  189.         }
  190.         $this->mGiven = array();
  191.     }
  192. }
  193. ?>

Documentation generated on Mon, 03 Sep 2007 22:21:28 +0200 by phpDocumentor 1.3.0RC6

Click me!
Guest#213
 
 
 
  Go to Top
 
 
Input Field OptionsClose Input Field Go to Top
 
Legal Notices | Copyright © 2006, 2007 Lennert Stock. All rights reserved. Last update: Mon Sep 03 2007, 21:50 CET.