1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: use stdClass;
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class FightController {
23:
24: 25: 26: 27:
28: public $moduleName;
29:
30:
31: public $text;
32:
33:
34: public $util;
35:
36: 37: 38: 39: 40:
41: public function fightCommand($message, $channel, $sender, $sendto, $args) {
42: $player1 = $args[1];
43: $player2 = $args[2];
44:
45:
46: if ($this->isChuckNorris($player1) && $this->isChuckNorris($player2)) {
47: $msg = "Theres only enough room in this world for one Chuck Norris!";
48: $sendto->reply($msg);
49: return;
50: }
51:
52:
53: if (strcasecmp($player1, $player2) == 0) {
54: $twin = array(
55: "Dejavu?",
56: "$player1 can't fight $player2, it may break the voids of space and time!",
57: "As much as I'd love to see $player1 punching himself/herself in the face, it just isn't theoretical...");
58:
59: $sendto->reply($this->util->randomArrayValue($twin));
60: return;
61: }
62:
63: $fighter1 = $this->getFighter($player1);
64: $fighter2 = $this->getFighter($player2);
65:
66: $list = "Fight <highlight>$player1<end> VS <highlight>$player2<end> \n\n";
67: while ($fighter1->hp > 0 && $fighter2->hp > 0) {
68: $list .= $this->doAttack($fighter1, $fighter2);
69: $list .= $this->doAttack($fighter2, $fighter1);
70: $list .= "\n";
71: }
72:
73: if ($fighter1->hp > $fighter2->hp) {
74: $list .= "\nAnd the winner is ..... <highlight>$player1!<end>";
75: $msg = $this->text->makeBlob("$player1 vs $player2....$player1 wins!", $list);
76: } else if ($fighter2->hp > $fighter1->hp) {
77: $list .= "\nAnd the winner is ..... <highlight>$player2!<end>";
78: $msg = $this->text->makeBlob("$player1 vs $player2....$player2 wins!", $list);
79: } else {
80: $list .= "\nIt's a tie!!";
81: $msg = $this->text->makeBlob("$player1 vs $player2....It's a tie!", $list);
82: }
83:
84: $sendto->reply($msg);
85: }
86:
87: public function getFighter($name) {
88: $fighter = new stdClass;
89: $fighter->name = $name;
90: if ($this->util->startsWith(strtolower($name), "tyrence")) {
91: $fighter->weapon = "bot";
92: $fighter->minDamage = 6001;
93: $fighter->maxDamage = 7000;
94: $fighter->hp = 20000;
95: } else if ($this->isChuckNorris($name)) {
96: $fighter->weapon = "round house kick";
97: $fighter->minDamage = 4001;
98: $fighter->maxDamage = 6000;
99: $fighter->hp = 20000;
100: } else {
101: $fighter->weapon = "nerfstick";
102: $fighter->minDamage = 1000;
103: $fighter->maxDamage = 4000;
104: $fighter->hp = 20000;
105: }
106: return $fighter;
107: }
108:
109: public function doAttack($attacker, $defender) {
110: $dmg = rand($attacker->minDamage, $attacker->maxDamage);
111: if ($this->isCriticalHit($attacker, $dmg)) {
112: $crit = " <red>Critical Hit!<end>";
113: } else {
114: $crit = "";
115: }
116:
117: $defender->hp -= $dmg;
118: return "<highlight>{$attacker->name}<end> hit <highlight>{$defender->name}<end> for $dmg of {$attacker->weapon} dmg.$crit\n";
119: }
120:
121: public function isCriticalHit($fighter, $dmg) {
122: return ($dmg / $fighter->maxDamage) > 0.9;
123: }
124:
125: public function isChuckNorris($name) {
126: $name = strtolower($name);
127: return $name == "chuck" || $name == "chuck norris" || $name == "chucknorris";
128: }
129: }
130: