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

Source for file DpNpc.php

Documentation is available at DpNpc.php

  1. <?php
  2. /**
  3.  * A 'non playing character', a bot
  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_std
  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: DpNpc.php 278 2007-08-19 22:52:25Z ls $
  18.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  19.  * @see        DpLiving
  20.  */
  21.  
  22. /**
  23.  * Builts upon the standard DpLiving class
  24.  */
  25. inherit(DPUNIVERSE_STD_PATH 'DpLiving.php');
  26.  
  27. /**
  28.  * A 'non playing character', a bot
  29.  *
  30.  * Creates the following DutchPIPE properties:<br />
  31.  *
  32.  * - boolean <b>isNpc</b> - Set to TRUE
  33.  *
  34.  * @package    DutchPIPE
  35.  * @subpackage dpuniverse_std
  36.  * @author     Lennert Stock <ls@dutchpipe.org>
  37.  * @copyright  2006, 2007 Lennert Stock
  38.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  39.  * @version    Release: 0.2.1
  40.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  41.  * @see        DpLiving
  42.  */
  43. class DpNpc extends DpLiving
  44. {
  45.     /**
  46.      * Creates this NPC
  47.      *
  48.      * Called by DpLiving when this object is created.
  49.      *
  50.      * Calls {@link createDpNpc()} in the inheriting class.
  51.      *
  52.      * @access     private
  53.      * @see        createDpNpc()
  54.      */
  55.     final function createDpLiving()
  56.     {
  57.         // Standard setup calls to set some default values:
  58.         $this->addId(dp_text('npc'));
  59.         $this->setTitle(dp_text('NPC'));
  60.         $this->setTitleDefinite(dp_text('the NPC'));
  61.         $this->setTitleIndefinite(dp_text('a NPC'));
  62.         $this->setTitleImg(DPUNIVERSE_IMAGE_URL 'npc.gif');
  63.         $this->isNpc new_dp_property(TRUE);
  64.  
  65.         // Call CreateDpNpc for objects that extend on this object:
  66.         $this->createDpNpc();
  67.     }
  68.  
  69.     /**
  70.      * Sets this NPC up at the time it is created
  71.      *
  72.      * An empty function which can be redefined by the NPC class extending on
  73.      * DpNpc. When the object is created, it has no title, HTML body, et cetera,
  74.      * so in this method methods like {@link DpObject::setTitle()} are called.
  75.      *
  76.      * @see        resetDpNpc()
  77.      */
  78.     function createDpNpc()
  79.     {
  80.     }
  81.  
  82.     /**
  83.      * Resets this NPC
  84.      *
  85.      * Called by DpLiving at regular intervals as defined in dpuniverse-ini.php.
  86.      * Calls the method 'resetDpNpc' in this NPC. You can redefine that function
  87.      * to periodically do stuff such as alter the state of this NPC.
  88.      *
  89.      * @access     private
  90.      * @see        resetDpNpc()
  91.      */
  92.     final function resetDpLiving()
  93.     {
  94.         $this->resetDpNpc();
  95.     }
  96.  
  97.     /**
  98.      * Resets this NPC
  99.      *
  100.      * Called by this NPC at regular intervals as defined in dpuniverse-ini.php.
  101.      * An empty function which can be redefined by the NPC class extending on
  102.      * DpNpc. To be used to periodically do stuff such as alter the state of the
  103.      * NPC.
  104.      *
  105.      * @see        createDpNpc()
  106.      */
  107.     function resetDpNpc()
  108.     {
  109.     }
  110.  
  111.     function eventDpLiving($name)
  112.     {
  113.         $args func_get_args();
  114.         call_user_func_array(array($this'eventDpNpc')$args);
  115.     }
  116.  
  117.     function eventDpNpc($name)
  118.     {
  119.     }
  120.  
  121.     /**
  122.      * Tells data (message, window, location, ...) to this NPC
  123.      *
  124.      * Tells a message to this NPC, for instance a chat line or a new location.
  125.      *
  126.      * @param      string    $data      message string
  127.      * @see        DpObject::tell(), DpUser::tell(), DpPage::tell()
  128.      */
  129.     function tell($data)
  130.     {
  131.         if (empty($data)) {
  132.             return;
  133.         }
  134.  
  135.         if (is_array($data)) {
  136.             $data $data[$this->displayMode];
  137.         }
  138.         if (dp_strlen($data>=&& dp_substr($data01== '<'
  139.                 && FALSE !== ($pos dp_strpos($data'>'))) {
  140.             $type dp_substr($data1$pos 1);
  141.             $endpos dp_strrpos($data'<');
  142.             $data "<$type><![CDATA[dp_substr($datadp_strlen($type2,
  143.                 $endpos dp_strlen($type2']]>'
  144.                 . dp_substr($data$endpos);
  145.         else {
  146.             $type 'message';
  147.             $data "<message><![CDATA[$data]]></message>";
  148.         }
  149.         if (dp_strlen($data19
  150.                 && FALSE !== ($pos1 dp_strpos($data'<location><![CDATA['))
  151.                 && FALSE !== ($pos2 dp_strpos($data']]></location>'))
  152.                 && $pos2 $pos1 14{
  153.             $data dp_substr($data0$pos2);
  154.             $data dp_substr($data$pos1 19);
  155.             $newlocation $data;
  156.             if (!$newlocation || '/' === $newlocation{
  157.                 $newlocation DPUNIVERSE_PAGE_PATH 'index.php';
  158.             }
  159.             $newlocation get_current_dpuniverse()->getDpObject($newlocation);
  160.             if (FALSE === ($env $this->getEnvironment())
  161.                     || $env !== $newlocation{
  162.                 if (!$env{
  163.                     $from_where sprintf(dp_text("%s enters the site.<br />"),
  164.                         ucfirst($this->getTitle(
  165.                         DPUNIVERSE_TITLE_TYPE_DEFINITE)));
  166.                 else {
  167.                     $env->tell(sprintf(dp_text("%s leaves to %s.<br />"),
  168.                         ucfirst($this->getTitle(
  169.                         DPUNIVERSE_TITLE_TYPE_DEFINITE)),
  170.                         $newlocation->getTitle())$this);
  171.                     $from_where sprintf(dp_text("%s arrives from %s.<br />"),
  172.                         ucfirst($this->getTitle(
  173.                         DPUNIVERSE_TITLE_TYPE_DEFINITE))$env->getTitle());
  174.                 }
  175.                 $this->moveDpObject($newlocation);
  176.                 $newlocation->tell($from_where$this);
  177.             }
  178.         }
  179.     }
  180. }
  181. ?>

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

Click me!
Guest#215
 
 
 
  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.