Last active
September 24, 2017 23:48
-
-
Save Fuitad/48750e8781351d7caba95d1bdac70baa to your computer and use it in GitHub Desktop.
Fighting enemies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach ($roundData->getEnemy() as $enemy) { | |
//30% chance to attack a buddy | |
$enemyHp = $enemy->getHp(); | |
while ($enemyHp > 0) { | |
if (rand(1, 100) <= 30) { | |
/** @var \FfrkCentral\Ffrk\Models\Battle\Buddy $randomBuddyToDamage */ | |
$randomBuddyToDamage = $battleData->getBuddy()[array_rand($battleData->getBuddy())]; | |
$damageDoneToBuddy = round($randomBuddyToDamage->getMaxHp() * (rand(5, 15) / 100)); | |
if (OUTPUT_LEVEL >= 4) { | |
Climate::info(sprintf('<bold>%s</bold> attacks <bold>%s</bold> for <red>%d</red> HP', | |
$enemy->getName(), | |
$this->getAppSession()->getBuddyByBuddyId($randomBuddyToDamage->getId())->getName(), | |
$damageDoneToBuddy | |
)); | |
} | |
$battleResult->logEnemyAction($enemy, $randomBuddyToDamage, $damageDoneToBuddy); | |
} | |
$damageDoneThisAttack = ($enemyHp > 9999) ? 9999 : $enemyHp; | |
/** @var Battle\Buddy $randomBuddyToPerformAtk */ | |
$randomBuddyToPerformAtk = $battleData->getBuddy()[array_rand($battleData->getBuddy())]; | |
if (OUTPUT_LEVEL >= 4) { | |
// enemy gets attacked | |
Climate::info(sprintf('<bold>%s</bold> attacks <bold>%s</bold> for <blue>%d</blue> HP.', | |
$this->getAppSession()->getBuddyByBuddyId($randomBuddyToPerformAtk->getId()), | |
$enemy->getName(), | |
$damageDoneThisAttack | |
)); | |
} | |
$battleResult->logBuddyAction($randomBuddyToPerformAtk, $enemy, $damageDoneThisAttack); | |
$enemyHp -= $damageDoneThisAttack; | |
} | |
//log death into battleresult | |
$battleResult->logEnemyDeath($roundNum, $roundNum === $roundCount, $enemy); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment