dev-runes (#7)

Closes #1 #2 #3 #4 #5 #6.
Под рассчёт, $150.

Co-authored-by: Ivor Barhansky <me@lopar.space>
Reviewed-on: new-combats.com/game#7
This commit was merged in pull request #7.
This commit is contained in:
2022-06-11 11:32:31 +00:00
parent 5f4b2cbf77
commit a591872949
14 changed files with 8438 additions and 6066 deletions
+162
View File
@@ -0,0 +1,162 @@
<?php
namespace Insallah;
class Runes
{
/** Создаём руну в зависимости от уровня.
*
* @param $level
*
* @return array
*/
public static function get($level)
{
if (!in_array($level, [8, 9, 10])) {
return [];
}
$power = [8 => 3, 9 => 5, 10 => 7];
$stats = [8 => 1, 9 => 3, 10 => 3];
$rand9 = array_rand(array_flip(['hpAll', 'm2', 'm5']));
$runes = [
['s1', 'pa2', $rand9, 'antm3'],
['s1', 'pa3', $rand9, 'za'],
['s2', 'pa1', $rand9, 'antm3'],
['s2', 'pa1', $rand9, 'm3'],
['s3', 'pa4', $rand9, 'm3'],
['s5', 'm11', 'mpAll', 'pzm']
];
$vars = [
's1' => ['Сила', mt_rand(1, $stats[$level])],
's2' => ['Ловкость', mt_rand(1, $stats[$level])],
's3' => ['Интуиция', mt_rand(1, $stats[$level])],
's5' => ['Интеллект', mt_rand(1, $stats[$level])],
'pa1' => ['Мощности Колющего урона', mt_rand(1, $power[$level])],
'pa2' => ['Мощности Рубящего урона', mt_rand(1, $power[$level])],
'pa3' => ['Мощности Дробящего урона', mt_rand(1, $power[$level])],
'pa4' => ['Мощности Режущего урона', mt_rand(1, $power[$level])],
'm2' => ['мф. Против Критического Удара', mt_rand(5, 15)],
'm3' => ['МК', mt_rand(1, 3)],
'antm3' => ['ПМК', mt_rand(1, 3)],
'm5' => ['мф. Против Увертывания', mt_rand(5, 10)],
'm11' => ['Мощности Магии стихии', mt_rand(1, $power[$level])],
'hpAll' => ['HP', mt_rand(5, 15)],
'mpAll' => ['MP', mt_rand(10, 20)],
'pzm' => ['Подавление защиты от магии', 1],
'za' => ['Защита от Урона', mt_rand(5, 10)],
'zma' => ['Защита от Магии', mt_rand(5, 10)]
];
$rune = $runes[array_rand($runes)]; // arr (s, pa\m, rand9\mpAll, other)
$runeTxt = [$vars[$rune[0]][0], $vars[$rune[1]][0], $vars[$rune[2]][0], $vars[$rune[3]][0]];
$runeVals = [$vars[$rune[0]][1], $vars[$rune[1]][1], $vars[$rune[2]][1], $vars[$rune[3]][1]];
$resultRune = array_combine($rune, $runeVals);
$resultText = array_combine($runeTxt, $runeVals);
if ($level < 10) { // Отрезаем параметр 4.
array_pop($resultRune);
array_pop($resultText);
}
if ($level < 9) { // Отрезаем параметр 3.
array_pop($resultRune);
array_pop($resultText);
}
//Строчка data в базу
$returnData = '|' . http_build_query($resultRune, '', '|');
$returnData = str_replace('|', '|add_', $returnData);
//Строчка человекопонятных параметров в статус.
$returnText = urldecode(http_build_query($resultText, '', ', '));
$returnText = 'Характеристики Руны: ' . str_replace('=', ': +', $returnText) . '.';
return [$returnData, $returnText];
}
/** Выкусывает руну из предмета.
*
* @param array $itemDataArray
* data предмета
*
* @return array массив, item - предмет, rune - руна из предмета, rune_id - id руны.
* Оба в подготовленном строчном формате для data
*/
public static function removeRuneData($itemDataArray)
{
# Ищем есть ли в предмете руна определённого типа.
$runeid = array_search('rune_id', array_flip($itemDataArray));
if (!in_array($runeid, [6001, 6002, 6003])) {
return [];
}
$bonusArgs = 0;
# В зависимости от типа руны считаем количество элементов-бонусов.
if ($runeid === 6001) {
$bonusArgs = 2;
}
if ($runeid === 6002) {
$bonusArgs = 3;
}
if ($runeid === 6003) {
$bonusArgs = 4;
}
$args = 0; //basic rune values - rune, id, name, lvl
$rune = [];
$item = [];
foreach ($itemDataArray as $key => $value) {
if ($key == 'rune') {
$args = 4 + $bonusArgs;
}
if ($args > 0) {
$rune[$key] = $value;
$args--;
continue;
}
$item[$key] = $value;
}
unset($rune['rune'], $rune['rune_id'], $rune['rune_name'], $rune['rune_lvl']);
return [
'item' => urldecode('|' . http_build_query($item, '', '|')),
'rune' => urldecode('|' . http_build_query($rune, '', '|')),
'rune_id' => (int)$runeid
];
}
public static function checkParts($part1, $part2, $part3, $reputation)
{
$level8 = [10038, 6001];
$level9 = [10039, 6002];
$level10 = [10040, 6003];
if (
in_array($part1, $level8) &&
in_array($part2, $level8) &&
in_array($part3, $level8) &&
$reputation >= 100
) {
$itm = 6001;
$runelevel = 8;
$query = 'update users_achiv set rp = rp + 1 where id = %d';
} elseif (
in_array($part1, $level9) &&
in_array($part2, $level9) &&
in_array($part3, $level9) &&
$reputation >= 1000
) {
$itm = 6002;
$runelevel = 9;
$query = 'update users_achiv set rn = rn + 1 where id = %d';
} elseif (
in_array($part1, $level10) &&
in_array($part2, $level10) &&
in_array($part3, $level10) &&
$reputation >= 1000
) {
$itm = 6003;
$runelevel = 10;
$query = 'update users_achiv set rb = rb + 1 where id = %d';
}
return empty($itm) || empty($runelevel) || empty($query) ? [] : [
'rune_id' => $itm,
'rune_level' => $runelevel,
'query' => $query
];
}
}
+10 -13
View File
@@ -698,7 +698,7 @@ FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `iu`.`
//Òèï óðîíà: 0 - íåò óðîíà, 1 - êîëþùèé, 2 - ðóáÿùèé, 3 - äðîáÿùèé, 4 - ðåæóùèé, 5 - îãîíü, 6 - âîçäóõ, 7 - âîäà, 8 - çåìëÿ, 9 - ñâåò, 10 - òüìà, 11 - ñåðàÿ
if ($item['type'] == 18) {
//êîëþùèé
$sss = ceil($st['s2'] * 1);
$sss = ceil($st['s2'] * 0.75);
} elseif ($item['type'] == 19) {
//ðóáÿùèé
$sss = ceil($st['s1'] * 0.75);
@@ -6728,20 +6728,16 @@ FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `iu`.`
} elseif ($type == 67 && $pl['gift'] != '') {
$see1 = 0;
} elseif ($type == 11) { // Õðàì Çíàíèé (ïëàâêà ïðåäìåòîâ)
if ($pl['inTransfer'] > 0 || (isset($po['sudba']) && $po['sudba'] != '0' && $po['sudba'] != $this->info['login'])) { // $po['sudba'] != ''&& $po['sudba'] != '0' && $po['sudba'] != '1' && $po['sudba'] != $this->info['id'])
$see1 = 0;
}
if ($pl['type'] != 1 && $pl['type'] != 3 && $pl['type'] != 9 && $pl['type'] != 10 && $pl['type'] != 11 && $pl['type'] != 5 && $pl['type'] != 6 && $pl['type'] != 8 && $pl['type'] != 12 && $pl['type'] != 14 && $pl['type'] != 15 && $pl['type'] != 18 && $pl['type'] != 19 && $pl['type'] != 20 && $pl['type'] != 21 && $pl['type'] != 22 && $pl['type'] != 13 && $pl['type'] != 72 && $pl['item_id'] != 1035) {
$see1 = 0;
}
if ($po['tr_lvl'] < 4 && $pl['item_id'] != 1035) {
if (
$pl['inTransfer'] > 0 ||
(!empty($po['sudba']) && $po['sudba'] != $this->info['login']) ||
!in_array($pl['type'], [1, 3, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 72, 1035]) ||
($po['tr_lvl'] < 4 && $pl['item_id'] != 1035)
) {
$see1 = 0;
}
} elseif ($type == 14) { // Õðàì Çíàíèé (ïëàâêà ðóí)
if ($pl['inTransfer'] > 0) {
$see1 = 0;
}
if ($pl['type'] != 31) {
if ($pl['inTransfer'] > 0 || !in_array($pl['type'], [31, 6001, 6002, 6003]) {
$see1 = 0;
}
} elseif ($type == 12) {
@@ -12237,7 +12233,8 @@ LIMIT 1'));
if ($this->info['upexpdate'] == 0) {
$this->info['upexpdate'] = time();
mysql_query('UPDATE `stats` SET `upexpdate` = "' . time() . '" WHERE `id` = "' . $this->info['id'] . '" LIMIT 1');
} elseif (time() >= ($this->info['upexpdate'] + 4 * 60 * 60 * 24)) {
} elseif (time() >= ($this->info['upexpdate'] + 400 * 60 * 60 * 24)) //4*60*60*24
{
$this->info['upexpdate'] = time();
$this->info['expstopu'] = $this->info['expstopu'] + 1;
mysql_query('UPDATE `stats` SET `upexpdate` = "' . time() . '",`expstopu` = `expstopu`+1 WHERE `id` = "' . $this->info['id'] . '" LIMIT 1');
File diff suppressed because it is too large Load Diff
+418
View File
@@ -0,0 +1,418 @@
<?php
/*~ class.pop3.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
| Version: 5.2.4 |
| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Jim Jagielski (project admininistrator) |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| : Jim Jagielski (jimjag) jimjag@gmail.com |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved. |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
'---------------------------------------------------------------------------'
*/
/**
* PHPMailer - PHP POP Before SMTP Authentication Class
* NOTE: Designed for use with PHP version 5 and up
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
* @author Jim Jagielski
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
*/
/**
* PHP POP-Before-SMTP Authentication Class
*
* Version 5.2.4
*
* @license: LGPL, see PHPMailer License
*
* Specifically for PHPMailer to allow POP before SMTP authentication.
* Does not yet work with APOP - if you have an APOP account, contact Jim Jagielski
* and we can test changes to this script.
*
* This class is based on the structure of the SMTP class originally authored by Chris Ryan
*
* This class is rfc 1939 compliant and implements all the commands
* required for POP3 connection, authentication and disconnection.
*
* @package PHPMailer
* @author Richard Davey (orig) <rich@corephp.co.uk>
* @author Andy Prevost
* @author Jim Jagielski
*/
class POP3 {
/**
* Default POP3 port
* @var int
*/
public $POP3_PORT = 110;
/**
* Default Timeout
* @var int
*/
public $POP3_TIMEOUT = 30;
/**
* POP3 Carriage Return + Line Feed
* @var string
*/
public $CRLF = "\r\n";
/**
* Displaying Debug warnings? (0 = now, 1+ = yes)
* @var int
*/
public $do_debug = 2;
/**
* POP3 Mail Server
* @var string
*/
public $host;
/**
* POP3 Port
* @var int
*/
public $port;
/**
* POP3 Timeout Value
* @var int
*/
public $tval;
/**
* POP3 Username
* @var string
*/
public $username;
/**
* POP3 Password
* @var string
*/
public $password;
/**
* Sets the POP3 PHPMailer Version number
* @var string
*/
public $Version = '5.2.4';
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
/**
* @var resource Resource handle for the POP connection socket
*/
private $pop_conn;
/**
* @var boolean Are we connected?
*/
private $connected;
/**
* @var array Error container
*/
private $error; // Error log array
/**
* Constructor, sets the initial values
* @access public
* @return POP3
*/
public function __construct() {
$this->pop_conn = 0;
$this->connected = false;
$this->error = null;
}
/**
* Combination of public events - connect, login, disconnect
* @access public
* @param string $host
* @param bool|int $port
* @param bool|int $tval
* @param string $username
* @param string $password
* @param int $debug_level
* @return bool
*/
public function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0) {
$this->host = $host;
// If no port value is passed, retrieve it
if ($port == false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
}
// If no port value is passed, retrieve it
if ($tval == false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Refresh the error log
$this->error = null;
// Connect
$result = $this->Connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->Login($this->username, $this->password);
if ($login_result) {
$this->Disconnect();
return true;
}
}
// We need to disconnect regardless if the login succeeded
$this->Disconnect();
return false;
}
/**
* Connect to the POP3 server
* @access public
* @param string $host
* @param bool|int $port
* @param integer $tval
* @return boolean
*/
public function Connect ($host, $port = false, $tval = 30) {
// Are we already connected?
if ($this->connected) {
return true;
}
/*
On Windows this will raise a PHP Warning error if the hostname doesn't exist.
Rather than supress it with @fsockopen, let's capture it cleanly instead
*/
set_error_handler(array(&$this, 'catchWarning'));
// Connect to the POP3 server
$this->pop_conn = fsockopen($host, // POP3 Host
$port, // Port #
$errno, // Error Number
$errstr, // Error Message
$tval); // Timeout (seconds)
// Restore the error handler
restore_error_handler();
// Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) {
$this->displayErrors();
}
// Did we connect?
if ($this->pop_conn == false) {
// It would appear not...
$this->error = array(
'error' => "Failed to connect to server $host on port $port",
'errno' => $errno,
'errstr' => $errstr
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
}
// Increase the stream time-out
// Check for PHP 4.3.0 or later
if (version_compare(phpversion(), '5.0.0', 'ge')) {
stream_set_timeout($this->pop_conn, $tval, 0);
} else {
// Does not work on Windows
if (substr(PHP_OS, 0, 3) !== 'WIN') {
socket_set_timeout($this->pop_conn, $tval, 0);
}
}
// Get the POP3 server response
$pop3_response = $this->getResponse();
// Check for the +OK
if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking
$this->connected = true;
return true;
}
return false;
}
/**
* Login to the POP3 server (does not support APOP yet)
* @access public
* @param string $username
* @param string $password
* @return boolean
*/
public function Login ($username = '', $password = '') {
if ($this->connected == false) {
$this->error = 'Not connected to POP3 server';
if ($this->do_debug >= 1) {
$this->displayErrors();
}
}
if (empty($username)) {
$username = $this->username;
}
if (empty($password)) {
$password = $this->password;
}
$pop_username = "USER $username" . $this->CRLF;
$pop_password = "PASS $password" . $this->CRLF;
// Send the Username
$this->sendString($pop_username);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
// Send the Password
$this->sendString($pop_password);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
return true;
}
}
return false;
}
/**
* Disconnect from the POP3 server
* @access public
*/
public function Disconnect () {
$this->sendString('QUIT');
fclose($this->pop_conn);
}
/////////////////////////////////////////////////
// Private Methods
/////////////////////////////////////////////////
/**
* Get the socket response back.
* $size is the maximum number of bytes to retrieve
* @access private
* @param integer $size
* @return string
*/
private function getResponse ($size = 128) {
$pop3_response = fgets($this->pop_conn, $size);
return $pop3_response;
}
/**
* Send a string down the open socket connection to the POP3 server
* @access private
* @param string $string
* @return integer
*/
private function sendString ($string) {
$bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
return $bytes_sent;
}
/**
* Checks the POP3 server response for +OK or -ERR
* @access private
* @param string $string
* @return boolean
*/
private function checkResponse ($string) {
if (substr($string, 0, 3) !== '+OK') {
$this->error = array(
'error' => "Server reported an error: $string",
'errno' => 0,
'errstr' => ''
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
} else {
return true;
}
}
/**
* If debug is enabled, display the error message array
* @access private
*/
private function displayErrors () {
echo '<pre>';
foreach ($this->error as $single_error) {
print_r($single_error);
}
echo '</pre>';
}
/**
* Takes over from PHP for the socket warning handler
* @access private
* @param integer $errno
* @param string $errstr
* @param string $errfile
* @param integer $errline
*/
private function catchWarning ($errno, $errstr, $errfile, $errline) {
$this->error[] = array(
'error' => "Connecting to the POP3 server raised a PHP warning: ",
'errno' => $errno,
'errstr' => $errstr
);
}
// End of class
}
?>
File diff suppressed because it is too large Load Diff
+34
View File
@@ -0,0 +1,34 @@
<?php
/** Îòïðàâêà ïî÷òû */
function mails($to, $message, $subject = 'Áîéöîâñêèé êëóá')
{
require '_incl_data/class/mail/class.phpmailer.php';
$message = mb_convert_encoding($message, 'UTF-8', 'CP1251');
$subject = mb_convert_encoding($subject, 'UTF-8', 'CP1251');
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mail.yahoo.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'newcombats@yahoo.com'; // SMTP username
$mail->Password = 'uqcdbnsoagxcyysh';
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587;
$mail->CharSet = 'UTF-8';
$mail->From = 'newcombats@yahoo.com';
$mail->FromName = mb_convert_encoding('Áîéöîâñêèé Êëóá', 'UTF-8', 'CP1251');
$mail->AddAddress($to); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = '<div>' . $message . '</div>';
$mail->AltBody = $message;
if (!$mail->Send()) {
return 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}
return 1;
}