1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34:
35: class LevelController {
36:
37: 38: 39: 40:
41: public $moduleName;
42:
43:
44: public $db;
45:
46:
47: public $commandAlias;
48:
49: 50: 51: 52:
53: public function setup() {
54: $this->db->loadSQLFile($this->moduleName, 'levels');
55:
56: $this->commandAlias->register($this->moduleName, "level", "pvp");
57: $this->commandAlias->register($this->moduleName, "level", "lvl");
58: }
59:
60: 61: 62: 63:
64: public function levelCommand($message, $channel, $sender, $sendto, $args) {
65: $level = $args[1];
66: if (($row = $this->getLevelInfo($level)) != false) {
67: $msg = "<white>L $row->level: Team {$row->teamMin}-{$row->teamMax}<end><highlight> | <end><cyan>PvP {$row->pvpMin}-{$row->pvpMax}<end><highlight> | <end><orange>Missions {$row->missions}<end><highlight> | <end><blue>{$row->tokens} token(s)<end>";
68: } else {
69: $msg = "Level must be between <highlight>1<end> and <highlight>220<end>.";
70: }
71:
72: $sendto->reply($msg);
73: }
74:
75: 76: 77: 78:
79: public function missionsCommand($message, $channel, $sender, $sendto, $args) {
80: $missionQl = $args[1];
81:
82: if ($missionQl > 0 && $missionQl <= 250) {
83: $msg = "QL{$missionQl} missions can be rolled from these levels:";
84:
85: forEach ($this->findAllLevels() as $row) {
86: $array = explode(",", $row->missions);
87: if (in_array($missionQl, $array)) {
88: $msg .= " " . $row->level;
89: }
90: }
91: } else {
92: $msg = "Missions are only available between QL1 and QL250.";
93: }
94:
95: $sendto->reply($msg);
96: }
97:
98: 99: 100: 101:
102: public function xpSingleCommand($message, $channel, $sender, $sendto, $args) {
103: $level = $args[1];
104: if (($row = $this->getLevelInfo($level)) != false) {
105: if ($level >= 200) {
106: $msg = "At level <highlight>{$row->level}<end> you need <highlight>".number_format($row->xpsk)."<end> SK to level up.";
107: } else {
108: $msg = "At level <highlight>{$row->level}<end> you need <highlight>".number_format($row->xpsk)."<end> XP to level up.";
109: }
110: } else {
111: $msg = "Level must be between 1 and 219.";
112: }
113:
114: $sendto->reply($msg);
115: }
116:
117: 118: 119: 120:
121: public function xpDoubleCommand($message, $channel, $sender, $sendto, $args) {
122: $minLevel = $args[1];
123: $maxLevel = $args[2];
124: if ($minLevel >= 1 && $minLevel <= 220 && $maxLevel >= 1 && $maxLevel <= 220) {
125: if ($minLevel < $maxLevel) {
126: $data = $this->db->query("SELECT * FROM levels WHERE level >= ? AND level < ?", $minLevel, $maxLevel);
127: $xp = 0;
128: $sk = 0;
129: forEach ($data as $row) {
130: if ($row->level < 200) {
131: $xp += $row->xpsk;
132: } else {
133: $sk += $row->xpsk;
134: }
135: }
136: if ($sk > 0 && $xp > 0) {
137: $msg = "From the beginning of level <highlight>$minLevel<end> you need <highlight>".number_format($xp)."<end> XP and <highlight>".number_format($sk)."<end> SK to reach level <highlight>$maxLevel<end>.";
138: } else if ($sk > 0) {
139: $msg = "From the beginning of level <highlight>$minLevel<end> you need <highlight>".number_format($sk)."<end> SK to reach level <highlight>$maxLevel<end>.";
140: } else if ($xp > 0) {
141: $msg = "From the beginning of level <highlight>$minLevel<end> you need <highlight>".number_format($xp)."<end> XP to reach level <highlight>$maxLevel<end>.";
142: }
143: } else {
144: $msg = "The start level cannot be higher than the end level.";
145: }
146: } else {
147: $msg = "Level must be between 1 and 220.";
148: }
149:
150: $sendto->reply($msg);
151: }
152:
153: public function getLevelInfo($level) {
154: $sql = "SELECT * FROM levels WHERE level = ?";
155: return $this->db->queryRow($sql, $level);
156: }
157:
158: public function findAllLevels() {
159: $sql = "SELECT * FROM levels ORDER BY level";
160: return $this->db->query($sql);
161: }
162: }
163: