Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Old solution
- <?php
- require("modprot");
- class KPO
- {
- public $moduleID = -1;
- protected $kpo = array();
- public function OnBotCommand($uid, $source, $command, $params)
- {
- switch ($command)
- {
- case "kpo":
- $chose=array('ko', 'papir', 'ollo');
- $beats=array('ollo' => 'papir', 'papir' => 'ko', 'ko' => 'ollo');
- if (!in_array($params, $chose)):
- privmsg ($source, "Használat: !kpo ko|papir|ollo");
- break;
- endif;
- $my = $chose[rand(0,count($chose)-1)];
- $your = $params;
- if (empty($this->kpo[$uid])):
- $this->kpo[$uid]['Beats'] = 0;
- $this->kpo[$uid]['Wins'] = 0;
- endif;
- if ($beats[$my] == $your):
- $this->kpo[$uid]['Beats'] = $this->kpo[$uid]['Beats'] + 1;
- privmsg ($source, User($uid)->Nick.": ".$your." ".User(-2)->Nick.": ".$my." - NYERTEM! (".User($uid)->Nick.": ".$this->kpo[$uid]['Wins']." győzelem, ".$this->kpo[$uid]['Beats']." vereség)");
- break;
- endif;
- if ($beats[$your] == $my):
- $this->kpo[$uid]['Wins'] = $this->kpo[$uid]['Wins'] + 1;
- privmsg ($source, User($uid)->Nick.": ".$your." ".User(-2)->Nick.": ".$my." - NYERTÉL! (".User($uid)->Nick.": ".$this->kpo[$uid]['Wins']." győzelem, ".$this->kpo[$uid]['Beats']." vereség)");
- break;
- endif;
- if ($your == $my):
- privmsg ($source, User($uid)->Nick.": ".$your." ".User(-2)->Nick.": ".$my." - döntetlen. (".User($uid)->Nick.": ".$this->kpo[$uid]['Wins']." győzelem, ".$this->kpo[$uid]['Beats']." vereség)");
- break;
- endif;
- break;
- }
- }
- }
- $newmod = new KPO();
- $cmds = array('!kpo');
- ?>
- New solution
- <?php
- class KPO2
- {
- public $moduleID = -1;
- public function cmd_kpo($uid, $source, $params)
- {
- if (KPO::$INVALID_WEAPON == ($weapIDPlayer = KPO::WeaponID($params)))
- return privmsg($source, User($uid)->Nick.": tiltott fegyver!");
- $weapIDBot = KPO::RandomWeapon();
- $msg = User($uid)->Nick.": " . KPO::WeaponName($weapIDPlayer);
- $msg .= " ".User(-2)->Nick.": " . KPO::WeaponName($weapIDBot);
- $msg .= " - ";
- if ($weapIDBot == $weapIDPlayer)
- {
- UserStore::Call('IncEntry', $uid, 'kpo/games/tie');
- $msg .= "döntetlen.";
- }
- else
- {
- if (KPO::IsBeat($weapIDPlayer, $weapIDBot))
- {
- $msg .= "NYERTÉL!";
- UserStore::Call("IncEntry", $uid, "kpo/games/win");
- }
- else
- {
- $msg .= "NYERTEM!";
- UserStore::Call('IncEntry', $uid, "kpo/games/lose");
- }
- }
- $msg .= " (" . User($uid)->Nick . ": " . UserStore::Call('GetEntry', $uid, 'kpo/games/win', 0) . " győzelem, " . UserStore::Call('GetEntry', $uid, 'kpo/games/lose', 0) . " vereség)";
- privmsg($source, $msg);
- }
- public function usage_kpo()
- {
- return [ 'desc' => 'Kő-Papír-Olló játék',
- 'usage' => [['fegyvernem' => true]]
- ];
- }
- }
- class KPO
- {
- public static $INVALID_WEAPON = -1;
- public static function IsBeat($Attacker, $Victim)
- {
- return self::$Weapons[$Attacker]['beats'] == $Victim;
- }
- public static function WeaponName($WeaponID)
- {
- return self::$Weapons[$WeaponID]['name'];
- }
- public static function WeaponID($WeaponName)
- {
- $WeaponName = mb_strtolower($WeaponName);
- foreach (self::$Weapons as $WeaponID => $WeaponData)
- {
- if (in_array($WeaponName, $WeaponData['aliases']))
- return $WeaponID;
- }
- return self::$INVALID_WEAPON;
- }
- public static function RandomWeapon()
- {
- return Veletlenszam(0, count(self::$Weapons)-1);
- }
- public static $Weapons = [
- 0 => [
- 'name' => 'kő',
- 'aliases' => ['ko', 'kö', 'kô', 'kő', 'kavics', 'szikla', 'rock', 'stone'],
- 'beats' => 2
- ],
- 1 => [
- 'name' => 'papír',
- 'aliases' => ['papir', 'papír', 'papirusz', 'papirusztekercs', 'lap', 'újság', 'könyv', 'konyv', 'ujsag', 'tekercs', 'pergamen', 'irat', 'iromány', 'iromany', 'paper', 'sheet'],
- 'beats' => 0
- ],
- 2 => [
- 'name' => 'olló',
- 'aliases' => ['ollo', 'olló', 'kés', 'kes', 'scissors', 'vago', 'vágó', 'penge', 'él', 'el', 'blade', 'cut'],
- 'beats' => 1
- ]
- ];
- }
- $newmod = new KPO2;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment