2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DNW\Skills;
|
2010-08-28 22:05:41 -04:00
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Represents a player who has a Rating.
|
|
|
|
*/
|
2022-07-05 16:21:06 +02:00
|
|
|
class Player implements ISupportPartialPlay, ISupportPartialUpdate, \Stringable
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2023-08-01 14:02:12 +00:00
|
|
|
private const DEFAULT_PARTIAL_PLAY_PERCENTAGE = 1.0; // = 100% play time
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2023-08-01 14:02:12 +00:00
|
|
|
private const DEFAULT_PARTIAL_UPDATE_PERCENTAGE = 1.0;
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2023-08-02 10:10:57 +00:00
|
|
|
private float $PartialPlayPercentage;
|
2022-07-05 15:55:47 +02:00
|
|
|
|
2023-08-02 10:10:57 +00:00
|
|
|
private float $PartialUpdatePercentage;
|
2010-08-28 22:05:41 -04:00
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* Constructs a player.
|
2016-05-24 14:10:39 +02:00
|
|
|
*
|
2023-08-02 09:04:56 +00:00
|
|
|
* @param mixed $Id The identifier for the player, such as a name.
|
2023-08-02 10:10:57 +00:00
|
|
|
* @param float $partialPlayPercentage The weight percentage to give this player when calculating a new rank.
|
|
|
|
* @param float $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-10-08 21:44:36 -04:00
|
|
|
*/
|
2023-08-01 13:53:19 +00:00
|
|
|
public function __construct(
|
2023-08-02 10:10:57 +00:00
|
|
|
private mixed $Id,
|
|
|
|
float $partialPlayPercentage = self::DEFAULT_PARTIAL_PLAY_PERCENTAGE,
|
|
|
|
float $partialUpdatePercentage = self::DEFAULT_PARTIAL_UPDATE_PERCENTAGE
|
2023-08-01 13:53:19 +00:00
|
|
|
) {
|
2010-08-28 22:05:41 -04:00
|
|
|
// If they don't want to give a player an id, that's ok...
|
2022-07-05 15:55:47 +02:00
|
|
|
Guard::argumentInRangeInclusive($partialPlayPercentage, 0.0, 1.0, 'partialPlayPercentage');
|
|
|
|
Guard::argumentInRangeInclusive($partialUpdatePercentage, 0, 1.0, 'partialUpdatePercentage');
|
2023-08-01 14:02:12 +00:00
|
|
|
$this->PartialPlayPercentage = $partialPlayPercentage;
|
|
|
|
$this->PartialUpdatePercentage = $partialUpdatePercentage;
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
|
|
|
|
2010-10-08 21:44:36 -04:00
|
|
|
/**
|
|
|
|
* The identifier for the player, such as a name.
|
|
|
|
*/
|
2023-08-02 10:10:57 +00:00
|
|
|
public function getId(): mixed
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2023-08-01 14:02:12 +00:00
|
|
|
return $this->Id;
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
2016-05-24 14:10:39 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
2023-08-02 10:10:57 +00:00
|
|
|
public function getPartialPlayPercentage(): float
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2023-08-01 14:02:12 +00:00
|
|
|
return $this->PartialPlayPercentage;
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
2016-05-24 14:10:39 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
2023-08-02 10:10:57 +00:00
|
|
|
public function getPartialUpdatePercentage(): float
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2023-08-01 14:02:12 +00:00
|
|
|
return $this->PartialUpdatePercentage;
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
2016-05-24 14:10:39 +02:00
|
|
|
|
2022-07-05 16:21:06 +02:00
|
|
|
public function __toString(): string
|
2010-08-28 22:05:41 -04:00
|
|
|
{
|
2023-08-01 14:02:12 +00:00
|
|
|
return (string) $this->Id;
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|