/** * 领取排名奖励 * @param int player_id 玩家id * @param int type 类型 1 等级,2战力 3公会等级 * @return array */ public function get_rank_reward($player_id, $type) { $player_id = intval($player_id); $type = intval($type); if (!in_array($type, array(1, 2, 3))) { $this->throw_error(10107, 6010086); } $activity_player_rank = $this->get_data('NewServerActivity')->get_player_rank($player_id, $type); if (!$activity_player_rank) { $this->throw_error(6010062, 6010065); } if ($activity_player_rank['flag'] > 1) { //已领取 $this->throw_error(6010063, 6010066); } //获取奖励配置 if (!($set_rank = Cache_NewServerActivity::getInstance()->get_rank_reward($type))) { $this->throw_error(10222, 6010067); } $set = array(); foreach ($set_rank as $rank) { if ($activity_player_rank['rank'] <= $rank['rank']) { $set = $rank; break; } } if (!$set) { $this->throw_error(10222, 6010068); } $up_arr = array('flag' => 2); $config = Cache_AchieveConfig::getInstance()->get_achieve_config($set['rewards']); $item_id = $config['reward']; $reward = array(); $reward[] = array('type' => Cache_Currency::getInstance()->get_key($item_id), 'item_id' => $item_id, 'item_num' => 1); switch ($type) { case 1: $cmd_id = 2316; break; case 2: $cmd_id = 23161; break; case 3: $cmd_id = 23162; break; } $this->start_trans(); $re = $this->get_data('NewServerActivity')->update_player_rank($player_id, $type, $up_arr); $this->write_check($re, 6010070); $re = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => $cmd_id, 'bind_flag' => 0)); $this->write_check_strict($re, 6010071); $this->commit(); $this->get_game('Reward')->add_reward_log(true); $data = $this->get_rank_panel($player_id, $type); Protocol::input($player_id, 8, 23, 2314, $data); # 新服活动,蛋疼的数字埋点 $this->get_game('PlayerFunc')->sync_func_tips($player_id, 1250); return array('res' => 1, 'type' => $type); }
private function receive_title_awards($player_id, $title_id, $player_360_vip_level) { $special_config = Cache_360VipSpecial::getInstance()->get_360_special_by_type($this->_special_title_type); if (!Com_Array::is_good_arr($special_config)) { $this->throw_error('10222', 5010194); } $title_ids = array(); $title_reward = array(); foreach ($special_config as $val) { $title_ids[$val['title_id']] = $val['vip_level']; $title_reward[$val['title_id']] = $val['reward']; } #不存在该称号 if (!isset($title_ids[$title_id])) { $this->throw_error('2319004', 5010204); } #等级不足无法领取 if ($player_360_vip_level < $title_ids[$title_id]) { $this->throw_error('2319003', 5010207); } #已获得过该称号 $receive_title_ids = $this->get_data("360Special")->get_gold_special($player_id, array('receive_title_ids')); if (isset($receive_title_ids['receive_title_ids'][$title_id])) { $this->throw_error('2326004', 5010214); } $achieve_config = Cache_AchieveConfig::getInstance()->get_achieve_config_by_titleid($title_id); if (empty($achieve_config)) { $this->throw_error('10222', 5010220); } if (empty($achieve_config[0]['reward'])) { $this->throw_error('10222', 5010221); } $reward = $this->get_format_reward($achieve_config[0]['reward'] . ":1"); $this->start_trans(); $result = $this->get_game('Reward')->send_reward($player_id, $reward, array('cmd_id' => '2319')); if ($result !== true) { $this->throw_error($result); } #记录已领取过的每日奖励 $receive_title_ids['receive_title_ids'][$title_id] = time(); $re = $this->get_data("360Special")->update_gold_special($player_id, $receive_title_ids); $this->write_check($re, 5010226); $this->commit(); $this->get_game('Reward')->add_reward_log(); }
public function run() { $achieve_configs = Cache_AchieveConfig::getInstance()->get_achieve_config(); $arr_ids = array(); foreach ($achieve_configs as $value) { $arr_ids[] = $value['achieve_id']; } $this->_achieve_ids = $arr_ids; $this->db = Com_Db::factory('game'); while (true) { $begin_time = time(); $player_list = $this->get_data('Online')->get_online_list(); if (empty($player_list)) { sleep($this->_sleep_time); //waiting continue; } $this->arr_union_ids = array(); $this->arr_player_union = array(); $time = $this->get_data('Online')->get_backup_time(); if ($time) { $logout_start_time = $time - $this->_offset_time; } else { $logout_start_time = $begin_time - $this->_offset_time; } foreach ($player_list as $player_id => $v) { if (empty($player_id)) { continue; } if (1 == $v) { continue; } $arr_time = json_decode($v, true); if ($arr_time['login_time'] > $arr_time['logout_time'] || $arr_time['logout_time'] >= $logout_start_time) { $this->db->start_trans(); try { if (!$this->backup($player_id)) { throw new Exception('error1!'); } if (!$this->backup_player_tables($player_id)) { throw new Exception('error2!'); } $this->db->commit(); } catch (Exception $e) { $this->db->rollback(); } } else { unset($player_list[$player_id]); } unset($arr_time); } sleep(1); //waiting foreach ($this->arr_union_ids as $union_id => $v) { if (!$union_id) { continue; } $this->db->start_trans(); try { if (!$this->backup_union($union_id)) { throw new Exception('error3!'); } if (!$this->backup_union_tables($union_id)) { throw new Exception('error4!'); } $this->db->commit(); } catch (Exception $e) { $this->db->rollback(); } } //单独处理 $this->backup_alone(); $end_time = time(); $used_time = $end_time - $begin_time; $this->get_data('Online')->set_backup_time($begin_time); if (!$time) { sleep($this->_delay_time); //waiting } else { sleep($this->_sleep_time); //waiting } echo "sync end!"; } }
/** * 更新玩家成就 * @param int $achieve_id * @param array $arr 更新内容 * @param int $player_id * @return null|array */ public function update_player_achieve($player_id, $title_id, $arrPlayerachieveDetail, $achieve_id = 0) { $this->sync_player_achieve_info($player_id); if (!is_array($arrPlayerachieveDetail)) { return false; } $player_id = intval($player_id); if ($achieve_id > 0) { if ($this->is_trans()) { $bDealCheck = $this->set_redis_pre_action(null, array($this->redis(), 'hash_set'), array($this->get_cache_key($player_id), $achieve_id, json_encode($arrPlayerachieveDetail[$achieve_id]))); } else { $bDealCheck = $this->redis()->hash_set($this->get_cache_key($player_id), $achieve_id, json_encode($arrPlayerachieveDetail[$achieve_id])); } } else { $achieveids = Cache_AchieveConfig::getInstance()->get_achieve_config_achieveids($title_id); foreach ($achieveids as $achieve_id) { if (!isset($arrPlayerachieveDetail[$achieve_id]) || empty($arrPlayerachieveDetail[$achieve_id]) || !Com_Array::is_good_arr($arrPlayerachieveDetail[$achieve_id])) { continue; } if ($this->is_trans()) { $bDealCheck = $this->set_redis_pre_action(null, array($this->redis(), 'hash_set'), array($this->get_cache_key($player_id), $achieve_id, json_encode($arrPlayerachieveDetail[$achieve_id]))); } else { $bDealCheck = $this->redis()->hash_set($this->get_cache_key($player_id), $achieve_id, json_encode($arrPlayerachieveDetail[$achieve_id])); } } } return $bDealCheck; }
public function get_title_finish_progress($player_id, $title_id) { $title_config = Cache_TitleConfig::getInstance()->get_title_config_by_id($title_id); $finish_title_ids = $this->get_data('PlayerAchieveCounter')->get_player_achieve_counter_info($player_id, 'finish_title_ids'); $title_state = 0; if (isset($finish_title_ids[$title_id])) { $title_state = 1; //激活 } $item = array(); $item['title_id'] = $title_config['title_id']; $item['title_state'] = isset($finish_title_ids[$title_id]) ? 1 : 0; $item['icon'] = $title_config['icon']; $item['title_name'] = $title_config['title_name']; $item['reward'] = $this->get_format_achieve_attr($title_config['reward']); $item['achieve_finish_num'] = $item['title_state']; $item['achieve_total_num'] = 1; $item['show_reward'] = 0; $item['target_info'] = ''; $item['target_tips'] = ''; $item['tag'] = intval($title_config['tag']); $item['resource_type'] = intval($title_config['resource_type']); if ($title_config['tag'] == 2 && $title_state == 0) { $language_config = Cache_Language::getInstance()->get_language_info(760001); $item['target_info'] = $language_config['content']; } if (empty($item['target_info'])) { $achieveConfig = Cache_AchieveConfig::getInstance()->get_achieve_config_by_titleid($title_id); $achieve_task_info = $this->get_data('PlayerAchieve')->get_player_achieve_info($player_id, $title_id); $item['target_info'] = $achieveConfig[0]['target_info']; if ($title_state == 0) { $item['target_tips'] = str_replace("%s", intval($achieve_task_info[$achieveConfig[0]['achieve_id']]['val']), $achieveConfig[0]['target_tips']); } } return $item; }