SolveExp moved to fbattle

This commit is contained in:
2022-06-11 14:58:58 +03:00
parent 5fbccc6a43
commit 775a56c4c8
3 changed files with 139 additions and 139 deletions
-130
View File
@@ -391,134 +391,4 @@ function addchp($text, $who, $room = 0)
function err($t)
{
echo '<span class="error">' . $t . '</span>';
}
function SolveExp($at_id, $def_id, $damage): float
{
$mods = [
'bloodb' => 1.2,
'btl_1' => 1,
'btl_2' => 0.5,
'btl_3' => 0.05,
];
$baseexp = [
"0" => "2",
"1" => "5",
"2" => "10",
"3" => "15",
"4" => "30",
"5" => "60",
"6" => "90",
"7" => "115",
"8" => "300",
"9" => "400",
"10" => "500",
"11" => "600",
"12" => "700",
"13" => "800",
"14" => "900",
"15" => "1000",
"16" => "1100",
"17" => "1200",
"18" => "1300",
"19" => "1400",
"20" => "1500",
"21" => "1600",
];
$expmf = 0;
$bot_active = false;
$bot_def = false;
if ($at_id > _BOTSEPARATOR_) {
$at_id = Db::getInstance()->fetchColumn('select prototype from bots where bot_id = ?', $at_id);
$bot_active = true;
}
$query = 'select greatest(1, sum(price)) as allprice from users left join inventory on users.id = inventory.owner_id where id = ?';
$atAllPrice = Db::getInstance()->fetchColumn($query, $at_id);
$defAllPrice = Db::getInstance()->fetchColumn($query, $def_id);
$atInfo = new UserStats($at_id);
$defInfo = new UserStats($def_id);
$table_name = $at_id > _BOTSEPARATOR_ ? 'bots' : 'users';
$bt = Db::getInstance()->ofetch('select blood, type, t1, t2 from battle where battle_id = (select battle from ? where id = ?)', [$table_name, $at_id]);
if ($def_id > _BOTSEPARATOR_) {
$def_id = Db::getInstance()->fetchColumn('select prototype from bots where bot_id = ?', $def_id);
$bot_def = true;
}
if ($bt->blood) {
$expmf = $mods['bloodb'];
}
$filebtl = '/tmp/' . $at_id . '.btl';
if ($bt->type == 1 && file_exists($filebtl)) {
$btfl = fopen($filebtl, 'r');
$contents = fread($btfl, filesize($filebtl));
fclose($btfl);
$cnt = substr_count($contents, $def_id);
$exmod = 1;
if ($cnt <= 1) {
$exmod = $mods['btl_1'];
} elseif ($cnt == 2) {
$exmod = $mods['btl_2'];
} elseif ($cnt > 2) {
$exmod = $mods['btl_3'];
}
$expmf = $expmf * $exmod;
}
$standart = [
"0" => 1,
"1" => 1,
"2" => 15,
"3" => 111,
"4" => 265,
"5" => 526,
"6" => 882,
"7" => 919,
"8" => 919,
"9" => 919,
"10" => 919,
"11" => 919,
"12" => 919,
"13" => 919,
"14" => 919,
"15" => 919,
"16" => 919,
"17" => 919,
"18" => 919,
"19" => 919,
"20" => 919,
"21" => 919,
"22" => 919,
"23" => 919,
"24" => 919,
"25" => 919
];
$mfit = ($atAllPrice / ($standart[$atInfo->getLevel()] / 3));
if ($mfit < 0.8) {
$mfit = 0.8;
}
if ($mfit > 1.5) {
$mfit = 1.5;
}
$pls = count(explode(";", $bt->t1)) + count(explode(";", $bt->t2));
if ($pls > 2) {
$mfbot = $bot_active ? 0.3 : 1;
$mfbot2 = $bot_def ? 0.7 : 1;
} else {
$mfbot = 1;
$mfbot2 = 1;
}
if ($expmf == 0) {
$expmf = 1;
}
return round((($baseexp[$defInfo->getLevel()]) * ($defAllPrice / (($atAllPrice + $defAllPrice) / 2)) * ($damage / $defInfo->getMaxHealth()) * $expmf * $mfit * $mfbot * $mfbot2) / 3);
}