谁知道这个代码是什么意思

高司机 2017-07-03 03:07:59

public function drawBoxDrop($accountId,$dropId)
{
$userInfo = $this->Player->getUserBlobInfo(array("userinfo"),$accountId);
$DrawData = xmlConfig::LoadXmlData("draw.xml");
$draw_item_array = array();
$speacial_dropId = array("201001"=>"pet", "202001"=>"equip","203001"=>"anima");//达到免费时间了可以抽取免费的
foreach($DrawData['draw_draws']['draw'] as $draw_sheet_key => $draw_sheet_value)
{
if(isset($draw_sheet_value[$dropId])){
$draw_item_array = $draw_sheet_value;
}
}
if(count($draw_item_array) == 0)
{
return $return_Data = array( "ts"=> time(), "errcode" => -2, "errmsg" => "draw failed");
}
$cost_res = array();
$need_cost_flag = true;
//检查下要不要消耗
if(isset($speacial_dropId[$dropId])){
//检查下cd时间到了没有 等待完善
}
if($need_cost_flag == true){
$cost_res = xmlConfig::getReward($draw_item_array['cost'])
if(strtoupper($draw_item_array['switch']) == "TRUE" && strtotime($draw_item_array['startTime']) <= time() && time() < strtotime($draw_item_array['endTime']))//活动期间打折
{
foreach($cost_res as $cost_res_key => $cost_res_value )
{
$cost_res[$cost_res_key] = floor($cost_res_value * $draw_item_array['discount']);
}
}
//检查下有没有这么多资源
if($this->CheckPlayerRes($cost_res,$accountId) == false){
return array("ts"=> time(), "errcode" => -3, "errmsg" => "You have not enough resources");
}
}
$randIndex = rand(1,100);
$rand_count = 0;
$draw_real_item = '';
...全文
90 1 收藏 3
写回复
3 条回复
傲雪星枫 2017年07月03日
抽奖概率控制代码。
回复 点赞
高司机 2017年07月03日
$randIndex = rand(1,$total_weight); 
		$rand_count = 0;
		$last_real_reward_item = array();
		foreach($arr_draw as $arr_draw_k => $arr_draw_v)
		{
			if($arr_draw_v  + $rand_count >= $randIndex){ 
				$last_real_reward_item = xmlConfig::getReward($arr_draw_k);
				break;
			}else{
				$rand_count += $arr_draw_v;
			}
		}
		
		$num = $draw_item_array['number'];
		foreach($last_real_reward_item as $reward_k => $rewar_v)
		{
			$last_real_reward_item[$reward_k] = $rewar_v * $num;
		}
		$add_cost_res = $last_real_reward_item;
		//再算一下资源
		foreach($cost_res as $cost_res_k => $cost_res_v)
		{ 
			$add_cost_res[$cost_res_k] = 0 - $cost_res_v;
		}
		$this->addItemToPlayer($add_cost_res,$accountId);
		if($need_cost_flag == false){
			//记录下抽奖时间 等待完善
		}
		$userinfo = $this->Player->getUserBlobInfo(array("userinfo"),$accountId);
		///////
		$this->updateUserBlobInfo(array("activity"=>$activityInfo["activity"]),$accountId); 
		return array( "ts"=> time(), "errcode" => 0, "errmsg" => "", "cost"=>$cost_res, "reward"=>$last_real_reward_item); 
回复 点赞
高司机 2017年07月03日

for($i = 1; $i <= 20; $i++)
		{
			if(!isset($draw_item_array['reward_'.$i])){
				continue;
			}
			if($draw_item_array['reward_'.$i] * 100 + $rand_count >= $randIndex){
				$draw_real_item = 'reward_'.$i;
				break;
			}else{
				$rand_count += $draw_item_array['reward_'.$i] * 100;
			}
		} 
		$total_weight = 0;
		$arr_draw =  array();
		foreach($DrawData['draw_'.$draw_real_item.'s'][$draw_real_item] as $draw_real_sheet_key => $draw_real_sheet_value)
		{ 
			foreach($draw_real_sheet_value as $draw_real_draw_k => $draw_real_draw_v)
			{
				if(isset($draw_real_draw_v['weight'])){
					$total_weight += $draw_real_draw_v['weight'];
					if(isset($arr_draw[$draw_real_draw_v['reward']])){
						$arr_draw[$draw_real_draw_v['reward']] += $draw_real_draw_v['weight'];
					}else{
						$arr_draw[$draw_real_draw_v['reward']] = $draw_real_draw_v['weight'];
					}
				}else (isset($draw_real_draw_v['ratio'])){
					$total_weight += $draw_real_draw_v['ratio'] * 10000;
					if(isset($arr_draw[$draw_real_draw_v['reward']])){
						$arr_draw[$draw_real_draw_v['reward']] += $draw_real_draw_v['ratio']* 10000;
					}else{
						$arr_draw[$draw_real_draw_v['reward']] = $draw_real_draw_v['ratio']* 10000;
					}
				}				
			} 
		}
		//随机一个吧
回复 点赞
发动态
发帖子
基础编程
创建于2007-09-28

9734

社区成员

14.0w+

社区内容

从PHP安装配置,PHP入门,PHP基础到PHP应用
社区公告
暂无公告