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 barkeeper.php

Documentation is available at barkeeper.php

  1. <?php
  2. /**
  3.  * 'Barkeeper' class to create a barkeeper serving free beer
  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: barkeeper.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 barkeeper serving free beer
  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 Barkeeper extends DpNpc
  45. {
  46.     /**
  47.      * Array to be filled with chat lines
  48.      */
  49.     private $mChat;
  50.  
  51.     /**
  52.      * Has it resetted before? TRUE if it hasn't.
  53.      */
  54.     private $mFirstReset TRUE;
  55.  
  56.     /**
  57.      * Sets up the NPC at object creation time
  58.      */
  59.     public function createDpNpc()
  60.     {
  61.         // Standard setup calls:
  62.         $this->addId(explode('#'dp_text('barkeeper')));
  63.         $this->title dp_text('barkeeper');
  64.         $this->titleDefinite dp_text('the barkeeper');
  65.         $this->titleIndefinite dp_text('a barkeeper');
  66.         $this->titleImg DPUNIVERSE_IMAGE_URL 'barkeeper.gif';
  67.         $this->titleImgWidth 58;
  68.         $this->titleImgHeight 100;
  69.         $this->body '<img src="' DPUNIVERSE_IMAGE_URL
  70.             . 'barkeeper_body.gif" width="116" height="200" border="0" alt="" '
  71.             . 'align="left" style="margin-right: 15px" />'
  72.             . dp_text('The barkeeper is serving free beer!<br />');
  73.  
  74.         // Sets up chat lines:
  75.         $this->mChat array(
  76.             dp_text('The barkeeper says: Today free beer for everybody!<br />'),
  77.             dp_text('The barkeeper hiccups.<br />'),
  78.             dp_text('The barkeeper drinks a cool, fresh beer.<br />'),
  79.             dp_text('The barkeeper says: Hello there.<br />'),
  80.             dp_text('The barkeeper stumbles, seems to fall, but takes a step and recovers.<br />'),
  81.             dp_text('The barkeeper says: Why don\'t you have a beer with me?<br />'));
  82.  
  83.         // Fetch beer in a few seconds:
  84.         $this->setTimeout('timeoutMakeNewBeer'4);
  85.     }
  86.  
  87.     /**
  88.      * Makes new beer
  89.      */
  90.     function resetDpNpc()
  91.     {
  92.         if ($this->mFirstReset{
  93.             $this->mFirstReset FALSE;
  94.             return;
  95.         }
  96.         $this->actionShout(dp_text('shout'),
  97.             dp_text('Today free beer in the bar for everyone!'));
  98.         $this->timeoutMakeNewBeer();
  99.     }
  100.  
  101.     /**
  102.      * Checks for dropped empty glasses using EVENT_ENTERED_ENV event
  103.      *
  104.      * If an empty glass was dropped in the environment of the barkeeper,
  105.      * calls {@link timeoutCheckEmptyGlasses()} in 4 seconds.
  106.      *
  107.      * @param   boolean $name       name of event
  108.      * @see     timeoutCheckEmptyGlasses()
  109.      */
  110.     function eventDpNpc($name)
  111.     {
  112.         // Do something when someone drops an empty glass on this page:
  113.         if (EVENT_ENTERED_ENV === $name{
  114.             $ob func_get_arg(1);
  115.             if ($ob->isId(dp_text('glass'))
  116.                     && FALSE === $ob->isFull{
  117.                 $this->setTimeout('timeoutCheckEmptyGlasses'4);
  118.             }
  119.         }
  120.     }
  121.  
  122.     /**
  123.      * Removes empty glasses from the environment of this barkeeper
  124.      *
  125.      * Makes the barkeeper carry away empty glasses, calls
  126.      * {@link timeoutMakeNewBeer()} in 4 seconds.
  127.      *
  128.      * @see     event(), timeoutMakeNewBeer()
  129.      */
  130.     function timeoutCheckEmptyGlasses()
  131.     {
  132.         if (FALSE === ($env $this->getEnvironment())) {
  133.             return;
  134.         }
  135.         $inv $env->getInventory();
  136.         $count 0;
  137.         foreach ($inv as &$ob{
  138.             if ($ob->isId(dp_text('glass')) && FALSE === $ob->isFull{
  139.                 $ob->removeDpObject();
  140.                 $count++;
  141.             }
  142.         }
  143.  
  144.         if ($count 0{
  145.             if ($count 2{
  146.                 $env->tell(dp_text('The barkeeper notices the empty beer glass and carries it away.<br />'));
  147.             else {
  148.                 $env->tell(dp_text('The barkeeper notices the empty beer glasses and carries them away.<br />'));
  149.             }
  150.  
  151.             $this->setTimeout('timeoutMakeNewBeer'4);
  152.         }
  153.     }
  154.  
  155.     /**
  156.      * Makes the barkeeper serve new beer if there aren't enough around
  157.      *
  158.      * Makes sure there are at least 4 beers in the barkeeper's environment.
  159.      *
  160.      * @see     timeoutCheckEmptyGlasses()
  161.      */
  162.     function timeoutMakeNewBeer()
  163.     {
  164.         if (FALSE === ($env $this->getEnvironment())) {
  165.             return;
  166.         }
  167.         $inv $env->getInventory();
  168.         $nr_of_beers 0;
  169.         foreach ($inv as &$ob{
  170.             if ($ob->isId(dp_text('glass')) && FALSE !== $ob->isFull{
  171.                 $nr_of_beers++;
  172.             }
  173.         }
  174.         $nr_of_beers $nr_of_beers;
  175.         if ($nr_of_beers 0{
  176.             $served_beers $nr_of_beers;
  177.             while ($nr_of_beers 0{
  178.                 $beer_obj get_current_dpuniverse()->newDpObject(
  179.                     DPUNIVERSE_STD_PATH 'DpDrink.php');
  180.  
  181.                 $beer_obj->addId(explode('#',
  182.                     dp_text('beer#cool beer#fresh beer#cool fresh beer#cool,fresh beer#cool, fresh beer#glass')));
  183.                 $beer_obj->title dp_text('cool, fresh beer');
  184.                 $beer_obj->titleDefinite dp_text('the cool, fresh beer');
  185.                 $beer_obj->titleIndefinite dp_text('a cool, fresh beer');
  186.                 $beer_obj->titleImg DPUNIVERSE_IMAGE_URL 'beer_full.gif';
  187.                 $beer_obj->titleImgWidth 33;
  188.                 $beer_obj->titleImgHeight 50;
  189.                 $beer_obj->body '<img src="' DPUNIVERSE_IMAGE_URL
  190.                     . 'beer_full_body.gif" width="88" height="132" alt="" '
  191.                     . 'border="0" align="left" style="margin-right: 20px"/>'
  192.                     . dp_text('A cool, fresh beer.<br />');
  193.  
  194.                 $beer_obj->setEmptyIds(explode('#',
  195.                     dp_text('glass#beer glass#empty glass#empty beer glass')));
  196.                 $beer_obj->setEmptyTitle(dp_text('empty beer glass'));
  197.                 $beer_obj->setEmptyTitleDefinite(
  198.                     dp_text('the empty beer glass'));
  199.                 $beer_obj->setEmptyTitleIndefinite(
  200.                     dp_text('an empty beer glass'));
  201.                 $beer_obj->setEmptyTitleImg(DPUNIVERSE_IMAGE_URL
  202.                     . 'beer_empty.gif');
  203.                 $beer_obj->setEmptyBody('<img src="' DPUNIVERSE_IMAGE_URL
  204.                     . 'beer_empty_body.gif" width="88" height="132" alt="" '
  205.                     . 'border="0" align="left" style="margin-right: 20px"/>'
  206.                     . dp_text('An empty beer glass.<br />'));
  207.  
  208.                 $beer_obj->moveDpObject($env);
  209.                 $nr_of_beers--;
  210.             }
  211.  
  212.             if ($served_beers == 1{
  213.                 $env->tell(dp_text('The barkeeper serves a new beer. Be quick and get your free beer before it\'s gone!<br />'));
  214.             else {
  215.                 $env->tell(dp_text('The barkeeper serves some new beers. Be quick and get your free beer before it\'s gone!<br />'));
  216.             }
  217.         }
  218.     }
  219.  
  220.     /**
  221.      * Called each 'heartbeat', randomly chat and perform actions
  222.      */
  223.     function timeoutHeartBeat()
  224.     {
  225.         if (== mt_rand(17&& FALSE !== ($env $this->getEnvironment())) {
  226.             $env->tell($this->mChat[mt_rand(0sizeof($this->mChat1)]);
  227.             if (== mt_rand(13)) {
  228.                 $this->actionTake(dp_text('get')dp_text('beer'));
  229.             elseif (50 == mt_rand(5051)) {
  230.                 $this->actionDrop(dp_text('drop')dp_text('all'));
  231.             }
  232.         }
  233.         DpNpc::timeoutHeartBeat();
  234.     }
  235. }
  236. ?>

Documentation generated on Mon, 03 Sep 2007 22:18:35 +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.