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

Documentation is available at shop.php

  1. <?php
  2. /**
  3.  * A Small Shop
  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://www.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_page
  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: shop.php 281 2007-08-20 21:45:53Z ls $
  18.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  19.  * @see        DpPage
  20.  */
  21.  
  22. /**
  23.  * Builts upon the standard DpPage class
  24.  */
  25. inherit(DPUNIVERSE_STD_PATH 'DpPage.php');
  26.  
  27. /**
  28.  * A Small Shop
  29.  *
  30.  * @package    DutchPIPE
  31.  * @subpackage dpuniverse_page
  32.  * @author     Lennert Stock <ls@dutchpipe.org>
  33.  * @copyright  2006, 2007 Lennert Stock
  34.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  35.  * @version    Release: 0.2.1
  36.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  37.  * @see        DpPage
  38.  */
  39. final class Shop extends DpPage
  40. {
  41.     /**
  42.      * Sets up the page at object creation time
  43.      */
  44.     public function createDpPage()
  45.     {
  46.         // Standard setup calls:
  47.         $this->title dp_text('A Small Shop');
  48.         $this->setBody('<img src="' DPUNIVERSE_IMAGE_URL 'shop.jpg"
  49. width="352" height="264" border="0" usemap="#shop_map" alt=""
  50. style="border: solid 1px black; margin-right: 10px" title="" alt=""
  51. align="left" />
  52. <div style="width: 220px; float: left">
  53. <br /><b>' dp_text('Small Shop''</b><br />'
  54.             . sprintf(dp_text('<p align="justify">You are in a small pawn shop
  55. where you can buy and sell things. Try this
  56. <a href="javascript:send_action2server(\'list\')">list</a> to view all items for
  57. sale. Check out your
  58. <a href="javascript: send_action2server(\'inventory\')">inventory</a> to see
  59. what you can sell.</p><p align="justify">An exit <a href="%s">west</a> leads
  60. back to the village square.</p>',
  61.             DPSERVER_CLIENT_URL '?location=/page/square.php')
  62.             . '</div><br clear="all" />')'text');
  63.         $this->setNavigationTrail(
  64.             array(DPUNIVERSE_NAVLOGO''),
  65.             array(dp_text('Showcases')DPUNIVERSE_PAGE_PATH
  66.             . 'showcases.php'));
  67.         $this->addExit(explode('#',
  68.             dp_text('w#square#out#exit#leave#leave shop')),
  69.             DPUNIVERSE_PAGE_PATH 'square.php'NULL,
  70.             array('shop_map''square_area''rect',
  71.             '0,20,50,244'dp_text('leave shop'))dp_text('leave shop'));
  72.         $this->addAction(dp_text('list')dp_text('list')'actionList',
  73.         $this->addAction(dp_text('sell')dp_text('sell')'actionSell',
  74.         $this->addAction(dp_text('buy')dp_text('buy')'actionBuy',
  75.         $this->addAction(dp_text('see')dp_text('see')'actionSee',
  76.  
  77.         $store get_current_dpuniverse()->getDpObject(DPUNIVERSE_PAGE_PATH
  78.             . 'store.php');
  79.         $store->addAction(dp_text('buy')dp_text('buy')'actionBuy',
  80.             DP_ACTION_OPERANT_MENUarray($storeDP_ACTION_TARGET_OBJINV),
  81.             DP_ACTION_AUTHORIZED_ALLarray($thisDP_ACTION_SCOPE_INVENTORY));
  82.         $store->addAction(dp_text('see')dp_text('see')'actionSee',
  83.             DP_ACTION_OPERANT_MENUarray($storeDP_ACTION_TARGET_OBJINV),
  84.             DP_ACTION_AUTHORIZED_ALLarray($thisDP_ACTION_SCOPE_INVENTORY));
  85.     }
  86.  
  87.     function eventDpPage($name)
  88.     {
  89.         if (EVENT_ENTERED_INV == $name{
  90.             $who func_get_arg(1);
  91.             $who->addAction(dp_text('sell')dp_text('sell')'actionSell',
  92.                 DP_ACTION_OPERANT_MENUDP_ACTION_TARGET_OBJINV,
  93.                 DP_ACTION_AUTHORIZED_ALLDP_ACTION_SCOPE_SELF);
  94.         elseif (EVENT_LEFT_INV == $name{
  95.             $who func_get_arg(1);
  96.             $who->removeAction('sell');
  97.         }
  98.     }
  99.  
  100.     /**
  101.      * Called at regular intervals
  102.      */
  103.     public function resetDpPage()
  104.     {
  105.         $this->makePresent(DPUNIVERSE_NPC_PATH 'shopkeeper.php');
  106.     }
  107.  
  108.     public function actionList($verb$noun)
  109.     {
  110.         $store get_current_dpuniverse()->getDpObject(DPUNIVERSE_PAGE_PATH
  111.             . 'store.php');
  112.  
  113.         $inventory $store->getAppearance(0TRUENULL,
  114.             get_current_dpobject()->displayMode-1'dpobinv');
  115.  
  116.         $title dp_text('The shop has the following items for sale:');
  117.         get_current_dpobject()->tell(
  118.             "<window name=\"list\">$title$inventory</window>");
  119.  
  120.         return TRUE;
  121.     }
  122.  
  123.     function filterAppearance($level&$from$appearance&$user)
  124.     {
  125.         if ($from[0]->getEnvironment(=== $user && === $level
  126.                 && !$from[0]->isNoSell{
  127.             $store get_current_dpuniverse()->getDpObject(DPUNIVERSE_PAGE_PATH
  128.                 . 'store.php');
  129.  
  130.             $appearance .= '<br /><a href="javascript:send_action2server(\''
  131.                 . sprintf(dp_text('sell %s')$from[0]->uniqueId'\')">'
  132.                 . sprintf(dp_text('sell for %d credits'),
  133.                 $store->getSellValue($from[0]->value)) '</a>';
  134.         }
  135.  
  136.         return $appearance;
  137.     }
  138.  
  139.     public function actionBuy($verb$noun)
  140.     {
  141.         $user get_current_dpuser();
  142.  
  143.         $store get_current_dpuniverse()->getDpObject(DPUNIVERSE_PAGE_PATH
  144.             . 'store.php');
  145.  
  146.         if (!($item $store->isPresent($noun))) {
  147.             $user->tell(sprintf(
  148.                 dp_text('That item ("%s") is not for sale here.<br />'),
  149.                 $noun));
  150.             return TRUE;
  151.         }
  152.  
  153.         $price $store->getBuyValue($item->value);
  154.  
  155.         if ($user->credits $price{
  156.             $user->tell(sprintf(
  157.                 dp_text("%s costs %d credits, which you don't have.<br />"),
  158.                 ucfirst($item->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE)),
  159.                 $price));
  160.             return TRUE;
  161.         }
  162.  
  163.         if (TRUE !== ($move_result $item->moveDpObject($user))) {
  164.             switch ($move_result{
  165.             case E_MOVEOBJECT_HEAVY:
  166.                 $err sprintf(
  167.                     dp_text("You cannot carry %s, it is too heavy. Drop something else first.<br />"),
  168.                     $item->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE));
  169.                 break;
  170.             case E_MOVEOBJECT_VOLUME:
  171.                 $err sprintf(
  172.                     dp_text("You cannot carry %s, it takes too much volume. Drop something else first.<br />"),
  173.                     $item->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE));
  174.                 break;
  175.             default:
  176.                 $err sprintf(
  177.                     dp_text("You fail to buy %s as it cannot be moved.<br />"),
  178.                     $item->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE));
  179.             }
  180.  
  181.             $user->tell($err);
  182.             return TRUE;
  183.         }
  184.  
  185.         $user->credits -= $price;
  186.         $user->tell(sprintf(dp_text("You buy %s for %d credits.<br />"),
  187.             $item->getTitle(DPUNIVERSE_TITLE_TYPE_INDEFINITE)$price));
  188.         if (($env $user->getEnvironment()) && $env === $this{
  189.             $this->tell(sprintf(dp_text("%s buys %s.<br />"),
  190.                 $user->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE),
  191.                 $item->getTitle(DPUNIVERSE_TITLE_TYPE_INDEFINITE))$user);
  192.         }
  193.         $user->tell('<refreshDpWindow name="list" action="' dp_text('list')
  194.             . '">&nbsp;</refreshDpWindow>');
  195.         $user->tell('<refreshDpWindow name="inventory" action="'
  196.             . dp_text('inventory''">&nbsp;</refreshDpWindow>');
  197.         return TRUE;
  198.     }
  199.  
  200.     public function actionSell($verb$noun)
  201.     {
  202.         $user get_current_dpuser();
  203.  
  204.         $store get_current_dpuniverse()->getDpObject(DPUNIVERSE_PAGE_PATH
  205.             . 'store.php');
  206.  
  207.         if (!($item $user->isPresent($noun))) {
  208.             $user->tell(sprintf(
  209.                 dp_text("You don't own that item (\"%s\").<br />")$noun));
  210.             return TRUE;
  211.         }
  212.  
  213.         if ($item->isDrink && $item->isFull{
  214.             $user->tell(dp_text("The shop doesn't accept filled glasses and liquids.<br />"));
  215.             return TRUE;
  216.         }
  217.  
  218.         if (== ($price $store->getSellValue($item->value))) {
  219.             $user->tell(sprintf(
  220.                 dp_text("%s has no value.<br />"),
  221.                 $item->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE)));
  222.             return TRUE;
  223.         }
  224.         if ($item->isNoStore{
  225.             $item->removeDpObject();
  226.         elseif ($item->isNoSell
  227.                 || TRUE !== ($move_result $item->moveDpObject($store))) {
  228.             $user->tell(sprintf(dp_text("%s cannot be sold.<br />"),
  229.                 $item->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE)));
  230.             return TRUE;
  231.         }
  232.  
  233.         $user->credits += $price;
  234.         $user->tell(sprintf(dp_text("You sell %s for %d credits.<br />"),
  235.             $item->getTitle(DPUNIVERSE_TITLE_TYPE_INDEFINITE)$price));
  236.         if (($env $user->getEnvironment()) && $env === $this{
  237.             $this->tell(sprintf(dp_text("%s sells %s.<br />"),
  238.                 $user->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE),
  239.                 $item->getTitle(DPUNIVERSE_TITLE_TYPE_INDEFINITE))$user);
  240.         }
  241.         return TRUE;
  242.     }
  243.  
  244.     /**
  245.      * Makes this living object examine an object
  246.      *
  247.      * @param   string  $verb       the action, "examine"
  248.      * @param   string  $noun       what to examine, could be empty
  249.      * @return  boolean TRUE for action completed, FALSE otherwise
  250.      */
  251.     function actionSee($verb$noun)
  252.     {
  253.         $user get_current_dpuser();
  254.  
  255.         if (!dp_strlen($noun)) {
  256.             $user->setActionFailure(dp_text('See what item for sale?<br />'));
  257.             return FALSE;
  258.         }
  259.  
  260.         $store get_current_dpuniverse()->getDpObject(DPUNIVERSE_PAGE_PATH
  261.             . 'store.php');
  262.  
  263.         if (!($item $store->isPresent($noun))) {
  264.             $user->tell(sprintf(
  265.                 dp_text('That item ("%s") is not for sale here.<br />')$noun));
  266.             return TRUE;
  267.         }
  268.  
  269.         $user->tell('<window>' $item->getAppearance(0TRUENULL,
  270.             $this->displayModeFALSE'dpobinv''</window>');
  271.         return TRUE;
  272.     }
  273. }
  274. ?>

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