Skip to content

Instantly share code, notes, and snippets.

@Fuitad
Last active September 24, 2017 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fuitad/48750e8781351d7caba95d1bdac70baa to your computer and use it in GitHub Desktop.
Save Fuitad/48750e8781351d7caba95d1bdac70baa to your computer and use it in GitHub Desktop.
Fighting enemies
<?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