<?php
header("Content-Type: text/plain; charset=utf-8");
FIRST => 'наносит резкий удар, лезвие проходит в дюйме от шеи противника.',
SECOND => 'делает ложный выпад и наносит неожиданный удар, но удача была в этот раз на стороне врага.',
THIRD => 'издает победный клич и наносит мощный рубящий удар, цель удара чудом избежала чудовищного удара.'
);
class Hero
{
public $name;
public $health;
public $armorLow;
public $armorHigh;
public $block;
public $dodgeCrit;
public $crit;
public $attackLow;
public $attackHigh;
public $charisma;
public $agility;
public $skill;
public $hitChance;
public $doubleHit = 0;
public $enemyBlock;
public $enemyArmorLow;
public $enemyArmorHigh;
public $enemyName;
public function __construct($name, $attackLow, $attackHigh, $health, $armorLow, $armorHigh, $block, $dodgeCrit, $crit, $charisma, $agility, $skill)
{
$this->name = $name;
$this->attackLow = $attackLow;
$this->attackHigh = $attackHigh;
$this->health = $health;
$this->armorLow = $armorLow;
$this->armorHigh = $armorHigh;
$this->block = $block;
$this->dodgeCrit = $dodgeCrit;
$this->crit = $crit;
$this->charisma = $charisma;
$this->agility = $agility;
$this->skill = $skill;
}
public function getAverageDmg() //средний урон персонажа
{
return mt_rand($this->attackLow, $this->attackHigh); }
public function getAverageDmgReduction() //среднее число блокируемое доспехами урона
{
return mt_rand($this->enemyArmorLow, $this->enemyArmorHigh); }
public function isDoubleAttack()
{
if ($roll <= $this->doubleHit) {
return 1;
} else {
return 0;
}
}
}
class Game
{
public $heroes;
public function __construct($heroFirst, $heroSecond)
{
$this->heroes[] = $heroFirst;
$this->heroes[] = $heroSecond;
}
private function makeRoll()
{
}
private function makeOneHit($hero) //шанс на удар->блок->крит
{
global $phrasesDodge;
if ($this->makeRoll() > $hero->hitChance) //true = промах
{
return 0;
}
if ($this->makeRoll() < $hero->enemyBlock) //true = атака заблокирована
{
return 0;
}
if ($this->makeRoll() > $hero->crit) // true = простая атака
{
$dmg = $hero->getAverageDmg() - $hero->getAverageDmgReduction();
return $dmg;
} else { //крит
$dmg = $hero->getAverageDmg() * 2 - $hero->getAverageDmgReduction(); //урон х 2 за минусом поглощения
return $dmg;
}
}
private function makeOneRound()
{
foreach ($this->heroes as $number => $hero) {
if ($hero->isDoubleAttack()) {
$k = 2;
} else {
$k = 1;
}
for ($i = 1; $i <= $k; $i++) {
$dmg = $this->makeOneHit($hero);
if (!isset($damage[$number])) { $damage[$number] = 0;
}
$damage[$number] += $dmg;
}
}
return $damage;
}
private function fillNotFilledStrings() //присвоить героям шанс на вторую атаку и шанс на успешное попадание исходя из разницы в харизме
{
$charAbs = abs($this->heroes[0]->charisma - $this->heroes[1]->charisma); if ($charAbs > 100) {
$charAbs = 100;
}
$charOne = $this->heroes[0]->charisma;
$charTwo = $this->heroes[1]->charisma;
if ($charOne > $charTwo) {
$this->heroes[0]->doubleHit = $charAbs;
} elseif ($charOne < $charTwo) {
$this->heroes[1]->doubleHit = $charAbs;
}
// шанс на попадание
$this->heroes[0]->hitChance = round(($this->heroes[0]->skill / ($this->heroes[1]->skill + $this->heroes[0]->agility)) * 100); $this->heroes[1]->hitChance = round(($this->heroes[1]->skill / ($this->heroes[0]->skill + $this->heroes[1]->agility)) * 100); //заполнение строки enemyBlock
$this->heroes[0]->enemyBlock = $this->heroes[1]->block;
$this->heroes[1]->enemyBlock = $this->heroes[0]->block;
//заполнение строки поглощение урона броней
$this->heroes[0]->enemyArmorLow = $this->heroes[1]->armorLow;
$this->heroes[0]->enemyArmorHigh = $this->heroes[1]->armorHigh;
$this->heroes[1]->enemyArmorLow = $this->heroes[0]->armorLow;
$this->heroes[1]->enemyArmorHigh = $this->heroes[0]->armorHigh;
//строка - имя врага
$this->heroes[0]->enemyName = $this->heroes[1]->name;
$this->heroes[1]->enemyName = $this->heroes[0]->name;
}
public function makeTwentyRounds()
{
$firstFullDmg = 0;
$secondFullDmg = 0;
$this->fillNotFilledStrings();
for ($i = 1; $i <= 20; $i++) {
$dmg = $this->makeOneRound();
list($firstDamage, $secondDamage) = $dmg; if ($this->heroes[0]->health < $secondDamage) {
$this->heroes[0]->health = 1;
return 1;
}
if ($this->heroes[1]->health < $firstDamage) {
$this->heroes[1]->health = 1;
return 0;
}
$this->heroes[0]->health -= $secondDamage;
$this->heroes[1]->health -= $firstDamage;
$firstFullDmg += $firstDamage;
$secondFullDmg += $secondDamage;
}
if ($firstFullDmg > $secondFullDmg) {
return 0;
} elseif ($firstFullDmg < $secondFullDmg) {
return 1;
} else {
return 2;
}
}
}
$hero1 = new Hero('DoctorS', 504, 563, 19520, 225, 276, 39, 25, 51, 1276, 890, 1182);
$hero2 = new Hero('Demarest', 350, 397, 14275, 214, 261, 50, 25, 41, 775, 774, 928);
/*
$hero11 = new Hero('DoctorS', 504, 563, 19520, 225, 276, 39, 25, 51, 1276);
$hero12 = new Hero('BkHitMan', 460, 515, 18919, 216, 264, 31, 23, 28, 1072);
$game2 = new Game($hero11, $hero12);
echo "\n\n\n\n\n";
$game2->makeTwentyRounds();
$game->makeTwentyRounds();*/
$game = new Game($hero1, $hero2);
$winOne = 0;
$winTwo = 0;
$draw = 0;
$k = 10000;
for ($i = 1; $i <= $k; $i++) {
$x = $game->makeTwentyRounds();
if ($x == 0) {
$winOne++;
} elseif ($x == 1) {
$winTwo++;
} elseif ($x == 2) {
$draw++;
}
}
$chanceFirstWin = round(($winOne / $k) * 100); $chanceSecondWin = round(($winTwo / $k) * 100); $chanceDraw = round(($draw / $k) * 100); echo "Winner: \n $chanceFirstWin%- first, $chanceSecondWin%- second, $chanceDraw% - draw";
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoIlVURi04Iik7CgpkZWZpbmUoJ0ZJUlNUJywgJzEnKTsKZGVmaW5lKCdTRUNPTkQnLCAnMicpOwpkZWZpbmUoJ1RISVJEJywgJzMnKTsKJHBocmFzZXNEb2RnZSA9IGFycmF5KAogICAgRklSU1QgPT4gJ9C90LDQvdC+0YHQuNGCINGA0LXQt9C60LjQuSDRg9C00LDRgCwg0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mhpdENoYW5jZSkgLy90cnVlID0g0L/RgNC+0LzQsNGFCiAgICAgICAgICAgIHsKICAgICAgICAgICAgJHJvbGwgPSBtdF9yYW5kKDEsIDMpOwogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgaWYgKCR0aGlzLT5tYWtlUm9sbCgpIDwgJGhlcm8tPmVuZW15QmxvY2spIC8vdHJ1ZSA9INCw0YLQsNC60LAg0LfQsNCx0LvQvtC60LjRgNC+0LLQsNC90LAKICAgICAgICAgICAgewogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgaWYgKCR0aGlzLT5tYWtlUm9sbCgpID4gJGhlcm8tPmNyaXQpIC8vIHRydWUgPSDQv9GA0L7RgdGC0LDRjyDQsNGC0LDQutCwCiAgICAgICAgICAgIHsKICAgICAgICAgICAgJGRtZyA9ICRoZXJvLT5nZXRBdmVyYWdlRG1nKCkgLSAkaGVyby0+Z2V0QXZlcmFnZURtZ1JlZHVjdGlvbigpOwogICAgICAgICAgICByZXR1cm4gJGRtZzsKICAgICAgICB9IGVsc2UgeyAvL9C60YDQuNGCCiAgICAgICAgICAgICRkbWcgPSAkaGVyby0+Z2V0QXZlcmFnZURtZygpICogMiAtICRoZXJvLT5nZXRBdmVyYWdlRG1nUmVkdWN0aW9uKCk7IC8v0YPRgNC+0L0g0YUgMiDQt9CwINC80LjQvdGD0YHQvtC8INC/0L7Qs9C70L7RidC10L3QuNGPCiAgICAgICAgICAgIHJldHVybiAkZG1nOwogICAgICAgIH0KICAgICAgICAKICAgIH0KICAgIHByaXZhdGUgZnVuY3Rpb24gbWFrZU9uZVJvdW5kKCkKICAgIHsKICAgICAgICAkZGFtYWdlID0gYXJyYXkoKTsKICAgICAgICBmb3JlYWNoICgkdGhpcy0+aGVyb2VzIGFzICRudW1iZXIgPT4gJGhlcm8pIHsKICAgICAgICAgICAgaWYgKCRoZXJvLT5pc0RvdWJsZUF0dGFjaygpKSB7CiAgICAgICAgICAgICAgICAkayA9IDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAkayA9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZm9yICgkaSA9IDE7ICRpIDw9ICRrOyAkaSsrKSB7CiAgICAgICAgICAgICAgICAkZG1nID0gJHRoaXMtPm1ha2VPbmVIaXQoJGhlcm8pOwogICAgICAgICAgICAgICAgaWYgKCFpc3NldCgkZGFtYWdlWyRudW1iZXJdKSkgewogICAgICAgICAgICAgICAgICAgICRkYW1hZ2VbJG51bWJlcl0gPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgJGRhbWFnZVskbnVtYmVyXSArPSAkZG1nOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAkZGFtYWdlOwogICAgfQogICAgCiAgICAKICAgIAogICAgcHJpdmF0ZSBmdW5jdGlvbiBmaWxsTm90RmlsbGVkU3RyaW5ncygpIC8v0L/RgNC40YHQstC+0LjRgtGMINCz0LXRgNC+0Y/QvCDRiNCw0L3RgSDQvdCwINCy0YLQvtGA0YPRjiDQsNGC0LDQutGDINC4INGI0LDQvdGBINC90LAg0YPRgdC/0LXRiNC90L7QtSDQv9C+0L/QsNC00LDQvdC40LUg0LjRgdGF0L7QtNGPINC40Lcg0YDQsNC30L3QuNGG0Ysg0LIg0YXQsNGA0LjQt9C80LUKICAgIHsKICAgICAgICAkY2hhckFicyA9IGFicygkdGhpcy0+aGVyb2VzWzBdLT5jaGFyaXNtYSAtICR0aGlzLT5oZXJvZXNbMV0tPmNoYXJpc21hKTsKICAgICAgICBpZiAoJGNoYXJBYnMgPiAxMDApIHsKICAgICAgICAgICAgJGNoYXJBYnMgPSAxMDA7CiAgICAgICAgfQogICAgICAgICRjaGFyT25lID0gJHRoaXMtPmhlcm9lc1swXS0+Y2hhcmlzbWE7CiAgICAgICAgJGNoYXJUd28gPSAkdGhpcy0+aGVyb2VzWzFdLT5jaGFyaXNtYTsKICAgICAgICBpZ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dGhpcy0+aGVyb2VzWzBdLT5oZWFsdGggPSAxOwogICAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKCR0aGlzLT5oZXJvZXNbMV0tPmhlYWx0aCA8ICRmaXJzdERhbWFnZSkgewogICAgICAgICAgICAgICAgJHRoaXMtPmhlcm9lc1sxXS0+aGVhbHRoID0gMTsKICAgICAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgICAgICB9CiAgICAgICAgICAgICR0aGlzLT5oZXJvZXNbMF0tPmhlYWx0aCAtPSAkc2Vjb25kRGFtYWdlOwogICAgICAgICAgICAkdGhpcy0+aGVyb2VzWzFdLT5oZWFsdGggLT0gJGZpcnN0RGFtYWdlOwogICAgICAgICAgICAkZmlyc3RGdWxsRG1nICs9ICRmaXJzdERhbWFnZTsKICAgICAgICAgICAgJHNlY29uZEZ1bGxEbWcgKz0gJHNlY29uZERhbWFnZTsKICAgICAgICB9CiAgICAgICAgaWYgKCRmaXJzdEZ1bGxEbWcgPiAkc2Vjb25kRnVsbERtZykgewogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9IGVsc2VpZiAoJGZpcnN0RnVsbERtZyA8ICRzZWNvbmRGdWxsRG1nKSB7CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiAyOwogICAgICAgIH0KICAgICAgICAKICAgIH0KfQokaGVybzEgID0gbmV3IEhlcm8oJ0RvY3RvclMnLCA1MDQsIDU2MywgMTk1MjAsIDIyNSwgMjc2LCAzOSwgMjUsIDUxLCAxMjc2LCA4OTAsIDExODIpOwokaGVybzIgID0gbmV3IEhlcm8oJ0RlbWFyZXN0JywgMzUwLCAzOTcsIDE0Mjc1LCAyMTQsIDI2MSwgNTAsIDI1LCA0MSwgNzc1LCA3NzQsIDkyOCk7Ci8qCiRoZXJvMTEgPSBuZXcgSGVybygnRG9jdG9yUycsIDUwNCwgNTYzLCAxO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