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 '';
         }
     }
 }
 public static function createAccount($ninja_name, $email, $class_identity)
 {
     $found = Player::findByName($ninja_name);
     if ($found) {
         throw new Exception("Test user found [{$found}] with name [{$ninja_name}] already exists");
     }
     $ip = isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // Create test user, unconfirmed, whatever the default is for activity.
     $confirm = rand(1000, 9999);
     //generate confirmation code
     $class_id = query_item('SELECT class_id FROM class WHERE identity = :class_identity', [':class_identity' => $class_identity]);
     $ninja = new Player();
     $ninja->uname = $ninja_name;
     $ninja->verification_number = $confirm;
     $ninja->active = 1;
     $ninja->_class_id = $class_id;
     $ninja->save();
     Account::create($ninja->id(), $email, TestAccountCreateAndDestroy::$test_password, $confirm, 0, 1, $ip);
     if ($confirm) {
         $ninja->active = 1;
         $ninja->save();
         $account = Account::findByChar($ninja);
         $account->confirmed = 1;
         $account->setOperational(true);
         $account->save();
     }
     return $ninja->id();
 }
Example #3
0
 /**
  * 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]];
 }
Example #4
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();
 }
Example #5
0
 public function testNewPlayerSave()
 {
     $player = new Player();
     try {
         $player->save();
         $this->assertTrue(false, 'Player with no data saved successfully! Bad!');
     } catch (\PDOException $e) {
         $this->assertContains('Not null violation', $e->getMessage());
     }
 }