hy-farm/muchang/common/services/RandServices.php
2026-05-29 19:54:56 +08:00

92 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Created by PhpStorm.
* User: zn
* Date: 2017/5/24
* Time: 19:44
*/
namespace common\services;
use common\models\User;
/**
* 随机
* Class RandServices
* @package common\services
*/
class RandServices
{
/**
* 随机干旱
* @param $commonRandID <p>配置表中的随机几率</p>
* @return bool
*/
public static function randLandDisease($commonRandID)
{
$odds = GameConfigServices::getCommonNumByID($commonRandID);
$s = rand(0, 100) < $odds;
return $s;
}
/**
* 是否被狗抓住
* @param User $userDbData
* @return int <p>被抓住要扣的钱大于0表示被抓住</p>
*/
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];
}
}