Example #1
0
 /**
  * Get random loot for a player.
  * @param SR_Player $player
  * @param int $level of killed mob
  * @return array
  */
 public static function randLoot(SR_Player $player, $level, $high_chance = array(), $chance_none = 1.85)
 {
     $items = SR_Item::getAllItems();
     $total = 0;
     $possible = array();
     foreach ($items as $item) {
         $item instanceof SR_Item;
         $il = $item->getItemLevel();
         if ($il > $level || $il < 0 || !$item->isItemLootable()) {
             continue;
         }
         # Normalize chance
         $chance = 100;
         # High chance
         if (in_array($item->getItemName(), $high_chance)) {
             $chance *= 3;
             # 3/1
         }
         # Lucky :)
         $chance = self::randLootLuckChance($player, $item, $level, $chance);
         # Crunch bit
         $chance /= 10;
         # dropchance = base chance * funky stuff
         $dc = round($item->getItemDropChance() * $chance);
         # printf("You can loot a %s with %d chance.", $item->getItemName(), $dc);
         $possible[] = array($item->getName(), $dc);
         $total += $dc;
     }
     # Party level betters chance none.
     // 		$chance_none -= ($player->get('luck') / 200);
     $chance_none -= $player->getParty()->getPartyLevel() / 200;
     $chance_none = Common::clamp($chance_none, 1.2);
     # Produce loot. Raise chance_none a lot.
     $back = array();
     while (false !== ($loot = self::randLootItem($player, $level, $possible, $total, $total * $chance_none))) {
         $back[] = $loot;
         $chance_none *= $chance_none;
     }
     return $back;
 }
Example #2
0
 private static function createItemDataFile()
 {
     $out = '<?php' . "\n\$lang = array(\n";
     $player = Shadowrun4::getDummyPlayer();
     $data = array();
     foreach (SR_Item::getAllItems() as $item) {
         $item instanceof SR_Item;
         $data[(int) $item->getItemUUID()] = $player->lang($item->displayPacked($player));
     }
     ksort($data);
     foreach ($data as $uuid => $type) {
         $out .= sprintf("'%d'=>'%s',\n", $uuid, $type);
     }
     $out .= ");\n?>\n";
     $outfile = Shadowrun4::getShadowDir() . 'data/itemdata/itemdata_en.php';
     @mkdir(dirname($outfile), 0700, true);
     file_put_contents($outfile, $out);
     return true;
 }