配置表中的随机几率
* @return bool */ public static function randLandDisease($commonRandID) { $odds = GameConfigServices::getCommonNumByID($commonRandID); $s = rand(0, 100) < $odds; return $s; } /** * 是否被狗抓住 * @param User $userDbData * @return int被抓住要扣的钱,大于0表示被抓住
*/ public static function getDogCatchDeductGold(User $userDbData) { //判断时间 if (UserService::getDogHungerRemainingTime($userDbData) <= 0) return 0; //查找配置表 $config = GameConfigServices::getParamByPath('item_list.' . $userDbData->use_dog_item_id); if (!$config) return 0; $odds = $config['effect_id']; $s = rand(0, 100) < $odds; if (!$s) return 0; $deductGold = GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_STEAL_CATCH); if ($deductGold < 0) return 0; return $deductGold; } /** * 随机一个果实 */ public static function getMySterySeedOddsItem() { $itemList = GameConfigServices::getParamByPath('crop_list'); $totalOdds = 0; $list = []; foreach ($itemList as $item) { $odds = intval($item['odds']); if ($odds == 0) continue; $item['minOdds'] = $totalOdds; $item['maxOdds'] = $odds + $totalOdds; array_push($list, $item); $totalOdds += $odds; } $odds = mt_rand(0, $totalOdds); foreach ($list as $item) { if ($item['minOdds'] <= $odds && $odds < $item['maxOdds']) return $item; } if (count($list) == 0) throw new StatusException(ResultStatusServices::RS_PARAM_ERROR); return $list[0]; } }