1: <?php
2: namespace aliuly\killrate\api;
3:
4: use aliuly\killrate\Main as KillRatePlugin;
5: use pocketmine\IPlayer;
6:
7: 8: 9:
10: class KillRate {
11: protected $plugin;
12: 13: 14:
15: public function __construct(KillRatePlugin $owner) {
16: $this->plugin = $owner;
17: }
18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: public function getRankings($limit=10,$online=false,$col = "points") {
29: return $this->plugin->getRankings($limit,$online,$col);
30: }
31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41:
42: public function getRankedScores($limit=10,$online=false,$col = "points") {
43: $tab = $this->plugin->getRankings($limit,$online,$col);
44: $res = [];
45: foreach ($tab as $n) {
46: $pn = $n["player"];
47: $scores = $this->plugin->getScores($pn);
48: if ($scores == null) continue;
49: $row = [ "player_name" => $pn ];
50: foreach ($scores as $dt) {
51: $row[$dt["type"]] = $dt["count"];
52: }
53: if (isset($row["deaths"]) && isset($row["player"]) && $row["deaths"] != 0) {
54: $row["kdratio"] = round((float)$row["player"]/$row["deaths"],2);
55: }
56: $res[] = $row;
57: }
58: return $res;
59: }
60: 61: 62: 63: 64: 65: 66:
67: public function updateScore($player,$col = "points",$incr = 1) {
68: if ($player instanceof IPlayer) $player = $player->getName();
69: return $this->plugin->updateDb($player, $col, $incr);
70: }
71: 72: 73: 74: 75: 76:
77: public function setScore($player,$val, $col = "points") {
78: if ($player instanceof IPlayer) $player = $player->getName();
79: return $this->plugin->setScore($player, $val, $col);
80: }
81: 82: 83: 84: 85: 86:
87: public function getScore($player,$col = "points") {
88: if ($col == "kdratio") return $this->getKDRatio($player);
89: if ($player instanceof IPlayer) $player = $player->getName();
90: return $this->plugin->getScoreV2($player);
91: }
92: 93: 94: 95: 96:
97: public function getKDRatio($player) {
98: if ($player instanceof IPlayer) $player = $player->getName();
99: $d = $this->plugin->getScoreV2($player,"deaths");
100: $k = (float)$this->plugin->getScoreV2($player,"player");
101: if ($d == 0) return null;
102: return round($k/$d,2);
103: }
104: 105: 106: 107: 108: 109:
110: public function delScore($pl, $type = null) {
111: if ($player instanceof IPlayer) $player = $player->getName();
112: $this->plugin->delScore($player, $type);
113: }
114: }
115: