<?php
class Room extends GameObject
{
private $characters; // Array of Character objects //
private $x;
private $y;
private $mapColor;
private $mapImage;
function __construct($eid, $name, $desc, $x, $y)
{
parent::__construct($eid, $name, $desc, GO_TYPE_ROOM);
$this->x = $x;
$this->y = $y;
$this->loadToCache();
}
function loadToCache()
{
setRoomMem($this);
}
// Overrides parent::getDescription so we can include the characters (a dynamic list) //
function getDescription($cEID=0)
{
if ($this->getPlayerList($cEID) != "")
$c_desc = " Looking around, you see {$this->getPlayerList($cEID)}.";
return parent::getDescription() . $c_desc;
}
function addCharacter($char)
{
if (!is_array($this->characters)) $this->characters = array();
$this->characters[$char->getEID()] = $char->getEID();
$this->loadToCache();
}
function removeCharacter($char)
{
unset($this->characters[$char->getEID()]);
$this->loadToCache();
}
function getCharacters()
{
$i = array();
foreach($this->characters as $key => $eid)
{
$i[$key] = getCharMem($eid);
}
return $i;
}
function getPlayerList($entityID)
{
// Get the latest "version" of each character standing here //
// Grabs from cache to account for status changes, etc. //
$pArray = $this->getCharacters();
$pList = "";
foreach ($pArray as $key => $player)
{
if ($player->getEID() != $entityID)
{
$pList .= "{$player->getName()}, ";
}
}
if ($pList != "")
{
$pList = rtrim($pList, ", ");
$pList = "<font color=#ffffff>$pList</font>";
}
return $pList;
}
function getPlayerListTable($pEID)
{
$pArray = $this->getCharacters();
if (count($pArray)-1 == 0) return " ";
$first = true;
foreach ($pArray as $key => $player)
{
if ($player->getEID() != $pEID) // If it's not the player looking at the room //
{
if (!$first) $border = 'border-top: 1px solid #fff;';
else $border = 'border: 0xp;';
$pTable .= "<div style='align: left; margin: 5px 3px;'>"
. "<a href='javascript:void(0);' onmouseover='expandHeight("$key");' onmouseout='shrinkHeight("$key");'>"
. $dir . ucfirst($player->getName())
. "</a><br>"
. "<div id='$key' style='position: absolute; width: 0; padding-top: 3px; visibility: hidden; overflow: hidden;'>"
. $player->getDescription() . "</font></i></div></div>";
}
}
return $pTable;
}
function getX()
{
return $this->x;
}
function getY()
{
return $this->y;
}
function getMapColor()
{
return $this->mapColor;
}
function getMapImageFilename()
{
return $this->mapImage;
}
// ****** Communication Features ****** //
// Send a message to all players in or watching the room (via socket connection) //
function send($message, $mType, $except=0)
{
$cList = $this->getCharacters();
foreach ($cList as $key => $char)
{
try {
if ($except == 0 || $char->getEID() != $except)
$char->send($message, $mType);
} catch (Exception $e)
{
echo "Failed to send to char [$key]: {$e->getMessage()}";
}
}
}
}
?>