3 Куски кода
Ivor Barhansky edited this page 2022-05-31 13:31:47 +00:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

На будущее

Запрос времени три часа назад

select hour(timediff(now(), `time`)) > 3

Ботогенератор

function create_bot ($level): object
{
    $stats = [
        'str' => 10,
        'dex' => 10,
        'intu' => 10,
        'endu' => 10,
        'inte' => 10,
        'wis' => 10,
    ];
    
    $free_points = 3 + (2 * $level);
    
    while ($free_points > 0) {
        $stats[array_rand($stats)] += 1;
        $free_points--;
    }
    
    $obj = (object)[];
    
    foreach ($stats as $k=>$v){
        $obj->$k = $v;
    }

    //Бонус даётся только за стат выше 10.
    $obj->eva = $obj->dex - 10;
    $obj->acc = $obj->dex - 10;
    $obj->krit = $obj->intu - 10;
    $obj->maxHealth = round(($obj->endu * 3) + ($obj->endu / 2) * ($level - 1) + ($obj->endu / 5) * (($level - 1) * ($level - 2) / 2));
    $obj->maxMana = round(($obj->wis * 3) + ($obj->wis / 2) * ($level - 1) + ($obj->wis / 5) * (($level - 1) * ($level - 2) / 2));

    return $obj;
}

Почему я раньше так тормозил с выдачей кучи ошибок??

$error[] = '1';
$error[] = '2';
$error[] = '3';

if (isset($error)) {
    $err = isset($error[1]) ? 'Ошибка' : 'Ошибки';
	foreach ($error as $item) {
        $err .= '<li>'.$item.'</li>';
    }
	$err = "<ol class='error'>$err</ol>";
} else { ... }