public function get_task_daily_collection_id($player_level) { if (empty($player_level)) { return 0; } # 首先确定等级区间 $level = 0; $sql = "select distinct level from task_daily_collection order by level desc"; $records = $this->select_all($sql, $this->get_cache_key(array('task_daily_collection' => 1, 'sort' => 'desc'), $this->prefix_task_daily_collection)); foreach ($records as $record) { if ($player_level >= $record['level']) { $level = $record['level']; break; } } $sql = "select * from task_daily_collection where level = {$level}"; $coll_task_list = $this->select_all($sql, $this->get_cache_key(array('level' => $level), $this->prefix_task_daily_collection)); $coll_task_weight_hash = array(); # 地图权重哈希,随机取map_id用 foreach ($coll_task_list as $index => $coll_task_info) { $coll_task_weight_hash[$coll_task_info['main_task_id']] = $coll_task_info['rand_weight']; } $rand_main_task_id = Com_Random::get_probability_key($coll_task_weight_hash); return intval($rand_main_task_id); }
/** * 随机需要合成的碎片 * @param number $number * @return Ambigous <multitype:, multitype:multitype:Ambigous <boolean, unknown> > */ public function rand_compose_pieces($number, $level, $no_need_prop_id = array(), $is_guide = 0) { $arr_prop_weight = array(); $arr_prop_pieces_weight = array(); $arr_prop_pieces_type_weight = array(); $rand_prop_list = array(); $arr_pieces_quality = array(); $arr_prop_quality = array(); $grabTreasureConfig = Cache_GrabTreasureBase::getInstance()->get_grab_treasure_list(); if (Com_Array::is_good_arr($grabTreasureConfig)) { foreach ($grabTreasureConfig as $key => $item) { if ($level < $item['min_lvl'] || $level > $item['max_lvl']) { unset($grabTreasureConfig[$key]); } } if (Com_Array::is_good_arr($grabTreasureConfig)) { foreach ($grabTreasureConfig as $item) { #道具权重 $arr_prop_weight[$item['id']] = $item['weight']; $arr_prop_quality[$item['quality']][$item['id']] = $item['weight']; $arr_pieces_num = explode(",", $item["pieces_num"]); $arr_pieces_weight = explode(",", $item["pieces_weight"]); $arr_piece_type = explode(",", $item["piece_type"]); $arr_pieces_type_weight = explode(",", $item["type_weight"]); #碎片数量权重 foreach ($arr_pieces_num as $key => $num) { $arr_prop_pieces_weight[$item['id']][$num] = $arr_pieces_weight[$key]; } #碎片道具权重 foreach ($arr_piece_type as $key => $piece_id) { $arr_prop_pieces_type_weight[$item['id']][$piece_id] = $arr_pieces_type_weight[$key]; $arr_pieces_quality[$piece_id] = $item['quality']; } } $real_number = 0; #随机的类型列表 $rand_prop_list = array(); $i = 0; while ($real_number < $number && $i <= 10) { ++$i; Com_Log::write("arr_prop_weight", "real_number:" . var_export($real_number, true)); Com_Log::write("arr_prop_weight", "number:" . var_export($number, true)); #新手引导第一个为品质2 if ($is_guide && empty($rand_prop_list)) { $rand_prop_id = Com_Random::get_probability_key($arr_prop_quality[2]); #去除已随机出来的 unset($arr_prop_quality[2][$rand_prop_id]); } else { $rand_prop_id = Com_Random::get_probability_key($arr_prop_weight); #去除已随机出来的 unset($arr_prop_weight[$rand_prop_id]); } if (isset($rand_prop_list[$rand_prop_id])) { # 该类型不允许重复 continue; } if (Com_Array::is_good_arr($no_need_prop_id) && in_array($rand_prop_id, $no_need_prop_id)) { # 该类型不允许重复 continue; } #随机碎片数量 $real_pieces = 0; $rand_piece_list = array(); #新手引导第一个中第一个碎片为空,其它碎片为已获得 if ($is_guide && empty($rand_prop_list)) { $piece_num = 0; foreach ($arr_prop_pieces_type_weight[$rand_prop_id] as $piece_id => $weight) { $piece_num++; if ($piece_num > 1) { $rand_piece_list[$piece_id] = $arr_pieces_quality[$piece_id]; } } } else { $rand_pieces = Com_Random::get_probability_key($arr_prop_pieces_weight[$rand_prop_id]); $j = 0; while ($real_pieces < $rand_pieces && $j <= 10) { $j++; #随机碎片道具 $rand_piece_id = Com_Random::get_probability_key($arr_prop_pieces_type_weight[$rand_prop_id]); #去除已随机出来的 unset($arr_prop_pieces_type_weight[$rand_prop_id][$rand_piece_id]); #该类型不允许重复 if (isset($rand_piece_list[$rand_piece_id])) { continue; } $rand_piece_list[$rand_piece_id] = $arr_pieces_quality[$rand_piece_id]; $real_pieces = count($rand_piece_list); } } $rand_prop_list[$rand_prop_id] = $rand_piece_list; $no_need_prop_id[] = $rand_prop_id; $real_number = count($rand_prop_list); } } } return $rand_prop_list; }
public function random_task($random_val, $all_random_task = null, $order) { if (is_null($all_random_task)) { $all_random_task = Cache_TaskRandom::getInstance()->get_task_random_info(); } if ($random_val) { $has_keys = array_keys($random_val); } else { $has_keys = array(); } $now_time = time(); $rand_keys = array(); foreach ($all_random_task as $key => $val) { if (!in_array($val['sid'], $has_keys)) { $rand_keys[$key] = $val['respawn_weight']; } } if ($rand_keys) { $key = Com_Random::get_probability_key($rand_keys); $quality_weight = array(); for ($i = 1; $i <= 5; $i++) { $q_key = 'quality_weight' . $i; $quality_weight[$i] = $all_random_task[$key][$q_key]; } $quality = Com_Random::get_probability_key($quality_weight); $due_time = $all_random_task[$key]['duration'] + $now_time; return $this->get_data('PlayerTask')->format_random_task_val($all_random_task[$key]['sid'], 1, $quality, $due_time, $order); } return array(); }
/** * 获取掉落数据 * @param $loot_id * @return array */ public function get_prop_loot($loot_id, $career_type = 0) { $prop_list = array(); $condition = Cache_LootCondition::getInstance()->get_loot_condition($loot_id); if (intval($condition['prob_part_per_million']) > 0) { //0直接退出 $flag = Com_Random::probability($condition['prob_part_per_million'], 1000000); if ($flag) { $loop_times = 0; //普通循环次数 $arr_loop = array(); $arr_critical_loop = array(); for ($i = 0; $i < 5; $i++) { //把循环次数权重取出 $lkey = 'count_weight' . $i; $wkey = 'critical_weight' . $i; $arr_loop[$i] = $condition[$lkey]; $arr_critical_loop[$i] = $condition[$wkey]; } $crit_flag = Com_Random::probability($condition['critical_prob_part_per_million']); if ($crit_flag) { //算暴击次数 $wkey = Com_Random::get_probability_key($arr_critical_loop); $wkey = 'critical_times' . $wkey; $loop_times += $condition[$wkey]; } $lkey = Com_Random::get_probability_key($arr_loop); $lkey = 'count' . $lkey; $loop_times += $condition[$lkey]; $loot_info = Cache_Loot::getInstance()->get_Loot_info($condition['loot_id']); if (!empty($loot_info)) { $arr_loot_lib = array(); foreach ($loot_info as $loot) { $arr_loot_lib[$loot['loot_lib_id']] = $loot['weight']; } $loot_lib = array(); for ($i = 0; $i < $loop_times; $i++) { //获取掉落库的随机次数 $key = Com_Random::get_probability_key($arr_loot_lib); $loot_lib[$key] += 1; } if (!empty($loot_lib)) { foreach ($loot_lib as $key => $times) { $arr_loot_lib = Cache_LootLib::getInstance()->get_loot_lib_info($key); if (!empty($arr_loot_lib)) { $arr_item = array(); $arr_item_limit = array(); $arr_item_num = array(); foreach ($arr_loot_lib as $loot_lib_info) { if ($loot_lib_info['class_filter'] > 0 && $loot_lib_info['class_filter'] != $career_type) { continue; } $arr_item[$loot_lib_info['item_sid']] = $loot_lib_info['weight']; $arr_item_num[$loot_lib_info['item_sid']] = $loot_lib_info['count'] <= 0 ? 1 : $loot_lib_info['count']; if ($loot_lib_info['loop_limit'] > 0) { if ($loot_lib_info['loop_limit'] > 0) { $arr_item_limit[$loot_lib_info['item_sid']] = $loot_lib_info['loop_limit']; } } } if (!empty($arr_item)) { for ($i = 0; $i < $times; $i++) { if (empty($arr_item)) { break; } $key = Com_Random::get_probability_key($arr_item); if (!isset($prop_list[$key])) { $type = $this->get_item_key($key); if ($type == 'prop') { $prop_list[$key] = array('type' => $type, 'item_id' => $key, 'item_num' => $arr_item_num[$key]); } else { $prop_list[$key] = array('type' => $type, 'item_id' => $key, 'item_num' => $arr_item_num[$key]); } } else { $prop_list[$key]['item_num'] += $arr_item_num[$key]; } if (isset($arr_item_limit[$key])) { $arr_item_limit[$key] -= 1; if ($arr_item_limit[$key] <= 0) { unset($arr_item[$key]); } } } } } } } } } } $flag = Com_Random::probability($condition['prob_silver_part_per_million'], 1000000); if ($flag) { $item_num = rand($condition['min_silver'], $condition['max_silver']); if ($item_num > 0) { if (isset($prop_list[3])) { $item_num = $prop_list[3]['item_num'] + $item_num; } $prop_list[3] = array('type' => $this->get_item_key(3), 'item_id' => 3, 'item_num' => $item_num); } } $flag = Com_Random::probability($condition['prob_mojo_part_per_million'], 1000000); if ($flag) { $item_num = rand($condition['min_mojo'], $condition['max_mojo']); if ($item_num > 0) { if (isset($prop_list[13])) { $item_num = $prop_list[13]['item_num'] + $item_num; } $prop_list[13] = array('type' => $this->get_item_key(13), 'item_id' => 13, 'item_num' => $item_num); } } if ($prop_list) { $now_time = time(); foreach ($prop_list as $key => $item) { if ($item['item_id'] > 200) { $arrPropConfig = Cache_Prop::getInstance()->get_prop_info($item['item_id']); $prop_list[$key]['prop_config'] = $arrPropConfig; if (!empty($arrPropConfig['generate_start_time']) && !empty($arrPropConfig['generate_end_time']) && ($now_time < strtotime($arrPropConfig['generate_start_time']) || $now_time > strtotime($arrPropConfig['generate_end_time']))) { unset($prop_list[$key]); } } } } return $prop_list; }
/** * @Purpose: * 提升英雄成长值 * @Param $player_id * @Param $hero_id * @Param $state 0普通提升 1批量提升 * @Param $auto 为1时表示道具不足时从上次自动购买道具 */ public function player_hero_grow_upgrade($player_id, $hero_id, $state, $auto = 0) { $player_id = intval($player_id); $hero_id = strval($hero_id); $obj_player_hero_data = $this->get_data('PlayerHero'); $hero_data = $obj_player_hero_data->get_player_hero_info($player_id, $hero_id); if (empty($hero_data)) { $this->throw_error('10102'); #英雄不存在 } $hero_conf = Cache_HeroAttr::getInstance()->get_hero_attr_info($hero_data['hero_code']); if (empty($hero_conf)) { $this->throw_error('50120'); #英雄配置错误 } if ($hero_data['grow_rate'] >= $hero_conf['grow_limit']) { $this->throw_error('50121'); #成长值已达上限 } $obj_hero_grow = $this->get_data('PlayerHeroGrow'); $hero_grow_id = $obj_hero_grow->get_player_hero_grow_data($hero_id); $hero_grow_conf = array(); $findFlag = false; if (!$hero_grow_id) { $findFlag = true; } else { $hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); if (empty($hero_grow_conf)) { $findFlag = true; } else { if ($hero_data['grow_rate'] < $hero_grow_conf['grow_left'] || $hero_data['grow_rate'] >= $hero_grow_conf['grow_right']) { #区间错误 $findFlag = true; } } } if ($findFlag) { #启动自动纠错 $hero_grow_id = $this->find_hero_grow_id($hero_data['grow_rate'], $hero_grow_conf); if (!$hero_grow_id) { $this->throw_error('10111'); #配置错误 } } if (empty($hero_grow_conf)) { $this->throw_error('10111'); } $obj_prop_game = $this->get_game('Prop'); $obj_shop_game = $this->get_game('Shop'); $consume_props = $last_props = $arr_consume = $arr_shop_log = array(); $last_props[$hero_grow_conf['item_id']] = intval($obj_prop_game->get_prop_num_by_prop_id($player_id, $hero_grow_conf['item_id'])); if (empty($auto) && $last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']) { $this->throw_error('50107'); } $player_info = $this->get_data('Player')->get_player_info($player_id, Com_Util::get_player_fields(array('currency', 'level', 'vip', 'privilege_level'))); $crit_counter = 0; #暴击计数 $counter = 10; #while执行计数 $sum_rand_grow_val = 0; #总提升数量 $new_hero_grow_val = 0; #新的成长值 $upgrade_times = $counter; $error_code = 0; $update_gold = false; #是否更新彩钻或钻石资源 do { $need_buy_prop_nums = 0; #每次执行所需要的材料需在商城购买的数量 if ($last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']) { $last_props[$hero_grow_conf['item_id']] = 0; $need_buy_prop_nums = $hero_grow_conf['item_nums'] - $last_props[$hero_grow_conf['item_id']]; if ($last_props[$hero_grow_conf['item_id']] > 0) { $consume_props[$hero_grow_conf['item_id']] += $last_props[$hero_grow_conf['item_id']]; } } else { $last_props[$hero_grow_conf['item_id']] -= $hero_grow_conf['item_nums']; #剩余数量 $consume_props[$hero_grow_conf['item_id']] += $hero_grow_conf['item_nums']; #消耗数量 } if ($need_buy_prop_nums > 0) { #材料不足需要在商城购买 $update_gold = true; $buy_prop_info = $obj_shop_game->shortcut_purchase_interface($hero_grow_conf['item_id'], 1); if (empty($buy_prop_info['item_price'])) { $this->throw_error('130001'); #商城没有出售该道具 } list($cost_currency_type, $cost_currency_value) = each($buy_prop_info['item_price']); $cost_currency_value *= $need_buy_prop_nums; $cost_currency_key = Cache_Currency::getInstance()->get_key($cost_currency_type); $arr_tmp_consume = Com_Util::get_consume_info_for_data_center($player_info, $cost_currency_key, $cost_currency_value, $need_buy_prop_nums); if (!empty($arr_tmp_consume)) { $arr_consume['price'] += $arr_tmp_consume['price']; $arr_consume['gold'] += $arr_tmp_consume['gold']; $arr_consume['ticket'] += $arr_tmp_consume['ticket']; $arr_consume['count'] += $arr_tmp_consume['count']; } #虚拟商城记录日志 if (!isset($arr_shop_log[$hero_grow_conf['item_id']])) { $arr_shop_log[$hero_grow_conf['item_id']]['cost_resource_id'] = $cost_currency_type; } $arr_shop_log[$hero_grow_conf['item_id']]['item_num'] += $need_buy_prop_nums; $arr_shop_log[$hero_grow_conf['item_id']]['cost_resource_num'] += $cost_currency_value; $error_code = $this->get_data('Player')->check_player_resource($player_id, $player_info, '-', $cost_currency_key, $cost_currency_value, 0, $cost_currency_type); if ($error_code !== true) { if ($counter == 10) { #首次执行如果资源不足则退出 $this->throw_error($error_code); } break; } } $counter--; $rand_val = 0; $is_crit = Com_Random::probability($hero_grow_conf['crit_rate']); if ($is_crit) { $crit_counter++; $rand_val = $this->parse_data($hero_grow_conf['val_crit']); } else { $rand_val = $this->parse_data($hero_grow_conf['val_nor']); } if (!$rand_val) { $this->throw_error('50122'); #英雄成长配置表解析错误 } #单次随机值 $real_rand_val = Com_Random::get_probability_key($rand_val); #批量随机值之和 $sum_rand_grow_val += $real_rand_val; #英雄的新成长值 $new_hero_grow_val = $hero_data['grow_rate'] + $sum_rand_grow_val; if ($new_hero_grow_val >= $hero_conf['grow_limit']) { #超过英雄成长值上限 $new_hero_grow_val = $hero_conf['grow_limit']; $sum_rand_grow_val = $hero_conf['grow_limit'] - $hero_data['grow_rate']; break; } #移动至下一个成长值区间 if ($new_hero_grow_val > $hero_grow_conf['grow_right']) { $hero_grow_id++; $hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); if (empty($hero_grow_conf)) { break; } if (!isset($last_props[$hero_grow_conf['item_id']])) { $last_props[$hero_grow_conf['item_id']] = intval($obj_prop_game->get_prop_num_by_prop_id($player_id, $hero_grow_conf['item_id'])); } } if (empty($auto) && $last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']) { #道具不足 break; } } while ($counter > 0 && $state > 0); #控制循环数量防止进入死循环 $this->start_trans(); $result = true; if ($update_gold) { $result = $this->get_data('Player')->update_player_resource($player_id, $player_info, 557, array(), $arr_consume); $this->write_check($result, 3010476); } if (!empty($consume_props)) { $log_param = array('cmd_id' => 557, 'level' => $player_info['level'], 'vip' => $player_info['vip']); $logs = array(); foreach ($consume_props as $prop_id => $prop_nums) { #批量扣除多个道具如果可能 $result = $obj_prop_game->deduct_prop_by_prop_id($player_id, $prop_id, $prop_nums, $logs, 1, $log_param); if (!$result) { $this->throw_error('10101'); } } } if ($result) { $hero_data['grow_rate'] = $new_hero_grow_val; $hero_data['fight'] = $this->calc_fight($player_id, $hero_data, $hero_data['fit'], $hero_data['rune_hole_list'], $hero_data['star_add_attr_per'], $hero_data['skill_list']); $update_field['grow_rate'] = $hero_data['grow_rate']; $update_field['fight'] = $hero_data['fight']; $result = $this->update_db($player_id, $update_field, $hero_data, 557); $this->get_data('RankList')->update_hero_rank($hero_id, $hero_data['fight']); } if ($result) { $this->commit(); $obj_hero_grow->set_player_hero_grow_data($hero_id, $hero_grow_id); $n_hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); #引导任务 $this->get_game('TaskTrigger')->async_trigger_guide_task($player_id, 26, $upgrade_times - $counter); $this->get_game('PlayerAchieve')->async_trigger_achieve_target($player_id, 37, $hero_data['grow_rate'] + $hero_data['fit_grow'], 8); if (!empty($arr_shop_log)) { foreach ($arr_shop_log as $item_id => $item_info) { $obj_shop_game->add_dummy_shop_log($player_id, $player_info, $item_id, $item_info['item_num'], $item_info['cost_resource_id'], $item_info['cost_resource_num'], 557); } } return array('res' => $crit_counter, 'rand_val' => $sum_rand_grow_val, 'cur_grow_val' => $new_hero_grow_val, 'effect' => 10000 * round($this->calc_grow_attar($new_hero_grow_val, $hero_conf['grow']), 4), 'prop_id' => $n_hero_grow_conf['item_id'], 'prop_nums' => $n_hero_grow_conf['item_nums'], 'nor_desc' => $n_hero_grow_conf['nor_desc'], 'crit_desc' => $n_hero_grow_conf['crit_desc']); } else { $this->throw_error('10101'); } }
public function player_hero_grow_upgrade($player_id, $hero_id, $state) { $player_id = intval($player_id); $hero_id = strval($hero_id); $obj_player_hero_data = $this->get_data('PlayerHero'); $hero_data = $obj_player_hero_data->get_player_hero_info($player_id, $hero_id); if (empty($hero_data)) { $this->throw_error('10102'); #英雄不存在 } $hero_conf = Cache_HeroAttr::getInstance()->get_hero_attr_info($hero_data['hero_code']); if (empty($hero_conf)) { $this->throw_error('50120'); #英雄配置错误 } if ($hero_data['grow_rate'] >= $hero_conf['grow_limit']) { $this->throw_error('50121'); #成长值已达上限 } /* $obj_hero_grow = $this->get_data('PlayerHeroGrow'); $hero_grow_id = $obj_hero_grow->get_player_hero_grow_data($hero_id); $hero_grow_conf = array(); $findFlag = false; if(!$hero_grow_id){ $findFlag = true; }else{ $hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); if(empty($hero_grow_conf)){ $findFlag = true; }else{ if($hero_data['grow_rate']<$hero_grow_conf['grow_left'] || $hero_data['grow_rate']>=$hero_grow_conf['grow_right']){#区间错误 $findFlag = true; } } } if($findFlag){#启动自动纠错 $hero_grow_id = $this->find_hero_grow_id($hero_data['grow_rate'], $hero_grow_conf); if(!$hero_grow_id){ $this->throw_error('10111');#配置错误 } } if(empty($hero_grow_conf)){ $this->throw_error('10111'); } $obj_prop_game = $this->get_game('Prop'); $consume_props = $last_props = array(); $last_props[$hero_grow_conf['item_id']] = intval($obj_prop_game->get_prop_num_by_prop_id($player_id, $hero_grow_conf['item_id'])); if($last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']){ $this->throw_error('50107'); } */ list($need_prop_id, $need_prop_nums) = explode(":", trim($hero_conf['grow_expend'])); if (empty($need_prop_id) || empty($need_prop_nums)) { $this->throw_error('10111'); } $obj_prop_game = $this->get_game('Prop'); $last_props_nums = intval($obj_prop_game->get_prop_num_by_prop_id($player_id, $need_prop_id)); if ($last_props_nums < $need_prop_nums) { $this->throw_error('50107'); } $hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($need_prop_id); if (empty($hero_grow_conf)) { $this->throw_error('10111'); #配置错误 } $consume_props_nums = 0; #消耗道具数量 $crit_counter = 0; #暴击计数 $counter = 10; #while执行计数 $sum_rand_grow_val = 0; #总提升数量 $new_hero_grow_val = 0; #新的成长值 do { $counter--; // $last_props[$hero_grow_conf['item_id']] -= $hero_grow_conf['item_nums'];#剩余数量 // $consume_props[$hero_grow_conf['item_id']] += $hero_grow_conf['item_nums'];#消耗数量 $last_props_nums -= $need_prop_nums; $consume_props_nums += $need_prop_nums; $rand_val = 0; $is_crit = Com_Random::probability($hero_grow_conf['crit_rate']); if ($is_crit) { $crit_counter++; $rand_val = $this->parse_data($hero_grow_conf['val_crit']); } else { $rand_val = $this->parse_data($hero_grow_conf['val_nor']); } if (!$rand_val) { $this->throw_error('50122'); #英雄成长配置表解析错误 } #单次随机值 $real_rand_val = Com_Random::get_probability_key($rand_val); #批量随机值之和 $sum_rand_grow_val += $real_rand_val; #英雄的新成长值 $new_hero_grow_val = $hero_data['grow_rate'] + $sum_rand_grow_val; if ($new_hero_grow_val >= $hero_conf['grow_limit']) { #超过英雄成长值上限 $new_hero_grow_val = $hero_conf['grow_limit']; $sum_rand_grow_val = $hero_conf['grow_limit'] - $hero_data['grow_rate']; break; } /* #移动至下一个成长值区间 if($new_hero_grow_val > $hero_grow_conf['grow_right']){ $hero_grow_id++; $hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); if(empty($hero_grow_conf)){ break; } if(!isset($last_props[$hero_grow_conf['item_id']])){ $last_props[$hero_grow_conf['item_id']] = intval($obj_prop_game->get_prop_num_by_prop_id($player_id, $hero_grow_conf['item_id'])); } } if($last_props[$hero_grow_conf['item_id']] < $hero_grow_conf['item_nums']){#道具不足 break; } */ if ($last_props_nums < $need_prop_nums) { break; } } while ($counter > 0 && $state > 0); #控制循环数量防止进入死循环 $result = true; $player_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'vip')); $log_param = array('cmd_id' => 557, 'level' => $player_info['level'], 'vip' => $player_info['vip']); $log = array(); $this->start_trans(); /* foreach($consume_props as $prop_id=>$prop_nums){#批量扣除多个道具如果可能 $result = $obj_prop_game->deduct_prop_by_prop_id($player_id, $prop_id, $prop_nums, $log, 1, $log_param); if(!$result){ $this->throw_error('10101'); } } */ $result = $obj_prop_game->deduct_prop_by_prop_id($player_id, $need_prop_id, $consume_props_nums, $log, 1, $log_param); if ($result) { $hero_data['grow_rate'] = $new_hero_grow_val; $result = $obj_player_hero_data->update_player_hero($player_id, $hero_id, array('grow_rate' => $new_hero_grow_val), $hero_data); } if ($result) { $this->commit(); // $obj_hero_grow->set_player_hero_grow_data($hero_id, $hero_grow_id); // $n_hero_grow_conf = Cache_HeroGrow::getInstance()->get_config_info($hero_grow_id); return array('res' => $crit_counter, 'rand_val' => $sum_rand_grow_val, 'cur_grow_val' => $new_hero_grow_val, 'effect' => 1000 * self::calc_grow_attar($new_hero_grow_val, $hero_conf['grow']), 'prop_id' => $need_prop_id, 'prop_nums' => $need_prop_nums, 'nor_desc' => $hero_grow_conf['nor_desc'], 'crit_desc' => $hero_grow_conf['crit_desc']); } else { $this->throw_error('10101'); } }
private function get_challenge_monster_info() { # 获取天梯榜中已有monster信息 $monster_info_all = $this->get_data('Challenge')->get_challenge_monster_info_all(); # 获取天梯每日怪物刷新次数 $monster_flush_seq = $this->get_data('PlayerDailyTime')->get_global_used_time('challenge_monster_flush_seq'); if (empty($monster_flush_seq)) { $monster_flush_seq = 0; } $cur_flush_seq = 0; # 获取当前刷新后的刷新序号 $flush_s2t = array_reverse($this->challenge_monster_flush_s2t); foreach ($flush_s2t as $s => $t) { if ($this->current_time >= $t) { $cur_flush_seq = $this->challenge_monster_flush_t2s[$t]; break; } } # 若($cur_flush_seq == 0 || $monster_flush_seq >= $cur_flush_seq)标识没到刷新时间||已经刷新过该序号次数对应的刷新 # 若该序号次数的刷新没有执行过,则刷新 if ($monster_flush_seq < $cur_flush_seq) { # 获取monster的随机用权重哈希 $ladder_element_info = Cache_Ladder::getInstance()->get_element_info_by_type(2); if (empty($ladder_element_info)) { $this->throw_error('120108'); } $rand_monster_weight_hash = array(); foreach ($ladder_element_info as $index => $element_info) { $rand_monster_weight_hash[$element_info['sub_type']] = $element_info['weight']; } # 构造一个随机monster_offset的集合数组,[2..100]分10段 $rand_offset_weight_hash = array(); for ($i = 1; $i <= $this->challenge_monster_section_num; $i++) { # 分10段填充,段位 for ($j = ($i - 1) * $this->challenge_monster_flush_step + 1; $j <= $i * $this->challenge_monster_flush_step; $j++) { # 该段位可用offset if ($j != 1) { $rand_offset_weight_hash[$i][$j] = 1; } # 怪物不能插入第1名之前,排除1,各偏移量的权重相等,都取1 } } # 获取已有monster的offset集合,并将已有monster的offset从随机monster_offset的集合中去重 $already_hold_monster_offset = array(); if (!empty($monster_info_all)) { foreach ($monster_info_all as $offset => $mon_info) { $section_idx = intval(($offset - 1) / $this->challenge_monster_flush_step) + 1; # 获取段索引,1..10段 $already_hold_monster_offset[$section_idx][] = $offset; unset($rand_offset_weight_hash[$section_idx][$offset]); } } # 刷新monster,每隔10名刷新3个怪物 for ($i = 1; $i <= $this->challenge_monster_section_num; $i++) { # 分10段填充 $hold_num = count($already_hold_monster_offset[$i]); if ($hold_num >= $this->challenge_monster_flush_num) { # 该段怪物已满,不需填充 continue; } else { $fill_num = $this->challenge_monster_flush_num - $hold_num; # 该段需填充怪物个数 for ($j = 1; $j <= $fill_num; $j++) { # 随机一个monster $rand_mon_id = Com_Random::get_probability_key($rand_monster_weight_hash); # 随机一个offset $rand_offset = Com_Random::get_probability_key($rand_offset_weight_hash[$i]); $mon_rtype = $this->get_game('Reward')->get_reward_type($ladder_element_info[$rand_mon_id]['reward']); unset($rand_offset_weight_hash[$i][$rand_offset]); # 去重 $monster_info_all[$rand_offset] = array('offset' => $rand_offset, 'mon_id' => $rand_mon_id, 'mon_rtype' => $mon_rtype, 'is_in_battle' => 0); } } } $re = $this->get_data('Challenge')->update_challenge_monster_info_all($monster_info_all); $this->write_check($re, 3012082); $re = $this->get_data('PlayerDailyTime')->set_global_used_time('challenge_monster_flush_seq', $cur_flush_seq); $this->write_check($re, 3012084); } return $monster_info_all; }
public function get_special_bounty_task($player_level, $star_type) { if ($star_type <= 0) { return false; } $sql = "select * from task_config where task_type = 3 and min_level <= {$player_level} and max_level >= {$player_level} and star_type = {$star_type}"; $task_list = $this->select_all($sql, $this->get_cache_key(array('player_level' => $player_level, 'star_type' => $star_type))); # 列表结构转为哈希结构 $task_hash = array(); $task_weight_hash = array(); # 任务权重哈希,随机取task_id用 foreach ($task_list as $index => $task_info) { $task_hash[$task_info['task_id']] = $task_info; $task_weight_hash[$task_info['task_id']] = $task_info['weight']; } $rand_task_id = Com_Random::get_probability_key($task_weight_hash); return $task_hash[$rand_task_id]; }
/** * * @param $sid * @param $player_info * @return array */ public function get_loot($sid, $player_id = null, $param = array()) { $drop_list = $this->get_fb_loot_info($sid); if (empty($drop_list)) { return array(); } $items = array(); if (!empty($player_id) && empty($param)) { $param = $this->get_data('Player')->get_player_info($player_id, array('career_type', 'level')); } $arr_special = array(); foreach ($drop_list as $key => $drop) { $arr_special[$drop['special']][$key] = $drop; # TODO: 郭鑫又改规则了 } foreach ($arr_special as $list) { $condition = array(); $conditions_by_role = array(); #按职业随机掉的 $conditions_by_99 = array(); #必掉的 foreach ($list as $key => $drop) { if ($drop['type'] > 0) { if ($drop['type'] == $param['career_type']) { $conditions_by_role[$key] = $drop['rate']; } if ($drop['type'] == 99) { $conditions_by_99[] = $key; } continue; } else { if ($drop['rate'] > 0) { $condition[$key] = $drop['rate']; } } } if ($conditions_by_role) { $key = Com_Random::get_probability_key($conditions_by_role, 1); $prop_param = explode(":", $drop_list[$key]['item_id']); if (count($prop_param) > 1) { $prop = Cache_Prop::getInstance()->get_prop_by_param_and_career_type($param['level'], $param['career_type'], $prop_param[0], $prop_param[1], $prop_param[2], $prop_param[3]); $items[] = array('type' => $this->get_item_key($prop['prop_id']), 'item_id' => $prop['prop_id'], 'item_num' => $drop_list[$key]['num']); } else { $items[] = array('type' => $this->get_item_key($drop_list[$key]['item_id']), 'item_id' => $drop_list[$key]['item_id'], 'item_num' => $drop_list[$key]['num']); } } if ($conditions_by_99) { foreach ($conditions_by_99 as $key) { $prop_param = explode(":", $drop_list[$key]['item_id']); if (count($prop_param) > 1) { $prop = Cache_Prop::getInstance()->get_prop_by_param($param['level'], $prop_param[0], $prop_param[1], $prop_param[2], $prop_param[3]); $items[] = array('type' => $this->get_item_key($prop['prop_id']), 'item_id' => $prop['prop_id'], 'item_num' => $drop_list[$key]['num']); } else { $items[] = array('type' => $this->get_item_key($drop_list[$key]['item_id']), 'item_id' => $drop_list[$key]['item_id'], 'item_num' => $drop_list[$key]['num']); } } } if ($condition) { $key = Com_Random::get_probability_key($condition, 1); $prop_param = explode(":", $list[$key]['item_id']); if (count($prop_param) > 1) { $prop = Cache_Prop::getInstance()->get_prop_by_param($param['level'], $prop_param[0], $prop_param[1], $prop_param[2], $prop_param[3]); // Com_Log::log($prop,'prop_use',1); $items[] = array('type' => $this->get_item_key($prop['prop_id']), 'item_id' => $prop['prop_id'], 'item_num' => $drop_list[$key]['num']); } else { $items[] = array('type' => $this->get_item_key($drop_list[$key]['item_id']), 'item_id' => $drop_list[$key]['item_id'], 'item_num' => $drop_list[$key]['num']); } } } if ($items) { $now_time = time(); foreach ($items as $key => $item) { if ($item['item_id'] > 200) { $arrPropConfig = Cache_Prop::getInstance()->get_prop_info($item['item_id']); $items[$key]['prop_config'] = $arrPropConfig; if (!empty($arrPropConfig['generate_start_time']) && !empty($arrPropConfig['generate_end_time']) && ($now_time < strtotime($arrPropConfig['generate_start_time']) || $now_time > strtotime($arrPropConfig['generate_end_time']))) { unset($items[$key]); } } } } return $items; }
private function daily_task_rule_apply($player_id, $task_info) { if ($task_info['task_step_type'] == 100 || $task_info['task_step_type'] == 101) { # [主线|挑战]副本类型日常任务 $rule = Cache_TaskDaily::getInstance()->get_task_daily_rule($task_info['task_step_type']); if (empty($rule)) { $this->throw_error('10019'); # 日常任务特殊规则未配置 } # 随机副本权重列表 $weight_list = explode(":", $rule['rule_param2']); if (empty($weight_list) || $rule['rule_param1'] != count($weight_list)) { $this->throw_error('10020'); # 日常任务特殊规则配置错误 } if ($task_info['task_step_type'] == 100) { $map_list = $this->get_game('PlayerFB')->get_pass_fb_last_interface($player_id, $rule['rule_param1']); Com_Log::write('xgame.dailytask', "player_id:{$player_id}:task_step_type:100" . json_encode($map_list)); if (empty($map_list)) { #$this->throw_error('10021'); # 特定类型的日常任务无法生成 $map_info = Cache_PlayerFB::getInstance()->get_player_fb_info($this->task_first_fb_map_id); $map_list[] = array('map_id' => $this->task_first_fb_map_id, 'difficulty' => $map_info['difficulty']); } # 考虑map_list可能少于weight_list,先去除无效的索引 for ($i = count($map_list); $i < $rule['rule_param1']; $i++) { unset($weight_list[$i]); } $rand_idx = Com_Random::get_probability_key($weight_list); # 随机一个索引 $task_info['dup_id'] = $map_list[$rand_idx]['map_id']; # 要求通关的副本ID # 处理难度加星 if (!empty($rule['rule_param3'])) { $star_add_info = explode("|", $rule['rule_param3']); $star_add_hash = array(); foreach ($star_add_info as $key => $val) { list($difficulty, $star_add) = explode(":", $val); $star_add_hash[$difficulty] = $star_add; } $task_info['star'] += $star_add_hash[$map_list[$rand_idx]['difficulty']]; } # 处理要求通关的水平以及通关水平加星 if (!empty($rule['rule_param4'])) { $clear_grade_info = explode("|", $rule['rule_param4']); $weight_hash = array(); $star_add_hash = array(); foreach ($clear_grade_info as $key => $val) { list($clear_grade, $weight, $star_add) = explode(":", $val); $weight_hash[$clear_grade] = $weight; $star_add_hash[$clear_grade] = $star_add; } $rand_clear_grade = Com_Random::get_probability_key($weight_hash); # 随机一个通关水平 $task_info['star'] += $star_add_hash[$rand_clear_grade]; $task_info['dup_cle_grade'] = $rand_clear_grade; } # 星级边界值修正 $task_info['star'] = min($task_info['star'], $this->task_star_stint); } elseif ($task_info['task_step_type'] == 101) { $map_list = $this->get_game('PlayerPVE')->get_last_three_chapter_id($player_id, $rule['rule_param1']); Com_Log::write('xgame.dailytask', "task_step_type:101" . json_encode($map_list)); if (empty($map_list)) { #$this->throw_error('10021'); # 特定类型的日常任务无法生成 $map_list[] = $this->task_first_pve_map_id; } $map_list = array_reverse($map_list); # 倒序 # 考虑map_list可能少于weight_list,先去除无效的索引 for ($i = count($map_list); $i < $rule['rule_param1']; $i++) { unset($weight_list[$i]); } $rand_idx = Com_Random::get_probability_key($weight_list); # 随机一个索引 $task_info['dup_id'] = $map_list[$rand_idx]; # 要求通关的副本ID } } else { $player_info = $this->get_data('Player')->get_player_info($player_id, array('level')); if ($task_info['task_step_type'] == 103) { # 守卫雅典娜副本ID $task_info['dup_id'] = Cache_ActivityHall::getInstance()->get_activity_map_id_by_category_and_level($player_info['level'], 2); } elseif ($task_info['task_step_type'] == 104) { # 世界BOSS副本ID $task_info['dup_id'] = Cache_ActivityHall::getInstance()->get_activity_map_id_by_category_and_level($player_info['level'], 1); } elseif ($task_info['task_step_type'] == 105) { # 抢矿副本ID $task_info['dup_id'] = Cache_ActivityHall::getInstance()->get_activity_map_id_by_category_and_level($player_info['level'], 4); } elseif ($task_info['task_step_type'] == 116) { # 通关副本ID #$task_info['dup_id'] = $task_info['city_id']; } elseif ($task_info['task_step_type'] == 117) { $task_info['dialog_task_id'] = Cache_TaskDaily::getInstance()->get_task_daily_dialog_id($player_info['level']); } elseif ($task_info['task_step_type'] == 10) { # 随机一个关联的采集主线任务ID $main_task_id = Cache_TaskDaily::getInstance()->get_task_daily_collection_id($player_info['level']); $main_task_step_config = Cache_TaskStepConfig::getInstance()->get_task_step_config($main_task_id, 1); if (empty($main_task_step_config) || !is_array($main_task_step_config)) { Com_Log::write('xgame.dailytask', "task_step_type:10\t" . $main_task_id); } else { $main_task_step_config['kill_npc_sid'] = $main_task_step_config['task_id']; $task_info = array_merge($main_task_step_config, $task_info); # 显示需要使用task_daily_base表的task_id,故而合并时,task_info靠后 } } } return $task_info; }
protected function get_rand_addition_attr_key($vocation_limit, $attr_num_addition) { if (empty($vocation_limit) || empty($attr_num_addition)) { return array(); } $sql = "select * from item_attr_key_rand_addi where item_vocation_limit = {$vocation_limit}"; $records = $this->select_all($sql, $this->get_cache_key(array('item_vocation_limit' => $vocation_limit), $this->prefix_item_attr_key_rand_addi)); if (empty($records)) { return array(); } $attr_key_weight_hash = array(); # 附加属性个数权重哈希,随机确定附加属性个数 foreach ($records as $record) { $attr_key_weight_hash[$record['attr_key']] = $record['rand_weight']; } # 附加属性要求去重 $addition_attr_key_list = array(); $i = 1; while ($i++ <= $attr_num_addition && !empty($attr_key_weight_hash)) { $rand_attr_key = Com_Random::get_probability_key($attr_key_weight_hash); unset($attr_key_weight_hash[$rand_attr_key]); $addition_attr_key_list[] = $rand_attr_key; } return $addition_attr_key_list; }
public function get_rand_attr_key_list($item_sub_type, $number, $lock_attr_key_hash) { if (empty($item_sub_type) || $number <= 0) { return false; } $sql = "select * from equip_refine_attr_key where item_sub_type = {$item_sub_type}"; $attr_list = $this->select_all($sql, $this->get_cache_key(array('item_sub_type' => $item_sub_type), $this->prefix_equip_refine_attr_key)); if (empty($attr_list)) { return false; } $attr_weight_hash = array(); # 属性key权重哈希,随机确定属性key foreach ($attr_list as $index => $attr_info) { #if (!isset($lock_attr_key_hash[$attr_info['attr_key']])) { # 对锁定属性去重 $attr_weight_hash[$attr_info['attr_key']] = $attr_info['rand_weight']; #} } if (empty($attr_weight_hash)) { return false; } # 防止一下随机函数返回false导致$rand_attr_list不为空 # 不允许重复 $rand_attr_key_list = array(); for ($i = 1; $i <= $number; $i++) { $rand_attr_key = Com_Random::get_probability_key($attr_weight_hash); #unset($attr_weight_hash[$rand_attr_key]); $rand_attr_key_list[] = $rand_attr_key; if (empty($attr_weight_hash)) { break; } } return $rand_attr_key_list; }