SolveExp moved to fbattle

This commit is contained in:
Ivor Barhansky 2022-06-11 14:58:58 +03:00
parent 5fbccc6a43
commit 775a56c4c8
3 changed files with 139 additions and 139 deletions

View File

@ -323,7 +323,7 @@ class fbattle
$this->damage[$enemy] += ($mf['he']['udar'] * $hs);
$jv = ($this->user['hp'] - $mf['he']['udar'] * $hs);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $mf['he']['udar'] * $hs);
$this->exp[$enemy] += self::SolveExp($enemy, $this->user['id'], $mf['he']['udar'] * $hs);
$this->add_log($this->razmen_log("krit" . $m, $this->battle[$enemy][$this->user['id']][0], $this->get_wep_type($this->enemyhar['weap']), ($mf['he']['udar'] * $hs), $enemy, $this->en_class, $this->user['id'], $this->my_class, ($this->user['hp'] - $mf['he']['udar'] * $hs), $this->user['maxhp']));
mysql_query('UPDATE users SET `hp` = `hp` - ' . ($mf['he']['udar'] * $hs) . ' WHERE `id` = ' . $this->user['id'] . '');
@ -332,7 +332,7 @@ class fbattle
$this->damage[$enemy] += ($mf['he']['udar']);
$jv = ($this->user['hp'] - $mf['he']['udar']);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $mf['he']['udar']);
$this->exp[$enemy] += self::SolveExp($enemy, $this->user['id'], $mf['he']['udar']);
$this->add_log($this->razmen_log("udar", $this->battle[$enemy][$this->user['id']][0], $this->get_wep_type($this->enemyhar['weap']), $mf['he']['udar'], $enemy, $this->en_class, $this->user['id'], $this->my_class, ($this->user['hp'] - $mf['he']['udar']), $this->user['maxhp']));
mysql_query('UPDATE users SET `hp` = `hp` - ' . ($mf['he']['udar']) . ' WHERE `id` = ' . $this->user['id'] . '');
@ -370,7 +370,7 @@ class fbattle
}
$this->damage[$this->user['id']] += ($mf['me']['udar'] * $hs);
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $mf['me']['udar'] * $hs);
$this->exp[$this->user['id']] += self::SolveExp($this->user['id'], $enemy, $mf['me']['udar'] * $hs);
$this->add_log($this->razmen_log("krit" . $m, $attack, $this->get_wep_type($this->user['weap']), ($mf['me']['udar'] * $hs), $this->user['id'], $this->my_class, $enemy, $this->en_class, ($this->enemyhar['hp'] - $mf['me']['udar'] * $hs), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {
@ -382,7 +382,7 @@ class fbattle
// я попал куда надо
$this->damage[$this->user['id']] += ($mf['me']['udar']);
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $mf['me']['udar']);
$this->exp[$this->user['id']] += self::SolveExp($this->user['id'], $enemy, $mf['me']['udar']);
$this->add_log($this->razmen_log("udar", $attack, $this->get_wep_type($this->user['weap']), $mf['me']['udar'], $this->user['id'], $this->my_class, $enemy, $this->en_class, ($this->enemyhar['hp'] - $mf['me']['udar']), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {
@ -1982,4 +1982,134 @@ class fbattle
fclose($fp); //закрытие
}
public static 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);
}
}

View File

@ -779,7 +779,7 @@ class fbattle
}
$this->damage[$enemy] += $yron;
$jv = ($hp_1['hp'] - $yron);
$this->exp[$enemy] += SolveExp($enemy, $uid, $yron);
$this->exp[$enemy] += fbattle::SolveExp($enemy, $uid, $yron);
$this->AddToLogBot($this->razmen_log("krit" . $m, $this->battle[$enemy][$uid][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['he'], $uid, $color['me'], ($hp_1['hp'] - $yron), $maxhp_2['maxhp']));
mysql_query('UPDATE `bots` SET `hp` = (`hp` - ' . $yron . ') WHERE `id` = "' . $uid . '" LIMIT 1'); ### Maybe not limited
} elseif (!$this->GetBlock("me", $this->battle[$enemy][$uid][0], $defend, $enemy)) {
@ -922,7 +922,7 @@ class fbattle
$this->damage[$enemy] += $yron;
$jv = ($this->user['hp'] - $yron);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $yron);
$this->exp[$enemy] += fbattle::SolveExp($enemy, $this->user['id'], $yron);
$this->AddToLog($this->razmen_log("krit" . $m, $this->battle[$this->user['id']][$enemy][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['me'], $this->user['id'], $color['he'], ($this->user['hp'] - $yron), $this->user['maxhp']));
mysql_query('UPDATE `users` SET `hp` = (`hp` - ' . $yron . ') WHERE `id` = "' . $this->user['id'] . '" LIMIT 1');
@ -948,7 +948,7 @@ class fbattle
$this->damage[$enemy] += $yron;
$jv = ($this->user['hp'] - $yron);
$this->exp[$enemy] += SolveExp($enemy, $this->user['id'], $yron);
$this->exp[$enemy] += fbattle::SolveExp($enemy, $this->user['id'], $yron);
$this->AddToLog($this->razmen_log("udar", $this->battle[$enemy][$this->user['id']][0], $this->GetWeaponType($this->enemyhar['weap']), $yron, $enemy, $color['me'], $this->user['id'], $color['he'], ($this->user['hp'] - $yron), $this->user['maxhp']));
mysql_query('UPDATE `users` SET `hp` = (`hp` - ' . $yron . ') WHERE `id` = "' . $this->user['id'] . '" LIMIT 1');
} else {
@ -998,7 +998,7 @@ class fbattle
}
$this->damage[$this->user['id']] += $yron;
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $yron);
$this->exp[$this->user['id']] += fbattle::SolveExp($this->user['id'], $enemy, $yron);
$this->AddToLog($this->razmen_log("krit" . $m, $attack, $this->GetWeaponType($this->user['weap']), $yron, $this->user['id'], $color['me'], $enemy, $color['he'], ($this->enemyhar['hp'] - $yron), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {
@ -1030,7 +1030,7 @@ class fbattle
$yron = $hp_u['hp'];
}
$this->damage[$this->user['id']] += $yron;
$this->exp[$this->user['id']] += SolveExp($this->user['id'], $enemy, $yron);
$this->exp[$this->user['id']] += fbattle::SolveExp($this->user['id'], $enemy, $yron);
$this->AddToLog($this->razmen_log("udar", $attack, $this->GetWeaponType($this->user['weap']), $yron, $this->user['id'], $color['me'], $enemy, $color['he'], ($this->enemyhar['hp'] - $yron), $this->enemyhar['maxhp']));
if ($enemy > _BOTSEPARATOR_) {

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);
}