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

Documentation is available at mobile.php

  1. <?php
  2. /**
  3.  * 'Mobile' class to create a mobile computer generated character
  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: mobile.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 mobile computer generated character
  34.  *
  35.  * Creates the following DutchPIPE properties:<br />
  36.  *
  37.  * - boolean <b>isSilent</b> - Set to FALSE
  38.  * - boolean <b>isNoCleanUp</b> - Set to TRUE
  39.  *
  40.  * @package    DutchPIPE
  41.  * @subpackage dpuniverse_npc
  42.  * @author     Lennert Stock <ls@dutchpipe.org>
  43.  * @copyright  2006, 2007 Lennert Stock
  44.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  45.  * @version    Release: 0.2.1
  46.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  47.  * @see        DpNpc
  48.  */
  49. final class Mobile extends DpNpc
  50. {
  51.     /**
  52.      * Array to be filled with chat lines
  53.      */
  54.     private $mChat;
  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('mobile#npc#mobile npc'));
  63.         $this->title dp_text('mobile NPC');
  64.         $this->titleDefinite dp_text('the mobile NPC');
  65.         $this->titleIndefinite dp_text('a mobile NPC');
  66.         $this->titleImg DPUNIVERSE_IMAGE_URL 'npc.gif';
  67.         $this->titleImgWidth 66;
  68.         $this->titleImgHeight 100;
  69.  
  70.         $this->body =
  71.             dp_text('A mobile computer generated character that runs around the website.<br />');
  72.         $this->addAction(dp_text('kick')dp_text('kick')'actionKick',
  73.         $this->addAction(array(dp_text('admin')dp_text('silence'))'silence',
  74.             'actionSilence'DP_ACTION_OPERANT_MENUDP_ACTION_TARGET_SELF,
  75.         $this->isSilent new_dp_property(FALSE);
  76.         $this->isNoCleanUp new_dp_property(TRUE);
  77.  
  78.         // Sets up chat lines:
  79.         $this->mChat array(
  80.             dp_text("The mobile NPC says: This is sooo depressing.<br />"),
  81.             dp_text("The mobile NPC says: How boring.<br />"),
  82.             dp_text("The mobile NPC says: Oh this is so exciting.<br />"));
  83.     }
  84.  
  85.     /**
  86.      * Called each 'heartbeat', randomly chat and wander
  87.      */
  88.     function timeoutHeartBeat()
  89.     {
  90.         if (!$this->isSilent{
  91.             // :KLUDGE: mt_rand behaves badly with small nummers on some
  92.             // systems, 30 is added/reduced everywhere
  93.             if (FALSE !== ($env $this->getEnvironment())) {
  94.                 $env_is_bar $env->location === (DPUNIVERSE_PAGE_PATH
  95.                     . 'bar.php');
  96.  
  97.                 if ($env_is_bar{
  98.                     for ($max 10;
  99.                             $this->isPresent(dp_text('glass')) && $max--{
  100.                         $this->performAction(dp_text('drop glass'));
  101.                     }
  102.                 }
  103.  
  104.                 if (35 === mt_rand(3040)) {
  105.                     $env->tell($this->mChat[mt_rand(0,
  106.                         sizeof($this->mChat1)]);
  107.                 }
  108.                 elseif (38 === mt_rand(30,51)) {
  109.                     $this->randomWalk();
  110.                 }
  111.                 elseif ((33 === mt_rand(3040)) && FALSE === $env_is_bar
  112.                         && FALSE == $this->isPresent(dp_text('glass 4'))) {
  113.                     if ($env->isPresent(dp_text('glass'))) {
  114.                         $this->performAction(
  115.                             dp_text('say What a mess, and who has to clean it up? Yes...'));
  116.                         $this->performAction(dp_text('get glass'));
  117.                     }
  118.                 }
  119.             }
  120.         }
  121.         DpNpc::timeoutHeartBeat();
  122.     }
  123.  
  124.     /**
  125.      * Leaves through a random link
  126.      */
  127.      function randomWalk()
  128.      {
  129.         if (FALSE === ($env $this->getEnvironment())
  130.                 || !method_exists($env'getExits')
  131.                 || !($exits $env->getExits())
  132.                 || !($exits_cnt count($exits))) {
  133.             return;
  134.         }
  135.         $keys array_keys($exits);
  136.         $i 0;
  137.         do {
  138.             $rnd mt_rand(3030 ($exits_cnt 1)) 30;
  139.             $rnd_link $keys[mt_rand(0$exits_cnt 1)];
  140.             if ($i++ > 9{
  141.                 return;
  142.             }
  143.         while ($rnd_link === dp_text('login'));
  144.         if ($rnd_link[0=== DPUNIVERSE_NAVLOGO{
  145.             $linkcommand dp_text('home');
  146.         else {
  147.             $linkcommand explode(' '$rnd_link);
  148.             $linkcommand dp_strtolower($rnd_link);
  149.         }
  150.         $this->performAction($linkcommand);
  151.     }
  152.  
  153.     /**
  154.      * Gives the mobile a good hard kick!
  155.      *
  156.      * @param   string  $verb       the action, "kick"
  157.      * @param   string  $noun       who to kick, could be empty
  158.      * @return  boolean TRUE for action completed, FALSE otherwise
  159.      */
  160.     function actionKick($verb$noun)
  161.     {
  162.         $living get_current_dpobject();
  163.  
  164.         if (!dp_strlen($noun)) {
  165.             $living->setActionFailure(dp_text('Kick who?<br />'));
  166.             return FALSE;
  167.         }
  168.  
  169.         if (FALSE === ($env $this->getEnvironment())) {
  170.             return FALSE;
  171.         }
  172.  
  173.         if (!$this->isId($noun)) {
  174.             $living->setActionFailure(ucfirst(sprintf(
  175.                 dp_text('%s is not here.<br />')$noun)));
  176.             return FALSE;
  177.         }
  178.  
  179.         $living->tell(sprintf(dp_text('You give %s a good hard kick!<br />'),
  180.             $this->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE)));
  181.         $env->tell(sprintf(dp_text('%s gives %s a good hard kick!<br />'),
  182.             $living->getTitle(),
  183.             $this->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE))$living);
  184.         $this->tell($living->getTitle(sprintf(dp_text(
  185.             '%s gives you a good hard kick!<br/>'),
  186.             DPUNIVERSE_TITLE_TYPE_DEFINITE)));
  187.         $env->tell('<window autoclose="2500" styleclass="dpwindow_drink">'
  188.             . '<div style="text-align: center"><h1>' dp_text('*KICK*')
  189.             . '</h1></div></window>');
  190.  
  191.         // Fetch beer in a few seconds:
  192.         $this->setTimeout('timeoutKicked'3);
  193.  
  194.         return TRUE;
  195.     }
  196.  
  197.     /**
  198.      * Makes the mobile complain and take a random exit
  199.      */
  200.     function timeoutKicked()
  201.     {
  202.         $this->performAction(
  203.             dp_text("say Oh, ok, I know when I'm not wanted."));
  204.         $this->randomWalk();
  205.     }
  206.  
  207.     /**
  208.      * Toggles between silent/talking&moving mode, admininistators only
  209.      *
  210.      * @param   string  $verb       the action, "silence!"
  211.      * @param   string  $noun       who to silence, could be empty
  212.      * @return  boolean TRUE for action completed, FALSE otherwise
  213.      */
  214.     function actionSilence($verb$noun)
  215.     {
  216.         $living get_current_dpobject();
  217.  
  218.         if (!dp_strlen($noun)) {
  219.             $living->setActionFailure(dp_text('Silence who?<br />'));
  220.             return FALSE;
  221.         }
  222.  
  223.         if (FALSE === ($env $this->getEnvironment())) {
  224.             return FALSE;
  225.         }
  226.  
  227.         if (!$this->isId($noun)) {
  228.             $living->setActionFailure(sprintf(dp_text('%s is not here.<br />'),
  229.                 ucfirst($noun)));
  230.             return FALSE;
  231.         }
  232.  
  233.         $this->isSilent !$this->isSilent;
  234.  
  235.         if ($this->isSilent{
  236.             $living->tell(sprintf(dp_text('You silence %s.<br />'),
  237.                 $this->getTitle()));
  238.             $env->tell(sprintf(dp_text('%s silences %s.<br />'),
  239.                 $living->getTitle()$this->getTitle())$living);
  240.             $this->tell(sprintf(dp_text('%s silences you.<br/>'),
  241.                 $living->getTitle()));
  242.         else {
  243.             $living->tell(sprintf(dp_text('You allow %s to talk again.<br />'),
  244.                 $this->getTitle()));
  245.             $env->tell(sprintf(dp_text('%s allows %s to talk again.<br />'),
  246.                 $living->getTitle()$this->getTitle())$living);
  247.             $this->tell(sprintf(dp_text('%s allows you to talk again.<br/>'),
  248.                 $living->getTitle()));
  249.         }
  250.  
  251.         return TRUE;
  252.     }
  253. }
  254. ?>

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