92 lines
2.1 KiB
PHP
92 lines
2.1 KiB
PHP
<?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];
|
||
}
|
||
} |