Вход Регистрация
Файл: pages/economy/pet.php
Строк: 109
<?php
/* Питомец v50.7 — карточка и прокачка 1–80. by Метриум (Стэлп) */
declare(strict_types=1);
if (!
defined('GAME_ROOT')) define('GAME_ROOT'dirname(__DIR__2));
chdir(GAME_ROOT);
if (
PHP_SAPI !== 'cli') { $_SERVER['PHP_SELF']='/pet.php'$_SERVER['SCRIPT_NAME']='/pet.php'; }

require_once 
'./system/common.php';
require_once 
'./system/functions.php';
require_once 
'./system/user.php';
require_once 
'./system/pets_v507.php';
if(!
$user){header('Location:/');exit;}
pet_v507_bootstrap();
$uid=(int)$user['id'];
$petId=max(0,(int)($_GET['pet_id']??$_GET['id']??0));
if(
$petId<=0){header('Location:/petshop/');exit;}
$pet=db_fetch_one('SELECT pu.*,u.`login` owner_login FROM `pet_u` pu JOIN `users` u ON u.`id`=pu.`user_id` WHERE pu.`id`=:i LIMIT 1',['i'=>$petId]);
if(!
$pet){header('Location:/petshop/');exit;}
$isOwner=(int)$pet['user_id']===$uid;

if((
$_SERVER['REQUEST_METHOD']??'GET')==='POST' && $isOwner){
    try{
        
security_require_csrf();
        if((string)(
$_POST['act']??'')==='upgrade'){
            
$r=pet_v507_upgrade($uid,$petId);
            
$_SESSION['ok']='Питомец улучшен до '.(int)$r['level'].' уровня. Параметры героя увеличены.';
        }
    }catch(
Throwable $e){$_SESSION['err']=$e->getMessage();}
    
header('Location:/pet/'.$petId.'/');exit;
}

$pet=db_fetch_one('SELECT pu.*,u.`login` owner_login FROM `pet_u` pu JOIN `users` u ON u.`id`=pu.`user_id` WHERE pu.`id`=:i LIMIT 1',['i'=>$petId]) ?: $pet;
$level=pet_v507_level($pet); $max=80$total=pet_v507_total($pet); $cost=$level<$max?pet_v507_cost($level):null;
$title='Питомец '.$pet['name'];
require 
'./system/h.php';
if(!empty(
$_SESSION['ok'])){echo '<div class="ok center">'.security_html(strip_tags((string)$_SESSION['ok'])).'</div>';unset($_SESSION['ok']);}
if(!empty(
$_SESSION['err'])){echo '<div class="ok center">'.security_html((string)$_SESSION['err']).'</div>';unset($_SESSION['err']);}
?>
<div class="pet-card-v507">
  <div class="pet-card-v507__owner"><?= $isOwner?'Ваш питомец':'Питомец игрока '.security_html((string)$pet['owner_login']) ?></div>
  <div class="pet-card-v507__name"><img src="/images/pet/icon.gif" alt=""> <b><?=security_html((string)$pet['name'])?></b> <span class="blue"><?=$level?> ур.</span></div>
  <div class="pet-card-v507__hero"><img src="/images/pet/<?=security_html((string)$pet['screen'])?>" alt="<?=security_html((string)$pet['name'])?>"></div>
  <div class="pet-card-v507__bonus"><b class="green">+<?=n_f($total)?> к сумме параметров героя</b></div>
  <div class="pet-card-v507__stats">
    <div><img src="/images/icon/str.png" alt=""> Сила <b><?=n_f((int)$pet['str'])?></b></div>
    <div><img src="/images/icon/vit.png" alt=""> Жизнь <b><?=n_f((int)$pet['vit'])?></b></div>
    <div><img src="/images/icon/agi.png" alt=""> Удача <b><?=n_f((int)$pet['agi'])?></b></div>
    <div><img src="/images/icon/def.png" alt=""> Защита <b><?=n_f((int)$pet['def'])?></b></div>
    <?php if((int)$pet['mana']>0):?><div><img src="/images/icon/mana.png" alt=""> Мана <b><?=n_f((int)$pet['mana'])?></b></div><?php endif;?>
  </div>
  <?=game_progress_markup($level,$max,'Уровень питомца')?>
  <?php if($isOwner && $level<$max && $cost): ?>
    <form method="post" class="pet-card-v507__upgrade">
      <?=security_csrf_field()?><input type="hidden" name="act" value="upgrade">
      <button class="btn" type="submit"><span class="end"><span class="label">Улучшить до <?=$level+1?> ур. за <img src="/images/icon/silver.png" alt=""> <?=n_f($cost['silver'])?> и <img src="/images/icon/gold.png" alt=""> <?=n_f($cost['gold'])?></span></span></button>
    </form>
  <?php elseif($isOwner): ?>
    <div class="pet-card-v507__max green">Питомец максимально улучшен: 80 из 80</div>
  <?php endif; ?>
</div>
<div class="menuList"><li><a href="/petshop/"><img src="/images/pet/icon.gif" alt=""> Мои питомцы и магазин</a></li><?php if(!$isOwner):?><li><a href="/user/<?=(int)$pet['user_id']?>/"><img src="/images/icon/arrow.png" alt=""> В профиль владельца</a></li><?php endif;?></div>
<?php require './system/f.php';
Онлайн: 3
Реклама