private function sort_hall_list($res_hall, $level, $union_info, $pre_view_group) { $res = array(); $datetime = time(); $date = date('Y-m-d'); $res_0 = array(); $res_1 = array(); $res_2 = array(); $res_3 = array(); $world_boss_base = Cache_WorldBoss::getInstance()->get_worldboss_set(); if (empty($res_hall)) { return $res; } $rank_list = $this->get_data('RankList')->get_sort_list('level'); foreach ($res_hall as $v) { $temp = array(); $start = strtotime($date . ' ' . $v['start_time']); $end = strtotime($date . ' ' . $v['end_time']); $status = 0; #0:结束,1:进行中,2:即将开始,3:等级未达到,4服务器开启条件未达到,5非公会成员 $lefttime = 0; #倒计时 #1:进行中 if ($start <= $datetime && $datetime <= $end) { $status = 1; $lefttime = $end - $datetime; } #2:即将开始 if ($start > $datetime) { $status = 2; $lefttime = $start - $datetime; } #0:结束 if ($end < $datetime) { $status = 0; $lefttime = $datetime - $end; } #提前结束 if ($status == 1 && $v['category'] == 1) { $check_over = $this->get_data('WorldBoss')->check_is_over(); if ($check_over) { $status = 0; } } if ($level < $v['join_min_lvl']) { $status = 3; } $joined = 0; if (!$v['category'] != 1 && $status == 1) { $joined = 1; } #判断世界boss加入条件 if ($this->check_in_world_boss($v['id'], $world_boss_base) && $status == 1) { $joined = 1; } if ($joined == 0 && $status == 1) { $status = 3; } #判断是否为公会活动 if ($v['category'] == 5 || $v['category'] == 6) { if (empty($union_info)) { $status = 5; } else { if ($v['category'] == 5) { $u_type = 1; } else { $u_type = 2; } foreach ($union_info as $union) { if ($union[1] == $u_type) { if ($union[13] == 1) { $status = 1; } else { $status = 0; } } } } } $temp['activity_id'] = $v['sid']; $temp['status'] = $status; $temp['lefttime'] = $lefttime; $temp['joined'] = $joined; $temp['tid'] = $v['id']; $temp['join_lvl'] = $v['join_min_lvl']; $temp['open_level'] = 0; $temp['open_num'] = 0; $temp['nums'] = 0; $temp['start_time'] = $start; $temp['end_time'] = $end; if (0 == $status) { array_push($res_0, $temp); } else { if (1 == $status) { array_push($res_1, $temp); } else { if (2 == $status) { array_push($res_2, $temp); } else { if (3 == $status || 5 == $status) { array_push($res_3, $temp); } } } } } $this->sort_by_time($res_0, 'lefttime', 'asc'); $this->sort_by_time($res_1, 'lefttime'); $this->sort_by_time($res_2, 'lefttime'); $this->sort_by_time($res_3, 'lefttime'); if (!empty($res_1)) { foreach ($res_1 as $v) { # array_push($res,$v); $res[] = $v; } } if (!empty($res_2)) { foreach ($res_2 as $v) { $res[] = $v; } } if (!empty($res_0)) { foreach ($res_0 as $v) { $res[] = $v; } } if (empty($pre_view_group)) { return $res; } $res_4 = array(); if (!empty($res_3)) { foreach ($res_3 as $v) { if ($v['join_lvl'] <= $level) { if (!$pre_view_group['worldboss']['open'] && $v['category'] == 1) { #世界boss $world_set = Cache_WorldBoss::getInstance()->get_worldboss_set($v['id']); $v['status'] = 4; #服务器未开启 $v['open_level'] = $world_set['level']; $v['open_num'] = $world_set['level_num']; $v['nums'] = $this->get_open_level_num($world_set['level'], $rank_list); } if (!$pre_view_group['athena']['open'] && $v['category'] == 2) { #守护女神 $athena_set = Cache_Athena::getInstance()->get_athena_set($v['id']); $v['status'] = 4; $v['open_level'] = $athena_set['open_level']; $v['open_num'] = $athena_set['open_num']; $v['nums'] = $this->get_open_level_num($athena_set['open_level'], $rank_list); } if (!$pre_view_group['trial']['open'] && $v['category'] == 10) { #神之试炼 $trial_set = Cache_Trial::getInstance()->get_trial_set($v['id']); $v['status'] = 4; $v['open_level'] = $trial_set['open_level']; $v['open_num'] = $trial_set['open_num']; $v['nums'] = $this->get_open_level_num($trial_set['open_level'], $rank_list); } if (!$pre_view_group['grab']['open'] && $v['category'] == 4) { #水晶争夺 $trial_set = Cache_GrabMine::getInstance()->get_base_info($v['id']); $v['status'] = 4; $v['open_level'] = $trial_set['open_level']; $v['open_num'] = $trial_set['open_num']; $v['nums'] = $this->get_open_level_num($trial_set['open_level'], $rank_list); } $res[] = $v; } else { $res_4[] = $v; } } } if (!empty($res_4)) { foreach ($res_4 as $v) { $res[] = $v; } } foreach ($pre_view_group as $key => $pre_list) { if (empty($pre_list['list'])) { continue; } foreach ($pre_list['list'] as $v) { switch ($key) { case "athena": $set = Cache_Athena::getInstance()->get_athena_set($v['id']); break; case 'worldboss': $set_boss = Cache_WorldBoss::getInstance()->get_worldboss_set($v['id']); $set['open_level'] = $set_boss['level']; $set['open_num'] = $set_boss['level_num']; break; case 'trial': $set = Cache_Trial::getInstance()->get_trial_set($v['id']); break; case 'grab': $set = Cache_GrabMine::getInstance()->get_base_info($v['id']); break; } $start = strtotime($date . ' ' . $v['start_time']); $end = strtotime($date . ' ' . $v['end_time']); $temp = array(); $temp['activity_id'] = $v['sid']; $temp['status'] = 4; $temp['lefttime'] = 0; $temp['joined'] = 0; $temp['tid'] = $v['id']; $temp['join_lvl'] = $v['join_min_lvl']; $temp['open_level'] = $set['open_level']; $temp['open_num'] = $set['open_num']; $temp['nums'] = $this->get_open_level_num($set['open_level'], $rank_list); $temp['start_time'] = $start; $temp['end_time'] = $end; $res[] = $temp; } } return $res; }
/** * 计算开启条件sid */ public function get_open_sid() { #$old_status = $this->redis()->hash_get($this->cacheKey_open); #if(!empty($old_status)) return $old_status['sid']; $list = $this->get_data('RankList')->get_sort_list('level'); $sid_list = Cache_Trial::getInstance()->get_trial_set(0); if (empty($list) || empty($sid_list)) { return 0; } $count = array(); foreach ($sid_list as $val) { foreach ($list as $level) { if ($val['open_level'] <= $level['level']) { $count[$val['sid']] += 1; } } } $sid = 0; foreach ($sid_list as $val) { if ($count[$val['sid']] >= $val['open_num'] && $val['sid'] > $sid) { $sid = $val['sid']; } } $expireAtTimestamp = strtotime("+1 hours"); $this->redis()->hash_set($this->cacheKey_open, array('sid' => $sid)); $this->redis()->expire($this->cacheKey_open, $expireAtTimestamp, true); return $sid; }
public function get_reward_by_sid($player_id, $sid, $times, $currency_types, $pinfo, $union_level, $wanted_level, $player_times = array()) { $currency_types = explode(',', $currency_types); $reward = ''; switch ($sid) { case 1: //主线副本 $exp_num = $this->get_game('PlayerFB')->main_fb_resource_retrieve($player_id, $times, 3, $pinfo, $union_level); if ($exp_num) { $reward = "1:" . ceil($exp_num); } break; case 2: //挑战副本 $send_reward = $this->get_game('PlayerPVE')->get_compensation_reward($player_id, 2, null, null, null, $pinfo); $arr_award = array(); foreach ($send_reward as $value) { if (in_array($value['item_id'], $currency_types)) { $arr_award[] = $value['item_id'] . ':' . ceil($value['item_num'] * $times); } } if ($arr_award) { $reward = implode('|', $arr_award); } break; case 3: //vip副本 $exp_num = $this->get_game('PlayerFB')->vip_fb_resource_retrieve($player_id, $pinfo['level'], $pinfo['vip'], $times); if ($exp_num) { $reward = "1:" . ceil($exp_num); } break; case 4: //日常任务 $arr_reward = $this->get_game('TaskHandler')->get_daily_task_reward($player_id, $pinfo); if ($arr_reward) { $send_reward = $arr_reward[0]; $arr_award = array(); foreach ($send_reward as $value) { if (in_array($value['item_id'], $currency_types)) { $arr_award[] = $value['item_id'] . ':' . ceil($value['item_num'] * $times); } } if ($arr_award) { $reward = implode('|', $arr_award); } } break; case 5: //天梯 $reward_detail = $this->get_game('Challenge')->get_challenge_battle_reward($player_id, $pinfo); if ($reward_detail) { $arr_award = array(); foreach ($reward_detail as $key => $value) { if (in_array($key, $currency_types)) { $arr_award[] = $key . ':' . ceil($value * $times); } } if ($arr_award) { $reward = implode('|', $arr_award); } } break; case 6: //竞技场 $send_reward = $this->get_game('KFArena')->get_back_reward($player_id, $pinfo['privilege_level'], $times); $arr_award = array(); foreach ($send_reward as $value) { if (in_array($value['item_id'], $currency_types)) { $arr_award[] = $value['item_id'] . ':' . ceil($value['item_num']); } } if ($arr_award) { $reward = implode('|', $arr_award); } break; case 7: //世界boss if (!$this->_player_func) { $this->get_now_sids($player_id, $pinfo['level']); } $f_sid = $this->_player_func[$sid]; if (!$f_sid) { return $reward; } $baseinfo = $this->get_game('WorldBoss')->get_base_info_id($f_sid); #vip加成奖励 $vip_exp = 0; if ($pinfo['privilege_level'] > 0) { $left_cd = $this->get_game('VipSpecial')->get_left_time($player_id); if ($left_cd > 0) { $vip_set = Cache_VipLevelLimit::getInstance()->get_limit_info($pinfo['privilege_level'], 10034); if (!empty($vip_set)) { $vip_exp = $vip_set['max_times']; } } } $rank_list = Cache_WorldBoss::getInstance()->get_rank_reward(); $rankreward = $rank_list[25]['reward_per']; $item_num = ($vip_exp / 10000 + 1) * ceil($baseinfo['dps_reward'] * $rankreward / 100); $reward = '1:' . ceil($item_num * $times); if (isset($player_times['world_boss_battle_rank']) && $player_times['world_boss_battle_rank']) { $count = count($rank_list); if ($player_times['world_boss_battle_rank'] > $count) { $rank_num = $count; } else { $rank_num = $player_times['world_boss_battle_rank']; } if ($rank_list[$rank_num - 1]['item_id'] && in_array($rank_list[$rank_num - 1]['item_id'], $currency_types) && $rank_list[$rank_num - 1]['item_reward_cnt']) { $item_num = ceil($rank_list[$rank_num - 1]['item_reward_cnt'] * 0.7) * $times; $reward = $reward . '|' . $rank_list[$rank_num - 1]['item_id'] . ':' . $item_num; } } break; case 8: //水晶争夺 if (!$this->_player_func) { $this->get_now_sids($player_id, $pinfo['level']); } $f_sid = $this->_player_func[$sid]; if (!$f_sid) { return $reward; } $send_reward = $this->get_game('GrabMine')->get_grabmine_reward($player_id, $pinfo, $f_sid); $arr_award = array(); foreach ($send_reward as $value) { if (in_array($value['item_id'], $currency_types)) { $arr_award[] = $value['item_id'] . ':' . ceil($value['item_num'] * $times); } } if ($arr_award) { $reward = implode('|', $arr_award); } break; case 9: //智力问答 $reward_detail = $this->get_game('AthenaQuestion')->get_athena_question_socre_reward($player_id, $pinfo); if ($reward_detail) { $arr_award = array(); foreach ($reward_detail as $key => $value) { if (in_array($key, $currency_types)) { $arr_award[] = $key . ':' . ceil($value * $times); } } if ($arr_award) { $reward = implode('|', $arr_award); } } break; case 10: //欢乐魔蛋 $rewards = $this->get_game('PlayerFB')->egg_active_resource_retrieve($player_id, $pinfo['level'], $times); if ($rewards) { $arr_award = array(); foreach ($rewards as $value) { if (in_array($value['id'], $currency_types)) { $arr_award[] = $value['id'] . ':' . ceil($value['num']); } } if ($arr_award) { $reward = implode('|', $arr_award); } } break; case 11: //守卫女神 if (!$this->_player_func) { $this->get_now_sids($player_id, $pinfo['level']); } $f_sid = $this->_player_func[$sid]; if (!$f_sid) { return $reward; } $athena_set = Cache_Athena::getInstance()->get_athena_set($f_sid); $max_waves = $athena_set['max_waves']; $wave = ceil($max_waves * 0.7); $rewards = Cache_Athena::getInstance()->get_athena_reward($f_sid); if ($rewards && $wave > 0) { $reward_ids = array(); foreach ($rewards as $val) { if ($val['sid'] == $f_sid && $wave == $val['waves']) { $reward_ids = explode('|', $val['rewards']); } } if (!empty($reward_ids)) { $arr_award = array(); $vip_exp = $this->get_game('Athena')->get_vip_add_exp($player_id); foreach ($reward_ids as $v) { $temp = explode(':', $v); if (count($temp) > 1) { if (in_array($temp[0], $currency_types)) { $item_num = $temp[1] * (1 + $vip_exp); $arr_award[] = $temp[0] . ':' . ceil($item_num * $times); } } } if ($arr_award) { $reward = implode('|', $arr_award); } } } break; case 12: //神之试炼 if (!$this->_player_func) { $this->get_now_sids($player_id, $pinfo['level']); } $f_sid = $this->_player_func[$sid]; if (!$f_sid) { return $reward; } $buff = Cache_Trial::getInstance()->get_buff($f_sid, 3); $rewards = Cache_Trial::getInstance()->get_trial_reward(); $reward_string = Cache_Trial::getInstance()->get_reward($pinfo['level'], $rewards); $reward_array = explode("|", $reward_string); $arr_award = array(); foreach ($reward_array as $arr) { list($item_idx, $item_num) = explode(":", $arr); if (empty($item_num)) { continue; } if (in_array($item_idx, $currency_types)) { $arr_award[] = $item_idx . ':' . ceil($item_num * $buff * $times); } } if ($arr_award) { $reward = implode('|', $arr_award); } break; case 13: //公会通缉 $exp_num = $this->get_game('UnionWanted')->wanted_fb_resource_retrieve($pinfo['level'], $wanted_level, 3, 2, $times); if ($exp_num) { $reward = "1:" . ceil($exp_num); } break; case 14: //3v3 $id = $this->get_data('KFDuel')->get_open_sid($pinfo['level']); $reward = ''; if ($id) { $reward_conf = Cache_CrossDuel::getInstance()->get_battle_reward_conf($id, $pinfo['level']); $point = intval($reward_conf['point'] * $times / 2); $rewards = array(); $arr_reward = explode('|', $reward_conf['reward']); foreach ($arr_reward as $value) { $ar_re = explode(':', $value); if (in_array($ar_re[0], $currency_types)) { $rewards[] = $ar_re[0] . ':' . intval($ar_re[1] * $times / 2); } } $reward = implode('|', $rewards); if (in_array(16, $currency_types)) { $reward = $reward . '|16:' . $point; } } break; case 15: //8v8 $rank_conf = Cache_FlameBattle::getInstance()->get_rank_conf(11); $gold = $rank_conf['gold']; $score = $rank_conf['reward']; $rewards = array(); $reward = ''; if (in_array(3, $currency_types)) { $rewards[] = '3:' . $gold * $times; } if (in_array(17, $currency_types)) { $rewards[] = '17:' . $score * $times; } $reward = implode('|', $rewards); break; default: //pass break; } return $reward; }
/** * 结束 * @param int $sid 活动id * @param array $roles 玩家 * @param array $mails 是否邮件发送奖励 * @param int $kill_num 击杀boss数 * @param int $time 时间 * @param int $owner_id 房主 * @param int $for_ranklist 0 结算,1 算排名 */ public function game_over($sid, $roles, $mails, $kill_num, $time, $owner_id = 0, $for_ranklist = 0, $roles_dmg = array(), $arr_kill_cnt = array(), $friends) { $sid = intval($sid); $kill_num = intval($kill_num); $time = intval($time); //排行榜处理 if ($for_ranklist) { //Com_Log::write('zzzwanghui','roles:'.json_encode($roles).'-kill_num:'.$kill_num.'-time:'.$time.'-owner:'.$owner_id.'-dmg:'.json_encode($roles_dmg).'-kills:'.json_encode($arr_kill_cnt)); if (!empty($roles) && count($roles) == count($arr_kill_cnt) && count($roles_dmg) == count($roles)) { $players = array(); $i = 0; $owner_name = ''; foreach ($roles as $player_id) { if ($player_id > 0) { $temp = $this->get_data('Player')->get_player_info($player_id, array('player_id', 'name', 'career_type', 'level')); $player_info = array('player_id' => $temp['player_id'], 'name' => $temp['name'], 'career_type' => $temp['career_type'], 'level' => $temp['level'], 'sum_fpower' => $roles_dmg[$i], 'kill_num' => $arr_kill_cnt[$i]); $players[] = $player_info; if ($player_id == $owner_id) { $owner_name = $temp['name']; } #添加好友亲密度 $this->get_game('Athena')->add_firend_point($player_id, $friends[$i]); } $i++; } $data = array('owner_id' => $owner_id, 'players' => json_encode($players), 'kill_num' => $kill_num, 'time' => $time, 'reptime' => time()); $this->get_data('Trial')->update_team_info($data); } return true; } //参数判断 if (!$sid || !is_array($roles) || !is_array($mails)) { $this->throw_error(10107, 6010010); } $p_num = count($roles); if ($p_num != count($mails)) { $this->throw_error(10107, 6010014); } //奖励 $buff = Cache_Trial::getInstance()->get_buff($sid, $kill_num); $rewards = Cache_Trial::getInstance()->get_trial_reward(); //次数 $set = Cache_ActivityHall::getInstance()->get_Activity_set($sid); if (!empty($set)) { $max_time = $set[0]['max_times']; } $record_info = $this->get_data('Trial')->get_record_info($sid); for ($i = 0; $i < $p_num; $i++) { $player_id = $roles[$i]; $used = $this->get_trial_remaining_count($player_id, $sid); if ($used > $max_time) { //次数超过限制 if (!$mails[$i]) { //在线 if ($record_info) { $arr_player = $this->get_data('Player')->get_player_info($record_info['player_id'], array('name', 'career_type')); $record_info['player_name'] = $arr_player['name']; $record_info['career_type'] = $arr_player['career_type']; unset($record_info['add_time']); } $res = array(); $res['sid'] = $sid; $res['kill_num'] = $kill_num; $res['time'] = $time; $res['reward'] = array(); $res['new'] = 0; #是否创记录 $res['old_num'] = 0; $res['old_time'] = 0; $res['record'] = $record_info; $res['reward_id'] = 0; Protocol::input($player_id, 8, 11, 1142, $res); } } else { $new = 1; $p_info = $this->get_data('Player')->get_player_info($player_id, array('level', 'gm')); //只记录普通账号记录 if ($p_info['gm'] == 0 || $p_info['gm'] == 3) { $insert_data = array('sid' => $sid, 'player_id' => $player_id, 'kill_num' => $kill_num, 'time' => $time, 'add_time' => time()); if (0 == $i) { if (!$record_info || ($record_info['kill_num'] < $kill_num || $record_info['kill_num'] == $kill_num && $time < $record_info['time'])) { $record_info = array('sid' => $sid, 'player_id' => $player_id, 'kill_num' => $kill_num, 'time' => $time, 'add_time' => time()); $this->get_data('Trial')->update_record_info($sid, $record_info); } } $player_trial = $this->get_data('Trial')->get_player_info($player_id, $sid); if (!empty($player_trial) && isset($player_trial['player_id'])) { //更新记录 if ($player_trial['kill_num'] < $kill_num || $player_trial['kill_num'] == $kill_num && $time < $player_trial['time']) { $this->get_data('Trial')->update_player_info($player_id, $sid, $insert_data); $new = 1; } else { $new = 0; } } else { #添加记录 if ($insert_data['kill_num'] > 0) { $this->get_data('Trial')->update_player_info($player_id, $sid, $insert_data); } $player_trial['kill_num'] = 0; $player_trial['time'] = 0; } } if (!($reward = Cache_Trial::getInstance()->get_reward($p_info['level'], $rewards))) { $this->throw_error(10222, 6010011); } if ($record_info) { $arr_player = $this->get_data('Player')->get_player_info($record_info['player_id'], array('name', 'career_type')); $record_info['player_name'] = $arr_player['name']; $record_info['career_type'] = $arr_player['career_type']; unset($record_info['add_time']); } $res = array(); $res['sid'] = $sid; $res['kill_num'] = $kill_num; $res['time'] = $time; $res['reward'] = array(); $res['new'] = $new; #是否创记录 $res['old_num'] = $player_trial['kill_num']; $res['old_time'] = $player_trial['time']; $res['record'] = $record_info; $reward_ids = explode('|', $reward); if ($reward_ids) { if ($kill_num) { foreach ($reward_ids as $value) { $temp = explode(':', $value); if (count($temp) > 1) { $temp_reward = array('type' => Cache_Currency::getInstance()->get_key($temp[0]), 'item_id' => $temp[0], 'item_num' => $temp[1] * $buff); array_push($res['reward'], $temp_reward); } else { $this->throw_error(10222, 6010015); } } } if ($mails[$i]) { //下线发邮件 if ($kill_num) { $phrase_config = Cache_FuncPhraseConfig::getInstance()->get_phrase_config_info(4071); $content = sprintf($phrase_config['content'], $kill_num); $attachment = array(); foreach ($res['reward'] as $value) { $attachment[] = array("prop_id" => $value['item_id'], "prop_num" => $value['item_num']); } $this->get_game('Mail')->async_trigger_mail($player_id, $phrase_config['title'], $content, $attachment, $phrase_config['sender'], 1, 1142, 0); } } else { if ($kill_num) { $result = $this->get_game('Reward')->send_reward($player_id, $res['reward'], array('cmd_id' => 1142, 'bind_flag' => 0), 1); if (true === $result) { $this->get_game('Reward')->add_reward_log(); //记录日志 $res['reward_id'] = 1; } else { $this->throw_error(10110, 6010009); } } else { $res['reward_id'] = 0; } Protocol::input($player_id, 8, 11, 1142, $res); } # 引导任务埋点 $this->get_game('TaskTrigger')->async_trigger_guide_task($player_id, 37, 1); //添加活跃度 $this->get_game('DailyBoon')->async_trigger_daily_boon_task($player_id, 3012, 1); } else { $this->throw_error(10222, 6010012); } } } }