/** * 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 ''; } } }
/** * Normal attack on a single thief. */ private function attackNormalThief(Player $player) { $damage = rand(0, 35); // Damage done $gold = 0; if ($victory = $player->harm($damage)) { $gold = rand(0, 40); // Gold in question if ($damage > 30) { // Steal gold $player->setGold(max(0, $player->gold - $gold)); } else { if ($damage < 30) { // award gold and item $player->setGold($player->gold + $gold); $inventory = new Inventory($player); $inventory->add('shuriken', 1); } } } $player->save(); return ['npc.thief.tpl', ['attack' => $damage, 'gold' => $gold, 'victory' => $victory]]; }
/** * If you try to bribe with a negative bounty, the doshin beat you up and take your money! * * @param Player $char * @return Player * @note * If the player loses a substantial enough amount, the doshin will actually decrease the bounty. */ private function doshinAttack(Player $char) { $current_bounty = $char->bounty; $doshin_takes = floor($char->gold * self::DOSHIN_CUT); // If the doshin take a lot of money, they'll // actually reduce the bounty somewhat. $bounty_reduction = (int) min($current_bounty, $doshin_takes > self::SAFE_WEALTH ? $doshin_takes / self::BRIBERY_DIVISOR : 0); if (0 < $bounty_reduction) { $char->setBounty($char->bounty - $bounty_reduction); } // Do fractional damage to the char $char->setHealth($char->health - floor($char->health * self::FAILED_BRIBERY_PAIN)); // Regardless, you lose some gold. $char->setGold($char->gold - $doshin_takes); return $char->save(); }