161 lines
5.7 KiB
PHP
161 lines
5.7 KiB
PHP
<?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 => 3, 10 => 5];
|
|
$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
|
|
];
|
|
}
|
|
} |