TrackManiaControl/core/Callbacks/Structures/PlayerHitStructure.php

121 lines
2.4 KiB
PHP
Raw Normal View History

2014-10-10 14:40:00 +02:00
<?php
2015-06-18 17:12:44 +02:00
namespace ManiaControl\Callbacks\Structures;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
/**
2015-06-18 17:12:44 +02:00
* Structure Class for the Player Hit Callback
*
* @author ManiaControl Team <mail@maniacontrol.com>
2016-05-04 09:57:31 +02:00
* @copyright 2014-2016 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
2014-10-10 14:40:00 +02:00
class PlayerHitStructure {
2014-10-24 20:20:12 +02:00
/*
* Private properties
*/
2014-10-10 14:40:00 +02:00
private $shooter;
private $victim;
private $damage;
private $shooterPoints;
private $weapon;
2015-07-19 11:05:09 +02:00
private $hitDistance;
private $shooterPosition = 0;
private $victimPosition = 0;
private $shooterAimDirection = 0;
private $victimAimDirection = 0;
2014-10-10 14:40:00 +02:00
/** @var ManiaControl $maniaControl */
private $maniaControl;
2014-10-24 20:20:12 +02:00
/**
* Construct new Player Hit Structure
*
* @param ManiaControl $maniaControl
* @param array $data
*/
public function __construct(ManiaControl $maniaControl, array $data) {
$this->maniaControl = $maniaControl;
2014-10-10 14:40:00 +02:00
$this->shooter = $data[0];
$this->victim = $data[1];
$this->damage = $data[2];
$this->weapon = $data[3];
$this->shooterPoints = $data[4];
2015-07-19 11:05:09 +02:00
$this->hitDistance = $data[5];
2015-06-18 17:12:44 +02:00
2015-07-19 11:05:09 +02:00
//TODO remove key check in some months (got implemented 2015-05-03)
if (array_key_exists(6, $data)) {
$this->shooterPosition = $data[6];
}
if (array_key_exists(7, $data)) {
$this->victimPosition = $data[7];
}
if (array_key_exists(8, $data)) {
$this->shooterAimDirection = $data[8];
}
if (array_key_exists(9, $data)) {
$this->victimAimDirection = $data[9];
}
2014-10-10 14:40:00 +02:00
}
/**
2014-10-24 20:20:12 +02:00
* Get the shooter
*
* @return Player
2014-10-10 14:40:00 +02:00
*/
public function getShooter() {
2014-10-24 20:20:12 +02:00
return $this->maniaControl->getPlayerManager()->getPlayer($this->shooter);
2014-10-10 14:40:00 +02:00
}
/**
2014-10-24 20:20:12 +02:00
* Get the victim
*
* @return Player
2014-10-10 14:40:00 +02:00
*/
public function getVictim() {
2014-10-24 20:20:12 +02:00
return $this->maniaControl->getPlayerManager()->getPlayer($this->victim);
2014-10-10 14:40:00 +02:00
}
/**
2014-10-24 20:20:12 +02:00
* Get the damage
*
2014-10-10 14:40:00 +02:00
* @return int
*/
public function getDamage() {
2014-12-21 23:21:59 +01:00
return intval($this->damage);
2014-10-10 14:40:00 +02:00
}
/**
2014-10-24 20:20:12 +02:00
* Get the shooter points
*
2014-10-10 14:40:00 +02:00
* @return int
*/
public function getShooterPoints() {
2014-12-21 23:21:59 +01:00
return intval($this->shooterPoints);
2014-10-10 14:40:00 +02:00
}
/**
2014-10-24 20:20:12 +02:00
* Get the weapon
*
2014-10-10 14:40:00 +02:00
* @return int
*/
2014-10-24 20:20:12 +02:00
public function getWeapon() {
// TODO: any way of returning type "Weapon?"
2014-10-10 14:40:00 +02:00
return $this->weapon;
}
/**
* Get The Hit Distance
*
2014-12-21 23:21:59 +01:00
* @return double
*/
public function getHitDistance() {
2014-12-21 23:21:59 +01:00
return doubleval($this->hitDistance);
}
2014-10-24 20:20:12 +02:00
}