/** * Rewards bounty if defender has some, or increments attacker bounty if power disparity * * @return string */ public static function runBountyExchange(Player $user, $defender, $bounty_mod = 0) { assert($defender instanceof Character); // 'cause can't typehint interfaces if ($defender instanceof Player && $defender->bounty > 0) { $bounty = $defender->bounty; $defender->setBounty(0); $defender->save(); $user->setGold($user->gold + $bounty); $user->save(); return "You have received the {$bounty} gold bounty on {$defender}'s head for your deeds!"; } else { // Add bounty to attacker only if defender doesn't already have bounty on them. $disparity = (int) floor(($user->difficulty() - $defender->difficulty()) / 10); $bountyIncrease = min(self::BOUNTY_MIN, max(0, $disparity * static::BOUNTY_MULTIPLIER + $bounty_mod)); // Cap the increase. if ($bountyIncrease + $user->bounty > static::BOUNTY_MAX) { $bountyIncrease = static::BOUNTY_MAX - $user->bounty; } if ($bountyIncrease > 0) { // If Defender has no bounty and there was a level difference $user->setBounty($user->bounty + $bountyIncrease); $user->save(); return "Your victim was much weaker than you. The townsfolk are angered. A bounty of {$bountyIncrease} gold has been placed on your head!"; } else { return ''; } } }