1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: use Exception;
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: class ImplantController {
29:
30: 31: 32: 33:
34: public $moduleName;
35:
36:
37: public $db;
38:
39:
40: public $text;
41:
42:
43: public $util;
44:
45: private $slots = array('head', 'eye', 'ear', 'rarm', 'chest', 'larm', 'rwrist', 'waist', 'lwrist', 'rhand', 'legs', 'lhand', 'feet');
46:
47: 48: 49:
50: public function setup() {
51: $this->db->loadSQLFile($this->moduleName, "implant_requirements");
52: $this->db->loadSQLFile($this->moduleName, "premade_implant");
53: }
54:
55: 56: 57: 58:
59: public function implantQlCommand($message, $channel, $sender, $sendto, $args) {
60: $ql = $args[1];
61:
62:
63: if (($ql < 1) || ($ql > 300)) {
64: $msg = "You must enter a value between 1 and 300.";
65: } else {
66: $obj = $this->getRequirements($ql);
67: $clusterInfo = $this->formatClusterBonuses($obj);
68: $link = $this->text->makeBlob("QL$obj->ql", $clusterInfo, "Implant Info (QL $obj->ql)");
69: $msg = "QL $ql implants--Ability: {$obj->ability}, Treatment: {$obj->treatment} $link";
70:
71: $msg = "$link: <highlight>$obj->ability<end> Ability, <highlight>$obj->treatment<end> Treatment";
72: }
73:
74: $sendto->reply($msg);
75: }
76:
77: 78: 79: 80:
81: public function implantRequirementsCommand($message, $channel, $sender, $sendto, $args) {
82: $ability = $args[1];
83: $treatment = $args[2];
84:
85: if ($treatment < 11 || $ability < 6) {
86: $msg = "You do not have enough treatment or ability to wear an implant.";
87: } else {
88: $obj = $this->findMaxImplantQlByReqs($ability, $treatment);
89: $clusterInfo = $this->formatClusterBonuses($obj);
90: $link = $this->text->makeBlob("QL$obj->ql", $clusterInfo, "Implant Info (QL $obj->ql)");
91:
92: $msg = "$link: <highlight>$obj->ability<end> Ability, <highlight>$obj->treatment<end> Treatment";
93: }
94: $sendto->reply($msg);
95: }
96:
97: 98: 99: 100:
101: public function ladderCommand($message, $channel, $sender, $sendto, $args) {
102: $type = strtolower($args[1]);
103: $startingValue = $args[2];
104:
105: if ($type == 'treat') {
106: $type = 'treatment';
107: }
108:
109:
110: if ($type != 'treatment' && $type != 'ability') {
111: $type = $this->util->getAbility($type, true);
112: if ($type === null) {
113: return false;
114: }
115: $type = strtolower($type);
116: }
117:
118: $value = $startingValue;
119: $prefix = $type == 'treatment' ? 'skill' : 'ability';
120:
121: $blob = "Starting $type: $value\n\n-------------------\n\n";
122:
123: $that = $this;
124: if ($type == 'treatment') {
125: if ($value < 11) {
126: $sendto->reply("Base treatment must be at least <highlight>11<end>.");
127: return;
128: }
129:
130: $getMax = function($value) use ($that) {
131: return $that->findMaxImplantQlByReqs(10000, $value);
132: };
133: } else {
134: if ($value < 6) {
135: $sendto->reply("Base ability must be at least <highlight>6<end>.");
136: return;
137: }
138:
139: $getMax = function($value) use ($that) {
140: return $that->findMaxImplantQlByReqs($value, 10000);
141: };
142: }
143:
144: $shiny = null;
145: $bright = null;
146: $faded = null;
147: $added = true;
148:
149:
150: while ($added) {
151: $added = false;
152:
153:
154: $tempValue = $shiny === null ? $value : $value - $shiny->{$prefix . 'Shiny'};
155: $newShiny = $getMax($tempValue);
156: if ($shiny === null || $newShiny->{$prefix . 'Shiny'} > $shiny->{$prefix . 'Shiny'}) {
157: $added = true;
158: if ($shiny !== null) {
159: $value -= $shiny->{$prefix . 'Shiny'};
160: $blob .= "Remove shiny QL $shiny->ql\n\n";
161: }
162: $shiny = $newShiny;
163: $value += $shiny->{$prefix . 'Shiny'};
164: $lowest = $shiny->{'lowest' . ucfirst($prefix) . 'Shiny'};
165: $blob .= "<highlight>Add shiny QL $shiny->ql<end> ($lowest) - Treatment: {$shiny->treatment}, Ability: {$shiny->ability}\n\n";
166: }
167:
168:
169: $tempValue = $bright === null ? $value : $value - $bright->{$prefix . 'Bright'};
170: $newBright = $getMax($tempValue);
171: if ($bright === null || $newBright->{$prefix . 'Bright'} > $bright->{$prefix . 'Bright'}) {
172: $added = true;
173: if ($bright !== null) {
174: $value -= $bright->{$prefix . 'Bright'};
175: $blob .= "Remove bright QL $bright->ql\n\n";
176: }
177: $bright = $newBright;
178: $value += $bright->{$prefix . 'Bright'};
179: $lowest = $bright->{'lowest' . ucfirst($prefix) . 'Bright'};
180: $blob .= "<highlight>Add bright QL $bright->ql<end> ($lowest) - Treatment: {$bright->treatment}, Ability: {$bright->ability}\n\n";
181: }
182:
183:
184: $tempValue = $faded === null ? $value : $value - $faded->{$prefix . 'Faded'};
185: $newFaded = $getMax($tempValue);
186: if ($faded === null || $newFaded->{$prefix . 'Faded'} > $faded->{$prefix . 'Faded'}) {
187: $added = true;
188: if ($faded !== null) {
189: $value -= $faded->{$prefix . 'Faded'};
190: $blob .= "Remove faded QL $faded->ql\n\n";
191: }
192: $faded = $newFaded;
193: $value += $faded->{$prefix . 'Faded'};
194: $lowest = $faded->{'lowest' . ucfirst($prefix) . 'Faded'};
195: $blob .= "<highlight>Add faded QL $faded->ql<end> ($lowest) - Treatment: {$faded->treatment}, Ability: {$faded->ability}\n\n";
196: }
197: }
198:
199: $blob .= "-------------------\n\nEnding $type: $value";
200: $blob .= "\n\n<highlight>Inspired by a command written by Lucier of the same name<end>";
201: $msg = $this->text->makeBlob("Laddering from $startingValue to $value " . ucfirst(strtolower($type)), $blob);
202:
203: $sendto->reply($msg);
204: }
205:
206:
207: public function getRequirements($ql) {
208: $sql = "SELECT * FROM implant_requirements WHERE ql = ?";
209:
210: $row = $this->db->queryRow($sql, $ql);
211:
212: $this->addClusterInfo($row);
213:
214: return $row;
215: }
216:
217: public function findMaxImplantQlByReqs($ability, $treatment) {
218: $sql = "SELECT * FROM implant_requirements WHERE ability <= ? AND treatment <= ? ORDER BY ql DESC LIMIT 1";
219:
220: $row = $this->db->queryRow($sql, $ability, $treatment);
221:
222: $this->addClusterInfo($row);
223:
224: return $row;
225: }
226:
227: public function formatClusterBonuses($obj) {
228: $msg .= "You will gain for most skills:\n" .
229: "<tab>Shiny <highlight>$obj->skillShiny<end> ($obj->lowestSkillShiny - $obj->highestSkillShiny)\n" .
230: "<tab>Bright <highlight>$obj->skillBright<end> ($obj->lowestSkillBright - $obj->highestSkillBright)\n" .
231: "<tab>Faded <highlight>$obj->skillFaded<end> ($obj->lowestSkillFaded - $obj->highestSkillFaded)\n" .
232: "-----------------------\n" .
233: "<tab>Total $obj->skillTotal\n";
234:
235: $msg .= "\n\n";
236:
237: $msg .= "You will gain for abilities:\n" .
238: "<tab>Shiny <highlight>$obj->abilityShiny<end> ($obj->lowestAbilityShiny - $obj->highestAbilityShiny)\n" .
239: "<tab>Bright <highlight>$obj->abilityBright<end> ($obj->lowestAbilityBright - $obj->highestAbilityBright)\n" .
240: "<tab>Faded <highlight>$obj->abilityFaded<end> ($obj->lowestAbilityFaded - $obj->highestAbilityFaded)\n" .
241: "-----------------------\n" .
242: "<tab>Total $obj->abilityTotal\n";
243:
244:
245: if ($obj->ql > 250) {
246:
247: $msg .= "\n\nRequires Title Level 6";
248:
249: } else if ($obj->ql > 200) {
250:
251: $msg .= "\n\nRequires Title Level 5";
252: }
253:
254: $msg .= "\n\nMinimum QL for clusters:\n" .
255: "<tab>Shiny: $obj->minShinyClusterQl\n" .
256: "<tab>Bright: $obj->minBrightClusterQl\n" .
257: "<tab>Faded: $obj->minFadedClusterQl\n";
258:
259: $msg .= "\n\nWritten by Tyrence (RK2)";
260:
261: return $msg;
262: }
263:
264: public function addClusterInfo($obj) {
265: if ($obj === null) {
266: return;
267: }
268:
269: $this->setHighestAndLowestQls($obj, 'abilityShiny');
270: $this->setHighestAndLowestQls($obj, 'abilityBright');
271: $this->setHighestAndLowestQls($obj, 'abilityFaded');
272: $this->setHighestAndLowestQls($obj, 'skillShiny');
273: $this->setHighestAndLowestQls($obj, 'skillBright');
274: $this->setHighestAndLowestQls($obj, 'skillFaded');
275:
276: $obj->abilityTotal = $obj->abilityShiny + $obj->abilityBright + $obj->abilityFaded;
277: $obj->skillTotal = $obj->skillShiny + $obj->skillBright + $obj->skillFaded;
278:
279: $obj->minShinyClusterQl = $this->getClusterMinQl($obj->ql, 'shiny');
280: $obj->minBrightClusterQl = $this->getClusterMinQl($obj->ql, 'bright');
281: $obj->minFadedClusterQl = $this->getClusterMinQl($obj->ql, 'faded');
282:
283:
284: if ($obj->ql >= 201) {
285: if ($obj->minShinyClusterQl < 201) {
286: $obj->minShinyClusterQl = 201;
287: }
288: if ($obj->minBrightClusterQl < 201) {
289: $obj->minBrightClusterQl = 201;
290: }
291: if ($obj->minFadedClusterQl < 201) {
292: $obj->minFadedClusterQl = 201;
293: }
294: }
295: }
296:
297: public function getClusterMinQl($ql, $grade) {
298: if ($grade == 'shiny') {
299: return floor($ql * 0.86);
300: } else if ($grade == 'bright') {
301: return floor($ql * 0.84);
302: } else if ($grade == 'faded') {
303: return floor($ql * 0.82);
304: } else {
305: throw new Exception("Invalid grade: '$grade'. Must be one of: 'shiny', 'bright', 'faded'");
306: }
307: }
308:
309: public function setHighestAndLowestQls($obj, $var) {
310: $varValue = $obj->$var;
311:
312: $sql = "SELECT MAX(ql) as max, MIN(ql) as min FROM implant_requirements WHERE $var = ?";
313: $row = $this->db->queryRow($sql, $varValue);
314:
315:
316: $tempNameVar = ucfirst($var);
317: $tempHighestName = "highest$tempNameVar";
318: $tempLowestName = "lowest$tempNameVar";
319:
320: $obj->$tempLowestName = $row->min;
321: $obj->$tempHighestName = $row->max;
322: }
323: }
324: