Example #1
0
 /**
  * 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 '';
         }
     }
 }
Example #2
0
 private function attackVillager(Player $player)
 {
     $damage = rand(0, 10);
     $just_villager = rand(0, 20);
     $bounty = 0;
     $gold = 0;
     if ($victory = $player->harm($damage)) {
         $gold = rand(0, 20);
         $player->setGold($player->gold + $gold);
         // *** Bounty or no bounty ***
         if ($player->level > 1 && $player->level <= 20) {
             $bounty = floor($player->level / 3);
             $player->setBounty($player->bounty + $bounty);
         }
         if (!$just_villager) {
             // Something beyond just a villager, drop a shuriken
             $inventory = new Inventory($player);
             $inventory->add('shuriken', 1);
         }
     }
     $player->save();
     return ['npc.peasant.tpl', ['just_villager' => $just_villager, 'attack' => $damage, 'gold' => $gold, 'level' => $player->level, 'bounty' => $bounty, 'victory' => $victory]];
 }
Example #3
0
 /**
  * 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();
 }