示例#1
0
 public function testControllerAttackAsIfAgainstAMerchant2()
 {
     $_SERVER['REQUEST_URI'] = '/npc/attack/merchant2';
     $init_gold = $this->char->gold();
     $npco = new Npc('merchant2');
     $response = $this->controller->attack();
     $final_char = Player::find($this->char->id());
     $this->assertNotEmpty($response);
     $this->assertEquals('merchant2', $response['parts']['victim']);
     $this->assertGreaterThan(0, $npco->min_gold());
     $this->assertGreaterThan($init_gold, $final_char->gold());
 }
示例#2
0
 /**
  * The reward for defeating an npc, less if items popped
  *
  * @param Npc $npco
  * @param boolean $reward_item Any items were rewarded.
  * @return int
  * @note
  * If npc gold explicitly set to 0, reward gold will be totally skipped
  * "rich" npcs will have a higher gold minimum
  */
 private function calcReceivedGold(Npc $npco, $reward_item)
 {
     if ($npco->gold() === 0) {
         // These npcs simply don't give gold.
         return 0;
     }
     // Hack a little off max gold if items received.
     $divisor = 1;
     if ($reward_item) {
         $divisor = self::ITEM_DECREASES_GOLD_FACTOR;
     }
     return rand($npco->min_gold(), floor($npco->gold() / $divisor));
 }