示例#1
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->minGold(), floor($npco->gold() / $divisor));
 }
示例#2
0
 public function testControllerAttackAsIfAgainstAMerchant2()
 {
     $this->markTestSkipped('Merchants are unreliable to test for now.');
     RequestWrapper::inject(Request::create('/npc/attack/merchant2'));
     $this->char->strength = 9999;
     $this->char->health = 9999;
     $init_gold = $this->char->gold;
     $npco = new Npc('merchant2');
     $response = $this->controller->attack($this->m_dependencies);
     $final_char = Player::find($this->char->id());
     $this->assertNotEmpty($response);
     $reflection = new \ReflectionProperty(get_class($response), 'data');
     $reflection->setAccessible(true);
     $response_data = $reflection->getValue($response);
     $this->assertEquals('merchant2', $response_data['victim']);
     $this->assertGreaterThan(0, $npco->minGold());
     $this->assertGreaterThan($init_gold, $final_char->gold);
 }