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: class PocketbossController {
28:
29: 30: 31: 32:
33: public $moduleName;
34:
35:
36: public $text;
37:
38:
39: public $util;
40:
41:
42: public $db;
43:
44: 45: 46: 47:
48: public function setup() {
49: $this->db->loadSQLFile($this->moduleName, "pocketboss");
50: }
51:
52: 53: 54: 55:
56: public function pocketbossCommand($message, $channel, $sender, $sendto, $args) {
57: $search = $args[1];
58: $data = $this->pbSearchResults($search);
59: $numrows = count($data);
60: if ($numrows == 0) {
61: $msg = "Could not find any pocket bosses that matched your search criteria.";
62: } else if ($numrows == 1) {
63: $name = $data[0]->pb;
64: $blob .= $this->singlePbBlob($name);
65: $msg = $this->text->makeBlob("Remains of $name", $blob);
66: } else {
67: $blob = '';
68: forEach ($data as $row) {
69: $pbLink = $this->text->makeChatcmd($row->pb, "/tell <myname> pocketboss $row->pb");
70: $blob .= $pbLink . "\n";
71: }
72: $msg = $this->text->makeBlob("Search results for $search ($numrows)", $blob);
73: }
74: $sendto->reply($msg);
75: }
76:
77: public function singlePbBlob($name) {
78: $data = $this->db->query("SELECT * FROM pocketboss WHERE pb = ? ORDER BY ql", $name);
79: $symbs = '';
80: forEach ($data as $symb) {
81: $name = "$symb->line $symb->slot Symbiant, $symb->type Unit Aban";
82: $symbs .= $this->text->makeItem($symb->itemid, $symb->itemid, $symb->ql, $name) . " ($symb->ql)\n";
83: }
84:
85: $blob = "Location: <highlight>$symb->pb_location, $symb->bp_location<end>\n";
86: $blob .= "Found on: <highlight>$symb->bp_mob, Level $symb->bp_lvl<end>\n\n";
87: $blob .= $symbs;
88:
89: return $blob;
90: }
91:
92: public function pbSearchResults($search) {
93: $row = $this->db->queryRow("SELECT pb FROM pocketboss WHERE pb LIKE ? GROUP BY `pb` ORDER BY `pb`", $search);
94: if ($row !== null) {
95: return array($row);
96: }
97:
98: $tmp = explode(" ", $search);
99: list($query, $params) = $this->util->generateQueryFromParams($tmp, '`pb`');
100:
101: return $this->db->query("SELECT DISTINCT pb FROM pocketboss WHERE $query GROUP BY `pb` ORDER BY `pb`", $params);
102: }
103:
104: 105: 106: 107: 108: 109:
110: public function symbiantCommand($message, $channel, $sender, $sendto, $args) {
111: $paramCount = count($args) - 1;
112:
113: $slot = '%';
114: $symbtype = '%';
115: $line = '%';
116:
117: $lines = $this->db->query("SELECT DISTINCT line FROM pocketboss");
118:
119: for ($i = 1; $i <= $paramCount; $i++) {
120: switch (strtolower($args[$i])) {
121: case "eye":
122: case "ocular":
123: $impDesignSlot = 'eye';
124: $slot = "Ocular";
125: break;
126: case "brain":
127: case "head":
128: $impDesignSlot = 'head';
129: $slot = "Brain";
130: break;
131: case "ear":
132: $impDesignSlot = 'ear';
133: $slot = "Ear";
134: break;
135: case "rarm":
136: $impDesignSlot = 'rarm';
137: $slot = "Right Arm";
138: break;
139: case "chest":
140: $impDesignSlot = 'chest';
141: $slot = "Chest";
142: break;
143: case "larm":
144: $impDesignSlot = 'larm';
145: $slot = "Left Arm";
146: break;
147: case "rwrist":
148: $impDesignSlot = 'rwrist';
149: $slot = "Right Wrist";
150: break;
151: case "waist":
152: $impDesignSlot = 'waist';
153: $slot = "Waist";
154: break;
155: case "lwrist":
156: $impDesignSlot = 'lwrist';
157: $slot = "Left Wrist";
158: break;
159: case "rhand":
160: $impDesignSlot = 'rhand';
161: $slot = "Right Hand";
162: break;
163: case "leg":
164: case "legs":
165: case "thigh":
166: $impDesignSlot = 'legs';
167: $slot = "Thigh";
168: break;
169: case "lhand":
170: $impDesignSlot = 'lhand';
171: $slot = "Left Hand";
172: break;
173: case "feet":
174: $impDesignSlot = 'feet';
175: $slot = "Feet";
176: break;
177: default:
178:
179: forEach ($lines as $l) {
180: if (strtolower($l->line) == strtolower($args[$i])) {
181: $line = $l->line;
182: break 2;
183: }
184: }
185:
186:
187: if (preg_match("/^art/i", $args[$i])) {
188: $symbtype = "Artillery";
189: } else if (preg_match("/^sup/i", $args[$i])) {
190: $symbtype = "Support";
191: } else if (preg_match("/^inf/i", $args[$i])) {
192: $symbtype = "Infantry";
193: } else if (preg_match("/^ext/i", $args[$i])) {
194: $symbtype = "Extermination";
195: } else if (preg_match("/^control/i", $args[$i])) {
196: $symbtype = "Control";
197: } else {
198: return false;
199: }
200: }
201: }
202:
203: $data = $this->db->query("SELECT * FROM pocketboss WHERE `slot` LIKE ? AND `type` LIKE ? AND `line` LIKE ? ORDER BY `ql` DESC, `type` ASC", $slot, $symbtype, $line);
204: $numrows = count($data);
205: if ($numrows != 0) {
206: $implantDesignerLink = $this->text->makeChatcmd("implant designer", "/tell <myname> implantdesigner");
207: $blob = "Click 'Add' to add symbiant to $implantDesignerLink.\n\n";
208: forEach ($data as $row) {
209: $name = "$row->line $row->slot Symbiant, $row->type Unit Aban";
210: $impDesignerAddLink = $this->text->makeChatcmd("Add", "/tell <myname> implantdesigner $impDesignSlot symb $name");
211: $blob .= "<pagebreak>" . $this->text->makeItem($row->itemid, $row->itemid, $row->ql, $name)." ($row->ql) $impDesignerAddLink\n";
212: $blob .= "Found on " . $this->text->makeChatcmd($row->pb, "/tell <myname> pb $row->pb");
213: $blob .= "\n\n";
214: }
215: $msg = $this->text->makeBlob("Symbiant Search Results ($numrows)", $blob);
216: } else {
217: $msg = "Could not find any symbiants that matched your search criteria.";
218: }
219:
220: $sendto->reply($msg);
221: }
222: }
223: