<?php
include "./system/common.php";
include "./system/functions.php";
include "./system/user.php";
if($user == false){
header("Location: /");
exit;
}
$title = "Завхоз";
include "./system/h.php";
$array = [
"vit" => 300000,
"str" => 150000,
"def" => 70000
];
$manager = mysql_fetch_assoc(mysql_query("SELECT * FROM `manager` WHERE `user` = '{$user["id"]}'"));
if($manager == false){
mysql_query("INSERT INTO `manager` (`user`) VALUES ('{$user["id"]}')");
header("Location: ?");
exit;
}
$manager_battle = mysql_fetch_assoc(mysql_query("SELECT * FROM `manager_battle` WHERE `user` = '{$user["id"]}'"));
if($manager_battle == false){
if(isset($_GET["join"]) and $manager["fight"] < 3){
$time = (time() + 180);
mysql_query("INSERT INTO `manager_battle` (`user`, `health`, `manager`, `manager_health`, `time`) VALUES ('{$user["id"]}', '{$user["hp"]}', '1', '{$array["vit"]}', '{$time}')");
mysql_query("UPDATE `manager` SET `fight` = `fight` + '1' WHERE `user` = '{$user["id"]}'");
header("Location: ?");
exit;
}
$cooldown = strtotime("+ 1 day 00:00");
echo "<div class=\"content\">
<div class=\"block center header\">
<img src=\"/images/icons/circle.png\" width=\"16\" height=\"16\" alt=\"\"> <a href=\"?\"><u>Завхоз</u></a>
</div>
<div class=\"dotted\"></div>
<div class=\"blue block center\">
<div><img src=\"/images/manager/boss.jpg\" width=\"50\" alt=\"\" style=\"border: 1px solid #f00\"></div>
<div class=\"m3\"></div>
Сразись с Завхозом и получи ресурсы!
</div>
<div class=\"dotted\"></div>
<div class=\"block center\">
<div>Проведено сражений: <b>{$manager["fight"]} из 3</b></div>
".($manager["fight"] > 0 ? "<div>Обновление через: "._time($cooldown - time())."</div>" : false)."
</div>";
if($manager["fight"] < 3)
echo "<div class=\"dotted\"></div>
<div class=\"block center\">
<span class=\"btn_start\">
<span class=\"btn_end\">
<a class=\"btn\" href=\"?join\">Начать сражение</a>
</span>
</span>
</div>";
echo "<div class=\"dotted\"></div>
<ul class=\"block\">
<li class=\"small color2\">Победи как можно больше раз Завхоза, чтобы собрать больше сундуков</li>
<li class=\"small color2\">После каждой победы Завхоз возрождается и становится сильнее</li>
</ul>
</div>";
}else{
if($manager_battle["health"] < 0 or $manager_battle["time"] < time()){
$chest = json_decode($manager["json"]);
if(isset($_GET["open-chest"]) and !empty($_GET["open-chest"])){
$id = intval($_GET["open-chest"]);
if($chest->{"chest_{$id}"} < 0){
header("Location: ?");
exit;
}
if($id == 1){
$exp = (20000 * $chest->{"chest_{$id}"});
$_SESSION["alert"] = "<div class=\"alert\">
<img src=\"/images/manager/chest/{$id}_1.png\" width=\"50\" alt=\"\">
<div class=\"center\">
<div class=\"blue\">Прибыль:</div>
<img src=\"/images/icons/experience.png\" width=\"16\" height=\"16\" alt=\"\"> Опыт
<span class=\"green\">+{$exp}</span><div><img src=\"/images/icons/pet.png\" width=\"16\" height=\"16\" alt=\"\"> Опыт питомца
<span class=\"green\">+{$exp}</span></div>
</div>
</div>
<div class=\"alert_bottom\"></div>";
mysql_query("UPDATE `users` SET `exp` = `exp` + '{$exp}' WHERE `id` = '{$user["id"]}'");
mysql_query("UPDATE `pets_user` SET `exp` = `exp` + '{$exp}' WHERE `user` = '{$user["id"]}'");
$json = json_decode($manager["json"]);
$json->{"chest_{$id}"} -= $chest->{"chest_{$id}"};
$json = json_encode($json);
mysql_query("UPDATE `manager` SET `json` = '{$json}' WHERE `user` = '{$user["id"]}'");
header("Location: ?");
exit;
}
if($id == 2){
$silver = (8000 * $chest->{"chest_{$id}"});
$_SESSION["alert"] = "<div class=\"alert\">
<img src=\"/images/manager/chest/{$id}_1.png\" width=\"50\" alt=\"\">
<div class=\"center\">
<div class=\"blue\">Прибыль:</div>
Рубли <img src=\"/images/icons/silver.png\" width=\"16\" height=\"16\" alt=\"\">
<span class=\"green\">+{$silver}</span>
</div>
</div>
<div class=\"alert_bottom\"></div>";
mysql_query("UPDATE `users` SET `s` = `s` + '{$silver}' WHERE `id` = '{$user["id"]}'");
$json = json_decode($manager["json"]);
$json->{"chest_{$id}"} -= $chest->{"chest_{$id}"};
$json = json_encode($json);
mysql_query("UPDATE `manager` SET `json` = '{$json}' WHERE `user` = '{$user["id"]}'");
header("Location: ?");
exit;
}
if($id == 3){
$gold = (100 * $chest->{"chest_{$id}"});
$_SESSION["alert"] = "<div class=\"alert\">
<img src=\"/images/manager/chest/{$id}_1.png\" width=\"50\" alt=\"\">
<div class=\"center\">
<div class=\"blue\">Прибыль:</div>
Сахар <img src=\"/images/icons/gold.png\" width=\"16\" height=\"16\" alt=\"\">
<span class=\"green\">+{$gold}</span>
</div>
</div>
<div class=\"alert_bottom\"></div>";
mysql_query("UPDATE `users` SET `g` = `g` + '{$gold}' WHERE `id` = '{$user["id"]}'");
$json = json_decode($manager["json"]);
$json->{"chest_{$id}"} -= $chest->{"chest_{$id}"};
$json = json_encode($json);
mysql_query("UPDATE `manager` SET `json` = '{$json}' WHERE `user` = '{$user["id"]}'");
header("Location: ?");
exit;
}
header("Location: ?");
exit;
}
if(isset($_GET["finish"]) and $chest->{"chest_1"} == 0 and $chest->{"chest_2"} == 0 and $chest->{"chest_3"} == 0){
mysql_query("DELETE FROM `manager_battle` WHERE `user` = '{$user["id"]}'");
header("Location: ?");
exit;
}
if(isset($_SESSION["alert"])){
echo $_SESSION["alert"];
unset($_SESSION["alert"]);
}
echo "<div class=\"content\">
<div class=\"block center header\">
Открой сундуки
</div>
<div class=\"dotted\"></div>
<div class=\"block center\">";
if($chest->{"chest_{$i}"} < 1) $chest->{"chest_{$i}"} = 0;
echo "
<div class=\"chest-block inline-block\">";
if($chest->{"chest_1"} > 0){
echo"
<a href=\"".($chest->{"chest_1"} != 0 ? "?open-chest=1" : "#")."\">
<span style=\"display: inline-block; position: relative; width: 80px; height: 64px; background-size: 80px 64px; background-image: url('/images/manager/chest/1_0.png')\">
<div style=\"position: absolute; bottom: 0; background-color: black; padding: 5px; border-radius: 8px; border: 1px solid yellow; margin: 0 auto; text-align: center; left: 10px; right: 10px\">{$chest->{"chest_1"}} шт.</div>
</span>
</a>";
}else{}
if($chest->{"chest_2"} > 0){
echo"
<a href=\"".($chest->{"chest_2"} != 0 ? "?open-chest=2" : "#")."\">
<span style=\"display: inline-block; position: relative; width: 80px; height: 64px; background-size: 80px 64px; background-image: url('/images/manager/chest/2_0.png')\">
<div style=\"position: absolute; bottom: 0; background-color: black; padding: 5px; border-radius: 8px; border: 1px solid yellow; margin: 0 auto; text-align: center; left: 10px; right: 10px\">{$chest->{"chest_2"}} шт.</div>
</span>
</a>";
}else{}
if($chest->{"chest_3"} > 0){
echo"
<a href=\"".($chest->{"chest_3"} != 0 ? "?open-chest=3" : "#")."\">
<span style=\"display: inline-block; position: relative; width: 80px; height: 64px; background-size: 80px 64px; background-image: url('/images/manager/chest/3_0.png')\">
<div style=\"position: absolute; bottom: 0; background-color: black; padding: 5px; border-radius: 8px; border: 1px solid yellow; margin: 0 auto; text-align: center; left: 10px; right: 10px\">{$chest->{"chest_3"}} шт.</div>
</span>
</a>";
}else{}
echo"</div>";
echo "</div>";
if($chest->{"chest_1"} == 0 and $chest->{"chest_2"} == 0 and $chest->{"chest_3"} == 0)
echo "
<div class=\"block center\">
<span class=\"btn_start\">
<span class=\"btn_end\">
<a class=\"btn\" href=\"?finish\">Завершить</a>
</span>
</span>
</div>";
echo "</div>";
include "./system/f.php";
exit;
}
$boss_hp = round(100 / (($array["vit"] * $manager_battle["manager"]) / $manager_battle["manager_health"]));
if($boss_hp < 0) $boss_hp = 0;
$user_hp = round(100 / ($user["vit"] / $manager_battle["health"]));
if($user_hp < 0) $user_hp = 0;
if(isset($_GET["attack"])){
$time_attack = isset($_SESSION["time_attack"]) && !empty($_SESSION["time_attack"]) ? intval($_SESSION["time_attack"]) : false;
if($time_attack < time()){
$user_damage = ($user["str"] - ($array["def"] * $manager_battle["manager"]));
$user_damage += rand(($user_damage * 0.02), ($user_damage * 0.1));
if ($user_damage < 0) $user_damage = 0;
$_SESSION["log_battl"]["user_damage"] = $user_damage;
$boss_damage = (($array["str"] * $manager_battle["manager"]) - $user["def"]);
$boss_damage += rand(($boss_damage * 0.04), ($boss_damage * 0.2));
if ($boss_damage < 0) $boss_damage = rand((($array["str"] * $manager_battle["manager"]) * 0.02), (($array["str"] * $manager_battle["manager"]) * 0.1));
$_SESSION["log_battle"]["boss_damage"] = $boss_damage;
$_SESSION["time_attack"] = time();
mysql_query("UPDATE `manager_battle` SET `health` = `health` - '{$boss_damage}', `manager_health` = `manager_health` - '{$user_damage}' WHERE `user` = '{$user["id"]}'");
if($manager_battle["manager_health"] < $user_damage or $manager_battle["manager_health"] < 0){
$health = ($array["vit"] * ($manager_battle["manager"] + 1));
mysql_query("UPDATE `manager_battle` SET `manager` = `manager` + '1', `manager_health` = '{$health}' WHERE `user` = '{$user["id"]}'");
$rand = mt_rand(1, 3);
$json = json_decode($manager["json"]);
$json->{"chest_{$rand}"} += 1;
$json = json_encode($json);
mysql_query("UPDATE `manager` SET `json` = '{$json}' WHERE `user` = '{$user["id"]}'");
}
header("Location: ?");
exit;
}
}
echo "<div class=\"content\">
<div class=\"block center header\">
<img src=\"/images/icons/circle.png\" alt=\"\">
<a href=\"?\"><u>Завхоз</u></a><span class=\"white\">, "._time($manager_battle["time"] - time())."</span>
</div>
<div class=\"dotted\"></div>
<div style=\"\">
<div class=\"block\">
<div class=\"center\">
<a href=\"?attack\">
<img class=\"left mr8\" src=\"/images/manager/boss.jpg\" width=\"50\" alt=\"\" style=\"border: 1px solid #f00\">
</a>
</div>
<img src=\"/images/icons/boss.png\" width=\"16\" hegiht=\"16\" alt=\"\">
<span class=\"color1\">
<u>Завхоз</u>
</span>
<span class=\"white\">
<img src=\"/images/icons/level.png\" width=\"16\" height=\"16\" alt=\"\"> {$manager_battle["manager"]} ур.
</span>
";
if(isset($_SESSION["log_battl"])){
echo"
<span class=\"green\">
-".n_f($_SESSION["log_battl"]["user_damage"])."</span>";
unset($_SESSION["log_battl"]);
}
echo"
<div class=\"small\">
<img src=\"/images/icons/currentHealth.png\" width=\"16\" height=\"16\" alt=\"\"> ".n_f($manager_battle["manager_health"])."
<img src=\"/images/icons/damage.png\" width=\"16\" height=\"16\" alt=\"\"> ".n_f($array["str"] * $manager_battle["manager"])."
<img src=\"/images/icons/armor.png\" width=\"16\" height=\"16\" alt=\"\"> ".n_f($array["def"] * $manager_battle["manager"])."
</div>
<div class=\"clear\"></div>
</div>
</div>
<div class=\"dotted\"></div>
<div class=\"block center\">
<span class=\"btn_start\">
<span class=\"btn_end\">
<a class=\"btn\" href=\"?attack\">Нанести удар</a>
</span>
</span>
</div>
<div class=\"dotted\"></div>";
for ($u_w = 1; $u_w <= 8; $u_w++) {
$inv = mysql_fetch_assoc(mysql_query("SELECT `item` FROM `inv` WHERE `user` = '{$user["id"]}' AND `equip` = '1' AND `id` = '{$user["w_{$u_w}"]}'"));
$w_[$u_w] = $inv == true ? $inv["item"] : 0;
}
echo "<div style=\"\">
<div class=\"block\">
<a>
<img class=\"left mr8\" src=\"/ManekenMini/{$user[r]}/{$w_[1]}/{$w_[2]}/{$w_[3]}/{$w_[4]}/{$w_[5]}/{$w_[6]}/{$w_[7]}/{$w_[8]}/\" width=\"50\" height=\"50\" alt=\"\">
</a>
<img src=\"/images/icons/{$user["r"]}.png\" width=\"16\" height=\"16\" alt=\"\">
<span class=\"color3\"><u>{$user["login"]}</u></span>
<span class=\"white\">
<img src=\"/images/icons/level.png\" width=\"16\" height=\"16\" alt=\"\"> {$user["level"]} ур.
</span>";
if(isset($_SESSION["log_battle"])){
echo"
<span class=\"red\">
- ".n_f($_SESSION["log_battle"]["boss_damage"])."
</span>";
unset($_SESSION["log_battle"]);
}
echo"
<div style=\"margin: 2px 0\">
<div class=\"m3\" style=\"padding-left: 58px\">
<div style=\"width: 100%; height: 4px\" class=\"progress-grey\">
<div style=\"width: {$user_hp}%; height: 4px\" class=\"progress-green\"></div>
</div>
</div>
</div>
<div class=\"small\">
<img src=\"/images/icons/currentHealth.png\" width=\"16\" height=\"16\" alt=\"\"> ".n_f($manager_battle["health"])."
<img src=\"/images/icons/damage.png\" width=\"16\" height=\"16\" alt=\"\"> ".n_f($user["str"])."
<img src=\"/images/icons/armor.png\" width=\"16\" height=\"16\" alt=\"\"> ".n_f($user["def"])."
</div>
<div class=\"clear\"></div>
</div>
</div>
<div class=\"dotted\"></div>";
$chest = json_decode($manager["json"]);
for ($i = 1; $i <= 3; $i++)
if($chest->{"chest_{$i}"} < 1) $chest->{"chest_{$i}"} = 0;
echo'<div class="center block">';
if($chest->{"chest_1"} > 0){
echo"
<span style=\"display: inline-block; position: relative; width: 80px; height: 64px; background-size: 80px 64px; background-image: url('/images/manager/chest/1_0.png')\">
<div style=\"position: absolute; bottom: 0; background-color: black; padding: 5px; border-radius: 8px; border: 1px solid yellow; margin: 0 auto; text-align: center; left: 10px; right: 10px\">{$chest->{"chest_1"}} шт.</div>
</span>
";
}else{}
if($chest->{"chest_2"} > 0){
echo"
<span style=\"display: inline-block; position: relative; width: 80px; height: 64px; background-size: 80px 64px; background-image: url('/images/manager/chest/2_0.png')\">
<div style=\"position: absolute; bottom: 0; background-color: black; padding: 5px; border-radius: 8px; border: 1px solid yellow; margin: 0 auto; text-align: center; left: 10px; right: 10px\">{$chest->{"chest_2"}} шт.</div>
</span>
";
}else{}
if($chest->{"chest_3"} > 0){
echo"
<span style=\"display: inline-block; position: relative; width: 80px; height: 64px; background-size: 80px 64px; background-image: url('/images/manager/chest/3_0.png')\">
<div style=\"position: absolute; bottom: 0; background-color: black; padding: 5px; border-radius: 8px; border: 1px solid yellow; margin: 0 auto; text-align: center; left: 10px; right: 10px\">{$chest->{"chest_3"}} шт.</div>
</span>
";
}else{}
echo"</div><center>
<span class=\"center color2\">Этап сражений: {$manager_battle["manager"]}</span>
</center> </div>";
}
include "./system/f.php";