2010-08-28 22:05:41 -04:00
|
|
|
<?php
|
|
|
|
namespace Moserware\Skills;
|
|
|
|
|
|
|
|
require_once(dirname(__FILE__) . "/Guard.php");
|
|
|
|
require_once(dirname(__FILE__) . "/ISupportPartialPlay.php");
|
|
|
|
require_once(dirname(__FILE__) . "/ISupportPartialUpdate.php");
|
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Represents a player who has a Rating.
|
|
|
|
*/
|
2010-08-28 22:05:41 -04:00
|
|
|
class Player implements ISupportPartialPlay, ISupportPartialUpdate
|
|
|
|
{
|
|
|
|
const DEFAULT_PARTIAL_PLAY_PERCENTAGE = 1.0; // = 100% play time
|
|
|
|
const DEFAULT_PARTIAL_UPDATE_PERCENTAGE = 1.0; // = receive 100% update
|
|
|
|
|
|
|
|
private $_Id;
|
|
|
|
private $_PartialPlayPercentage;
|
|
|
|
private $_PartialUpdatePercentage;
|
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Constructs a player.
|
|
|
|
*
|
|
|
|
* @param mixed $id The identifier for the player, such as a name.
|
|
|
|
* @param number $partialPlayPercentage The weight percentage to give this player when calculating a new rank.
|
|
|
|
* @param number $partialUpdatePercentage Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update.
|
|
|
|
*/
|
2010-08-28 22:05:41 -04:00
|
|
|
public function __construct($id,
|
|
|
|
$partialPlayPercentage = self::DEFAULT_PARTIAL_PLAY_PERCENTAGE,
|
|
|
|
$partialUpdatePercentage = self::DEFAULT_PARTIAL_UPDATE_PERCENTAGE)
|
|
|
|
{
|
|
|
|
// If they don't want to give a player an id, that's ok...
|
|
|
|
Guard::argumentInRangeInclusive($partialPlayPercentage, 0.0, 1.0, "partialPlayPercentage");
|
|
|
|
Guard::argumentInRangeInclusive($partialUpdatePercentage, 0, 1.0, "partialUpdatePercentage");
|
|
|
|
$this->_Id = $id;
|
|
|
|
$this->_PartialPlayPercentage = $partialPlayPercentage;
|
|
|
|
$this->_PartialUpdatePercentage = $partialUpdatePercentage;
|
|
|
|
}
|
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* The identifier for the player, such as a name.
|
|
|
|
*/
|
2010-09-30 08:25:31 -04:00
|
|
|
public function &getId()
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2010-09-30 08:25:31 -04:00
|
|
|
$id = &$this->_Id;
|
2010-08-28 22:05:41 -04:00
|
|
|
return $this->_Id;
|
|
|
|
}
|
2010-10-08 21:44:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates the percent of the time the player should be weighted where 0.0 indicates the player didn't play and 1.0 indicates the player played 100% of the time.
|
|
|
|
*/
|
2010-08-28 22:05:41 -04:00
|
|
|
public function getPartialPlayPercentage()
|
|
|
|
{
|
|
|
|
return $this->_PartialPlayPercentage;
|
|
|
|
}
|
2010-10-08 21:44:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicated how much of a skill update a player should receive where 0.0 represents no update and 1.0 represents 100% of the update.
|
|
|
|
*/
|
2010-08-28 22:05:41 -04:00
|
|
|
public function getPartialUpdatePercentage()
|
|
|
|
{
|
|
|
|
return $this->_PartialUpdatePercentage;
|
|
|
|
}
|
2010-10-08 21:44:36 -04:00
|
|
|
|
2010-08-28 22:05:41 -04:00
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
if ($this->_Id != null)
|
|
|
|
{
|
2010-09-26 21:43:17 -04:00
|
|
|
return (string)$this->_Id;
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::__toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|